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.jaxb.AbstractCommonList;
36 import org.collectionspace.services.loanout.LoanedObjectStatusGroup;
37 import org.collectionspace.services.loanout.LoanedObjectStatusGroupList;
38 import org.collectionspace.services.loanout.LoansoutCommon;
40 import org.jboss.resteasy.client.ClientResponse;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * LoanoutServiceTest, carries out tests against a
50 * deployed and running Loanout (aka Loans Out) Service.
52 * $LastChangedRevision$
55 public class LoanoutServiceTest extends AbstractServiceTestImpl {
58 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60 /** The known resource id. */
61 private String knownResourceId = null;
64 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
67 protected CollectionSpaceClient getClientInstance() {
68 return new LoanoutClient();
72 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
75 protected AbstractCommonList getAbstractCommonList(
76 ClientResponse<AbstractCommonList> response) {
77 return response.getEntity(AbstractCommonList.class);
80 // ---------------------------------------------------------------
81 // CRUD tests : CREATE tests
82 // ---------------------------------------------------------------
85 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
88 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
89 public void create(String testName) throws Exception {
91 if (logger.isDebugEnabled()) {
92 logger.debug(testBanner(testName, CLASS_NAME));
94 // Perform setup, such as initializing the type of service request
95 // (e.g. CREATE, DELETE), its valid and expected status codes, and
96 // its associated HTTP method name (e.g. POST, DELETE).
99 // Submit the request to the service and store the response.
100 LoanoutClient client = new LoanoutClient();
101 String identifier = createIdentifier();
102 PoxPayloadOut multipart = createLoanoutInstance(identifier);
103 ClientResponse<Response> res = client.create(multipart);
105 int statusCode = res.getStatus();
107 // Check the status code of the response: does it match
108 // the expected response(s)?
111 // Does it fall within the set of valid status codes?
112 // Does it exactly match the expected status code?
113 if (logger.isDebugEnabled()) {
114 logger.debug(testName + ": status = " + statusCode);
116 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
117 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
118 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
120 // Store the ID returned from the first resource created
121 // for additional tests below.
122 if (knownResourceId == null) {
123 knownResourceId = extractId(res);
124 if (logger.isDebugEnabled()) {
125 logger.debug(testName + ": knownResourceId=" + knownResourceId);
129 // Store the IDs from every resource created by tests,
130 // so they can be deleted after tests have been run.
131 allResourceIdsCreated.add(extractId(res));
135 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
138 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
139 dependsOnMethods = {"create"})
140 public void createList(String testName) throws Exception {
141 for (int i = 0; i < 3; i++) {
147 // Placeholders until the three tests below can be uncommented.
148 // See Issue CSPACE-401.
150 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
153 public void createWithEmptyEntityBody(String testName) throws Exception {
154 //Should this really be empty?
158 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
161 public void createWithMalformedXml(String testName) throws Exception {
162 //Should this really be empty?
166 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
169 public void createWithWrongXmlSchema(String testName) throws Exception {
170 //Should this really be empty?
175 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
176 dependsOnMethods = {"create", "testSubmitRequest"})
177 public void createWithEmptyEntityBody(String testName) throws Exception {
179 if (logger.isDebugEnabled()) {
180 logger.debug(testBanner(testName, CLASS_NAME));
183 setupCreateWithEmptyEntityBody();
185 // Submit the request to the service and store the response.
186 String method = REQUEST_TYPE.httpMethodName();
187 String url = getServiceRootURL();
188 String mediaType = MediaType.APPLICATION_XML;
189 final String entity = "";
190 int statusCode = submitRequest(method, url, mediaType, entity);
192 // Check the status code of the response: does it match
193 // the expected response(s)?
194 if(logger.isDebugEnabled()){
195 logger.debug("createWithEmptyEntityBody url=" + url +
196 " status=" + statusCode);
198 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
199 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
200 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
204 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
205 dependsOnMethods = {"create", "testSubmitRequest"})
206 public void createWithMalformedXml(String testName) throws Exception {
208 if (logger.isDebugEnabled()) {
209 logger.debug(testBanner(testName, CLASS_NAME));
212 setupCreateWithMalformedXml();
214 // Submit the request to the service and store the response.
215 String method = REQUEST_TYPE.httpMethodName();
216 String url = getServiceRootURL();
217 String mediaType = MediaType.APPLICATION_XML;
218 final String entity = MALFORMED_XML_DATA; // Constant from base class.
219 int statusCode = submitRequest(method, url, mediaType, entity);
221 // Check the status code of the response: does it match
222 // the expected response(s)?
223 if(logger.isDebugEnabled()){
224 logger.debug(testName + ": url=" + url +
225 " status=" + statusCode);
227 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
228 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
229 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
233 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
234 dependsOnMethods = {"create", "testSubmitRequest"})
235 public void createWithWrongXmlSchema(String testName) throws Exception {
237 if (logger.isDebugEnabled()) {
238 logger.debug(testBanner(testName, CLASS_NAME));
241 setupCreateWithWrongXmlSchema();
243 // Submit the request to the service and store the response.
244 String method = REQUEST_TYPE.httpMethodName();
245 String url = getServiceRootURL();
246 String mediaType = MediaType.APPLICATION_XML;
247 final String entity = WRONG_XML_SCHEMA_DATA;
248 int statusCode = submitRequest(method, url, mediaType, entity);
250 // Check the status code of the response: does it match
251 // the expected response(s)?
252 if(logger.isDebugEnabled()){
253 logger.debug(testName + ": url=" + url +
254 " status=" + statusCode);
256 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
257 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
258 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
261 // ---------------------------------------------------------------
262 // CRUD tests : READ tests
263 // ---------------------------------------------------------------
266 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
269 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
270 dependsOnMethods = {"create"})
271 public void read(String testName) throws Exception {
273 if (logger.isDebugEnabled()) {
274 logger.debug(testBanner(testName, CLASS_NAME));
279 // Submit the request to the service and store the response.
280 LoanoutClient client = new LoanoutClient();
281 ClientResponse<String> res = client.read(knownResourceId);
282 int statusCode = res.getStatus();
284 // Check the status code of the response: does it match
285 // the expected response(s)?
286 if (logger.isDebugEnabled()) {
287 logger.debug(testName + ": status = " + statusCode);
289 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
290 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
291 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
293 // Get the common part of the response and verify that it is not null.
294 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
295 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
296 LoansoutCommon loanoutCommon = null;
297 if (payloadInputPart != null) {
298 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
300 Assert.assertNotNull(loanoutCommon);
302 // Check selected fields in the common part.
303 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
305 LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
306 Assert.assertNotNull(statusGroupList);
307 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
308 Assert.assertNotNull(statusGroups);
309 Assert.assertTrue(statusGroups.size() > 0);
310 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
311 Assert.assertNotNull(statusGroup);
312 Assert.assertNotNull(statusGroup.getLoanedObjectStatus());
314 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
315 if (logger.isDebugEnabled()) {
316 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
317 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
319 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
320 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
321 + "' does not match expected data '" + getUTF8DataFragment());
326 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
329 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
330 dependsOnMethods = {"read"})
331 public void readNonExistent(String testName) throws Exception {
333 if (logger.isDebugEnabled()) {
334 logger.debug(testBanner(testName, CLASS_NAME));
337 setupReadNonExistent();
339 // Submit the request to the service and store the response.
340 LoanoutClient client = new LoanoutClient();
341 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
342 int statusCode = res.getStatus();
344 // Check the status code of the response: does it match
345 // the expected response(s)?
346 if (logger.isDebugEnabled()) {
347 logger.debug(testName + ": status = " + statusCode);
349 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
350 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
351 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
354 // ---------------------------------------------------------------
355 // CRUD tests : READ_LIST tests
356 // ---------------------------------------------------------------
359 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
362 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
363 dependsOnMethods = {"createList", "read"})
364 public void readList(String testName) throws Exception {
366 if (logger.isDebugEnabled()) {
367 logger.debug(testBanner(testName, CLASS_NAME));
372 // Submit the request to the service and store the response.
373 LoanoutClient client = new LoanoutClient();
374 ClientResponse<AbstractCommonList> res = client.readList();
375 AbstractCommonList list = res.getEntity();
376 int statusCode = res.getStatus();
378 // Check the status code of the response: does it match
379 // the expected response(s)?
380 if (logger.isDebugEnabled()) {
381 logger.debug(testName + ": status = " + statusCode);
383 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
384 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
385 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387 // Optionally output additional data about list members for debugging.
388 boolean iterateThroughList = true;
389 if(iterateThroughList && logger.isDebugEnabled()){
390 ListItemsInAbstractCommonList(list, logger, testName);
397 // ---------------------------------------------------------------
398 // CRUD tests : UPDATE tests
399 // ---------------------------------------------------------------
402 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
405 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
406 dependsOnMethods = {"read"})
407 public void update(String testName) throws Exception {
409 if (logger.isDebugEnabled()) {
410 logger.debug(testBanner(testName, CLASS_NAME));
415 // Retrieve the contents of a resource to update.
416 LoanoutClient client = new LoanoutClient();
417 ClientResponse<String> res = client.read(knownResourceId);
418 if (logger.isDebugEnabled()) {
419 logger.debug(testName + ": read status = " + res.getStatus());
421 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
423 if (logger.isDebugEnabled()) {
424 logger.debug("got object to update with ID: " + knownResourceId);
427 // Extract the common part from the response.
428 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
429 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
430 LoansoutCommon loanoutCommon = null;
431 if (payloadInputPart != null) {
432 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
434 Assert.assertNotNull(loanoutCommon);
436 // Update the content of this resource.
437 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
438 loanoutCommon.setLoanReturnDate("updated-" + loanoutCommon.getLoanReturnDate());
439 LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
440 Assert.assertNotNull(statusGroupList);
441 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
442 Assert.assertNotNull(statusGroups);
443 Assert.assertTrue(statusGroups.size() > 0);
444 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
445 Assert.assertNotNull(statusGroup);
446 String loanedObjectStatus = statusGroup.getLoanedObjectStatus();
447 Assert.assertNotNull(loanedObjectStatus);
448 String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus;
449 statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus);
450 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
451 if (logger.isDebugEnabled()) {
452 logger.debug("to be updated object");
453 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
455 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
457 // Submit the updated resource in an update request to the service and store the response.
458 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
459 PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
460 commonPart.setLabel(client.getCommonPartName());
461 res = client.update(knownResourceId, output);
462 int statusCode = res.getStatus();
464 // Check the status code of the response: does it match the expected response(s)?
465 if (logger.isDebugEnabled()) {
466 logger.debug(testName + ": status = " + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472 // Extract the updated common part from the response.
473 input = new PoxPayloadIn(res.getEntity());
474 payloadInputPart = input.getPart(client.getCommonPartName());
475 LoansoutCommon updatedLoanoutCommon = null;
476 if (payloadInputPart != null) {
477 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
479 Assert.assertNotNull(updatedLoanoutCommon);
481 // Check selected fields in the updated resource.
482 Assert.assertEquals(updatedLoanoutCommon.getLoanReturnDate(),
483 loanoutCommon.getLoanReturnDate(),
484 "Data in updated object did not match submitted data.");
486 LoanedObjectStatusGroupList updatedStatusGroupList =
487 updatedLoanoutCommon.getLoanedObjectStatusGroupList();
488 Assert.assertNotNull(updatedStatusGroupList);
489 List<LoanedObjectStatusGroup> updatedStatusGroups =
490 updatedStatusGroupList.getLoanedObjectStatusGroup();
491 Assert.assertNotNull(updatedStatusGroups);
492 Assert.assertTrue(updatedStatusGroups.size() > 0);
493 Assert.assertNotNull(updatedStatusGroups.get(0));
494 Assert.assertEquals(updatedLoanedObjectStatus,
495 updatedStatusGroups.get(0).getLoanedObjectStatus(),
496 "Data in updated object did not match submitted data.");
498 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
499 if (logger.isDebugEnabled()) {
500 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
501 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
503 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
504 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
505 + "' does not contain expected data '" + getUTF8DataFragment());
506 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
507 loanoutCommon.getLoanOutNote(),
508 "Data in updated object did not match submitted data.");
512 // Placeholders until the three tests below can be uncommented.
513 // See Issue CSPACE-401.
515 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
518 public void updateWithEmptyEntityBody(String testName) throws Exception {
519 //Should this really be empty?
523 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
526 public void updateWithMalformedXml(String testName) throws Exception {
527 //Should this really be empty?
531 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
534 public void updateWithWrongXmlSchema(String testName) throws Exception {
535 //Should this really be empty?
540 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
541 dependsOnMethods = {"create", "update", "testSubmitRequest"})
542 public void updateWithEmptyEntityBody(String testName) throws Exception {
544 if (logger.isDebugEnabled()) {
545 logger.debug(testBanner(testName, CLASS_NAME));
548 setupUpdateWithEmptyEntityBody();
550 // Submit the request to the service and store the response.
551 String method = REQUEST_TYPE.httpMethodName();
552 String url = getResourceURL(knownResourceId);
553 String mediaType = MediaType.APPLICATION_XML;
554 final String entity = "";
555 int statusCode = submitRequest(method, url, mediaType, entity);
557 // Check the status code of the response: does it match
558 // the expected response(s)?
559 if(logger.isDebugEnabled()){
560 logger.debug(testName + ": url=" + url +
561 " status=" + statusCode);
563 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
564 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
565 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
569 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
570 dependsOnMethods = {"create", "update", "testSubmitRequest"})
571 public void updateWithMalformedXml(String testName) throws Exception {
573 if (logger.isDebugEnabled()) {
574 logger.debug(testBanner(testName, CLASS_NAME));
577 setupUpdateWithMalformedXml();
579 // Submit the request to the service and store the response.
580 String method = REQUEST_TYPE.httpMethodName();
581 String url = getResourceURL(knownResourceId);
582 String mediaType = MediaType.APPLICATION_XML;
583 final String entity = MALFORMED_XML_DATA;
584 int statusCode = submitRequest(method, url, mediaType, entity);
586 // Check the status code of the response: does it match
587 // the expected response(s)?
588 if(logger.isDebugEnabled()){
589 logger.debug(testName + ": url=" + url +
590 " status=" + statusCode);
592 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
593 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
594 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
598 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
599 dependsOnMethods = {"create", "update", "testSubmitRequest"})
600 public void updateWithWrongXmlSchema(String testName) throws Exception {
602 if (logger.isDebugEnabled()) {
603 logger.debug(testBanner(testName, CLASS_NAME));
606 setupUpdateWithWrongXmlSchema();
608 // Submit the request to the service and store the response.
609 String method = REQUEST_TYPE.httpMethodName();
610 String url = getResourceURL(knownResourceId);
611 String mediaType = MediaType.APPLICATION_XML;
612 final String entity = WRONG_XML_SCHEMA_DATA;
613 int statusCode = submitRequest(method, url, mediaType, entity);
615 // Check the status code of the response: does it match
616 // the expected response(s)?
617 if(logger.isDebugEnabled()){
618 logger.debug(testName + ": url=" + url +
619 " status=" + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
631 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
632 dependsOnMethods = {"update", "testSubmitRequest"})
633 public void updateNonExistent(String testName) throws Exception {
635 if (logger.isDebugEnabled()) {
636 logger.debug(testBanner(testName, CLASS_NAME));
639 setupUpdateNonExistent();
641 // Submit the request to the service and store the response.
642 // Note: The ID used in this 'create' call may be arbitrary.
643 // The only relevant ID may be the one used in update(), below.
644 LoanoutClient client = new LoanoutClient();
645 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
646 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
647 int statusCode = res.getStatus();
649 // Check the status code of the response: does it match
650 // the expected response(s)?
651 if (logger.isDebugEnabled()) {
652 logger.debug(testName + ": status = " + statusCode);
654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 // ---------------------------------------------------------------
660 // CRUD tests : DELETE tests
661 // ---------------------------------------------------------------
664 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
667 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
668 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
669 public void delete(String testName) throws Exception {
671 if (logger.isDebugEnabled()) {
672 logger.debug(testBanner(testName, CLASS_NAME));
677 // Submit the request to the service and store the response.
678 LoanoutClient client = new LoanoutClient();
679 ClientResponse<Response> res = client.delete(knownResourceId);
680 int statusCode = res.getStatus();
682 // Check the status code of the response: does it match
683 // the expected response(s)?
684 if (logger.isDebugEnabled()) {
685 logger.debug(testName + ": status = " + statusCode);
687 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
694 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
697 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
698 dependsOnMethods = {"delete"})
699 public void deleteNonExistent(String testName) throws Exception {
701 if (logger.isDebugEnabled()) {
702 logger.debug(testBanner(testName, CLASS_NAME));
705 setupDeleteNonExistent();
707 // Submit the request to the service and store the response.
708 LoanoutClient client = new LoanoutClient();
709 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
710 int statusCode = res.getStatus();
712 // Check the status code of the response: does it match
713 // the expected response(s)?
714 if (logger.isDebugEnabled()) {
715 logger.debug(testName + ": status = " + statusCode);
717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
722 // ---------------------------------------------------------------
723 // Utility tests : tests of code used in tests above
724 // ---------------------------------------------------------------
726 * Tests the code for manually submitting data that is used by several
727 * of the methods above.
729 @Test(dependsOnMethods = {"create", "read"})
730 public void testSubmitRequest() {
732 // Expected status code: 200 OK
733 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
735 // Submit the request to the service and store the response.
736 String method = ServiceRequestType.READ.httpMethodName();
737 String url = getResourceURL(knownResourceId);
738 int statusCode = submitRequest(method, url);
740 // Check the status code of the response: does it match
741 // the expected response(s)?
742 if (logger.isDebugEnabled()) {
743 logger.debug("testSubmitRequest: url=" + url
744 + " status=" + statusCode);
746 Assert.assertEquals(statusCode, EXPECTED_STATUS);
750 // ---------------------------------------------------------------
751 // Utility methods used by tests above
752 // ---------------------------------------------------------------
754 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
757 public String getServicePathComponent() {
758 return LoanoutClient.SERVICE_PATH_COMPONENT;
762 protected PoxPayloadOut createInstance(String identifier) {
763 return createLoanoutInstance(identifier);
767 * Creates the loanout instance.
769 * @param identifier the identifier
770 * @return the multipart output
772 private PoxPayloadOut createLoanoutInstance(String identifier) {
773 return createLoanoutInstance(
774 "loanoutNumber-" + identifier,
775 "returnDate-" + identifier);
779 * Creates the loanout instance.
781 * @param loanOutNumber the loan out number
782 * @param returnDate the return date
783 * @return the multipart output
785 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
787 LoansoutCommon loanoutCommon = new LoansoutCommon();
788 loanoutCommon.setLoanOutNumber(loanOutNumber);
789 loanoutCommon.setLoanReturnDate(returnDate);
790 loanoutCommon.setBorrower(
791 "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
792 loanoutCommon.setBorrowersContact(
793 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
794 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
795 LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList();
796 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
797 LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup();
798 statusGroup.setLoanedObjectStatus("returned");
799 statusGroup.setLoanedObjectStatusNote("Left under the front mat.");
800 statusGroups.add(statusGroup);
801 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
802 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
804 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
805 PayloadOutputPart commonPart =
806 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
807 commonPart.setLabel(new LoanoutClient().getCommonPartName());
809 if (logger.isDebugEnabled()) {
810 logger.debug("to be created, loanout common");
811 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
812 // logger.debug(multipart.toXML());
819 protected String getServiceName() {
820 return LoanoutClient.SERVICE_NAME;