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