]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
362b31ccc0d1c177534475d581ec18754d41cf77
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.client.test;
2
3 import javax.ws.rs.core.Response;
4
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;
14
15 /*
16  * <CLT> - Common list type
17  * <CPT> - Common part type
18  */
19 public abstract class AbstractPoxServiceTestImpl<CLT extends AbstractCommonList, CPT>
20                 extends AbstractServiceTestImpl<CLT, CPT, PoxPayloadOut, String> {
21                 
22         @Override
23         public CPT extractCommonPartValue(Response res) throws Exception {
24                 CPT result = null;
25                 
26                 CollectionSpaceClient client = getClientInstance();
27                 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
28                 if (payloadInputPart != null) {
29                         result = (CPT) payloadInputPart.getBody();
30                 }
31                 Assert.assertNotNull(result,
32                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
33                 
34                 return result;
35         }
36         
37     protected void printList(String testName, CLT list) {
38         if (getLogger().isDebugEnabled()){
39                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
40         }
41     }
42     
43     @Override
44     protected long getSizeOfList(CLT list) {
45         return list.getTotalItems();            
46     }
47     
48     /**
49      * The entity type expected from the JAX-RS Response object
50      */
51     public Class<String> getEntityResponseType() {
52         return String.class;
53     }
54         
55         @Override
56     public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
57         CPT result = null;
58         
59         CollectionSpaceClient client = getClientInstance();
60         PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
61         if (payloadOutputPart != null) {
62                 result = (CPT) payloadOutputPart.getBody();
63         }
64         Assert.assertNotNull(result,
65                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
66         
67         return result;
68     }
69                 
70         @Override
71         public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
72                 PoxPayloadOut result = null;
73                 
74                 CollectionSpaceClient client = this.getClientInstance();
75         PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
76         PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
77         result = payloadOut;
78                 
79                 return result;
80         }
81     
82     protected PayloadInputPart extractPart(Response res, String partLabel)
83             throws Exception {
84             if (getLogger().isDebugEnabled()) {
85                 getLogger().debug("Reading part " + partLabel + " ...");
86             }
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;
92     }
93 }