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