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;
40 //import org.collectionspace.services.loanin.LoansinCommonList;
42 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
44 //import org.testng.annotations.AfterClass;
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);
63 // Instance variables specific to this test.
64 /** The service path component. */
65 final String SERVICE_NAME = "loansin";
66 final String SERVICE_PATH_COMPONENT = "loansin";
68 /** The known resource id. */
69 private String knownResourceId = null;
71 private String LENDER_REF_NAME =
72 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
75 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
78 protected CollectionSpaceClient getClientInstance() {
79 return new LoaninClient();
83 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
86 protected AbstractCommonList getAbstractCommonList(
87 ClientResponse<AbstractCommonList> response) {
88 return response.getEntity(AbstractCommonList.class);
91 // ---------------------------------------------------------------
92 // CRUD tests : CREATE tests
93 // ---------------------------------------------------------------
96 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
99 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
100 public void create(String testName) throws Exception {
102 if (logger.isDebugEnabled()) {
103 logger.debug(testBanner(testName, CLASS_NAME));
105 // Perform setup, such as initializing the type of service request
106 // (e.g. CREATE, DELETE), its valid and expected status codes, and
107 // its associated HTTP method name (e.g. POST, DELETE).
110 // Submit the request to the service and store the response.
111 LoaninClient client = new LoaninClient();
112 String identifier = createIdentifier();
113 PoxPayloadOut multipart = createLoaninInstance(identifier);
115 ClientResponse<Response> res = client.create(multipart);
117 int statusCode = res.getStatus();
119 // Check the status code of the response: does it match
120 // the expected response(s)?
123 // Does it fall within the set of valid status codes?
124 // Does it exactly match the expected status code?
125 if(logger.isDebugEnabled()){
126 logger.debug(testName + ": status = " + statusCode);
128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
130 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
132 newID = extractId(res);
134 res.releaseConnection();
137 // Store the ID returned from the first resource created
138 // for additional tests below.
139 if (knownResourceId == null){
140 knownResourceId = newID;
141 if (logger.isDebugEnabled()) {
142 logger.debug(testName + ": knownResourceId=" + knownResourceId);
146 // Store the IDs from every resource created by tests,
147 // so they can be deleted after tests have been run.
148 allResourceIdsCreated.add(newID);
152 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
155 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
156 dependsOnMethods = {"create"})
157 public void createList(String testName) throws Exception {
158 for(int i = 0; i < 3; i++){
164 // Placeholders until the three tests below can be uncommented.
165 // See Issue CSPACE-401.
167 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
170 public void createWithEmptyEntityBody(String testName) throws Exception {
171 //Should this really be empty?
175 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
178 public void createWithMalformedXml(String testName) throws Exception {
179 //Should this really be empty?
183 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
186 public void createWithWrongXmlSchema(String testName) throws Exception {
187 //Should this really be empty?
192 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
193 dependsOnMethods = {"create", "testSubmitRequest"})
194 public void createWithEmptyEntityBody(String testName) throws Exception {
196 if (logger.isDebugEnabled()) {
197 logger.debug(testBanner(testName, CLASS_NAME));
200 setupCreateWithEmptyEntityBody();
202 // Submit the request to the service and store the response.
203 String method = REQUEST_TYPE.httpMethodName();
204 String url = getServiceRootURL();
205 String mediaType = MediaType.APPLICATION_XML;
206 final String entity = "";
207 int statusCode = submitRequest(method, url, mediaType, entity);
209 // Check the status code of the response: does it match
210 // the expected response(s)?
211 if(logger.isDebugEnabled()){
212 logger.debug("createWithEmptyEntityBody url=" + url +
213 " status=" + statusCode);
215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
221 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
222 dependsOnMethods = {"create", "testSubmitRequest"})
223 public void createWithMalformedXml(String testName) throws Exception {
225 if (logger.isDebugEnabled()) {
226 logger.debug(testBanner(testName, CLASS_NAME));
229 setupCreateWithMalformedXml(testName, logger);
231 // Submit the request to the service and store the response.
232 String method = REQUEST_TYPE.httpMethodName();
233 String url = getServiceRootURL();
234 String mediaType = MediaType.APPLICATION_XML;
235 final String entity = MALFORMED_XML_DATA; // Constant from base class.
236 int statusCode = submitRequest(method, url, mediaType, entity);
238 // Check the status code of the response: does it match
239 // the expected response(s)?
240 if(logger.isDebugEnabled()){
241 logger.debug(testName + ": url=" + url +
242 " status=" + statusCode);
244 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
245 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
246 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
250 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
251 dependsOnMethods = {"create", "testSubmitRequest"})
252 public void createWithWrongXmlSchema(String testName) throws Exception {
254 if (logger.isDebugEnabled()) {
255 logger.debug(testBanner(testName, CLASS_NAME));
258 setupCreateWithWrongXmlSchema(testName, logger);
260 // Submit the request to the service and store the response.
261 String method = REQUEST_TYPE.httpMethodName();
262 String url = getServiceRootURL();
263 String mediaType = MediaType.APPLICATION_XML;
264 final String entity = WRONG_XML_SCHEMA_DATA;
265 int statusCode = submitRequest(method, url, mediaType, entity);
267 // Check the status code of the response: does it match
268 // the expected response(s)?
269 if(logger.isDebugEnabled()){
270 logger.debug(testName + ": url=" + url +
271 " status=" + statusCode);
273 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
274 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
275 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
279 // ---------------------------------------------------------------
280 // CRUD tests : READ tests
281 // ---------------------------------------------------------------
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 // ---------------------------------------------------------------
384 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
387 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
388 dependsOnMethods = {"createList", "read"})
389 public void readList(String testName) throws Exception {
391 if (logger.isDebugEnabled()) {
392 logger.debug(testBanner(testName, CLASS_NAME));
397 // Submit the request to the service and store the response.
398 AbstractCommonList list = null;
399 LoaninClient client = new LoaninClient();
400 ClientResponse<AbstractCommonList> res = client.readList();
402 int statusCode = res.getStatus();
404 // Check the status code of the response: does it match
405 // the expected response(s)?
406 if(logger.isDebugEnabled()){
407 logger.debug(testName + ": status = " + statusCode);
409 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
410 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
411 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413 list = res.getEntity();
415 res.releaseConnection();
418 // Optionally output additional data about list members for debugging.
419 boolean iterateThroughList = false;
420 if (iterateThroughList && logger.isDebugEnabled()){
421 List<AbstractCommonList.ListItem> items =
424 for(AbstractCommonList.ListItem item : items){
425 logger.debug(testName + ": list-item[" + i + "] " +
434 // ---------------------------------------------------------------
435 // CRUD tests : UPDATE tests
436 // ---------------------------------------------------------------
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.
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 // ---------------------------------------------------------------
689 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
692 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
693 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
694 public void delete(String testName) throws Exception {
696 if (logger.isDebugEnabled()) {
697 logger.debug(testBanner(testName, CLASS_NAME));
702 // Submit the request to the service and store the response.
703 LoaninClient client = new LoaninClient();
704 ClientResponse<Response> res = client.delete(knownResourceId);
706 int statusCode = res.getStatus();
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if(logger.isDebugEnabled()){
711 logger.debug(testName + ": status = " + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
717 res.releaseConnection();
723 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
726 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
727 dependsOnMethods = {"delete"})
728 public void deleteNonExistent(String testName) throws Exception {
730 if (logger.isDebugEnabled()) {
731 logger.debug(testBanner(testName, CLASS_NAME));
734 setupDeleteNonExistent();
736 // Submit the request to the service and store the response.
737 LoaninClient client = new LoaninClient();
738 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
740 int statusCode = res.getStatus();
742 // Check the status code of the response: does it match
743 // the expected response(s)?
744 if(logger.isDebugEnabled()){
745 logger.debug(testName + ": status = " + statusCode);
747 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
748 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
749 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
751 res.releaseConnection();
755 // ---------------------------------------------------------------
756 // Utility tests : tests of code used in tests above
757 // ---------------------------------------------------------------
759 * Tests the code for manually submitting data that is used by several
760 * of the methods above.
762 @Test(dependsOnMethods = {"create", "read"})
763 public void testSubmitRequest() {
765 // Expected status code: 200 OK
766 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
768 // Submit the request to the service and store the response.
769 String method = ServiceRequestType.READ.httpMethodName();
770 String url = getResourceURL(knownResourceId);
771 int statusCode = submitRequest(method, url);
773 // Check the status code of the response: does it match
774 // the expected response(s)?
775 if(logger.isDebugEnabled()){
776 logger.debug("testSubmitRequest: url=" + url +
777 " status=" + statusCode);
779 Assert.assertEquals(statusCode, EXPECTED_STATUS);
783 // ---------------------------------------------------------------
784 // Utility methods used by tests above
785 // ---------------------------------------------------------------
788 public String getServiceName() {
793 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
796 public String getServicePathComponent() {
797 return SERVICE_PATH_COMPONENT;
801 * Creates the loanin instance.
803 * @param identifier the identifier
804 * @return the multipart output
806 private PoxPayloadOut createLoaninInstance(String identifier) {
807 return createLoaninInstance(
808 "loaninNumber-" + identifier,
809 "returnDate-" + identifier);
813 * Creates the loanin instance.
815 * @param loaninNumber the loanin number
816 * @param returnDate the return date
817 * @return the multipart output
819 private PoxPayloadOut createLoaninInstance(String loaninNumber,
822 LoansinCommon loaninCommon = new LoansinCommon();
823 loaninCommon.setLoanInNumber(loaninNumber);
824 loaninCommon.setLoanReturnDate(returnDate);
825 LenderGroupList lenderGroupList = new LenderGroupList();
826 LenderGroup lenderGroup = new LenderGroup();
827 lenderGroup.setLender(LENDER_REF_NAME);
828 lenderGroupList.getLenderGroup().add(lenderGroup);
829 loaninCommon.setLenderGroupList(lenderGroupList);
830 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
831 loaninCommon.setLoanInNote(getUTF8DataFragment());
833 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
834 PayloadOutputPart commonPart =
835 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
836 commonPart.setLabel(new LoaninClient().getCommonPartName());
838 if(logger.isDebugEnabled()){
839 logger.debug("to be created, loanin common");
840 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));