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 assertStatusCode(res, testName);
300 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
301 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
302 IntakesCommon intakeCommons = null;
303 if (payloadInputPart != null) {
304 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
306 // IntakesCommon intake = (IntakesCommon) extractPart(input,
307 // client.getCommonPartName(), IntakesCommon.class);
308 Assert.assertNotNull(intakeCommons);
310 // Verify the number and contents of values in repeatable fields,
311 // as created in the instance record used for testing.
312 List<String> entryMethods =
313 intakeCommons.getEntryMethods().getEntryMethod();
314 Assert.assertTrue(entryMethods.size() > 0);
315 Assert.assertNotNull(entryMethods.get(0));
317 List<String> fieldCollectionEventNames =
318 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
319 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
320 Assert.assertNotNull(fieldCollectionEventNames.get(0));
322 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
323 Assert.assertNotNull(currentLocationGroupList);
324 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
325 Assert.assertNotNull(currentLocationGroups);
326 Assert.assertTrue(currentLocationGroups.size() > 0);
327 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
328 Assert.assertNotNull(currentLocationGroup);
329 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
331 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
332 if (logger.isDebugEnabled()) {
333 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
334 + "UTF-8 data received=" + intakeCommons.getEntryNote());
336 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
337 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
338 + "' does not match expected data '" + getUTF8DataFragment());
344 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
347 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
348 dependsOnMethods = {"read"})
349 public void readNonExistent(String testName) throws Exception {
351 if (logger.isDebugEnabled()) {
352 logger.debug(testBanner(testName, CLASS_NAME));
355 setupReadNonExistent();
357 // Submit the request to the service and store the response.
358 IntakeClient client = new IntakeClient();
359 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
360 int statusCode = res.getStatus();
362 // Check the status code of the response: does it match
363 // the expected response(s)?
364 if (logger.isDebugEnabled()) {
365 logger.debug(testName + ": status = " + statusCode);
367 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
368 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
369 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
372 // ---------------------------------------------------------------
373 // CRUD tests : READ_LIST tests
374 // ---------------------------------------------------------------
379 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
382 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
383 dependsOnMethods = {"createList", "read"})
384 public void readList(String testName) throws Exception {
386 if (logger.isDebugEnabled()) {
387 logger.debug(testBanner(testName, CLASS_NAME));
392 // Submit the request to the service and store the response.
393 IntakeClient client = new IntakeClient();
394 ClientResponse<AbstractCommonList> res = client.readList();
395 assertStatusCode(res, testName);
396 AbstractCommonList list = res.getEntity();
398 // Optionally output additional data about list members for debugging.
399 boolean iterateThroughList = true;
400 if (iterateThroughList && logger.isDebugEnabled()) {
401 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
409 // ---------------------------------------------------------------
410 // CRUD tests : UPDATE tests
411 // ---------------------------------------------------------------
416 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
419 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
420 dependsOnMethods = {"read"})
421 public void update(String testName) throws Exception {
423 if (logger.isDebugEnabled()) {
424 logger.debug(testBanner(testName, CLASS_NAME));
429 // Retrieve the contents of a resource to update.
430 IntakeClient client = new IntakeClient();
431 ClientResponse<String> res = client.read(knownResourceId);
432 assertStatusCode(res, testName);
434 if (logger.isDebugEnabled()) {
435 logger.debug("got object to update with ID: " + knownResourceId);
437 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
438 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
439 IntakesCommon intakeCommons = null;
440 if (payloadInputPart != null) {
441 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
443 // IntakesCommon intake = (IntakesCommon) extractPart(input,
444 // client.getCommonPartName(), IntakesCommon.class);
445 Assert.assertNotNull(intakeCommons);
447 // Update the content of this resource.
448 intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
449 if (logger.isDebugEnabled()) {
450 logger.debug("to be updated object");
451 logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class));
454 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
455 Assert.assertNotNull(currentLocationGroupList);
456 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
457 Assert.assertNotNull(currentLocationGroups);
458 Assert.assertTrue(currentLocationGroups.size() > 0);
459 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
460 Assert.assertNotNull(currentLocationGroup);
461 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
462 Assert.assertNotNull(currentLocationNote);
463 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
464 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
465 intakeCommons.setCurrentLocationGroupList(currentLocationGroupList);
467 // Create an output payload to send to the service, and add teh common part
468 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
469 PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
470 commonPart.setLabel(client.getCommonPartName());
472 // Submit the request to the service and store the response.
473 res = client.update(knownResourceId, output);
474 assertStatusCode(res, testName);
476 input = new PoxPayloadIn(res.getEntity());
477 IntakesCommon updatedIntake =
478 (IntakesCommon) extractPart(input,
479 client.getCommonPartName(), IntakesCommon.class);
481 Assert.assertNotNull(updatedIntake);
483 Assert.assertEquals(updatedIntake.getEntryNumber(),
484 intakeCommons.getEntryNumber(),
485 "Data in updated object did not match submitted data.");
487 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
488 Assert.assertNotNull(currentLocationGroupList);
489 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
490 Assert.assertNotNull(currentLocationGroups);
491 Assert.assertTrue(currentLocationGroups.size() > 0);
492 Assert.assertNotNull(currentLocationGroups.get(0));
493 Assert.assertEquals(updatedCurrentLocationNote,
494 currentLocationGroups.get(0).getCurrentLocationNote(),
495 "Data in updated object did not match submitted data.");
497 if (logger.isDebugEnabled()) {
498 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
499 + "UTF-8 data received=" + updatedIntake.getEntryNote());
501 Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
502 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
503 + "' does not contain expected data '" + getUTF8DataFragment());
504 Assert.assertEquals(updatedIntake.getEntryNote(),
505 intakeCommons.getEntryNote(),
506 "Data in updated object did not match submitted data.");
510 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
511 dependsOnMethods = {"update"})
512 public void verifyReadOnlyCoreFields(String testName) throws Exception {
513 // TODO These should be in some core client utils
514 final String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
515 final String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
516 final String COLLECTIONSPACE_CORE_URI = "uri";
517 final String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt";
518 final String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt";
519 final String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy";
520 final String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy";
522 if (logger.isDebugEnabled()) {
523 logger.debug(testBanner(testName, CLASS_NAME));
528 // Retrieve the contents of a resource to update.
529 IntakeClient client = new IntakeClient();
530 ClientResponse<String> res = client.read(knownResourceId);
531 assertStatusCode(res, testName);
533 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
534 PayloadInputPart payloadInputPart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
535 Element coreAsElement = null;
536 if (payloadInputPart != null) {
537 coreAsElement = payloadInputPart.getElementBody();
539 Assert.assertNotNull(coreAsElement);
540 if (logger.isDebugEnabled()) {
541 logger.debug("Core part before update:");
542 logger.debug(coreAsElement.asXML());
545 // Update the read-only elements
546 Element tenantId = coreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
547 String originalTenantId = tenantId.getText();
548 tenantId.setText("foo");
549 Element uri = coreAsElement.element(COLLECTIONSPACE_CORE_URI);
550 String originalUri = uri.getText();
552 Element createdAt = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
553 String originalCreatedAt = createdAt.getText();
554 String now = GregorianCalendarDateTimeUtils.timestampUTC();
555 if(originalCreatedAt.equalsIgnoreCase(now) && logger.isWarnEnabled()) {
556 logger.warn("Cannot check createdAt read-only; too fast!");
558 createdAt.setText(now);
559 Element createdBy = coreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
560 String originalCreatedBy = createdBy.getText();
561 createdBy.setText("foo");
563 if (logger.isDebugEnabled()) {
564 logger.debug("Core part to be updated:");
565 logger.debug(coreAsElement.asXML());
568 // Create an output payload to send to the service, and add the common part
569 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
570 PayloadOutputPart corePart = output.addPart(
571 COLLECTIONSPACE_CORE_SCHEMA, coreAsElement);
573 // Submit the request to the service and store the response.
574 res = client.update(knownResourceId, output);
575 assertStatusCode(res, testName);
577 input = new PoxPayloadIn(res.getEntity());
578 PayloadInputPart updatedCorePart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA);
579 Element updatedCoreAsElement = null;
580 if (updatedCorePart != null) {
581 updatedCoreAsElement = updatedCorePart.getElementBody();
583 Assert.assertNotNull(updatedCoreAsElement);
585 tenantId = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_TENANTID);
586 String updatedTenantId = tenantId.getText();
587 Assert.assertEquals(updatedTenantId, originalTenantId,
588 "CORE part TenantID was able to update!");
589 uri = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_URI);
590 String updatedUri = uri.getText();
591 Assert.assertEquals(updatedUri, originalUri,
592 "CORE part URI was able to update!");
593 createdAt = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_AT);
594 String updatedCreatedAt = createdAt.getText();
595 Assert.assertEquals(updatedCreatedAt, originalCreatedAt,
596 "CORE part CreatedAt was able to update!");
597 createdBy = updatedCoreAsElement.element(COLLECTIONSPACE_CORE_CREATED_BY);
598 String updatedCreatedBy = createdBy.getText();
599 Assert.assertEquals(updatedCreatedBy, originalCreatedBy,
600 "CORE part CreatedBy was able to update!");
605 // Placeholders until the three tests below can be uncommented.
607 // See Issue CSPACE-401.
609 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
612 public void updateWithEmptyEntityBody(String testName) throws Exception {
613 //Should this really be empty?
617 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
620 public void updateWithMalformedXml(String testName) throws Exception {
621 //Should this really be empty?
625 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
628 public void updateWithWrongXmlSchema(String testName) throws Exception {
629 //Should this really be empty?
634 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
635 dependsOnMethods = {"create", "update", "testSubmitRequest"})
636 public void updateWithEmptyEntityBody(String testName) throws Exception {
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
642 setupUpdateWithEmptyEntityBody();
644 // Submit the request to the service and store the response.
645 String method = REQUEST_TYPE.httpMethodName();
646 String url = getResourceURL(knownResourceId);
647 String mediaType = MediaType.APPLICATION_XML;
648 final String entity = "";
649 int statusCode = submitRequest(method, url, mediaType, entity);
651 // Check the status code of the response: does it match
652 // the expected response(s)?
653 if(logger.isDebugEnabled()){
654 logger.debug(testName + ": url=" + url +
655 " status=" + statusCode);
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
663 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
664 dependsOnMethods = {"create", "update", "testSubmitRequest"})
665 public void updateWithMalformedXml(String testName) throws Exception {
667 if (logger.isDebugEnabled()) {
668 logger.debug(testBanner(testName, CLASS_NAME));
671 setupUpdateWithMalformedXml();
673 // Submit the request to the service and store the response.
674 String method = REQUEST_TYPE.httpMethodName();
675 String url = getResourceURL(knownResourceId);
676 String mediaType = MediaType.APPLICATION_XML;
677 final String entity = MALFORMED_XML_DATA;
678 int statusCode = submitRequest(method, url, mediaType, entity);
680 // Check the status code of the response: does it match
681 // the expected response(s)?
682 if(logger.isDebugEnabled()){
683 logger.debug(testName + ": url=" + url +
684 " status=" + statusCode);
686 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
687 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
688 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
693 dependsOnMethods = {"create", "update", "testSubmitRequest"})
694 public void updateWithWrongXmlSchema(String testName) throws Exception {
696 if (logger.isDebugEnabled()) {
697 logger.debug(testBanner(testName, CLASS_NAME));
700 setupUpdateWithWrongXmlSchema();
702 // Submit the request to the service and store the response.
703 String method = REQUEST_TYPE.httpMethodName();
704 String url = getResourceURL(knownResourceId);
705 String mediaType = MediaType.APPLICATION_XML;
706 final String entity = WRONG_XML_SCHEMA_DATA;
707 int statusCode = submitRequest(method, url, mediaType, entity);
709 // Check the status code of the response: does it match
710 // the expected response(s)?
711 if(logger.isDebugEnabled()){
712 logger.debug(testName + ": url=" + url +
713 " status=" + statusCode);
715 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
716 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
717 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
722 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
725 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
726 dependsOnMethods = {"update", "testSubmitRequest"})
727 public void updateNonExistent(String testName) throws Exception {
729 if (logger.isDebugEnabled()) {
730 logger.debug(testBanner(testName, CLASS_NAME));
733 setupUpdateNonExistent();
735 // Submit the request to the service and store the response.
736 // Note: The ID used in this 'create' call may be arbitrary.
737 // The only relevant ID may be the one used in update(), below.
738 IntakeClient client = new IntakeClient();
739 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
740 ClientResponse<String> res =
741 client.update(NON_EXISTENT_ID, multipart);
742 int statusCode = res.getStatus();
744 // Check the status code of the response: does it match
745 // the expected response(s)?
746 if (logger.isDebugEnabled()) {
747 logger.debug(testName + ": status = " + statusCode);
749 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
750 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
751 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 // ---------------------------------------------------------------
755 // CRUD tests : DELETE tests
756 // ---------------------------------------------------------------
761 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
764 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
765 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "verifyReadOnlyCoreFields"})
766 public void delete(String testName) throws Exception {
768 if (logger.isDebugEnabled()) {
769 logger.debug(testBanner(testName, CLASS_NAME));
774 // Submit the request to the service and store the response.
775 IntakeClient client = new IntakeClient();
776 ClientResponse<Response> res = client.delete(knownResourceId);
777 int statusCode = res.getStatus();
779 // Check the status code of the response: does it match
780 // the expected response(s)?
781 if (logger.isDebugEnabled()) {
782 logger.debug(testName + ": status = " + statusCode);
784 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
785 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
786 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
792 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
795 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
796 dependsOnMethods = {"delete"})
797 public void deleteNonExistent(String testName) throws Exception {
799 if (logger.isDebugEnabled()) {
800 logger.debug(testBanner(testName, CLASS_NAME));
803 setupDeleteNonExistent();
805 // Submit the request to the service and store the response.
806 IntakeClient client = new IntakeClient();
807 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
808 int statusCode = res.getStatus();
810 // Check the status code of the response: does it match
811 // the expected response(s)?
812 if (logger.isDebugEnabled()) {
813 logger.debug(testName + ": status = " + statusCode);
815 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
816 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
817 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
820 // ---------------------------------------------------------------
821 // Utility tests : tests of code used in tests above
822 // ---------------------------------------------------------------
825 * Tests the code for manually submitting data that is used by several
826 * of the methods above.
828 @Test(dependsOnMethods = {"create", "read"})
829 public void testSubmitRequest() {
831 // Expected status code: 200 OK
832 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
834 // Submit the request to the service and store the response.
835 String method = ServiceRequestType.READ.httpMethodName();
836 String url = getResourceURL(knownResourceId);
837 int statusCode = submitRequest(method, url);
839 // Check the status code of the response: does it match
840 // the expected response(s)?
841 if (logger.isDebugEnabled()) {
842 logger.debug("testSubmitRequest: url=" + url
843 + " status=" + statusCode);
845 Assert.assertEquals(statusCode, EXPECTED_STATUS);
849 // ---------------------------------------------------------------
850 // Utility methods used by tests above
851 // ---------------------------------------------------------------
854 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
857 public String getServicePathComponent() {
858 return IntakeClient.SERVICE_PATH_COMPONENT;
862 * Creates the intake instance.
864 * @param identifier the identifier
865 * @return the multipart output
868 protected PoxPayloadOut createInstance(String identifier) {
869 return createIntakeInstance(
870 "entryNumber-" + identifier,
872 "depositor-" + identifier);
876 * Creates the intake instance.
878 * @param entryNumber the entry number
879 * @param entryDate the entry date
880 * @param depositor the depositor
881 * @return the multipart output
883 private PoxPayloadOut createIntakeInstance(String entryNumber,
886 IntakesCommon intake = new IntakesCommon();
887 intake.setEntryNumber(entryNumber);
888 intake.setEntryDate(entryDate);
889 intake.setDepositor(depositor);
891 EntryMethodList entryMethodsList = new EntryMethodList();
892 List<String> entryMethods = entryMethodsList.getEntryMethod();
893 entryMethods.add("Left at doorstep");
894 entryMethods.add("Received via post");
895 intake.setEntryMethods(entryMethodsList);
897 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
898 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
899 // FIXME Use properly formatted refNames for representative event names
900 // in this example test record. The following are mere placeholders.
901 eventNames.add("Field Collection Event Name-1");
902 eventNames.add("Field Collection Event Name-2");
903 intake.setFieldCollectionEventNames(eventNamesList);
905 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
906 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
907 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
908 currentLocationGroup.setCurrentLocation("upstairs");
909 currentLocationGroup.setCurrentLocationFitness("suitable");
910 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
911 currentLocationGroups.add(currentLocationGroup);
912 intake.setCurrentLocationGroupList(currentLocationGroupList);
914 intake.setEntryNote(getUTF8DataFragment());
916 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
917 PayloadOutputPart commonPart =
918 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
919 commonPart.setLabel(new IntakeClient().getCommonPartName());
921 if (logger.isDebugEnabled()) {
922 logger.debug("to be created, intake common");
923 logger.debug(objectAsXmlString(intake, IntakesCommon.class));