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.CollectionSpaceClient;
30 import org.collectionspace.services.client.IntakeClient;
31 import org.collectionspace.services.client.PayloadInputPart;
32 import org.collectionspace.services.client.PayloadOutputPart;
33 import org.collectionspace.services.client.PoxPayloadIn;
34 import org.collectionspace.services.client.PoxPayloadOut;
35 import org.collectionspace.services.intake.EntryMethodList;
36 import org.collectionspace.services.intake.FieldCollectionEventNameList;
37 import org.collectionspace.services.intake.CurrentLocationGroup;
38 import org.collectionspace.services.intake.CurrentLocationGroupList;
39 import org.collectionspace.services.intake.IntakesCommon;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
44 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
49 // FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
51 * IntakeServiceTest, carries out tests against a
52 * deployed and running Intake Service.
54 * $LastChangedRevision$
57 public class IntakeServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = IntakeServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class);
62 /** The known resource id. */
63 private String knownResourceId = null;
66 protected CollectionSpaceClient getClientInstance() {
67 return new IntakeClient();
71 protected String getServiceName() {
72 return IntakeClient.SERVICE_NAME;
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getAbstractCommonList(
80 ClientResponse<AbstractCommonList> response) {
81 return response.getEntity(AbstractCommonList.class);
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
91 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
94 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
95 public void create(String testName) throws Exception {
97 if (logger.isDebugEnabled()) {
98 logger.debug(testBanner(testName, CLASS_NAME));
100 // Perform setup, such as initializing the type of service request
101 // (e.g. CREATE, DELETE), its valid and expected status codes, and
102 // its associated HTTP method name (e.g. POST, DELETE).
105 // Submit the request to the service and store the response.
106 IntakeClient client = new IntakeClient();
107 String identifier = createIdentifier();
108 PoxPayloadOut multipart = createInstance(identifier);
109 ClientResponse<Response> res = client.create(multipart);
111 int statusCode = res.getStatus();
113 // Check the status code of the response: does it match
114 // the expected response(s)?
117 // Does it fall within the set of valid status codes?
118 // Does it exactly match the expected status code?
119 if (logger.isDebugEnabled()) {
120 logger.debug(testName + ": status = " + statusCode);
122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
126 // Store the ID returned from the first resource created
127 // for additional tests below.
128 if (knownResourceId == null) {
129 knownResourceId = extractId(res);
130 if (logger.isDebugEnabled()) {
131 logger.debug(testName + ": knownResourceId=" + knownResourceId);
135 // Store the IDs from every resource created by tests,
136 // so they can be deleted after tests have been run.
137 allResourceIdsCreated.add(extractId(res));
141 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
144 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
145 dependsOnMethods = {"create"})
146 public void createList(String testName) throws Exception {
147 for (int i = 0; i < 3; i++) {
153 // Placeholders until the three tests below can be uncommented.
155 // See Issue CSPACE-401.
157 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
160 public void createWithEmptyEntityBody(String testName) throws Exception {
161 //Should this really be empty?
165 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
168 public void createWithMalformedXml(String testName) throws Exception {
169 //Should this really be empty?
173 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
176 public void createWithWrongXmlSchema(String testName) throws Exception {
177 //Should this really be empty?
182 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
183 dependsOnMethods = {"create", "testSubmitRequest"})
184 public void createWithEmptyEntityBody(String testName) throws Exception {
186 if (logger.isDebugEnabled()) {
187 logger.debug(testBanner(testName, CLASS_NAME));
190 setupCreateWithEmptyEntityBody();
192 // Submit the request to the service and store the response.
193 String method = REQUEST_TYPE.httpMethodName();
194 String url = getServiceRootURL();
195 String mediaType = MediaType.APPLICATION_XML;
196 final String entity = "";
197 int statusCode = submitRequest(method, url, mediaType, entity);
199 // Check the status code of the response: does it match
200 // the expected response(s)?
201 if(logger.isDebugEnabled()){
202 logger.debug("createWithEmptyEntityBody url=" + url +
203 " status=" + statusCode);
205 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
206 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
207 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
211 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
212 dependsOnMethods = {"create", "testSubmitRequest"})
213 public void createWithMalformedXml(String testName) throws Exception {
215 if (logger.isDebugEnabled()) {
216 logger.debug(testBanner(testName, CLASS_NAME));
219 setupCreateWithMalformedXml();
221 // Submit the request to the service and store the response.
222 String method = REQUEST_TYPE.httpMethodName();
223 String url = getServiceRootURL();
224 String mediaType = MediaType.APPLICATION_XML;
225 final String entity = MALFORMED_XML_DATA; // Constant from base class.
226 int statusCode = submitRequest(method, url, mediaType, entity);
228 // Check the status code of the response: does it match
229 // the expected response(s)?
230 if(logger.isDebugEnabled()){
231 logger.debug(testName + ": url=" + url +
232 " status=" + statusCode);
234 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
235 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
236 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
240 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
241 dependsOnMethods = {"create", "testSubmitRequest"})
242 public void createWithWrongXmlSchema(String testName) throws Exception {
244 if (logger.isDebugEnabled()) {
245 logger.debug(testBanner(testName, CLASS_NAME));
248 setupCreateWithWrongXmlSchema(testName, logger);
250 // Submit the request to the service and store the response.
251 String method = REQUEST_TYPE.httpMethodName();
252 String url = getServiceRootURL();
253 String mediaType = MediaType.APPLICATION_XML;
254 final String entity = WRONG_XML_SCHEMA_DATA;
255 int statusCode = submitRequest(method, url, mediaType, entity);
257 // Check the status code of the response: does it match
258 // the expected response(s)?
259 if(logger.isDebugEnabled()){
260 logger.debug(testName + ": url=" + url +
261 " status=" + statusCode);
263 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
264 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
265 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
269 // ---------------------------------------------------------------
270 // CRUD tests : READ tests
271 // ---------------------------------------------------------------
276 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
279 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
280 dependsOnMethods = {"create"})
281 public void read(String testName) throws Exception {
283 if (logger.isDebugEnabled()) {
284 logger.debug(testBanner(testName, CLASS_NAME));
289 // Submit the request to the service and store the response.
290 IntakeClient client = new IntakeClient();
291 ClientResponse<String> res = client.read(knownResourceId);
292 int statusCode = res.getStatus();
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 if (logger.isDebugEnabled()) {
297 logger.debug(testName + ": status = " + statusCode);
299 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
300 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
301 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
303 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
304 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
305 IntakesCommon intakeCommons = null;
306 if (payloadInputPart != null) {
307 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
309 // IntakesCommon intake = (IntakesCommon) extractPart(input,
310 // client.getCommonPartName(), IntakesCommon.class);
311 Assert.assertNotNull(intakeCommons);
313 // Verify the number and contents of values in repeatable fields,
314 // as created in the instance record used for testing.
315 List<String> entryMethods =
316 intakeCommons.getEntryMethods().getEntryMethod();
317 Assert.assertTrue(entryMethods.size() > 0);
318 Assert.assertNotNull(entryMethods.get(0));
320 List<String> fieldCollectionEventNames =
321 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
322 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
323 Assert.assertNotNull(fieldCollectionEventNames.get(0));
325 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
326 Assert.assertNotNull(currentLocationGroupList);
327 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
328 Assert.assertNotNull(currentLocationGroups);
329 Assert.assertTrue(currentLocationGroups.size() > 0);
330 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
331 Assert.assertNotNull(currentLocationGroup);
332 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
334 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
335 if (logger.isDebugEnabled()) {
336 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
337 + "UTF-8 data received=" + intakeCommons.getEntryNote());
339 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
340 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
341 + "' does not match expected data '" + getUTF8DataFragment());
347 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
350 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351 dependsOnMethods = {"read"})
352 public void readNonExistent(String testName) throws Exception {
354 if (logger.isDebugEnabled()) {
355 logger.debug(testBanner(testName, CLASS_NAME));
358 setupReadNonExistent();
360 // Submit the request to the service and store the response.
361 IntakeClient client = new IntakeClient();
362 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
363 int statusCode = res.getStatus();
365 // Check the status code of the response: does it match
366 // the expected response(s)?
367 if (logger.isDebugEnabled()) {
368 logger.debug(testName + ": status = " + statusCode);
370 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
371 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
372 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
375 // ---------------------------------------------------------------
376 // CRUD tests : READ_LIST tests
377 // ---------------------------------------------------------------
382 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
385 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
386 dependsOnMethods = {"createList", "read"})
387 public void readList(String testName) throws Exception {
389 if (logger.isDebugEnabled()) {
390 logger.debug(testBanner(testName, CLASS_NAME));
395 // Submit the request to the service and store the response.
396 IntakeClient client = new IntakeClient();
397 ClientResponse<AbstractCommonList> res = client.readList();
398 AbstractCommonList list = res.getEntity();
399 int statusCode = res.getStatus();
401 // Check the status code of the response: does it match
402 // the expected response(s)?
403 if (logger.isDebugEnabled()) {
404 logger.debug(testName + ": status = " + statusCode);
406 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
407 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
408 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
410 // Optionally output additional data about list members for debugging.
411 boolean iterateThroughList = true;
412 if (iterateThroughList && logger.isDebugEnabled()) {
413 ListItemsInAbstractCommonList(list, logger, testName);
421 // ---------------------------------------------------------------
422 // CRUD tests : UPDATE tests
423 // ---------------------------------------------------------------
428 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
431 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
432 dependsOnMethods = {"read"})
433 public void update(String testName) throws Exception {
435 if (logger.isDebugEnabled()) {
436 logger.debug(testBanner(testName, CLASS_NAME));
441 // Retrieve the contents of a resource to update.
442 IntakeClient client = new IntakeClient();
443 ClientResponse<String> res = client.read(knownResourceId);
444 if (logger.isDebugEnabled()) {
445 logger.debug(testName + ": read status = " + res.getStatus());
447 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
449 if (logger.isDebugEnabled()) {
450 logger.debug("got object to update with ID: " + knownResourceId);
452 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
453 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
454 IntakesCommon intakeCommons = null;
455 if (payloadInputPart != null) {
456 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
458 // IntakesCommon intake = (IntakesCommon) extractPart(input,
459 // client.getCommonPartName(), IntakesCommon.class);
460 Assert.assertNotNull(intakeCommons);
462 // Update the content of this resource.
463 intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
464 intakeCommons.setEntryDate("updated-" + intakeCommons.getEntryDate());
465 if (logger.isDebugEnabled()) {
466 logger.debug("to be updated object");
467 logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class));
470 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
471 Assert.assertNotNull(currentLocationGroupList);
472 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
473 Assert.assertNotNull(currentLocationGroups);
474 Assert.assertTrue(currentLocationGroups.size() > 0);
475 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
476 Assert.assertNotNull(currentLocationGroup);
477 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
478 Assert.assertNotNull(currentLocationNote);
479 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
480 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
481 intakeCommons.setCurrentLocationGroupList(currentLocationGroupList);
483 // Submit the request to the service and store the response.
484 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
485 PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
486 commonPart.setLabel(client.getCommonPartName());
488 res = client.update(knownResourceId, output);
489 int statusCode = res.getStatus();
490 // Check the status code of the response: does it match the expected response(s)?
491 if (logger.isDebugEnabled()) {
492 logger.debug(testName + ": status = " + statusCode);
494 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
495 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
496 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
498 input = new PoxPayloadIn(res.getEntity());
499 IntakesCommon updatedIntake =
500 (IntakesCommon) extractPart(input,
501 client.getCommonPartName(), IntakesCommon.class);
503 Assert.assertNotNull(updatedIntake);
505 Assert.assertEquals(updatedIntake.getEntryDate(),
506 intakeCommons.getEntryDate(),
507 "Data in updated object did not match submitted data.");
509 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
510 Assert.assertNotNull(currentLocationGroupList);
511 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
512 Assert.assertNotNull(currentLocationGroups);
513 Assert.assertTrue(currentLocationGroups.size() > 0);
514 Assert.assertNotNull(currentLocationGroups.get(0));
515 Assert.assertEquals(updatedCurrentLocationNote,
516 currentLocationGroups.get(0).getCurrentLocationNote(),
517 "Data in updated object did not match submitted data.");
519 if (logger.isDebugEnabled()) {
520 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
521 + "UTF-8 data received=" + updatedIntake.getEntryNote());
523 Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
524 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
525 + "' does not contain expected data '" + getUTF8DataFragment());
526 Assert.assertEquals(updatedIntake.getEntryNote(),
527 intakeCommons.getEntryNote(),
528 "Data in updated object did not match submitted data.");
533 // Placeholders until the three tests below can be uncommented.
535 // See Issue CSPACE-401.
537 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
540 public void updateWithEmptyEntityBody(String testName) throws Exception {
541 //Should this really be empty?
545 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
548 public void updateWithMalformedXml(String testName) throws Exception {
549 //Should this really be empty?
553 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
556 public void updateWithWrongXmlSchema(String testName) throws Exception {
557 //Should this really be empty?
562 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
563 dependsOnMethods = {"create", "update", "testSubmitRequest"})
564 public void updateWithEmptyEntityBody(String testName) throws Exception {
566 if (logger.isDebugEnabled()) {
567 logger.debug(testBanner(testName, CLASS_NAME));
570 setupUpdateWithEmptyEntityBody();
572 // Submit the request to the service and store the response.
573 String method = REQUEST_TYPE.httpMethodName();
574 String url = getResourceURL(knownResourceId);
575 String mediaType = MediaType.APPLICATION_XML;
576 final String entity = "";
577 int statusCode = submitRequest(method, url, mediaType, entity);
579 // Check the status code of the response: does it match
580 // the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug(testName + ": url=" + url +
583 " status=" + statusCode);
585 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
592 dependsOnMethods = {"create", "update", "testSubmitRequest"})
593 public void updateWithMalformedXml(String testName) throws Exception {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
599 setupUpdateWithMalformedXml();
601 // Submit the request to the service and store the response.
602 String method = REQUEST_TYPE.httpMethodName();
603 String url = getResourceURL(knownResourceId);
604 String mediaType = MediaType.APPLICATION_XML;
605 final String entity = MALFORMED_XML_DATA;
606 int statusCode = submitRequest(method, url, mediaType, entity);
608 // Check the status code of the response: does it match
609 // the expected response(s)?
610 if(logger.isDebugEnabled()){
611 logger.debug(testName + ": url=" + url +
612 " status=" + statusCode);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
620 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
621 dependsOnMethods = {"create", "update", "testSubmitRequest"})
622 public void updateWithWrongXmlSchema(String testName) throws Exception {
624 if (logger.isDebugEnabled()) {
625 logger.debug(testBanner(testName, CLASS_NAME));
628 setupUpdateWithWrongXmlSchema();
630 // Submit the request to the service and store the response.
631 String method = REQUEST_TYPE.httpMethodName();
632 String url = getResourceURL(knownResourceId);
633 String mediaType = MediaType.APPLICATION_XML;
634 final String entity = WRONG_XML_SCHEMA_DATA;
635 int statusCode = submitRequest(method, url, mediaType, entity);
637 // Check the status code of the response: does it match
638 // the expected response(s)?
639 if(logger.isDebugEnabled()){
640 logger.debug(testName + ": url=" + url +
641 " status=" + statusCode);
643 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
644 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
645 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
653 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
654 dependsOnMethods = {"update", "testSubmitRequest"})
655 public void updateNonExistent(String testName) throws Exception {
657 if (logger.isDebugEnabled()) {
658 logger.debug(testBanner(testName, CLASS_NAME));
661 setupUpdateNonExistent();
663 // Submit the request to the service and store the response.
664 // Note: The ID used in this 'create' call may be arbitrary.
665 // The only relevant ID may be the one used in update(), below.
666 IntakeClient client = new IntakeClient();
667 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
668 ClientResponse<String> res =
669 client.update(NON_EXISTENT_ID, multipart);
670 int statusCode = res.getStatus();
672 // Check the status code of the response: does it match
673 // the expected response(s)?
674 if (logger.isDebugEnabled()) {
675 logger.debug(testName + ": status = " + statusCode);
677 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
678 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
679 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682 // ---------------------------------------------------------------
683 // CRUD tests : DELETE tests
684 // ---------------------------------------------------------------
689 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
692 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
693 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
694 public void delete(String testName) throws Exception {
696 if (logger.isDebugEnabled()) {
697 logger.debug(testBanner(testName, CLASS_NAME));
702 // Submit the request to the service and store the response.
703 IntakeClient client = new IntakeClient();
704 ClientResponse<Response> res = client.delete(knownResourceId);
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if (logger.isDebugEnabled()) {
710 logger.debug(testName + ": status = " + statusCode);
712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
723 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
724 dependsOnMethods = {"delete"})
725 public void deleteNonExistent(String testName) throws Exception {
727 if (logger.isDebugEnabled()) {
728 logger.debug(testBanner(testName, CLASS_NAME));
731 setupDeleteNonExistent();
733 // Submit the request to the service and store the response.
734 IntakeClient client = new IntakeClient();
735 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
736 int statusCode = res.getStatus();
738 // Check the status code of the response: does it match
739 // the expected response(s)?
740 if (logger.isDebugEnabled()) {
741 logger.debug(testName + ": status = " + statusCode);
743 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
744 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
745 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
748 // ---------------------------------------------------------------
749 // Utility tests : tests of code used in tests above
750 // ---------------------------------------------------------------
753 * Tests the code for manually submitting data that is used by several
754 * of the methods above.
756 @Test(dependsOnMethods = {"create", "read"})
757 public void testSubmitRequest() {
759 // Expected status code: 200 OK
760 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
762 // Submit the request to the service and store the response.
763 String method = ServiceRequestType.READ.httpMethodName();
764 String url = getResourceURL(knownResourceId);
765 int statusCode = submitRequest(method, url);
767 // Check the status code of the response: does it match
768 // the expected response(s)?
769 if (logger.isDebugEnabled()) {
770 logger.debug("testSubmitRequest: url=" + url
771 + " status=" + statusCode);
773 Assert.assertEquals(statusCode, EXPECTED_STATUS);
777 // ---------------------------------------------------------------
778 // Utility methods used by tests above
779 // ---------------------------------------------------------------
782 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
785 public String getServicePathComponent() {
786 return IntakeClient.SERVICE_PATH_COMPONENT;
790 * Creates the intake instance.
792 * @param identifier the identifier
793 * @return the multipart output
796 protected PoxPayloadOut createInstance(String identifier) {
797 return createIntakeInstance(
798 "entryNumber-" + identifier,
799 "entryDate-" + identifier,
800 "depositor-" + identifier);
804 * Creates the intake instance.
806 * @param entryNumber the entry number
807 * @param entryDate the entry date
808 * @param depositor the depositor
809 * @return the multipart output
811 private PoxPayloadOut createIntakeInstance(String entryNumber,
814 IntakesCommon intake = new IntakesCommon();
815 intake.setEntryNumber(entryNumber);
816 intake.setEntryDate(entryDate);
817 intake.setDepositor(depositor);
819 EntryMethodList entryMethodsList = new EntryMethodList();
820 List<String> entryMethods = entryMethodsList.getEntryMethod();
821 entryMethods.add("Left at doorstep");
822 entryMethods.add("Received via post");
823 intake.setEntryMethods(entryMethodsList);
825 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
826 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
827 // FIXME Use properly formatted refNames for representative event names
828 // in this example test record. The following are mere placeholders.
829 eventNames.add("Field Collection Event Name-1");
830 eventNames.add("Field Collection Event Name-2");
831 intake.setFieldCollectionEventNames(eventNamesList);
833 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
834 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
835 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
836 currentLocationGroup.setCurrentLocation("upstairs");
837 currentLocationGroup.setCurrentLocationFitness("suitable");
838 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
839 currentLocationGroups.add(currentLocationGroup);
840 intake.setCurrentLocationGroupList(currentLocationGroupList);
842 intake.setEntryNote(getUTF8DataFragment());
844 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
845 PayloadOutputPart commonPart =
846 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
847 commonPart.setLabel(new IntakeClient().getCommonPartName());
849 if (logger.isDebugEnabled()) {
850 logger.debug("to be created, intake common");
851 logger.debug(objectAsXmlString(intake, IntakesCommon.class));