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