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