Java Reference
In-Depth Information
protected
protected
void
void
populateDB
()
throws
throws
Exception
{
Response response
=
client
.
target
(
"http://localhost:8080/ex14_1/services/shop"
)
.
request
().
head
();
Link products
=
response
.
getLink
(
"products"
);
response
.
close
();
System
.
out
.
println
(
"** Populate Products"
);
Product product
=
new
new
Product
();
product
.
setName
(
"iPhone"
);
product
.
setCost
(
199.99
);
response
=
client
.
target
(
products
).
request
().
post
(
Entity
.
xml
(
product
));
Assert
.
assertEquals
(
201
,
response
.
getStatus
());
response
.
close
();
product
=
new
new
Product
();
product
.
setName
(
"MacBook Pro"
);
product
.
setCost
(
3299.99
);
response
=
client
.
target
(
products
).
request
().
post
(
Entity
.
xml
(
product
));
Assert
.
assertEquals
(
201
,
response
.
getStatus
());
response
.
close
();
product
=
new
new
Product
();
product
.
setName
(
"iPod"
);
product
.
setCost
(
49.99
);
response
=
client
.
target
(
products
).
request
().
post
(
Entity
.
xml
(
product
));
Assert
.
assertEquals
(
201
,
response
.
getStatus
());
response
.
close
();
}
The
populateDB()
method makes HTTP calls on the
ProductResource
JAX-RS service to
create a few products in the database.
@Test
public
public
void
void
testCreateOrder
()
throws
throws
Exception
{
populateDB
();
Response response
=
client
.
target
(
"http://localhost:8080/ex14_1/services/shop"
).
request
().
head
();
Link customers
=
response
.
getLink
(
"customers"
);
Link products
=
response
.
getLink
(
"products"
);
Link orders
=
response
.
getLink
(
"orders"
);
response
.
close
();