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.AbstractCommonListUtils;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoanoutClient;
32 import org.collectionspace.services.client.PayloadInputPart;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.common.api.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;
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 AbstractPoxServiceTestImpl<AbstractCommonList, LoansoutCommon> {
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 final static String CURRENT_DATE_UTC =
63 GregorianCalendarDateTimeUtils.currentDateUTC();
66 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
69 protected CollectionSpaceClient getClientInstance() {
70 return new LoanoutClient();
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
77 protected AbstractCommonList getCommonList(
78 ClientResponse<AbstractCommonList> response) {
79 return response.getEntity(AbstractCommonList.class);
82 // ---------------------------------------------------------------
83 // CRUD tests : CREATE tests
84 // ---------------------------------------------------------------
87 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
90 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
91 public void create(String testName) throws Exception {
92 // Perform setup, such as initializing the type of service request
93 // (e.g. CREATE, DELETE), its valid and expected status codes, and
94 // its associated HTTP method name (e.g. POST, DELETE).
97 // Submit the request to the service and store the response.
98 LoanoutClient client = new LoanoutClient();
99 String identifier = createIdentifier();
100 PoxPayloadOut multipart = createLoanoutInstance(identifier);
102 Response res = client.create(multipart);
104 int statusCode = res.getStatus();
106 // Check the status code of the response: does it match
107 // the expected response(s)?
110 // Does it fall within the set of valid status codes?
111 // Does it exactly match the expected status code?
112 if (logger.isDebugEnabled()) {
113 logger.debug(testName + ": status = " + statusCode);
115 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
116 invalidStatusCodeMessage(testRequestType, statusCode));
117 Assert.assertEquals(statusCode, testExpectedStatusCode);
118 newId = extractId(res);
123 // Store the ID returned from the first resource created
124 // for additional tests below.
125 if (knownResourceId == null) {
126 knownResourceId = newId;
127 if (logger.isDebugEnabled()) {
128 logger.debug(testName + ": knownResourceId=" + knownResourceId);
132 // Store the IDs from every resource created by tests,
133 // so they can be deleted after tests have been run.
134 allResourceIdsCreated.add(newId);
138 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
141 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
142 // dependsOnMethods = {"create"})
143 public void createList(String testName) throws Exception {
144 for (int i = 0; i < 3; i++) {
150 // Placeholders until the three tests below can be uncommented.
151 // See Issue CSPACE-401.
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
156 public void createWithEmptyEntityBody(String testName) throws Exception {
157 //Should this really be empty?
161 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
164 public void createWithMalformedXml(String testName) throws Exception {
165 //Should this really be empty?
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
172 public void createWithWrongXmlSchema(String testName) throws Exception {
173 //Should this really be empty?
178 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
179 dependsOnMethods = {"create", "testSubmitRequest"})
180 public void createWithEmptyEntityBody(String testName) throws Exception {
182 if (logger.isDebugEnabled()) {
183 logger.debug(testBanner(testName, CLASS_NAME));
186 setupCreateWithEmptyEntityBody();
188 // Submit the request to the service and store the response.
189 String method = REQUEST_TYPE.httpMethodName();
190 String url = getServiceRootURL();
191 String mediaType = MediaType.APPLICATION_XML;
192 final String entity = "";
193 int statusCode = submitRequest(method, url, mediaType, entity);
195 // Check the status code of the response: does it match
196 // the expected response(s)?
197 if(logger.isDebugEnabled()){
198 logger.debug("createWithEmptyEntityBody url=" + url +
199 " status=" + statusCode);
201 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
202 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
203 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
207 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
208 dependsOnMethods = {"create", "testSubmitRequest"})
209 public void createWithMalformedXml(String testName) throws Exception {
211 if (logger.isDebugEnabled()) {
212 logger.debug(testBanner(testName, CLASS_NAME));
215 setupCreateWithMalformedXml();
217 // Submit the request to the service and store the response.
218 String method = REQUEST_TYPE.httpMethodName();
219 String url = getServiceRootURL();
220 String mediaType = MediaType.APPLICATION_XML;
221 final String entity = MALFORMED_XML_DATA; // Constant from base class.
222 int statusCode = submitRequest(method, url, mediaType, entity);
224 // Check the status code of the response: does it match
225 // the expected response(s)?
226 if(logger.isDebugEnabled()){
227 logger.debug(testName + ": url=" + url +
228 " status=" + statusCode);
230 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
231 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
232 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
237 dependsOnMethods = {"create", "testSubmitRequest"})
238 public void createWithWrongXmlSchema(String testName) throws Exception {
240 if (logger.isDebugEnabled()) {
241 logger.debug(testBanner(testName, CLASS_NAME));
244 setupCreateWithWrongXmlSchema();
246 // Submit the request to the service and store the response.
247 String method = REQUEST_TYPE.httpMethodName();
248 String url = getServiceRootURL();
249 String mediaType = MediaType.APPLICATION_XML;
250 final String entity = WRONG_XML_SCHEMA_DATA;
251 int statusCode = submitRequest(method, url, mediaType, entity);
253 // Check the status code of the response: does it match
254 // the expected response(s)?
255 if(logger.isDebugEnabled()){
256 logger.debug(testName + ": url=" + url +
257 " status=" + statusCode);
259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
264 // ---------------------------------------------------------------
265 // CRUD tests : READ tests
266 // ---------------------------------------------------------------
269 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
272 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
273 // dependsOnMethods = {"create"})
274 public void read(String testName) throws Exception {
278 // Submit the request to the service and store the response.
279 LoanoutClient client = new LoanoutClient();
280 ClientResponse<String> res = client.read(knownResourceId);
281 LoansoutCommon loanoutCommon = null;
283 assertStatusCode(res, testName);
284 // Get the common part of the response and verify that it is not null.
285 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
286 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
287 if (payloadInputPart != null) {
288 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
290 Assert.assertNotNull(loanoutCommon);
293 res.releaseConnection();
297 // Check selected fields in the common part.
298 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
300 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
301 Assert.assertNotNull(statusGroupList);
302 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
303 Assert.assertNotNull(statusGroups);
304 Assert.assertTrue(statusGroups.size() > 0);
305 LoanStatusGroup statusGroup = statusGroups.get(0);
306 Assert.assertNotNull(statusGroup);
307 Assert.assertNotNull(statusGroup.getLoanStatus());
309 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
310 if (logger.isDebugEnabled()) {
311 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
312 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
314 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
315 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
316 + "' does not match expected data '" + getUTF8DataFragment());
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
324 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
325 // dependsOnMethods = {"read"})
326 public void readNonExistent(String testName) throws Exception {
328 setupReadNonExistent();
330 // Submit the request to the service and store the response.
331 LoanoutClient client = new LoanoutClient();
332 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
333 int statusCode = res.getStatus();
335 // Check the status code of the response: does it match
336 // the expected response(s)?
337 if (logger.isDebugEnabled()) {
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(testRequestType, statusCode));
342 Assert.assertEquals(statusCode, testExpectedStatusCode);
345 // ---------------------------------------------------------------
346 // CRUD tests : READ_LIST tests
347 // ---------------------------------------------------------------
350 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
353 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
354 // dependsOnMethods = {"createList", "read"})
355 public void readList(String testName) throws Exception {
359 // Submit the request to the service and store the response.
360 LoanoutClient client = new LoanoutClient();
361 ClientResponse<AbstractCommonList> res = client.readList();
362 AbstractCommonList list = null;
364 assertStatusCode(res, testName);
365 list = res.getEntity();
368 res.releaseConnection();
371 // Optionally output additional data about list members for debugging.
372 boolean iterateThroughList = true;
373 if (iterateThroughList && logger.isDebugEnabled()){
374 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
381 // ---------------------------------------------------------------
382 // CRUD tests : UPDATE tests
383 // ---------------------------------------------------------------
386 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
389 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
390 // dependsOnMethods = {"read"})
391 public void update(String testName) throws Exception {
395 // Retrieve the contents of a resource to update.
396 LoanoutClient client = new LoanoutClient();
397 ClientResponse<String> res = client.read(knownResourceId);
398 LoansoutCommon loanoutCommon = null;
400 assertStatusCode(res, testName);
401 // Extract the common part from the response.
402 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
403 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
404 if (payloadInputPart != null) {
405 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
407 Assert.assertNotNull(loanoutCommon);
410 res.releaseConnection();
414 // Update the content of this resource.
415 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
416 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
417 Assert.assertNotNull(statusGroupList);
418 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
419 Assert.assertNotNull(statusGroups);
420 Assert.assertTrue(statusGroups.size() > 0);
421 LoanStatusGroup statusGroup = statusGroups.get(0);
422 Assert.assertNotNull(statusGroup);
423 String loanStatus = statusGroup.getLoanStatus();
424 Assert.assertNotNull(loanStatus);
425 String updatedLoanStatus = "updated-" + loanStatus;
426 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
427 loanoutCommon.setLoanStatusGroupList(statusGroupList);
428 if (logger.isDebugEnabled()) {
429 logger.debug("to be updated object");
430 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
432 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
436 // Submit the updated resource in an update request to the service and store the response.
437 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
438 PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon);
440 res = client.update(knownResourceId, output);
441 LoansoutCommon updatedLoanoutCommon = null;
443 assertStatusCode(res, testName);
444 // Extract the updated common part from the response.
445 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
446 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
447 if (payloadInputPart != null) {
448 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
450 Assert.assertNotNull(updatedLoanoutCommon);
453 res.releaseConnection();
457 // Check selected fields in the updated resource.
458 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
459 loanoutCommon.getLoanOutNumber(),
460 "Data in updated object did not match submitted data.");
462 LoanStatusGroupList updatedStatusGroupList =
463 updatedLoanoutCommon.getLoanStatusGroupList();
464 Assert.assertNotNull(updatedStatusGroupList);
465 List<LoanStatusGroup> updatedStatusGroups =
466 updatedStatusGroupList.getLoanStatusGroup();
467 Assert.assertNotNull(updatedStatusGroups);
468 Assert.assertTrue(updatedStatusGroups.size() > 0);
469 Assert.assertNotNull(updatedStatusGroups.get(0));
470 Assert.assertEquals(updatedLoanStatus,
471 updatedStatusGroups.get(0).getLoanStatus(),
472 "Data in updated object did not match submitted data.");
474 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
475 if (logger.isDebugEnabled()) {
476 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
477 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
479 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
480 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
481 + "' does not contain expected data '" + getUTF8DataFragment());
482 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
483 loanoutCommon.getLoanOutNote(),
484 "Data in updated object did not match submitted data.");
488 // Placeholders until the three tests below can be uncommented.
489 // See Issue CSPACE-401.
491 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
494 public void updateWithEmptyEntityBody(String testName) throws Exception {
495 //Should this really be empty?
499 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
502 public void updateWithMalformedXml(String testName) throws Exception {
503 //Should this really be empty?
507 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
510 public void updateWithWrongXmlSchema(String testName) throws Exception {
511 //Should this really be empty?
516 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
517 dependsOnMethods = {"create", "update", "testSubmitRequest"})
518 public void updateWithEmptyEntityBody(String testName) throws Exception {
520 if (logger.isDebugEnabled()) {
521 logger.debug(testBanner(testName, CLASS_NAME));
524 setupUpdateWithEmptyEntityBody();
526 // Submit the request to the service and store the response.
527 String method = REQUEST_TYPE.httpMethodName();
528 String url = getResourceURL(knownResourceId);
529 String mediaType = MediaType.APPLICATION_XML;
530 final String entity = "";
531 int statusCode = submitRequest(method, url, mediaType, entity);
533 // Check the status code of the response: does it match
534 // the expected response(s)?
535 if(logger.isDebugEnabled()){
536 logger.debug(testName + ": url=" + url +
537 " status=" + statusCode);
539 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
545 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
546 dependsOnMethods = {"create", "update", "testSubmitRequest"})
547 public void updateWithMalformedXml(String testName) throws Exception {
549 if (logger.isDebugEnabled()) {
550 logger.debug(testBanner(testName, CLASS_NAME));
553 setupUpdateWithMalformedXml();
555 // Submit the request to the service and store the response.
556 String method = REQUEST_TYPE.httpMethodName();
557 String url = getResourceURL(knownResourceId);
558 String mediaType = MediaType.APPLICATION_XML;
559 final String entity = MALFORMED_XML_DATA;
560 int statusCode = submitRequest(method, url, mediaType, entity);
562 // Check the status code of the response: does it match
563 // the expected response(s)?
564 if(logger.isDebugEnabled()){
565 logger.debug(testName + ": url=" + url +
566 " status=" + statusCode);
568 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
569 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
570 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
574 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
575 dependsOnMethods = {"create", "update", "testSubmitRequest"})
576 public void updateWithWrongXmlSchema(String testName) throws Exception {
578 if (logger.isDebugEnabled()) {
579 logger.debug(testBanner(testName, CLASS_NAME));
582 setupUpdateWithWrongXmlSchema();
584 // Submit the request to the service and store the response.
585 String method = REQUEST_TYPE.httpMethodName();
586 String url = getResourceURL(knownResourceId);
587 String mediaType = MediaType.APPLICATION_XML;
588 final String entity = WRONG_XML_SCHEMA_DATA;
589 int statusCode = submitRequest(method, url, mediaType, entity);
591 // Check the status code of the response: does it match
592 // the expected response(s)?
593 if(logger.isDebugEnabled()){
594 logger.debug(testName + ": url=" + url +
595 " status=" + statusCode);
597 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
598 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
599 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
604 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
607 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
608 // dependsOnMethods = {"update", "testSubmitRequest"})
609 public void updateNonExistent(String testName) throws Exception {
611 setupUpdateNonExistent();
613 // Submit the request to the service and store the response.
614 // Note: The ID used in this 'create' call may be arbitrary.
615 // The only relevant ID may be the one used in update(), below.
616 LoanoutClient client = new LoanoutClient();
617 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
618 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
619 int statusCode = res.getStatus();
621 // Check the status code of the response: does it match
622 // the expected response(s)?
623 if (logger.isDebugEnabled()) {
624 logger.debug(testName + ": status = " + statusCode);
626 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
627 invalidStatusCodeMessage(testRequestType, statusCode));
628 Assert.assertEquals(statusCode, testExpectedStatusCode);
631 // ---------------------------------------------------------------
632 // CRUD tests : DELETE tests
633 // ---------------------------------------------------------------
636 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
639 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
640 // dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
641 public void delete(String testName) throws Exception {
645 // Submit the request to the service and store the response.
646 LoanoutClient client = new LoanoutClient();
647 ClientResponse<Response> res = client.delete(knownResourceId);
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(testRequestType.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(testRequestType, statusCode));
657 Assert.assertEquals(statusCode, testExpectedStatusCode);
662 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
665 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
666 // dependsOnMethods = {"delete"})
667 public void deleteNonExistent(String testName) throws Exception {
669 setupDeleteNonExistent();
671 // Submit the request to the service and store the response.
672 LoanoutClient client = new LoanoutClient();
673 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
674 int statusCode = res.getStatus();
676 // Check the status code of the response: does it match
677 // the expected response(s)?
678 if (logger.isDebugEnabled()) {
679 logger.debug(testName + ": status = " + statusCode);
681 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(testRequestType, statusCode));
683 Assert.assertEquals(statusCode, testExpectedStatusCode);
686 // ---------------------------------------------------------------
687 // Utility tests : tests of code used in tests above
688 // ---------------------------------------------------------------
690 * Tests the code for manually submitting data that is used by several
691 * of the methods above.
693 // @Test(dependsOnMethods = {"create", "read"})
694 public void testSubmitRequest() {
696 // Expected status code: 200 OK
697 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
699 // Submit the request to the service and store the response.
700 String method = ServiceRequestType.READ.httpMethodName();
701 String url = getResourceURL(knownResourceId);
702 int statusCode = submitRequest(method, url);
704 // Check the status code of the response: does it match
705 // the expected response(s)?
706 if (logger.isDebugEnabled()) {
707 logger.debug("testSubmitRequest: url=" + url
708 + " status=" + statusCode);
710 Assert.assertEquals(statusCode, EXPECTED_STATUS);
714 // ---------------------------------------------------------------
715 // Utility methods used by tests above
716 // ---------------------------------------------------------------
718 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
721 public String getServicePathComponent() {
722 return LoanoutClient.SERVICE_PATH_COMPONENT;
726 protected PoxPayloadOut createInstance(String identifier) {
727 return createLoanoutInstance(identifier);
731 * Creates the loanout instance.
733 * @param identifier the identifier
734 * @return the multipart output
736 private PoxPayloadOut createLoanoutInstance(String identifier) {
737 return createLoanoutInstance(
738 "loanoutNumber-" + identifier,
743 * Creates the loanout instance.
745 * @param loanOutNumber the loan out number
746 * @param returnDate the return date
747 * @return the multipart output
749 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
751 LoansoutCommon loanoutCommon = new LoansoutCommon();
752 loanoutCommon.setLoanOutNumber(loanOutNumber);
753 loanoutCommon.setLoanReturnDate(returnDate);
754 loanoutCommon.setBorrower(
755 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
756 loanoutCommon.setBorrowersContact(
757 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
758 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
759 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
760 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
761 LoanStatusGroup statusGroup = new LoanStatusGroup();
762 statusGroup.setLoanStatus("returned");
763 statusGroup.setLoanStatusNote("Left under the front mat.");
764 statusGroups.add(statusGroup);
765 loanoutCommon.setLoanStatusGroupList(statusGroupList);
766 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
768 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
769 PayloadOutputPart commonPart =
770 multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon);
772 if (logger.isDebugEnabled()) {
773 logger.debug("to be created, loanout common");
774 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
775 // logger.debug(multipart.toXML());
782 protected String getServiceName() {
783 return LoanoutClient.SERVICE_NAME;
787 public void CRUDTests(String testName) {
788 // TODO Auto-generated method stub
793 protected PoxPayloadOut createInstance(String commonPartName,
795 PoxPayloadOut result = createLoanoutInstance(identifier);
800 protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) {
801 // TODO Auto-generated method stub
806 protected void compareUpdatedInstances(LoansoutCommon original,
807 LoansoutCommon updated) throws Exception {
808 // TODO Auto-generated method stub