1 package org.collectionspace.services.client.test;
3 import javax.ws.rs.core.Response;
5 import org.collectionspace.services.client.CollectionSpaceClient;
6 import org.collectionspace.services.client.PayloadInputPart;
7 import org.collectionspace.services.client.PayloadOutputPart;
8 import org.collectionspace.services.client.PoxPayloadIn;
9 import org.collectionspace.services.client.PoxPayloadOut;
10 import org.collectionspace.services.client.AbstractCommonListUtils;
11 import org.collectionspace.services.jaxb.AbstractCommonList;
12 import org.jboss.resteasy.client.ClientResponse;
13 import org.testng.Assert;
16 * <CLT> - Common list type
17 * <CPT> - Common part type
19 public abstract class AbstractPoxServiceTestImpl<CLT extends AbstractCommonList, CPT>
20 extends AbstractServiceTestImpl<CLT, CPT, PoxPayloadOut, String> {
23 public CPT extractCommonPartValue(Response res) throws Exception {
26 CollectionSpaceClient client = getClientInstance();
27 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
28 if (payloadInputPart != null) {
29 result = (CPT) payloadInputPart.getBody();
31 Assert.assertNotNull(result,
32 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
37 protected void printList(String testName, CLT list) {
38 if (getLogger().isDebugEnabled()){
39 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
44 protected long getSizeOfList(CLT list) {
45 return list.getTotalItems();
49 * The entity type expected from the JAX-RS Response object
51 public Class<String> getEntityResponseType() {
56 public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
59 CollectionSpaceClient client = getClientInstance();
60 PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
61 if (payloadOutputPart != null) {
62 result = (CPT) payloadOutputPart.getBody();
64 Assert.assertNotNull(result,
65 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
71 public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
72 PoxPayloadOut result = null;
74 CollectionSpaceClient client = this.getClientInstance();
75 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
76 PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
82 protected PayloadInputPart extractPart(Response res, String partLabel)
84 if (getLogger().isDebugEnabled()) {
85 getLogger().debug("Reading part " + partLabel + " ...");
87 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
88 PayloadInputPart payloadInputPart = input.getPart(partLabel);
89 Assert.assertNotNull(payloadInputPart,
90 "Part " + partLabel + " was unexpectedly null.");
91 return payloadInputPart;