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.collectionspace.services.client.AbstractServiceClientImpl;
30 import org.collectionspace.services.client.CollectionObjectClient;
31 import org.collectionspace.services.client.CollectionObjectFactory;
32 import org.collectionspace.services.client.CollectionSpaceClient;
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.collectionobject.BriefDescriptionList;
38 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
39 import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory;
40 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
41 import org.collectionspace.services.collectionobject.ResponsibleDepartmentList;
42 import org.collectionspace.services.collectionobject.DimensionGroup;
43 import org.collectionspace.services.collectionobject.DimensionList;
44 import org.collectionspace.services.collectionobject.ObjectNameGroup;
45 import org.collectionspace.services.collectionobject.ObjectNameList;
46 import org.collectionspace.services.collectionobject.OtherNumber;
47 import org.collectionspace.services.collectionobject.OtherNumberList;
48 import org.collectionspace.services.collectionobject.TitleGroup;
49 import org.collectionspace.services.collectionobject.TitleGroupList;
51 import org.collectionspace.services.jaxb.AbstractCommonList;
53 import org.jboss.resteasy.client.ClientResponse;
54 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
55 import org.testng.Assert;
56 import org.testng.annotations.Test;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
62 * CollectionObjectServiceTest, carries out tests against a
63 * deployed and running CollectionObject Service.
65 * $LastChangedRevision$
68 public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
71 private final String CLASS_NAME = CollectionObjectServiceTest.class.getName();
72 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
74 // Instance variables specific to this test.
75 /** The known resource id. */
76 private String knownResourceId = null;
78 private final String OBJECT_NAME_VALUE = "an object name";
79 private final String UPDATED_MEASURED_PART_VALUE = "updated measured part value";
80 private final String UTF8_DATA_SAMPLE = "Audiorecording album cover signed by Lech "
81 + "Wa" + '\u0142' + '\u0119' + "sa";
84 // * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
87 // protected String getServicePathComponent() {
88 // return new CollectionObjectClient().getServicePathComponent();
92 protected String getServiceName() {
93 return CollectionObjectClient.SERVICE_NAME;
97 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
100 protected CollectionSpaceClient getClientInstance() {
101 return new CollectionObjectClient();
105 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
108 protected AbstractCommonList getAbstractCommonList(
109 ClientResponse<AbstractCommonList> response) {
110 return response.getEntity(CollectionobjectsCommonList.class);
113 // ---------------------------------------------------------------
114 // CRUD tests : CREATE tests
115 // ---------------------------------------------------------------
118 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
121 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
122 public void create(String testName) throws Exception {
124 if (logger.isDebugEnabled()) {
125 logger.debug(testBanner(testName, CLASS_NAME));
127 // Perform setup, such as initializing the type of service request
128 // (e.g. CREATE, DELETE), its valid and expected status codes, and
129 // its associated HTTP method name (e.g. POST, DELETE).
132 // Submit the request to the service and store the response.
133 CollectionObjectClient client = new CollectionObjectClient();
134 String identifier = createIdentifier();
135 PoxPayloadOut multipart =
136 createCollectionObjectInstance(client.getCommonPartName(), identifier);
137 ClientResponse<Response> res = client.create(multipart);
138 int statusCode = res.getStatus();
140 // Check the status code of the response: does it match
141 // the expected response(s)?
144 // Does it fall within the set of valid status codes?
145 // Does it exactly match the expected status code?
146 if (logger.isDebugEnabled()) {
147 logger.debug(testName + ": status = " + statusCode);
149 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
150 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
151 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
153 // Store the ID returned from the first resource created
154 // for additional tests below.
155 if (knownResourceId == null) {
156 knownResourceId = extractId(res);
157 if (logger.isDebugEnabled()) {
158 logger.debug(testName + ": knownResourceId=" + knownResourceId);
162 // Store the IDs from every resource created by tests,
163 // so they can be deleted after tests have been run.
164 allResourceIdsCreated.add(extractId(res));
169 * Tests to diagnose and verify the fixed status of CSPACE-1026,
170 * "Whitespace at certain points in payload cause failure"
173 * Creates the from xml cambridge.
175 * @param testName the test name
176 * @throws Exception the exception
178 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
179 dependsOnMethods = {"create", "testSubmitRequest"})
180 public void createFromXmlCambridge(String testName) throws Exception {
182 createFromXmlFile(testName, "./test-data/testCambridge.xml", true);
183 testSubmitRequest(newId);
187 * Tests to diagnose and fix CSPACE-2242.
189 * This is a bug identified in release 0.8 in which value instances of a
190 * repeatable field are not stored when the first value instance of that
194 // Verify that record creation occurs successfully when the first value instance
195 // of a single, repeatable String scalar field is non-blank.
196 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
197 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"})
198 public void createFromXmlNonBlankFirstValueInstance(String testName) throws Exception {
199 if (logger.isDebugEnabled()) {
200 logger.debug(testBanner(testName, CLASS_NAME));
203 createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-nonblank.xml", true);
204 CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
205 // Verify that at least one value instance of the repeatable field was successfully persisted.
206 BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
207 List<String> descriptions = descriptionList.getBriefDescription();
208 Assert.assertTrue(descriptions.size() > 0);
211 // Verify that record creation occurs successfully when the first value instance
212 // of a single, repeatable String scalar field is blank.
213 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
214 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"})
215 public void createFromXmlBlankFirstValueInstance(String testName) throws Exception {
216 if (logger.isDebugEnabled()) {
217 logger.debug(testBanner(testName, CLASS_NAME));
220 createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-blank.xml", true);
221 CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
222 // Verify that at least one value instance of the repeatable field was successfully persisted.
223 BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
224 List<String> descriptions = descriptionList.getBriefDescription();
225 Assert.assertTrue(descriptions.size() > 0);
228 // Verify that values are preserved when enclosed in double quote marks.
229 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
230 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace3237group"})
231 public void doubleQuotesEnclosingFieldContents(String testName) throws Exception {
232 if (logger.isDebugEnabled()) {
233 logger.debug(testBanner(testName, CLASS_NAME));
236 createFromXmlFile(testName, "./test-data/cspace-3237-double-quotes.xml", true);
237 CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
239 Assert.assertTrue(collectionObject.getDistinguishingFeatures().matches("^\\\".+?\\\"$"));
241 BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
242 List<String> descriptions = descriptionList.getBriefDescription();
243 Assert.assertTrue(descriptions.size() > 0);
244 Assert.assertNotNull(descriptions.get(0));
245 Assert.assertTrue(descriptions.get(0).matches("^\\\".+?\\\"$"));
247 if (logger.isDebugEnabled()) {
248 logger.debug(objectAsXmlString(collectionObject,
249 CollectionobjectsCommon.class));
254 * Creates the from xml rfw s1.
256 * @param testName the test name
257 * @throws Exception the exception
259 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
260 dependsOnMethods = {"create", "testSubmitRequest"})
261 public void createFromXmlRFWS1(String testName) throws Exception {
262 String testDataDir = System.getProperty("test-data.fileName");
264 //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp1.xml", false);
265 createFromXmlFile(testName, testDataDir + "/repfield_whitesp1.xml", false);
266 testSubmitRequest(newId);
270 * Creates the from xml rfw s2.
272 * @param testName the test name
273 * @throws Exception the exception
275 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
276 dependsOnMethods = {"create", "testSubmitRequest"})
277 public void createFromXmlRFWS2(String testName) throws Exception {
278 String testDataDir = System.getProperty("test-data.fileName");
280 //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp2.xml", false);
281 createFromXmlFile(testName, testDataDir + "/repfield_whitesp2.xml", false);
282 testSubmitRequest(newId);
286 * Creates the from xml rfw s3.
288 * @param testName the test name
289 * @throws Exception the exception
291 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
292 dependsOnMethods = {"create", "testSubmitRequest"})
293 public void createFromXmlRFWS3(String testName) throws Exception {
294 String testDataDir = System.getProperty("test-data.fileName");
296 //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp3.xml", false);
297 createFromXmlFile(testName, testDataDir + "/repfield_whitesp3.xml", false);
298 testSubmitRequest(newId);
302 * Creates the from xml rfw s4.
304 * @param testName the test name
305 * @throws Exception the exception
307 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
308 dependsOnMethods = {"create", "testSubmitRequest"})
309 public void createFromXmlRFWS4(String testName) throws Exception {
310 String testDataDir = System.getProperty("test-data.fileName");
312 createFromXmlFile(testName, testDataDir + "/repfield_whitesp4.xml", false);
313 testSubmitRequest(newId);
317 * Tests to diagnose and verify the fixed status of CSPACE-1248,
318 * "Wedged records created!" (i.e. records with child repeatable
319 * fields, which contain null values, can be successfully created
320 * but an error occurs on trying to retrieve those records).
324 * Creates a CollectionObject resource with a null value repeatable field.
326 * @param testName the test name
327 * @throws Exception the exception
329 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
330 dependsOnMethods = {"create", "testSubmitRequest"})
331 public void createWithNullValueRepeatableField(String testName) throws Exception {
332 String testDataDir = System.getProperty("test-data.fileName");
334 createFromXmlFile(testName, testDataDir + "/repfield_null1.xml", false);
335 if (logger.isDebugEnabled()) {
336 logger.debug("Successfully created record with null value repeatable field.");
337 logger.debug("Attempting to retrieve just-created record ...");
339 testSubmitRequest(newId);
343 * Creates a CollectionObject resource, one of whose fields contains
344 * non-Latin 1 Unicode UTF-8 characters.
346 * @param testName the test name
347 * @throws Exception the exception
349 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
350 dependsOnMethods = {"create", "testSubmitRequest"}, groups={"utf8-create"})
351 public void createWithUTF8Data(String testName) throws Exception {
352 String testDataDir = System.getProperty("test-data.fileName");
354 createFromXmlFile(testName, testDataDir + "/cspace-2779-utf-8-create.xml", false);
355 if (logger.isDebugEnabled()) {
356 logger.debug("Created record with UTF-8 chars in payload.");
357 logger.debug("Attempting to retrieve just-created record ...");
359 CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
360 String distinguishingFeatures = collectionObject.getDistinguishingFeatures();
361 if (logger.isDebugEnabled()) {
362 logger.debug("Sent distinguishingFeatures: " + UTF8_DATA_SAMPLE);
363 logger.debug("Received distinguishingFeatures: " + distinguishingFeatures);
365 Assert.assertTrue(distinguishingFeatures.equals(UTF8_DATA_SAMPLE));
369 * @see org.collectionspace.services.client.test.ServiceTest#createList()
372 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
373 dependsOnMethods = {"create"})
374 public void createList(String testName) throws Exception {
375 this.createPaginatedList(testName, DEFAULT_LIST_SIZE);
379 // Placeholders until the three tests below can be uncommented.
380 // See Issue CSPACE-401.
382 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
385 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
386 public void createWithEmptyEntityBody(String testName) throws Exception {
387 //FIXME: Should this test really be empty?
391 * Test how the service handles XML that is not well formed,
392 * when sent in the payload of a Create request.
394 * @param testName The name of this test method. This name is supplied
395 * automatically, via reflection, by a TestNG 'data provider' in
399 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
400 public void createWithMalformedXml(String testName) throws Exception {
404 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
407 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
408 public void createWithWrongXmlSchema(String testName) throws Exception {
409 //FIXME: Should this test really be empty?
415 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
416 dependsOnMethods = {"create", "testSubmitRequest"})
417 public void createWithEmptyEntityBody(String testName) throwsException {
419 if (logger.isDebugEnabled()) {
420 logger.debug(testBanner(testName, CLASS_NAME));
423 setupCreateWithEmptyEntityBody();
425 // Submit the request to the service and store the response.
426 String method = REQUEST_TYPE.httpMethodName();
427 String url = getServiceRootURL();
428 String mediaType = MediaType.APPLICATION_XML;
429 final String entity = "";
430 int statusCode = submitRequest(method, url, mediaType, entity);
432 // Check the status code of the response: does it match
433 // the expected response(s)?
434 if(logger.isDebugEnabled()){
435 logger.debug(testName + ": url=" + url +
436 " status=" + statusCode);
438 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
439 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
440 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
444 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
445 dependsOnMethods = {"create", "testSubmitRequest"})
446 public void createWithMalformedXml(String testName) throws Exception {
448 if (logger.isDebugEnabled()) {
449 logger.debug(testBanner(testName, CLASS_NAME));
452 setupCreateWithMalformedXml();
454 // Submit the request to the service and store the response.
455 String method = REQUEST_TYPE.httpMethodName();
456 String url = getServiceRootURL();
457 String mediaType = MediaType.APPLICATION_XML;
458 final String entity = MALFORMED_XML_DATA; // Constant from base class.
459 int statusCode = submitRequest(method, url, mediaType, entity);
461 // Check the status code of the response: does it match
462 // the expected response(s)?
463 if(logger.isDebugEnabled()){
464 logger.debug(testName + ": url=" + url +
465 " status=" + statusCode);
467 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
468 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
469 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
473 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
474 dependsOnMethods = {"create", "testSubmitRequest"})
475 public void createWithWrongXmlSchema(String testName) throws Exception {
477 if (logger.isDebugEnabled()) {
478 logger.debug(testBanner(testName, CLASS_NAME));
481 setupCreateWithWrongXmlSchema();
483 // Submit the request to the service and store the response.
484 String method = REQUEST_TYPE.httpMethodName();
485 String url = getServiceRootURL();
486 String mediaType = MediaType.APPLICATION_XML;
487 final String entity = WRONG_XML_SCHEMA_DATA;
488 int statusCode = submitRequest(method, url, mediaType, entity);
490 // Check the status code of the response: does it match
491 // the expected response(s)?
492 if(logger.isDebugEnabled()){
493 logger.debug(testName + ": url=" + url +
494 " status=" + statusCode);
496 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
497 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
498 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 * Test how the service handles, in a Create request, payloads
504 * containing null values (or, in the case of String fields,
505 * empty String values) in one or more fields which must be
506 * present and are required to contain non-empty values.
508 * This is a test of code and/or configuration in the service's
509 * validation routine(s).
511 * @param testName The name of this test method. This name is supplied
512 * automatically, via reflection, by a TestNG 'data provider' in
516 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
517 public void createWithRequiredValuesNullOrEmpty(String testName) throws Exception {
518 if (logger.isDebugEnabled()) {
519 logger.debug(testBanner(testName, CLASS_NAME));
523 // Build a payload with invalid content, by omitting a
524 // field (objectNumber) which must be present, and in which
525 // a non-empty value is required, as enforced by the service's
526 // validation routine(s).
527 CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
529 TitleGroupList titleGroupList = new TitleGroupList();
530 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
531 TitleGroup titleGroup = new TitleGroup();
532 titleGroup.setTitle("a title");
533 titleGroups.add(titleGroup);
534 collectionObject.setTitleGroupList(titleGroupList);
536 ObjectNameList objNameList = new ObjectNameList();
537 List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
538 ObjectNameGroup objectNameGroup = new ObjectNameGroup();
539 objectNameGroup.setObjectName("an object name");
540 objNameGroups.add(objectNameGroup);
541 collectionObject.setObjectNameList(objNameList);
543 // Submit the request to the service and store the response.
544 CollectionObjectClient client = new CollectionObjectClient();
545 PoxPayloadOut multipart =
546 createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
547 ClientResponse<Response> res = client.create(multipart);
548 int statusCode = res.getStatus();
550 // Read the response and verify that the create attempt failed.
551 if (logger.isDebugEnabled()) {
552 logger.debug(testName + ": status = " + statusCode);
554 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
558 // FIXME: Consider splitting off the following into its own test method.
560 // Build a payload with invalid content, by setting a value to the
561 // empty String, in a field (objectNumber) that requires a non-empty
562 // value, as enforced by the service's validation routine(s).
563 collectionObject = new CollectionobjectsCommon();
564 collectionObject.setObjectNumber("");
565 collectionObject.setDistinguishingFeatures("Distinguishing features.");
567 objNameList = new ObjectNameList();
568 objNameGroups = objNameList.getObjectNameGroup();
569 objectNameGroup = new ObjectNameGroup();
570 objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
571 objNameGroups.add(objectNameGroup);
572 collectionObject.setObjectNameList(objNameList);
574 // Submit the request to the service and store the response.
576 createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
577 res = client.create(multipart);
578 statusCode = res.getStatus();
580 // Read the response and verify that the create attempt failed.
581 if (logger.isDebugEnabled()) {
582 logger.debug(testName + ": status = " + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
591 // ---------------------------------------------------------------
592 // CRUD tests : READ tests
593 // ---------------------------------------------------------------
596 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
599 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
600 dependsOnMethods = {"create"})
601 public void read(String testName) throws Exception {
603 if (logger.isDebugEnabled()) {
604 logger.debug(testBanner(testName, CLASS_NAME));
609 // Submit the request to the service and store the response.
610 CollectionObjectClient client = new CollectionObjectClient();
611 ClientResponse<String> res = client.read(knownResourceId);
612 int statusCode = res.getStatus();
614 // Check the status code of the response: does it match
615 // the expected response(s)?
616 if (logger.isDebugEnabled()) {
617 logger.debug(testName + ": status = " + statusCode);
619 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
620 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
621 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
623 // Extract the common part.
624 CollectionobjectsCommon collectionobjectCommon = extractCommonPartValue(testName, res);
626 // Verify the number and contents of values in repeatable fields,
627 // as created in the instance record used for testing.
628 DimensionList dimensionList = collectionobjectCommon.getDimensions();
629 Assert.assertNotNull(dimensionList);
630 List<DimensionGroup> dimensionsGroups = dimensionList.getDimensionGroup();
631 Assert.assertNotNull(dimensionsGroups);
632 Assert.assertTrue(dimensionsGroups.size() > 0);
633 Assert.assertNotNull(dimensionsGroups.get(0));
634 Assert.assertNotNull(dimensionsGroups.get(0).getMeasuredPart());
636 /* No longer part of the "default" domain service tests for the CollectionObject record.
637 if (logger.isDebugEnabled()) {
638 logger.debug(testName + ": Reading Natural History part ...");
641 // Currently checking only that the natural history part is non-null;
642 // can add specific field-level checks as warranted.
643 Object conh = extractPartValue(testName, res, getNHPartName());
644 Assert.assertNotNull(conh);
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
653 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
654 dependsOnMethods = {"read"})
655 public void readNonExistent(String testName) throws Exception {
657 if (logger.isDebugEnabled()) {
658 logger.debug(testBanner(testName, CLASS_NAME));
661 setupReadNonExistent();
663 // Submit the request to the service and store the response.
664 CollectionObjectClient client = new CollectionObjectClient();
665 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
666 int statusCode = res.getStatus();
668 // Check the status code of the response: does it match
669 // the expected response(s)?
670 if (logger.isDebugEnabled()) {
671 logger.debug(testName + ": status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679 // ---------------------------------------------------------------
680 // CRUD tests : READ_LIST tests
681 // ---------------------------------------------------------------
684 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
687 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
688 dependsOnMethods = {"createList", "read"})
689 public void readList(String testName) throws Exception {
691 if (logger.isDebugEnabled()) {
692 logger.debug(testBanner(testName, CLASS_NAME));
697 // Submit the request to the service and store the response.
698 CollectionObjectClient client = new CollectionObjectClient();
699 ClientResponse<CollectionobjectsCommonList> res = client.readList();
700 CollectionobjectsCommonList list = res.getEntity();
701 int statusCode = res.getStatus();
703 // Check the status code of the response: does it match
704 // the expected response(s)?
705 if (logger.isDebugEnabled()) {
706 logger.debug(testName + ": status = " + statusCode);
708 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
709 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
710 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 // Optionally output additional data about list members for debugging.
713 boolean iterateThroughList = false;
714 if (iterateThroughList && logger.isDebugEnabled()) {
715 List<CollectionobjectsCommonList.CollectionObjectListItem> items =
716 list.getCollectionObjectListItem();
719 for (CollectionobjectsCommonList.CollectionObjectListItem item : items) {
720 logger.debug(testName + ": list-item[" + i + "] csid="
722 logger.debug(testName + ": list-item[" + i + "] objectNumber="
723 + item.getObjectNumber());
724 logger.debug(testName + ": list-item[" + i + "] URI="
734 // ---------------------------------------------------------------
735 // CRUD tests : UPDATE tests
736 // ---------------------------------------------------------------
739 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
742 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
743 dependsOnMethods = {"read"})
744 public void update(String testName) throws Exception {
746 if (logger.isDebugEnabled()) {
747 logger.debug(testBanner(testName, CLASS_NAME));
750 // Read an existing resource that will be updated.
751 ClientResponse<String> res = updateRetrieve(testName, knownResourceId);
753 // Extract its common part.
754 CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res);
756 // Change the content of one or more fields in the common part.
758 collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber());
760 // Change the object name in the first value instance in the
761 // object name repeatable group.
762 ObjectNameList objNameList = collectionObjectCommon.getObjectNameList();
763 List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
764 Assert.assertNotNull(objNameGroups);
765 Assert.assertTrue(objNameGroups.size() >= 1);
766 String objectName = objNameGroups.get(0).getObjectName();
767 Assert.assertEquals(objectName, OBJECT_NAME_VALUE);
768 String updatedObjectName = "updated-" + objectName;
769 objNameGroups.get(0).setObjectName(updatedObjectName);
770 collectionObjectCommon.setObjectNameList(objNameList);
772 // Replace the existing value instances in the dimensions repeatable group
773 // with entirely new value instances, also changing the number of such instances.
774 DimensionList dimensionList = collectionObjectCommon.getDimensions();
775 Assert.assertNotNull(dimensionList);
776 List<DimensionGroup> dimensionGroups = dimensionList.getDimensionGroup();
777 Assert.assertNotNull(dimensionGroups);
778 int originalDimensionGroupSize = dimensionGroups.size();
779 Assert.assertTrue(originalDimensionGroupSize >= 1);
781 DimensionGroup updatedDimensionGroup = new DimensionGroup();
782 updatedDimensionGroup.setMeasuredPart(UPDATED_MEASURED_PART_VALUE);
783 dimensionGroups.clear();
784 dimensionGroups.add(updatedDimensionGroup);
785 int updatedDimensionGroupSize = dimensionGroups.size();
786 Assert.assertTrue(updatedDimensionGroupSize >= 1);
787 Assert.assertTrue(updatedDimensionGroupSize != originalDimensionGroupSize);
788 collectionObjectCommon.setDimensions(dimensionList);
790 if (logger.isDebugEnabled()) {
791 logger.debug("sparse update that will be sent in update request:");
792 logger.debug(objectAsXmlString(collectionObjectCommon,
793 CollectionobjectsCommon.class));
796 // Send the changed resource to be updated and read the updated resource
797 // from the response.
798 res = updateSend(testName, knownResourceId, collectionObjectCommon);
800 // Extract its common part.
801 CollectionobjectsCommon updatedCollectionobjectCommon = extractCommonPartValue(testName, res);
803 // Read the updated common part and verify that the resource was correctly updated.
804 objNameList = updatedCollectionobjectCommon.getObjectNameList();
805 Assert.assertNotNull(objNameList);
806 objNameGroups = objNameList.getObjectNameGroup();
807 Assert.assertNotNull(objNameGroups);
808 Assert.assertTrue(objNameGroups.size() >= 1);
809 Assert.assertEquals(updatedObjectName,
810 objNameGroups.get(0).getObjectName(),
811 "Data in updated object did not match submitted data.");
813 dimensionList = updatedCollectionobjectCommon.getDimensions();
814 Assert.assertNotNull(dimensionList);
815 dimensionGroups = dimensionList.getDimensionGroup();
816 Assert.assertNotNull(dimensionGroups);
817 Assert.assertTrue(dimensionGroups.size() == updatedDimensionGroupSize);
818 Assert.assertEquals(UPDATED_MEASURED_PART_VALUE,
819 dimensionGroups.get(0).getMeasuredPart(),
820 "Data in updated object did not match submitted data.");
827 * @param testName the test name
829 * @return the client response
831 private ClientResponse<String> updateRetrieve(String testName, String id) {
833 CollectionObjectClient client = new CollectionObjectClient();
834 ClientResponse<String> res = client.read(knownResourceId);
835 int statusCode = res.getStatus();
836 // Check the status code of the response: does it match
837 // the expected response(s)?
838 if (logger.isDebugEnabled()) {
839 logger.debug(testName + ": read status = " + statusCode);
841 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
842 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
843 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
844 if(logger.isDebugEnabled()){
845 logger.debug("got object to update with ID: " + knownResourceId);
853 * @param testName the test name
855 * @param collectionObject the collection object
856 * @return the client response
858 private ClientResponse<String> updateSend(String testName, String id,
859 CollectionobjectsCommon collectionObjectCommon) {
861 PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
862 PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
863 CollectionObjectClient client = new CollectionObjectClient();
864 commonPart.setLabel(client.getCommonPartName());
865 ClientResponse<String> res = client.update(knownResourceId, output);
866 int statusCode = res.getStatus();
867 // Check the status code of the response: does it match
868 // the expected response(s)?
869 if (logger.isDebugEnabled()) {
870 logger.debug(testName + ": read status = " + statusCode);
872 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
873 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
874 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
879 // Placeholders until the three tests below can be uncommented.
880 // See Issue CSPACE-401.
882 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
885 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
886 dependsOnMethods = {"read"})
887 public void updateWithEmptyEntityBody(String testName) throws Exception {
888 //FIXME: Should this test really be empty?
892 * Test how the service handles XML that is not well formed,
893 * when sent in the payload of an Update request.
895 * @param testName The name of this test method. This name is supplied
896 * automatically, via reflection, by a TestNG 'data provider' in
900 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
901 dependsOnMethods = {"read"})
902 public void updateWithMalformedXml(String testName) throws Exception {
903 //FIXME: Should this test really be empty?
907 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
910 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
911 dependsOnMethods = {"read"})
912 public void updateWithWrongXmlSchema(String testName) throws Exception {
913 //FIXME: Should this test really be empty?
918 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
919 dependsOnMethods = {"create", "update", "testSubmitRequest"})
920 public void updateWithEmptyEntityBody(String testName) throws Exception {
922 if (logger.isDebugEnabled()) {
923 logger.debug(testBanner(testName, CLASS_NAME));
926 setupUpdateWithEmptyEntityBody();
928 // Submit the request to the service and store the response.
929 String method = REQUEST_TYPE.httpMethodName();
930 String url = getResourceURL(knownResourceId);
931 String mediaType = MediaType.APPLICATION_XML;
932 final String entity = "";
933 int statusCode = submitRequest(method, url, mediaType, entity);
935 // Check the status code of the response: does it match
936 // the expected response(s)?
937 if(logger.isDebugEnabled()){
938 logger.debug(testName + ": url=" + url +
939 " status=" + statusCode);
941 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
942 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
943 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
947 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
948 dependsOnMethods = {"create", "update", "testSubmitRequest"})
949 public void updateWithMalformedXml() throws Exception {
951 if (logger.isDebugEnabled()) {
952 logger.debug(testBanner(testName, CLASS_NAME));
955 setupUpdateWithMalformedXml();
957 // Submit the request to the service and store the response.
958 String method = REQUEST_TYPE.httpMethodName();
959 String url = getResourceURL(knownResourceId);
960 final String entity = MALFORMED_XML_DATA;
961 String mediaType = MediaType.APPLICATION_XML;
962 int statusCode = submitRequest(method, url, mediaType, entity);
964 // Check the status code of the response: does it match
965 // the expected response(s)?
966 if(logger.isDebugEnabled()){
967 logger.debug(testName + ": url=" + url +
968 " status=" + statusCode);
970 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
971 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
972 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
976 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
977 dependsOnMethods = {"create", "update", "testSubmitRequest"})
978 public void updateWithWrongXmlSchema(String testName) throws Exception {
980 if (logger.isDebugEnabled()) {
981 logger.debug(testBanner(testName, CLASS_NAME));
984 setupUpdateWithWrongXmlSchema();
986 // Submit the request to the service and store the response.
987 String method = REQUEST_TYPE.httpMethodName();
988 String url = getResourceURL(knownResourceId);
989 String mediaType = MediaType.APPLICATION_XML;
990 final String entity = WRONG_XML_SCHEMA_DATA;
991 int statusCode = submitRequest(method, url, mediaType, entity);
993 // Check the status code of the response: does it match
994 // the expected response(s)?
995 if(logger.isDebugEnabled()){
996 logger.debug(testName + ": url=" + url +
997 " status=" + statusCode);
999 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1000 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1001 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1006 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1009 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1010 dependsOnMethods = {"update", "testSubmitRequest"})
1011 public void updateNonExistent(String testName) throws Exception {
1013 if (logger.isDebugEnabled()) {
1014 logger.debug(testBanner(testName, CLASS_NAME));
1017 setupUpdateNonExistent();
1019 // Submit the request to the service and store the response.
1021 // Note: The ID used in this 'create' call may be arbitrary.
1022 // The only relevant ID may be the one used in updateCollectionObject(), below.
1023 CollectionObjectClient client = new CollectionObjectClient();
1024 PoxPayloadOut multipart =
1025 createCollectionObjectInstance(client.getCommonPartName(), NON_EXISTENT_ID);
1026 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
1027 int statusCode = res.getStatus();
1029 // Check the status code of the response: does it match
1030 // the expected response(s)?
1031 if (logger.isDebugEnabled()) {
1032 logger.debug(testName + ": status = " + statusCode);
1034 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1035 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1036 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1040 * Test how the service handles, in an Update request, payloads
1041 * containing null values (or, in the case of String fields,
1042 * empty String values) in one or more fields in which non-empty
1043 * values are required.
1045 * This is a test of code and/or configuration in the service's
1046 * validation routine(s).
1048 * @param testName The name of this test method. This name is supplied
1049 * automatically, via reflection, by a TestNG 'data provider' in
1053 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1054 dependsOnMethods = {"read"})
1055 public void updateWithRequiredValuesNullOrEmpty(String testName) throws Exception {
1057 if (logger.isDebugEnabled()) {
1058 logger.debug(testBanner(testName, CLASS_NAME));
1061 // Read an existing record for updating.
1062 ClientResponse<String> res = updateRetrieve(testName, knownResourceId);
1064 // Extract its common part.
1065 CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res);
1067 // Update the common part with invalid content, by setting a value to
1068 // the empty String, in a field that requires a non-empty value,
1069 // as enforced by the service's validation routine(s).
1070 collectionObjectCommon.setObjectNumber("");
1072 if (logger.isDebugEnabled()) {
1073 logger.debug(testName + " updated object");
1074 logger.debug(objectAsXmlString(collectionObjectCommon,
1075 CollectionobjectsCommon.class));
1078 // Submit the request to the service and store the response.
1080 PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1081 PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
1082 CollectionObjectClient client = new CollectionObjectClient();
1083 commonPart.setLabel(client.getCommonPartName());
1084 res = client.update(knownResourceId, output);
1085 int statusCode = res.getStatus();
1087 // Read the response and verify that the update attempt failed.
1088 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1089 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1090 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1094 // ---------------------------------------------------------------
1095 // CRUD tests : DELETE tests
1096 // ---------------------------------------------------------------
1099 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1102 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1103 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
1104 public void delete(String testName) throws Exception {
1106 if (logger.isDebugEnabled()) {
1107 logger.debug(testBanner(testName, CLASS_NAME));
1112 // Submit the request to the service and store the response.
1113 CollectionObjectClient client = new CollectionObjectClient();
1114 ClientResponse<Response> res = client.delete(knownResourceId);
1115 int statusCode = res.getStatus();
1117 // Check the status code of the response: does it match
1118 // the expected response(s)?
1119 if (logger.isDebugEnabled()) {
1120 logger.debug(testName + ": status = " + statusCode);
1122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1129 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1132 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1133 dependsOnMethods = {"delete"})
1134 public void deleteNonExistent(String testName) throws Exception {
1136 if (logger.isDebugEnabled()) {
1137 logger.debug(testBanner(testName, CLASS_NAME));
1140 setupDeleteNonExistent();
1142 // Submit the request to the service and store the response.
1143 CollectionObjectClient client = new CollectionObjectClient();
1144 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1145 int statusCode = res.getStatus();
1147 // Check the status code of the response: does it match
1148 // the expected response(s)?
1149 if (logger.isDebugEnabled()) {
1150 logger.debug(testName + ": status = " + statusCode);
1152 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1153 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1154 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1157 // ---------------------------------------------------------------
1158 // Utility tests : tests of code used in tests above
1159 // ---------------------------------------------------------------
1161 * Tests the code for manually submitting data that is used by several
1162 * of the methods above.
1166 @Test(dependsOnMethods = {"create", "read"})
1167 public void testSubmitRequest() throws Exception {
1168 testSubmitRequest(knownResourceId);
1172 * Test submit request.
1174 * @param resourceId the resource id
1175 * @throws Exception the exception
1177 private void testSubmitRequest(String resourceId) throws Exception {
1179 // Expected status code: 200 OK
1180 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1182 // Submit the request to the service and store the response.
1183 String method = ServiceRequestType.READ.httpMethodName();
1184 String url = getResourceURL(resourceId);
1185 int statusCode = submitRequest(method, url);
1187 // Check the status code of the response: does it match
1188 // the expected response(s)?
1189 if (logger.isDebugEnabled()) {
1190 logger.debug("testSubmitRequest: url=" + url
1191 + " status=" + statusCode);
1193 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1197 // ---------------------------------------------------------------
1198 // Utility methods used by tests above
1199 // ---------------------------------------------------------------
1201 * Creates the collection object instance.
1203 * @param commonPartName the common part name
1204 * @param identifier the identifier
1205 * @return the multipart output
1207 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1208 String identifier) {
1209 return createCollectionObjectInstance(commonPartName,
1210 "objectNumber-" + identifier,
1211 "objectName-" + identifier);
1215 protected PoxPayloadOut createInstance(String identifier) {
1216 String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME;
1217 return createCollectionObjectInstance(commonPartName, identifier);
1221 * Creates the collection object instance.
1223 * @param commonPartName the common part name
1224 * @param objectNumber the object number
1225 * @param objectName the object name
1226 * @return the multipart output
1228 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1229 String objectNumber, String objectName) {
1230 CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
1233 OtherNumber remNumber = new OtherNumber();
1234 remNumber.setNumberType("remNumber");
1235 remNumber.setNumberValue("2271966-" + System.currentTimeMillis());
1236 collectionObject.setRemNumber(remNumber);
1239 collectionObject.setObjectNumber(objectNumber);
1240 collectionObject.setAge(""); //test for null string
1242 // FIXME this can be removed when the repeatable other number list
1243 // is supported by the application layers
1244 collectionObject.setOtherNumber("urn:org.walkerart.id:123");
1246 // Repeatable structured groups
1248 TitleGroupList titleGroupList = new TitleGroupList();
1249 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
1250 TitleGroup titleGroup = new TitleGroup();
1251 titleGroup.setTitle("a title");
1252 titleGroups.add(titleGroup);
1253 collectionObject.setTitleGroupList(titleGroupList);
1255 ObjectNameList objNameList = new ObjectNameList();
1256 List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1257 ObjectNameGroup objectNameGroup = new ObjectNameGroup();
1258 objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
1259 objNameGroups.add(objectNameGroup);
1260 collectionObject.setObjectNameList(objNameList);
1262 DimensionList dimensionList = new DimensionList();
1263 List<DimensionGroup> dimensionGroups = dimensionList.getDimensionGroup();
1264 DimensionGroup dimensionGroup1 = new DimensionGroup();
1265 dimensionGroup1.setMeasuredPart("head");
1266 dimensionGroup1.setDimension("length");
1267 dimensionGroup1.setValue("30");
1268 dimensionGroup1.setMeasurementUnit("cm");
1269 DimensionGroup dimensionGroup2 = new DimensionGroup();
1270 dimensionGroup2.setMeasuredPart("leg");
1271 dimensionGroup2.setDimension("width");
1272 dimensionGroup2.setValue("2.57");
1273 dimensionGroup2.setMeasurementUnit("m");
1274 dimensionGroup2.setValueQualifier(""); // test null string
1275 dimensionGroups.add(dimensionGroup1);
1276 dimensionGroups.add(dimensionGroup2);
1277 collectionObject.setDimensions(dimensionList);
1279 // Repeatable scalar fields
1281 BriefDescriptionList descriptionList = new BriefDescriptionList();
1282 List<String> descriptions = descriptionList.getBriefDescription();
1283 descriptions.add("Papier mache bird cow mask with horns, "
1284 + "painted red with black and yellow spots. "
1285 + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns).");
1286 descriptions.add("Acrylic rabbit mask with wings, "
1287 + "painted red with green and aquamarine spots. "
1288 + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with wings).");
1289 collectionObject.setBriefDescriptions(descriptionList);
1291 ResponsibleDepartmentList deptList = new ResponsibleDepartmentList();
1292 List<String> depts = deptList.getResponsibleDepartment();
1293 // @TODO Use properly formatted refNames for representative departments
1294 // in this example test record. The following are mere placeholders.
1295 depts.add("urn:org.collectionspace.services.department:Registrar");
1296 depts.add("urn:org.walkerart.department:Fine Art");
1297 collectionObject.setResponsibleDepartments(deptList);
1299 OtherNumberList otherNumList = new OtherNumberList();
1300 List<OtherNumber> otherNumbers = otherNumList.getOtherNumber();
1301 OtherNumber otherNumber1 = new OtherNumber();
1302 otherNumber1.setNumberValue("101." + objectName);
1303 otherNumber1.setNumberType("integer");
1304 otherNumbers.add(otherNumber1);
1305 OtherNumber otherNumber2 = new OtherNumber();
1306 otherNumber2.setNumberValue("101.502.23.456." + objectName);
1307 otherNumber2.setNumberType("ipaddress");
1308 otherNumbers.add(otherNumber2);
1309 collectionObject.setOtherNumberList(otherNumList);
1311 // Add instances of fields from an extension schema
1313 CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
1314 conh.setNhString("test-string");
1316 conh.setNhLong(9999);
1318 PoxPayloadOut multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
1323 * Creates the collection object instance.
1325 * @param commonPartName the common part name
1326 * @param collectionObject the collection object
1327 * @param conh the conh
1328 * @return the multipart output
1330 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1331 CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
1333 PoxPayloadOut multipart = CollectionObjectFactory.createCollectionObjectInstance(
1334 commonPartName, collectionObject, getNHPartName(), conh);
1335 if (logger.isDebugEnabled()) {
1336 logger.debug("to be created, collectionobject common");
1337 logger.debug(objectAsXmlString(collectionObject,
1338 CollectionobjectsCommon.class));
1342 if (logger.isDebugEnabled()) {
1343 logger.debug("to be created, collectionobject nhistory");
1344 logger.debug(objectAsXmlString(conh,
1345 CollectionobjectsNaturalhistory.class));
1353 * createCollectionObjectInstanceFromXml uses JAXB unmarshaller to retrieve
1354 * collectionobject from given file
1355 * @param commonPartName
1356 * @param commonPartFileName
1360 private PoxPayloadOut createCollectionObjectInstanceFromXml(String testName, String commonPartName,
1361 String commonPartFileName) throws Exception {
1363 CollectionobjectsCommon collectionObject =
1364 (CollectionobjectsCommon) getObjectFromFile(CollectionobjectsCommon.class,
1365 commonPartFileName);
1366 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1367 PayloadOutputPart commonPart = multipart.addPart(collectionObject,
1368 MediaType.APPLICATION_XML_TYPE);
1369 CollectionObjectClient client = new CollectionObjectClient();
1370 commonPart.setLabel(client.getCommonPartName());
1372 if (logger.isDebugEnabled()) {
1373 logger.debug(testName + " to be created, collectionobject common");
1374 logger.debug(objectAsXmlString(collectionObject,
1375 CollectionobjectsCommon.class));
1382 * createCollectionObjectInstanceFromRawXml uses stringified collectionobject
1383 * retrieve from given file
1384 * @param commonPartName
1385 * @param commonPartFileName
1389 private PoxPayloadOut createCollectionObjectInstanceFromRawXml(String testName, String commonPartName,
1390 String commonPartFileName) throws Exception {
1392 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1393 String stringObject = getXmlDocumentAsString(commonPartFileName);
1394 if (logger.isDebugEnabled()) {
1395 logger.debug(testName + " to be created, collectionobject common " + "\n" + stringObject);
1397 PayloadOutputPart commonPart = multipart.addPart(commonPartName, stringObject);
1398 // commonPart.setLabel(commonPartName);
1404 * Gets the nH part name.
1406 * @return the nH part name
1408 private String getNHPartName() {
1409 return "collectionobjects_naturalhistory";
1413 * Creates the from xml file.
1415 * @param testName the test name
1416 * @param fileName the file name
1417 * @param useJaxb the use jaxb
1418 * @return the string
1419 * @throws Exception the exception
1421 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
1426 PoxPayloadOut multipart = null;
1428 CollectionObjectClient client = new CollectionObjectClient();
1430 multipart = createCollectionObjectInstanceFromXml(testName,
1431 client.getCommonPartName(), fileName);
1433 multipart = createCollectionObjectInstanceFromRawXml(testName,
1434 client.getCommonPartName(), fileName);
1436 ClientResponse<Response> res = client.create(multipart);
1437 int statusCode = res.getStatus();
1439 if (logger.isDebugEnabled()) {
1440 logger.debug(testName + ": status = " + statusCode);
1442 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1443 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1444 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1445 String newId = extractId(res);
1446 allResourceIdsCreated.add(newId);
1450 // FIXME: This duplicates code in read(), and should be consolidated.
1451 // This is an expedient to support reading and verifying the contents
1452 // of resources that have been created from test data XML files.
1453 private CollectionobjectsCommon readCollectionObjectCommonPart(String csid)
1456 String testName = "readCollectionObjectCommonPart";
1460 // Submit the request to the service and store the response.
1461 CollectionObjectClient client = new CollectionObjectClient();
1462 ClientResponse<String> res = client.read(csid);
1463 int statusCode = res.getStatus();
1465 // Check the status code of the response: does it match
1466 // the expected response(s)?
1467 if (logger.isDebugEnabled()) {
1468 logger.debug(testName + ": status = " + statusCode);
1470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1474 // Extract the common part.
1475 CollectionobjectsCommon collectionObject = extractCommonPartValue(testName, res);
1476 Assert.assertNotNull(collectionObject);
1478 return collectionObject;
1481 private CollectionobjectsCommon extractCommonPartValue(String testName, ClientResponse<String> res)
1483 CollectionObjectClient client = new CollectionObjectClient();
1484 PayloadInputPart payloadInputPart = extractPart(testName, res, client.getCommonPartName());
1486 if (payloadInputPart != null) {
1487 obj = payloadInputPart.getBody();
1489 Assert.assertNotNull(obj,
1490 testName + ": body of " + client.getCommonPartName() + " part was unexpectedly null.");
1491 CollectionobjectsCommon collectionobjectCommon = (CollectionobjectsCommon) obj;
1492 Assert.assertNotNull(collectionobjectCommon,
1493 testName + ": " + client.getCommonPartName() + " part was unexpectedly null.");
1494 return collectionobjectCommon;
1497 private Object extractPartValue(String testName, ClientResponse<String> res, String partLabel)
1500 PayloadInputPart payloadInputPart = extractPart(testName, res, partLabel);
1501 if (payloadInputPart != null) {
1502 obj = payloadInputPart.getElementBody();
1504 Assert.assertNotNull(obj,
1505 testName + ": value of part " + partLabel + " was unexpectedly null.");
1509 private PayloadInputPart extractPart(String testName, ClientResponse<String> res, String partLabel)
1511 if (logger.isDebugEnabled()) {
1512 logger.debug(testName + ": Reading part " + partLabel + " ...");
1514 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1515 PayloadInputPart payloadInputPart = input.getPart(partLabel);
1516 Assert.assertNotNull(payloadInputPart,
1517 testName + ": part " + partLabel + " was unexpectedly null.");
1518 return payloadInputPart;
1522 protected String getServicePathComponent() {
1523 // TODO Auto-generated method stub
1524 return CollectionObjectClient.SERVICE_PATH_COMPONENT;