]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
40f0f36a03ec59a99a83f3a06eeb176fa7603d1c
[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 javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27
28 import org.collectionspace.services.client.AbstractCommonListUtils;
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.PayloadInputPart;
31 import org.collectionspace.services.client.ServiceGroupClient;
32 import org.collectionspace.services.client.ServiceGroupProxy;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.collectionspace.services.servicegroup.ServicegroupsCommon;
38
39 import org.jboss.resteasy.client.ClientResponse;
40
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * ServiceGroupServiceTest, carries out tests against a deployed and running ServiceGroup Service. <p/>
49  * $LastChangedRevision:  $
50  * $LastChangedDate:  $
51  */
52 public class ServiceGroupServiceTest extends BaseServiceTest<AbstractCommonList> {
53
54     private final String CLASS_NAME = ServiceGroupServiceTest.class.getName();
55     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
56     final String SERVICE_PATH_COMPONENT = "servicegroups";
57     private String readGroupName = "procedure";
58
59     @Override
60         public String getServicePathComponent() {
61                 return ServiceGroupClient.SERVICE_PATH_COMPONENT;
62         }
63
64         @Override
65         protected String getServiceName() {
66                 return ServiceGroupClient.SERVICE_NAME;
67         }
68     
69     @Override
70     protected CollectionSpaceClient<AbstractCommonList, PoxPayloadOut, String, ServiceGroupProxy> getClientInstance() {
71         return new ServiceGroupClient();
72     }
73
74     @Override
75     protected AbstractCommonList getCommonList(ClientResponse<AbstractCommonList> response) {
76         return response.getEntity(AbstractCommonList.class);
77     }
78     
79         public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client,
80                         ClientResponse<String> res) throws Exception {
81                 
82                 ServicegroupsCommon result = null;
83                 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
84                 if (payloadInputPart != null) {
85                         result = (ServicegroupsCommon) payloadInputPart.getBody();
86                 }
87                 Assert.assertNotNull(result,
88                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
89                 
90                 return result;
91         }
92
93     protected PayloadInputPart extractPart(ClientResponse<String> res, String partLabel)
94             throws Exception {
95             if (getLogger().isDebugEnabled()) {
96                 getLogger().debug("Reading part " + partLabel + " ...");
97             }
98             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
99             PayloadInputPart payloadInputPart = input.getPart(partLabel);
100             Assert.assertNotNull(payloadInputPart,
101                     "Part " + partLabel + " was unexpectedly null.");
102             return payloadInputPart;
103     }
104
105
106     @Test(dataProvider = "testName", dependsOnMethods = {"readList"})    
107     public void read(String testName) throws Exception {
108         // Perform setup.
109         setupRead();
110
111         // Submit the request to the service and store the response.
112         CollectionSpaceClient client = this.getClientInstance();
113         ClientResponse<String> res = client.read(readGroupName);
114         int statusCode = res.getStatus();
115
116         // Check the status code of the response: does it match
117         // the expected response(s)?
118         if (logger.isDebugEnabled()) {
119             logger.debug(testName + ": status = " + statusCode);
120         }
121         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
122                 invalidStatusCodeMessage(testRequestType, statusCode));
123         Assert.assertEquals(statusCode, testExpectedStatusCode);
124
125         ServicegroupsCommon output = extractCommonPartValue(client, res);
126         Assert.assertNotNull(output);
127
128         //
129         // Now compare with the expected field values
130         //
131         Assert.assertEquals(output.getName(), readGroupName, 
132                 "Display name in updated object did not match submitted data.");
133     }
134     
135         
136     @Test(dataProvider = "testName")    
137     public void readList(String testName) throws Exception {
138         // Perform setup.
139         setupReadList();
140
141         // Submit the request to the service and store the response.
142         CollectionSpaceClient client = this.getClientInstance();
143         ClientResponse<AbstractCommonList> res = client.readList();
144         AbstractCommonList list = res.getEntity();
145         int statusCode = res.getStatus();
146
147         // Check the status code of the response: does it match
148         // the expected response(s)?
149         if (logger.isDebugEnabled()) {
150             logger.debug(testName + ": status = " + statusCode);
151         }
152         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
153                 invalidStatusCodeMessage(testRequestType, statusCode));
154         Assert.assertEquals(statusCode, testExpectedStatusCode);
155
156         // Optionally output additional data about list members for debugging.
157         boolean iterateThroughList = true;
158         if (iterateThroughList && logger.isTraceEnabled()) {
159                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);
160         }
161     }
162     
163     
164 }