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.jaxb.AbstractCommonList;
38 import org.collectionspace.services.loanin.LenderGroup;
39 import org.collectionspace.services.loanin.LenderGroupList;
40 import org.collectionspace.services.loanin.LoansinCommon;
42 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
44 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * LoaninServiceTest, carries out tests against a
51 * deployed and running Loanin (aka Loans In) Service.
53 * $LastChangedRevision$
56 public class LoaninServiceTest extends AbstractServiceTestImpl {
59 private final String CLASS_NAME = LoaninServiceTest.class.getName();
60 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";
65 /** The known resource id. */
66 private String knownResourceId = null;
67 private String LENDER_REF_NAME =
68 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
71 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
74 protected CollectionSpaceClient getClientInstance() {
75 return new LoaninClient();
79 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
82 protected AbstractCommonList getAbstractCommonList(
83 ClientResponse<AbstractCommonList> response) {
84 return response.getEntity(AbstractCommonList.class);
87 // ---------------------------------------------------------------
88 // CRUD tests : CREATE tests
89 // ---------------------------------------------------------------
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.
166 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
169 public void createWithEmptyEntityBody(String testName) throws Exception {
170 //Should this really be empty?
174 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
177 public void createWithMalformedXml(String testName) throws Exception {
178 //Should this really be empty?
182 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
185 public void createWithWrongXmlSchema(String testName) throws Exception {
186 //Should this really be empty?
191 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
192 dependsOnMethods = {"create", "testSubmitRequest"})
193 public void createWithEmptyEntityBody(String testName) throws Exception {
195 if (logger.isDebugEnabled()) {
196 logger.debug(testBanner(testName, CLASS_NAME));
199 setupCreateWithEmptyEntityBody();
201 // Submit the request to the service and store the response.
202 String method = REQUEST_TYPE.httpMethodName();
203 String url = getServiceRootURL();
204 String mediaType = MediaType.APPLICATION_XML;
205 final String entity = "";
206 int statusCode = submitRequest(method, url, mediaType, entity);
208 // Check the status code of the response: does it match
209 // the expected response(s)?
210 if(logger.isDebugEnabled()){
211 logger.debug("createWithEmptyEntityBody url=" + url +
212 " status=" + statusCode);
214 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
215 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
216 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
220 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
221 dependsOnMethods = {"create", "testSubmitRequest"})
222 public void createWithMalformedXml(String testName) throws Exception {
224 if (logger.isDebugEnabled()) {
225 logger.debug(testBanner(testName, CLASS_NAME));
228 setupCreateWithMalformedXml(testName, logger);
230 // Submit the request to the service and store the response.
231 String method = REQUEST_TYPE.httpMethodName();
232 String url = getServiceRootURL();
233 String mediaType = MediaType.APPLICATION_XML;
234 final String entity = MALFORMED_XML_DATA; // Constant from base class.
235 int statusCode = submitRequest(method, url, mediaType, entity);
237 // Check the status code of the response: does it match
238 // the expected response(s)?
239 if(logger.isDebugEnabled()){
240 logger.debug(testName + ": url=" + url +
241 " status=" + statusCode);
243 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
244 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
245 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
249 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
250 dependsOnMethods = {"create", "testSubmitRequest"})
251 public void createWithWrongXmlSchema(String testName) throws Exception {
253 if (logger.isDebugEnabled()) {
254 logger.debug(testBanner(testName, CLASS_NAME));
257 setupCreateWithWrongXmlSchema(testName, logger);
259 // Submit the request to the service and store the response.
260 String method = REQUEST_TYPE.httpMethodName();
261 String url = getServiceRootURL();
262 String mediaType = MediaType.APPLICATION_XML;
263 final String entity = WRONG_XML_SCHEMA_DATA;
264 int statusCode = submitRequest(method, url, mediaType, entity);
266 // Check the status code of the response: does it match
267 // the expected response(s)?
268 if(logger.isDebugEnabled()){
269 logger.debug(testName + ": url=" + url +
270 " status=" + statusCode);
272 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
278 // ---------------------------------------------------------------
279 // CRUD tests : READ tests
280 // ---------------------------------------------------------------
285 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
288 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
289 dependsOnMethods = {"create"})
290 public void read(String testName) throws Exception {
292 if (logger.isDebugEnabled()) {
293 logger.debug(testBanner(testName, CLASS_NAME));
298 // Submit the request to the service and store the response.
299 LoaninClient client = new LoaninClient();
300 ClientResponse<String> res = client.read(knownResourceId);
301 PoxPayloadIn input = null;
303 int statusCode = res.getStatus();
305 // Check the status code of the response: does it match
306 // the expected response(s)?
307 if (logger.isDebugEnabled()) {
308 logger.debug(testName + ": status = " + statusCode);
310 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
311 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
312 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
313 input = new PoxPayloadIn(res.getEntity());
315 res.releaseConnection();
318 // Get the common part of the response and verify that it is not null.
319 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
320 LoansinCommon loaninCommon = null;
321 if (payloadInputPart != null) {
322 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
324 Assert.assertNotNull(loaninCommon);
326 // Check selected fields.
327 LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
328 Assert.assertNotNull(lenderGroupList);
329 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
330 Assert.assertNotNull(lenderGroups);
331 Assert.assertTrue(lenderGroups.size() > 0);
332 String lender = lenderGroups.get(0).getLender();
333 Assert.assertEquals(lender, LENDER_REF_NAME);
335 if (logger.isDebugEnabled()) {
336 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
337 + "UTF-8 data received=" + loaninCommon.getLoanInNote());
340 Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
341 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
342 + "' does not match expected data '" + getUTF8DataFragment());
348 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
351 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 dependsOnMethods = {"read"})
353 public void readNonExistent(String testName) throws Exception {
355 if (logger.isDebugEnabled()) {
356 logger.debug(testBanner(testName, CLASS_NAME));
359 setupReadNonExistent();
361 // Submit the request to the service and store the response.
362 LoaninClient client = new LoaninClient();
363 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
365 int statusCode = res.getStatus();
367 // Check the status code of the response: does it match
368 // the expected response(s)?
369 if (logger.isDebugEnabled()) {
370 logger.debug(testName + ": status = " + statusCode);
372 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376 res.releaseConnection();
380 // ---------------------------------------------------------------
381 // CRUD tests : READ_LIST tests
382 // ---------------------------------------------------------------
387 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
390 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
391 dependsOnMethods = {"createList", "read"})
392 public void readList(String testName) throws Exception {
394 if (logger.isDebugEnabled()) {
395 logger.debug(testBanner(testName, CLASS_NAME));
400 // Submit the request to the service and store the response.
401 AbstractCommonList list = null;
402 LoaninClient client = new LoaninClient();
403 ClientResponse<AbstractCommonList> res = client.readList();
405 int statusCode = res.getStatus();
407 // Check the status code of the response: does it match
408 // the expected response(s)?
409 if (logger.isDebugEnabled()) {
410 logger.debug(testName + ": status = " + statusCode);
412 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416 list = res.getEntity();
418 res.releaseConnection();
421 // Optionally output additional data about list members for debugging.
422 boolean iterateThroughList = true;
423 if(iterateThroughList && logger.isDebugEnabled()){
424 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
432 // ---------------------------------------------------------------
433 // CRUD tests : UPDATE tests
434 // ---------------------------------------------------------------
439 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
442 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
443 dependsOnMethods = {"read"})
444 public void update(String testName) throws Exception {
446 if (logger.isDebugEnabled()) {
447 logger.debug(testBanner(testName, CLASS_NAME));
452 // Retrieve the contents of a resource to update.
453 LoaninClient client = new LoaninClient();
454 ClientResponse<String> res = client.read(knownResourceId);
455 PoxPayloadIn input = null;
457 if (logger.isDebugEnabled()) {
458 logger.debug(testName + ": read status = " + res.getStatus());
460 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
462 if (logger.isDebugEnabled()) {
463 logger.debug("got object to update with ID: " + knownResourceId);
465 input = new PoxPayloadIn(res.getEntity());
467 res.releaseConnection();
470 // Extract the common part from the response.
471 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
472 LoansinCommon loaninCommon = null;
473 if (payloadInputPart != null) {
474 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
476 Assert.assertNotNull(loaninCommon);
478 // Update the content of this resource.
479 loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
480 loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate());
481 loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
482 if (logger.isDebugEnabled()) {
483 logger.debug("to be updated object");
484 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
487 // Submit the updated common part in an update request to the service
488 // and store the response.
489 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
490 PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
491 commonPart.setLabel(client.getCommonPartName());
492 res = client.update(knownResourceId, output);
494 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match the expected response(s)?
496 if (logger.isDebugEnabled()) {
497 logger.debug(testName + ": status = " + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
502 input = new PoxPayloadIn(res.getEntity());
504 res.releaseConnection();
507 // Extract the updated common part from the response.
508 payloadInputPart = input.getPart(client.getCommonPartName());
509 LoansinCommon updatedLoaninCommon = null;
510 if (payloadInputPart != null) {
511 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
513 Assert.assertNotNull(updatedLoaninCommon);
515 // Check selected fields in the updated common part.
516 Assert.assertEquals(updatedLoaninCommon.getLoanReturnDate(),
517 loaninCommon.getLoanReturnDate(),
518 "Data in updated object did not match submitted data.");
520 if (logger.isDebugEnabled()) {
521 logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
522 + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
524 Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
525 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
526 + "' does not contain expected data '" + getUTF8DataFragment());
527 Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
528 loaninCommon.getLoanInNote(),
529 "Data in updated object did not match submitted data.");
533 // Placeholders until the three tests below can be uncommented.
534 // See Issue CSPACE-401.
537 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
540 public void updateWithEmptyEntityBody(String testName) throws Exception {
541 //Should this really be empty?
545 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
548 public void updateWithMalformedXml(String testName) throws Exception {
549 //Should this really be empty?
553 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
556 public void updateWithWrongXmlSchema(String testName) throws Exception {
557 //Should this really be empty?
562 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
563 dependsOnMethods = {"create", "update", "testSubmitRequest"})
564 public void updateWithEmptyEntityBody(String testName) throws Exception {
566 if (logger.isDebugEnabled()) {
567 logger.debug(testBanner(testName, CLASS_NAME));
570 setupUpdateWithEmptyEntityBody();
572 // Submit the request to the service and store the response.
573 String method = REQUEST_TYPE.httpMethodName();
574 String url = getResourceURL(knownResourceId);
575 String mediaType = MediaType.APPLICATION_XML;
576 final String entity = "";
577 int statusCode = submitRequest(method, url, mediaType, entity);
579 // Check the status code of the response: does it match
580 // the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug(testName + ": url=" + url +
583 " status=" + statusCode);
585 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
592 dependsOnMethods = {"create", "update", "testSubmitRequest"})
593 public void updateWithMalformedXml(String testName) throws Exception {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
599 setupUpdateWithMalformedXml();
601 // Submit the request to the service and store the response.
602 String method = REQUEST_TYPE.httpMethodName();
603 String url = getResourceURL(knownResourceId);
604 String mediaType = MediaType.APPLICATION_XML;
605 final String entity = MALFORMED_XML_DATA;
606 int statusCode = submitRequest(method, url, mediaType, entity);
608 // Check the status code of the response: does it match
609 // the expected response(s)?
610 if(logger.isDebugEnabled()){
611 logger.debug(testName + ": url=" + url +
612 " status=" + statusCode);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
620 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
621 dependsOnMethods = {"create", "update", "testSubmitRequest"})
622 public void updateWithWrongXmlSchema(String testName) throws Exception {
624 if (logger.isDebugEnabled()) {
625 logger.debug(testBanner(testName, CLASS_NAME));
628 setupUpdateWithWrongXmlSchema();
630 // Submit the request to the service and store the response.
631 String method = REQUEST_TYPE.httpMethodName();
632 String url = getResourceURL(knownResourceId);
633 String mediaType = MediaType.APPLICATION_XML;
634 final String entity = WRONG_XML_SCHEMA_DATA;
635 int statusCode = submitRequest(method, url, mediaType, entity);
637 // Check the status code of the response: does it match
638 // the expected response(s)?
639 if(logger.isDebugEnabled()){
640 logger.debug(testName + ": url=" + url +
641 " status=" + statusCode);
643 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
644 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
645 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
653 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
654 dependsOnMethods = {"update", "testSubmitRequest"})
655 public void updateNonExistent(String testName) throws Exception {
657 if (logger.isDebugEnabled()) {
658 logger.debug(testBanner(testName, CLASS_NAME));
661 setupUpdateNonExistent();
663 // Submit the request to the service and store the response.
664 // Note: The ID used in this 'create' call may be arbitrary.
665 // The only relevant ID may be the one used in update(), below.
666 LoaninClient client = new LoaninClient();
667 PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
668 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
670 int statusCode = res.getStatus();
672 // Check the status code of the response: does it match
673 // the expected response(s)?
674 if (logger.isDebugEnabled()) {
675 logger.debug(testName + ": status = " + statusCode);
677 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
678 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
679 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
681 res.releaseConnection();
685 // ---------------------------------------------------------------
686 // CRUD tests : DELETE tests
687 // ---------------------------------------------------------------
692 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
695 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
696 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
697 public void delete(String testName) throws Exception {
699 if (logger.isDebugEnabled()) {
700 logger.debug(testBanner(testName, CLASS_NAME));
705 // Submit the request to the service and store the response.
706 LoaninClient client = new LoaninClient();
707 ClientResponse<Response> res = client.delete(knownResourceId);
709 int statusCode = res.getStatus();
711 // Check the status code of the response: does it match
712 // the expected response(s)?
713 if (logger.isDebugEnabled()) {
714 logger.debug(testName + ": status = " + statusCode);
716 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
717 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
718 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 res.releaseConnection();
727 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
730 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
731 dependsOnMethods = {"delete"})
732 public void deleteNonExistent(String testName) throws Exception {
734 if (logger.isDebugEnabled()) {
735 logger.debug(testBanner(testName, CLASS_NAME));
738 setupDeleteNonExistent();
740 // Submit the request to the service and store the response.
741 LoaninClient client = new LoaninClient();
742 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
744 int statusCode = res.getStatus();
746 // Check the status code of the response: does it match
747 // the expected response(s)?
748 if (logger.isDebugEnabled()) {
749 logger.debug(testName + ": status = " + statusCode);
751 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
752 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
753 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
755 res.releaseConnection();
759 // ---------------------------------------------------------------
760 // Utility tests : tests of code used in tests above
761 // ---------------------------------------------------------------
764 * Tests the code for manually submitting data that is used by several
765 * of the methods above.
767 @Test(dependsOnMethods = {"create", "read"})
768 public void testSubmitRequest() {
770 // Expected status code: 200 OK
771 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
773 // Submit the request to the service and store the response.
774 String method = ServiceRequestType.READ.httpMethodName();
775 String url = getResourceURL(knownResourceId);
776 int statusCode = submitRequest(method, url);
778 // Check the status code of the response: does it match
779 // the expected response(s)?
780 if (logger.isDebugEnabled()) {
781 logger.debug("testSubmitRequest: url=" + url
782 + " status=" + statusCode);
784 Assert.assertEquals(statusCode, EXPECTED_STATUS);
788 // ---------------------------------------------------------------
789 // Utility methods used by tests above
790 // ---------------------------------------------------------------
793 public String getServiceName() {
798 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
801 public String getServicePathComponent() {
802 return SERVICE_PATH_COMPONENT;
806 protected PoxPayloadOut createInstance(String identifier) {
807 return createLoaninInstance(identifier);
811 * Creates the loanin instance.
813 * @param identifier the identifier
814 * @return the multipart output
816 private PoxPayloadOut createLoaninInstance(String identifier) {
817 return createLoaninInstance(
818 "loaninNumber-" + identifier,
819 "returnDate-" + identifier);
823 * Creates the loanin instance.
825 * @param loaninNumber the loanin number
826 * @param returnDate the return date
827 * @return the multipart output
829 private PoxPayloadOut createLoaninInstance(String loaninNumber,
832 LoansinCommon loaninCommon = new LoansinCommon();
833 loaninCommon.setLoanInNumber(loaninNumber);
834 loaninCommon.setLoanReturnDate(returnDate);
835 LenderGroupList lenderGroupList = new LenderGroupList();
836 LenderGroup lenderGroup = new LenderGroup();
837 lenderGroup.setLender(LENDER_REF_NAME);
838 lenderGroupList.getLenderGroup().add(lenderGroup);
839 loaninCommon.setLenderGroupList(lenderGroupList);
840 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
841 loaninCommon.setLoanInNote(getUTF8DataFragment());
843 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
844 PayloadOutputPart commonPart =
845 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
846 commonPart.setLabel(new LoaninClient().getCommonPartName());
848 if (logger.isDebugEnabled()) {
849 logger.debug("to be created, loanin common");
850 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));