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().isTraceEnabled()){
39 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
44 public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
47 CollectionSpaceClient client = getClientInstance();
48 PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
49 if (payloadOutputPart != null) {
50 result = (CPT) payloadOutputPart.getBody();
52 Assert.assertNotNull(result,
53 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
59 public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
60 PoxPayloadOut result = null;
62 CollectionSpaceClient client = this.getClientInstance();
63 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
64 PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
70 protected PayloadInputPart extractPart(Response res, String partLabel)
72 if (getLogger().isDebugEnabled()) {
73 getLogger().debug("Reading part " + partLabel + " ...");
75 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
76 PayloadInputPart payloadInputPart = input.getPart(partLabel);
77 Assert.assertNotNull(payloadInputPart,
78 "Part " + partLabel + " was unexpectedly null.");
79 return payloadInputPart;