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.common.AbstractCommonListUtils;
36 import org.collectionspace.services.intake.EntryMethodList;
37 import org.collectionspace.services.intake.FieldCollectionEventNameList;
38 import org.collectionspace.services.intake.CurrentLocationGroup;
39 import org.collectionspace.services.intake.CurrentLocationGroupList;
40 import org.collectionspace.services.intake.IntakesCommon;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
43 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
50 // FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
52 * IntakeServiceTest, carries out tests against a
53 * deployed and running Intake Service.
55 * $LastChangedRevision$
58 public class IntakeServiceTest extends AbstractServiceTestImpl {
61 private final String CLASS_NAME = IntakeServiceTest.class.getName();
62 private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class);
63 /** The known resource id. */
64 private String knownResourceId = null;
67 protected CollectionSpaceClient getClientInstance() {
68 return new IntakeClient();
72 protected String getServiceName() {
73 return IntakeClient.SERVICE_NAME;
77 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
80 protected AbstractCommonList getAbstractCommonList(
81 ClientResponse<AbstractCommonList> response) {
82 return response.getEntity(AbstractCommonList.class);
85 // ---------------------------------------------------------------
86 // CRUD tests : CREATE tests
87 // ---------------------------------------------------------------
92 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
95 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
96 public void create(String testName) throws Exception {
98 if (logger.isDebugEnabled()) {
99 logger.debug(testBanner(testName, CLASS_NAME));
101 // Perform setup, such as initializing the type of service request
102 // (e.g. CREATE, DELETE), its valid and expected status codes, and
103 // its associated HTTP method name (e.g. POST, DELETE).
106 // Submit the request to the service and store the response.
107 IntakeClient client = new IntakeClient();
108 String identifier = createIdentifier();
109 PoxPayloadOut multipart = createInstance(identifier);
110 ClientResponse<Response> res = client.create(multipart);
112 int statusCode = res.getStatus();
114 // Check the status code of the response: does it match
115 // the expected response(s)?
118 // Does it fall within the set of valid status codes?
119 // Does it exactly match the expected status code?
120 if (logger.isDebugEnabled()) {
121 logger.debug(testName + ": status = " + statusCode);
123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
127 // Store the ID returned from the first resource created
128 // for additional tests below.
129 if (knownResourceId == null) {
130 knownResourceId = extractId(res);
131 if (logger.isDebugEnabled()) {
132 logger.debug(testName + ": knownResourceId=" + knownResourceId);
136 // Store the IDs from every resource created by tests,
137 // so they can be deleted after tests have been run.
138 allResourceIdsCreated.add(extractId(res));
142 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
145 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
146 dependsOnMethods = {"create"})
147 public void createList(String testName) throws Exception {
148 for (int i = 0; i < 3; i++) {
154 // Placeholders until the three tests below can be uncommented.
156 // See Issue CSPACE-401.
158 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
161 public void createWithEmptyEntityBody(String testName) throws Exception {
162 //Should this really be empty?
166 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
169 public void createWithMalformedXml(String testName) throws Exception {
170 //Should this really be empty?
174 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
177 public void createWithWrongXmlSchema(String testName) throws Exception {
178 //Should this really be empty?
183 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
184 dependsOnMethods = {"create", "testSubmitRequest"})
185 public void createWithEmptyEntityBody(String testName) throws Exception {
187 if (logger.isDebugEnabled()) {
188 logger.debug(testBanner(testName, CLASS_NAME));
191 setupCreateWithEmptyEntityBody();
193 // Submit the request to the service and store the response.
194 String method = REQUEST_TYPE.httpMethodName();
195 String url = getServiceRootURL();
196 String mediaType = MediaType.APPLICATION_XML;
197 final String entity = "";
198 int statusCode = submitRequest(method, url, mediaType, entity);
200 // Check the status code of the response: does it match
201 // the expected response(s)?
202 if(logger.isDebugEnabled()){
203 logger.debug("createWithEmptyEntityBody url=" + url +
204 " status=" + statusCode);
206 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
207 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
208 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
212 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
213 dependsOnMethods = {"create", "testSubmitRequest"})
214 public void createWithMalformedXml(String testName) throws Exception {
216 if (logger.isDebugEnabled()) {
217 logger.debug(testBanner(testName, CLASS_NAME));
220 setupCreateWithMalformedXml();
222 // Submit the request to the service and store the response.
223 String method = REQUEST_TYPE.httpMethodName();
224 String url = getServiceRootURL();
225 String mediaType = MediaType.APPLICATION_XML;
226 final String entity = MALFORMED_XML_DATA; // Constant from base class.
227 int statusCode = submitRequest(method, url, mediaType, entity);
229 // Check the status code of the response: does it match
230 // the expected response(s)?
231 if(logger.isDebugEnabled()){
232 logger.debug(testName + ": url=" + url +
233 " status=" + statusCode);
235 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
236 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
237 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
241 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
242 dependsOnMethods = {"create", "testSubmitRequest"})
243 public void createWithWrongXmlSchema(String testName) throws Exception {
245 if (logger.isDebugEnabled()) {
246 logger.debug(testBanner(testName, CLASS_NAME));
249 setupCreateWithWrongXmlSchema(testName, logger);
251 // Submit the request to the service and store the response.
252 String method = REQUEST_TYPE.httpMethodName();
253 String url = getServiceRootURL();
254 String mediaType = MediaType.APPLICATION_XML;
255 final String entity = WRONG_XML_SCHEMA_DATA;
256 int statusCode = submitRequest(method, url, mediaType, entity);
258 // Check the status code of the response: does it match
259 // the expected response(s)?
260 if(logger.isDebugEnabled()){
261 logger.debug(testName + ": url=" + url +
262 " status=" + statusCode);
264 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
265 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
266 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
270 // ---------------------------------------------------------------
271 // CRUD tests : READ tests
272 // ---------------------------------------------------------------
277 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
280 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
281 dependsOnMethods = {"create"})
282 public void read(String testName) throws Exception {
284 if (logger.isDebugEnabled()) {
285 logger.debug(testBanner(testName, CLASS_NAME));
290 // Submit the request to the service and store the response.
291 IntakeClient client = new IntakeClient();
292 ClientResponse<String> res = client.read(knownResourceId);
293 int statusCode = res.getStatus();
295 // Check the status code of the response: does it match
296 // the expected response(s)?
297 if (logger.isDebugEnabled()) {
298 logger.debug(testName + ": status = " + statusCode);
300 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
301 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
302 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
304 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
305 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
306 IntakesCommon intakeCommons = null;
307 if (payloadInputPart != null) {
308 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
310 // IntakesCommon intake = (IntakesCommon) extractPart(input,
311 // client.getCommonPartName(), IntakesCommon.class);
312 Assert.assertNotNull(intakeCommons);
314 // Verify the number and contents of values in repeatable fields,
315 // as created in the instance record used for testing.
316 List<String> entryMethods =
317 intakeCommons.getEntryMethods().getEntryMethod();
318 Assert.assertTrue(entryMethods.size() > 0);
319 Assert.assertNotNull(entryMethods.get(0));
321 List<String> fieldCollectionEventNames =
322 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
323 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
324 Assert.assertNotNull(fieldCollectionEventNames.get(0));
326 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
327 Assert.assertNotNull(currentLocationGroupList);
328 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
329 Assert.assertNotNull(currentLocationGroups);
330 Assert.assertTrue(currentLocationGroups.size() > 0);
331 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
332 Assert.assertNotNull(currentLocationGroup);
333 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
335 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
336 if (logger.isDebugEnabled()) {
337 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
338 + "UTF-8 data received=" + intakeCommons.getEntryNote());
340 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
341 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
342 + "' does not match expected data '" + getUTF8DataFragment());
348 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
351 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 dependsOnMethods = {"read"})
353 public void readNonExistent(String testName) throws Exception {
355 if (logger.isDebugEnabled()) {
356 logger.debug(testBanner(testName, CLASS_NAME));
359 setupReadNonExistent();
361 // Submit the request to the service and store the response.
362 IntakeClient client = new IntakeClient();
363 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
364 int statusCode = res.getStatus();
366 // Check the status code of the response: does it match
367 // the expected response(s)?
368 if (logger.isDebugEnabled()) {
369 logger.debug(testName + ": status = " + statusCode);
371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376 // ---------------------------------------------------------------
377 // CRUD tests : READ_LIST tests
378 // ---------------------------------------------------------------
383 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
386 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
387 dependsOnMethods = {"createList", "read"})
388 public void readList(String testName) throws Exception {
390 if (logger.isDebugEnabled()) {
391 logger.debug(testBanner(testName, CLASS_NAME));
396 // Submit the request to the service and store the response.
397 IntakeClient client = new IntakeClient();
398 ClientResponse<AbstractCommonList> res = client.readList();
399 AbstractCommonList list = res.getEntity();
400 int statusCode = res.getStatus();
402 // Check the status code of the response: does it match
403 // the expected response(s)?
404 if (logger.isDebugEnabled()) {
405 logger.debug(testName + ": status = " + statusCode);
407 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
408 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
409 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
411 // Optionally output additional data about list members for debugging.
412 boolean iterateThroughList = true;
413 if (iterateThroughList && logger.isDebugEnabled()) {
414 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
422 // ---------------------------------------------------------------
423 // CRUD tests : UPDATE tests
424 // ---------------------------------------------------------------
429 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
432 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
433 dependsOnMethods = {"read"})
434 public void update(String testName) throws Exception {
436 if (logger.isDebugEnabled()) {
437 logger.debug(testBanner(testName, CLASS_NAME));
442 // Retrieve the contents of a resource to update.
443 IntakeClient client = new IntakeClient();
444 ClientResponse<String> res = client.read(knownResourceId);
445 if (logger.isDebugEnabled()) {
446 logger.debug(testName + ": read status = " + res.getStatus());
448 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
450 if (logger.isDebugEnabled()) {
451 logger.debug("got object to update with ID: " + knownResourceId);
453 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
454 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
455 IntakesCommon intakeCommons = null;
456 if (payloadInputPart != null) {
457 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
459 // IntakesCommon intake = (IntakesCommon) extractPart(input,
460 // client.getCommonPartName(), IntakesCommon.class);
461 Assert.assertNotNull(intakeCommons);
463 // Update the content of this resource.
464 intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
465 intakeCommons.setEntryDate("updated-" + intakeCommons.getEntryDate());
466 if (logger.isDebugEnabled()) {
467 logger.debug("to be updated object");
468 logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class));
471 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
472 Assert.assertNotNull(currentLocationGroupList);
473 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
474 Assert.assertNotNull(currentLocationGroups);
475 Assert.assertTrue(currentLocationGroups.size() > 0);
476 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
477 Assert.assertNotNull(currentLocationGroup);
478 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
479 Assert.assertNotNull(currentLocationNote);
480 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
481 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
482 intakeCommons.setCurrentLocationGroupList(currentLocationGroupList);
484 // Submit the request to the service and store the response.
485 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
486 PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
487 commonPart.setLabel(client.getCommonPartName());
489 res = client.update(knownResourceId, output);
490 int statusCode = res.getStatus();
491 // Check the status code of the response: does it match the expected response(s)?
492 if (logger.isDebugEnabled()) {
493 logger.debug(testName + ": status = " + statusCode);
495 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
496 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
497 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
499 input = new PoxPayloadIn(res.getEntity());
500 IntakesCommon updatedIntake =
501 (IntakesCommon) extractPart(input,
502 client.getCommonPartName(), IntakesCommon.class);
504 Assert.assertNotNull(updatedIntake);
506 Assert.assertEquals(updatedIntake.getEntryDate(),
507 intakeCommons.getEntryDate(),
508 "Data in updated object did not match submitted data.");
510 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
511 Assert.assertNotNull(currentLocationGroupList);
512 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
513 Assert.assertNotNull(currentLocationGroups);
514 Assert.assertTrue(currentLocationGroups.size() > 0);
515 Assert.assertNotNull(currentLocationGroups.get(0));
516 Assert.assertEquals(updatedCurrentLocationNote,
517 currentLocationGroups.get(0).getCurrentLocationNote(),
518 "Data in updated object did not match submitted data.");
520 if (logger.isDebugEnabled()) {
521 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
522 + "UTF-8 data received=" + updatedIntake.getEntryNote());
524 Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
525 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
526 + "' does not contain expected data '" + getUTF8DataFragment());
527 Assert.assertEquals(updatedIntake.getEntryNote(),
528 intakeCommons.getEntryNote(),
529 "Data in updated object did not match submitted data.");
534 // Placeholders until the three tests below can be uncommented.
536 // See Issue CSPACE-401.
538 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
541 public void updateWithEmptyEntityBody(String testName) throws Exception {
542 //Should this really be empty?
546 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
549 public void updateWithMalformedXml(String testName) throws Exception {
550 //Should this really be empty?
554 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
557 public void updateWithWrongXmlSchema(String testName) throws Exception {
558 //Should this really be empty?
563 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
564 dependsOnMethods = {"create", "update", "testSubmitRequest"})
565 public void updateWithEmptyEntityBody(String testName) throws Exception {
567 if (logger.isDebugEnabled()) {
568 logger.debug(testBanner(testName, CLASS_NAME));
571 setupUpdateWithEmptyEntityBody();
573 // Submit the request to the service and store the response.
574 String method = REQUEST_TYPE.httpMethodName();
575 String url = getResourceURL(knownResourceId);
576 String mediaType = MediaType.APPLICATION_XML;
577 final String entity = "";
578 int statusCode = submitRequest(method, url, mediaType, entity);
580 // Check the status code of the response: does it match
581 // the expected response(s)?
582 if(logger.isDebugEnabled()){
583 logger.debug(testName + ": url=" + url +
584 " status=" + statusCode);
586 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
587 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
588 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
593 dependsOnMethods = {"create", "update", "testSubmitRequest"})
594 public void updateWithMalformedXml(String testName) throws Exception {
596 if (logger.isDebugEnabled()) {
597 logger.debug(testBanner(testName, CLASS_NAME));
600 setupUpdateWithMalformedXml();
602 // Submit the request to the service and store the response.
603 String method = REQUEST_TYPE.httpMethodName();
604 String url = getResourceURL(knownResourceId);
605 String mediaType = MediaType.APPLICATION_XML;
606 final String entity = MALFORMED_XML_DATA;
607 int statusCode = submitRequest(method, url, mediaType, entity);
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if(logger.isDebugEnabled()){
612 logger.debug(testName + ": url=" + url +
613 " status=" + statusCode);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
621 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
622 dependsOnMethods = {"create", "update", "testSubmitRequest"})
623 public void updateWithWrongXmlSchema(String testName) throws Exception {
625 if (logger.isDebugEnabled()) {
626 logger.debug(testBanner(testName, CLASS_NAME));
629 setupUpdateWithWrongXmlSchema();
631 // Submit the request to the service and store the response.
632 String method = REQUEST_TYPE.httpMethodName();
633 String url = getResourceURL(knownResourceId);
634 String mediaType = MediaType.APPLICATION_XML;
635 final String entity = WRONG_XML_SCHEMA_DATA;
636 int statusCode = submitRequest(method, url, mediaType, entity);
638 // Check the status code of the response: does it match
639 // the expected response(s)?
640 if(logger.isDebugEnabled()){
641 logger.debug(testName + ": url=" + url +
642 " status=" + statusCode);
644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
651 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
654 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
655 dependsOnMethods = {"update", "testSubmitRequest"})
656 public void updateNonExistent(String testName) throws Exception {
658 if (logger.isDebugEnabled()) {
659 logger.debug(testBanner(testName, CLASS_NAME));
662 setupUpdateNonExistent();
664 // Submit the request to the service and store the response.
665 // Note: The ID used in this 'create' call may be arbitrary.
666 // The only relevant ID may be the one used in update(), below.
667 IntakeClient client = new IntakeClient();
668 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
669 ClientResponse<String> res =
670 client.update(NON_EXISTENT_ID, multipart);
671 int statusCode = res.getStatus();
673 // Check the status code of the response: does it match
674 // the expected response(s)?
675 if (logger.isDebugEnabled()) {
676 logger.debug(testName + ": status = " + statusCode);
678 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
679 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
680 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
683 // ---------------------------------------------------------------
684 // CRUD tests : DELETE tests
685 // ---------------------------------------------------------------
690 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
693 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
694 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
695 public void delete(String testName) throws Exception {
697 if (logger.isDebugEnabled()) {
698 logger.debug(testBanner(testName, CLASS_NAME));
703 // Submit the request to the service and store the response.
704 IntakeClient client = new IntakeClient();
705 ClientResponse<Response> res = client.delete(knownResourceId);
706 int statusCode = res.getStatus();
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if (logger.isDebugEnabled()) {
711 logger.debug(testName + ": status = " + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
721 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
724 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
725 dependsOnMethods = {"delete"})
726 public void deleteNonExistent(String testName) throws Exception {
728 if (logger.isDebugEnabled()) {
729 logger.debug(testBanner(testName, CLASS_NAME));
732 setupDeleteNonExistent();
734 // Submit the request to the service and store the response.
735 IntakeClient client = new IntakeClient();
736 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
737 int statusCode = res.getStatus();
739 // Check the status code of the response: does it match
740 // the expected response(s)?
741 if (logger.isDebugEnabled()) {
742 logger.debug(testName + ": status = " + statusCode);
744 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
745 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
746 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
749 // ---------------------------------------------------------------
750 // Utility tests : tests of code used in tests above
751 // ---------------------------------------------------------------
754 * Tests the code for manually submitting data that is used by several
755 * of the methods above.
757 @Test(dependsOnMethods = {"create", "read"})
758 public void testSubmitRequest() {
760 // Expected status code: 200 OK
761 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
763 // Submit the request to the service and store the response.
764 String method = ServiceRequestType.READ.httpMethodName();
765 String url = getResourceURL(knownResourceId);
766 int statusCode = submitRequest(method, url);
768 // Check the status code of the response: does it match
769 // the expected response(s)?
770 if (logger.isDebugEnabled()) {
771 logger.debug("testSubmitRequest: url=" + url
772 + " status=" + statusCode);
774 Assert.assertEquals(statusCode, EXPECTED_STATUS);
778 // ---------------------------------------------------------------
779 // Utility methods used by tests above
780 // ---------------------------------------------------------------
783 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
786 public String getServicePathComponent() {
787 return IntakeClient.SERVICE_PATH_COMPONENT;
791 * Creates the intake instance.
793 * @param identifier the identifier
794 * @return the multipart output
797 protected PoxPayloadOut createInstance(String identifier) {
798 return createIntakeInstance(
799 "entryNumber-" + identifier,
800 "entryDate-" + identifier,
801 "depositor-" + identifier);
805 * Creates the intake instance.
807 * @param entryNumber the entry number
808 * @param entryDate the entry date
809 * @param depositor the depositor
810 * @return the multipart output
812 private PoxPayloadOut createIntakeInstance(String entryNumber,
815 IntakesCommon intake = new IntakesCommon();
816 intake.setEntryNumber(entryNumber);
817 intake.setEntryDate(entryDate);
818 intake.setDepositor(depositor);
820 EntryMethodList entryMethodsList = new EntryMethodList();
821 List<String> entryMethods = entryMethodsList.getEntryMethod();
822 entryMethods.add("Left at doorstep");
823 entryMethods.add("Received via post");
824 intake.setEntryMethods(entryMethodsList);
826 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
827 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
828 // FIXME Use properly formatted refNames for representative event names
829 // in this example test record. The following are mere placeholders.
830 eventNames.add("Field Collection Event Name-1");
831 eventNames.add("Field Collection Event Name-2");
832 intake.setFieldCollectionEventNames(eventNamesList);
834 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
835 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
836 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
837 currentLocationGroup.setCurrentLocation("upstairs");
838 currentLocationGroup.setCurrentLocationFitness("suitable");
839 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
840 currentLocationGroups.add(currentLocationGroup);
841 intake.setCurrentLocationGroupList(currentLocationGroupList);
843 intake.setEntryNote(getUTF8DataFragment());
845 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
846 PayloadOutputPart commonPart =
847 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
848 commonPart.setLabel(new IntakeClient().getCommonPartName());
850 if (logger.isDebugEnabled()) {
851 logger.debug("to be created, intake common");
852 logger.debug(objectAsXmlString(intake, IntakesCommon.class));