]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
055323dadd3975db4942fc156bbd980c18ccb131
[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         int statusCode = res.getStatus();
299
300         // Check the status code of the response: does it match
301         // the expected response(s)?
302         if (logger.isDebugEnabled()) {
303             logger.debug(testName + ": status = " + statusCode);
304         }
305         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
306                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
307         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
308
309         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
310         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
311         IntakesCommon intakeCommons = null;
312         if (payloadInputPart != null) {
313             intakeCommons = (IntakesCommon) payloadInputPart.getBody();
314         }
315 //        IntakesCommon intake = (IntakesCommon) extractPart(input,
316 //                client.getCommonPartName(), IntakesCommon.class);
317         Assert.assertNotNull(intakeCommons);
318
319         // Verify the number and contents of values in repeatable fields,
320         // as created in the instance record used for testing.
321         List<String> entryMethods =
322                 intakeCommons.getEntryMethods().getEntryMethod();
323         Assert.assertTrue(entryMethods.size() > 0);
324         Assert.assertNotNull(entryMethods.get(0));
325
326         List<String> fieldCollectionEventNames =
327                 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
328         Assert.assertTrue(fieldCollectionEventNames.size() > 0);
329         Assert.assertNotNull(fieldCollectionEventNames.get(0));
330
331         CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
332         Assert.assertNotNull(currentLocationGroupList);
333         List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
334         Assert.assertNotNull(currentLocationGroups);
335         Assert.assertTrue(currentLocationGroups.size() > 0);
336         CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
337         Assert.assertNotNull(currentLocationGroup);
338         Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
339
340         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
341         if (logger.isDebugEnabled()) {
342             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
343                     + "UTF-8 data received=" + intakeCommons.getEntryNote());
344         }
345         Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
346                 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
347                 + "' does not match expected data '" + getUTF8DataFragment());
348     }
349
350     // Failure outcomes
351     
352     /* (non-Javadoc)
353      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
354      */
355     @Override
356     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
357     dependsOnMethods = {"read"})
358     public void readNonExistent(String testName) throws Exception {
359
360         if (logger.isDebugEnabled()) {
361             logger.debug(testBanner(testName, CLASS_NAME));
362         }
363         // Perform setup.
364         setupReadNonExistent();
365
366         // Submit the request to the service and store the response.
367         IntakeClient client = new IntakeClient();
368         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
369         int statusCode = res.getStatus();
370
371         // Check the status code of the response: does it match
372         // the expected response(s)?
373         if (logger.isDebugEnabled()) {
374             logger.debug(testName + ": status = " + statusCode);
375         }
376         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
379     }
380
381     // ---------------------------------------------------------------
382     // CRUD tests : READ_LIST tests
383     // ---------------------------------------------------------------
384     
385     // Success outcomes
386     
387     /* (non-Javadoc)
388      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
389      */
390     @Override
391     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
392     dependsOnMethods = {"createList", "read"})
393     public void readList(String testName) throws Exception {
394
395         if (logger.isDebugEnabled()) {
396             logger.debug(testBanner(testName, CLASS_NAME));
397         }
398         // Perform setup.
399         setupReadList();
400
401         // Submit the request to the service and store the response.
402         IntakeClient client = new IntakeClient();
403         ClientResponse<AbstractCommonList> res = client.readList();
404         AbstractCommonList list = res.getEntity();
405         int statusCode = res.getStatus();
406
407         // Check the status code of the response: does it match
408         // the expected response(s)?
409         if (logger.isDebugEnabled()) {
410             logger.debug(testName + ": status = " + statusCode);
411         }
412         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
415
416         // Optionally output additional data about list members for debugging.
417         boolean iterateThroughList = true;
418         if (iterateThroughList && logger.isDebugEnabled()) {
419             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
420         }
421
422     }
423
424     // Failure outcomes
425     // None at present.
426     
427     // ---------------------------------------------------------------
428     // CRUD tests : UPDATE tests
429     // ---------------------------------------------------------------
430     
431     // Success outcomes
432     
433     /* (non-Javadoc)
434      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
435      */
436     @Override
437     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
438     dependsOnMethods = {"read"})
439     public void update(String testName) throws Exception {
440
441         if (logger.isDebugEnabled()) {
442             logger.debug(testBanner(testName, CLASS_NAME));
443         }
444         // Perform setup.
445         setupUpdate();
446
447         // Retrieve the contents of a resource to update.
448         IntakeClient client = new IntakeClient();
449         ClientResponse<String> res = client.read(knownResourceId);
450         if (logger.isDebugEnabled()) {
451             logger.debug(testName + ": read status = " + res.getStatus());
452         }
453         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
454
455         if (logger.isDebugEnabled()) {
456             logger.debug("got object to update with ID: " + knownResourceId);
457         }
458         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
459         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
460         IntakesCommon intakeCommons = null;
461         if (payloadInputPart != null) {
462             intakeCommons = (IntakesCommon) payloadInputPart.getBody();
463         }
464 //        IntakesCommon intake = (IntakesCommon) extractPart(input,
465 //                client.getCommonPartName(), IntakesCommon.class);
466         Assert.assertNotNull(intakeCommons);
467
468         // Update the content of this resource.
469         intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
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         // Create an output payload to send to the service, and add teh common part
489         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
490         PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
491         commonPart.setLabel(client.getCommonPartName());
492         
493         // Submit the request to the service and store the response.
494         res = client.update(knownResourceId, output);
495         int statusCode = res.getStatus();
496         // Check the status code of the response: does it match the expected response(s)?
497         if (logger.isDebugEnabled()) {
498             logger.debug(testName + ": status = " + statusCode);
499         }
500         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
501                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
502         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503
504         input = new PoxPayloadIn(res.getEntity());
505         IntakesCommon updatedIntake =
506                 (IntakesCommon) extractPart(input,
507                 client.getCommonPartName(), IntakesCommon.class);
508
509         Assert.assertNotNull(updatedIntake);
510
511         Assert.assertEquals(updatedIntake.getEntryNumber(),
512                 intakeCommons.getEntryNumber(),
513                 "Data in updated object did not match submitted data.");
514
515         currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
516         Assert.assertNotNull(currentLocationGroupList);
517         currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
518         Assert.assertNotNull(currentLocationGroups);
519         Assert.assertTrue(currentLocationGroups.size() > 0);
520         Assert.assertNotNull(currentLocationGroups.get(0));
521         Assert.assertEquals(updatedCurrentLocationNote,
522                 currentLocationGroups.get(0).getCurrentLocationNote(),
523                 "Data in updated object did not match submitted data.");
524
525         if (logger.isDebugEnabled()) {
526             logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
527                     + "UTF-8 data received=" + updatedIntake.getEntryNote());
528         }
529         Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
530                 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
531                 + "' does not contain expected data '" + getUTF8DataFragment());
532         Assert.assertEquals(updatedIntake.getEntryNote(),
533                 intakeCommons.getEntryNote(),
534                 "Data in updated object did not match submitted data.");
535
536     }
537
538     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
539     dependsOnMethods = {"update"})
540     public void verifyReadOnlyCoreFields(String testName) throws Exception {
541         // TODO These should be in some core client utils
542         final String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
543         final String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
544         final String COLLECTIONSPACE_CORE_URI = "uri";
545         final String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt";
546         final String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt";
547         final String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy";
548         final String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy";
549
550         if (logger.isDebugEnabled()) {
551             logger.debug(testBanner(testName, CLASS_NAME));
552         }
553         // Perform setup.
554         setupUpdate();
555
556         // Retrieve the contents of a resource to update.
557         IntakeClient client = new IntakeClient();
558         ClientResponse<String> res = client.read(knownResourceId);
559         if (logger.isDebugEnabled()) {
560             logger.debug(testName + ": read status = " + res.getStatus());
561         }
562         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
563
564         if (logger.isDebugEnabled()) {
565             logger.debug("got object to update with ID: " + knownResourceId);
566         }
567         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
568         PayloadInputPart payloadInputPart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
569         Element coreAsElement = null;
570         if (payloadInputPart != null) {
571                 coreAsElement = payloadInputPart.getElementBody();
572         }
573         Assert.assertNotNull(coreAsElement);
574         if (logger.isDebugEnabled()) {
575             logger.debug("Core part before update:");
576             logger.debug(coreAsElement.asXML());
577         }
578
579         // Update the read-only elements
580         Element tenantId = coreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
581         String originalTenantId = tenantId.getText();
582         tenantId.setText("foo");
583         Element uri = coreAsElement.element(COLLECTIONSPACE_CORE_URI);
584         String originalUri = uri.getText();
585         uri.setText("foo");
586         Element createdAt = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
587         String originalCreatedAt = createdAt.getText();
588         String now = GregorianCalendarDateTimeUtils.timestampUTC();
589         if(originalCreatedAt.equalsIgnoreCase(now) && logger.isWarnEnabled()) {
590                         logger.warn("Cannot check createdAt read-only; too fast!");
591         }
592         createdAt.setText(now);
593         Element createdBy = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
594         String originalCreatedBy = createdBy.getText();
595         createdBy.setText("foo");
596         
597         if (logger.isDebugEnabled()) {
598             logger.debug("Core part to be updated:");
599             logger.debug(coreAsElement.asXML());
600         }
601
602         // Create an output payload to send to the service, and add the common part
603         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
604         PayloadOutputPart corePart = output.addPart(
605                                                 COLLECTIONSPACE_CORE_SCHEMA, coreAsElement);
606         
607         // Submit the request to the service and store the response.
608         res = client.update(knownResourceId, output);
609         int statusCode = res.getStatus();
610         // Check the status code of the response: does it match the expected response(s)?
611         if (logger.isDebugEnabled()) {
612             logger.debug(testName + ": status = " + statusCode);
613         }
614         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617
618         input = new PoxPayloadIn(res.getEntity());
619         PayloadInputPart updatedCorePart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
620         Element updatedCoreAsElement = null;
621         if (updatedCorePart != null) {
622                 updatedCoreAsElement = updatedCorePart.getElementBody();
623         }
624         Assert.assertNotNull(updatedCoreAsElement);
625         
626         tenantId = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
627         String updatedTenantId = tenantId.getText();
628         Assert.assertEquals(updatedTenantId, originalTenantId,
629                                 "CORE part TenantID was able to update!");
630         uri = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_URI);
631         String updatedUri = uri.getText();
632         Assert.assertEquals(updatedUri, originalUri,
633                                 "CORE part URI was able to update!");
634         createdAt = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
635         String updatedCreatedAt = createdAt.getText();
636         Assert.assertEquals(updatedCreatedAt, originalCreatedAt,
637                                 "CORE part CreatedAt was able to update!");
638         createdBy = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
639         String updatedCreatedBy = createdBy.getText();
640         Assert.assertEquals(updatedCreatedBy, originalCreatedBy,
641                                 "CORE part CreatedBy was able to update!");
642
643     }
644
645     // Failure outcomes
646     // Placeholders until the three tests below can be uncommented.
647     
648     // See Issue CSPACE-401.
649     /* (non-Javadoc)
650      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
651      */
652     @Override
653     public void updateWithEmptyEntityBody(String testName) throws Exception {
654         //Should this really be empty?
655     }
656
657     /* (non-Javadoc)
658      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
659      */
660     @Override
661     public void updateWithMalformedXml(String testName) throws Exception {
662         //Should this really be empty?
663     }
664
665     /* (non-Javadoc)
666      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
667      */
668     @Override
669     public void updateWithWrongXmlSchema(String testName) throws Exception {
670         //Should this really be empty?
671     }
672
673     /*
674     @Override
675     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
676     dependsOnMethods = {"create", "update", "testSubmitRequest"})
677     public void updateWithEmptyEntityBody(String testName) throws Exception {
678     
679     if (logger.isDebugEnabled()) {
680     logger.debug(testBanner(testName, CLASS_NAME));
681     }
682     // Perform setup.
683     setupUpdateWithEmptyEntityBody();
684     
685     // Submit the request to the service and store the response.
686     String method = REQUEST_TYPE.httpMethodName();
687     String url = getResourceURL(knownResourceId);
688     String mediaType = MediaType.APPLICATION_XML;
689     final String entity = "";
690     int statusCode = submitRequest(method, url, mediaType, entity);
691     
692     // Check the status code of the response: does it match
693     // the expected response(s)?
694     if(logger.isDebugEnabled()){
695     logger.debug(testName + ": url=" + url +
696     " status=" + statusCode);
697     }
698     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701     }
702     
703     @Override
704     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
705     dependsOnMethods = {"create", "update", "testSubmitRequest"})
706     public void updateWithMalformedXml(String testName) throws Exception {
707     
708     if (logger.isDebugEnabled()) {
709     logger.debug(testBanner(testName, CLASS_NAME));
710     }
711     // Perform setup.
712     setupUpdateWithMalformedXml();
713     
714     // Submit the request to the service and store the response.
715     String method = REQUEST_TYPE.httpMethodName();
716     String url = getResourceURL(knownResourceId);
717     String mediaType = MediaType.APPLICATION_XML;
718     final String entity = MALFORMED_XML_DATA;
719     int statusCode = submitRequest(method, url, mediaType, entity);
720     
721     // Check the status code of the response: does it match
722     // the expected response(s)?
723     if(logger.isDebugEnabled()){
724     logger.debug(testName + ": url=" + url +
725     " status=" + statusCode);
726     }
727     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
728     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
729     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
730     }
731     
732     @Override
733     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
734     dependsOnMethods = {"create", "update", "testSubmitRequest"})
735     public void updateWithWrongXmlSchema(String testName) throws Exception {
736     
737     if (logger.isDebugEnabled()) {
738     logger.debug(testBanner(testName, CLASS_NAME));
739     }
740     // Perform setup.
741     setupUpdateWithWrongXmlSchema();
742     
743     // Submit the request to the service and store the response.
744     String method = REQUEST_TYPE.httpMethodName();
745     String url = getResourceURL(knownResourceId);
746     String mediaType = MediaType.APPLICATION_XML;
747     final String entity = WRONG_XML_SCHEMA_DATA;
748     int statusCode = submitRequest(method, url, mediaType, entity);
749     
750     // Check the status code of the response: does it match
751     // the expected response(s)?
752     if(logger.isDebugEnabled()){
753     logger.debug(testName + ": url=" + url +
754     " status=" + statusCode);
755     }
756     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
757     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
758     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
759     }
760      */
761
762     /* (non-Javadoc)
763      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
764      */
765     @Override
766     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
767     dependsOnMethods = {"update", "testSubmitRequest"})
768     public void updateNonExistent(String testName) throws Exception {
769
770         if (logger.isDebugEnabled()) {
771             logger.debug(testBanner(testName, CLASS_NAME));
772         }
773         // Perform setup.
774         setupUpdateNonExistent();
775
776         // Submit the request to the service and store the response.
777         // Note: The ID used in this 'create' call may be arbitrary.
778         // The only relevant ID may be the one used in update(), below.
779         IntakeClient client = new IntakeClient();
780         PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
781         ClientResponse<String> res =
782                 client.update(NON_EXISTENT_ID, multipart);
783         int statusCode = res.getStatus();
784
785         // Check the status code of the response: does it match
786         // the expected response(s)?
787         if (logger.isDebugEnabled()) {
788             logger.debug(testName + ": status = " + statusCode);
789         }
790         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
791                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
792         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
793     }
794
795     // ---------------------------------------------------------------
796     // CRUD tests : DELETE tests
797     // ---------------------------------------------------------------
798     
799     // Success outcomes
800     
801     /* (non-Javadoc)
802      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
803      */
804     @Override
805     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
806     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "verifyReadOnlyCoreFields"})
807     public void delete(String testName) throws Exception {
808
809         if (logger.isDebugEnabled()) {
810             logger.debug(testBanner(testName, CLASS_NAME));
811         }
812         // Perform setup.
813         setupDelete();
814
815         // Submit the request to the service and store the response.
816         IntakeClient client = new IntakeClient();
817         ClientResponse<Response> res = client.delete(knownResourceId);
818         int statusCode = res.getStatus();
819
820         // Check the status code of the response: does it match
821         // the expected response(s)?
822         if (logger.isDebugEnabled()) {
823             logger.debug(testName + ": status = " + statusCode);
824         }
825         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
826                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
827         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
828     }
829
830     // Failure outcomes
831     
832     /* (non-Javadoc)
833      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
834      */
835     @Override
836     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
837     dependsOnMethods = {"delete"})
838     public void deleteNonExistent(String testName) throws Exception {
839
840         if (logger.isDebugEnabled()) {
841             logger.debug(testBanner(testName, CLASS_NAME));
842         }
843         // Perform setup.
844         setupDeleteNonExistent();
845
846         // Submit the request to the service and store the response.
847         IntakeClient client = new IntakeClient();
848         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
849         int statusCode = res.getStatus();
850
851         // Check the status code of the response: does it match
852         // the expected response(s)?
853         if (logger.isDebugEnabled()) {
854             logger.debug(testName + ": status = " + statusCode);
855         }
856         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
857                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
858         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
859     }
860
861     // ---------------------------------------------------------------
862     // Utility tests : tests of code used in tests above
863     // ---------------------------------------------------------------
864     
865     /**
866      * Tests the code for manually submitting data that is used by several
867      * of the methods above.
868      */
869     @Test(dependsOnMethods = {"create", "read"})
870     public void testSubmitRequest() {
871
872         // Expected status code: 200 OK
873         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
874
875         // Submit the request to the service and store the response.
876         String method = ServiceRequestType.READ.httpMethodName();
877         String url = getResourceURL(knownResourceId);
878         int statusCode = submitRequest(method, url);
879
880         // Check the status code of the response: does it match
881         // the expected response(s)?
882         if (logger.isDebugEnabled()) {
883             logger.debug("testSubmitRequest: url=" + url
884                     + " status=" + statusCode);
885         }
886         Assert.assertEquals(statusCode, EXPECTED_STATUS);
887
888     }
889
890     // ---------------------------------------------------------------
891     // Utility methods used by tests above
892     // ---------------------------------------------------------------
893     
894     /* (non-Javadoc)
895      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
896      */
897     @Override
898     public String getServicePathComponent() {
899         return IntakeClient.SERVICE_PATH_COMPONENT;
900     }
901
902     /**
903      * Creates the intake instance.
904      *
905      * @param identifier the identifier
906      * @return the multipart output
907      */
908     @Override
909     protected PoxPayloadOut createInstance(String identifier) {
910         return createIntakeInstance(
911                 "entryNumber-" + identifier,
912                 CURRENT_DATE_UTC,
913                 "depositor-" + identifier);
914     }
915
916     /**
917      * Creates the intake instance.
918      *
919      * @param entryNumber the entry number
920      * @param entryDate the entry date
921      * @param depositor the depositor
922      * @return the multipart output
923      */
924     private PoxPayloadOut createIntakeInstance(String entryNumber,
925             String entryDate,
926             String depositor) {
927         IntakesCommon intake = new IntakesCommon();
928         intake.setEntryNumber(entryNumber);
929         intake.setEntryDate(entryDate);
930         intake.setDepositor(depositor);
931
932         EntryMethodList entryMethodsList = new EntryMethodList();
933         List<String> entryMethods = entryMethodsList.getEntryMethod();
934         entryMethods.add("Left at doorstep");
935         entryMethods.add("Received via post");
936         intake.setEntryMethods(entryMethodsList);
937
938         FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
939         List<String> eventNames = eventNamesList.getFieldCollectionEventName();
940         // FIXME Use properly formatted refNames for representative event names
941         // in this example test record. The following are mere placeholders.
942         eventNames.add("Field Collection Event Name-1");
943         eventNames.add("Field Collection Event Name-2");
944         intake.setFieldCollectionEventNames(eventNamesList);
945
946         CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
947         List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
948         CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
949         currentLocationGroup.setCurrentLocation("upstairs");
950         currentLocationGroup.setCurrentLocationFitness("suitable");
951         currentLocationGroup.setCurrentLocationNote("A most suitable location.");
952         currentLocationGroups.add(currentLocationGroup);
953         intake.setCurrentLocationGroupList(currentLocationGroupList);
954
955         intake.setEntryNote(getUTF8DataFragment());
956
957         PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
958         PayloadOutputPart commonPart =
959                 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
960         commonPart.setLabel(new IntakeClient().getCommonPartName());
961
962         if (logger.isDebugEnabled()) {
963             logger.debug("to be created, intake common");
964             logger.debug(objectAsXmlString(intake, IntakesCommon.class));
965         }
966
967         return multipart;
968     }
969 }