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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
25 import java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.dom4j.Element;
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;
46 import org.jboss.resteasy.client.ClientResponse;
47 import org.testng.Assert;
48 import org.testng.annotations.Test;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
53 // FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
55 * IntakeServiceTest, carries out tests against a
56 * deployed and running Intake Service.
58 * $LastChangedRevision$
61 public class IntakeServiceTest extends AbstractServiceTestImpl {
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();
72 protected CollectionSpaceClient getClientInstance() {
73 return new IntakeClient();
77 protected String getServiceName() {
78 return IntakeClient.SERVICE_NAME;
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
85 protected AbstractCommonList getAbstractCommonList(
86 ClientResponse<AbstractCommonList> response) {
87 return response.getEntity(AbstractCommonList.class);
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
97 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
101 public void create(String testName) throws Exception {
103 if (logger.isDebugEnabled()) {
104 logger.debug(testBanner(testName, CLASS_NAME));
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).
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);
117 int statusCode = res.getStatus();
119 // Check the status code of the response: does it match
120 // the expected response(s)?
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);
128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
130 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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));
147 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
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++) {
159 // Placeholders until the three tests below can be uncommented.
161 // See Issue CSPACE-401.
163 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
166 public void createWithEmptyEntityBody(String testName) throws Exception {
167 //Should this really be empty?
171 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
174 public void createWithMalformedXml(String testName) throws Exception {
175 //Should this really be empty?
179 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
182 public void createWithWrongXmlSchema(String testName) throws Exception {
183 //Should this really be empty?
188 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
189 dependsOnMethods = {"create", "testSubmitRequest"})
190 public void createWithEmptyEntityBody(String testName) throws Exception {
192 if (logger.isDebugEnabled()) {
193 logger.debug(testBanner(testName, CLASS_NAME));
196 setupCreateWithEmptyEntityBody();
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);
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);
211 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
212 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
213 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
217 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
218 dependsOnMethods = {"create", "testSubmitRequest"})
219 public void createWithMalformedXml(String testName) throws Exception {
221 if (logger.isDebugEnabled()) {
222 logger.debug(testBanner(testName, CLASS_NAME));
225 setupCreateWithMalformedXml();
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);
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);
240 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
241 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
242 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
246 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
247 dependsOnMethods = {"create", "testSubmitRequest"})
248 public void createWithWrongXmlSchema(String testName) throws Exception {
250 if (logger.isDebugEnabled()) {
251 logger.debug(testBanner(testName, CLASS_NAME));
254 setupCreateWithWrongXmlSchema(testName, logger);
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);
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);
269 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
270 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
271 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
275 // ---------------------------------------------------------------
276 // CRUD tests : READ tests
277 // ---------------------------------------------------------------
282 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
285 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
286 dependsOnMethods = {"create"})
287 public void read(String testName) throws Exception {
289 if (logger.isDebugEnabled()) {
290 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
305 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
306 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
307 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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();
315 // IntakesCommon intake = (IntakesCommon) extractPart(input,
316 // client.getCommonPartName(), IntakesCommon.class);
317 Assert.assertNotNull(intakeCommons);
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));
326 List<String> fieldCollectionEventNames =
327 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
328 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
329 Assert.assertNotNull(fieldCollectionEventNames.get(0));
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());
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());
345 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
346 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
347 + "' does not match expected data '" + getUTF8DataFragment());
353 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
356 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
357 dependsOnMethods = {"read"})
358 public void readNonExistent(String testName) throws Exception {
360 if (logger.isDebugEnabled()) {
361 logger.debug(testBanner(testName, CLASS_NAME));
364 setupReadNonExistent();
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();
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);
376 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
381 // ---------------------------------------------------------------
382 // CRUD tests : READ_LIST tests
383 // ---------------------------------------------------------------
388 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
391 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
392 dependsOnMethods = {"createList", "read"})
393 public void readList(String testName) throws Exception {
395 if (logger.isDebugEnabled()) {
396 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
412 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
427 // ---------------------------------------------------------------
428 // CRUD tests : UPDATE tests
429 // ---------------------------------------------------------------
434 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
437 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
438 dependsOnMethods = {"read"})
439 public void update(String testName) throws Exception {
441 if (logger.isDebugEnabled()) {
442 logger.debug(testBanner(testName, CLASS_NAME));
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());
453 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
455 if (logger.isDebugEnabled()) {
456 logger.debug("got object to update with ID: " + knownResourceId);
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();
464 // IntakesCommon intake = (IntakesCommon) extractPart(input,
465 // client.getCommonPartName(), IntakesCommon.class);
466 Assert.assertNotNull(intakeCommons);
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));
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);
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());
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);
500 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
501 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
502 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
504 input = new PoxPayloadIn(res.getEntity());
505 IntakesCommon updatedIntake =
506 (IntakesCommon) extractPart(input,
507 client.getCommonPartName(), IntakesCommon.class);
509 Assert.assertNotNull(updatedIntake);
511 Assert.assertEquals(updatedIntake.getEntryNumber(),
512 intakeCommons.getEntryNumber(),
513 "Data in updated object did not match submitted data.");
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.");
525 if (logger.isDebugEnabled()) {
526 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
527 + "UTF-8 data received=" + updatedIntake.getEntryNote());
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.");
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";
550 if (logger.isDebugEnabled()) {
551 logger.debug(testBanner(testName, CLASS_NAME));
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());
562 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
564 if (logger.isDebugEnabled()) {
565 logger.debug("got object to update with ID: " + knownResourceId);
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();
573 Assert.assertNotNull(coreAsElement);
574 if (logger.isDebugEnabled()) {
575 logger.debug("Core part before update:");
576 logger.debug(coreAsElement.asXML());
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();
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!");
592 createdAt.setText(now);
593 Element createdBy = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
594 String originalCreatedBy = createdBy.getText();
595 createdBy.setText("foo");
597 if (logger.isDebugEnabled()) {
598 logger.debug("Core part to be updated:");
599 logger.debug(coreAsElement.asXML());
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);
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);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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();
624 Assert.assertNotNull(updatedCoreAsElement);
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!");
646 // Placeholders until the three tests below can be uncommented.
648 // See Issue CSPACE-401.
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
653 public void updateWithEmptyEntityBody(String testName) throws Exception {
654 //Should this really be empty?
658 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
661 public void updateWithMalformedXml(String testName) throws Exception {
662 //Should this really be empty?
666 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
669 public void updateWithWrongXmlSchema(String testName) throws Exception {
670 //Should this really be empty?
675 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
676 dependsOnMethods = {"create", "update", "testSubmitRequest"})
677 public void updateWithEmptyEntityBody(String testName) throws Exception {
679 if (logger.isDebugEnabled()) {
680 logger.debug(testBanner(testName, CLASS_NAME));
683 setupUpdateWithEmptyEntityBody();
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);
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);
698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
704 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
705 dependsOnMethods = {"create", "update", "testSubmitRequest"})
706 public void updateWithMalformedXml(String testName) throws Exception {
708 if (logger.isDebugEnabled()) {
709 logger.debug(testBanner(testName, CLASS_NAME));
712 setupUpdateWithMalformedXml();
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);
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);
727 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
728 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
729 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
733 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
734 dependsOnMethods = {"create", "update", "testSubmitRequest"})
735 public void updateWithWrongXmlSchema(String testName) throws Exception {
737 if (logger.isDebugEnabled()) {
738 logger.debug(testBanner(testName, CLASS_NAME));
741 setupUpdateWithWrongXmlSchema();
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);
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);
756 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
757 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
758 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
763 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
766 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
767 dependsOnMethods = {"update", "testSubmitRequest"})
768 public void updateNonExistent(String testName) throws Exception {
770 if (logger.isDebugEnabled()) {
771 logger.debug(testBanner(testName, CLASS_NAME));
774 setupUpdateNonExistent();
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();
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);
790 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
791 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
792 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
795 // ---------------------------------------------------------------
796 // CRUD tests : DELETE tests
797 // ---------------------------------------------------------------
802 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
805 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
806 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "verifyReadOnlyCoreFields"})
807 public void delete(String testName) throws Exception {
809 if (logger.isDebugEnabled()) {
810 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
825 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
826 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
827 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
833 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
836 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
837 dependsOnMethods = {"delete"})
838 public void deleteNonExistent(String testName) throws Exception {
840 if (logger.isDebugEnabled()) {
841 logger.debug(testBanner(testName, CLASS_NAME));
844 setupDeleteNonExistent();
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();
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);
856 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
857 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
858 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
861 // ---------------------------------------------------------------
862 // Utility tests : tests of code used in tests above
863 // ---------------------------------------------------------------
866 * Tests the code for manually submitting data that is used by several
867 * of the methods above.
869 @Test(dependsOnMethods = {"create", "read"})
870 public void testSubmitRequest() {
872 // Expected status code: 200 OK
873 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
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);
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);
886 Assert.assertEquals(statusCode, EXPECTED_STATUS);
890 // ---------------------------------------------------------------
891 // Utility methods used by tests above
892 // ---------------------------------------------------------------
895 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
898 public String getServicePathComponent() {
899 return IntakeClient.SERVICE_PATH_COMPONENT;
903 * Creates the intake instance.
905 * @param identifier the identifier
906 * @return the multipart output
909 protected PoxPayloadOut createInstance(String identifier) {
910 return createIntakeInstance(
911 "entryNumber-" + identifier,
913 "depositor-" + identifier);
917 * Creates the intake instance.
919 * @param entryNumber the entry number
920 * @param entryDate the entry date
921 * @param depositor the depositor
922 * @return the multipart output
924 private PoxPayloadOut createIntakeInstance(String entryNumber,
927 IntakesCommon intake = new IntakesCommon();
928 intake.setEntryNumber(entryNumber);
929 intake.setEntryDate(entryDate);
930 intake.setDepositor(depositor);
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);
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);
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);
955 intake.setEntryNote(getUTF8DataFragment());
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());
962 if (logger.isDebugEnabled()) {
963 logger.debug("to be created, intake common");
964 logger.debug(objectAsXmlString(intake, IntakesCommon.class));