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.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.CollectionObjectClient;
31 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
32 import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory;
33 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
34 import org.collectionspace.services.collectionobject.ResponsibleDepartmentList;
35 import org.jboss.resteasy.client.ClientResponse;
37 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
38 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
39 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
40 import org.testng.Assert;
41 import org.testng.annotations.AfterClass;
42 import org.testng.annotations.Test;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * CollectionObjectServiceTest, carries out tests against a
49 * deployed and running CollectionObject Service.
51 * $LastChangedRevision$
54 public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
56 private final Logger logger =
57 LoggerFactory.getLogger(CollectionObjectServiceTest.class);
58 // Instance variables specific to this test.
59 private CollectionObjectClient client = new CollectionObjectClient();
60 private String knownResourceId = null;
61 private List<String> allResourceIdsCreated = new ArrayList();
62 private boolean multivalue; //toggle
65 * This method is called only by the parent class, AbstractServiceTest
68 protected String getServicePathComponent() {
69 return client.getServicePathComponent();
72 // ---------------------------------------------------------------
73 // CRUD tests : CREATE tests
74 // ---------------------------------------------------------------
77 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
78 public void create(String testName) throws Exception {
80 // Perform setup, such as initializing the type of service request
81 // (e.g. CREATE, DELETE), its valid and expected status codes, and
82 // its associated HTTP method name (e.g. POST, DELETE).
83 setupCreate(testName);
85 // Submit the request to the service and store the response.
86 String identifier = createIdentifier();
87 MultipartOutput multipart =
88 createCollectionObjectInstance(client.getCommonPartName(), identifier);
89 ClientResponse<Response> res = client.create(multipart);
90 int statusCode = res.getStatus();
92 // Check the status code of the response: does it match
93 // the expected response(s)?
96 // Does it fall within the set of valid status codes?
97 // Does it exactly match the expected status code?
98 if (logger.isDebugEnabled()) {
99 logger.debug(testName + ": status = " + statusCode);
101 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
102 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
103 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
105 // Store the ID returned from the first resource created
106 // for additional tests below.
107 if (knownResourceId == null) {
108 knownResourceId = extractId(res);
109 if (logger.isDebugEnabled()) {
110 logger.debug(testName + ": knownResourceId=" + knownResourceId);
114 // Store the IDs from every resource created by tests,
115 // so they can be deleted after tests have been run.
116 allResourceIdsCreated.add(extractId(res));
120 * @see org.collectionspace.services.client.test.ServiceTest#createList()
123 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
124 dependsOnMethods = {"create"})
125 public void createList(String testName) throws Exception {
126 for (int i = 0; i < 3; i++) {
132 // Placeholders until the three tests below can be uncommented.
133 // See Issue CSPACE-401.
135 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
136 public void createWithEmptyEntityBody(String testName) throws Exception {
140 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
141 public void createWithMalformedXml(String testName) throws Exception {
142 setupCreate(testName);
144 CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
145 collectionObject.setTitle("atitle");
146 //don't set objectNumber to check validation
147 collectionObject.setObjectName("some name");
148 MultipartOutput multipart =
149 createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
150 ClientResponse<Response> res = client.create(multipart);
151 int statusCode = res.getStatus();
153 if (logger.isDebugEnabled()) {
154 logger.debug(testName + ": status = " + statusCode);
156 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
157 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
158 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
162 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
163 public void createWithWrongXmlSchema(String testName) throws Exception {
169 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
170 dependsOnMethods = {"create", "testSubmitRequest"})
171 public void createWithEmptyEntityBody(String testName) throwsException {
174 setupCreateWithEmptyEntityBody(testName);
176 // Submit the request to the service and store the response.
177 String method = REQUEST_TYPE.httpMethodName();
178 String url = getServiceRootURL();
179 String mediaType = MediaType.APPLICATION_XML;
180 final String entity = "";
181 int statusCode = submitRequest(method, url, mediaType, entity);
183 // Check the status code of the response: does it match
184 // the expected response(s)?
185 if(logger.isDebugEnabled()){
186 logger.debug(testName + ": url=" + url +
187 " status=" + statusCode);
189 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
190 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
191 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
195 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
196 dependsOnMethods = {"create", "testSubmitRequest"})
197 public void createWithMalformedXml(String testName) throws Exception {
200 setupCreateWithMalformedXml(testName);
202 // Submit the request to the service and store the response.
203 String method = REQUEST_TYPE.httpMethodName();
204 String url = getServiceRootURL();
205 String mediaType = MediaType.APPLICATION_XML;
206 final String entity = MALFORMED_XML_DATA; // Constant from base class.
207 int statusCode = submitRequest(method, url, mediaType, entity);
209 // Check the status code of the response: does it match
210 // the expected response(s)?
211 if(logger.isDebugEnabled()){
212 logger.debug(testName + ": url=" + url +
213 " status=" + statusCode);
215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
221 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
222 dependsOnMethods = {"create", "testSubmitRequest"})
223 public void createWithWrongXmlSchema(String testName) throws Exception {
226 setupCreateWithWrongXmlSchema(testName);
228 // Submit the request to the service and store the response.
229 String method = REQUEST_TYPE.httpMethodName();
230 String url = getServiceRootURL();
231 String mediaType = MediaType.APPLICATION_XML;
232 final String entity = WRONG_XML_SCHEMA_DATA;
233 int statusCode = submitRequest(method, url, mediaType, entity);
235 // Check the status code of the response: does it match
236 // the expected response(s)?
237 if(logger.isDebugEnabled()){
238 logger.debug(testName + ": url=" + url +
239 " status=" + statusCode);
241 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
242 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
243 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
246 // ---------------------------------------------------------------
247 // CRUD tests : READ tests
248 // ---------------------------------------------------------------
251 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
252 dependsOnMethods = {"create"})
253 public void read(String testName) throws Exception {
258 // Submit the request to the service and store the response.
259 ClientResponse<MultipartInput> res = client.read(knownResourceId);
260 int statusCode = res.getStatus();
262 // Check the status code of the response: does it match
263 // the expected response(s)?
264 if (logger.isDebugEnabled()) {
265 logger.debug(testName + ": status = " + statusCode);
267 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
271 MultipartInput input = (MultipartInput) res.getEntity();
273 if (logger.isDebugEnabled()) {
274 logger.debug(testName + ": Reading Common part ...");
276 CollectionobjectsCommon collectionObject =
277 (CollectionobjectsCommon) extractPart(input,
278 client.getCommonPartName(), CollectionobjectsCommon.class);
279 Assert.assertNotNull(collectionObject);
281 if (logger.isDebugEnabled()) {
282 logger.debug(testName + ": Reading Natural History part ...");
284 CollectionobjectsNaturalhistory conh =
285 (CollectionobjectsNaturalhistory) extractPart(input,
286 getNHPartName(), CollectionobjectsNaturalhistory.class);
287 Assert.assertNotNull(conh);
292 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
293 dependsOnMethods = {"read"})
294 public void readNonExistent(String testName) throws Exception {
297 setupReadNonExistent(testName);
299 // Submit the request to the service and store the response.
300 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
301 int statusCode = res.getStatus();
303 // Check the status code of the response: does it match
304 // the expected response(s)?
305 if (logger.isDebugEnabled()) {
306 logger.debug(testName + ": status = " + statusCode);
308 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
309 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
310 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
313 // ---------------------------------------------------------------
314 // CRUD tests : READ_LIST tests
315 // ---------------------------------------------------------------
318 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
319 dependsOnMethods = {"createList", "read"})
320 public void readList(String testName) throws Exception {
323 setupReadList(testName);
325 // Submit the request to the service and store the response.
326 ClientResponse<CollectionobjectsCommonList> res = client.readList();
327 CollectionobjectsCommonList list = res.getEntity();
328 int statusCode = res.getStatus();
330 // Check the status code of the response: does it match
331 // the expected response(s)?
332 if (logger.isDebugEnabled()) {
333 logger.debug(testName + ": status = " + statusCode);
335 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
336 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
337 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
339 // Optionally output additional data about list members for debugging.
340 boolean iterateThroughList = false;
341 if (iterateThroughList && logger.isDebugEnabled()) {
342 List<CollectionobjectsCommonList.CollectionObjectListItem> items =
343 list.getCollectionObjectListItem();
346 for (CollectionobjectsCommonList.CollectionObjectListItem item : items) {
347 logger.debug(testName + ": list-item[" + i + "] csid="
349 logger.debug(testName + ": list-item[" + i + "] objectNumber="
350 + item.getObjectNumber());
351 logger.debug(testName + ": list-item[" + i + "] URI="
361 // ---------------------------------------------------------------
362 // CRUD tests : UPDATE tests
363 // ---------------------------------------------------------------
366 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
367 dependsOnMethods = {"read"})
368 public void update(String testName) throws Exception {
371 setupUpdate(testName);
373 ClientResponse<MultipartInput> res = updateRetrieve(testName, knownResourceId);
375 if (logger.isDebugEnabled()) {
376 logger.debug("got object to update with ID: " + knownResourceId);
378 MultipartInput input = (MultipartInput) res.getEntity();
379 CollectionobjectsCommon collectionObject =
380 (CollectionobjectsCommon) extractPart(input,
381 client.getCommonPartName(), CollectionobjectsCommon.class);
382 Assert.assertNotNull(collectionObject);
384 // Update the content of this resource.
385 collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
386 collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
387 if (logger.isDebugEnabled()) {
388 logger.debug("updated object");
389 logger.debug(objectAsXmlString(collectionObject,
390 CollectionobjectsCommon.class));
393 res = updateSend(testName, knownResourceId, collectionObject);
395 int statusCode = res.getStatus();
396 // Check the status code of the response: does it match the expected response(s)?
397 if (logger.isDebugEnabled()) {
398 logger.debug(testName + ": status = " + statusCode);
400 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
401 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
402 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
405 input = (MultipartInput) res.getEntity();
406 CollectionobjectsCommon updatedCollectionObject =
407 (CollectionobjectsCommon) extractPart(input,
408 client.getCommonPartName(), CollectionobjectsCommon.class);
409 Assert.assertNotNull(updatedCollectionObject);
411 Assert.assertEquals(updatedCollectionObject.getObjectName(),
412 collectionObject.getObjectName(),
413 "Data in updated object did not match submitted data.");
417 private ClientResponse<MultipartInput> updateRetrieve(String testName, String id) {
418 ClientResponse<MultipartInput> res =
420 if (logger.isDebugEnabled()) {
421 logger.debug("read in updateRetrieve for " + testName + " status = " + res.getStatus());
423 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
425 if (logger.isDebugEnabled()) {
426 logger.debug("got object to updateRetrieve for " + testName + " with ID: " + id);
431 private ClientResponse<MultipartInput> updateSend(String testName, String id,
432 CollectionobjectsCommon collectionObject) {
433 MultipartOutput output = new MultipartOutput();
434 OutputPart commonPart = output.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
435 commonPart.getHeaders().add("label", client.getCommonPartName());
437 ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
438 // Check the status code of the response: does it match the expected response(s)?
439 if (logger.isDebugEnabled()) {
440 logger.debug("updateSend for " + testName + ": status = " + res.getStatus());
446 // Placeholders until the three tests below can be uncommented.
447 // See Issue CSPACE-401.
449 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
450 dependsOnMethods = {"read"})
451 public void updateWithEmptyEntityBody(String testName) throws Exception {
455 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456 dependsOnMethods = {"read"})
457 public void updateWithMalformedXml(String testName) throws Exception {
459 setupUpdate(testName);
460 if (logger.isDebugEnabled()) {
461 logger.debug(testName + " got object to update with ID: " + knownResourceId);
464 ClientResponse<MultipartInput> res = updateRetrieve(testName, knownResourceId);
466 MultipartInput input = (MultipartInput) res.getEntity();
467 CollectionobjectsCommon collectionObject =
468 (CollectionobjectsCommon) extractPart(input,
469 client.getCommonPartName(), CollectionobjectsCommon.class);
470 Assert.assertNotNull(collectionObject);
472 //update with invalid content
473 collectionObject.setObjectNumber("");
475 if (logger.isDebugEnabled()) {
476 logger.debug(testName + " updated object");
477 logger.debug(objectAsXmlString(collectionObject,
478 CollectionobjectsCommon.class));
481 // Submit the request to the service and store the response.
482 res = updateSend(testName, knownResourceId, collectionObject);
483 int statusCode = res.getStatus();
484 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
485 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
486 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
491 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
492 dependsOnMethods = {"read"})
493 public void updateWithWrongXmlSchema(String testName) throws Exception {
498 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
499 dependsOnMethods = {"create", "update", "testSubmitRequest"})
500 public void updateWithEmptyEntityBody(String testName) throws Exception {
503 setupUpdateWithEmptyEntityBody(testName);
505 // Submit the request to the service and store the response.
506 String method = REQUEST_TYPE.httpMethodName();
507 String url = getResourceURL(knownResourceId);
508 String mediaType = MediaType.APPLICATION_XML;
509 final String entity = "";
510 int statusCode = submitRequest(method, url, mediaType, entity);
512 // Check the status code of the response: does it match
513 // the expected response(s)?
514 if(logger.isDebugEnabled()){
515 logger.debug(testName + ": url=" + url +
516 " status=" + statusCode);
518 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
519 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
520 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
524 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
525 dependsOnMethods = {"create", "update", "testSubmitRequest"})
526 public void updateWithMalformedXml() throws Exception {
529 setupUpdateWithMalformedXml(testName);
531 // Submit the request to the service and store the response.
532 String method = REQUEST_TYPE.httpMethodName();
533 String url = getResourceURL(knownResourceId);
534 final String entity = MALFORMED_XML_DATA;
535 String mediaType = MediaType.APPLICATION_XML;
536 int statusCode = submitRequest(method, url, mediaType, entity);
538 // Check the status code of the response: does it match
539 // the expected response(s)?
540 if(logger.isDebugEnabled()){
541 logger.debug(testName + ": url=" + url +
542 " status=" + statusCode);
544 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
545 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
546 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
550 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
551 dependsOnMethods = {"create", "update", "testSubmitRequest"})
552 public void updateWithWrongXmlSchema(String testName) throws Exception {
555 setupUpdateWithWrongXmlSchema(String testName);
557 // Submit the request to the service and store the response.
558 String method = REQUEST_TYPE.httpMethodName();
559 String url = getResourceURL(knownResourceId);
560 String mediaType = MediaType.APPLICATION_XML;
561 final String entity = WRONG_XML_SCHEMA_DATA;
562 int statusCode = submitRequest(method, url, mediaType, entity);
564 // Check the status code of the response: does it match
565 // the expected response(s)?
566 if(logger.isDebugEnabled()){
567 logger.debug(testName + ": url=" + url +
568 " status=" + statusCode);
570 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
571 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
572 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
576 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
577 dependsOnMethods = {"update", "testSubmitRequest"})
578 public void updateNonExistent(String testName) throws Exception {
581 setupUpdateNonExistent(testName);
583 // Submit the request to the service and store the response.
585 // Note: The ID used in this 'create' call may be arbitrary.
586 // The only relevant ID may be the one used in updateCollectionObject(), below.
587 MultipartOutput multipart =
588 createCollectionObjectInstance(client.getCommonPartName(),
590 ClientResponse<MultipartInput> res =
591 client.update(NON_EXISTENT_ID, multipart);
592 int statusCode = res.getStatus();
594 // Check the status code of the response: does it match
595 // the expected response(s)?
596 if (logger.isDebugEnabled()) {
597 logger.debug(testName + ": status = " + statusCode);
599 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
600 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
601 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
604 // ---------------------------------------------------------------
605 // CRUD tests : DELETE tests
606 // ---------------------------------------------------------------
609 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
610 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
611 public void delete(String testName) throws Exception {
614 setupDelete(testName);
616 // Submit the request to the service and store the response.
617 ClientResponse<Response> res = client.delete(knownResourceId);
618 int statusCode = res.getStatus();
620 // Check the status code of the response: does it match
621 // the expected response(s)?
622 if (logger.isDebugEnabled()) {
623 logger.debug(testName + ": status = " + statusCode);
625 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
626 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
627 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
632 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
633 dependsOnMethods = {"delete"})
634 public void deleteNonExistent(String testName) throws Exception {
637 setupDeleteNonExistent(testName);
639 // Submit the request to the service and store the response.
640 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if (logger.isDebugEnabled()) {
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
653 // ---------------------------------------------------------------
654 // Utility tests : tests of code used in tests above
655 // ---------------------------------------------------------------
657 * Tests the code for manually submitting data that is used by several
658 * of the methods above.
660 @Test(dependsOnMethods = {"create", "read"})
661 public void testSubmitRequest() throws Exception {
663 // Expected status code: 200 OK
664 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
666 // Submit the request to the service and store the response.
667 String method = ServiceRequestType.READ.httpMethodName();
668 String url = getResourceURL(knownResourceId);
669 int statusCode = submitRequest(method, url);
671 // Check the status code of the response: does it match
672 // the expected response(s)?
673 if (logger.isDebugEnabled()) {
674 logger.debug("testSubmitRequest: url=" + url
675 + " status=" + statusCode);
677 Assert.assertEquals(statusCode, EXPECTED_STATUS);
681 // ---------------------------------------------------------------
682 // Cleanup of resources created during testing
683 // ---------------------------------------------------------------
685 * Deletes all resources created by tests, after all tests have been run.
687 * This cleanup method will always be run, even if one or more tests fail.
688 * For this reason, it attempts to remove all resources created
689 * at any point during testing, even if some of those resources
690 * may be expected to be deleted by certain tests.
692 @AfterClass(alwaysRun = true)
693 public void cleanUp() {
694 if (logger.isDebugEnabled()) {
695 logger.debug("Cleaning up temporary resources created for testing ...");
697 for (String resourceId : allResourceIdsCreated) {
698 // Note: Any non-success responses are ignored and not reported.
699 ClientResponse<Response> res = client.delete(resourceId);
703 // ---------------------------------------------------------------
704 // Utility methods used by tests above
705 // ---------------------------------------------------------------
706 private MultipartOutput createCollectionObjectInstance(String commonPartName,
708 return createCollectionObjectInstance(commonPartName,
709 "objectNumber-" + identifier,
710 "objectName-" + identifier);
713 private MultipartOutput createCollectionObjectInstance(String commonPartName,
714 String objectNumber, String objectName) {
715 CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
716 ResponsibleDepartmentList deptList = new ResponsibleDepartmentList();
717 List<String> depts = deptList.getResponsibleDepartment();
718 // @TODO Use properly formatted refNames for representative departments
719 // in this example test record. The following are mere placeholders.
720 depts.add("urn:org.collectionspace.services.department:Registrar");
722 depts.add("urn:org.walkerart.department:Fine Art");
724 multivalue = !multivalue;
725 //FIXME: Title does not need to be set.
726 collectionObject.setTitle("acoward");
727 collectionObject.setResponsibleDepartments(deptList);
728 collectionObject.setObjectNumber(objectNumber);
729 collectionObject.setOtherNumber("urn:org.walkerart.id:123");
730 collectionObject.setObjectName(objectName);
731 collectionObject.setAge(""); //test for null string
732 collectionObject.setBriefDescription("Papier mache bird cow mask with horns, "
733 + "painted red with black and yellow spots. "
734 + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns).");
736 CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
737 conh.setNhString("test-string");
739 conh.setNhLong(9999);
742 MultipartOutput multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
746 private MultipartOutput createCollectionObjectInstance(String commonPartName,
747 CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
749 MultipartOutput multipart = new MultipartOutput();
750 OutputPart commonPart = multipart.addPart(collectionObject,
751 MediaType.APPLICATION_XML_TYPE);
752 commonPart.getHeaders().add("label", commonPartName);
754 if (logger.isDebugEnabled()) {
755 logger.debug("to be created, collectionobject common");
756 logger.debug(objectAsXmlString(collectionObject,
757 CollectionobjectsCommon.class));
761 OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE);
762 nhPart.getHeaders().add("label", getNHPartName());
764 if (logger.isDebugEnabled()) {
765 logger.debug("to be created, collectionobject nhistory");
766 logger.debug(objectAsXmlString(conh,
767 CollectionobjectsNaturalhistory.class));
774 private String getNHPartName() {
775 return "collectionobjects_naturalhistory";