]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1e0d806354c154a0a4936d6f3884f6442bae8145
[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.jboss.resteasy.plugins.providers.multipart.MultipartInput;
44 //import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
45 //import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
46 import org.testng.Assert;
47 //import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
49
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53 /**
54  * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
55  * IntakeServiceTest, carries out tests against a
56  * deployed and running Intake Service.
57  *
58  * $LastChangedRevision$
59  * $LastChangedDate$
60  */
61 public class IntakeServiceTest extends AbstractServiceTestImpl {
62    /** The logger. */
63     private final String CLASS_NAME = IntakeServiceTest.class.getName();
64     private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class);
65     
66     /** The known resource id. */
67     private String knownResourceId = null;
68     
69     @Override
70     protected CollectionSpaceClient getClientInstance() {
71         return new IntakeClient();
72     }
73     
74         @Override
75         protected String getServiceName() {
76                 return IntakeClient.SERVICE_NAME;
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(AbstractCommonList.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         PoxPayloadOut multipart = createInstance(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<String> 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         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
303         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
304         IntakesCommon intakeCommons = null;
305         if (payloadInputPart != null) {
306                 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
307         }
308 //        IntakesCommon intake = (IntakesCommon) extractPart(input,
309 //                client.getCommonPartName(), IntakesCommon.class);
310         Assert.assertNotNull(intakeCommons);
311
312         // Verify the number and contents of values in repeatable fields,
313         // as created in the instance record used for testing.
314         List<String> entryMethods =
315                 intakeCommons.getEntryMethods().getEntryMethod();
316         Assert.assertTrue(entryMethods.size() > 0);
317         Assert.assertNotNull(entryMethods.get(0));
318
319         List<String> fieldCollectionEventNames =
320                 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
321         Assert.assertTrue(fieldCollectionEventNames.size() > 0);
322         Assert.assertNotNull(fieldCollectionEventNames.get(0));
323
324         CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
325         Assert.assertNotNull(currentLocationGroupList);
326         List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
327         Assert.assertNotNull(currentLocationGroups);
328         Assert.assertTrue(currentLocationGroups.size() > 0);
329         CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
330         Assert.assertNotNull(currentLocationGroup);
331         Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
332
333         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
334         if(logger.isDebugEnabled()){
335             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
336                     + "UTF-8 data received=" + intakeCommons.getEntryNote());
337     }
338         Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
339                 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
340                 + "' does not match expected data '" + getUTF8DataFragment());
341     }
342
343     // Failure outcomes
344     /* (non-Javadoc)
345      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
346      */
347     @Override
348     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349         dependsOnMethods = {"read"})
350     public void readNonExistent(String testName) throws Exception {
351
352         if (logger.isDebugEnabled()) {
353             logger.debug(testBanner(testName, CLASS_NAME));
354         }
355         // Perform setup.
356         setupReadNonExistent();
357
358         // Submit the request to the service and store the response.
359         IntakeClient client = new IntakeClient();
360         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
361         int statusCode = res.getStatus();
362
363         // Check the status code of the response: does it match
364         // the expected response(s)?
365         if(logger.isDebugEnabled()){
366             logger.debug(testName + ": status = " + statusCode);
367         }
368         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
369                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
370         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
371     }
372
373     // ---------------------------------------------------------------
374     // CRUD tests : READ_LIST tests
375     // ---------------------------------------------------------------
376     // Success outcomes
377     /* (non-Javadoc)
378      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
379      */
380     @Override
381     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
382         dependsOnMethods = {"createList", "read"})
383     public void readList(String testName) throws Exception {
384
385         if (logger.isDebugEnabled()) {
386             logger.debug(testBanner(testName, CLASS_NAME));
387         }
388         // Perform setup.
389         setupReadList();
390
391         // Submit the request to the service and store the response.
392         IntakeClient client = new IntakeClient();
393         ClientResponse<AbstractCommonList> res = client.readList();
394         AbstractCommonList list = res.getEntity();
395         int statusCode = res.getStatus();
396
397         // Check the status code of the response: does it match
398         // the expected response(s)?
399         if(logger.isDebugEnabled()){
400             logger.debug(testName + ": status = " + statusCode);
401         }
402         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
403                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
404         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
405
406         // Optionally output additional data about list members for debugging.
407         boolean iterateThroughList = false;
408         if(iterateThroughList && logger.isDebugEnabled()){
409             List<AbstractCommonList.ListItem> items =
410                     list.getListItem();
411             int i = 0;
412             for(AbstractCommonList.ListItem item : items){
413                 logger.debug(testName + ": list-item[" + i + "] " +
414                         item.toString());
415                 i++;
416             }
417         }
418
419     }
420
421     // Failure outcomes
422     // None at present.
423     // ---------------------------------------------------------------
424     // CRUD tests : UPDATE tests
425     // ---------------------------------------------------------------
426     // Success outcomes
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     // See Issue CSPACE-401.
535     /* (non-Javadoc)
536      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
537      */
538     @Override
539     public void updateWithEmptyEntityBody(String testName) throws Exception {
540         //Should this really be empty?
541     }
542     
543     /* (non-Javadoc)
544      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
545      */
546     @Override
547     public void updateWithMalformedXml(String testName) throws Exception {
548         //Should this really be empty?
549     }
550     
551     /* (non-Javadoc)
552      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
553      */
554     @Override
555     public void updateWithWrongXmlSchema(String testName) throws Exception {
556         //Should this really be empty?
557     }
558
559     /*
560     @Override
561     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
562         dependsOnMethods = {"create", "update", "testSubmitRequest"})
563     public void updateWithEmptyEntityBody(String testName) throws Exception {
564
565         if (logger.isDebugEnabled()) {
566             logger.debug(testBanner(testName, CLASS_NAME));
567         }
568         // Perform setup.
569         setupUpdateWithEmptyEntityBody();
570
571         // Submit the request to the service and store the response.
572         String method = REQUEST_TYPE.httpMethodName();
573         String url = getResourceURL(knownResourceId);
574         String mediaType = MediaType.APPLICATION_XML;
575         final String entity = "";
576         int statusCode = submitRequest(method, url, mediaType, entity);
577
578         // Check the status code of the response: does it match
579         // the expected response(s)?
580         if(logger.isDebugEnabled()){
581             logger.debug(testName + ": url=" + url +
582                 " status=" + statusCode);
583          }
584         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
587     }
588
589     @Override
590     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
591         dependsOnMethods = {"create", "update", "testSubmitRequest"})
592     public void updateWithMalformedXml(String testName) throws Exception {
593
594         if (logger.isDebugEnabled()) {
595             logger.debug(testBanner(testName, CLASS_NAME));
596         }
597         // Perform setup.
598         setupUpdateWithMalformedXml();
599
600         // Submit the request to the service and store the response.
601         String method = REQUEST_TYPE.httpMethodName();
602         String url = getResourceURL(knownResourceId);
603         String mediaType = MediaType.APPLICATION_XML;
604         final String entity = MALFORMED_XML_DATA;
605         int statusCode = submitRequest(method, url, mediaType, entity);
606
607         // Check the status code of the response: does it match
608         // the expected response(s)?
609         if(logger.isDebugEnabled()){
610             logger.debug(testName + ": url=" + url +
611              " status=" + statusCode);
612          }
613         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
616     }
617
618     @Override
619     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
620         dependsOnMethods = {"create", "update", "testSubmitRequest"})
621     public void updateWithWrongXmlSchema(String testName) throws Exception {
622
623         if (logger.isDebugEnabled()) {
624             logger.debug(testBanner(testName, CLASS_NAME));
625         }
626         // Perform setup.
627         setupUpdateWithWrongXmlSchema();
628
629         // Submit the request to the service and store the response.
630         String method = REQUEST_TYPE.httpMethodName();
631         String url = getResourceURL(knownResourceId);
632         String mediaType = MediaType.APPLICATION_XML;
633         final String entity = WRONG_XML_SCHEMA_DATA;
634         int statusCode = submitRequest(method, url, mediaType, entity);
635
636         // Check the status code of the response: does it match
637         // the expected response(s)?
638         if(logger.isDebugEnabled()){
639             logger.debug(testName + ": url=" + url +
640             " status=" + statusCode);
641          }
642         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
645     }
646      */
647
648     /* (non-Javadoc)
649      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
650      */
651     @Override
652     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
653         dependsOnMethods = {"update", "testSubmitRequest"})
654     public void updateNonExistent(String testName) throws Exception {
655
656         if (logger.isDebugEnabled()) {
657             logger.debug(testBanner(testName, CLASS_NAME));
658         }
659         // Perform setup.
660         setupUpdateNonExistent();
661
662         // Submit the request to the service and store the response.
663         // Note: The ID used in this 'create' call may be arbitrary.
664         // The only relevant ID may be the one used in update(), below.
665         IntakeClient client = new IntakeClient();
666         PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
667         ClientResponse<String> res =
668                 client.update(NON_EXISTENT_ID, multipart);
669         int statusCode = res.getStatus();
670
671         // Check the status code of the response: does it match
672         // the expected response(s)?
673         if(logger.isDebugEnabled()){
674             logger.debug(testName + ": status = " + statusCode);
675         }
676         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
677                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
678         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679     }
680
681     // ---------------------------------------------------------------
682     // CRUD tests : DELETE tests
683     // ---------------------------------------------------------------
684     // Success outcomes
685     /* (non-Javadoc)
686      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
687      */
688     @Override
689     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
690         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
691     public void delete(String testName) throws Exception {
692
693         if (logger.isDebugEnabled()) {
694             logger.debug(testBanner(testName, CLASS_NAME));
695         }
696         // Perform setup.
697         setupDelete();
698
699         // Submit the request to the service and store the response.
700         IntakeClient client = new IntakeClient();
701         ClientResponse<Response> res = client.delete(knownResourceId);
702         int statusCode = res.getStatus();
703
704         // Check the status code of the response: does it match
705         // the expected response(s)?
706         if(logger.isDebugEnabled()){
707             logger.debug(testName + ": status = " + statusCode);
708         }
709         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
710                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
711         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712     }
713     
714     // Failure outcomes
715     /* (non-Javadoc)
716      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
717      */
718     @Override
719     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
720         dependsOnMethods = {"delete"})
721     public void deleteNonExistent(String testName) throws Exception {
722
723         if (logger.isDebugEnabled()) {
724             logger.debug(testBanner(testName, CLASS_NAME));
725         }
726         // Perform setup.
727         setupDeleteNonExistent();
728
729         // Submit the request to the service and store the response.
730         IntakeClient client = new IntakeClient();
731         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
732         int statusCode = res.getStatus();
733
734         // Check the status code of the response: does it match
735         // the expected response(s)?
736         if(logger.isDebugEnabled()){
737             logger.debug(testName + ": status = " + statusCode);
738         }
739         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
742     }
743
744     // ---------------------------------------------------------------
745     // Utility tests : tests of code used in tests above
746     // ---------------------------------------------------------------
747     /**
748      * Tests the code for manually submitting data that is used by several
749      * of the methods above.
750      */
751     @Test(dependsOnMethods = {"create", "read"})
752     public void testSubmitRequest() {
753
754         // Expected status code: 200 OK
755         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
756
757         // Submit the request to the service and store the response.
758         String method = ServiceRequestType.READ.httpMethodName();
759         String url = getResourceURL(knownResourceId);
760         int statusCode = submitRequest(method, url);
761
762         // Check the status code of the response: does it match
763         // the expected response(s)?
764         if(logger.isDebugEnabled()){
765             logger.debug("testSubmitRequest: url=" + url +
766                 " status=" + statusCode);
767         }
768         Assert.assertEquals(statusCode, EXPECTED_STATUS);
769
770     }
771
772     // ---------------------------------------------------------------
773     // Utility methods used by tests above
774     // ---------------------------------------------------------------
775     /* (non-Javadoc)
776      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
777      */
778     @Override
779     public String getServicePathComponent() {
780         return IntakeClient.SERVICE_PATH_COMPONENT;
781     }
782
783     /**
784      * Creates the intake instance.
785      *
786      * @param identifier the identifier
787      * @return the multipart output
788      */
789     @Override
790     protected PoxPayloadOut createInstance(String identifier) {
791         return createIntakeInstance(
792                 "entryNumber-" + identifier,
793                 "entryDate-" + identifier,
794                 "depositor-" + identifier);
795     }
796
797     /**
798      * Creates the intake instance.
799      *
800      * @param entryNumber the entry number
801      * @param entryDate the entry date
802      * @param depositor the depositor
803      * @return the multipart output
804      */
805     private PoxPayloadOut createIntakeInstance(String entryNumber,
806                 String entryDate,
807                 String depositor) {
808         IntakesCommon intake = new IntakesCommon();
809         intake.setEntryNumber(entryNumber);
810         intake.setEntryDate(entryDate);
811         intake.setDepositor(depositor);
812
813         EntryMethodList entryMethodsList = new EntryMethodList();
814         List<String> entryMethods = entryMethodsList.getEntryMethod();
815         entryMethods.add("Left at doorstep");
816         entryMethods.add("Received via post");
817         intake.setEntryMethods(entryMethodsList);
818
819         FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
820         List<String> eventNames = eventNamesList.getFieldCollectionEventName();
821         // FIXME Use properly formatted refNames for representative event names
822         // in this example test record. The following are mere placeholders.
823         eventNames.add("Field Collection Event Name-1");
824         eventNames.add("Field Collection Event Name-2");
825         intake.setFieldCollectionEventNames(eventNamesList);
826
827         CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
828         List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
829         CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
830         currentLocationGroup.setCurrentLocation("upstairs");
831         currentLocationGroup.setCurrentLocationFitness("suitable");
832         currentLocationGroup.setCurrentLocationNote("A most suitable location.");
833         currentLocationGroups.add(currentLocationGroup);
834         intake.setCurrentLocationGroupList(currentLocationGroupList);
835
836         intake.setEntryNote(getUTF8DataFragment());
837
838         PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
839         PayloadOutputPart commonPart =
840             multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
841         commonPart.setLabel(new IntakeClient().getCommonPartName());
842
843         if(logger.isDebugEnabled()){
844             logger.debug("to be created, intake common");
845             logger.debug(objectAsXmlString(intake, IntakesCommon.class));
846         }
847
848         return multipart;
849     }
850
851 }