Java Reference
In-Depth Information
The output of the build should end with
BUILD SUCCESS
.
Examining the Source Code
The server-side source code is exactly as posted in
Chapter 3
. The guts of the client code are
the same as in
Chapter 3
, but the client code is structured as a JUnit class. JUnit is an open
source Java library for defining unit tests. Maven automatically knows how to find JUnit-en-
abled test code and run it with the build. It scans the classes within the
src/test/java
directory,
looking for classes that have methods annotated with
@org.junit.Test
. This example has
only one:
com.restfully.shop.test.CustomerResourceTest
. Let's go over the code for
it that is different from the topic:
src/test/java/com/restfully/shop/test/CustomerResourceTest.java
package
package
com
.
restfully
.
shop
.
test
;
import
import
org.junit.Test
org.junit.Test
;
import
import
javax.ws.rs.client.Client
javax.ws.rs.client.Client
;
import
import
javax.ws.rs.client.ClientBuilder
javax.ws.rs.client.ClientBuilder
;
import
import
javax.ws.rs.client.Entity
javax.ws.rs.client.Entity
;
import
import
javax.ws.rs.core.Response
javax.ws.rs.core.Response
;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public
public class
class
CustomerResourceTest
CustomerResourceTest
{
@Test
public
public
void
void
testCustomerResource
()
throws
throws
Exception
{
Our test class has only one method:
testCustomerResource()
. It is annotated with
@Test
.
This tells Maven that this method is a JUnit test. The code for this method is exactly the
within this method to run the example.
That's it! The rest of the examples in this topic have the same Maven structure as
ex03_1
and
are tested using JUnit.