-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Mercap/http_transport_improvements
Fixed some HTTP transport related glitches
- Loading branch information
Showing
8 changed files
with
129 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Extension { #name : #ZnEntity } | ||
|
||
{ #category : #'*JRPC-Server-Pharo6' } | ||
ZnEntity class >> json: text [ | ||
|
||
^ self stringEntityClass json: text | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Extension { #name : #ZnStringEntity } | ||
|
||
{ #category : #'*JRPC-Server-Pharo6' } | ||
ZnStringEntity class >> json: string [ | ||
^ (self type: ZnMimeType applicationJson) | ||
string: string; | ||
yourself | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'JRPC-Server-Pharo6' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
" | ||
I'm a test for JSON RPC over HTTP transport | ||
" | ||
Class { | ||
#name : #JRPCHttpServerTest, | ||
#superclass : #TestCase, | ||
#instVars : [ | ||
'server' | ||
], | ||
#category : #'JRPC-Tests' | ||
} | ||
|
||
{ #category : #private } | ||
JRPCHttpServerTest >> checkPortAvailability [ | ||
|
||
[ ( ZnNetworkingUtils serverSocketOn: self port ) close ] | ||
on: Error | ||
do: [ :error | self fail: ( 'Port <1p> is not available' expandMacrosWith: self port ) ] | ||
] | ||
|
||
{ #category : #private } | ||
JRPCHttpServerTest >> port [ | ||
|
||
^ 7777 | ||
] | ||
|
||
{ #category : #running } | ||
JRPCHttpServerTest >> setUp [ | ||
|
||
super setUp. | ||
self checkPortAvailability. | ||
server := JRPCServer http. | ||
server port: self port. | ||
server start | ||
] | ||
|
||
{ #category : #running } | ||
JRPCHttpServerTest >> tearDown [ | ||
|
||
server ifNotNil: [ server stop ]. | ||
server := nil. | ||
super tearDown | ||
] | ||
|
||
{ #category : #accessing } | ||
JRPCHttpServerTest >> testRequestOnInvalidEndpoint [ | ||
|
||
| httpClient failed | | ||
|
||
server addHandlerNamed: 'sum' block: [ :a :b | a + b ]. | ||
failed := false. | ||
|
||
httpClient := JRPCClient http: ( 'http://localhost' asUrl port: self port ) / 'bad'. | ||
httpClient | ||
ifFail: [ :error | | ||
failed := true. | ||
'{}' | ||
]. | ||
self | ||
should: [ httpClient callMethod: 'sum' arguments: #(1 3) withId: 1 ] raise: JRPCIncorrectJSON; | ||
assert: failed | ||
] | ||
|
||
{ #category : #accessing } | ||
JRPCHttpServerTest >> testValidRequest [ | ||
|
||
| httpClient | | ||
|
||
server addHandlerNamed: 'sum' block: [ :a :b | a + b ]. | ||
|
||
httpClient := JRPCClient http: ( 'http://localhost' asUrl port: self port ). | ||
|
||
self assert: ( httpClient callMethod: 'sum' arguments: #(1 3) withId: 1 ) result equals: 4 | ||
] |