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