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;
70 protected CollectionSpaceClient getClientInstance() {
71 return new IntakeClient();
75 protected String getServiceName() {
76 return IntakeClient.SERVICE_NAME;
80 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
83 protected AbstractCommonList getAbstractCommonList(
84 ClientResponse<AbstractCommonList> response) {
85 return response.getEntity(AbstractCommonList.class);
88 // ---------------------------------------------------------------
89 // CRUD tests : CREATE tests
90 // ---------------------------------------------------------------
95 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
98 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
99 public void create(String testName) throws Exception {
101 if (logger.isDebugEnabled()) {
102 logger.debug(testBanner(testName, CLASS_NAME));
104 // Perform setup, such as initializing the type of service request
105 // (e.g. CREATE, DELETE), its valid and expected status codes, and
106 // its associated HTTP method name (e.g. POST, DELETE).
109 // Submit the request to the service and store the response.
110 IntakeClient client = new IntakeClient();
111 String identifier = createIdentifier();
112 PoxPayloadOut multipart = createInstance(identifier);
113 ClientResponse<Response> res = client.create(multipart);
115 int statusCode = res.getStatus();
117 // Check the status code of the response: does it match
118 // the expected response(s)?
121 // Does it fall within the set of valid status codes?
122 // Does it exactly match the expected status code?
123 if (logger.isDebugEnabled()) {
124 logger.debug(testName + ": status = " + statusCode);
126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
130 // Store the ID returned from the first resource created
131 // for additional tests below.
132 if (knownResourceId == null) {
133 knownResourceId = extractId(res);
134 if (logger.isDebugEnabled()) {
135 logger.debug(testName + ": knownResourceId=" + knownResourceId);
139 // Store the IDs from every resource created by tests,
140 // so they can be deleted after tests have been run.
141 allResourceIdsCreated.add(extractId(res));
145 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
148 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
149 dependsOnMethods = {"create"})
150 public void createList(String testName) throws Exception {
151 for (int i = 0; i < 3; i++) {
157 // Placeholders until the three tests below can be uncommented.
159 // See Issue CSPACE-401.
161 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
164 public void createWithEmptyEntityBody(String testName) throws Exception {
165 //Should this really be empty?
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
172 public void createWithMalformedXml(String testName) throws Exception {
173 //Should this really be empty?
177 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
180 public void createWithWrongXmlSchema(String testName) throws Exception {
181 //Should this really be empty?
186 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
187 dependsOnMethods = {"create", "testSubmitRequest"})
188 public void createWithEmptyEntityBody(String testName) throws Exception {
190 if (logger.isDebugEnabled()) {
191 logger.debug(testBanner(testName, CLASS_NAME));
194 setupCreateWithEmptyEntityBody();
196 // Submit the request to the service and store the response.
197 String method = REQUEST_TYPE.httpMethodName();
198 String url = getServiceRootURL();
199 String mediaType = MediaType.APPLICATION_XML;
200 final String entity = "";
201 int statusCode = submitRequest(method, url, mediaType, entity);
203 // Check the status code of the response: does it match
204 // the expected response(s)?
205 if(logger.isDebugEnabled()){
206 logger.debug("createWithEmptyEntityBody url=" + url +
207 " status=" + statusCode);
209 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
210 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
211 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
215 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
216 dependsOnMethods = {"create", "testSubmitRequest"})
217 public void createWithMalformedXml(String testName) throws Exception {
219 if (logger.isDebugEnabled()) {
220 logger.debug(testBanner(testName, CLASS_NAME));
223 setupCreateWithMalformedXml();
225 // Submit the request to the service and store the response.
226 String method = REQUEST_TYPE.httpMethodName();
227 String url = getServiceRootURL();
228 String mediaType = MediaType.APPLICATION_XML;
229 final String entity = MALFORMED_XML_DATA; // Constant from base class.
230 int statusCode = submitRequest(method, url, mediaType, entity);
232 // Check the status code of the response: does it match
233 // the expected response(s)?
234 if(logger.isDebugEnabled()){
235 logger.debug(testName + ": url=" + url +
236 " status=" + statusCode);
238 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
239 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
240 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
244 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
245 dependsOnMethods = {"create", "testSubmitRequest"})
246 public void createWithWrongXmlSchema(String testName) throws Exception {
248 if (logger.isDebugEnabled()) {
249 logger.debug(testBanner(testName, CLASS_NAME));
252 setupCreateWithWrongXmlSchema(testName, logger);
254 // Submit the request to the service and store the response.
255 String method = REQUEST_TYPE.httpMethodName();
256 String url = getServiceRootURL();
257 String mediaType = MediaType.APPLICATION_XML;
258 final String entity = WRONG_XML_SCHEMA_DATA;
259 int statusCode = submitRequest(method, url, mediaType, entity);
261 // Check the status code of the response: does it match
262 // the expected response(s)?
263 if(logger.isDebugEnabled()){
264 logger.debug(testName + ": url=" + url +
265 " status=" + statusCode);
267 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
273 // ---------------------------------------------------------------
274 // CRUD tests : READ tests
275 // ---------------------------------------------------------------
280 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
283 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
284 dependsOnMethods = {"create"})
285 public void read(String testName) throws Exception {
287 if (logger.isDebugEnabled()) {
288 logger.debug(testBanner(testName, CLASS_NAME));
293 // Submit the request to the service and store the response.
294 IntakeClient client = new IntakeClient();
295 ClientResponse<String> res = client.read(knownResourceId);
296 int statusCode = res.getStatus();
298 // Check the status code of the response: does it match
299 // the expected response(s)?
300 if (logger.isDebugEnabled()) {
301 logger.debug(testName + ": status = " + statusCode);
303 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
304 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
305 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
307 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
308 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
309 IntakesCommon intakeCommons = null;
310 if (payloadInputPart != null) {
311 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
313 // IntakesCommon intake = (IntakesCommon) extractPart(input,
314 // client.getCommonPartName(), IntakesCommon.class);
315 Assert.assertNotNull(intakeCommons);
317 // Verify the number and contents of values in repeatable fields,
318 // as created in the instance record used for testing.
319 List<String> entryMethods =
320 intakeCommons.getEntryMethods().getEntryMethod();
321 Assert.assertTrue(entryMethods.size() > 0);
322 Assert.assertNotNull(entryMethods.get(0));
324 List<String> fieldCollectionEventNames =
325 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
326 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
327 Assert.assertNotNull(fieldCollectionEventNames.get(0));
329 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
330 Assert.assertNotNull(currentLocationGroupList);
331 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
332 Assert.assertNotNull(currentLocationGroups);
333 Assert.assertTrue(currentLocationGroups.size() > 0);
334 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
335 Assert.assertNotNull(currentLocationGroup);
336 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
338 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
339 if (logger.isDebugEnabled()) {
340 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
341 + "UTF-8 data received=" + intakeCommons.getEntryNote());
343 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
344 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
345 + "' does not match expected data '" + getUTF8DataFragment());
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
354 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
355 dependsOnMethods = {"read"})
356 public void readNonExistent(String testName) throws Exception {
358 if (logger.isDebugEnabled()) {
359 logger.debug(testBanner(testName, CLASS_NAME));
362 setupReadNonExistent();
364 // Submit the request to the service and store the response.
365 IntakeClient client = new IntakeClient();
366 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
367 int statusCode = res.getStatus();
369 // Check the status code of the response: does it match
370 // the expected response(s)?
371 if (logger.isDebugEnabled()) {
372 logger.debug(testName + ": status = " + statusCode);
374 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
375 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
376 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
379 // ---------------------------------------------------------------
380 // CRUD tests : READ_LIST tests
381 // ---------------------------------------------------------------
386 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
389 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
390 dependsOnMethods = {"createList", "read"})
391 public void readList(String testName) throws Exception {
393 if (logger.isDebugEnabled()) {
394 logger.debug(testBanner(testName, CLASS_NAME));
399 // Submit the request to the service and store the response.
400 IntakeClient client = new IntakeClient();
401 ClientResponse<AbstractCommonList> res = client.readList();
402 AbstractCommonList list = res.getEntity();
403 int statusCode = res.getStatus();
405 // Check the status code of the response: does it match
406 // the expected response(s)?
407 if (logger.isDebugEnabled()) {
408 logger.debug(testName + ": status = " + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
414 // Optionally output additional data about list members for debugging.
415 boolean iterateThroughList = true;
416 if (iterateThroughList && logger.isDebugEnabled()) {
417 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
425 // ---------------------------------------------------------------
426 // CRUD tests : UPDATE tests
427 // ---------------------------------------------------------------
432 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
435 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
436 dependsOnMethods = {"read"})
437 public void update(String testName) throws Exception {
439 if (logger.isDebugEnabled()) {
440 logger.debug(testBanner(testName, CLASS_NAME));
445 // Retrieve the contents of a resource to update.
446 IntakeClient client = new IntakeClient();
447 ClientResponse<String> res = client.read(knownResourceId);
448 if (logger.isDebugEnabled()) {
449 logger.debug(testName + ": read status = " + res.getStatus());
451 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
453 if (logger.isDebugEnabled()) {
454 logger.debug("got object to update with ID: " + knownResourceId);
456 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
457 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
458 IntakesCommon intakeCommons = null;
459 if (payloadInputPart != null) {
460 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
462 // IntakesCommon intake = (IntakesCommon) extractPart(input,
463 // client.getCommonPartName(), IntakesCommon.class);
464 Assert.assertNotNull(intakeCommons);
466 // Update the content of this resource.
467 intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
468 intakeCommons.setEntryDate("updated-" + intakeCommons.getEntryDate());
469 if (logger.isDebugEnabled()) {
470 logger.debug("to be updated object");
471 logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class));
474 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
475 Assert.assertNotNull(currentLocationGroupList);
476 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
477 Assert.assertNotNull(currentLocationGroups);
478 Assert.assertTrue(currentLocationGroups.size() > 0);
479 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
480 Assert.assertNotNull(currentLocationGroup);
481 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
482 Assert.assertNotNull(currentLocationNote);
483 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
484 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
485 intakeCommons.setCurrentLocationGroupList(currentLocationGroupList);
487 // Create an output payload to send to the service, and add teh common part
488 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
489 PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
490 commonPart.setLabel(client.getCommonPartName());
492 // Submit the request to the service and store the response.
493 res = client.update(knownResourceId, output);
494 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match the expected response(s)?
496 if (logger.isDebugEnabled()) {
497 logger.debug(testName + ": status = " + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 input = new PoxPayloadIn(res.getEntity());
504 IntakesCommon updatedIntake =
505 (IntakesCommon) extractPart(input,
506 client.getCommonPartName(), IntakesCommon.class);
508 Assert.assertNotNull(updatedIntake);
510 Assert.assertEquals(updatedIntake.getEntryDate(),
511 intakeCommons.getEntryDate(),
512 "Data in updated object did not match submitted data.");
514 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
515 Assert.assertNotNull(currentLocationGroupList);
516 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
517 Assert.assertNotNull(currentLocationGroups);
518 Assert.assertTrue(currentLocationGroups.size() > 0);
519 Assert.assertNotNull(currentLocationGroups.get(0));
520 Assert.assertEquals(updatedCurrentLocationNote,
521 currentLocationGroups.get(0).getCurrentLocationNote(),
522 "Data in updated object did not match submitted data.");
524 if (logger.isDebugEnabled()) {
525 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
526 + "UTF-8 data received=" + updatedIntake.getEntryNote());
528 Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
529 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
530 + "' does not contain expected data '" + getUTF8DataFragment());
531 Assert.assertEquals(updatedIntake.getEntryNote(),
532 intakeCommons.getEntryNote(),
533 "Data in updated object did not match submitted data.");
537 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
538 dependsOnMethods = {"update"})
539 public void verifyReadOnlyCoreFields(String testName) throws Exception {
540 // TODO These should be in some core client utils
541 final String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
542 final String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
543 final String COLLECTIONSPACE_CORE_URI = "uri";
544 final String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt";
545 final String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt";
546 final String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy";
547 final String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy";
549 if (logger.isDebugEnabled()) {
550 logger.debug(testBanner(testName, CLASS_NAME));
555 // Retrieve the contents of a resource to update.
556 IntakeClient client = new IntakeClient();
557 ClientResponse<String> res = client.read(knownResourceId);
558 if (logger.isDebugEnabled()) {
559 logger.debug(testName + ": read status = " + res.getStatus());
561 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
563 if (logger.isDebugEnabled()) {
564 logger.debug("got object to update with ID: " + knownResourceId);
566 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
567 PayloadInputPart payloadInputPart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
568 Element coreAsElement = null;
569 if (payloadInputPart != null) {
570 coreAsElement = payloadInputPart.getElementBody();
572 Assert.assertNotNull(coreAsElement);
573 if (logger.isDebugEnabled()) {
574 logger.debug("Core part before update:");
575 logger.debug(coreAsElement.asXML());
578 // Update the read-only elements
579 Element tenantId = coreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
580 String originalTenantId = tenantId.getText();
581 tenantId.setText("foo");
582 Element uri = coreAsElement.element(COLLECTIONSPACE_CORE_URI);
583 String originalUri = uri.getText();
585 Element createdAt = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
586 String originalCreatedAt = createdAt.getText();
587 String now = GregorianCalendarDateTimeUtils.timestampUTC();
588 if(originalCreatedAt.equalsIgnoreCase(now) && logger.isWarnEnabled()) {
589 logger.warn("Cannot check createdAt read-only; too fast!");
591 createdAt.setText(now);
592 Element createdBy = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
593 String originalCreatedBy = createdBy.getText();
594 createdBy.setText("foo");
596 if (logger.isDebugEnabled()) {
597 logger.debug("Core part to be updated:");
598 logger.debug(coreAsElement.asXML());
601 // Create an output payload to send to the service, and add the common part
602 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
603 PayloadOutputPart corePart = output.addPart(
604 COLLECTIONSPACE_CORE_SCHEMA, coreAsElement);
606 // Submit the request to the service and store the response.
607 res = client.update(knownResourceId, output);
608 int statusCode = res.getStatus();
609 // Check the status code of the response: does it match the expected response(s)?
610 if (logger.isDebugEnabled()) {
611 logger.debug(testName + ": status = " + statusCode);
613 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617 input = new PoxPayloadIn(res.getEntity());
618 PayloadInputPart updatedCorePart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
619 Element updatedCoreAsElement = null;
620 if (updatedCorePart != null) {
621 updatedCoreAsElement = updatedCorePart.getElementBody();
623 Assert.assertNotNull(updatedCoreAsElement);
625 tenantId = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
626 String updatedTenantId = tenantId.getText();
627 Assert.assertEquals(updatedTenantId, originalTenantId,
628 "CORE part TenantID was able to update!");
629 uri = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_URI);
630 String updatedUri = uri.getText();
631 Assert.assertEquals(updatedUri, originalUri,
632 "CORE part URI was able to update!");
633 createdAt = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
634 String updatedCreatedAt = createdAt.getText();
635 Assert.assertEquals(updatedCreatedAt, originalCreatedAt,
636 "CORE part CreatedAt was able to update!");
637 createdBy = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
638 String updatedCreatedBy = createdBy.getText();
639 Assert.assertEquals(updatedCreatedBy, originalCreatedBy,
640 "CORE part CreatedBy was able to update!");
645 // Placeholders until the three tests below can be uncommented.
647 // See Issue CSPACE-401.
649 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
652 public void updateWithEmptyEntityBody(String testName) throws Exception {
653 //Should this really be empty?
657 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
660 public void updateWithMalformedXml(String testName) throws Exception {
661 //Should this really be empty?
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
668 public void updateWithWrongXmlSchema(String testName) throws Exception {
669 //Should this really be empty?
674 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
675 dependsOnMethods = {"create", "update", "testSubmitRequest"})
676 public void updateWithEmptyEntityBody(String testName) throws Exception {
678 if (logger.isDebugEnabled()) {
679 logger.debug(testBanner(testName, CLASS_NAME));
682 setupUpdateWithEmptyEntityBody();
684 // Submit the request to the service and store the response.
685 String method = REQUEST_TYPE.httpMethodName();
686 String url = getResourceURL(knownResourceId);
687 String mediaType = MediaType.APPLICATION_XML;
688 final String entity = "";
689 int statusCode = submitRequest(method, url, mediaType, entity);
691 // Check the status code of the response: does it match
692 // the expected response(s)?
693 if(logger.isDebugEnabled()){
694 logger.debug(testName + ": url=" + url +
695 " status=" + statusCode);
697 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
698 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
699 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
703 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
704 dependsOnMethods = {"create", "update", "testSubmitRequest"})
705 public void updateWithMalformedXml(String testName) throws Exception {
707 if (logger.isDebugEnabled()) {
708 logger.debug(testBanner(testName, CLASS_NAME));
711 setupUpdateWithMalformedXml();
713 // Submit the request to the service and store the response.
714 String method = REQUEST_TYPE.httpMethodName();
715 String url = getResourceURL(knownResourceId);
716 String mediaType = MediaType.APPLICATION_XML;
717 final String entity = MALFORMED_XML_DATA;
718 int statusCode = submitRequest(method, url, mediaType, entity);
720 // Check the status code of the response: does it match
721 // the expected response(s)?
722 if(logger.isDebugEnabled()){
723 logger.debug(testName + ": url=" + url +
724 " status=" + statusCode);
726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
732 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
733 dependsOnMethods = {"create", "update", "testSubmitRequest"})
734 public void updateWithWrongXmlSchema(String testName) throws Exception {
736 if (logger.isDebugEnabled()) {
737 logger.debug(testBanner(testName, CLASS_NAME));
740 setupUpdateWithWrongXmlSchema();
742 // Submit the request to the service and store the response.
743 String method = REQUEST_TYPE.httpMethodName();
744 String url = getResourceURL(knownResourceId);
745 String mediaType = MediaType.APPLICATION_XML;
746 final String entity = WRONG_XML_SCHEMA_DATA;
747 int statusCode = submitRequest(method, url, mediaType, entity);
749 // Check the status code of the response: does it match
750 // the expected response(s)?
751 if(logger.isDebugEnabled()){
752 logger.debug(testName + ": url=" + url +
753 " status=" + statusCode);
755 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
756 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
757 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
762 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
765 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
766 dependsOnMethods = {"update", "testSubmitRequest"})
767 public void updateNonExistent(String testName) throws Exception {
769 if (logger.isDebugEnabled()) {
770 logger.debug(testBanner(testName, CLASS_NAME));
773 setupUpdateNonExistent();
775 // Submit the request to the service and store the response.
776 // Note: The ID used in this 'create' call may be arbitrary.
777 // The only relevant ID may be the one used in update(), below.
778 IntakeClient client = new IntakeClient();
779 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
780 ClientResponse<String> res =
781 client.update(NON_EXISTENT_ID, multipart);
782 int statusCode = res.getStatus();
784 // Check the status code of the response: does it match
785 // the expected response(s)?
786 if (logger.isDebugEnabled()) {
787 logger.debug(testName + ": status = " + statusCode);
789 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
794 // ---------------------------------------------------------------
795 // CRUD tests : DELETE tests
796 // ---------------------------------------------------------------
801 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
804 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
805 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "verifyReadOnlyCoreFields"})
806 public void delete(String testName) throws Exception {
808 if (logger.isDebugEnabled()) {
809 logger.debug(testBanner(testName, CLASS_NAME));
814 // Submit the request to the service and store the response.
815 IntakeClient client = new IntakeClient();
816 ClientResponse<Response> res = client.delete(knownResourceId);
817 int statusCode = res.getStatus();
819 // Check the status code of the response: does it match
820 // the expected response(s)?
821 if (logger.isDebugEnabled()) {
822 logger.debug(testName + ": status = " + statusCode);
824 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
825 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
826 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
832 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
835 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
836 dependsOnMethods = {"delete"})
837 public void deleteNonExistent(String testName) throws Exception {
839 if (logger.isDebugEnabled()) {
840 logger.debug(testBanner(testName, CLASS_NAME));
843 setupDeleteNonExistent();
845 // Submit the request to the service and store the response.
846 IntakeClient client = new IntakeClient();
847 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
848 int statusCode = res.getStatus();
850 // Check the status code of the response: does it match
851 // the expected response(s)?
852 if (logger.isDebugEnabled()) {
853 logger.debug(testName + ": status = " + statusCode);
855 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
856 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
857 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
860 // ---------------------------------------------------------------
861 // Utility tests : tests of code used in tests above
862 // ---------------------------------------------------------------
865 * Tests the code for manually submitting data that is used by several
866 * of the methods above.
868 @Test(dependsOnMethods = {"create", "read"})
869 public void testSubmitRequest() {
871 // Expected status code: 200 OK
872 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
874 // Submit the request to the service and store the response.
875 String method = ServiceRequestType.READ.httpMethodName();
876 String url = getResourceURL(knownResourceId);
877 int statusCode = submitRequest(method, url);
879 // Check the status code of the response: does it match
880 // the expected response(s)?
881 if (logger.isDebugEnabled()) {
882 logger.debug("testSubmitRequest: url=" + url
883 + " status=" + statusCode);
885 Assert.assertEquals(statusCode, EXPECTED_STATUS);
889 // ---------------------------------------------------------------
890 // Utility methods used by tests above
891 // ---------------------------------------------------------------
894 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
897 public String getServicePathComponent() {
898 return IntakeClient.SERVICE_PATH_COMPONENT;
902 * Creates the intake instance.
904 * @param identifier the identifier
905 * @return the multipart output
908 protected PoxPayloadOut createInstance(String identifier) {
909 return createIntakeInstance(
910 "entryNumber-" + identifier,
911 "entryDate-" + identifier,
912 "depositor-" + identifier);
916 * Creates the intake instance.
918 * @param entryNumber the entry number
919 * @param entryDate the entry date
920 * @param depositor the depositor
921 * @return the multipart output
923 private PoxPayloadOut createIntakeInstance(String entryNumber,
926 IntakesCommon intake = new IntakesCommon();
927 intake.setEntryNumber(entryNumber);
928 intake.setEntryDate(entryDate);
929 intake.setDepositor(depositor);
931 EntryMethodList entryMethodsList = new EntryMethodList();
932 List<String> entryMethods = entryMethodsList.getEntryMethod();
933 entryMethods.add("Left at doorstep");
934 entryMethods.add("Received via post");
935 intake.setEntryMethods(entryMethodsList);
937 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
938 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
939 // FIXME Use properly formatted refNames for representative event names
940 // in this example test record. The following are mere placeholders.
941 eventNames.add("Field Collection Event Name-1");
942 eventNames.add("Field Collection Event Name-2");
943 intake.setFieldCollectionEventNames(eventNamesList);
945 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
946 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
947 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
948 currentLocationGroup.setCurrentLocation("upstairs");
949 currentLocationGroup.setCurrentLocationFitness("suitable");
950 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
951 currentLocationGroups.add(currentLocationGroup);
952 intake.setCurrentLocationGroupList(currentLocationGroupList);
954 intake.setEntryNote(getUTF8DataFragment());
956 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
957 PayloadOutputPart commonPart =
958 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
959 commonPart.setLabel(new IntakeClient().getCommonPartName());
961 if (logger.isDebugEnabled()) {
962 logger.debug("to be created, intake common");
963 logger.debug(objectAsXmlString(intake, IntakesCommon.class));