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);
60 // Instance variables specific to this test.
61 /** The service path component. */
62 final String SERVICE_NAME = "loansin";
63 final String SERVICE_PATH_COMPONENT = "loansin";
64 /** The known resource id. */
65 private String knownResourceId = null;
66 private String LENDER_REF_NAME =
67 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
70 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
73 protected CollectionSpaceClient getClientInstance() {
74 return new LoaninClient();
78 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
81 protected AbstractCommonList getAbstractCommonList(
82 ClientResponse<AbstractCommonList> response) {
83 return response.getEntity(AbstractCommonList.class);
86 // ---------------------------------------------------------------
87 // CRUD tests : CREATE tests
88 // ---------------------------------------------------------------
93 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
96 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
97 public void create(String testName) throws Exception {
99 if (logger.isDebugEnabled()) {
100 logger.debug(testBanner(testName, CLASS_NAME));
102 // Perform setup, such as initializing the type of service request
103 // (e.g. CREATE, DELETE), its valid and expected status codes, and
104 // its associated HTTP method name (e.g. POST, DELETE).
107 // Submit the request to the service and store the response.
108 LoaninClient client = new LoaninClient();
109 String identifier = createIdentifier();
110 PoxPayloadOut multipart = createLoaninInstance(identifier);
112 ClientResponse<Response> res = client.create(multipart);
114 int statusCode = res.getStatus();
116 // Check the status code of the response: does it match
117 // the expected response(s)?
120 // Does it fall within the set of valid status codes?
121 // Does it exactly match the expected status code?
122 if (logger.isDebugEnabled()) {
123 logger.debug(testName + ": status = " + statusCode);
125 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
126 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
127 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
129 newID = extractId(res);
131 res.releaseConnection();
134 // Store the ID returned from the first resource created
135 // for additional tests below.
136 if (knownResourceId == null) {
137 knownResourceId = newID;
138 if (logger.isDebugEnabled()) {
139 logger.debug(testName + ": knownResourceId=" + knownResourceId);
143 // Store the IDs from every resource created by tests,
144 // so they can be deleted after tests have been run.
145 allResourceIdsCreated.add(newID);
149 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
152 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
153 dependsOnMethods = {"create"})
154 public void createList(String testName) throws Exception {
155 for (int i = 0; i < 3; i++) {
161 // Placeholders until the three tests below can be uncommented.
162 // 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 // ---------------------------------------------------------------
284 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
287 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
288 dependsOnMethods = {"create"})
289 public void read(String testName) throws Exception {
291 if (logger.isDebugEnabled()) {
292 logger.debug(testBanner(testName, CLASS_NAME));
297 // Submit the request to the service and store the response.
298 LoaninClient client = new LoaninClient();
299 ClientResponse<String> res = client.read(knownResourceId);
300 PoxPayloadIn input = null;
302 int statusCode = res.getStatus();
304 // Check the status code of the response: does it match
305 // the expected response(s)?
306 if (logger.isDebugEnabled()) {
307 logger.debug(testName + ": status = " + statusCode);
309 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
310 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
311 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
312 input = new PoxPayloadIn(res.getEntity());
314 res.releaseConnection();
317 // Get the common part of the response and verify that it is not null.
318 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
319 LoansinCommon loaninCommon = null;
320 if (payloadInputPart != null) {
321 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
323 Assert.assertNotNull(loaninCommon);
325 // Check selected fields.
326 LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
327 Assert.assertNotNull(lenderGroupList);
328 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
329 Assert.assertNotNull(lenderGroups);
330 Assert.assertTrue(lenderGroups.size() > 0);
331 String lender = lenderGroups.get(0).getLender();
332 Assert.assertEquals(lender, LENDER_REF_NAME);
334 if (logger.isDebugEnabled()) {
335 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
336 + "UTF-8 data received=" + loaninCommon.getLoanInNote());
339 Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
340 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
341 + "' does not match expected data '" + getUTF8DataFragment());
347 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
350 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351 dependsOnMethods = {"read"})
352 public void readNonExistent(String testName) throws Exception {
354 if (logger.isDebugEnabled()) {
355 logger.debug(testBanner(testName, CLASS_NAME));
358 setupReadNonExistent();
360 // Submit the request to the service and store the response.
361 LoaninClient client = new LoaninClient();
362 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
364 int statusCode = res.getStatus();
366 // Check the status code of the response: does it match
367 // the expected response(s)?
368 if (logger.isDebugEnabled()) {
369 logger.debug(testName + ": status = " + statusCode);
371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
375 res.releaseConnection();
379 // ---------------------------------------------------------------
380 // CRUD tests : READ_LIST tests
381 // ---------------------------------------------------------------
386 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
389 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
390 dependsOnMethods = {"createList", "read"})
391 public void readList(String testName) throws Exception {
393 if (logger.isDebugEnabled()) {
394 logger.debug(testBanner(testName, CLASS_NAME));
399 // Submit the request to the service and store the response.
400 AbstractCommonList list = null;
401 LoaninClient client = new LoaninClient();
402 ClientResponse<AbstractCommonList> res = client.readList();
404 int statusCode = res.getStatus();
406 // Check the status code of the response: does it match
407 // the expected response(s)?
408 if (logger.isDebugEnabled()) {
409 logger.debug(testName + ": status = " + statusCode);
411 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
412 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
413 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
415 list = res.getEntity();
417 res.releaseConnection();
420 // Optionally output additional data about list members for debugging.
421 boolean iterateThroughList = true;
422 if(iterateThroughList && logger.isDebugEnabled()){
423 ListItemsInAbstractCommonList(list, logger, testName);
431 // ---------------------------------------------------------------
432 // CRUD tests : UPDATE tests
433 // ---------------------------------------------------------------
438 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
441 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
442 dependsOnMethods = {"read"})
443 public void update(String testName) throws Exception {
445 if (logger.isDebugEnabled()) {
446 logger.debug(testBanner(testName, CLASS_NAME));
451 // Retrieve the contents of a resource to update.
452 LoaninClient client = new LoaninClient();
453 ClientResponse<String> res = client.read(knownResourceId);
454 PoxPayloadIn input = null;
456 if (logger.isDebugEnabled()) {
457 logger.debug(testName + ": read status = " + res.getStatus());
459 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
461 if (logger.isDebugEnabled()) {
462 logger.debug("got object to update with ID: " + knownResourceId);
464 input = new PoxPayloadIn(res.getEntity());
466 res.releaseConnection();
469 // Extract the common part from the response.
470 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
471 LoansinCommon loaninCommon = null;
472 if (payloadInputPart != null) {
473 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
475 Assert.assertNotNull(loaninCommon);
477 // Update the content of this resource.
478 loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
479 loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate());
480 loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
481 if (logger.isDebugEnabled()) {
482 logger.debug("to be updated object");
483 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
486 // Submit the updated common part in an update request to the service
487 // and store the response.
488 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
489 PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
490 commonPart.setLabel(client.getCommonPartName());
491 res = client.update(knownResourceId, output);
493 int statusCode = res.getStatus();
494 // Check the status code of the response: does it match the expected response(s)?
495 if (logger.isDebugEnabled()) {
496 logger.debug(testName + ": status = " + statusCode);
498 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
499 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
500 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
501 input = new PoxPayloadIn(res.getEntity());
503 res.releaseConnection();
506 // Extract the updated common part from the response.
507 payloadInputPart = input.getPart(client.getCommonPartName());
508 LoansinCommon updatedLoaninCommon = null;
509 if (payloadInputPart != null) {
510 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
512 Assert.assertNotNull(updatedLoaninCommon);
514 // Check selected fields in the updated common part.
515 Assert.assertEquals(updatedLoaninCommon.getLoanReturnDate(),
516 loaninCommon.getLoanReturnDate(),
517 "Data in updated object did not match submitted data.");
519 if (logger.isDebugEnabled()) {
520 logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
521 + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
523 Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
524 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
525 + "' does not contain expected data '" + getUTF8DataFragment());
526 Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
527 loaninCommon.getLoanInNote(),
528 "Data in updated object did not match submitted data.");
532 // Placeholders until the three tests below can be uncommented.
533 // See Issue CSPACE-401.
536 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
539 public void updateWithEmptyEntityBody(String testName) throws Exception {
540 //Should this really be empty?
544 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
547 public void updateWithMalformedXml(String testName) throws Exception {
548 //Should this really be empty?
552 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
555 public void updateWithWrongXmlSchema(String testName) throws Exception {
556 //Should this really be empty?
561 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
562 dependsOnMethods = {"create", "update", "testSubmitRequest"})
563 public void updateWithEmptyEntityBody(String testName) throws Exception {
565 if (logger.isDebugEnabled()) {
566 logger.debug(testBanner(testName, CLASS_NAME));
569 setupUpdateWithEmptyEntityBody();
571 // Submit the request to the service and store the response.
572 String method = REQUEST_TYPE.httpMethodName();
573 String url = getResourceURL(knownResourceId);
574 String mediaType = MediaType.APPLICATION_XML;
575 final String entity = "";
576 int statusCode = submitRequest(method, url, mediaType, entity);
578 // Check the status code of the response: does it match
579 // the expected response(s)?
580 if(logger.isDebugEnabled()){
581 logger.debug(testName + ": url=" + url +
582 " status=" + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
590 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
591 dependsOnMethods = {"create", "update", "testSubmitRequest"})
592 public void updateWithMalformedXml(String testName) throws Exception {
594 if (logger.isDebugEnabled()) {
595 logger.debug(testBanner(testName, CLASS_NAME));
598 setupUpdateWithMalformedXml();
600 // Submit the request to the service and store the response.
601 String method = REQUEST_TYPE.httpMethodName();
602 String url = getResourceURL(knownResourceId);
603 String mediaType = MediaType.APPLICATION_XML;
604 final String entity = MALFORMED_XML_DATA;
605 int statusCode = submitRequest(method, url, mediaType, entity);
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 if(logger.isDebugEnabled()){
610 logger.debug(testName + ": url=" + url +
611 " status=" + statusCode);
613 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
619 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
620 dependsOnMethods = {"create", "update", "testSubmitRequest"})
621 public void updateWithWrongXmlSchema(String testName) throws Exception {
623 if (logger.isDebugEnabled()) {
624 logger.debug(testBanner(testName, CLASS_NAME));
627 setupUpdateWithWrongXmlSchema();
629 // Submit the request to the service and store the response.
630 String method = REQUEST_TYPE.httpMethodName();
631 String url = getResourceURL(knownResourceId);
632 String mediaType = MediaType.APPLICATION_XML;
633 final String entity = WRONG_XML_SCHEMA_DATA;
634 int statusCode = submitRequest(method, url, mediaType, entity);
636 // Check the status code of the response: does it match
637 // the expected response(s)?
638 if(logger.isDebugEnabled()){
639 logger.debug(testName + ": url=" + url +
640 " status=" + statusCode);
642 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
649 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
652 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
653 dependsOnMethods = {"update", "testSubmitRequest"})
654 public void updateNonExistent(String testName) throws Exception {
656 if (logger.isDebugEnabled()) {
657 logger.debug(testBanner(testName, CLASS_NAME));
660 setupUpdateNonExistent();
662 // Submit the request to the service and store the response.
663 // Note: The ID used in this 'create' call may be arbitrary.
664 // The only relevant ID may be the one used in update(), below.
665 LoaninClient client = new LoaninClient();
666 PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
667 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
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(REQUEST_TYPE.isValidStatusCode(statusCode),
677 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
678 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
680 res.releaseConnection();
684 // ---------------------------------------------------------------
685 // CRUD tests : DELETE tests
686 // ---------------------------------------------------------------
691 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
694 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
695 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
696 public void delete(String testName) throws Exception {
698 if (logger.isDebugEnabled()) {
699 logger.debug(testBanner(testName, CLASS_NAME));
704 // Submit the request to the service and store the response.
705 LoaninClient client = new LoaninClient();
706 ClientResponse<Response> res = client.delete(knownResourceId);
708 int statusCode = res.getStatus();
710 // Check the status code of the response: does it match
711 // the expected response(s)?
712 if (logger.isDebugEnabled()) {
713 logger.debug(testName + ": status = " + statusCode);
715 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
716 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
717 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
719 res.releaseConnection();
726 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
729 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
730 dependsOnMethods = {"delete"})
731 public void deleteNonExistent(String testName) throws Exception {
733 if (logger.isDebugEnabled()) {
734 logger.debug(testBanner(testName, CLASS_NAME));
737 setupDeleteNonExistent();
739 // Submit the request to the service and store the response.
740 LoaninClient client = new LoaninClient();
741 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
743 int statusCode = res.getStatus();
745 // Check the status code of the response: does it match
746 // the expected response(s)?
747 if (logger.isDebugEnabled()) {
748 logger.debug(testName + ": status = " + statusCode);
750 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
751 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
752 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 res.releaseConnection();
758 // ---------------------------------------------------------------
759 // Utility tests : tests of code used in tests above
760 // ---------------------------------------------------------------
763 * Tests the code for manually submitting data that is used by several
764 * of the methods above.
766 @Test(dependsOnMethods = {"create", "read"})
767 public void testSubmitRequest() {
769 // Expected status code: 200 OK
770 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
772 // Submit the request to the service and store the response.
773 String method = ServiceRequestType.READ.httpMethodName();
774 String url = getResourceURL(knownResourceId);
775 int statusCode = submitRequest(method, url);
777 // Check the status code of the response: does it match
778 // the expected response(s)?
779 if (logger.isDebugEnabled()) {
780 logger.debug("testSubmitRequest: url=" + url
781 + " status=" + statusCode);
783 Assert.assertEquals(statusCode, EXPECTED_STATUS);
787 // ---------------------------------------------------------------
788 // Utility methods used by tests above
789 // ---------------------------------------------------------------
792 public String getServiceName() {
797 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
800 public String getServicePathComponent() {
801 return SERVICE_PATH_COMPONENT;
805 protected PoxPayloadOut createInstance(String identifier) {
806 return createLoaninInstance(identifier);
810 * Creates the loanin instance.
812 * @param identifier the identifier
813 * @return the multipart output
815 private PoxPayloadOut createLoaninInstance(String identifier) {
816 return createLoaninInstance(
817 "loaninNumber-" + identifier,
818 "returnDate-" + identifier);
822 * Creates the loanin instance.
824 * @param loaninNumber the loanin number
825 * @param returnDate the return date
826 * @return the multipart output
828 private PoxPayloadOut createLoaninInstance(String loaninNumber,
831 LoansinCommon loaninCommon = new LoansinCommon();
832 loaninCommon.setLoanInNumber(loaninNumber);
833 loaninCommon.setLoanReturnDate(returnDate);
834 LenderGroupList lenderGroupList = new LenderGroupList();
835 LenderGroup lenderGroup = new LenderGroup();
836 lenderGroup.setLender(LENDER_REF_NAME);
837 lenderGroupList.getLenderGroup().add(lenderGroup);
838 loaninCommon.setLenderGroupList(lenderGroupList);
839 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
840 loaninCommon.setLoanInNote(getUTF8DataFragment());
842 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
843 PayloadOutputPart commonPart =
844 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
845 commonPart.setLabel(new LoaninClient().getCommonPartName());
847 if (logger.isDebugEnabled()) {
848 logger.debug("to be created, loanin common");
849 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));