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 if (logger.isDebugEnabled()) {
637 logger.debug(testName + ": Reading Natural History part ...");
640 // Currently checking only that the natural history part is non-null;
641 // can add specific field-level checks as warranted.
642 Object conh = extractPartValue(testName, res, getNHPartName());
643 Assert.assertNotNull(conh);
648 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
651 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
652 dependsOnMethods = {"read"})
653 public void readNonExistent(String testName) throws Exception {
655 if (logger.isDebugEnabled()) {
656 logger.debug(testBanner(testName, CLASS_NAME));
659 setupReadNonExistent();
661 // Submit the request to the service and store the response.
662 CollectionObjectClient client = new CollectionObjectClient();
663 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
664 int statusCode = res.getStatus();
666 // Check the status code of the response: does it match
667 // the expected response(s)?
668 if (logger.isDebugEnabled()) {
669 logger.debug(testName + ": status = " + statusCode);
671 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
672 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
673 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 // ---------------------------------------------------------------
678 // CRUD tests : READ_LIST tests
679 // ---------------------------------------------------------------
682 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
685 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
686 dependsOnMethods = {"createList", "read"})
687 public void readList(String testName) throws Exception {
689 if (logger.isDebugEnabled()) {
690 logger.debug(testBanner(testName, CLASS_NAME));
695 // Submit the request to the service and store the response.
696 CollectionObjectClient client = new CollectionObjectClient();
697 ClientResponse<CollectionobjectsCommonList> res = client.readList();
698 CollectionobjectsCommonList list = res.getEntity();
699 int statusCode = res.getStatus();
701 // Check the status code of the response: does it match
702 // the expected response(s)?
703 if (logger.isDebugEnabled()) {
704 logger.debug(testName + ": status = " + statusCode);
706 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
707 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
708 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
710 // Optionally output additional data about list members for debugging.
711 boolean iterateThroughList = false;
712 if (iterateThroughList && logger.isDebugEnabled()) {
713 List<CollectionobjectsCommonList.CollectionObjectListItem> items =
714 list.getCollectionObjectListItem();
717 for (CollectionobjectsCommonList.CollectionObjectListItem item : items) {
718 logger.debug(testName + ": list-item[" + i + "] csid="
720 logger.debug(testName + ": list-item[" + i + "] objectNumber="
721 + item.getObjectNumber());
722 logger.debug(testName + ": list-item[" + i + "] URI="
732 // ---------------------------------------------------------------
733 // CRUD tests : UPDATE tests
734 // ---------------------------------------------------------------
737 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
740 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
741 dependsOnMethods = {"read"})
742 public void update(String testName) throws Exception {
744 if (logger.isDebugEnabled()) {
745 logger.debug(testBanner(testName, CLASS_NAME));
748 // Read an existing resource that will be updated.
749 ClientResponse<String> res = updateRetrieve(testName, knownResourceId);
751 // Extract its common part.
752 CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res);
754 // Change the content of one or more fields in the common part.
756 collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber());
758 // Change the object name in the first value instance in the
759 // object name repeatable group.
760 ObjectNameList objNameList = collectionObjectCommon.getObjectNameList();
761 List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
762 Assert.assertNotNull(objNameGroups);
763 Assert.assertTrue(objNameGroups.size() >= 1);
764 String objectName = objNameGroups.get(0).getObjectName();
765 Assert.assertEquals(objectName, OBJECT_NAME_VALUE);
766 String updatedObjectName = "updated-" + objectName;
767 objNameGroups.get(0).setObjectName(updatedObjectName);
768 collectionObjectCommon.setObjectNameList(objNameList);
770 // Replace the existing value instances in the dimensions repeatable group
771 // with entirely new value instances, also changing the number of such instances.
772 DimensionList dimensionList = collectionObjectCommon.getDimensions();
773 Assert.assertNotNull(dimensionList);
774 List<DimensionGroup> dimensionGroups = dimensionList.getDimensionGroup();
775 Assert.assertNotNull(dimensionGroups);
776 int originalDimensionGroupSize = dimensionGroups.size();
777 Assert.assertTrue(originalDimensionGroupSize >= 1);
779 DimensionGroup updatedDimensionGroup = new DimensionGroup();
780 updatedDimensionGroup.setMeasuredPart(UPDATED_MEASURED_PART_VALUE);
781 dimensionGroups.clear();
782 dimensionGroups.add(updatedDimensionGroup);
783 int updatedDimensionGroupSize = dimensionGroups.size();
784 Assert.assertTrue(updatedDimensionGroupSize >= 1);
785 Assert.assertTrue(updatedDimensionGroupSize != originalDimensionGroupSize);
786 collectionObjectCommon.setDimensions(dimensionList);
788 if (logger.isDebugEnabled()) {
789 logger.debug("sparse update that will be sent in update request:");
790 logger.debug(objectAsXmlString(collectionObjectCommon,
791 CollectionobjectsCommon.class));
794 // Send the changed resource to be updated and read the updated resource
795 // from the response.
796 res = updateSend(testName, knownResourceId, collectionObjectCommon);
798 // Extract its common part.
799 CollectionobjectsCommon updatedCollectionobjectCommon = extractCommonPartValue(testName, res);
801 // Read the updated common part and verify that the resource was correctly updated.
802 objNameList = updatedCollectionobjectCommon.getObjectNameList();
803 Assert.assertNotNull(objNameList);
804 objNameGroups = objNameList.getObjectNameGroup();
805 Assert.assertNotNull(objNameGroups);
806 Assert.assertTrue(objNameGroups.size() >= 1);
807 Assert.assertEquals(updatedObjectName,
808 objNameGroups.get(0).getObjectName(),
809 "Data in updated object did not match submitted data.");
811 dimensionList = updatedCollectionobjectCommon.getDimensions();
812 Assert.assertNotNull(dimensionList);
813 dimensionGroups = dimensionList.getDimensionGroup();
814 Assert.assertNotNull(dimensionGroups);
815 Assert.assertTrue(dimensionGroups.size() == updatedDimensionGroupSize);
816 Assert.assertEquals(UPDATED_MEASURED_PART_VALUE,
817 dimensionGroups.get(0).getMeasuredPart(),
818 "Data in updated object did not match submitted data.");
825 * @param testName the test name
827 * @return the client response
829 private ClientResponse<String> updateRetrieve(String testName, String id) {
831 CollectionObjectClient client = new CollectionObjectClient();
832 ClientResponse<String> res = client.read(knownResourceId);
833 int statusCode = res.getStatus();
834 // Check the status code of the response: does it match
835 // the expected response(s)?
836 if (logger.isDebugEnabled()) {
837 logger.debug(testName + ": read status = " + statusCode);
839 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
840 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
841 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
842 if(logger.isDebugEnabled()){
843 logger.debug("got object to update with ID: " + knownResourceId);
851 * @param testName the test name
853 * @param collectionObject the collection object
854 * @return the client response
856 private ClientResponse<String> updateSend(String testName, String id,
857 CollectionobjectsCommon collectionObjectCommon) {
859 PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
860 PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
861 CollectionObjectClient client = new CollectionObjectClient();
862 commonPart.setLabel(client.getCommonPartName());
863 ClientResponse<String> res = client.update(knownResourceId, output);
864 int statusCode = res.getStatus();
865 // Check the status code of the response: does it match
866 // the expected response(s)?
867 if (logger.isDebugEnabled()) {
868 logger.debug(testName + ": read status = " + statusCode);
870 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
871 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
872 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
877 // Placeholders until the three tests below can be uncommented.
878 // See Issue CSPACE-401.
880 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
883 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
884 dependsOnMethods = {"read"})
885 public void updateWithEmptyEntityBody(String testName) throws Exception {
886 //FIXME: Should this test really be empty?
890 * Test how the service handles XML that is not well formed,
891 * when sent in the payload of an Update request.
893 * @param testName The name of this test method. This name is supplied
894 * automatically, via reflection, by a TestNG 'data provider' in
898 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
899 dependsOnMethods = {"read"})
900 public void updateWithMalformedXml(String testName) throws Exception {
901 //FIXME: Should this test really be empty?
905 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
908 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
909 dependsOnMethods = {"read"})
910 public void updateWithWrongXmlSchema(String testName) throws Exception {
911 //FIXME: Should this test really be empty?
916 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
917 dependsOnMethods = {"create", "update", "testSubmitRequest"})
918 public void updateWithEmptyEntityBody(String testName) throws Exception {
920 if (logger.isDebugEnabled()) {
921 logger.debug(testBanner(testName, CLASS_NAME));
924 setupUpdateWithEmptyEntityBody();
926 // Submit the request to the service and store the response.
927 String method = REQUEST_TYPE.httpMethodName();
928 String url = getResourceURL(knownResourceId);
929 String mediaType = MediaType.APPLICATION_XML;
930 final String entity = "";
931 int statusCode = submitRequest(method, url, mediaType, entity);
933 // Check the status code of the response: does it match
934 // the expected response(s)?
935 if(logger.isDebugEnabled()){
936 logger.debug(testName + ": url=" + url +
937 " status=" + statusCode);
939 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
940 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
941 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
945 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
946 dependsOnMethods = {"create", "update", "testSubmitRequest"})
947 public void updateWithMalformedXml() throws Exception {
949 if (logger.isDebugEnabled()) {
950 logger.debug(testBanner(testName, CLASS_NAME));
953 setupUpdateWithMalformedXml();
955 // Submit the request to the service and store the response.
956 String method = REQUEST_TYPE.httpMethodName();
957 String url = getResourceURL(knownResourceId);
958 final String entity = MALFORMED_XML_DATA;
959 String mediaType = MediaType.APPLICATION_XML;
960 int statusCode = submitRequest(method, url, mediaType, entity);
962 // Check the status code of the response: does it match
963 // the expected response(s)?
964 if(logger.isDebugEnabled()){
965 logger.debug(testName + ": url=" + url +
966 " status=" + statusCode);
968 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
969 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
970 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
974 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
975 dependsOnMethods = {"create", "update", "testSubmitRequest"})
976 public void updateWithWrongXmlSchema(String testName) throws Exception {
978 if (logger.isDebugEnabled()) {
979 logger.debug(testBanner(testName, CLASS_NAME));
982 setupUpdateWithWrongXmlSchema();
984 // Submit the request to the service and store the response.
985 String method = REQUEST_TYPE.httpMethodName();
986 String url = getResourceURL(knownResourceId);
987 String mediaType = MediaType.APPLICATION_XML;
988 final String entity = WRONG_XML_SCHEMA_DATA;
989 int statusCode = submitRequest(method, url, mediaType, entity);
991 // Check the status code of the response: does it match
992 // the expected response(s)?
993 if(logger.isDebugEnabled()){
994 logger.debug(testName + ": url=" + url +
995 " status=" + statusCode);
997 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
998 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
999 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1004 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1007 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1008 dependsOnMethods = {"update", "testSubmitRequest"})
1009 public void updateNonExistent(String testName) throws Exception {
1011 if (logger.isDebugEnabled()) {
1012 logger.debug(testBanner(testName, CLASS_NAME));
1015 setupUpdateNonExistent();
1017 // Submit the request to the service and store the response.
1019 // Note: The ID used in this 'create' call may be arbitrary.
1020 // The only relevant ID may be the one used in updateCollectionObject(), below.
1021 CollectionObjectClient client = new CollectionObjectClient();
1022 PoxPayloadOut multipart =
1023 createCollectionObjectInstance(client.getCommonPartName(), NON_EXISTENT_ID);
1024 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
1025 int statusCode = res.getStatus();
1027 // Check the status code of the response: does it match
1028 // the expected response(s)?
1029 if (logger.isDebugEnabled()) {
1030 logger.debug(testName + ": status = " + statusCode);
1032 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1033 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1034 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1038 * Test how the service handles, in an Update request, payloads
1039 * containing null values (or, in the case of String fields,
1040 * empty String values) in one or more fields in which non-empty
1041 * values are required.
1043 * This is a test of code and/or configuration in the service's
1044 * validation routine(s).
1046 * @param testName The name of this test method. This name is supplied
1047 * automatically, via reflection, by a TestNG 'data provider' in
1051 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1052 dependsOnMethods = {"read"})
1053 public void updateWithRequiredValuesNullOrEmpty(String testName) throws Exception {
1055 if (logger.isDebugEnabled()) {
1056 logger.debug(testBanner(testName, CLASS_NAME));
1059 // Read an existing record for updating.
1060 ClientResponse<String> res = updateRetrieve(testName, knownResourceId);
1062 // Extract its common part.
1063 CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res);
1065 // Update the common part with invalid content, by setting a value to
1066 // the empty String, in a field that requires a non-empty value,
1067 // as enforced by the service's validation routine(s).
1068 collectionObjectCommon.setObjectNumber("");
1070 if (logger.isDebugEnabled()) {
1071 logger.debug(testName + " updated object");
1072 logger.debug(objectAsXmlString(collectionObjectCommon,
1073 CollectionobjectsCommon.class));
1076 // Submit the request to the service and store the response.
1078 PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1079 PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
1080 CollectionObjectClient client = new CollectionObjectClient();
1081 commonPart.setLabel(client.getCommonPartName());
1082 res = client.update(knownResourceId, output);
1083 int statusCode = res.getStatus();
1085 // Read the response and verify that the update attempt failed.
1086 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1087 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1088 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1092 // ---------------------------------------------------------------
1093 // CRUD tests : DELETE tests
1094 // ---------------------------------------------------------------
1097 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1101 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
1102 public void delete(String testName) throws Exception {
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testBanner(testName, CLASS_NAME));
1110 // Submit the request to the service and store the response.
1111 CollectionObjectClient client = new CollectionObjectClient();
1112 ClientResponse<Response> res = client.delete(knownResourceId);
1113 int statusCode = res.getStatus();
1115 // Check the status code of the response: does it match
1116 // the expected response(s)?
1117 if (logger.isDebugEnabled()) {
1118 logger.debug(testName + ": status = " + statusCode);
1120 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1121 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1122 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1127 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1130 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1131 dependsOnMethods = {"delete"})
1132 public void deleteNonExistent(String testName) throws Exception {
1134 if (logger.isDebugEnabled()) {
1135 logger.debug(testBanner(testName, CLASS_NAME));
1138 setupDeleteNonExistent();
1140 // Submit the request to the service and store the response.
1141 CollectionObjectClient client = new CollectionObjectClient();
1142 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1143 int statusCode = res.getStatus();
1145 // Check the status code of the response: does it match
1146 // the expected response(s)?
1147 if (logger.isDebugEnabled()) {
1148 logger.debug(testName + ": status = " + statusCode);
1150 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1151 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1152 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1155 // ---------------------------------------------------------------
1156 // Utility tests : tests of code used in tests above
1157 // ---------------------------------------------------------------
1159 * Tests the code for manually submitting data that is used by several
1160 * of the methods above.
1164 @Test(dependsOnMethods = {"create", "read"})
1165 public void testSubmitRequest() throws Exception {
1166 testSubmitRequest(knownResourceId);
1170 * Test submit request.
1172 * @param resourceId the resource id
1173 * @throws Exception the exception
1175 private void testSubmitRequest(String resourceId) throws Exception {
1177 // Expected status code: 200 OK
1178 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1180 // Submit the request to the service and store the response.
1181 String method = ServiceRequestType.READ.httpMethodName();
1182 String url = getResourceURL(resourceId);
1183 int statusCode = submitRequest(method, url);
1185 // Check the status code of the response: does it match
1186 // the expected response(s)?
1187 if (logger.isDebugEnabled()) {
1188 logger.debug("testSubmitRequest: url=" + url
1189 + " status=" + statusCode);
1191 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1195 // ---------------------------------------------------------------
1196 // Utility methods used by tests above
1197 // ---------------------------------------------------------------
1199 * Creates the collection object instance.
1201 * @param commonPartName the common part name
1202 * @param identifier the identifier
1203 * @return the multipart output
1205 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1206 String identifier) {
1207 return createCollectionObjectInstance(commonPartName,
1208 "objectNumber-" + identifier,
1209 "objectName-" + identifier);
1213 protected PoxPayloadOut createInstance(String identifier) {
1214 String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME;
1215 return createCollectionObjectInstance(commonPartName, identifier);
1219 * Creates the collection object instance.
1221 * @param commonPartName the common part name
1222 * @param objectNumber the object number
1223 * @param objectName the object name
1224 * @return the multipart output
1226 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1227 String objectNumber, String objectName) {
1228 CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
1231 OtherNumber remNumber = new OtherNumber();
1232 remNumber.setNumberType("remNumber");
1233 remNumber.setNumberValue("2271966-" + System.currentTimeMillis());
1234 collectionObject.setRemNumber(remNumber);
1237 collectionObject.setObjectNumber(objectNumber);
1238 collectionObject.setAge(""); //test for null string
1240 // FIXME this can be removed when the repeatable other number list
1241 // is supported by the application layers
1242 collectionObject.setOtherNumber("urn:org.walkerart.id:123");
1244 // Repeatable structured groups
1246 TitleGroupList titleGroupList = new TitleGroupList();
1247 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
1248 TitleGroup titleGroup = new TitleGroup();
1249 titleGroup.setTitle("a title");
1250 titleGroups.add(titleGroup);
1251 collectionObject.setTitleGroupList(titleGroupList);
1253 ObjectNameList objNameList = new ObjectNameList();
1254 List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1255 ObjectNameGroup objectNameGroup = new ObjectNameGroup();
1256 objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
1257 objNameGroups.add(objectNameGroup);
1258 collectionObject.setObjectNameList(objNameList);
1260 DimensionList dimensionList = new DimensionList();
1261 List<DimensionGroup> dimensionGroups = dimensionList.getDimensionGroup();
1262 DimensionGroup dimensionGroup1 = new DimensionGroup();
1263 dimensionGroup1.setMeasuredPart("head");
1264 dimensionGroup1.setDimension("length");
1265 dimensionGroup1.setValue("30");
1266 dimensionGroup1.setMeasurementUnit("cm");
1267 DimensionGroup dimensionGroup2 = new DimensionGroup();
1268 dimensionGroup2.setMeasuredPart("leg");
1269 dimensionGroup2.setDimension("width");
1270 dimensionGroup2.setValue("2.57");
1271 dimensionGroup2.setMeasurementUnit("m");
1272 dimensionGroup2.setValueQualifier(""); // test null string
1273 dimensionGroups.add(dimensionGroup1);
1274 dimensionGroups.add(dimensionGroup2);
1275 collectionObject.setDimensions(dimensionList);
1277 // Repeatable scalar fields
1279 BriefDescriptionList descriptionList = new BriefDescriptionList();
1280 List<String> descriptions = descriptionList.getBriefDescription();
1281 descriptions.add("Papier mache bird cow mask with horns, "
1282 + "painted red with black and yellow spots. "
1283 + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns).");
1284 descriptions.add("Acrylic rabbit mask with wings, "
1285 + "painted red with green and aquamarine spots. "
1286 + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with wings).");
1287 collectionObject.setBriefDescriptions(descriptionList);
1289 ResponsibleDepartmentList deptList = new ResponsibleDepartmentList();
1290 List<String> depts = deptList.getResponsibleDepartment();
1291 // @TODO Use properly formatted refNames for representative departments
1292 // in this example test record. The following are mere placeholders.
1293 depts.add("urn:org.collectionspace.services.department:Registrar");
1294 depts.add("urn:org.walkerart.department:Fine Art");
1295 collectionObject.setResponsibleDepartments(deptList);
1297 OtherNumberList otherNumList = new OtherNumberList();
1298 List<OtherNumber> otherNumbers = otherNumList.getOtherNumber();
1299 OtherNumber otherNumber1 = new OtherNumber();
1300 otherNumber1.setNumberValue("101." + objectName);
1301 otherNumber1.setNumberType("integer");
1302 otherNumbers.add(otherNumber1);
1303 OtherNumber otherNumber2 = new OtherNumber();
1304 otherNumber2.setNumberValue("101.502.23.456." + objectName);
1305 otherNumber2.setNumberType("ipaddress");
1306 otherNumbers.add(otherNumber2);
1307 collectionObject.setOtherNumberList(otherNumList);
1309 // Add instances of fields from an extension schema
1311 CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
1312 conh.setNhString("test-string");
1314 conh.setNhLong(9999);
1316 PoxPayloadOut multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
1321 * Creates the collection object instance.
1323 * @param commonPartName the common part name
1324 * @param collectionObject the collection object
1325 * @param conh the conh
1326 * @return the multipart output
1328 private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1329 CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
1331 PoxPayloadOut multipart = CollectionObjectFactory.createCollectionObjectInstance(
1332 commonPartName, collectionObject, getNHPartName(), conh);
1333 if (logger.isDebugEnabled()) {
1334 logger.debug("to be created, collectionobject common");
1335 logger.debug(objectAsXmlString(collectionObject,
1336 CollectionobjectsCommon.class));
1340 if (logger.isDebugEnabled()) {
1341 logger.debug("to be created, collectionobject nhistory");
1342 logger.debug(objectAsXmlString(conh,
1343 CollectionobjectsNaturalhistory.class));
1351 * createCollectionObjectInstanceFromXml uses JAXB unmarshaller to retrieve
1352 * collectionobject from given file
1353 * @param commonPartName
1354 * @param commonPartFileName
1358 private PoxPayloadOut createCollectionObjectInstanceFromXml(String testName, String commonPartName,
1359 String commonPartFileName) throws Exception {
1361 CollectionobjectsCommon collectionObject =
1362 (CollectionobjectsCommon) getObjectFromFile(CollectionobjectsCommon.class,
1363 commonPartFileName);
1364 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1365 PayloadOutputPart commonPart = multipart.addPart(collectionObject,
1366 MediaType.APPLICATION_XML_TYPE);
1367 CollectionObjectClient client = new CollectionObjectClient();
1368 commonPart.setLabel(client.getCommonPartName());
1370 if (logger.isDebugEnabled()) {
1371 logger.debug(testName + " to be created, collectionobject common");
1372 logger.debug(objectAsXmlString(collectionObject,
1373 CollectionobjectsCommon.class));
1380 * createCollectionObjectInstanceFromRawXml uses stringified collectionobject
1381 * retrieve from given file
1382 * @param commonPartName
1383 * @param commonPartFileName
1387 private PoxPayloadOut createCollectionObjectInstanceFromRawXml(String testName, String commonPartName,
1388 String commonPartFileName) throws Exception {
1390 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1391 String stringObject = getXmlDocumentAsString(commonPartFileName);
1392 if (logger.isDebugEnabled()) {
1393 logger.debug(testName + " to be created, collectionobject common " + "\n" + stringObject);
1395 PayloadOutputPart commonPart = multipart.addPart(commonPartName, stringObject);
1396 // commonPart.setLabel(commonPartName);
1402 * Gets the nH part name.
1404 * @return the nH part name
1406 private String getNHPartName() {
1407 return "collectionobjects_naturalhistory";
1411 * Creates the from xml file.
1413 * @param testName the test name
1414 * @param fileName the file name
1415 * @param useJaxb the use jaxb
1416 * @return the string
1417 * @throws Exception the exception
1419 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
1424 PoxPayloadOut multipart = null;
1426 CollectionObjectClient client = new CollectionObjectClient();
1428 multipart = createCollectionObjectInstanceFromXml(testName,
1429 client.getCommonPartName(), fileName);
1431 multipart = createCollectionObjectInstanceFromRawXml(testName,
1432 client.getCommonPartName(), fileName);
1434 ClientResponse<Response> res = client.create(multipart);
1435 int statusCode = res.getStatus();
1437 if (logger.isDebugEnabled()) {
1438 logger.debug(testName + ": status = " + statusCode);
1440 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1441 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1442 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1443 String newId = extractId(res);
1444 allResourceIdsCreated.add(newId);
1448 // FIXME: This duplicates code in read(), and should be consolidated.
1449 // This is an expedient to support reading and verifying the contents
1450 // of resources that have been created from test data XML files.
1451 private CollectionobjectsCommon readCollectionObjectCommonPart(String csid)
1454 String testName = "readCollectionObjectCommonPart";
1458 // Submit the request to the service and store the response.
1459 CollectionObjectClient client = new CollectionObjectClient();
1460 ClientResponse<String> res = client.read(csid);
1461 int statusCode = res.getStatus();
1463 // Check the status code of the response: does it match
1464 // the expected response(s)?
1465 if (logger.isDebugEnabled()) {
1466 logger.debug(testName + ": status = " + statusCode);
1468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1472 // Extract the common part.
1473 CollectionobjectsCommon collectionObject = extractCommonPartValue(testName, res);
1474 Assert.assertNotNull(collectionObject);
1476 return collectionObject;
1479 private CollectionobjectsCommon extractCommonPartValue(String testName, ClientResponse<String> res)
1481 CollectionObjectClient client = new CollectionObjectClient();
1482 PayloadInputPart payloadInputPart = extractPart(testName, res, client.getCommonPartName());
1484 if (payloadInputPart != null) {
1485 obj = payloadInputPart.getBody();
1487 Assert.assertNotNull(obj,
1488 testName + ": body of " + client.getCommonPartName() + " part was unexpectedly null.");
1489 CollectionobjectsCommon collectionobjectCommon = (CollectionobjectsCommon) obj;
1490 Assert.assertNotNull(collectionobjectCommon,
1491 testName + ": " + client.getCommonPartName() + " part was unexpectedly null.");
1492 return collectionobjectCommon;
1495 private Object extractPartValue(String testName, ClientResponse<String> res, String partLabel)
1498 PayloadInputPart payloadInputPart = extractPart(testName, res, partLabel);
1499 if (payloadInputPart != null) {
1500 obj = payloadInputPart.getElementBody();
1502 Assert.assertNotNull(obj,
1503 testName + ": value of part " + partLabel + " was unexpectedly null.");
1507 private PayloadInputPart extractPart(String testName, ClientResponse<String> res, String partLabel)
1509 if (logger.isDebugEnabled()) {
1510 logger.debug(testName + ": Reading part " + partLabel + " ...");
1512 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1513 PayloadInputPart payloadInputPart = input.getPart(partLabel);
1514 Assert.assertNotNull(payloadInputPart,
1515 testName + ": part " + partLabel + " was unexpectedly null.");
1516 return payloadInputPart;
1520 protected String getServicePathComponent() {
1521 // TODO Auto-generated method stub
1522 return CollectionObjectClient.SERVICE_PATH_COMPONENT;