]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b4c1abce2779298a9bf9e8c949ddb22f3f7a39cc
[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().isTraceEnabled()){
39                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
40         }
41     }
42         
43         @Override
44     public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
45         CPT result = null;
46         
47         CollectionSpaceClient client = getClientInstance();
48         PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
49         if (payloadOutputPart != null) {
50                 result = (CPT) payloadOutputPart.getBody();
51         }
52         Assert.assertNotNull(result,
53                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
54         
55         return result;
56     }   
57         
58         @Override
59         public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
60                 PoxPayloadOut result = null;
61                 
62                 CollectionSpaceClient client = this.getClientInstance();
63         PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
64         PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
65         result = payloadOut;
66                 
67                 return result;
68         }
69     
70     protected PayloadInputPart extractPart(Response res, String partLabel)
71             throws Exception {
72             if (getLogger().isDebugEnabled()) {
73                 getLogger().debug("Reading part " + partLabel + " ...");
74             }
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;
80     }
81 }