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.jboss.resteasy.plugins.providers.multipart.MultipartInput;
44 //import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
45 //import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
46 import org.testng.Assert;
47 //import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
54 * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
55 * IntakeServiceTest, carries out tests against a
56 * deployed and running Intake Service.
58 * $LastChangedRevision$
61 public class IntakeServiceTest extends AbstractServiceTestImpl {
63 private final String CLASS_NAME = IntakeServiceTest.class.getName();
64 private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class);
66 /** The known resource id. */
67 private String knownResourceId = null;
70 protected CollectionSpaceClient getClientInstance() {
71 return new IntakeClient();
75 protected String getServiceName() {
76 return IntakeClient.SERVICE_NAME;
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(AbstractCommonList.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 PoxPayloadOut multipart = createInstance(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<String> 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 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
303 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
304 IntakesCommon intakeCommons = null;
305 if (payloadInputPart != null) {
306 intakeCommons = (IntakesCommon) payloadInputPart.getBody();
308 // IntakesCommon intake = (IntakesCommon) extractPart(input,
309 // client.getCommonPartName(), IntakesCommon.class);
310 Assert.assertNotNull(intakeCommons);
312 // Verify the number and contents of values in repeatable fields,
313 // as created in the instance record used for testing.
314 List<String> entryMethods =
315 intakeCommons.getEntryMethods().getEntryMethod();
316 Assert.assertTrue(entryMethods.size() > 0);
317 Assert.assertNotNull(entryMethods.get(0));
319 List<String> fieldCollectionEventNames =
320 intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName();
321 Assert.assertTrue(fieldCollectionEventNames.size() > 0);
322 Assert.assertNotNull(fieldCollectionEventNames.get(0));
324 CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList();
325 Assert.assertNotNull(currentLocationGroupList);
326 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
327 Assert.assertNotNull(currentLocationGroups);
328 Assert.assertTrue(currentLocationGroups.size() > 0);
329 CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0);
330 Assert.assertNotNull(currentLocationGroup);
331 Assert.assertNotNull(currentLocationGroup.getCurrentLocationNote());
333 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
334 if(logger.isDebugEnabled()){
335 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
336 + "UTF-8 data received=" + intakeCommons.getEntryNote());
338 Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(),
339 "UTF-8 data retrieved '" + intakeCommons.getEntryNote()
340 + "' does not match expected data '" + getUTF8DataFragment());
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
348 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349 dependsOnMethods = {"read"})
350 public void readNonExistent(String testName) throws Exception {
352 if (logger.isDebugEnabled()) {
353 logger.debug(testBanner(testName, CLASS_NAME));
356 setupReadNonExistent();
358 // Submit the request to the service and store the response.
359 IntakeClient client = new IntakeClient();
360 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
361 int statusCode = res.getStatus();
363 // Check the status code of the response: does it match
364 // the expected response(s)?
365 if(logger.isDebugEnabled()){
366 logger.debug(testName + ": status = " + statusCode);
368 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
369 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
370 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
373 // ---------------------------------------------------------------
374 // CRUD tests : READ_LIST tests
375 // ---------------------------------------------------------------
378 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
381 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
382 dependsOnMethods = {"createList", "read"})
383 public void readList(String testName) throws Exception {
385 if (logger.isDebugEnabled()) {
386 logger.debug(testBanner(testName, CLASS_NAME));
391 // Submit the request to the service and store the response.
392 IntakeClient client = new IntakeClient();
393 ClientResponse<AbstractCommonList> res = client.readList();
394 AbstractCommonList list = res.getEntity();
395 int statusCode = res.getStatus();
397 // Check the status code of the response: does it match
398 // the expected response(s)?
399 if(logger.isDebugEnabled()){
400 logger.debug(testName + ": status = " + statusCode);
402 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
403 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
404 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
406 // Optionally output additional data about list members for debugging.
407 boolean iterateThroughList = false;
408 if(iterateThroughList && logger.isDebugEnabled()){
409 List<AbstractCommonList.ListItem> items =
412 for(AbstractCommonList.ListItem item : items){
413 logger.debug(testName + ": list-item[" + i + "] " +
423 // ---------------------------------------------------------------
424 // CRUD tests : UPDATE tests
425 // ---------------------------------------------------------------
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.
534 // See Issue CSPACE-401.
536 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
539 public void updateWithEmptyEntityBody(String testName) throws Exception {
540 //Should this really be empty?
544 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
547 public void updateWithMalformedXml(String testName) throws Exception {
548 //Should this really be empty?
552 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
555 public void updateWithWrongXmlSchema(String testName) throws Exception {
556 //Should this really be empty?
561 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
562 dependsOnMethods = {"create", "update", "testSubmitRequest"})
563 public void updateWithEmptyEntityBody(String testName) throws Exception {
565 if (logger.isDebugEnabled()) {
566 logger.debug(testBanner(testName, CLASS_NAME));
569 setupUpdateWithEmptyEntityBody();
571 // Submit the request to the service and store the response.
572 String method = REQUEST_TYPE.httpMethodName();
573 String url = getResourceURL(knownResourceId);
574 String mediaType = MediaType.APPLICATION_XML;
575 final String entity = "";
576 int statusCode = submitRequest(method, url, mediaType, entity);
578 // Check the status code of the response: does it match
579 // the expected response(s)?
580 if(logger.isDebugEnabled()){
581 logger.debug(testName + ": url=" + url +
582 " status=" + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
590 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
591 dependsOnMethods = {"create", "update", "testSubmitRequest"})
592 public void updateWithMalformedXml(String testName) throws Exception {
594 if (logger.isDebugEnabled()) {
595 logger.debug(testBanner(testName, CLASS_NAME));
598 setupUpdateWithMalformedXml();
600 // Submit the request to the service and store the response.
601 String method = REQUEST_TYPE.httpMethodName();
602 String url = getResourceURL(knownResourceId);
603 String mediaType = MediaType.APPLICATION_XML;
604 final String entity = MALFORMED_XML_DATA;
605 int statusCode = submitRequest(method, url, mediaType, entity);
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 if(logger.isDebugEnabled()){
610 logger.debug(testName + ": url=" + url +
611 " status=" + statusCode);
613 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
619 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
620 dependsOnMethods = {"create", "update", "testSubmitRequest"})
621 public void updateWithWrongXmlSchema(String testName) throws Exception {
623 if (logger.isDebugEnabled()) {
624 logger.debug(testBanner(testName, CLASS_NAME));
627 setupUpdateWithWrongXmlSchema();
629 // Submit the request to the service and store the response.
630 String method = REQUEST_TYPE.httpMethodName();
631 String url = getResourceURL(knownResourceId);
632 String mediaType = MediaType.APPLICATION_XML;
633 final String entity = WRONG_XML_SCHEMA_DATA;
634 int statusCode = submitRequest(method, url, mediaType, entity);
636 // Check the status code of the response: does it match
637 // the expected response(s)?
638 if(logger.isDebugEnabled()){
639 logger.debug(testName + ": url=" + url +
640 " status=" + statusCode);
642 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
649 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
652 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
653 dependsOnMethods = {"update", "testSubmitRequest"})
654 public void updateNonExistent(String testName) throws Exception {
656 if (logger.isDebugEnabled()) {
657 logger.debug(testBanner(testName, CLASS_NAME));
660 setupUpdateNonExistent();
662 // Submit the request to the service and store the response.
663 // Note: The ID used in this 'create' call may be arbitrary.
664 // The only relevant ID may be the one used in update(), below.
665 IntakeClient client = new IntakeClient();
666 PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID);
667 ClientResponse<String> res =
668 client.update(NON_EXISTENT_ID, multipart);
669 int statusCode = res.getStatus();
671 // Check the status code of the response: does it match
672 // the expected response(s)?
673 if(logger.isDebugEnabled()){
674 logger.debug(testName + ": status = " + statusCode);
676 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
677 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
678 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
681 // ---------------------------------------------------------------
682 // CRUD tests : DELETE tests
683 // ---------------------------------------------------------------
686 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
689 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
690 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
691 public void delete(String testName) throws Exception {
693 if (logger.isDebugEnabled()) {
694 logger.debug(testBanner(testName, CLASS_NAME));
699 // Submit the request to the service and store the response.
700 IntakeClient client = new IntakeClient();
701 ClientResponse<Response> res = client.delete(knownResourceId);
702 int statusCode = res.getStatus();
704 // Check the status code of the response: does it match
705 // the expected response(s)?
706 if(logger.isDebugEnabled()){
707 logger.debug(testName + ": status = " + statusCode);
709 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
710 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
711 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
716 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
719 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
720 dependsOnMethods = {"delete"})
721 public void deleteNonExistent(String testName) throws Exception {
723 if (logger.isDebugEnabled()) {
724 logger.debug(testBanner(testName, CLASS_NAME));
727 setupDeleteNonExistent();
729 // Submit the request to the service and store the response.
730 IntakeClient client = new IntakeClient();
731 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
732 int statusCode = res.getStatus();
734 // Check the status code of the response: does it match
735 // the expected response(s)?
736 if(logger.isDebugEnabled()){
737 logger.debug(testName + ": status = " + statusCode);
739 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
744 // ---------------------------------------------------------------
745 // Utility tests : tests of code used in tests above
746 // ---------------------------------------------------------------
748 * Tests the code for manually submitting data that is used by several
749 * of the methods above.
751 @Test(dependsOnMethods = {"create", "read"})
752 public void testSubmitRequest() {
754 // Expected status code: 200 OK
755 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
757 // Submit the request to the service and store the response.
758 String method = ServiceRequestType.READ.httpMethodName();
759 String url = getResourceURL(knownResourceId);
760 int statusCode = submitRequest(method, url);
762 // Check the status code of the response: does it match
763 // the expected response(s)?
764 if(logger.isDebugEnabled()){
765 logger.debug("testSubmitRequest: url=" + url +
766 " status=" + statusCode);
768 Assert.assertEquals(statusCode, EXPECTED_STATUS);
772 // ---------------------------------------------------------------
773 // Utility methods used by tests above
774 // ---------------------------------------------------------------
776 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
779 public String getServicePathComponent() {
780 return IntakeClient.SERVICE_PATH_COMPONENT;
784 * Creates the intake instance.
786 * @param identifier the identifier
787 * @return the multipart output
790 protected PoxPayloadOut createInstance(String identifier) {
791 return createIntakeInstance(
792 "entryNumber-" + identifier,
793 "entryDate-" + identifier,
794 "depositor-" + identifier);
798 * Creates the intake instance.
800 * @param entryNumber the entry number
801 * @param entryDate the entry date
802 * @param depositor the depositor
803 * @return the multipart output
805 private PoxPayloadOut createIntakeInstance(String entryNumber,
808 IntakesCommon intake = new IntakesCommon();
809 intake.setEntryNumber(entryNumber);
810 intake.setEntryDate(entryDate);
811 intake.setDepositor(depositor);
813 EntryMethodList entryMethodsList = new EntryMethodList();
814 List<String> entryMethods = entryMethodsList.getEntryMethod();
815 entryMethods.add("Left at doorstep");
816 entryMethods.add("Received via post");
817 intake.setEntryMethods(entryMethodsList);
819 FieldCollectionEventNameList eventNamesList = new FieldCollectionEventNameList();
820 List<String> eventNames = eventNamesList.getFieldCollectionEventName();
821 // FIXME Use properly formatted refNames for representative event names
822 // in this example test record. The following are mere placeholders.
823 eventNames.add("Field Collection Event Name-1");
824 eventNames.add("Field Collection Event Name-2");
825 intake.setFieldCollectionEventNames(eventNamesList);
827 CurrentLocationGroupList currentLocationGroupList = new CurrentLocationGroupList();
828 List<CurrentLocationGroup> currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup();
829 CurrentLocationGroup currentLocationGroup = new CurrentLocationGroup();
830 currentLocationGroup.setCurrentLocation("upstairs");
831 currentLocationGroup.setCurrentLocationFitness("suitable");
832 currentLocationGroup.setCurrentLocationNote("A most suitable location.");
833 currentLocationGroups.add(currentLocationGroup);
834 intake.setCurrentLocationGroupList(currentLocationGroupList);
836 intake.setEntryNote(getUTF8DataFragment());
838 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
839 PayloadOutputPart commonPart =
840 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
841 commonPart.setLabel(new IntakeClient().getCommonPartName());
843 if(logger.isDebugEnabled()){
844 logger.debug("to be created, intake common");
845 logger.debug(objectAsXmlString(intake, IntakesCommon.class));