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.intake.IntakesCommonList;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
43 import org.jboss.resteasy.client.ClientResponse;
44 //import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
45 //import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
46 //import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
47 import org.testng.Assert;
48 //import org.testng.annotations.AfterClass;
49 import org.testng.annotations.Test;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
55 * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
56 * IntakeServiceTest, carries out tests against a
57 * deployed and running Intake Service.
59 * $LastChangedRevision$
62 public class IntakeServiceTest extends AbstractServiceTestImpl {
64 private final String CLASS_NAME = IntakeServiceTest.class.getName();
65 private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class);
67 /** The known resource id. */
68 private String knownResourceId = null;
71 protected CollectionSpaceClient getClientInstance() {
72 return new IntakeClient();
76 protected String getServiceName() {
77 return IntakeClient.SERVICE_NAME;
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
84 protected AbstractCommonList getAbstractCommonList(
85 ClientResponse<AbstractCommonList> response) {
86 return response.getEntity(IntakesCommonList.class);
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
97 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
98 public void create(String testName) throws Exception {
100 if (logger.isDebugEnabled()) {
101 logger.debug(testBanner(testName, CLASS_NAME));
103 // Perform setup, such as initializing the type of service request
104 // (e.g. CREATE, DELETE), its valid and expected status codes, and
105 // its associated HTTP method name (e.g. POST, DELETE).
108 // Submit the request to the service and store the response.
109 IntakeClient client = new IntakeClient();
110 String identifier = createIdentifier();
111 PoxPayloadOut multipart = createInstance(identifier);
112 ClientResponse<Response> res = client.create(multipart);
114 int statusCode = res.getStatus();
116 // Check the status code of the response: does it match
117 // the expected response(s)?
120 // Does it fall within the set of valid status codes?
121 // Does it exactly match the expected status code?
122 if(logger.isDebugEnabled()){
123 logger.debug(testName + ": status = " + statusCode);
125 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
126 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
127 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
129 // Store the ID returned from the first resource created
130 // for additional tests below.
131 if (knownResourceId == null){
132 knownResourceId = extractId(res);
133 if (logger.isDebugEnabled()) {
134 logger.debug(testName + ": knownResourceId=" + knownResourceId);
138 // Store the IDs from every resource created by tests,
139 // so they can be deleted after tests have been run.
140 allResourceIdsCreated.add(extractId(res));
144 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
147 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
148 dependsOnMethods = {"create"})
149 public void createList(String testName) throws Exception {
150 for(int i = 0; i < 3; i++){
156 // Placeholders until the three tests below can be uncommented.
157 // See Issue CSPACE-401.
159 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
162 public void createWithEmptyEntityBody(String testName) throws Exception {
163 //Should this really be empty?
167 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
170 public void createWithMalformedXml(String testName) throws Exception {
171 //Should this really be empty?
175 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
178 public void createWithWrongXmlSchema(String testName) throws Exception {
179 //Should this really be empty?
184 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
185 dependsOnMethods = {"create", "testSubmitRequest"})
186 public void createWithEmptyEntityBody(String testName) throws Exception {
188 if (logger.isDebugEnabled()) {
189 logger.debug(testBanner(testName, CLASS_NAME));
192 setupCreateWithEmptyEntityBody();
194 // Submit the request to the service and store the response.
195 String method = REQUEST_TYPE.httpMethodName();
196 String url = getServiceRootURL();
197 String mediaType = MediaType.APPLICATION_XML;
198 final String entity = "";
199 int statusCode = submitRequest(method, url, mediaType, entity);
201 // Check the status code of the response: does it match
202 // the expected response(s)?
203 if(logger.isDebugEnabled()){
204 logger.debug("createWithEmptyEntityBody url=" + url +
205 " status=" + statusCode);
207 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
208 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
209 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
213 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
214 dependsOnMethods = {"create", "testSubmitRequest"})
215 public void createWithMalformedXml(String testName) throws Exception {
217 if (logger.isDebugEnabled()) {
218 logger.debug(testBanner(testName, CLASS_NAME));
221 setupCreateWithMalformedXml();
223 // Submit the request to the service and store the response.
224 String method = REQUEST_TYPE.httpMethodName();
225 String url = getServiceRootURL();
226 String mediaType = MediaType.APPLICATION_XML;
227 final String entity = MALFORMED_XML_DATA; // Constant from base class.
228 int statusCode = submitRequest(method, url, mediaType, entity);
230 // Check the status code of the response: does it match
231 // the expected response(s)?
232 if(logger.isDebugEnabled()){
233 logger.debug(testName + ": url=" + url +
234 " status=" + statusCode);
236 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
237 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
238 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
242 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
243 dependsOnMethods = {"create", "testSubmitRequest"})
244 public void createWithWrongXmlSchema(String testName) throws Exception {
246 if (logger.isDebugEnabled()) {
247 logger.debug(testBanner(testName, CLASS_NAME));
250 setupCreateWithWrongXmlSchema(testName, logger);
252 // Submit the request to the service and store the response.
253 String method = REQUEST_TYPE.httpMethodName();
254 String url = getServiceRootURL();
255 String mediaType = MediaType.APPLICATION_XML;
256 final String entity = WRONG_XML_SCHEMA_DATA;
257 int statusCode = submitRequest(method, url, mediaType, entity);
259 // Check the status code of the response: does it match
260 // the expected response(s)?
261 if(logger.isDebugEnabled()){
262 logger.debug(testName + ": url=" + url +
263 " status=" + statusCode);
265 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
266 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
271 // ---------------------------------------------------------------
272 // CRUD tests : READ tests
273 // ---------------------------------------------------------------
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());
346 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
349 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
350 dependsOnMethods = {"read"})
351 public void readNonExistent(String testName) throws Exception {
353 if (logger.isDebugEnabled()) {
354 logger.debug(testBanner(testName, CLASS_NAME));
357 setupReadNonExistent();
359 // Submit the request to the service and store the response.
360 IntakeClient client = new IntakeClient();
361 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
362 int statusCode = res.getStatus();
364 // Check the status code of the response: does it match
365 // the expected response(s)?
366 if(logger.isDebugEnabled()){
367 logger.debug(testName + ": status = " + statusCode);
369 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
370 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
371 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
374 // ---------------------------------------------------------------
375 // CRUD tests : READ_LIST tests
376 // ---------------------------------------------------------------
379 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
382 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
383 dependsOnMethods = {"createList", "read"})
384 public void readList(String testName) throws Exception {
386 if (logger.isDebugEnabled()) {
387 logger.debug(testBanner(testName, CLASS_NAME));
392 // Submit the request to the service and store the response.
393 IntakeClient client = new IntakeClient();
394 ClientResponse<IntakesCommonList> res = client.readList();
395 IntakesCommonList list = res.getEntity();
396 int statusCode = res.getStatus();
398 // Check the status code of the response: does it match
399 // the expected response(s)?
400 if(logger.isDebugEnabled()){
401 logger.debug(testName + ": status = " + statusCode);
403 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
404 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
405 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
407 // Optionally output additional data about list members for debugging.
408 boolean iterateThroughList = false;
409 if(iterateThroughList && logger.isDebugEnabled()){
410 List<IntakesCommonList.IntakeListItem> items =
411 list.getIntakeListItem();
413 for(IntakesCommonList.IntakeListItem item : items){
414 logger.debug(testName + ": list-item[" + i + "] csid=" +
416 logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
417 item.getEntryNumber());
418 logger.debug(testName + ": list-item[" + i + "] URI=" +
428 // ---------------------------------------------------------------
429 // CRUD tests : UPDATE tests
430 // ---------------------------------------------------------------
433 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
436 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
437 dependsOnMethods = {"read"})
438 public void update(String testName) throws Exception {
440 if (logger.isDebugEnabled()) {
441 logger.debug(testBanner(testName, CLASS_NAME));
446 // Retrieve the contents of a resource to update.
447 IntakeClient client = new IntakeClient();
448 ClientResponse<String> res = client.read(knownResourceId);
449 if(logger.isDebugEnabled()){
450 logger.debug(testName + ": read status = " + res.getStatus());
452 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
454 if(logger.isDebugEnabled()){
455 logger.debug("got object to update with ID: " + knownResourceId);
457 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
458 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
459 IntakesCommon intakeCommons = null;
460 if (payloadInputPart != null) {
461 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
463 // IntakesCommon intake = (IntakesCommon) extractPart(input,
464 // client.getCommonPartName(), IntakesCommon.class);
465 Assert.assertNotNull(intakeCommons);
467 // Update the content of this resource.
468 intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber());
469 intakeCommons.setEntryDate("updated-" + intakeCommons.getEntryDate());
470 if(logger.isDebugEnabled()){
471 logger.debug("to be updated object");
472 logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class));
475 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
476 Assert.assertNotNull(currentLocationGroupList);
477 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
478 Assert.assertNotNull(currentLocationGroups);
479 Assert.assertTrue(currentLocationGroups.size() > 0);
480 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
481 Assert.assertNotNull(currentLocationGroup);
482 String currentLocationNote = currentLocationGroup.getCurrentLocationNote();
483 Assert.assertNotNull(currentLocationNote);
484 String updatedCurrentLocationNote = "updated-" + currentLocationNote;
485 currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote);
486 intakeCommons.setCurrentLocationGroupList(currentLocationGroupList);
488 // Submit the request to the service and store the response.
489 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
490 PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE);
491 commonPart.setLabel(client.getCommonPartName());
493 res = client.update(knownResourceId, output);
494 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match the expected response(s)?
496 if(logger.isDebugEnabled()){
497 logger.debug(testName + ": status = " + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 input = new PoxPayloadIn(res.getEntity());
504 IntakesCommon updatedIntake =
505 (IntakesCommon) extractPart(input,
506 client.getCommonPartName(), IntakesCommon.class);
508 Assert.assertNotNull(updatedIntake);
510 Assert.assertEquals(updatedIntake.getEntryDate(),
511 intakeCommons.getEntryDate(),
512 "Data in updated object did not match submitted data.");
514 currentLocationGroupList = updatedIntake.getCurrentLocationGroupList();
515 Assert.assertNotNull(currentLocationGroupList);
516 currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
517 Assert.assertNotNull(currentLocationGroups);
518 Assert.assertTrue(currentLocationGroups.size() > 0);
519 Assert.assertNotNull(currentLocationGroups.get(0));
520 Assert.assertEquals(updatedCurrentLocationNote,
521 currentLocationGroups.get(0).getCurrentLocationNote(),
522 "Data in updated object did not match submitted data.");
524 if(logger.isDebugEnabled()){
525 logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n"
526 + "UTF-8 data received=" + updatedIntake.getEntryNote());
528 Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()),
529 "UTF-8 data retrieved '" + updatedIntake.getEntryNote()
530 + "' does not contain expected data '" + getUTF8DataFragment());
531 Assert.assertEquals(updatedIntake.getEntryNote(),
532 intakeCommons.getEntryNote(),
533 "Data in updated object did not match submitted data.");
538 // Placeholders until the three tests below can be uncommented.
539 // See Issue CSPACE-401.
541 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
544 public void updateWithEmptyEntityBody(String testName) throws Exception {
545 //Should this really be empty?
549 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
552 public void updateWithMalformedXml(String testName) throws Exception {
553 //Should this really be empty?
557 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
560 public void updateWithWrongXmlSchema(String testName) throws Exception {
561 //Should this really be empty?
566 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
567 dependsOnMethods = {"create", "update", "testSubmitRequest"})
568 public void updateWithEmptyEntityBody(String testName) throws Exception {
570 if (logger.isDebugEnabled()) {
571 logger.debug(testBanner(testName, CLASS_NAME));
574 setupUpdateWithEmptyEntityBody();
576 // Submit the request to the service and store the response.
577 String method = REQUEST_TYPE.httpMethodName();
578 String url = getResourceURL(knownResourceId);
579 String mediaType = MediaType.APPLICATION_XML;
580 final String entity = "";
581 int statusCode = submitRequest(method, url, mediaType, entity);
583 // Check the status code of the response: does it match
584 // the expected response(s)?
585 if(logger.isDebugEnabled()){
586 logger.debug(testName + ": url=" + url +
587 " status=" + statusCode);
589 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
590 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
591 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
595 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
596 dependsOnMethods = {"create", "update", "testSubmitRequest"})
597 public void updateWithMalformedXml(String testName) throws Exception {
599 if (logger.isDebugEnabled()) {
600 logger.debug(testBanner(testName, CLASS_NAME));
603 setupUpdateWithMalformedXml();
605 // Submit the request to the service and store the response.
606 String method = REQUEST_TYPE.httpMethodName();
607 String url = getResourceURL(knownResourceId);
608 String mediaType = MediaType.APPLICATION_XML;
609 final String entity = MALFORMED_XML_DATA;
610 int statusCode = submitRequest(method, url, mediaType, entity);
612 // Check the status code of the response: does it match
613 // the expected response(s)?
614 if(logger.isDebugEnabled()){
615 logger.debug(testName + ": url=" + url +
616 " status=" + statusCode);
618 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
619 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
620 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
625 dependsOnMethods = {"create", "update", "testSubmitRequest"})
626 public void updateWithWrongXmlSchema(String testName) throws Exception {
628 if (logger.isDebugEnabled()) {
629 logger.debug(testBanner(testName, CLASS_NAME));
632 setupUpdateWithWrongXmlSchema();
634 // Submit the request to the service and store the response.
635 String method = REQUEST_TYPE.httpMethodName();
636 String url = getResourceURL(knownResourceId);
637 String mediaType = MediaType.APPLICATION_XML;
638 final String entity = WRONG_XML_SCHEMA_DATA;
639 int statusCode = submitRequest(method, url, mediaType, entity);
641 // Check the status code of the response: does it match
642 // the expected response(s)?
643 if(logger.isDebugEnabled()){
644 logger.debug(testName + ": url=" + url +
645 " status=" + statusCode);
647 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
648 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
649 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
654 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
657 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
658 dependsOnMethods = {"update", "testSubmitRequest"})
659 public void updateNonExistent(String testName) throws Exception {
661 if (logger.isDebugEnabled()) {
662 logger.debug(testBanner(testName, CLASS_NAME));
665 setupUpdateNonExistent();
667 // Submit the request to the service and store the response.
668 // Note: The ID used in this 'create' call may be arbitrary.
669 // The only relevant ID may be the one used in update(), below.
670 IntakeClient client = new IntakeClient();
671 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
672 ClientResponse<String> res =
673 client.update(NON_EXISTENT_ID, multipart);
674 int statusCode = res.getStatus();
676 // Check the status code of the response: does it match
677 // the expected response(s)?
678 if(logger.isDebugEnabled()){
679 logger.debug(testName + ": status = " + statusCode);
681 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
683 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
686 // ---------------------------------------------------------------
687 // CRUD tests : DELETE tests
688 // ---------------------------------------------------------------
691 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
694 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
695 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
696 public void delete(String testName) throws Exception {
698 if (logger.isDebugEnabled()) {
699 logger.debug(testBanner(testName, CLASS_NAME));
704 // Submit the request to the service and store the response.
705 IntakeClient client = new IntakeClient();
706 ClientResponse<Response> res = client.delete(knownResourceId);
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);
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 // ---------------------------------------------------------------
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 // ---------------------------------------------------------------
781 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
784 public String getServicePathComponent() {
785 return IntakeClient.SERVICE_PATH_COMPONENT;
789 * Creates the intake instance.
791 * @param identifier the identifier
792 * @return the multipart output
795 protected PoxPayloadOut createInstance(String identifier) {
796 return createIntakeInstance(
797 "entryNumber-" + identifier,
798 "entryDate-" + identifier,
799 "depositor-" + identifier);
803 * Creates the intake instance.
805 * @param entryNumber the entry number
806 * @param entryDate the entry date
807 * @param depositor the depositor
808 * @return the multipart output
810 private PoxPayloadOut createIntakeInstance(String entryNumber,
813 IntakesCommon intake = new IntakesCommon();
814 intake.setEntryNumber(entryNumber);
815 intake.setEntryDate(entryDate);
816 intake.setDepositor(depositor);
818 EntryMethodList entryMethodsList = new EntryMethodList();
819 List<String> entryMethods = entryMethodsList.getEntryMethod();
820 entryMethods.add("Left at doorstep");
821 entryMethods.add("Received via post");
822 intake.setEntryMethods(entryMethodsList);
824 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
825 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
826 // FIXME Use properly formatted refNames for representative event names
827 // in this example test record. The following are mere placeholders.
828 eventNames.add("Field Collection Event Name-1");
829 eventNames.add("Field Collection Event Name-2");
830 intake.setFieldCollectionEventNames(eventNamesList);
832 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
833 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
834 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
835 currentLocationGroup.setCurrentLocation("upstairs");
836 currentLocationGroup.setCurrentLocationFitness("suitable");
837 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
838 currentLocationGroups.add(currentLocationGroup);
839 intake.setCurrentLocationGroupList(currentLocationGroupList);
841 intake.setEntryNote(getUTF8DataFragment());
843 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
844 PayloadOutputPart commonPart =
845 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
846 commonPart.setLabel(new IntakeClient().getCommonPartName());
848 if(logger.isDebugEnabled()){
849 logger.debug("to be created, intake common");
850 logger.debug(objectAsXmlString(intake, IntakesCommon.class));