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);
101 ClientResponse<Response> res = client.create(multipart);
103 int statusCode = res.getStatus();
105 // Check the status code of the response: does it match
106 // the expected response(s)?
109 // Does it fall within the set of valid status codes?
110 // Does it exactly match the expected status code?
111 if (logger.isDebugEnabled()) {
112 logger.debug(testName + ": status = " + statusCode);
114 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
115 invalidStatusCodeMessage(testRequestType, statusCode));
116 Assert.assertEquals(statusCode, testExpectedStatusCode);
118 // Store the ID returned from the first resource created
119 // for additional tests below.
120 if (knownResourceId == null) {
121 knownResourceId = extractId(res);
122 if (logger.isDebugEnabled()) {
123 logger.debug(testName + ": knownResourceId=" + knownResourceId);
127 // Store the IDs from every resource created by tests,
128 // so they can be deleted after tests have been run.
129 allResourceIdsCreated.add(extractId(res));
133 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
136 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
137 // dependsOnMethods = {"create"})
138 public void createList(String testName) throws Exception {
139 for (int i = 0; i < 3; i++) {
145 // Placeholders until the three tests below can be uncommented.
146 // See Issue CSPACE-401.
148 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
151 public void createWithEmptyEntityBody(String testName) throws Exception {
152 //Should this really be empty?
156 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
159 public void createWithMalformedXml(String testName) throws Exception {
160 //Should this really be empty?
164 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
167 public void createWithWrongXmlSchema(String testName) throws Exception {
168 //Should this really be empty?
173 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
174 dependsOnMethods = {"create", "testSubmitRequest"})
175 public void createWithEmptyEntityBody(String testName) throws Exception {
177 if (logger.isDebugEnabled()) {
178 logger.debug(testBanner(testName, CLASS_NAME));
181 setupCreateWithEmptyEntityBody();
183 // Submit the request to the service and store the response.
184 String method = REQUEST_TYPE.httpMethodName();
185 String url = getServiceRootURL();
186 String mediaType = MediaType.APPLICATION_XML;
187 final String entity = "";
188 int statusCode = submitRequest(method, url, mediaType, entity);
190 // Check the status code of the response: does it match
191 // the expected response(s)?
192 if(logger.isDebugEnabled()){
193 logger.debug("createWithEmptyEntityBody url=" + url +
194 " status=" + statusCode);
196 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
197 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
198 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
202 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
203 dependsOnMethods = {"create", "testSubmitRequest"})
204 public void createWithMalformedXml(String testName) throws Exception {
206 if (logger.isDebugEnabled()) {
207 logger.debug(testBanner(testName, CLASS_NAME));
210 setupCreateWithMalformedXml();
212 // Submit the request to the service and store the response.
213 String method = REQUEST_TYPE.httpMethodName();
214 String url = getServiceRootURL();
215 String mediaType = MediaType.APPLICATION_XML;
216 final String entity = MALFORMED_XML_DATA; // Constant from base class.
217 int statusCode = submitRequest(method, url, mediaType, entity);
219 // Check the status code of the response: does it match
220 // the expected response(s)?
221 if(logger.isDebugEnabled()){
222 logger.debug(testName + ": url=" + url +
223 " status=" + statusCode);
225 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
226 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
227 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
231 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
232 dependsOnMethods = {"create", "testSubmitRequest"})
233 public void createWithWrongXmlSchema(String testName) throws Exception {
235 if (logger.isDebugEnabled()) {
236 logger.debug(testBanner(testName, CLASS_NAME));
239 setupCreateWithWrongXmlSchema();
241 // Submit the request to the service and store the response.
242 String method = REQUEST_TYPE.httpMethodName();
243 String url = getServiceRootURL();
244 String mediaType = MediaType.APPLICATION_XML;
245 final String entity = WRONG_XML_SCHEMA_DATA;
246 int statusCode = submitRequest(method, url, mediaType, entity);
248 // Check the status code of the response: does it match
249 // the expected response(s)?
250 if(logger.isDebugEnabled()){
251 logger.debug(testName + ": url=" + url +
252 " status=" + statusCode);
254 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
255 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
256 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
259 // ---------------------------------------------------------------
260 // CRUD tests : READ tests
261 // ---------------------------------------------------------------
264 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
267 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268 // dependsOnMethods = {"create"})
269 public void read(String testName) throws Exception {
273 // Submit the request to the service and store the response.
274 LoanoutClient client = new LoanoutClient();
275 ClientResponse<String> res = client.read(knownResourceId);
276 LoansoutCommon loanoutCommon = null;
278 assertStatusCode(res, testName);
279 // Get the common part of the response and verify that it is not null.
280 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
281 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
282 if (payloadInputPart != null) {
283 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
285 Assert.assertNotNull(loanoutCommon);
288 res.releaseConnection();
292 // Check selected fields in the common part.
293 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
295 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
296 Assert.assertNotNull(statusGroupList);
297 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
298 Assert.assertNotNull(statusGroups);
299 Assert.assertTrue(statusGroups.size() > 0);
300 LoanStatusGroup statusGroup = statusGroups.get(0);
301 Assert.assertNotNull(statusGroup);
302 Assert.assertNotNull(statusGroup.getLoanStatus());
304 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
305 if (logger.isDebugEnabled()) {
306 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
307 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
309 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
310 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
311 + "' does not match expected data '" + getUTF8DataFragment());
316 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
319 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
320 // dependsOnMethods = {"read"})
321 public void readNonExistent(String testName) throws Exception {
323 setupReadNonExistent();
325 // Submit the request to the service and store the response.
326 LoanoutClient client = new LoanoutClient();
327 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
328 int statusCode = res.getStatus();
330 // Check the status code of the response: does it match
331 // the expected response(s)?
332 if (logger.isDebugEnabled()) {
333 logger.debug(testName + ": status = " + statusCode);
335 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
336 invalidStatusCodeMessage(testRequestType, statusCode));
337 Assert.assertEquals(statusCode, testExpectedStatusCode);
340 // ---------------------------------------------------------------
341 // CRUD tests : READ_LIST tests
342 // ---------------------------------------------------------------
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
348 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
349 // dependsOnMethods = {"createList", "read"})
350 public void readList(String testName) throws Exception {
354 // Submit the request to the service and store the response.
355 LoanoutClient client = new LoanoutClient();
356 ClientResponse<AbstractCommonList> res = client.readList();
357 AbstractCommonList list = null;
359 assertStatusCode(res, testName);
360 list = res.getEntity();
363 res.releaseConnection();
366 // Optionally output additional data about list members for debugging.
367 boolean iterateThroughList = true;
368 if (iterateThroughList && logger.isDebugEnabled()){
369 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
376 // ---------------------------------------------------------------
377 // CRUD tests : UPDATE tests
378 // ---------------------------------------------------------------
381 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
384 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385 // dependsOnMethods = {"read"})
386 public void update(String testName) throws Exception {
390 // Retrieve the contents of a resource to update.
391 LoanoutClient client = new LoanoutClient();
392 ClientResponse<String> res = client.read(knownResourceId);
393 LoansoutCommon loanoutCommon = null;
395 assertStatusCode(res, testName);
396 // Extract the common part from the response.
397 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
398 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
399 if (payloadInputPart != null) {
400 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
402 Assert.assertNotNull(loanoutCommon);
405 res.releaseConnection();
409 // Update the content of this resource.
410 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
411 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
412 Assert.assertNotNull(statusGroupList);
413 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
414 Assert.assertNotNull(statusGroups);
415 Assert.assertTrue(statusGroups.size() > 0);
416 LoanStatusGroup statusGroup = statusGroups.get(0);
417 Assert.assertNotNull(statusGroup);
418 String loanStatus = statusGroup.getLoanStatus();
419 Assert.assertNotNull(loanStatus);
420 String updatedLoanStatus = "updated-" + loanStatus;
421 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
422 loanoutCommon.setLoanStatusGroupList(statusGroupList);
423 if (logger.isDebugEnabled()) {
424 logger.debug("to be updated object");
425 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
427 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
431 // Submit the updated resource in an update request to the service and store the response.
432 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
433 PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon);
435 res = client.update(knownResourceId, output);
436 LoansoutCommon updatedLoanoutCommon = null;
438 assertStatusCode(res, testName);
439 // Extract the updated common part from the response.
440 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
441 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
442 if (payloadInputPart != null) {
443 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
445 Assert.assertNotNull(updatedLoanoutCommon);
448 res.releaseConnection();
452 // Check selected fields in the updated resource.
453 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
454 loanoutCommon.getLoanOutNumber(),
455 "Data in updated object did not match submitted data.");
457 LoanStatusGroupList updatedStatusGroupList =
458 updatedLoanoutCommon.getLoanStatusGroupList();
459 Assert.assertNotNull(updatedStatusGroupList);
460 List<LoanStatusGroup> updatedStatusGroups =
461 updatedStatusGroupList.getLoanStatusGroup();
462 Assert.assertNotNull(updatedStatusGroups);
463 Assert.assertTrue(updatedStatusGroups.size() > 0);
464 Assert.assertNotNull(updatedStatusGroups.get(0));
465 Assert.assertEquals(updatedLoanStatus,
466 updatedStatusGroups.get(0).getLoanStatus(),
467 "Data in updated object did not match submitted data.");
469 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
470 if (logger.isDebugEnabled()) {
471 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
472 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
474 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
475 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
476 + "' does not contain expected data '" + getUTF8DataFragment());
477 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
478 loanoutCommon.getLoanOutNote(),
479 "Data in updated object did not match submitted data.");
483 // Placeholders until the three tests below can be uncommented.
484 // See Issue CSPACE-401.
486 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
489 public void updateWithEmptyEntityBody(String testName) throws Exception {
490 //Should this really be empty?
494 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
497 public void updateWithMalformedXml(String testName) throws Exception {
498 //Should this really be empty?
502 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
505 public void updateWithWrongXmlSchema(String testName) throws Exception {
506 //Should this really be empty?
511 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
512 dependsOnMethods = {"create", "update", "testSubmitRequest"})
513 public void updateWithEmptyEntityBody(String testName) throws Exception {
515 if (logger.isDebugEnabled()) {
516 logger.debug(testBanner(testName, CLASS_NAME));
519 setupUpdateWithEmptyEntityBody();
521 // Submit the request to the service and store the response.
522 String method = REQUEST_TYPE.httpMethodName();
523 String url = getResourceURL(knownResourceId);
524 String mediaType = MediaType.APPLICATION_XML;
525 final String entity = "";
526 int statusCode = submitRequest(method, url, mediaType, entity);
528 // Check the status code of the response: does it match
529 // the expected response(s)?
530 if(logger.isDebugEnabled()){
531 logger.debug(testName + ": url=" + url +
532 " status=" + statusCode);
534 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
535 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
536 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
540 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
541 dependsOnMethods = {"create", "update", "testSubmitRequest"})
542 public void updateWithMalformedXml(String testName) throws Exception {
544 if (logger.isDebugEnabled()) {
545 logger.debug(testBanner(testName, CLASS_NAME));
548 setupUpdateWithMalformedXml();
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 = MALFORMED_XML_DATA;
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 updateWithWrongXmlSchema(String testName) throws Exception {
573 if (logger.isDebugEnabled()) {
574 logger.debug(testBanner(testName, CLASS_NAME));
577 setupUpdateWithWrongXmlSchema();
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 = WRONG_XML_SCHEMA_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);
599 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
602 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
603 // dependsOnMethods = {"update", "testSubmitRequest"})
604 public void updateNonExistent(String testName) throws Exception {
606 setupUpdateNonExistent();
608 // Submit the request to the service and store the response.
609 // Note: The ID used in this 'create' call may be arbitrary.
610 // The only relevant ID may be the one used in update(), below.
611 LoanoutClient client = new LoanoutClient();
612 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
613 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
614 int statusCode = res.getStatus();
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if (logger.isDebugEnabled()) {
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(testRequestType, statusCode));
623 Assert.assertEquals(statusCode, testExpectedStatusCode);
626 // ---------------------------------------------------------------
627 // CRUD tests : DELETE tests
628 // ---------------------------------------------------------------
631 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
634 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
635 // dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
636 public void delete(String testName) throws Exception {
640 // Submit the request to the service and store the response.
641 LoanoutClient client = new LoanoutClient();
642 ClientResponse<Response> res = client.delete(knownResourceId);
643 int statusCode = res.getStatus();
645 // Check the status code of the response: does it match
646 // the expected response(s)?
647 if (logger.isDebugEnabled()) {
648 logger.debug(testName + ": status = " + statusCode);
650 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
651 invalidStatusCodeMessage(testRequestType, statusCode));
652 Assert.assertEquals(statusCode, testExpectedStatusCode);
657 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
660 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
661 // dependsOnMethods = {"delete"})
662 public void deleteNonExistent(String testName) throws Exception {
664 setupDeleteNonExistent();
666 // Submit the request to the service and store the response.
667 LoanoutClient client = new LoanoutClient();
668 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
669 int statusCode = res.getStatus();
671 // Check the status code of the response: does it match
672 // the expected response(s)?
673 if (logger.isDebugEnabled()) {
674 logger.debug(testName + ": status = " + statusCode);
676 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
677 invalidStatusCodeMessage(testRequestType, statusCode));
678 Assert.assertEquals(statusCode, testExpectedStatusCode);
681 // ---------------------------------------------------------------
682 // Utility tests : tests of code used in tests above
683 // ---------------------------------------------------------------
685 * Tests the code for manually submitting data that is used by several
686 * of the methods above.
688 // @Test(dependsOnMethods = {"create", "read"})
689 public void testSubmitRequest() {
691 // Expected status code: 200 OK
692 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
694 // Submit the request to the service and store the response.
695 String method = ServiceRequestType.READ.httpMethodName();
696 String url = getResourceURL(knownResourceId);
697 int statusCode = submitRequest(method, url);
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if (logger.isDebugEnabled()) {
702 logger.debug("testSubmitRequest: url=" + url
703 + " status=" + statusCode);
705 Assert.assertEquals(statusCode, EXPECTED_STATUS);
709 // ---------------------------------------------------------------
710 // Utility methods used by tests above
711 // ---------------------------------------------------------------
713 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
716 public String getServicePathComponent() {
717 return LoanoutClient.SERVICE_PATH_COMPONENT;
721 protected PoxPayloadOut createInstance(String identifier) {
722 return createLoanoutInstance(identifier);
726 * Creates the loanout instance.
728 * @param identifier the identifier
729 * @return the multipart output
731 private PoxPayloadOut createLoanoutInstance(String identifier) {
732 return createLoanoutInstance(
733 "loanoutNumber-" + identifier,
738 * Creates the loanout instance.
740 * @param loanOutNumber the loan out number
741 * @param returnDate the return date
742 * @return the multipart output
744 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
746 LoansoutCommon loanoutCommon = new LoansoutCommon();
747 loanoutCommon.setLoanOutNumber(loanOutNumber);
748 loanoutCommon.setLoanReturnDate(returnDate);
749 loanoutCommon.setBorrower(
750 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
751 loanoutCommon.setBorrowersContact(
752 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
753 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
754 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
755 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
756 LoanStatusGroup statusGroup = new LoanStatusGroup();
757 statusGroup.setLoanStatus("returned");
758 statusGroup.setLoanStatusNote("Left under the front mat.");
759 statusGroups.add(statusGroup);
760 loanoutCommon.setLoanStatusGroupList(statusGroupList);
761 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
763 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
764 PayloadOutputPart commonPart =
765 multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon);
767 if (logger.isDebugEnabled()) {
768 logger.debug("to be created, loanout common");
769 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
770 // logger.debug(multipart.toXML());
777 protected String getServiceName() {
778 return LoanoutClient.SERVICE_NAME;
782 public void CRUDTests(String testName) {
783 // TODO Auto-generated method stub
788 protected PoxPayloadOut createInstance(String commonPartName,
790 PoxPayloadOut result = createLoanoutInstance(identifier);
795 protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) {
796 // TODO Auto-generated method stub
801 protected void compareUpdatedInstances(LoansoutCommon original,
802 LoansoutCommon updated) throws Exception {
803 // TODO Auto-generated method stub