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.intake.EntryMethodList;
32 import org.collectionspace.services.intake.FieldCollectionEventNameList;
33 import org.collectionspace.services.intake.CurrentLocationGroup;
34 import org.collectionspace.services.intake.CurrentLocationGroupList;
35 import org.collectionspace.services.intake.IntakesCommon;
36 import org.collectionspace.services.intake.IntakesCommonList;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.jboss.resteasy.client.ClientResponse;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
42 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
43 import org.testng.Assert;
44 //import org.testng.annotations.AfterClass;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * 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(CLASS_NAME);
64 // Instance variables specific to this test.
65 /** The service path component. */
66 final String SERVICE_PATH_COMPONENT = "intakes";
68 /** The known resource id. */
69 private String knownResourceId = null;
72 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
75 protected CollectionSpaceClient getClientInstance() {
76 return new IntakeClient();
80 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
83 protected AbstractCommonList getAbstractCommonList(
84 ClientResponse<AbstractCommonList> response) {
85 return response.getEntity(IntakesCommonList.class);
88 // ---------------------------------------------------------------
89 // CRUD tests : CREATE tests
90 // ---------------------------------------------------------------
93 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
96 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
97 public void create(String testName) throws Exception {
99 if (logger.isDebugEnabled()) {
100 logger.debug(testBanner(testName, CLASS_NAME));
102 // Perform setup, such as initializing the type of service request
103 // (e.g. CREATE, DELETE), its valid and expected status codes, and
104 // its associated HTTP method name (e.g. POST, DELETE).
107 // Submit the request to the service and store the response.
108 IntakeClient client = new IntakeClient();
109 String identifier = createIdentifier();
110 MultipartOutput multipart = createIntakeInstance(identifier);
111 ClientResponse<Response> res = client.create(multipart);
113 int statusCode = res.getStatus();
115 // Check the status code of the response: does it match
116 // the expected response(s)?
119 // Does it fall within the set of valid status codes?
120 // Does it exactly match the expected status code?
121 if(logger.isDebugEnabled()){
122 logger.debug(testName + ": status = " + statusCode);
124 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
125 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
126 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
128 // Store the ID returned from the first resource created
129 // for additional tests below.
130 if (knownResourceId == null){
131 knownResourceId = extractId(res);
132 if (logger.isDebugEnabled()) {
133 logger.debug(testName + ": knownResourceId=" + knownResourceId);
137 // Store the IDs from every resource created by tests,
138 // so they can be deleted after tests have been run.
139 allResourceIdsCreated.add(extractId(res));
143 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
146 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
147 dependsOnMethods = {"create"})
148 public void createList(String testName) throws Exception {
149 for(int i = 0; i < 3; i++){
155 // 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 // ---------------------------------------------------------------
275 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
278 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
279 dependsOnMethods = {"create"})
280 public void read(String testName) throws Exception {
282 if (logger.isDebugEnabled()) {
283 logger.debug(testBanner(testName, CLASS_NAME));
288 // Submit the request to the service and store the response.
289 IntakeClient client = new IntakeClient();
290 ClientResponse<MultipartInput> res = client.read(knownResourceId);
291 int statusCode = res.getStatus();
293 // Check the status code of the response: does it match
294 // the expected response(s)?
295 if(logger.isDebugEnabled()){
296 logger.debug(testName + ": status = " + statusCode);
298 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
299 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
300 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
302 MultipartInput input = (MultipartInput) res.getEntity();
303 IntakesCommon intake = (IntakesCommon) extractPart(input,
304 client.getCommonPartName(), IntakesCommon.class);
305 Assert.assertNotNull(intake);
307 // Verify the number and contents of values in repeatable fields,
308 // as created in the instance record used for testing.
309 List<String> entryMethods =
310 intake.getEntryMethods().getEntryMethod();
311 Assert.assertTrue(entryMethods.size() > 0);
312 Assert.assertNotNull(entryMethods.get(0));
314 List<String> fieldCollectionEventNames =
315 intake.getFieldCollectionEventNames().getFieldCollectionEventName();
316 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
317 Assert.assertNotNull(fieldCollectionEventNames.get(0));
319 CurrentLocationGroupList currentLocationGroupList = intake.getCurrentLocationGroupList();
320 Assert.assertNotNull(currentLocationGroupList);
321 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
322 Assert.assertNotNull(currentLocationGroups);
323 Assert.assertTrue(currentLocationGroups.size() > 0);
324 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
325 Assert.assertNotNull(currentLocationGroup);
326 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
331 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
334 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
335 dependsOnMethods = {"read"})
336 public void readNonExistent(String testName) throws Exception {
338 if (logger.isDebugEnabled()) {
339 logger.debug(testBanner(testName, CLASS_NAME));
342 setupReadNonExistent();
344 // Submit the request to the service and store the response.
345 IntakeClient client = new IntakeClient();
346 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
347 int statusCode = res.getStatus();
349 // Check the status code of the response: does it match
350 // the expected response(s)?
351 if(logger.isDebugEnabled()){
352 logger.debug(testName + ": status = " + statusCode);
354 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
355 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
356 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
359 // ---------------------------------------------------------------
360 // CRUD tests : READ_LIST tests
361 // ---------------------------------------------------------------
364 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
367 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
368 dependsOnMethods = {"createList", "read"})
369 public void readList(String testName) throws Exception {
371 if (logger.isDebugEnabled()) {
372 logger.debug(testBanner(testName, CLASS_NAME));
377 // Submit the request to the service and store the response.
378 IntakeClient client = new IntakeClient();
379 ClientResponse<IntakesCommonList> res = client.readList();
380 IntakesCommonList list = res.getEntity();
381 int statusCode = res.getStatus();
383 // Check the status code of the response: does it match
384 // the expected response(s)?
385 if(logger.isDebugEnabled()){
386 logger.debug(testName + ": status = " + statusCode);
388 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
389 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
390 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
392 // Optionally output additional data about list members for debugging.
393 boolean iterateThroughList = false;
394 if(iterateThroughList && logger.isDebugEnabled()){
395 List<IntakesCommonList.IntakeListItem> items =
396 list.getIntakeListItem();
398 for(IntakesCommonList.IntakeListItem item : items){
399 logger.debug(testName + ": list-item[" + i + "] csid=" +
401 logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
402 item.getEntryNumber());
403 logger.debug(testName + ": list-item[" + i + "] URI=" +
413 // ---------------------------------------------------------------
414 // CRUD tests : UPDATE tests
415 // ---------------------------------------------------------------
418 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
421 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
422 dependsOnMethods = {"read"})
423 public void update(String testName) throws Exception {
425 if (logger.isDebugEnabled()) {
426 logger.debug(testBanner(testName, CLASS_NAME));
431 // Retrieve the contents of a resource to update.
432 IntakeClient client = new IntakeClient();
433 ClientResponse<MultipartInput> res =
434 client.read(knownResourceId);
435 if(logger.isDebugEnabled()){
436 logger.debug(testName + ": read status = " + res.getStatus());
438 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
440 if(logger.isDebugEnabled()){
441 logger.debug("got object to update with ID: " + knownResourceId);
443 MultipartInput input = (MultipartInput) res.getEntity();
444 IntakesCommon intake = (IntakesCommon) extractPart(input,
445 client.getCommonPartName(), IntakesCommon.class);
446 Assert.assertNotNull(intake);
448 // Update the content of this resource.
449 intake.setEntryNumber("updated-" + intake.getEntryNumber());
450 intake.setEntryDate("updated-" + intake.getEntryDate());
451 if(logger.isDebugEnabled()){
452 logger.debug("to be updated object");
453 logger.debug(objectAsXmlString(intake, IntakesCommon.class));
456 CurrentLocationGroupList currentLocationGroupList = intake.getCurrentLocationGroupList();
457 Assert.assertNotNull(currentLocationGroupList);
458 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
459 Assert.assertNotNull(currentLocationGroups);
460 Assert.assertTrue(currentLocationGroups.size() > 0);
461 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
462 Assert.assertNotNull(currentLocationGroup);
463 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
464 Assert.assertNotNull(currentLocationNote);
465 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
466 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
467 intake.setCurrentLocationGroupList(currentLocationGroupList);
469 // Submit the request to the service and store the response.
470 MultipartOutput output = new MultipartOutput();
471 OutputPart commonPart = output.addPart(intake, MediaType.APPLICATION_XML_TYPE);
472 commonPart.getHeaders().add("label", client.getCommonPartName());
474 res = client.update(knownResourceId, output);
475 int statusCode = res.getStatus();
476 // Check the status code of the response: does it match the expected response(s)?
477 if(logger.isDebugEnabled()){
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 input = (MultipartInput) res.getEntity();
485 IntakesCommon updatedIntake =
486 (IntakesCommon) extractPart(input,
487 client.getCommonPartName(), IntakesCommon.class);
489 Assert.assertNotNull(updatedIntake);
491 Assert.assertEquals(updatedIntake.getEntryDate(),
492 intake.getEntryDate(),
493 "Data in updated object did not match submitted data.");
495 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
496 Assert.assertNotNull(currentLocationGroupList);
497 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
498 Assert.assertNotNull(currentLocationGroups);
499 Assert.assertTrue(currentLocationGroups.size() > 0);
500 Assert.assertNotNull(currentLocationGroups.get(0));
501 Assert.assertEquals(updatedCurrentLocationNote,
502 currentLocationGroups.get(0).getCurrentLocationNote(),
503 "Data in updated object did not match submitted data.");
508 // Placeholders until the three tests below can be uncommented.
509 // See Issue CSPACE-401.
511 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
514 public void updateWithEmptyEntityBody(String testName) throws Exception {
515 //Should this really be empty?
519 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
522 public void updateWithMalformedXml(String testName) throws Exception {
523 //Should this really be empty?
527 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
530 public void updateWithWrongXmlSchema(String testName) throws Exception {
531 //Should this really be empty?
536 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
537 dependsOnMethods = {"create", "update", "testSubmitRequest"})
538 public void updateWithEmptyEntityBody(String testName) throws Exception {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
544 setupUpdateWithEmptyEntityBody();
546 // Submit the request to the service and store the response.
547 String method = REQUEST_TYPE.httpMethodName();
548 String url = getResourceURL(knownResourceId);
549 String mediaType = MediaType.APPLICATION_XML;
550 final String entity = "";
551 int statusCode = submitRequest(method, url, mediaType, entity);
553 // Check the status code of the response: does it match
554 // the expected response(s)?
555 if(logger.isDebugEnabled()){
556 logger.debug(testName + ": url=" + url +
557 " status=" + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
566 dependsOnMethods = {"create", "update", "testSubmitRequest"})
567 public void updateWithMalformedXml(String testName) throws Exception {
569 if (logger.isDebugEnabled()) {
570 logger.debug(testBanner(testName, CLASS_NAME));
573 setupUpdateWithMalformedXml();
575 // Submit the request to the service and store the response.
576 String method = REQUEST_TYPE.httpMethodName();
577 String url = getResourceURL(knownResourceId);
578 String mediaType = MediaType.APPLICATION_XML;
579 final String entity = MALFORMED_XML_DATA;
580 int statusCode = submitRequest(method, url, mediaType, entity);
582 // Check the status code of the response: does it match
583 // the expected response(s)?
584 if(logger.isDebugEnabled()){
585 logger.debug(testName + ": url=" + url +
586 " status=" + statusCode);
588 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
589 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
590 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
595 dependsOnMethods = {"create", "update", "testSubmitRequest"})
596 public void updateWithWrongXmlSchema(String testName) throws Exception {
598 if (logger.isDebugEnabled()) {
599 logger.debug(testBanner(testName, CLASS_NAME));
602 setupUpdateWithWrongXmlSchema();
604 // Submit the request to the service and store the response.
605 String method = REQUEST_TYPE.httpMethodName();
606 String url = getResourceURL(knownResourceId);
607 String mediaType = MediaType.APPLICATION_XML;
608 final String entity = WRONG_XML_SCHEMA_DATA;
609 int statusCode = submitRequest(method, url, mediaType, entity);
611 // Check the status code of the response: does it match
612 // the expected response(s)?
613 if(logger.isDebugEnabled()){
614 logger.debug(testName + ": url=" + url +
615 " status=" + statusCode);
617 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
618 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
619 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
627 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
628 dependsOnMethods = {"update", "testSubmitRequest"})
629 public void updateNonExistent(String testName) throws Exception {
631 if (logger.isDebugEnabled()) {
632 logger.debug(testBanner(testName, CLASS_NAME));
635 setupUpdateNonExistent();
637 // Submit the request to the service and store the response.
638 // Note: The ID used in this 'create' call may be arbitrary.
639 // The only relevant ID may be the one used in update(), below.
640 IntakeClient client = new IntakeClient();
641 MultipartOutput multipart = createIntakeInstance(NON_EXISTENT_ID);
642 ClientResponse<MultipartInput> res =
643 client.update(NON_EXISTENT_ID, multipart);
644 int statusCode = res.getStatus();
646 // Check the status code of the response: does it match
647 // the expected response(s)?
648 if(logger.isDebugEnabled()){
649 logger.debug(testName + ": status = " + statusCode);
651 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
656 // ---------------------------------------------------------------
657 // CRUD tests : DELETE tests
658 // ---------------------------------------------------------------
661 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
664 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
665 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
666 public void delete(String testName) throws Exception {
668 if (logger.isDebugEnabled()) {
669 logger.debug(testBanner(testName, CLASS_NAME));
674 // Submit the request to the service and store the response.
675 IntakeClient client = new IntakeClient();
676 ClientResponse<Response> res = client.delete(knownResourceId);
677 int statusCode = res.getStatus();
679 // Check the status code of the response: does it match
680 // the expected response(s)?
681 if(logger.isDebugEnabled()){
682 logger.debug(testName + ": status = " + statusCode);
684 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
685 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
686 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
691 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
694 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
695 dependsOnMethods = {"delete"})
696 public void deleteNonExistent(String testName) throws Exception {
698 if (logger.isDebugEnabled()) {
699 logger.debug(testBanner(testName, CLASS_NAME));
702 setupDeleteNonExistent();
704 // Submit the request to the service and store the response.
705 IntakeClient client = new IntakeClient();
706 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
707 int statusCode = res.getStatus();
709 // Check the status code of the response: does it match
710 // the expected response(s)?
711 if(logger.isDebugEnabled()){
712 logger.debug(testName + ": status = " + statusCode);
714 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
715 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
716 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
719 // ---------------------------------------------------------------
720 // Utility tests : tests of code used in tests above
721 // ---------------------------------------------------------------
723 * Tests the code for manually submitting data that is used by several
724 * of the methods above.
726 @Test(dependsOnMethods = {"create", "read"})
727 public void testSubmitRequest() {
729 // Expected status code: 200 OK
730 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
732 // Submit the request to the service and store the response.
733 String method = ServiceRequestType.READ.httpMethodName();
734 String url = getResourceURL(knownResourceId);
735 int statusCode = submitRequest(method, url);
737 // Check the status code of the response: does it match
738 // the expected response(s)?
739 if(logger.isDebugEnabled()){
740 logger.debug("testSubmitRequest: url=" + url +
741 " status=" + statusCode);
743 Assert.assertEquals(statusCode, EXPECTED_STATUS);
747 // ---------------------------------------------------------------
748 // Utility methods used by tests above
749 // ---------------------------------------------------------------
751 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
754 public String getServicePathComponent() {
755 return SERVICE_PATH_COMPONENT;
759 * Creates the intake instance.
761 * @param identifier the identifier
762 * @return the multipart output
764 private MultipartOutput createIntakeInstance(String identifier) {
765 return createIntakeInstance(
766 "entryNumber-" + identifier,
767 "entryDate-" + identifier,
768 "depositor-" + identifier);
772 * Creates the intake instance.
774 * @param entryNumber the entry number
775 * @param entryDate the entry date
776 * @param depositor the depositor
777 * @return the multipart output
779 private MultipartOutput createIntakeInstance(String entryNumber,
782 IntakesCommon intake = new IntakesCommon();
783 intake.setEntryNumber(entryNumber);
784 intake.setEntryDate(entryDate);
785 intake.setDepositor(depositor);
787 EntryMethodList entryMethodsList = new EntryMethodList();
788 List<String> entryMethods = entryMethodsList.getEntryMethod();
789 entryMethods.add("Left at doorstep");
790 entryMethods.add("Received via post");
791 intake.setEntryMethods(entryMethodsList);
793 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
794 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
795 // FIXME Use properly formatted refNames for representative event names
796 // in this example test record. The following are mere placeholders.
797 eventNames.add("Field Collection Event Name-1");
798 eventNames.add("Field Collection Event Name-2");
799 intake.setFieldCollectionEventNames(eventNamesList);
801 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
802 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
803 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
804 currentLocationGroup.setCurrentLocation("upstairs");
805 currentLocationGroup.setCurrentLocationFitness("suitable");
806 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
807 currentLocationGroups.add(currentLocationGroup);
808 intake.setCurrentLocationGroupList(currentLocationGroupList);
810 MultipartOutput multipart = new MultipartOutput();
811 OutputPart commonPart =
812 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
813 commonPart.getHeaders().add("label", new IntakeClient().getCommonPartName());
815 if(logger.isDebugEnabled()){
816 logger.debug("to be created, intake common");
817 logger.debug(objectAsXmlString(intake, IntakesCommon.class));