Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

add rest example tests #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add rest example tests #15

wants to merge 2 commits into from

Conversation

gamerson
Copy link

No description provided.

@gamerson
Copy link
Author

@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);
Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

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?

Copy link
Author

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);
Copy link
Author

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);
Copy link
Author

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/");
Copy link
Author

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>
@gamerson
Copy link
Author

Squashed the commits and force pushed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants