1 package org.collectionspace.services.client.test;
3 import javax.ws.rs.core.Response;
5 import org.collectionspace.services.client.AuthorityClient;
6 import org.collectionspace.services.client.CollectionSpaceClient;
7 import org.collectionspace.services.client.PayloadInputPart;
8 import org.collectionspace.services.client.PayloadOutputPart;
9 import org.collectionspace.services.client.PoxPayloadIn;
10 import org.collectionspace.services.client.PoxPayloadOut;
11 import org.collectionspace.services.client.AbstractCommonListUtils;
12 import org.collectionspace.services.client.XmlTools;
13 import org.collectionspace.services.client.workflow.WorkflowClient;
14 import org.collectionspace.services.jaxb.AbstractCommonList;
15 import org.dom4j.Document;
16 import org.jboss.resteasy.client.ClientResponse;
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> {
27 public CPT extractCommonPartValue(Response res) throws Exception {
30 CollectionSpaceClient client = getClientInstance();
31 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
32 if (payloadInputPart != null) {
33 result = (CPT) payloadInputPart.getBody();
35 Assert.assertNotNull(result,
36 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
41 protected void printList(String testName, CLT list) {
42 if (getLogger().isDebugEnabled()){
43 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
48 protected long getSizeOfList(CLT list) {
49 return list.getTotalItems();
53 * Extracts the workflow state of PoxPayloadIn
59 protected String extractAuthorityWorkflowState(PoxPayloadIn input) throws Exception {
62 Document document = input.getDOMDocument();
63 result = XmlTools.getElementValue(document, "//" + WorkflowClient.WORKFLOWSTATE_XML_ELEMENT_NAME);
69 * Extracts the workflow state of a response payload
75 protected String extractAuthorityWorkflowState(Response res) throws Exception {
78 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
79 result = extractAuthorityWorkflowState(input);
85 * The entity type expected from the JAX-RS Response object
87 public Class<String> getEntityResponseType() {
92 public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
95 CollectionSpaceClient client = getClientInstance();
96 PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
97 if (payloadOutputPart != null) {
98 result = (CPT) payloadOutputPart.getBody();
100 Assert.assertNotNull(result,
101 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
107 public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) throws Exception {
108 PoxPayloadOut result = null;
110 CollectionSpaceClient client = this.getClientInstance();
111 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
112 PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
118 protected PayloadInputPart extractPart(Response res, String partLabel)
120 if (getLogger().isDebugEnabled()) {
121 getLogger().debug("Reading part " + partLabel + " ...");
123 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
124 PayloadInputPart payloadInputPart = input.getPart(partLabel);
125 Assert.assertNotNull(payloadInputPart,
126 "Part " + partLabel + " was unexpectedly null.");
127 return payloadInputPart;