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.client.XmlTools;
12 import org.collectionspace.services.client.workflow.WorkflowClient;
13 import org.collectionspace.services.jaxb.AbstractCommonList;
14 import org.dom4j.Document;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.testng.Assert;
20 * <CLT> - Common list type
21 * <CPT> - Common part type
23 public abstract class AbstractPoxServiceTestImpl<CLT extends AbstractCommonList, CPT>
24 extends AbstractServiceTestImpl<CLT, CPT, PoxPayloadOut, String> {
26 private final String CLASS_NAME = AbstractPoxServiceTestImpl.class.getName();
27 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
30 public CPT extractCommonPartValue(Response res) throws Exception {
33 CollectionSpaceClient client = getClientInstance();
34 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
35 if (payloadInputPart != null) {
36 result = (CPT) payloadInputPart.getBody();
38 Assert.assertNotNull(result,
39 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
44 protected void printList(String testName, CLT list) {
45 if (getLogger().isDebugEnabled()){
46 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
51 protected long getSizeOfList(CLT list) {
52 return list.getTotalItems();
56 * Extracts the workflow state of PoxPayloadIn
62 protected String extractAuthorityWorkflowState(PoxPayloadIn input) throws Exception {
65 Document document = input.getDOMDocument();
66 result = XmlTools.getElementValue(document, "//" + WorkflowClient.WORKFLOWSTATE_XML_ELEMENT_NAME);
72 * Extracts the workflow state of a response payload
78 protected String extractAuthorityWorkflowState(Response res) throws Exception {
81 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
82 result = extractAuthorityWorkflowState(input);
88 * The entity type expected from the JAX-RS Response object
90 public Class<String> getEntityResponseType() {
95 public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
98 CollectionSpaceClient client = getClientInstance();
99 PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
100 if (payloadOutputPart != null) {
101 result = (CPT) payloadOutputPart.getBody();
103 Assert.assertNotNull(result,
104 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
110 public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) throws Exception {
111 PoxPayloadOut result = null;
113 CollectionSpaceClient client = this.getClientInstance();
114 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
115 PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
121 protected PayloadInputPart extractPart(Response res, String partLabel)
123 if (getLogger().isDebugEnabled()) {
124 getLogger().debug("Reading part " + partLabel + " ...");
126 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
127 PayloadInputPart payloadInputPart = input.getPart(partLabel);
128 Assert.assertNotNull(payloadInputPart,
129 "Part " + partLabel + " was unexpectedly null.");
130 return payloadInputPart;