]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ce50a7b9b245c10d300a3e7cdded64a6b4a769f5
[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 java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28
29 import org.collectionspace.services.client.AbstractCommonListUtils;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoanoutClient;
32 import org.collectionspace.services.client.PayloadInputPart;
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.common.api.GregorianCalendarDateTimeUtils;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.loanout.LoanStatusGroup;
39 import org.collectionspace.services.loanout.LoanStatusGroupList;
40 import org.collectionspace.services.loanout.LoansoutCommon;
41
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.testng.Assert;
45
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49 /**
50  * LoanoutServiceTest, carries out tests against a
51  * deployed and running Loanout (aka Loans Out) Service.
52  *
53  * $LastChangedRevision$
54  * $LastChangedDate$
55  */
56 public class LoanoutServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, LoansoutCommon> {
57
58     /** The logger. */
59     private final String CLASS_NAME = LoanoutServiceTest.class.getName();
60     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61     /** The known resource id. */
62     private final static String CURRENT_DATE_UTC =
63         GregorianCalendarDateTimeUtils.currentDateUTC();
64
65     /* (non-Javadoc)
66      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
67      */
68     @Override
69     protected CollectionSpaceClient getClientInstance() {
70         return new LoanoutClient();
71     }
72
73     /* (non-Javadoc)
74      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
75      */
76     @Override
77     protected AbstractCommonList getCommonList(
78             ClientResponse<AbstractCommonList> response) {
79         return response.getEntity(AbstractCommonList.class);
80     }
81
82     // ---------------------------------------------------------------
83     // CRUD tests : CREATE tests
84     // ---------------------------------------------------------------
85     // Success outcomes
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
88      */
89     @Override
90 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
91     public void create(String testName) throws Exception {
92         // Perform setup, such as initializing the type of service request
93         // (e.g. CREATE, DELETE), its valid and expected status codes, and
94         // its associated HTTP method name (e.g. POST, DELETE).
95         setupCreate();
96
97         // Submit the request to the service and store the response.
98         LoanoutClient client = new LoanoutClient();
99         String identifier = createIdentifier();
100         PoxPayloadOut multipart = createLoanoutInstance(identifier);
101         ClientResponse<Response> res = client.create(multipart);
102
103         int statusCode = res.getStatus();
104
105         // Check the status code of the response: does it match
106         // the expected response(s)?
107         //
108         // Specifically:
109         // Does it fall within the set of valid status codes?
110         // Does it exactly match the expected status code?
111         if (logger.isDebugEnabled()) {
112             logger.debug(testName + ": status = " + statusCode);
113         }
114         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
115                 invalidStatusCodeMessage(testRequestType, statusCode));
116         Assert.assertEquals(statusCode, testExpectedStatusCode);
117
118         // Store the ID returned from the first resource created
119         // for additional tests below.
120         if (knownResourceId == null) {
121             knownResourceId = extractId(res);
122             if (logger.isDebugEnabled()) {
123                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
124             }
125         }
126
127         // Store the IDs from every resource created by tests,
128         // so they can be deleted after tests have been run.
129         allResourceIdsCreated.add(extractId(res));
130     }
131
132     /* (non-Javadoc)
133      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
134      */
135     @Override
136 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
137 //    dependsOnMethods = {"create"})
138     public void createList(String testName) throws Exception {
139         for (int i = 0; i < 3; i++) {
140             create(testName);
141         }
142     }
143
144     // Failure outcomes
145     // Placeholders until the three tests below can be uncommented.
146     // See Issue CSPACE-401.
147     /* (non-Javadoc)
148      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
149      */
150     @Override
151     public void createWithEmptyEntityBody(String testName) throws Exception {
152         //Should this really be empty?
153     }
154
155     /* (non-Javadoc)
156      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
157      */
158     @Override
159     public void createWithMalformedXml(String testName) throws Exception {
160         //Should this really be empty?
161     }
162
163     /* (non-Javadoc)
164      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
165      */
166     @Override
167     public void createWithWrongXmlSchema(String testName) throws Exception {
168         //Should this really be empty?
169     }
170
171     /*
172     @Override
173     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
174     dependsOnMethods = {"create", "testSubmitRequest"})
175     public void createWithEmptyEntityBody(String testName) throws Exception {
176
177     if (logger.isDebugEnabled()) {
178     logger.debug(testBanner(testName, CLASS_NAME));
179     }
180     // Perform setup.
181     setupCreateWithEmptyEntityBody();
182
183     // Submit the request to the service and store the response.
184     String method = REQUEST_TYPE.httpMethodName();
185     String url = getServiceRootURL();
186     String mediaType = MediaType.APPLICATION_XML;
187     final String entity = "";
188     int statusCode = submitRequest(method, url, mediaType, entity);
189
190     // Check the status code of the response: does it match
191     // the expected response(s)?
192     if(logger.isDebugEnabled()){
193     logger.debug("createWithEmptyEntityBody url=" + url +
194     " status=" + statusCode);
195     }
196     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
197     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
198     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
199     }
200
201     @Override
202     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
203     dependsOnMethods = {"create", "testSubmitRequest"})
204     public void createWithMalformedXml(String testName) throws Exception {
205
206     if (logger.isDebugEnabled()) {
207     logger.debug(testBanner(testName, CLASS_NAME));
208     }
209     // Perform setup.
210     setupCreateWithMalformedXml();
211
212     // Submit the request to the service and store the response.
213     String method = REQUEST_TYPE.httpMethodName();
214     String url = getServiceRootURL();
215     String mediaType = MediaType.APPLICATION_XML;
216     final String entity = MALFORMED_XML_DATA; // Constant from base class.
217     int statusCode = submitRequest(method, url, mediaType, entity);
218
219     // Check the status code of the response: does it match
220     // the expected response(s)?
221     if(logger.isDebugEnabled()){
222     logger.debug(testName + ": url=" + url +
223     " status=" + statusCode);
224     }
225     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
226     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
227     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
228     }
229
230     @Override
231     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
232     dependsOnMethods = {"create", "testSubmitRequest"})
233     public void createWithWrongXmlSchema(String testName) throws Exception {
234
235     if (logger.isDebugEnabled()) {
236     logger.debug(testBanner(testName, CLASS_NAME));
237     }
238     // Perform setup.
239     setupCreateWithWrongXmlSchema();
240
241     // Submit the request to the service and store the response.
242     String method = REQUEST_TYPE.httpMethodName();
243     String url = getServiceRootURL();
244     String mediaType = MediaType.APPLICATION_XML;
245     final String entity = WRONG_XML_SCHEMA_DATA;
246     int statusCode = submitRequest(method, url, mediaType, entity);
247
248     // Check the status code of the response: does it match
249     // the expected response(s)?
250     if(logger.isDebugEnabled()){
251     logger.debug(testName + ": url=" + url +
252     " status=" + statusCode);
253     }
254     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
255     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
256     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
257     }
258      */
259     // ---------------------------------------------------------------
260     // CRUD tests : READ tests
261     // ---------------------------------------------------------------
262     // Success outcomes
263     /* (non-Javadoc)
264      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
265      */
266     @Override
267 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268 //    dependsOnMethods = {"create"})
269     public void read(String testName) throws Exception {
270         // Perform setup.
271         setupRead();
272
273         // Submit the request to the service and store the response.
274         LoanoutClient client = new LoanoutClient();
275         ClientResponse<String> res = client.read(knownResourceId);
276         LoansoutCommon loanoutCommon = null;
277         try {
278                 assertStatusCode(res, testName);
279                 // Get the common part of the response and verify that it is not null.
280                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
281                 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
282                 if (payloadInputPart != null) {
283                     loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
284                 }
285                 Assert.assertNotNull(loanoutCommon);
286         } finally {
287                 if (res != null) {
288                 res.releaseConnection();
289             }
290         }
291
292         // Check selected fields in the common part.
293         Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
294
295         LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
296         Assert.assertNotNull(statusGroupList);
297         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
298         Assert.assertNotNull(statusGroups);
299         Assert.assertTrue(statusGroups.size() > 0);
300         LoanStatusGroup statusGroup = statusGroups.get(0);
301         Assert.assertNotNull(statusGroup);
302         Assert.assertNotNull(statusGroup.getLoanStatus());
303
304         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
305         if (logger.isDebugEnabled()) {
306             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
307                     + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
308         }
309         Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
310                 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
311                 + "' does not match expected data '" + getUTF8DataFragment());
312     }
313
314     // Failure outcomes
315     /* (non-Javadoc)
316      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
317      */
318     @Override
319 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
320 //    dependsOnMethods = {"read"})
321     public void readNonExistent(String testName) throws Exception {
322         // Perform setup.
323         setupReadNonExistent();
324
325         // Submit the request to the service and store the response.
326         LoanoutClient client = new LoanoutClient();
327         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
328         int statusCode = res.getStatus();
329
330         // Check the status code of the response: does it match
331         // the expected response(s)?
332         if (logger.isDebugEnabled()) {
333             logger.debug(testName + ": status = " + statusCode);
334         }
335         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
336                 invalidStatusCodeMessage(testRequestType, statusCode));
337         Assert.assertEquals(statusCode, testExpectedStatusCode);
338     }
339
340     // ---------------------------------------------------------------
341     // CRUD tests : READ_LIST tests
342     // ---------------------------------------------------------------
343     // Success outcomes
344     /* (non-Javadoc)
345      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
346      */
347     @Override
348 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
349 //    dependsOnMethods = {"createList", "read"})
350     public void readList(String testName) throws Exception {
351         // Perform setup.
352         setupReadList();
353
354         // Submit the request to the service and store the response.
355         LoanoutClient client = new LoanoutClient();
356         ClientResponse<AbstractCommonList> res = client.readList();
357         AbstractCommonList list = null;
358         try {
359                 assertStatusCode(res, testName);
360                 list = res.getEntity();
361         } finally {
362                 if (res != null) {
363                 res.releaseConnection();
364             }
365         }
366         // Optionally output additional data about list members for debugging.
367         boolean iterateThroughList = true;
368         if (iterateThroughList && logger.isDebugEnabled()){
369                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
370         }
371
372     }
373
374     // Failure outcomes
375     // None at present.
376     // ---------------------------------------------------------------
377     // CRUD tests : UPDATE tests
378     // ---------------------------------------------------------------
379     // Success outcomes
380     /* (non-Javadoc)
381      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
382      */
383     @Override
384 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385 //    dependsOnMethods = {"read"})
386     public void update(String testName) throws Exception {
387         // Perform setup.
388         setupRead();
389
390         // Retrieve the contents of a resource to update.
391         LoanoutClient client = new LoanoutClient();
392         ClientResponse<String> res = client.read(knownResourceId);
393         LoansoutCommon loanoutCommon = null;
394         try {
395                 assertStatusCode(res, testName);
396                 // Extract the common part from the response.
397                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
398                 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
399                 if (payloadInputPart != null) {
400                     loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
401                 }
402                 Assert.assertNotNull(loanoutCommon);
403         } finally {
404                 if (res != null) {
405                 res.releaseConnection();
406             }
407         }
408
409         // Update the content of this resource.
410         loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
411         LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
412         Assert.assertNotNull(statusGroupList);
413         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
414         Assert.assertNotNull(statusGroups);
415         Assert.assertTrue(statusGroups.size() > 0);
416         LoanStatusGroup statusGroup = statusGroups.get(0);
417         Assert.assertNotNull(statusGroup);
418         String loanStatus = statusGroup.getLoanStatus();
419         Assert.assertNotNull(loanStatus);
420         String updatedLoanStatus = "updated-" + loanStatus;
421         statusGroups.get(0).setLoanStatus(updatedLoanStatus);
422         loanoutCommon.setLoanStatusGroupList(statusGroupList);
423         if (logger.isDebugEnabled()) {
424             logger.debug("to be updated object");
425             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
426         }
427         loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
428
429         setupUpdate();
430         
431         // Submit the updated resource in an update request to the service and store the response.
432         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
433         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon);
434
435         res = client.update(knownResourceId, output);
436         LoansoutCommon updatedLoanoutCommon = null;
437         try {
438                 assertStatusCode(res, testName);
439                 // Extract the updated common part from the response.
440                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
441                 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
442                 if (payloadInputPart != null) {
443                     updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
444                 }
445                 Assert.assertNotNull(updatedLoanoutCommon);
446         } finally {
447                 if (res != null) {
448                 res.releaseConnection();
449             }
450         }
451
452         // Check selected fields in the updated resource.
453         Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
454                 loanoutCommon.getLoanOutNumber(),
455                 "Data in updated object did not match submitted data.");
456
457         LoanStatusGroupList updatedStatusGroupList =
458                 updatedLoanoutCommon.getLoanStatusGroupList();
459         Assert.assertNotNull(updatedStatusGroupList);
460         List<LoanStatusGroup> updatedStatusGroups =
461                 updatedStatusGroupList.getLoanStatusGroup();
462         Assert.assertNotNull(updatedStatusGroups);
463         Assert.assertTrue(updatedStatusGroups.size() > 0);
464         Assert.assertNotNull(updatedStatusGroups.get(0));
465         Assert.assertEquals(updatedLoanStatus,
466                 updatedStatusGroups.get(0).getLoanStatus(),
467                 "Data in updated object did not match submitted data.");
468
469         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
470         if (logger.isDebugEnabled()) {
471             logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
472                     + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
473         }
474         Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
475                 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
476                 + "' does not contain expected data '" + getUTF8DataFragment());
477         Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
478                 loanoutCommon.getLoanOutNote(),
479                 "Data in updated object did not match submitted data.");
480     }
481
482     // Failure outcomes
483     // Placeholders until the three tests below can be uncommented.
484     // See Issue CSPACE-401.
485     /* (non-Javadoc)
486      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
487      */
488     @Override
489     public void updateWithEmptyEntityBody(String testName) throws Exception {
490         //Should this really be empty?
491     }
492
493     /* (non-Javadoc)
494      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
495      */
496     @Override
497     public void updateWithMalformedXml(String testName) throws Exception {
498         //Should this really be empty?
499     }
500
501     /* (non-Javadoc)
502      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
503      */
504     @Override
505     public void updateWithWrongXmlSchema(String testName) throws Exception {
506         //Should this really be empty?
507     }
508
509     /*
510     @Override
511     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
512     dependsOnMethods = {"create", "update", "testSubmitRequest"})
513     public void updateWithEmptyEntityBody(String testName) throws Exception {
514
515     if (logger.isDebugEnabled()) {
516     logger.debug(testBanner(testName, CLASS_NAME));
517     }
518     // Perform setup.
519     setupUpdateWithEmptyEntityBody();
520
521     // Submit the request to the service and store the response.
522     String method = REQUEST_TYPE.httpMethodName();
523     String url = getResourceURL(knownResourceId);
524     String mediaType = MediaType.APPLICATION_XML;
525     final String entity = "";
526     int statusCode = submitRequest(method, url, mediaType, entity);
527
528     // Check the status code of the response: does it match
529     // the expected response(s)?
530     if(logger.isDebugEnabled()){
531     logger.debug(testName + ": url=" + url +
532     " status=" + statusCode);
533     }
534     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
535     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
536     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
537     }
538
539     @Override
540     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
541     dependsOnMethods = {"create", "update", "testSubmitRequest"})
542     public void updateWithMalformedXml(String testName) throws Exception {
543
544     if (logger.isDebugEnabled()) {
545     logger.debug(testBanner(testName, CLASS_NAME));
546     }
547     // Perform setup.
548     setupUpdateWithMalformedXml();
549
550     // Submit the request to the service and store the response.
551     String method = REQUEST_TYPE.httpMethodName();
552     String url = getResourceURL(knownResourceId);
553     String mediaType = MediaType.APPLICATION_XML;
554     final String entity = MALFORMED_XML_DATA;
555     int statusCode = submitRequest(method, url, mediaType, entity);
556
557     // Check the status code of the response: does it match
558     // the expected response(s)?
559     if(logger.isDebugEnabled()){
560     logger.debug(testName + ": url=" + url +
561     " status=" + statusCode);
562     }
563     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
564     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
565     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
566     }
567
568     @Override
569     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
570     dependsOnMethods = {"create", "update", "testSubmitRequest"})
571     public void updateWithWrongXmlSchema(String testName) throws Exception {
572
573     if (logger.isDebugEnabled()) {
574     logger.debug(testBanner(testName, CLASS_NAME));
575     }
576     // Perform setup.
577     setupUpdateWithWrongXmlSchema();
578
579     // Submit the request to the service and store the response.
580     String method = REQUEST_TYPE.httpMethodName();
581     String url = getResourceURL(knownResourceId);
582     String mediaType = MediaType.APPLICATION_XML;
583     final String entity = WRONG_XML_SCHEMA_DATA;
584     int statusCode = submitRequest(method, url, mediaType, entity);
585
586     // Check the status code of the response: does it match
587     // the expected response(s)?
588     if(logger.isDebugEnabled()){
589     logger.debug(testName + ": url=" + url +
590     " status=" + statusCode);
591     }
592     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
593     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
594     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
595     }
596      */
597
598     /* (non-Javadoc)
599      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
600      */
601     @Override
602 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
603 //    dependsOnMethods = {"update", "testSubmitRequest"})
604     public void updateNonExistent(String testName) throws Exception {
605         // Perform setup.
606         setupUpdateNonExistent();
607
608         // Submit the request to the service and store the response.
609         // Note: The ID used in this 'create' call may be arbitrary.
610         // The only relevant ID may be the one used in update(), below.
611         LoanoutClient client = new LoanoutClient();
612         PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
613         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
614         int statusCode = res.getStatus();
615
616         // Check the status code of the response: does it match
617         // the expected response(s)?
618         if (logger.isDebugEnabled()) {
619             logger.debug(testName + ": status = " + statusCode);
620         }
621         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
622                 invalidStatusCodeMessage(testRequestType, statusCode));
623         Assert.assertEquals(statusCode, testExpectedStatusCode);
624     }
625
626     // ---------------------------------------------------------------
627     // CRUD tests : DELETE tests
628     // ---------------------------------------------------------------
629     // Success outcomes
630     /* (non-Javadoc)
631      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
632      */
633     @Override
634 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
635 //    dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
636     public void delete(String testName) throws Exception {
637         // Perform setup.
638         setupDelete();
639
640         // Submit the request to the service and store the response.
641         LoanoutClient client = new LoanoutClient();
642         ClientResponse<Response> res = client.delete(knownResourceId);
643         int statusCode = res.getStatus();
644
645         // Check the status code of the response: does it match
646         // the expected response(s)?
647         if (logger.isDebugEnabled()) {
648             logger.debug(testName + ": status = " + statusCode);
649         }
650         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
651                 invalidStatusCodeMessage(testRequestType, statusCode));
652         Assert.assertEquals(statusCode, testExpectedStatusCode);
653     }
654
655     // Failure outcomes
656     /* (non-Javadoc)
657      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
658      */
659     @Override
660 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
661 //    dependsOnMethods = {"delete"})
662     public void deleteNonExistent(String testName) throws Exception {
663         // Perform setup.
664         setupDeleteNonExistent();
665
666         // Submit the request to the service and store the response.
667         LoanoutClient client = new LoanoutClient();
668         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
669         int statusCode = res.getStatus();
670
671         // Check the status code of the response: does it match
672         // the expected response(s)?
673         if (logger.isDebugEnabled()) {
674             logger.debug(testName + ": status = " + statusCode);
675         }
676         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
677                 invalidStatusCodeMessage(testRequestType, statusCode));
678         Assert.assertEquals(statusCode, testExpectedStatusCode);
679     }
680
681     // ---------------------------------------------------------------
682     // Utility tests : tests of code used in tests above
683     // ---------------------------------------------------------------
684     /**
685      * Tests the code for manually submitting data that is used by several
686      * of the methods above.
687      */
688 //    @Test(dependsOnMethods = {"create", "read"})
689     public void testSubmitRequest() {
690
691         // Expected status code: 200 OK
692         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
693
694         // Submit the request to the service and store the response.
695         String method = ServiceRequestType.READ.httpMethodName();
696         String url = getResourceURL(knownResourceId);
697         int statusCode = submitRequest(method, url);
698
699         // Check the status code of the response: does it match
700         // the expected response(s)?
701         if (logger.isDebugEnabled()) {
702             logger.debug("testSubmitRequest: url=" + url
703                     + " status=" + statusCode);
704         }
705         Assert.assertEquals(statusCode, EXPECTED_STATUS);
706
707     }
708
709     // ---------------------------------------------------------------
710     // Utility methods used by tests above
711     // ---------------------------------------------------------------
712     /* (non-Javadoc)
713      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
714      */
715     @Override
716     public String getServicePathComponent() {
717         return LoanoutClient.SERVICE_PATH_COMPONENT;
718     }
719
720     @Override
721     protected PoxPayloadOut createInstance(String identifier) {
722         return createLoanoutInstance(identifier);
723     }
724     
725     /**
726      * Creates the loanout instance.
727      *
728      * @param identifier the identifier
729      * @return the multipart output
730      */
731     private PoxPayloadOut createLoanoutInstance(String identifier) {
732         return createLoanoutInstance(
733                 "loanoutNumber-" + identifier,
734                 CURRENT_DATE_UTC);
735     }
736
737     /**
738      * Creates the loanout instance.
739      *
740      * @param loanOutNumber the loan out number
741      * @param returnDate the return date
742      * @return the multipart output
743      */
744     private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
745             String returnDate) {
746         LoansoutCommon loanoutCommon = new LoansoutCommon();
747         loanoutCommon.setLoanOutNumber(loanOutNumber);
748         loanoutCommon.setLoanReturnDate(returnDate);
749         loanoutCommon.setBorrower(
750                 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
751         loanoutCommon.setBorrowersContact(
752                 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
753         loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
754         LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
755         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
756         LoanStatusGroup statusGroup = new LoanStatusGroup();
757         statusGroup.setLoanStatus("returned");
758         statusGroup.setLoanStatusNote("Left under the front mat.");
759         statusGroups.add(statusGroup);
760         loanoutCommon.setLoanStatusGroupList(statusGroupList);
761         loanoutCommon.setLoanOutNote(getUTF8DataFragment());  // For UTF-8 tests
762
763         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
764         PayloadOutputPart commonPart =
765                 multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon);
766
767         if (logger.isDebugEnabled()) {
768             logger.debug("to be created, loanout common");
769             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
770             // logger.debug(multipart.toXML());
771         }
772
773         return multipart;
774     }
775
776     @Override
777     protected String getServiceName() {
778         return LoanoutClient.SERVICE_NAME;
779     }
780
781         @Override
782         public void CRUDTests(String testName) {
783                 // TODO Auto-generated method stub
784                 
785         }
786
787         @Override
788         protected PoxPayloadOut createInstance(String commonPartName,
789                         String identifier) {
790         PoxPayloadOut result = createLoanoutInstance(identifier);
791         return result;
792         }
793
794         @Override
795         protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) {
796                 // TODO Auto-generated method stub
797                 return null;
798         }
799
800         @Override
801         protected void compareUpdatedInstances(LoansoutCommon original,
802                         LoansoutCommon updated) throws Exception {
803                 // TODO Auto-generated method stub
804                 
805         }
806 }