]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
5d228ee662798e283cd18c41e434fbd972ecdbc9
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.client.test;
2
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;
10
11 import org.jboss.resteasy.client.ClientResponse;
12 import org.testng.Assert;
13
14 /*
15  * <CLT> - Common list type
16  * <CPT> - Common part type
17  */
18 public abstract class AbstractPoxServiceTestImpl<CLT extends AbstractCommonList, CPT>
19                 extends AbstractServiceTestImpl<CLT, CPT, PoxPayloadOut, String> {
20                 
21         @Override
22         public CPT extractCommonPartValue(ClientResponse<String> res) throws Exception {
23                 CPT result = null;
24                 
25                 CollectionSpaceClient client = getClientInstance();
26                 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
27                 if (payloadInputPart != null) {
28                         result = (CPT) payloadInputPart.getBody();
29                 }
30                 Assert.assertNotNull(result,
31                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
32                 
33                 return result;
34         }
35         
36     protected void printList(String testName, CLT list) {
37         if (getLogger().isTraceEnabled()){
38                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
39         }
40     }
41         
42         @Override
43     public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception {
44         CPT result = null;
45         
46         CollectionSpaceClient client = getClientInstance();
47         PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName());
48         if (payloadOutputPart != null) {
49                 result = (CPT) payloadOutputPart.getBody();
50         }
51         Assert.assertNotNull(result,
52                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
53         
54         return result;
55     }   
56         
57         @Override
58         public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) {
59                 PoxPayloadOut result = null;
60                 
61                 CollectionSpaceClient client = this.getClientInstance();
62         PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent());
63         PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance);
64         result = payloadOut;
65                 
66                 return result;
67         }
68     
69     protected PayloadInputPart extractPart(ClientResponse<String> res, String partLabel)
70             throws Exception {
71             if (getLogger().isDebugEnabled()) {
72                 getLogger().debug("Reading part " + partLabel + " ...");
73             }
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;
79     }
80 }