1 package org.collectionspace.services.client.test;
3 import org.collectionspace.services.client.CollectionSpaceClient;
4 import org.collectionspace.services.client.PayloadInputPart;
5 import org.collectionspace.services.client.PayloadOutputPart;
6 import org.collectionspace.services.client.PoxPayloadIn;
7 import org.collectionspace.services.client.PoxPayloadOut;
8 import org.collectionspace.services.client.AbstractCommonListUtils;
9 import org.collectionspace.services.jaxb.AbstractCommonList;
11 import org.jboss.resteasy.client.ClientResponse;
12 import org.testng.Assert;
15 * <CLT> - Common list type
16 * <CPT> - Common part type
18 public abstract class AbstractPoxServiceTestImpl<CLT extends AbstractCommonList, CPT>
19 extends AbstractServiceTestImpl<CLT, CPT, PoxPayloadOut, String> {
22 public CPT extractCommonPartValue(ClientResponse<String> res) throws Exception {
25 CollectionSpaceClient client = getClientInstance();
26 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
27 if (payloadInputPart != null) {
28 result = (CPT) payloadInputPart.getBody();
30 Assert.assertNotNull(result,
31 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
36 protected void printList(String testName, CLT list) {
37 if (getLogger().isTraceEnabled()){
38 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
43 public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
46 CollectionSpaceClient client = getClientInstance();
47 PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
48 if (payloadOutputPart != null) {
49 result = (CPT) payloadOutputPart.getBody();
51 Assert.assertNotNull(result,
52 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
58 public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
59 PoxPayloadOut result = null;
61 CollectionSpaceClient client = this.getClientInstance();
62 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
63 PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
69 protected PayloadInputPart extractPart(ClientResponse<String> res, String partLabel)
71 if (getLogger().isDebugEnabled()) {
72 getLogger().debug("Reading part " + partLabel + " ...");
74 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
75 PayloadInputPart payloadInputPart = input.getPart(partLabel);
76 Assert.assertNotNull(payloadInputPart,
77 "Part " + partLabel + " was unexpectedly null.");
78 return payloadInputPart;