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;
39 import org.collectionspace.services.loanout.LoansoutCommonList;
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(LoansoutCommonList.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<LoansoutCommonList> res = client.readList();
376 LoansoutCommonList 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 = false;
390 if (iterateThroughList && logger.isDebugEnabled()) {
391 List<LoansoutCommonList.LoanoutListItem> items =
392 list.getLoanoutListItem();
394 for (LoansoutCommonList.LoanoutListItem item : items) {
395 logger.debug(testName + ": list-item[" + i + "] csid="
397 logger.debug(testName + ": list-item[" + i + "] loanOutNumber="
398 + item.getLoanOutNumber());
399 logger.debug(testName + ": list-item[" + i + "] URI="
409 // ---------------------------------------------------------------
410 // CRUD tests : UPDATE tests
411 // ---------------------------------------------------------------
414 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
417 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
418 dependsOnMethods = {"read"})
419 public void update(String testName) throws Exception {
421 if (logger.isDebugEnabled()) {
422 logger.debug(testBanner(testName, CLASS_NAME));
427 // Retrieve the contents of a resource to update.
428 LoanoutClient client = new LoanoutClient();
429 ClientResponse<String> res = client.read(knownResourceId);
430 if (logger.isDebugEnabled()) {
431 logger.debug(testName + ": read status = " + res.getStatus());
433 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
435 if (logger.isDebugEnabled()) {
436 logger.debug("got object to update with ID: " + knownResourceId);
439 // Extract the common part from the response.
440 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
441 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
442 LoansoutCommon loanoutCommon = null;
443 if (payloadInputPart != null) {
444 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
446 Assert.assertNotNull(loanoutCommon);
448 // Update the content of this resource.
449 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
450 loanoutCommon.setLoanReturnDate("updated-" + loanoutCommon.getLoanReturnDate());
451 LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
452 Assert.assertNotNull(statusGroupList);
453 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
454 Assert.assertNotNull(statusGroups);
455 Assert.assertTrue(statusGroups.size() > 0);
456 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
457 Assert.assertNotNull(statusGroup);
458 String loanedObjectStatus = statusGroup.getLoanedObjectStatus();
459 Assert.assertNotNull(loanedObjectStatus);
460 String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus;
461 statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus);
462 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
463 if (logger.isDebugEnabled()) {
464 logger.debug("to be updated object");
465 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
467 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
469 // Submit the updated resource in an update request to the service and store the response.
470 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
471 PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
472 commonPart.setLabel(client.getCommonPartName());
473 res = client.update(knownResourceId, output);
474 int statusCode = res.getStatus();
476 // Check the status code of the response: does it match the expected response(s)?
477 if (logger.isDebugEnabled()) {
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 // Extract the updated common part from the response.
485 input = new PoxPayloadIn(res.getEntity());
486 payloadInputPart = input.getPart(client.getCommonPartName());
487 LoansoutCommon updatedLoanoutCommon = null;
488 if (payloadInputPart != null) {
489 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
491 Assert.assertNotNull(updatedLoanoutCommon);
493 // Check selected fields in the updated resource.
494 Assert.assertEquals(updatedLoanoutCommon.getLoanReturnDate(),
495 loanoutCommon.getLoanReturnDate(),
496 "Data in updated object did not match submitted data.");
498 LoanedObjectStatusGroupList updatedStatusGroupList =
499 updatedLoanoutCommon.getLoanedObjectStatusGroupList();
500 Assert.assertNotNull(updatedStatusGroupList);
501 List<LoanedObjectStatusGroup> updatedStatusGroups =
502 updatedStatusGroupList.getLoanedObjectStatusGroup();
503 Assert.assertNotNull(updatedStatusGroups);
504 Assert.assertTrue(updatedStatusGroups.size() > 0);
505 Assert.assertNotNull(updatedStatusGroups.get(0));
506 Assert.assertEquals(updatedLoanedObjectStatus,
507 updatedStatusGroups.get(0).getLoanedObjectStatus(),
508 "Data in updated object did not match submitted data.");
510 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
511 if (logger.isDebugEnabled()) {
512 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
513 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
515 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
516 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
517 + "' does not contain expected data '" + getUTF8DataFragment());
518 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
519 loanoutCommon.getLoanOutNote(),
520 "Data in updated object did not match submitted data.");
524 // Placeholders until the three tests below can be uncommented.
525 // See Issue CSPACE-401.
527 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
530 public void updateWithEmptyEntityBody(String testName) throws Exception {
531 //Should this really be empty?
535 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
538 public void updateWithMalformedXml(String testName) throws Exception {
539 //Should this really be empty?
543 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
546 public void updateWithWrongXmlSchema(String testName) throws Exception {
547 //Should this really be empty?
552 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
553 dependsOnMethods = {"create", "update", "testSubmitRequest"})
554 public void updateWithEmptyEntityBody(String testName) throws Exception {
556 if (logger.isDebugEnabled()) {
557 logger.debug(testBanner(testName, CLASS_NAME));
560 setupUpdateWithEmptyEntityBody();
562 // Submit the request to the service and store the response.
563 String method = REQUEST_TYPE.httpMethodName();
564 String url = getResourceURL(knownResourceId);
565 String mediaType = MediaType.APPLICATION_XML;
566 final String entity = "";
567 int statusCode = submitRequest(method, url, mediaType, entity);
569 // Check the status code of the response: does it match
570 // the expected response(s)?
571 if(logger.isDebugEnabled()){
572 logger.debug(testName + ": url=" + url +
573 " status=" + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
581 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
582 dependsOnMethods = {"create", "update", "testSubmitRequest"})
583 public void updateWithMalformedXml(String testName) throws Exception {
585 if (logger.isDebugEnabled()) {
586 logger.debug(testBanner(testName, CLASS_NAME));
589 setupUpdateWithMalformedXml();
591 // Submit the request to the service and store the response.
592 String method = REQUEST_TYPE.httpMethodName();
593 String url = getResourceURL(knownResourceId);
594 String mediaType = MediaType.APPLICATION_XML;
595 final String entity = MALFORMED_XML_DATA;
596 int statusCode = submitRequest(method, url, mediaType, entity);
598 // Check the status code of the response: does it match
599 // the expected response(s)?
600 if(logger.isDebugEnabled()){
601 logger.debug(testName + ": url=" + url +
602 " status=" + statusCode);
604 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
611 dependsOnMethods = {"create", "update", "testSubmitRequest"})
612 public void updateWithWrongXmlSchema(String testName) throws Exception {
614 if (logger.isDebugEnabled()) {
615 logger.debug(testBanner(testName, CLASS_NAME));
618 setupUpdateWithWrongXmlSchema();
620 // Submit the request to the service and store the response.
621 String method = REQUEST_TYPE.httpMethodName();
622 String url = getResourceURL(knownResourceId);
623 String mediaType = MediaType.APPLICATION_XML;
624 final String entity = WRONG_XML_SCHEMA_DATA;
625 int statusCode = submitRequest(method, url, mediaType, entity);
627 // Check the status code of the response: does it match
628 // the expected response(s)?
629 if(logger.isDebugEnabled()){
630 logger.debug(testName + ": url=" + url +
631 " status=" + statusCode);
633 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
634 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
635 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
643 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
644 dependsOnMethods = {"update", "testSubmitRequest"})
645 public void updateNonExistent(String testName) throws Exception {
647 if (logger.isDebugEnabled()) {
648 logger.debug(testBanner(testName, CLASS_NAME));
651 setupUpdateNonExistent();
653 // Submit the request to the service and store the response.
654 // Note: The ID used in this 'create' call may be arbitrary.
655 // The only relevant ID may be the one used in update(), below.
656 LoanoutClient client = new LoanoutClient();
657 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
658 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
659 int statusCode = res.getStatus();
661 // Check the status code of the response: does it match
662 // the expected response(s)?
663 if (logger.isDebugEnabled()) {
664 logger.debug(testName + ": status = " + statusCode);
666 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
667 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
668 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
671 // ---------------------------------------------------------------
672 // CRUD tests : DELETE tests
673 // ---------------------------------------------------------------
676 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
679 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
680 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
681 public void delete(String testName) throws Exception {
683 if (logger.isDebugEnabled()) {
684 logger.debug(testBanner(testName, CLASS_NAME));
689 // Submit the request to the service and store the response.
690 LoanoutClient client = new LoanoutClient();
691 ClientResponse<Response> res = client.delete(knownResourceId);
692 int statusCode = res.getStatus();
694 // Check the status code of the response: does it match
695 // the expected response(s)?
696 if (logger.isDebugEnabled()) {
697 logger.debug(testName + ": status = " + statusCode);
699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
706 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
709 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
710 dependsOnMethods = {"delete"})
711 public void deleteNonExistent(String testName) throws Exception {
713 if (logger.isDebugEnabled()) {
714 logger.debug(testBanner(testName, CLASS_NAME));
717 setupDeleteNonExistent();
719 // Submit the request to the service and store the response.
720 LoanoutClient client = new LoanoutClient();
721 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
722 int statusCode = res.getStatus();
724 // Check the status code of the response: does it match
725 // the expected response(s)?
726 if (logger.isDebugEnabled()) {
727 logger.debug(testName + ": status = " + statusCode);
729 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
730 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
731 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
734 // ---------------------------------------------------------------
735 // Utility tests : tests of code used in tests above
736 // ---------------------------------------------------------------
738 * Tests the code for manually submitting data that is used by several
739 * of the methods above.
741 @Test(dependsOnMethods = {"create", "read"})
742 public void testSubmitRequest() {
744 // Expected status code: 200 OK
745 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
747 // Submit the request to the service and store the response.
748 String method = ServiceRequestType.READ.httpMethodName();
749 String url = getResourceURL(knownResourceId);
750 int statusCode = submitRequest(method, url);
752 // Check the status code of the response: does it match
753 // the expected response(s)?
754 if (logger.isDebugEnabled()) {
755 logger.debug("testSubmitRequest: url=" + url
756 + " status=" + statusCode);
758 Assert.assertEquals(statusCode, EXPECTED_STATUS);
762 // ---------------------------------------------------------------
763 // Utility methods used by tests above
764 // ---------------------------------------------------------------
766 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
769 public String getServicePathComponent() {
770 return LoanoutClient.SERVICE_PATH_COMPONENT;
774 * Creates the loanout instance.
776 * @param identifier the identifier
777 * @return the multipart output
779 private PoxPayloadOut createLoanoutInstance(String identifier) {
780 return createLoanoutInstance(
781 "loanoutNumber-" + identifier,
782 "returnDate-" + identifier);
786 * Creates the loanout instance.
788 * @param loanOutNumber the loan out number
789 * @param returnDate the return date
790 * @return the multipart output
792 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
794 LoansoutCommon loanoutCommon = new LoansoutCommon();
795 loanoutCommon.setLoanOutNumber(loanOutNumber);
796 loanoutCommon.setLoanReturnDate(returnDate);
797 loanoutCommon.setBorrower(
798 "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
799 loanoutCommon.setBorrowersContact(
800 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
801 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
802 LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList();
803 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
804 LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup();
805 statusGroup.setLoanedObjectStatus("returned");
806 statusGroup.setLoanedObjectStatusNote("Left under the front mat.");
807 statusGroups.add(statusGroup);
808 loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
809 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
811 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
812 PayloadOutputPart commonPart =
813 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
814 commonPart.setLabel(new LoanoutClient().getCommonPartName());
816 if (logger.isDebugEnabled()) {
817 logger.debug("to be created, loanout common");
818 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
819 // logger.debug(multipart.toXML());
826 protected String getServiceName() {
827 return LoanoutClient.SERVICE_NAME;