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.common.datetime.GregorianCalendarDateTimeUtils;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.loanout.LoanStatusGroup;
39 import org.collectionspace.services.loanout.LoanStatusGroupList;
40 import org.collectionspace.services.loanout.LoansoutCommon;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * LoanoutServiceTest, carries out tests against a
52 * deployed and running Loanout (aka Loans Out) Service.
54 * $LastChangedRevision$
57 public class LoanoutServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 /** The known resource id. */
63 private String knownResourceId = null;
64 private final static String CURRENT_DATE_UTC =
65 GregorianCalendarDateTimeUtils.currentDateUTC();
68 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71 protected CollectionSpaceClient getClientInstance() {
72 return new LoanoutClient();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getAbstractCommonList(
80 ClientResponse<AbstractCommonList> response) {
81 return response.getEntity(AbstractCommonList.class);
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
89 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
92 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
93 public void create(String testName) throws Exception {
95 if (logger.isDebugEnabled()) {
96 logger.debug(testBanner(testName, CLASS_NAME));
98 // Perform setup, such as initializing the type of service request
99 // (e.g. CREATE, DELETE), its valid and expected status codes, and
100 // its associated HTTP method name (e.g. POST, DELETE).
103 // Submit the request to the service and store the response.
104 LoanoutClient client = new LoanoutClient();
105 String identifier = createIdentifier();
106 PoxPayloadOut multipart = createLoanoutInstance(identifier);
107 ClientResponse<Response> res = client.create(multipart);
109 int statusCode = res.getStatus();
111 // Check the status code of the response: does it match
112 // the expected response(s)?
115 // Does it fall within the set of valid status codes?
116 // Does it exactly match the expected status code?
117 if (logger.isDebugEnabled()) {
118 logger.debug(testName + ": status = " + statusCode);
120 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
121 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
122 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
124 // Store the ID returned from the first resource created
125 // for additional tests below.
126 if (knownResourceId == null) {
127 knownResourceId = extractId(res);
128 if (logger.isDebugEnabled()) {
129 logger.debug(testName + ": knownResourceId=" + knownResourceId);
133 // Store the IDs from every resource created by tests,
134 // so they can be deleted after tests have been run.
135 allResourceIdsCreated.add(extractId(res));
139 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
142 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
143 dependsOnMethods = {"create"})
144 public void createList(String testName) throws Exception {
145 for (int i = 0; i < 3; i++) {
151 // Placeholders until the three tests below can be uncommented.
152 // See Issue CSPACE-401.
154 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
157 public void createWithEmptyEntityBody(String testName) throws Exception {
158 //Should this really be empty?
162 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
165 public void createWithMalformedXml(String testName) throws Exception {
166 //Should this really be empty?
170 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
173 public void createWithWrongXmlSchema(String testName) throws Exception {
174 //Should this really be empty?
179 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
180 dependsOnMethods = {"create", "testSubmitRequest"})
181 public void createWithEmptyEntityBody(String testName) throws Exception {
183 if (logger.isDebugEnabled()) {
184 logger.debug(testBanner(testName, CLASS_NAME));
187 setupCreateWithEmptyEntityBody();
189 // Submit the request to the service and store the response.
190 String method = REQUEST_TYPE.httpMethodName();
191 String url = getServiceRootURL();
192 String mediaType = MediaType.APPLICATION_XML;
193 final String entity = "";
194 int statusCode = submitRequest(method, url, mediaType, entity);
196 // Check the status code of the response: does it match
197 // the expected response(s)?
198 if(logger.isDebugEnabled()){
199 logger.debug("createWithEmptyEntityBody url=" + url +
200 " status=" + statusCode);
202 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
203 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
204 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
208 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
209 dependsOnMethods = {"create", "testSubmitRequest"})
210 public void createWithMalformedXml(String testName) throws Exception {
212 if (logger.isDebugEnabled()) {
213 logger.debug(testBanner(testName, CLASS_NAME));
216 setupCreateWithMalformedXml();
218 // Submit the request to the service and store the response.
219 String method = REQUEST_TYPE.httpMethodName();
220 String url = getServiceRootURL();
221 String mediaType = MediaType.APPLICATION_XML;
222 final String entity = MALFORMED_XML_DATA; // Constant from base class.
223 int statusCode = submitRequest(method, url, mediaType, entity);
225 // Check the status code of the response: does it match
226 // the expected response(s)?
227 if(logger.isDebugEnabled()){
228 logger.debug(testName + ": url=" + url +
229 " status=" + statusCode);
231 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
232 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
233 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
237 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
238 dependsOnMethods = {"create", "testSubmitRequest"})
239 public void createWithWrongXmlSchema(String testName) throws Exception {
241 if (logger.isDebugEnabled()) {
242 logger.debug(testBanner(testName, CLASS_NAME));
245 setupCreateWithWrongXmlSchema();
247 // Submit the request to the service and store the response.
248 String method = REQUEST_TYPE.httpMethodName();
249 String url = getServiceRootURL();
250 String mediaType = MediaType.APPLICATION_XML;
251 final String entity = WRONG_XML_SCHEMA_DATA;
252 int statusCode = submitRequest(method, url, mediaType, entity);
254 // Check the status code of the response: does it match
255 // the expected response(s)?
256 if(logger.isDebugEnabled()){
257 logger.debug(testName + ": url=" + url +
258 " status=" + statusCode);
260 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
261 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
262 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265 // ---------------------------------------------------------------
266 // CRUD tests : READ tests
267 // ---------------------------------------------------------------
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
273 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
274 dependsOnMethods = {"create"})
275 public void read(String testName) throws Exception {
277 if (logger.isDebugEnabled()) {
278 logger.debug(testBanner(testName, CLASS_NAME));
283 // Submit the request to the service and store the response.
284 LoanoutClient client = new LoanoutClient();
285 ClientResponse<String> res = client.read(knownResourceId);
286 int statusCode = res.getStatus();
288 // Check the status code of the response: does it match
289 // the expected response(s)?
290 if (logger.isDebugEnabled()) {
291 logger.debug(testName + ": status = " + statusCode);
293 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
294 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
295 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
297 // Get the common part of the response and verify that it is not null.
298 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
299 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
300 LoansoutCommon loanoutCommon = null;
301 if (payloadInputPart != null) {
302 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
304 Assert.assertNotNull(loanoutCommon);
306 // Check selected fields in the common part.
307 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
309 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
310 Assert.assertNotNull(statusGroupList);
311 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
312 Assert.assertNotNull(statusGroups);
313 Assert.assertTrue(statusGroups.size() > 0);
314 LoanStatusGroup statusGroup = statusGroups.get(0);
315 Assert.assertNotNull(statusGroup);
316 Assert.assertNotNull(statusGroup.getLoanStatus());
318 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
319 if (logger.isDebugEnabled()) {
320 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
321 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
323 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
324 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
325 + "' does not match expected data '" + getUTF8DataFragment());
330 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
333 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
334 dependsOnMethods = {"read"})
335 public void readNonExistent(String testName) throws Exception {
337 if (logger.isDebugEnabled()) {
338 logger.debug(testBanner(testName, CLASS_NAME));
341 setupReadNonExistent();
343 // Submit the request to the service and store the response.
344 LoanoutClient client = new LoanoutClient();
345 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
346 int statusCode = res.getStatus();
348 // Check the status code of the response: does it match
349 // the expected response(s)?
350 if (logger.isDebugEnabled()) {
351 logger.debug(testName + ": status = " + statusCode);
353 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
354 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
355 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
358 // ---------------------------------------------------------------
359 // CRUD tests : READ_LIST tests
360 // ---------------------------------------------------------------
363 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
366 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
367 dependsOnMethods = {"createList", "read"})
368 public void readList(String testName) throws Exception {
370 if (logger.isDebugEnabled()) {
371 logger.debug(testBanner(testName, CLASS_NAME));
376 // Submit the request to the service and store the response.
377 LoanoutClient client = new LoanoutClient();
378 ClientResponse<AbstractCommonList> res = client.readList();
379 AbstractCommonList list = res.getEntity();
380 int statusCode = res.getStatus();
382 // Check the status code of the response: does it match
383 // the expected response(s)?
384 if (logger.isDebugEnabled()) {
385 logger.debug(testName + ": status = " + statusCode);
387 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
388 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
389 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
391 // Optionally output additional data about list members for debugging.
392 boolean iterateThroughList = true;
393 if(iterateThroughList && logger.isDebugEnabled()){
394 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
401 // ---------------------------------------------------------------
402 // CRUD tests : UPDATE tests
403 // ---------------------------------------------------------------
406 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
409 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
410 dependsOnMethods = {"read"})
411 public void update(String testName) throws Exception {
413 if (logger.isDebugEnabled()) {
414 logger.debug(testBanner(testName, CLASS_NAME));
419 // Retrieve the contents of a resource to update.
420 LoanoutClient client = new LoanoutClient();
421 ClientResponse<String> res = client.read(knownResourceId);
422 if (logger.isDebugEnabled()) {
423 logger.debug(testName + ": read status = " + res.getStatus());
425 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
427 if (logger.isDebugEnabled()) {
428 logger.debug("got object to update with ID: " + knownResourceId);
431 // Extract the common part from the response.
432 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
433 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
434 LoansoutCommon loanoutCommon = null;
435 if (payloadInputPart != null) {
436 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
438 Assert.assertNotNull(loanoutCommon);
440 // Update the content of this resource.
441 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
442 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
443 Assert.assertNotNull(statusGroupList);
444 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
445 Assert.assertNotNull(statusGroups);
446 Assert.assertTrue(statusGroups.size() > 0);
447 LoanStatusGroup statusGroup = statusGroups.get(0);
448 Assert.assertNotNull(statusGroup);
449 String loanStatus = statusGroup.getLoanStatus();
450 Assert.assertNotNull(loanStatus);
451 String updatedLoanStatus = "updated-" + loanStatus;
452 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
453 loanoutCommon.setLoanStatusGroupList(statusGroupList);
454 if (logger.isDebugEnabled()) {
455 logger.debug("to be updated object");
456 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
458 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
460 // Submit the updated resource in an update request to the service and store the response.
461 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
462 PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
463 commonPart.setLabel(client.getCommonPartName());
464 res = client.update(knownResourceId, output);
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match the expected response(s)?
468 if (logger.isDebugEnabled()) {
469 logger.debug(testName + ": status = " + statusCode);
471 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
472 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
473 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475 // Extract the updated common part from the response.
476 input = new PoxPayloadIn(res.getEntity());
477 payloadInputPart = input.getPart(client.getCommonPartName());
478 LoansoutCommon updatedLoanoutCommon = null;
479 if (payloadInputPart != null) {
480 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
482 Assert.assertNotNull(updatedLoanoutCommon);
484 // Check selected fields in the updated resource.
485 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
486 loanoutCommon.getLoanOutNumber(),
487 "Data in updated object did not match submitted data.");
489 LoanStatusGroupList updatedStatusGroupList =
490 updatedLoanoutCommon.getLoanStatusGroupList();
491 Assert.assertNotNull(updatedStatusGroupList);
492 List<LoanStatusGroup> updatedStatusGroups =
493 updatedStatusGroupList.getLoanStatusGroup();
494 Assert.assertNotNull(updatedStatusGroups);
495 Assert.assertTrue(updatedStatusGroups.size() > 0);
496 Assert.assertNotNull(updatedStatusGroups.get(0));
497 Assert.assertEquals(updatedLoanStatus,
498 updatedStatusGroups.get(0).getLoanStatus(),
499 "Data in updated object did not match submitted data.");
501 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
502 if (logger.isDebugEnabled()) {
503 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
504 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
506 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
507 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
508 + "' does not contain expected data '" + getUTF8DataFragment());
509 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
510 loanoutCommon.getLoanOutNote(),
511 "Data in updated object did not match submitted data.");
515 // Placeholders until the three tests below can be uncommented.
516 // See Issue CSPACE-401.
518 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
521 public void updateWithEmptyEntityBody(String testName) throws Exception {
522 //Should this really be empty?
526 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
529 public void updateWithMalformedXml(String testName) throws Exception {
530 //Should this really be empty?
534 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
537 public void updateWithWrongXmlSchema(String testName) throws Exception {
538 //Should this really be empty?
543 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
544 dependsOnMethods = {"create", "update", "testSubmitRequest"})
545 public void updateWithEmptyEntityBody(String testName) throws Exception {
547 if (logger.isDebugEnabled()) {
548 logger.debug(testBanner(testName, CLASS_NAME));
551 setupUpdateWithEmptyEntityBody();
553 // Submit the request to the service and store the response.
554 String method = REQUEST_TYPE.httpMethodName();
555 String url = getResourceURL(knownResourceId);
556 String mediaType = MediaType.APPLICATION_XML;
557 final String entity = "";
558 int statusCode = submitRequest(method, url, mediaType, entity);
560 // Check the status code of the response: does it match
561 // the expected response(s)?
562 if(logger.isDebugEnabled()){
563 logger.debug(testName + ": url=" + url +
564 " status=" + statusCode);
566 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
567 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
568 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
572 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
573 dependsOnMethods = {"create", "update", "testSubmitRequest"})
574 public void updateWithMalformedXml(String testName) throws Exception {
576 if (logger.isDebugEnabled()) {
577 logger.debug(testBanner(testName, CLASS_NAME));
580 setupUpdateWithMalformedXml();
582 // Submit the request to the service and store the response.
583 String method = REQUEST_TYPE.httpMethodName();
584 String url = getResourceURL(knownResourceId);
585 String mediaType = MediaType.APPLICATION_XML;
586 final String entity = MALFORMED_XML_DATA;
587 int statusCode = submitRequest(method, url, mediaType, entity);
589 // Check the status code of the response: does it match
590 // the expected response(s)?
591 if(logger.isDebugEnabled()){
592 logger.debug(testName + ": url=" + url +
593 " status=" + statusCode);
595 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
596 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
597 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
602 dependsOnMethods = {"create", "update", "testSubmitRequest"})
603 public void updateWithWrongXmlSchema(String testName) throws Exception {
605 if (logger.isDebugEnabled()) {
606 logger.debug(testBanner(testName, CLASS_NAME));
609 setupUpdateWithWrongXmlSchema();
611 // Submit the request to the service and store the response.
612 String method = REQUEST_TYPE.httpMethodName();
613 String url = getResourceURL(knownResourceId);
614 String mediaType = MediaType.APPLICATION_XML;
615 final String entity = WRONG_XML_SCHEMA_DATA;
616 int statusCode = submitRequest(method, url, mediaType, entity);
618 // Check the status code of the response: does it match
619 // the expected response(s)?
620 if(logger.isDebugEnabled()){
621 logger.debug(testName + ": url=" + url +
622 " status=" + statusCode);
624 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
625 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
626 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
631 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
634 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
635 dependsOnMethods = {"update", "testSubmitRequest"})
636 public void updateNonExistent(String testName) throws Exception {
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
642 setupUpdateNonExistent();
644 // Submit the request to the service and store the response.
645 // Note: The ID used in this 'create' call may be arbitrary.
646 // The only relevant ID may be the one used in update(), below.
647 LoanoutClient client = new LoanoutClient();
648 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
649 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
650 int statusCode = res.getStatus();
652 // Check the status code of the response: does it match
653 // the expected response(s)?
654 if (logger.isDebugEnabled()) {
655 logger.debug(testName + ": status = " + statusCode);
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
662 // ---------------------------------------------------------------
663 // CRUD tests : DELETE tests
664 // ---------------------------------------------------------------
667 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
670 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
671 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
672 public void delete(String testName) throws Exception {
674 if (logger.isDebugEnabled()) {
675 logger.debug(testBanner(testName, CLASS_NAME));
680 // Submit the request to the service and store the response.
681 LoanoutClient client = new LoanoutClient();
682 ClientResponse<Response> res = client.delete(knownResourceId);
683 int statusCode = res.getStatus();
685 // Check the status code of the response: does it match
686 // the expected response(s)?
687 if (logger.isDebugEnabled()) {
688 logger.debug(testName + ": status = " + statusCode);
690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
697 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
700 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
701 dependsOnMethods = {"delete"})
702 public void deleteNonExistent(String testName) throws Exception {
704 if (logger.isDebugEnabled()) {
705 logger.debug(testBanner(testName, CLASS_NAME));
708 setupDeleteNonExistent();
710 // Submit the request to the service and store the response.
711 LoanoutClient client = new LoanoutClient();
712 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
713 int statusCode = res.getStatus();
715 // Check the status code of the response: does it match
716 // the expected response(s)?
717 if (logger.isDebugEnabled()) {
718 logger.debug(testName + ": status = " + statusCode);
720 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
721 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
722 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725 // ---------------------------------------------------------------
726 // Utility tests : tests of code used in tests above
727 // ---------------------------------------------------------------
729 * Tests the code for manually submitting data that is used by several
730 * of the methods above.
732 @Test(dependsOnMethods = {"create", "read"})
733 public void testSubmitRequest() {
735 // Expected status code: 200 OK
736 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
738 // Submit the request to the service and store the response.
739 String method = ServiceRequestType.READ.httpMethodName();
740 String url = getResourceURL(knownResourceId);
741 int statusCode = submitRequest(method, url);
743 // Check the status code of the response: does it match
744 // the expected response(s)?
745 if (logger.isDebugEnabled()) {
746 logger.debug("testSubmitRequest: url=" + url
747 + " status=" + statusCode);
749 Assert.assertEquals(statusCode, EXPECTED_STATUS);
753 // ---------------------------------------------------------------
754 // Utility methods used by tests above
755 // ---------------------------------------------------------------
757 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
760 public String getServicePathComponent() {
761 return LoanoutClient.SERVICE_PATH_COMPONENT;
765 protected PoxPayloadOut createInstance(String identifier) {
766 return createLoanoutInstance(identifier);
770 * Creates the loanout instance.
772 * @param identifier the identifier
773 * @return the multipart output
775 private PoxPayloadOut createLoanoutInstance(String identifier) {
776 return createLoanoutInstance(
777 "loanoutNumber-" + identifier,
782 * Creates the loanout instance.
784 * @param loanOutNumber the loan out number
785 * @param returnDate the return date
786 * @return the multipart output
788 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
790 LoansoutCommon loanoutCommon = new LoansoutCommon();
791 loanoutCommon.setLoanOutNumber(loanOutNumber);
792 loanoutCommon.setLoanReturnDate(returnDate);
793 loanoutCommon.setBorrower(
794 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
795 loanoutCommon.setBorrowersContact(
796 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
797 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
798 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
799 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
800 LoanStatusGroup statusGroup = new LoanStatusGroup();
801 statusGroup.setLoanStatus("returned");
802 statusGroup.setLoanStatusNote("Left under the front mat.");
803 statusGroups.add(statusGroup);
804 loanoutCommon.setLoanStatusGroupList(statusGroupList);
805 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
807 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
808 PayloadOutputPart commonPart =
809 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
810 commonPart.setLabel(new LoanoutClient().getCommonPartName());
812 if (logger.isDebugEnabled()) {
813 logger.debug("to be created, loanout common");
814 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
815 // logger.debug(multipart.toXML());
822 protected String getServiceName() {
823 return LoanoutClient.SERVICE_NAME;