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.LoanoutClient;
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.jaxb.AbstractCommonList;
37 import org.collectionspace.services.loanout.LoanedObjectStatusGroup;
38 import org.collectionspace.services.loanout.LoanedObjectStatusGroupList;
39 import org.collectionspace.services.loanout.LoansoutCommon;
41 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
44 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * LoanoutServiceTest, carries out tests against a
51 * deployed and running Loanout (aka Loans Out) Service.
53 * $LastChangedRevision$
56 public class LoanoutServiceTest extends AbstractServiceTestImpl {
59 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
60 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 /** The known resource id. */
62 private String knownResourceId = null;
65 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
68 protected CollectionSpaceClient getClientInstance() {
69 return new LoanoutClient();
73 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
76 protected AbstractCommonList getAbstractCommonList(
77 ClientResponse<AbstractCommonList> response) {
78 return response.getEntity(AbstractCommonList.class);
81 // ---------------------------------------------------------------
82 // CRUD tests : CREATE tests
83 // ---------------------------------------------------------------
86 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
89 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
90 public void create(String testName) throws Exception {
92 if (logger.isDebugEnabled()) {
93 logger.debug(testBanner(testName, CLASS_NAME));
95 // Perform setup, such as initializing the type of service request
96 // (e.g. CREATE, DELETE), its valid and expected status codes, and
97 // its associated HTTP method name (e.g. POST, DELETE).
100 // Submit the request to the service and store the response.
101 LoanoutClient client = new LoanoutClient();
102 String identifier = createIdentifier();
103 PoxPayloadOut multipart = createLoanoutInstance(identifier);
104 ClientResponse<Response> res = client.create(multipart);
106 int statusCode = res.getStatus();
108 // Check the status code of the response: does it match
109 // the expected response(s)?
112 // Does it fall within the set of valid status codes?
113 // Does it exactly match the expected status code?
114 if (logger.isDebugEnabled()) {
115 logger.debug(testName + ": status = " + statusCode);
117 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
118 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
119 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
121 // Store the ID returned from the first resource created
122 // for additional tests below.
123 if (knownResourceId == null) {
124 knownResourceId = extractId(res);
125 if (logger.isDebugEnabled()) {
126 logger.debug(testName + ": knownResourceId=" + knownResourceId);
130 // Store the IDs from every resource created by tests,
131 // so they can be deleted after tests have been run.
132 allResourceIdsCreated.add(extractId(res));
136 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
139 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
140 dependsOnMethods = {"create"})
141 public void createList(String testName) throws Exception {
142 for (int i = 0; i < 3; i++) {
148 // Placeholders until the three tests below can be uncommented.
149 // See Issue CSPACE-401.
151 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
154 public void createWithEmptyEntityBody(String testName) throws Exception {
155 //Should this really be empty?
159 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
162 public void createWithMalformedXml(String testName) throws Exception {
163 //Should this really be empty?
167 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
170 public void createWithWrongXmlSchema(String testName) throws Exception {
171 //Should this really be empty?
176 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
177 dependsOnMethods = {"create", "testSubmitRequest"})
178 public void createWithEmptyEntityBody(String testName) throws Exception {
180 if (logger.isDebugEnabled()) {
181 logger.debug(testBanner(testName, CLASS_NAME));
184 setupCreateWithEmptyEntityBody();
186 // Submit the request to the service and store the response.
187 String method = REQUEST_TYPE.httpMethodName();
188 String url = getServiceRootURL();
189 String mediaType = MediaType.APPLICATION_XML;
190 final String entity = "";
191 int statusCode = submitRequest(method, url, mediaType, entity);
193 // Check the status code of the response: does it match
194 // the expected response(s)?
195 if(logger.isDebugEnabled()){
196 logger.debug("createWithEmptyEntityBody url=" + url +
197 " status=" + statusCode);
199 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
200 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
201 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
205 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
206 dependsOnMethods = {"create", "testSubmitRequest"})
207 public void createWithMalformedXml(String testName) throws Exception {
209 if (logger.isDebugEnabled()) {
210 logger.debug(testBanner(testName, CLASS_NAME));
213 setupCreateWithMalformedXml();
215 // Submit the request to the service and store the response.
216 String method = REQUEST_TYPE.httpMethodName();
217 String url = getServiceRootURL();
218 String mediaType = MediaType.APPLICATION_XML;
219 final String entity = MALFORMED_XML_DATA; // Constant from base class.
220 int statusCode = submitRequest(method, url, mediaType, entity);
222 // Check the status code of the response: does it match
223 // the expected response(s)?
224 if(logger.isDebugEnabled()){
225 logger.debug(testName + ": url=" + url +
226 " status=" + statusCode);
228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
234 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
235 dependsOnMethods = {"create", "testSubmitRequest"})
236 public void createWithWrongXmlSchema(String testName) throws Exception {
238 if (logger.isDebugEnabled()) {
239 logger.debug(testBanner(testName, CLASS_NAME));
242 setupCreateWithWrongXmlSchema();
244 // Submit the request to the service and store the response.
245 String method = REQUEST_TYPE.httpMethodName();
246 String url = getServiceRootURL();
247 String mediaType = MediaType.APPLICATION_XML;
248 final String entity = WRONG_XML_SCHEMA_DATA;
249 int statusCode = submitRequest(method, url, mediaType, entity);
251 // Check the status code of the response: does it match
252 // the expected response(s)?
253 if(logger.isDebugEnabled()){
254 logger.debug(testName + ": url=" + url +
255 " status=" + statusCode);
257 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
258 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
259 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
262 // ---------------------------------------------------------------
263 // CRUD tests : READ tests
264 // ---------------------------------------------------------------
267 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
270 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
271 dependsOnMethods = {"create"})
272 public void read(String testName) throws Exception {
274 if (logger.isDebugEnabled()) {
275 logger.debug(testBanner(testName, CLASS_NAME));
280 // Submit the request to the service and store the response.
281 LoanoutClient client = new LoanoutClient();
282 ClientResponse<String> res = client.read(knownResourceId);
283 int statusCode = res.getStatus();
285 // Check the status code of the response: does it match
286 // the expected response(s)?
287 if (logger.isDebugEnabled()) {
288 logger.debug(testName + ": status = " + statusCode);
290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294 // Get the common part of the response and verify that it is not null.
295 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
296 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
297 LoansoutCommon loanoutCommon = null;
298 if (payloadInputPart != null) {
299 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
301 Assert.assertNotNull(loanoutCommon);
303 // Check selected fields in the common part.
304 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
306 LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
307 Assert.assertNotNull(statusGroupList);
308 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
309 Assert.assertNotNull(statusGroups);
310 Assert.assertTrue(statusGroups.size() > 0);
311 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
312 Assert.assertNotNull(statusGroup);
313 Assert.assertNotNull(statusGroup.getLoanedObjectStatus());
315 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
316 if (logger.isDebugEnabled()) {
317 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
318 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
320 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
321 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
322 + "' does not match expected data '" + getUTF8DataFragment());
327 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
330 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
331 dependsOnMethods = {"read"})
332 public void readNonExistent(String testName) throws Exception {
334 if (logger.isDebugEnabled()) {
335 logger.debug(testBanner(testName, CLASS_NAME));
338 setupReadNonExistent();
340 // Submit the request to the service and store the response.
341 LoanoutClient client = new LoanoutClient();
342 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
343 int statusCode = res.getStatus();
345 // Check the status code of the response: does it match
346 // the expected response(s)?
347 if (logger.isDebugEnabled()) {
348 logger.debug(testName + ": status = " + statusCode);
350 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
351 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
352 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
355 // ---------------------------------------------------------------
356 // CRUD tests : READ_LIST tests
357 // ---------------------------------------------------------------
360 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
363 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
364 dependsOnMethods = {"createList", "read"})
365 public void readList(String testName) throws Exception {
367 if (logger.isDebugEnabled()) {
368 logger.debug(testBanner(testName, CLASS_NAME));
373 // Submit the request to the service and store the response.
374 LoanoutClient client = new LoanoutClient();
375 ClientResponse<AbstractCommonList> res = client.readList();
376 AbstractCommonList list = res.getEntity();
377 int statusCode = res.getStatus();
379 // Check the status code of the response: does it match
380 // the expected response(s)?
381 if (logger.isDebugEnabled()) {
382 logger.debug(testName + ": status = " + statusCode);
384 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
385 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
386 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
388 // Optionally output additional data about list members for debugging.
389 boolean iterateThroughList = true;
390 if(iterateThroughList && logger.isDebugEnabled()){
391 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
398 // ---------------------------------------------------------------
399 // CRUD tests : UPDATE tests
400 // ---------------------------------------------------------------
403 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
406 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
407 dependsOnMethods = {"read"})
408 public void update(String testName) throws Exception {
410 if (logger.isDebugEnabled()) {
411 logger.debug(testBanner(testName, CLASS_NAME));
416 // Retrieve the contents of a resource to update.
417 LoanoutClient client = new LoanoutClient();
418 ClientResponse<String> res = client.read(knownResourceId);
419 if (logger.isDebugEnabled()) {
420 logger.debug(testName + ": read status = " + res.getStatus());
422 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
424 if (logger.isDebugEnabled()) {
425 logger.debug("got object to update with ID: " + knownResourceId);
428 // Extract the common part from the response.
429 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
430 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
431 LoansoutCommon loanoutCommon = null;
432 if (payloadInputPart != null) {
433 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
435 Assert.assertNotNull(loanoutCommon);
437 // Update the content of this resource.
438 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
439 loanoutCommon.setLoanReturnDate("updated-" + loanoutCommon.getLoanReturnDate());
440 LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
441 Assert.assertNotNull(statusGroupList);
442 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
443 Assert.assertNotNull(statusGroups);
444 Assert.assertTrue(statusGroups.size() > 0);
445 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
446 Assert.assertNotNull(statusGroup);
447 String loanedObjectStatus = statusGroup.getLoanedObjectStatus();
448 Assert.assertNotNull(loanedObjectStatus);
449 String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus;
450 statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus);
451 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
452 if (logger.isDebugEnabled()) {
453 logger.debug("to be updated object");
454 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
456 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
458 // Submit the updated resource in an update request to the service and store the response.
459 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
460 PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
461 commonPart.setLabel(client.getCommonPartName());
462 res = client.update(knownResourceId, output);
463 int statusCode = res.getStatus();
465 // Check the status code of the response: does it match the expected response(s)?
466 if (logger.isDebugEnabled()) {
467 logger.debug(testName + ": status = " + statusCode);
469 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
470 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
471 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
473 // Extract the updated common part from the response.
474 input = new PoxPayloadIn(res.getEntity());
475 payloadInputPart = input.getPart(client.getCommonPartName());
476 LoansoutCommon updatedLoanoutCommon = null;
477 if (payloadInputPart != null) {
478 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
480 Assert.assertNotNull(updatedLoanoutCommon);
482 // Check selected fields in the updated resource.
483 Assert.assertEquals(updatedLoanoutCommon.getLoanReturnDate(),
484 loanoutCommon.getLoanReturnDate(),
485 "Data in updated object did not match submitted data.");
487 LoanedObjectStatusGroupList updatedStatusGroupList =
488 updatedLoanoutCommon.getLoanedObjectStatusGroupList();
489 Assert.assertNotNull(updatedStatusGroupList);
490 List<LoanedObjectStatusGroup> updatedStatusGroups =
491 updatedStatusGroupList.getLoanedObjectStatusGroup();
492 Assert.assertNotNull(updatedStatusGroups);
493 Assert.assertTrue(updatedStatusGroups.size() > 0);
494 Assert.assertNotNull(updatedStatusGroups.get(0));
495 Assert.assertEquals(updatedLoanedObjectStatus,
496 updatedStatusGroups.get(0).getLoanedObjectStatus(),
497 "Data in updated object did not match submitted data.");
499 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
500 if (logger.isDebugEnabled()) {
501 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
502 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
504 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
505 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
506 + "' does not contain expected data '" + getUTF8DataFragment());
507 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
508 loanoutCommon.getLoanOutNote(),
509 "Data in updated object did not match submitted data.");
513 // Placeholders until the three tests below can be uncommented.
514 // See Issue CSPACE-401.
516 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
519 public void updateWithEmptyEntityBody(String testName) throws Exception {
520 //Should this really be empty?
524 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
527 public void updateWithMalformedXml(String testName) throws Exception {
528 //Should this really be empty?
532 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
535 public void updateWithWrongXmlSchema(String testName) throws Exception {
536 //Should this really be empty?
541 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
542 dependsOnMethods = {"create", "update", "testSubmitRequest"})
543 public void updateWithEmptyEntityBody(String testName) throws Exception {
545 if (logger.isDebugEnabled()) {
546 logger.debug(testBanner(testName, CLASS_NAME));
549 setupUpdateWithEmptyEntityBody();
551 // Submit the request to the service and store the response.
552 String method = REQUEST_TYPE.httpMethodName();
553 String url = getResourceURL(knownResourceId);
554 String mediaType = MediaType.APPLICATION_XML;
555 final String entity = "";
556 int statusCode = submitRequest(method, url, mediaType, entity);
558 // Check the status code of the response: does it match
559 // the expected response(s)?
560 if(logger.isDebugEnabled()){
561 logger.debug(testName + ": url=" + url +
562 " status=" + statusCode);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
570 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
571 dependsOnMethods = {"create", "update", "testSubmitRequest"})
572 public void updateWithMalformedXml(String testName) throws Exception {
574 if (logger.isDebugEnabled()) {
575 logger.debug(testBanner(testName, CLASS_NAME));
578 setupUpdateWithMalformedXml();
580 // Submit the request to the service and store the response.
581 String method = REQUEST_TYPE.httpMethodName();
582 String url = getResourceURL(knownResourceId);
583 String mediaType = MediaType.APPLICATION_XML;
584 final String entity = MALFORMED_XML_DATA;
585 int statusCode = submitRequest(method, url, mediaType, entity);
587 // Check the status code of the response: does it match
588 // the expected response(s)?
589 if(logger.isDebugEnabled()){
590 logger.debug(testName + ": url=" + url +
591 " status=" + statusCode);
593 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
594 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
595 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
599 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
600 dependsOnMethods = {"create", "update", "testSubmitRequest"})
601 public void updateWithWrongXmlSchema(String testName) throws Exception {
603 if (logger.isDebugEnabled()) {
604 logger.debug(testBanner(testName, CLASS_NAME));
607 setupUpdateWithWrongXmlSchema();
609 // Submit the request to the service and store the response.
610 String method = REQUEST_TYPE.httpMethodName();
611 String url = getResourceURL(knownResourceId);
612 String mediaType = MediaType.APPLICATION_XML;
613 final String entity = WRONG_XML_SCHEMA_DATA;
614 int statusCode = submitRequest(method, url, mediaType, entity);
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": url=" + url +
620 " status=" + statusCode);
622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
632 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
633 dependsOnMethods = {"update", "testSubmitRequest"})
634 public void updateNonExistent(String testName) throws Exception {
636 if (logger.isDebugEnabled()) {
637 logger.debug(testBanner(testName, CLASS_NAME));
640 setupUpdateNonExistent();
642 // Submit the request to the service and store the response.
643 // Note: The ID used in this 'create' call may be arbitrary.
644 // The only relevant ID may be the one used in update(), below.
645 LoanoutClient client = new LoanoutClient();
646 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
647 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
648 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match
651 // the expected response(s)?
652 if (logger.isDebugEnabled()) {
653 logger.debug(testName + ": status = " + statusCode);
655 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
660 // ---------------------------------------------------------------
661 // CRUD tests : DELETE tests
662 // ---------------------------------------------------------------
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
668 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
669 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
670 public void delete(String testName) throws Exception {
672 if (logger.isDebugEnabled()) {
673 logger.debug(testBanner(testName, CLASS_NAME));
678 // Submit the request to the service and store the response.
679 LoanoutClient client = new LoanoutClient();
680 ClientResponse<Response> res = client.delete(knownResourceId);
681 int statusCode = res.getStatus();
683 // Check the status code of the response: does it match
684 // the expected response(s)?
685 if (logger.isDebugEnabled()) {
686 logger.debug(testName + ": status = " + statusCode);
688 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
689 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
690 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
695 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
698 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
699 dependsOnMethods = {"delete"})
700 public void deleteNonExistent(String testName) throws Exception {
702 if (logger.isDebugEnabled()) {
703 logger.debug(testBanner(testName, CLASS_NAME));
706 setupDeleteNonExistent();
708 // Submit the request to the service and store the response.
709 LoanoutClient client = new LoanoutClient();
710 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
711 int statusCode = res.getStatus();
713 // Check the status code of the response: does it match
714 // the expected response(s)?
715 if (logger.isDebugEnabled()) {
716 logger.debug(testName + ": status = " + statusCode);
718 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
719 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
720 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
723 // ---------------------------------------------------------------
724 // Utility tests : tests of code used in tests above
725 // ---------------------------------------------------------------
727 * Tests the code for manually submitting data that is used by several
728 * of the methods above.
730 @Test(dependsOnMethods = {"create", "read"})
731 public void testSubmitRequest() {
733 // Expected status code: 200 OK
734 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
736 // Submit the request to the service and store the response.
737 String method = ServiceRequestType.READ.httpMethodName();
738 String url = getResourceURL(knownResourceId);
739 int statusCode = submitRequest(method, url);
741 // Check the status code of the response: does it match
742 // the expected response(s)?
743 if (logger.isDebugEnabled()) {
744 logger.debug("testSubmitRequest: url=" + url
745 + " status=" + statusCode);
747 Assert.assertEquals(statusCode, EXPECTED_STATUS);
751 // ---------------------------------------------------------------
752 // Utility methods used by tests above
753 // ---------------------------------------------------------------
755 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
758 public String getServicePathComponent() {
759 return LoanoutClient.SERVICE_PATH_COMPONENT;
763 protected PoxPayloadOut createInstance(String identifier) {
764 return createLoanoutInstance(identifier);
768 * Creates the loanout instance.
770 * @param identifier the identifier
771 * @return the multipart output
773 private PoxPayloadOut createLoanoutInstance(String identifier) {
774 return createLoanoutInstance(
775 "loanoutNumber-" + identifier,
776 "returnDate-" + identifier);
780 * Creates the loanout instance.
782 * @param loanOutNumber the loan out number
783 * @param returnDate the return date
784 * @return the multipart output
786 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
788 LoansoutCommon loanoutCommon = new LoansoutCommon();
789 loanoutCommon.setLoanOutNumber(loanOutNumber);
790 loanoutCommon.setLoanReturnDate(returnDate);
791 loanoutCommon.setBorrower(
792 "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
793 loanoutCommon.setBorrowersContact(
794 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
795 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
796 LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList();
797 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
798 LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup();
799 statusGroup.setLoanedObjectStatus("returned");
800 statusGroup.setLoanedObjectStatusNote("Left under the front mat.");
801 statusGroups.add(statusGroup);
802 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
803 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
805 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
806 PayloadOutputPart commonPart =
807 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
808 commonPart.setLabel(new LoanoutClient().getCommonPartName());
810 if (logger.isDebugEnabled()) {
811 logger.debug("to be created, loanout common");
812 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
813 // logger.debug(multipart.toXML());
820 protected String getServiceName() {
821 return LoanoutClient.SERVICE_NAME;