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.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoaninClient;
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.AbstractCommonListUtils;
37 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.loanin.LenderGroup;
40 import org.collectionspace.services.loanin.LenderGroupList;
41 import org.collectionspace.services.loanin.LoansinCommon;
43 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 * LoaninServiceTest, carries out tests against a
52 * deployed and running Loanin (aka Loans In) Service.
54 * $LastChangedRevision$
57 public class LoaninServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = LoaninServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 // Instance variables specific to this test.
63 /** The service path component. */
64 final String SERVICE_NAME = "loansin";
65 final String SERVICE_PATH_COMPONENT = "loansin";
66 /** The known resource id. */
67 private String knownResourceId = null;
68 private String LENDER_REF_NAME =
69 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(HarryLender)'Harry Lender'";
70 private final static String CURRENT_DATE_UTC =
71 GregorianCalendarDateTimeUtils.currentDateUTC();
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
77 protected CollectionSpaceClient getClientInstance() {
78 return new LoaninClient();
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
85 protected AbstractCommonList getAbstractCommonList(
86 ClientResponse<AbstractCommonList> response) {
87 return response.getEntity(AbstractCommonList.class);
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
97 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
101 public void create(String testName) throws Exception {
103 if (logger.isDebugEnabled()) {
104 logger.debug(testBanner(testName, CLASS_NAME));
106 // Perform setup, such as initializing the type of service request
107 // (e.g. CREATE, DELETE), its valid and expected status codes, and
108 // its associated HTTP method name (e.g. POST, DELETE).
111 // Submit the request to the service and store the response.
112 LoaninClient client = new LoaninClient();
113 String identifier = createIdentifier();
114 PoxPayloadOut multipart = createLoaninInstance(identifier);
116 ClientResponse<Response> res = client.create(multipart);
118 int statusCode = res.getStatus();
120 // Check the status code of the response: does it match
121 // the expected response(s)?
124 // Does it fall within the set of valid status codes?
125 // Does it exactly match the expected status code?
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": status = " + statusCode);
129 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
130 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
131 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
133 newID = extractId(res);
135 res.releaseConnection();
138 // Store the ID returned from the first resource created
139 // for additional tests below.
140 if (knownResourceId == null) {
141 knownResourceId = newID;
142 if (logger.isDebugEnabled()) {
143 logger.debug(testName + ": knownResourceId=" + knownResourceId);
147 // Store the IDs from every resource created by tests,
148 // so they can be deleted after tests have been run.
149 allResourceIdsCreated.add(newID);
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
156 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
157 dependsOnMethods = {"create"})
158 public void createList(String testName) throws Exception {
159 for (int i = 0; i < 3; i++) {
165 // Placeholders until the three tests below can be uncommented.
166 // See Issue CSPACE-401.
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
172 public void createWithEmptyEntityBody(String testName) throws Exception {
173 //Should this really be empty?
177 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
180 public void createWithMalformedXml(String testName) throws Exception {
181 //Should this really be empty?
185 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
188 public void createWithWrongXmlSchema(String testName) throws Exception {
189 //Should this really be empty?
194 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
195 dependsOnMethods = {"create", "testSubmitRequest"})
196 public void createWithEmptyEntityBody(String testName) throws Exception {
198 if (logger.isDebugEnabled()) {
199 logger.debug(testBanner(testName, CLASS_NAME));
202 setupCreateWithEmptyEntityBody();
204 // Submit the request to the service and store the response.
205 String method = REQUEST_TYPE.httpMethodName();
206 String url = getServiceRootURL();
207 String mediaType = MediaType.APPLICATION_XML;
208 final String entity = "";
209 int statusCode = submitRequest(method, url, mediaType, entity);
211 // Check the status code of the response: does it match
212 // the expected response(s)?
213 if(logger.isDebugEnabled()){
214 logger.debug("createWithEmptyEntityBody url=" + url +
215 " status=" + statusCode);
217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
219 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
223 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
224 dependsOnMethods = {"create", "testSubmitRequest"})
225 public void createWithMalformedXml(String testName) throws Exception {
227 if (logger.isDebugEnabled()) {
228 logger.debug(testBanner(testName, CLASS_NAME));
231 setupCreateWithMalformedXml(testName, logger);
233 // Submit the request to the service and store the response.
234 String method = REQUEST_TYPE.httpMethodName();
235 String url = getServiceRootURL();
236 String mediaType = MediaType.APPLICATION_XML;
237 final String entity = MALFORMED_XML_DATA; // Constant from base class.
238 int statusCode = submitRequest(method, url, mediaType, entity);
240 // Check the status code of the response: does it match
241 // the expected response(s)?
242 if(logger.isDebugEnabled()){
243 logger.debug(testName + ": url=" + url +
244 " status=" + statusCode);
246 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
247 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
248 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
253 dependsOnMethods = {"create", "testSubmitRequest"})
254 public void createWithWrongXmlSchema(String testName) throws Exception {
256 if (logger.isDebugEnabled()) {
257 logger.debug(testBanner(testName, CLASS_NAME));
260 setupCreateWithWrongXmlSchema(testName, logger);
262 // Submit the request to the service and store the response.
263 String method = REQUEST_TYPE.httpMethodName();
264 String url = getServiceRootURL();
265 String mediaType = MediaType.APPLICATION_XML;
266 final String entity = WRONG_XML_SCHEMA_DATA;
267 int statusCode = submitRequest(method, url, mediaType, entity);
269 // Check the status code of the response: does it match
270 // the expected response(s)?
271 if(logger.isDebugEnabled()){
272 logger.debug(testName + ": url=" + url +
273 " status=" + statusCode);
275 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
276 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
277 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
281 // ---------------------------------------------------------------
282 // CRUD tests : READ tests
283 // ---------------------------------------------------------------
288 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
291 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
292 dependsOnMethods = {"create"})
293 public void read(String testName) throws Exception {
295 if (logger.isDebugEnabled()) {
296 logger.debug(testBanner(testName, CLASS_NAME));
301 // Submit the request to the service and store the response.
302 LoaninClient client = new LoaninClient();
303 ClientResponse<String> res = client.read(knownResourceId);
304 PoxPayloadIn input = null;
306 int statusCode = res.getStatus();
308 // Check the status code of the response: does it match
309 // the expected response(s)?
310 if (logger.isDebugEnabled()) {
311 logger.debug(testName + ": status = " + statusCode);
313 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
314 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
315 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
316 input = new PoxPayloadIn(res.getEntity());
318 res.releaseConnection();
321 // Get the common part of the response and verify that it is not null.
322 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
323 LoansinCommon loaninCommon = null;
324 if (payloadInputPart != null) {
325 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
327 Assert.assertNotNull(loaninCommon);
329 // Check selected fields.
330 LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
331 Assert.assertNotNull(lenderGroupList);
332 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
333 Assert.assertNotNull(lenderGroups);
334 Assert.assertTrue(lenderGroups.size() > 0);
335 String lender = lenderGroups.get(0).getLender();
336 Assert.assertEquals(lender, LENDER_REF_NAME);
338 if (logger.isDebugEnabled()) {
339 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
340 + "UTF-8 data received=" + loaninCommon.getLoanInNote());
343 Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
344 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
345 + "' does not match expected data '" + getUTF8DataFragment());
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
354 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
355 dependsOnMethods = {"read"})
356 public void readNonExistent(String testName) throws Exception {
358 if (logger.isDebugEnabled()) {
359 logger.debug(testBanner(testName, CLASS_NAME));
362 setupReadNonExistent();
364 // Submit the request to the service and store the response.
365 LoaninClient client = new LoaninClient();
366 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
368 int statusCode = res.getStatus();
370 // Check the status code of the response: does it match
371 // the expected response(s)?
372 if (logger.isDebugEnabled()) {
373 logger.debug(testName + ": status = " + statusCode);
375 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
376 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
377 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
379 res.releaseConnection();
383 // ---------------------------------------------------------------
384 // CRUD tests : READ_LIST tests
385 // ---------------------------------------------------------------
390 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
393 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
394 dependsOnMethods = {"createList", "read"})
395 public void readList(String testName) throws Exception {
397 if (logger.isDebugEnabled()) {
398 logger.debug(testBanner(testName, CLASS_NAME));
403 // Submit the request to the service and store the response.
404 AbstractCommonList list = null;
405 LoaninClient client = new LoaninClient();
406 ClientResponse<AbstractCommonList> res = client.readList();
408 int statusCode = res.getStatus();
410 // Check the status code of the response: does it match
411 // the expected response(s)?
412 if (logger.isDebugEnabled()) {
413 logger.debug(testName + ": status = " + statusCode);
415 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
416 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
417 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
419 list = res.getEntity();
421 res.releaseConnection();
424 // Optionally output additional data about list members for debugging.
425 boolean iterateThroughList = true;
426 if(iterateThroughList && logger.isDebugEnabled()){
427 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
435 // ---------------------------------------------------------------
436 // CRUD tests : UPDATE tests
437 // ---------------------------------------------------------------
442 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
445 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
446 dependsOnMethods = {"read"})
447 public void update(String testName) throws Exception {
449 if (logger.isDebugEnabled()) {
450 logger.debug(testBanner(testName, CLASS_NAME));
455 // Retrieve the contents of a resource to update.
456 LoaninClient client = new LoaninClient();
457 ClientResponse<String> res = client.read(knownResourceId);
458 PoxPayloadIn input = null;
460 if (logger.isDebugEnabled()) {
461 logger.debug(testName + ": read status = " + res.getStatus());
463 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
465 if (logger.isDebugEnabled()) {
466 logger.debug("got object to update with ID: " + knownResourceId);
468 input = new PoxPayloadIn(res.getEntity());
470 res.releaseConnection();
473 // Extract the common part from the response.
474 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
475 LoansinCommon loaninCommon = null;
476 if (payloadInputPart != null) {
477 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
479 Assert.assertNotNull(loaninCommon);
481 // Update the content of this resource.
482 loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
483 loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
484 if (logger.isDebugEnabled()) {
485 logger.debug("to be updated object");
486 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
489 // Submit the updated common part in an update request to the service
490 // and store the response.
491 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
492 PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
493 commonPart.setLabel(client.getCommonPartName());
494 res = client.update(knownResourceId, output);
496 int statusCode = res.getStatus();
497 // Check the status code of the response: does it match the expected response(s)?
498 if (logger.isDebugEnabled()) {
499 logger.debug(testName + ": status = " + statusCode);
501 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
502 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
503 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
504 input = new PoxPayloadIn(res.getEntity());
506 res.releaseConnection();
509 // Extract the updated common part from the response.
510 payloadInputPart = input.getPart(client.getCommonPartName());
511 LoansinCommon updatedLoaninCommon = null;
512 if (payloadInputPart != null) {
513 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
515 Assert.assertNotNull(updatedLoaninCommon);
517 // Check selected fields in the updated common part.
518 Assert.assertEquals(updatedLoaninCommon.getLoanInNumber(),
519 loaninCommon.getLoanInNumber(),
520 "Data in updated object did not match submitted data.");
522 if (logger.isDebugEnabled()) {
523 logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
524 + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
526 Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
527 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
528 + "' does not contain expected data '" + getUTF8DataFragment());
529 Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
530 loaninCommon.getLoanInNote(),
531 "Data in updated object did not match submitted data.");
535 // Placeholders until the three tests below can be uncommented.
536 // See Issue CSPACE-401.
539 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
542 public void updateWithEmptyEntityBody(String testName) throws Exception {
543 //Should this really be empty?
547 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
550 public void updateWithMalformedXml(String testName) throws Exception {
551 //Should this really be empty?
555 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
558 public void updateWithWrongXmlSchema(String testName) throws Exception {
559 //Should this really be empty?
564 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
565 dependsOnMethods = {"create", "update", "testSubmitRequest"})
566 public void updateWithEmptyEntityBody(String testName) throws Exception {
568 if (logger.isDebugEnabled()) {
569 logger.debug(testBanner(testName, CLASS_NAME));
572 setupUpdateWithEmptyEntityBody();
574 // Submit the request to the service and store the response.
575 String method = REQUEST_TYPE.httpMethodName();
576 String url = getResourceURL(knownResourceId);
577 String mediaType = MediaType.APPLICATION_XML;
578 final String entity = "";
579 int statusCode = submitRequest(method, url, mediaType, entity);
581 // Check the status code of the response: does it match
582 // the expected response(s)?
583 if(logger.isDebugEnabled()){
584 logger.debug(testName + ": url=" + url +
585 " status=" + statusCode);
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
593 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
594 dependsOnMethods = {"create", "update", "testSubmitRequest"})
595 public void updateWithMalformedXml(String testName) throws Exception {
597 if (logger.isDebugEnabled()) {
598 logger.debug(testBanner(testName, CLASS_NAME));
601 setupUpdateWithMalformedXml();
603 // Submit the request to the service and store the response.
604 String method = REQUEST_TYPE.httpMethodName();
605 String url = getResourceURL(knownResourceId);
606 String mediaType = MediaType.APPLICATION_XML;
607 final String entity = MALFORMED_XML_DATA;
608 int statusCode = submitRequest(method, url, mediaType, entity);
610 // Check the status code of the response: does it match
611 // the expected response(s)?
612 if(logger.isDebugEnabled()){
613 logger.debug(testName + ": url=" + url +
614 " status=" + statusCode);
616 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
617 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
618 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
622 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
623 dependsOnMethods = {"create", "update", "testSubmitRequest"})
624 public void updateWithWrongXmlSchema(String testName) throws Exception {
626 if (logger.isDebugEnabled()) {
627 logger.debug(testBanner(testName, CLASS_NAME));
630 setupUpdateWithWrongXmlSchema();
632 // Submit the request to the service and store the response.
633 String method = REQUEST_TYPE.httpMethodName();
634 String url = getResourceURL(knownResourceId);
635 String mediaType = MediaType.APPLICATION_XML;
636 final String entity = WRONG_XML_SCHEMA_DATA;
637 int statusCode = submitRequest(method, url, mediaType, entity);
639 // Check the status code of the response: does it match
640 // the expected response(s)?
641 if(logger.isDebugEnabled()){
642 logger.debug(testName + ": url=" + url +
643 " status=" + statusCode);
645 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
655 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
656 dependsOnMethods = {"update", "testSubmitRequest"})
657 public void updateNonExistent(String testName) throws Exception {
659 if (logger.isDebugEnabled()) {
660 logger.debug(testBanner(testName, CLASS_NAME));
663 setupUpdateNonExistent();
665 // Submit the request to the service and store the response.
666 // Note: The ID used in this 'create' call may be arbitrary.
667 // The only relevant ID may be the one used in update(), below.
668 LoaninClient client = new LoaninClient();
669 PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
670 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
672 int statusCode = res.getStatus();
674 // Check the status code of the response: does it match
675 // the expected response(s)?
676 if (logger.isDebugEnabled()) {
677 logger.debug(testName + ": status = " + statusCode);
679 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
680 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
681 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
683 res.releaseConnection();
687 // ---------------------------------------------------------------
688 // CRUD tests : DELETE tests
689 // ---------------------------------------------------------------
694 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
697 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
698 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
699 public void delete(String testName) throws Exception {
701 if (logger.isDebugEnabled()) {
702 logger.debug(testBanner(testName, CLASS_NAME));
707 // Submit the request to the service and store the response.
708 LoaninClient client = new LoaninClient();
709 ClientResponse<Response> res = client.delete(knownResourceId);
711 int statusCode = res.getStatus();
713 // Check the status code of the response: does it match
714 // the expected response(s)?
715 if (logger.isDebugEnabled()) {
716 logger.debug(testName + ": status = " + statusCode);
718 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
719 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
720 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
722 res.releaseConnection();
729 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
732 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
733 dependsOnMethods = {"delete"})
734 public void deleteNonExistent(String testName) throws Exception {
736 if (logger.isDebugEnabled()) {
737 logger.debug(testBanner(testName, CLASS_NAME));
740 setupDeleteNonExistent();
742 // Submit the request to the service and store the response.
743 LoaninClient client = new LoaninClient();
744 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
746 int statusCode = res.getStatus();
748 // Check the status code of the response: does it match
749 // the expected response(s)?
750 if (logger.isDebugEnabled()) {
751 logger.debug(testName + ": status = " + statusCode);
753 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
754 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
755 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
757 res.releaseConnection();
761 // ---------------------------------------------------------------
762 // Utility tests : tests of code used in tests above
763 // ---------------------------------------------------------------
766 * Tests the code for manually submitting data that is used by several
767 * of the methods above.
769 @Test(dependsOnMethods = {"create", "read"})
770 public void testSubmitRequest() {
772 // Expected status code: 200 OK
773 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
775 // Submit the request to the service and store the response.
776 String method = ServiceRequestType.READ.httpMethodName();
777 String url = getResourceURL(knownResourceId);
778 int statusCode = submitRequest(method, url);
780 // Check the status code of the response: does it match
781 // the expected response(s)?
782 if (logger.isDebugEnabled()) {
783 logger.debug("testSubmitRequest: url=" + url
784 + " status=" + statusCode);
786 Assert.assertEquals(statusCode, EXPECTED_STATUS);
790 // ---------------------------------------------------------------
791 // Utility methods used by tests above
792 // ---------------------------------------------------------------
795 public String getServiceName() {
800 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
803 public String getServicePathComponent() {
804 return SERVICE_PATH_COMPONENT;
808 protected PoxPayloadOut createInstance(String identifier) {
809 return createLoaninInstance(identifier);
813 * Creates the loanin instance.
815 * @param identifier the identifier
816 * @return the multipart output
818 private PoxPayloadOut createLoaninInstance(String identifier) {
819 return createLoaninInstance(
820 "loaninNumber-" + identifier,
821 "returnDate-" + identifier);
825 * Creates the loanin instance.
827 * @param loaninNumber the loanin number
828 * @param returnDate the return date
829 * @return the multipart output
831 private PoxPayloadOut createLoaninInstance(String loaninNumber,
834 LoansinCommon loaninCommon = new LoansinCommon();
835 loaninCommon.setLoanInNumber(loaninNumber);
836 loaninCommon.setLoanReturnDate(CURRENT_DATE_UTC);
837 LenderGroupList lenderGroupList = new LenderGroupList();
838 LenderGroup lenderGroup = new LenderGroup();
839 lenderGroup.setLender(LENDER_REF_NAME);
840 lenderGroupList.getLenderGroup().add(lenderGroup);
841 loaninCommon.setLenderGroupList(lenderGroupList);
842 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
843 loaninCommon.setLoanInNote(getUTF8DataFragment());
845 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
846 PayloadOutputPart commonPart =
847 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
848 commonPart.setLabel(new LoaninClient().getCommonPartName());
850 if (logger.isDebugEnabled()) {
851 logger.debug("to be created, loanin common");
852 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));