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.jaxb.AbstractCommonList;
37 import org.collectionspace.services.loanin.LenderGroup;
38 import org.collectionspace.services.loanin.LenderGroupList;
39 import org.collectionspace.services.loanin.LoansinCommon;
41 import org.jboss.resteasy.client.ClientResponse;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * LoaninServiceTest, carries out tests against a
50 * deployed and running Loanin (aka Loans In) Service.
52 * $LastChangedRevision$
55 public class LoaninServiceTest extends AbstractServiceTestImpl {
58 private final String CLASS_NAME = LoaninServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 // Instance variables specific to this test.
62 /** The service path component. */
63 final String SERVICE_NAME = "loansin";
64 final String SERVICE_PATH_COMPONENT = "loansin";
66 /** The known resource id. */
67 private String knownResourceId = null;
69 private String LENDER_REF_NAME =
70 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
73 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
76 protected CollectionSpaceClient getClientInstance() {
77 return new LoaninClient();
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
84 protected AbstractCommonList getAbstractCommonList(
85 ClientResponse<AbstractCommonList> response) {
86 return response.getEntity(AbstractCommonList.class);
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
97 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
98 public void create(String testName) throws Exception {
100 if (logger.isDebugEnabled()) {
101 logger.debug(testBanner(testName, CLASS_NAME));
103 // Perform setup, such as initializing the type of service request
104 // (e.g. CREATE, DELETE), its valid and expected status codes, and
105 // its associated HTTP method name (e.g. POST, DELETE).
108 // Submit the request to the service and store the response.
109 LoaninClient client = new LoaninClient();
110 String identifier = createIdentifier();
111 PoxPayloadOut multipart = createLoaninInstance(identifier);
113 ClientResponse<Response> res = client.create(multipart);
115 int statusCode = res.getStatus();
117 // Check the status code of the response: does it match
118 // the expected response(s)?
121 // Does it fall within the set of valid status codes?
122 // Does it exactly match the expected status code?
123 if(logger.isDebugEnabled()){
124 logger.debug(testName + ": status = " + statusCode);
126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
130 newID = extractId(res);
132 res.releaseConnection();
135 // Store the ID returned from the first resource created
136 // for additional tests below.
137 if (knownResourceId == null){
138 knownResourceId = newID;
139 if (logger.isDebugEnabled()) {
140 logger.debug(testName + ": knownResourceId=" + knownResourceId);
144 // Store the IDs from every resource created by tests,
145 // so they can be deleted after tests have been run.
146 allResourceIdsCreated.add(newID);
150 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
153 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
154 dependsOnMethods = {"create"})
155 public void createList(String testName) throws Exception {
156 for(int i = 0; i < 3; i++){
162 // Placeholders until the three tests below can be uncommented.
163 // See Issue CSPACE-401.
165 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
168 public void createWithEmptyEntityBody(String testName) throws Exception {
169 //Should this really be empty?
173 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
176 public void createWithMalformedXml(String testName) throws Exception {
177 //Should this really be empty?
181 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
184 public void createWithWrongXmlSchema(String testName) throws Exception {
185 //Should this really be empty?
190 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
191 dependsOnMethods = {"create", "testSubmitRequest"})
192 public void createWithEmptyEntityBody(String testName) throws Exception {
194 if (logger.isDebugEnabled()) {
195 logger.debug(testBanner(testName, CLASS_NAME));
198 setupCreateWithEmptyEntityBody();
200 // Submit the request to the service and store the response.
201 String method = REQUEST_TYPE.httpMethodName();
202 String url = getServiceRootURL();
203 String mediaType = MediaType.APPLICATION_XML;
204 final String entity = "";
205 int statusCode = submitRequest(method, url, mediaType, entity);
207 // Check the status code of the response: does it match
208 // the expected response(s)?
209 if(logger.isDebugEnabled()){
210 logger.debug("createWithEmptyEntityBody url=" + url +
211 " status=" + statusCode);
213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
220 dependsOnMethods = {"create", "testSubmitRequest"})
221 public void createWithMalformedXml(String testName) throws Exception {
223 if (logger.isDebugEnabled()) {
224 logger.debug(testBanner(testName, CLASS_NAME));
227 setupCreateWithMalformedXml(testName, logger);
229 // Submit the request to the service and store the response.
230 String method = REQUEST_TYPE.httpMethodName();
231 String url = getServiceRootURL();
232 String mediaType = MediaType.APPLICATION_XML;
233 final String entity = MALFORMED_XML_DATA; // Constant from base class.
234 int statusCode = submitRequest(method, url, mediaType, entity);
236 // Check the status code of the response: does it match
237 // the expected response(s)?
238 if(logger.isDebugEnabled()){
239 logger.debug(testName + ": url=" + url +
240 " status=" + statusCode);
242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
244 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
249 dependsOnMethods = {"create", "testSubmitRequest"})
250 public void createWithWrongXmlSchema(String testName) throws Exception {
252 if (logger.isDebugEnabled()) {
253 logger.debug(testBanner(testName, CLASS_NAME));
256 setupCreateWithWrongXmlSchema(testName, logger);
258 // Submit the request to the service and store the response.
259 String method = REQUEST_TYPE.httpMethodName();
260 String url = getServiceRootURL();
261 String mediaType = MediaType.APPLICATION_XML;
262 final String entity = WRONG_XML_SCHEMA_DATA;
263 int statusCode = submitRequest(method, url, mediaType, entity);
265 // Check the status code of the response: does it match
266 // the expected response(s)?
267 if(logger.isDebugEnabled()){
268 logger.debug(testName + ": url=" + url +
269 " status=" + statusCode);
271 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
272 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
273 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
277 // ---------------------------------------------------------------
278 // CRUD tests : READ tests
279 // ---------------------------------------------------------------
282 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
285 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
286 dependsOnMethods = {"create"})
287 public void read(String testName) throws Exception {
289 if (logger.isDebugEnabled()) {
290 logger.debug(testBanner(testName, CLASS_NAME));
295 // Submit the request to the service and store the response.
296 LoaninClient client = new LoaninClient();
297 ClientResponse<String> res = client.read(knownResourceId);
298 PoxPayloadIn input = null;
300 int statusCode = res.getStatus();
302 // Check the status code of the response: does it match
303 // the expected response(s)?
304 if(logger.isDebugEnabled()){
305 logger.debug(testName + ": status = " + statusCode);
307 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
308 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
309 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
310 input = new PoxPayloadIn(res.getEntity());
312 res.releaseConnection();
315 // Get the common part of the response and verify that it is not null.
316 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
317 LoansinCommon loaninCommon = null;
318 if (payloadInputPart != null) {
319 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
321 Assert.assertNotNull(loaninCommon);
323 // Check selected fields.
324 LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
325 Assert.assertNotNull(lenderGroupList);
326 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
327 Assert.assertNotNull(lenderGroups);
328 Assert.assertTrue(lenderGroups.size() > 0);
329 String lender = lenderGroups.get(0).getLender();
330 Assert.assertEquals(lender, LENDER_REF_NAME);
332 if(logger.isDebugEnabled()){
333 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
334 + "UTF-8 data received=" + loaninCommon.getLoanInNote());
337 Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
338 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
339 + "' does not match expected data '" + getUTF8DataFragment());
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
348 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349 dependsOnMethods = {"read"})
350 public void readNonExistent(String testName) throws Exception {
352 if (logger.isDebugEnabled()) {
353 logger.debug(testBanner(testName, CLASS_NAME));
356 setupReadNonExistent();
358 // Submit the request to the service and store the response.
359 LoaninClient client = new LoaninClient();
360 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
362 int statusCode = res.getStatus();
364 // Check the status code of the response: does it match
365 // the expected response(s)?
366 if(logger.isDebugEnabled()){
367 logger.debug(testName + ": status = " + statusCode);
369 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
370 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
371 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
373 res.releaseConnection();
377 // ---------------------------------------------------------------
378 // CRUD tests : READ_LIST tests
379 // ---------------------------------------------------------------
382 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
385 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
386 dependsOnMethods = {"createList", "read"})
387 public void readList(String testName) throws Exception {
389 if (logger.isDebugEnabled()) {
390 logger.debug(testBanner(testName, CLASS_NAME));
395 // Submit the request to the service and store the response.
396 AbstractCommonList list = null;
397 LoaninClient client = new LoaninClient();
398 ClientResponse<AbstractCommonList> res = client.readList();
400 int statusCode = res.getStatus();
402 // Check the status code of the response: does it match
403 // the expected response(s)?
404 if(logger.isDebugEnabled()){
405 logger.debug(testName + ": status = " + statusCode);
407 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
408 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
409 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
411 list = res.getEntity();
413 res.releaseConnection();
416 // Optionally output additional data about list members for debugging.
417 boolean iterateThroughList = false;
418 if (iterateThroughList && logger.isDebugEnabled()){
419 List<AbstractCommonList.ListItem> items =
422 for(AbstractCommonList.ListItem item : items){
423 logger.debug(testName + ": list-item[" + i + "] " +
432 // ---------------------------------------------------------------
433 // CRUD tests : UPDATE tests
434 // ---------------------------------------------------------------
437 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
440 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
441 dependsOnMethods = {"read"})
442 public void update(String testName) throws Exception {
444 if (logger.isDebugEnabled()) {
445 logger.debug(testBanner(testName, CLASS_NAME));
450 // Retrieve the contents of a resource to update.
451 LoaninClient client = new LoaninClient();
452 ClientResponse<String> res = client.read(knownResourceId);
453 PoxPayloadIn input = null;
455 if(logger.isDebugEnabled()){
456 logger.debug(testName + ": read status = " + res.getStatus());
458 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
460 if(logger.isDebugEnabled()){
461 logger.debug("got object to update with ID: " + knownResourceId);
463 input = new PoxPayloadIn(res.getEntity());
465 res.releaseConnection();
468 // Extract the common part from the response.
469 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
470 LoansinCommon loaninCommon = null;
471 if (payloadInputPart != null) {
472 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
474 Assert.assertNotNull(loaninCommon);
476 // Update the content of this resource.
477 loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
478 loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate());
479 loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
480 if(logger.isDebugEnabled()){
481 logger.debug("to be updated object");
482 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
485 // Submit the updated common part in an update request to the service
486 // and store the response.
487 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
488 PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
489 commonPart.setLabel(client.getCommonPartName());
490 res = client.update(knownResourceId, output);
492 int statusCode = res.getStatus();
493 // Check the status code of the response: does it match the expected response(s)?
494 if(logger.isDebugEnabled()){
495 logger.debug(testName + ": status = " + statusCode);
497 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
498 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
499 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
500 input = new PoxPayloadIn(res.getEntity());
502 res.releaseConnection();
505 // Extract the updated common part from the response.
506 payloadInputPart = input.getPart(client.getCommonPartName());
507 LoansinCommon updatedLoaninCommon = null;
508 if (payloadInputPart != null) {
509 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
511 Assert.assertNotNull(updatedLoaninCommon);
513 // Check selected fields in the updated common part.
514 Assert.assertEquals(updatedLoaninCommon.getLoanReturnDate(),
515 loaninCommon.getLoanReturnDate(),
516 "Data in updated object did not match submitted data.");
518 if(logger.isDebugEnabled()){
519 logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
520 + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
522 Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
523 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
524 + "' does not contain expected data '" + getUTF8DataFragment());
525 Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
526 loaninCommon.getLoanInNote(),
527 "Data in updated object did not match submitted data.");
531 // Placeholders until the three tests below can be uncommented.
532 // See Issue CSPACE-401.
534 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
537 public void updateWithEmptyEntityBody(String testName) throws Exception {
538 //Should this really be empty?
542 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
545 public void updateWithMalformedXml(String testName) throws Exception {
546 //Should this really be empty?
550 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
553 public void updateWithWrongXmlSchema(String testName) throws Exception {
554 //Should this really be empty?
559 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
560 dependsOnMethods = {"create", "update", "testSubmitRequest"})
561 public void updateWithEmptyEntityBody(String testName) throws Exception {
563 if (logger.isDebugEnabled()) {
564 logger.debug(testBanner(testName, CLASS_NAME));
567 setupUpdateWithEmptyEntityBody();
569 // Submit the request to the service and store the response.
570 String method = REQUEST_TYPE.httpMethodName();
571 String url = getResourceURL(knownResourceId);
572 String mediaType = MediaType.APPLICATION_XML;
573 final String entity = "";
574 int statusCode = submitRequest(method, url, mediaType, entity);
576 // Check the status code of the response: does it match
577 // the expected response(s)?
578 if(logger.isDebugEnabled()){
579 logger.debug(testName + ": url=" + url +
580 " status=" + statusCode);
582 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
589 dependsOnMethods = {"create", "update", "testSubmitRequest"})
590 public void updateWithMalformedXml(String testName) throws Exception {
592 if (logger.isDebugEnabled()) {
593 logger.debug(testBanner(testName, CLASS_NAME));
596 setupUpdateWithMalformedXml();
598 // Submit the request to the service and store the response.
599 String method = REQUEST_TYPE.httpMethodName();
600 String url = getResourceURL(knownResourceId);
601 String mediaType = MediaType.APPLICATION_XML;
602 final String entity = MALFORMED_XML_DATA;
603 int statusCode = submitRequest(method, url, mediaType, entity);
605 // Check the status code of the response: does it match
606 // the expected response(s)?
607 if(logger.isDebugEnabled()){
608 logger.debug(testName + ": url=" + url +
609 " status=" + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
618 dependsOnMethods = {"create", "update", "testSubmitRequest"})
619 public void updateWithWrongXmlSchema(String testName) throws Exception {
621 if (logger.isDebugEnabled()) {
622 logger.debug(testBanner(testName, CLASS_NAME));
625 setupUpdateWithWrongXmlSchema();
627 // Submit the request to the service and store the response.
628 String method = REQUEST_TYPE.httpMethodName();
629 String url = getResourceURL(knownResourceId);
630 String mediaType = MediaType.APPLICATION_XML;
631 final String entity = WRONG_XML_SCHEMA_DATA;
632 int statusCode = submitRequest(method, url, mediaType, entity);
634 // Check the status code of the response: does it match
635 // the expected response(s)?
636 if(logger.isDebugEnabled()){
637 logger.debug(testName + ": url=" + url +
638 " status=" + statusCode);
640 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
647 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
650 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
651 dependsOnMethods = {"update", "testSubmitRequest"})
652 public void updateNonExistent(String testName) throws Exception {
654 if (logger.isDebugEnabled()) {
655 logger.debug(testBanner(testName, CLASS_NAME));
658 setupUpdateNonExistent();
660 // Submit the request to the service and store the response.
661 // Note: The ID used in this 'create' call may be arbitrary.
662 // The only relevant ID may be the one used in update(), below.
663 LoaninClient client = new LoaninClient();
664 PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
665 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
667 int statusCode = res.getStatus();
669 // Check the status code of the response: does it match
670 // the expected response(s)?
671 if(logger.isDebugEnabled()){
672 logger.debug(testName + ": status = " + statusCode);
674 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 res.releaseConnection();
682 // ---------------------------------------------------------------
683 // CRUD tests : DELETE tests
684 // ---------------------------------------------------------------
687 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
690 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
691 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
692 public void delete(String testName) throws Exception {
694 if (logger.isDebugEnabled()) {
695 logger.debug(testBanner(testName, CLASS_NAME));
700 // Submit the request to the service and store the response.
701 LoaninClient client = new LoaninClient();
702 ClientResponse<Response> res = client.delete(knownResourceId);
704 int statusCode = res.getStatus();
706 // Check the status code of the response: does it match
707 // the expected response(s)?
708 if(logger.isDebugEnabled()){
709 logger.debug(testName + ": status = " + statusCode);
711 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
712 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
713 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
715 res.releaseConnection();
721 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
724 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
725 dependsOnMethods = {"delete"})
726 public void deleteNonExistent(String testName) throws Exception {
728 if (logger.isDebugEnabled()) {
729 logger.debug(testBanner(testName, CLASS_NAME));
732 setupDeleteNonExistent();
734 // Submit the request to the service and store the response.
735 LoaninClient client = new LoaninClient();
736 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
738 int statusCode = res.getStatus();
740 // Check the status code of the response: does it match
741 // the expected response(s)?
742 if(logger.isDebugEnabled()){
743 logger.debug(testName + ": status = " + statusCode);
745 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
746 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
747 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
749 res.releaseConnection();
753 // ---------------------------------------------------------------
754 // Utility tests : tests of code used in tests above
755 // ---------------------------------------------------------------
757 * Tests the code for manually submitting data that is used by several
758 * of the methods above.
760 @Test(dependsOnMethods = {"create", "read"})
761 public void testSubmitRequest() {
763 // Expected status code: 200 OK
764 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
766 // Submit the request to the service and store the response.
767 String method = ServiceRequestType.READ.httpMethodName();
768 String url = getResourceURL(knownResourceId);
769 int statusCode = submitRequest(method, url);
771 // Check the status code of the response: does it match
772 // the expected response(s)?
773 if(logger.isDebugEnabled()){
774 logger.debug("testSubmitRequest: url=" + url +
775 " status=" + statusCode);
777 Assert.assertEquals(statusCode, EXPECTED_STATUS);
781 // ---------------------------------------------------------------
782 // Utility methods used by tests above
783 // ---------------------------------------------------------------
786 public String getServiceName() {
791 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
794 public String getServicePathComponent() {
795 return SERVICE_PATH_COMPONENT;
799 protected PoxPayloadOut createInstance(String identifier) {
800 return createLoaninInstance(identifier);
804 * Creates the loanin instance.
806 * @param identifier the identifier
807 * @return the multipart output
809 private PoxPayloadOut createLoaninInstance(String identifier) {
810 return createLoaninInstance(
811 "loaninNumber-" + identifier,
812 "returnDate-" + identifier);
816 * Creates the loanin instance.
818 * @param loaninNumber the loanin number
819 * @param returnDate the return date
820 * @return the multipart output
822 private PoxPayloadOut createLoaninInstance(String loaninNumber,
825 LoansinCommon loaninCommon = new LoansinCommon();
826 loaninCommon.setLoanInNumber(loaninNumber);
827 loaninCommon.setLoanReturnDate(returnDate);
828 LenderGroupList lenderGroupList = new LenderGroupList();
829 LenderGroup lenderGroup = new LenderGroup();
830 lenderGroup.setLender(LENDER_REF_NAME);
831 lenderGroupList.getLenderGroup().add(lenderGroup);
832 loaninCommon.setLenderGroupList(lenderGroupList);
833 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
834 loaninCommon.setLoanInNote(getUTF8DataFragment());
836 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
837 PayloadOutputPart commonPart =
838 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
839 commonPart.setLabel(new LoaninClient().getCommonPartName());
841 if(logger.isDebugEnabled()){
842 logger.debug("to be created, loanin common");
843 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));