]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
067d2e5997e72b8bb326ef16416f7fe7cb3b2a99
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.client.test;
24
25 import org.collectionspace.services.client.AbstractCommonListUtils;
26 import org.collectionspace.services.client.CollectionSpaceClient;
27 import org.collectionspace.services.client.PayloadInputPart;
28 import org.collectionspace.services.client.ServiceGroupClient;
29 import org.collectionspace.services.client.ServiceGroupProxy;
30 import org.collectionspace.services.client.PoxPayloadIn;
31 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.servicegroup.ServicegroupsCommon;
34
35 import javax.ws.rs.core.Response;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * ServiceGroupServiceTest, carries out tests against a deployed and running ServiceGroup Service. <p/>
43  * $LastChangedRevision:  $
44  * $LastChangedDate:  $
45  */
46 public class ServiceGroupServiceTest extends BaseServiceTest<AbstractCommonList> {
47
48     private final String CLASS_NAME = ServiceGroupServiceTest.class.getName();
49     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
50     final String SERVICE_PATH_COMPONENT = "servicegroups";
51     private String readGroupName = "procedure";
52
53     @Override
54         public String getServicePathComponent() {
55                 return ServiceGroupClient.SERVICE_PATH_COMPONENT;
56         }
57
58         @Override
59         protected String getServiceName() {
60                 return ServiceGroupClient.SERVICE_NAME;
61         }
62     
63     @Override
64     protected CollectionSpaceClient<AbstractCommonList, PoxPayloadOut, String, ServiceGroupProxy> getClientInstance() {
65         return new ServiceGroupClient();
66     }
67
68         @Override
69         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
70         return new ServiceGroupClient(clientPropertiesFilename);
71         }
72
73     @Override
74     protected AbstractCommonList getCommonList(Response response) {
75         return response.readEntity(AbstractCommonList.class);
76     }
77     
78         public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client,
79                         Response res) throws Exception {
80                 
81                 ServicegroupsCommon result = null;
82                 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
83                 if (payloadInputPart != null) {
84                         result = (ServicegroupsCommon) payloadInputPart.getBody();
85                 }
86                 Assert.assertNotNull(result,
87                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
88                 
89                 return result;
90         }
91
92     protected PayloadInputPart extractPart(Response res, String partLabel)
93             throws Exception {
94             if (getLogger().isDebugEnabled()) {
95                 getLogger().debug("Reading part " + partLabel + " ...");
96             }
97             PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
98             PayloadInputPart payloadInputPart = input.getPart(partLabel);
99             Assert.assertNotNull(payloadInputPart,
100                     "Part " + partLabel + " was unexpectedly null.");
101             return payloadInputPart;
102     }
103
104
105     @Test(dataProvider = "testName", dependsOnMethods = {"readList"})    
106     public void read(String testName) throws Exception {
107         // Perform setup.
108         setupRead();
109
110         // Submit the request to the service and store the response.
111         CollectionSpaceClient client = this.getClientInstance();
112         Response res = client.read(readGroupName);
113         int statusCode = res.getStatus();
114
115         // Check the status code of the response: does it match
116         // the expected response(s)?
117         if (logger.isDebugEnabled()) {
118             logger.debug(testName + ": status = " + statusCode);
119         }
120         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
121                 invalidStatusCodeMessage(testRequestType, statusCode));
122         Assert.assertEquals(statusCode, testExpectedStatusCode);
123
124         ServicegroupsCommon output = extractCommonPartValue(client, res);
125         Assert.assertNotNull(output);
126
127         //
128         // Now compare with the expected field values
129         //
130         Assert.assertEquals(output.getName(), readGroupName, 
131                 "Display name in updated object did not match submitted data.");
132     }
133     
134         
135     @Test(dataProvider = "testName")    
136     public void readList(String testName) throws Exception {
137         // Perform setup.
138         setupReadList();
139
140         // Submit the request to the service and store the response.
141         CollectionSpaceClient client = this.getClientInstance();
142         Response res = client.readList();
143         AbstractCommonList list = res.readEntity(getCommonListType());
144         int statusCode;
145         try {
146                 statusCode = res.getStatus();
147         } finally {
148                 res.close();
149         }
150         
151
152         // Check the status code of the response: does it match
153         // the expected response(s)?
154         if (logger.isDebugEnabled()) {
155             logger.debug(testName + ": status = " + statusCode);
156         }
157         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
158                 invalidStatusCodeMessage(testRequestType, statusCode));
159         Assert.assertEquals(statusCode, testExpectedStatusCode);
160
161         // Optionally output additional data about list members for debugging.
162         boolean iterateThroughList = true;
163         if (iterateThroughList && logger.isTraceEnabled()) {
164                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
165         }
166     }
167 }