CS639 Homework3 Getting started with REST Web Services, Unit testing with JUnit4
Due Tuesday, Apr.10, in class, on paper.

1. Read the Jersey REST tutorial by Lars Vogel at least through Section 4, about JAXB. Copy this example from $cs630/firstRest to your cs639 directory on Linux and to your own development system. I have customized its client to use our TOMCAT_URL environment variable, which you should have already set up for pa2. Also the package names are changed, and needed jar files added, and build.xml too. Read the build.xml, deploy the project with “ant deploy”, and try out the various ways to run it: ant restGetXML gets the XML hello message by using wget, vs. ant runClient runs the Java client program, etc. Note the added capability to echo posted XML back enclosed within an echo element.

a.       Add another method to Hello.java to echo posted plain text where the response is prepended with “this was your message: “ and appended with “end of message”. Add a target to build.xml and a plain text file to test this capability.  Include your method and build target in your homework.

b.      Explain how to use telnet to get a response from firstRest: what does it send back?

2. Get firstRest working in eclipse in a Dynamic Web Project, using the same procedure as we used with pa2.

a. Add a method to Test.java to post to your text echo service. Put this method in your homework paper. Report on any problems with the project in eclipse.  Try out using tomcat inside eclipse (but this is not essential, you can run eclipse from startup.bat and still use eclipse for editing files.)

b. Try running the client when tomcat is down. What exception do you get and what line of Test.java throws?

3. Get the supplied orderServer project up and running on your home PC using ant.
a. Report on success or problems, and what ant targets you tried out (just a list of them.)

b. Check that the provided order.xml is valid based on the provided XSD schema schemas/OrderService.xsd.  Explain how you checked this, for example by giving the command line for sax.Counter execution.  Does order.xml have all the first-level elements (children of the order element) described in OrderService.xsd? If not, how can it pass validation?

4. Read Chap. 4 of Rest in Practice.

a. Based on what is in this chapter, give the sequence of HTTP commands (like “GET /order/1234”) involved in the following user sequence: order a coffee, ask for status of order, change order, ask for status again, and finally deleting the order.

b. Note that the supplied orderService implements all the actions you listed in a., plus two more: doing a DELETE on /order to remove all orders, and doing a POST to /poke to make the oldest non-ready order ready. Write down the Service description for orderService in terms of HTTP actions, that is, what URLs work with what HTTP verbs (GET, POST, etc.) and what content goes back and forth.  This is what is described (at least in part) by the WADL file (see pp. 86-87), which you can obtain with “ant get-wadl”.

5. Get orderService working under eclipse. This is tricky because of its multiple source areas. See orderService/README for detailed instructions.  If you can’t get the complex setup working, you can combine all the source areas to main and use that setup for now.

a. Report on your success or problems with the setup.

b. Note all the JUnit tests provided. You can run all the tests by right-clicking the project icon in Package Explorer and selecting Run As>JUnit Test. Try this out and report on the results.  You can run parts of the unit testing by right-clicking package icons or source file icons. Try running EndToEndTest by itself and report on success or problems.

b. Note that the system is producing quite a bit of debug output. Explain how you find both the client-side and server-side output for the run of EndToEndTest.  For example, the string “set BASE_URI (from env var TOMCAT_URL) = ...” is coming from the client code in EndToEndTest, while the string "in CreateOrderActivity" is coming from the server. The client-side output is definitely handled by eclipse, but the server output is handled by eclipse only if you are running tomcat from within eclipse. Explain how you are running eclipse (from inside eclipse or separately, with startup.bat).

6.  Intro to unit testing. Read the JUnit docs linked to the class web page under Resources>JUnit4. Look at the unit tests in orderService. In Eclipse, pull down Help, select Help Contents>TestingApplications>Testing with JUnit, and read about Creating JUnit tests. To run them, just right-click on the file, package or project, and Run as..>JUnit test. Report on your success adding another test to orderService and running all the tests, from eclipse and also using ant directly.