-
Notifications
You must be signed in to change notification settings - Fork 24
add rest example tests #15
base: master
Are you sure you want to change the base?
Conversation
@pkriens I'm trying to play around with enroute rest application and I wanted to make sure I was understanding the input/outputs of the rest endpoints. So I wrote up some tests and added them here. Two of these tests are failing. I'll mark them in the comments and see if you can help out. |
|
||
Object result = request.go(url); | ||
|
||
Assert.assertEquals("{\"input\":\"Sam\",\"output\":\"SAM\"}", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert fails, the result is {input=Sam, output=SAM}
but according to this line https://github.com/osgi/osgi.enroute.examples/blob/master/osgi.enroute.examples.rest.application/src/osgi/enroute/examples/rest/application/RestApplication.java#L145 it should be {"input":"Sam","output":"SAM"}
Some JSON encoding difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is wrong. Instead of using the dtos encoder (or JSONCodec in bnd on which it is build) to compare it uses the toString() method which is not proper JSON. Both encoders have canonicalized outputs. You can also of course test the fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when I get the result
object from the server, what should I do with it exactly? Do I hand it off to some JSON decoder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now new JSONCodec().enc().to().put(result).toString()
works
|
||
Object result = request.go(url); | ||
|
||
Assert.assertEquals("{\"input\":\"Sam\",\"output\":\"SAM\"}", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert fails, the result is {input=Sam, output=SAM} but according to this line https://github.com/osgi/osgi.enroute.examples/blob/master/osgi.enroute.examples.rest.application/src/osgi/enroute/examples/rest/application/RestApplication.java#L127 it should be {"input":"Sam","output":"SAM"}
Some JSON encoding difference?
|
||
Object result = request.go(url); | ||
|
||
Assert.assertEquals("{\"input\":\"Sam\",\"output\":\"SAM\"}", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when I get the result
object from the server, what should I do with it exactly? Do I hand it off to some JSON decoder?
|
||
@Test | ||
public void testPostUpper5() throws Exception { | ||
URL url = new URL("http://localhost:8080/rest/upper5/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For doing a "POST" with a body, I had to resort to JDK url connection. I'd rather use HttpClient but I wasn't sure how to do a "POST" with body using httpClient.
Signed-off-by: Gregory Amerson <gregory.amerson@liferay.com>
Signed-off-by: Gregory Amerson <gregory.amerson@liferay.com>
Squashed the commits and force pushed. |
No description provided.