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