2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 //import java.util.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoaninClient;
32 import org.collectionspace.services.client.PayloadInputPart;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.common.AbstractCommonListUtils;
37 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.loanin.LenderGroup;
40 import org.collectionspace.services.loanin.LenderGroupList;
41 import org.collectionspace.services.loanin.LoansinCommon;
43 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * LoaninServiceTest, carries out tests against a
52 * deployed and running Loanin (aka Loans In) Service.
54 * $LastChangedRevision$
57 public class LoaninServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = LoaninServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 // Instance variables specific to this test.
63 /** The service path component. */
64 final String SERVICE_NAME = "loansin";
65 final String SERVICE_PATH_COMPONENT = "loansin";
66 /** The known resource id. */
67 private String knownResourceId = null;
68 private String LENDER_REF_NAME =
69 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(HarryLender)'Harry Lender'";
70 private final static String CURRENT_DATE_UTC =
71 GregorianCalendarDateTimeUtils.currentDateUTC();
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
77 protected CollectionSpaceClient getClientInstance() {
78 return new LoaninClient();
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
85 protected AbstractCommonList getAbstractCommonList(
86 ClientResponse<AbstractCommonList> response) {
87 return response.getEntity(AbstractCommonList.class);
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
97 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
101 public void create(String testName) throws Exception {
103 if (logger.isDebugEnabled()) {
104 logger.debug(testBanner(testName, CLASS_NAME));
106 // Perform setup, such as initializing the type of service request
107 // (e.g. CREATE, DELETE), its valid and expected status codes, and
108 // its associated HTTP method name (e.g. POST, DELETE).
111 // Submit the request to the service and store the response.
112 LoaninClient client = new LoaninClient();
113 String identifier = createIdentifier();
114 PoxPayloadOut multipart = createLoaninInstance(identifier);
116 ClientResponse<Response> res = client.create(multipart);
118 int statusCode = res.getStatus();
120 // Check the status code of the response: does it match
121 // the expected response(s)?
124 // Does it fall within the set of valid status codes?
125 // Does it exactly match the expected status code?
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": status = " + statusCode);
129 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
130 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
131 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
133 newID = extractId(res);
135 res.releaseConnection();
138 // Store the ID returned from the first resource created
139 // for additional tests below.
140 if (knownResourceId == null) {
141 knownResourceId = newID;
142 if (logger.isDebugEnabled()) {
143 logger.debug(testName + ": knownResourceId=" + knownResourceId);
147 // Store the IDs from every resource created by tests,
148 // so they can be deleted after tests have been run.
149 allResourceIdsCreated.add(newID);
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
156 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
157 dependsOnMethods = {"create"})
158 public void createList(String testName) throws Exception {
159 for (int i = 0; i < 3; i++) {
165 // Placeholders until the three tests below can be uncommented.
166 // See Issue CSPACE-401.
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
172 public void createWithEmptyEntityBody(String testName) throws Exception {
173 //Should this really be empty?
177 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
180 public void createWithMalformedXml(String testName) throws Exception {
181 //Should this really be empty?
185 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
188 public void createWithWrongXmlSchema(String testName) throws Exception {
189 //Should this really be empty?
194 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
195 dependsOnMethods = {"create", "testSubmitRequest"})
196 public void createWithEmptyEntityBody(String testName) throws Exception {
198 if (logger.isDebugEnabled()) {
199 logger.debug(testBanner(testName, CLASS_NAME));
202 setupCreateWithEmptyEntityBody();
204 // Submit the request to the service and store the response.
205 String method = REQUEST_TYPE.httpMethodName();
206 String url = getServiceRootURL();
207 String mediaType = MediaType.APPLICATION_XML;
208 final String entity = "";
209 int statusCode = submitRequest(method, url, mediaType, entity);
211 // Check the status code of the response: does it match
212 // the expected response(s)?
213 if(logger.isDebugEnabled()){
214 logger.debug("createWithEmptyEntityBody url=" + url +
215 " status=" + statusCode);
217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
219 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
223 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
224 dependsOnMethods = {"create", "testSubmitRequest"})
225 public void createWithMalformedXml(String testName) throws Exception {
227 if (logger.isDebugEnabled()) {
228 logger.debug(testBanner(testName, CLASS_NAME));
231 setupCreateWithMalformedXml(testName, logger);
233 // Submit the request to the service and store the response.
234 String method = REQUEST_TYPE.httpMethodName();
235 String url = getServiceRootURL();
236 String mediaType = MediaType.APPLICATION_XML;
237 final String entity = MALFORMED_XML_DATA; // Constant from base class.
238 int statusCode = submitRequest(method, url, mediaType, entity);
240 // Check the status code of the response: does it match
241 // the expected response(s)?
242 if(logger.isDebugEnabled()){
243 logger.debug(testName + ": url=" + url +
244 " status=" + statusCode);
246 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
247 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
248 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
253 dependsOnMethods = {"create", "testSubmitRequest"})
254 public void createWithWrongXmlSchema(String testName) throws Exception {
256 if (logger.isDebugEnabled()) {
257 logger.debug(testBanner(testName, CLASS_NAME));
260 setupCreateWithWrongXmlSchema(testName, logger);
262 // Submit the request to the service and store the response.
263 String method = REQUEST_TYPE.httpMethodName();
264 String url = getServiceRootURL();
265 String mediaType = MediaType.APPLICATION_XML;
266 final String entity = WRONG_XML_SCHEMA_DATA;
267 int statusCode = submitRequest(method, url, mediaType, entity);
269 // Check the status code of the response: does it match
270 // the expected response(s)?
271 if(logger.isDebugEnabled()){
272 logger.debug(testName + ": url=" + url +
273 " status=" + statusCode);
275 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
276 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
277 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
281 // ---------------------------------------------------------------
282 // CRUD tests : READ tests
283 // ---------------------------------------------------------------
288 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
291 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
292 dependsOnMethods = {"create"})
293 public void read(String testName) throws Exception {
295 if (logger.isDebugEnabled()) {
296 logger.debug(testBanner(testName, CLASS_NAME));
301 // Submit the request to the service and store the response.
302 LoaninClient client = new LoaninClient();
303 ClientResponse<String> res = client.read(knownResourceId);
304 assertStatusCode(res, testName);
305 PoxPayloadIn input = null;
307 input = new PoxPayloadIn(res.getEntity());
309 res.releaseConnection();
312 // Get the common part of the response and verify that it is not null.
313 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
314 LoansinCommon loaninCommon = null;
315 if (payloadInputPart != null) {
316 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
318 Assert.assertNotNull(loaninCommon);
320 // Check selected fields.
321 LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
322 Assert.assertNotNull(lenderGroupList);
323 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
324 Assert.assertNotNull(lenderGroups);
325 Assert.assertTrue(lenderGroups.size() > 0);
326 String lender = lenderGroups.get(0).getLender();
327 Assert.assertEquals(lender, LENDER_REF_NAME);
329 if (logger.isDebugEnabled()) {
330 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
331 + "UTF-8 data received=" + loaninCommon.getLoanInNote());
334 Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
335 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
336 + "' does not match expected data '" + getUTF8DataFragment());
342 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
345 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
346 dependsOnMethods = {"read"})
347 public void readNonExistent(String testName) throws Exception {
349 if (logger.isDebugEnabled()) {
350 logger.debug(testBanner(testName, CLASS_NAME));
353 setupReadNonExistent();
355 // Submit the request to the service and store the response.
356 LoaninClient client = new LoaninClient();
357 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
359 int statusCode = res.getStatus();
361 // Check the status code of the response: does it match
362 // the expected response(s)?
363 if (logger.isDebugEnabled()) {
364 logger.debug(testName + ": status = " + statusCode);
366 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
367 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
368 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
370 res.releaseConnection();
374 // ---------------------------------------------------------------
375 // CRUD tests : READ_LIST tests
376 // ---------------------------------------------------------------
381 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
384 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385 dependsOnMethods = {"createList", "read"})
386 public void readList(String testName) throws Exception {
388 if (logger.isDebugEnabled()) {
389 logger.debug(testBanner(testName, CLASS_NAME));
394 // Submit the request to the service and store the response.
395 AbstractCommonList list = null;
396 LoaninClient client = new LoaninClient();
397 ClientResponse<AbstractCommonList> res = client.readList();
398 assertStatusCode(res, testName);
400 list = res.getEntity();
402 res.releaseConnection();
405 // Optionally output additional data about list members for debugging.
406 boolean iterateThroughList = true;
407 if(iterateThroughList && logger.isDebugEnabled()){
408 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
416 // ---------------------------------------------------------------
417 // CRUD tests : UPDATE tests
418 // ---------------------------------------------------------------
423 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
426 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
427 dependsOnMethods = {"read"})
428 public void update(String testName) throws Exception {
430 if (logger.isDebugEnabled()) {
431 logger.debug(testBanner(testName, CLASS_NAME));
436 // Retrieve the contents of a resource to update.
437 LoaninClient client = new LoaninClient();
438 ClientResponse<String> res = client.read(knownResourceId);
439 assertStatusCode(res, testName);
440 PoxPayloadIn input = null;
442 if (logger.isDebugEnabled()) {
443 logger.debug("got object to update with ID: " + knownResourceId);
445 input = new PoxPayloadIn(res.getEntity());
447 res.releaseConnection();
450 // Extract the common part from the response.
451 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
452 LoansinCommon loaninCommon = null;
453 if (payloadInputPart != null) {
454 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
456 Assert.assertNotNull(loaninCommon);
458 // Update the content of this resource.
459 loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
460 loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
461 if (logger.isDebugEnabled()) {
462 logger.debug("to be updated object");
463 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
466 // Submit the updated common part in an update request to the service
467 // and store the response.
468 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
469 PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
470 commonPart.setLabel(client.getCommonPartName());
471 res = client.update(knownResourceId, output);
472 assertStatusCode(res, testName);
474 input = new PoxPayloadIn(res.getEntity());
476 res.releaseConnection();
479 // Extract the updated common part from the response.
480 payloadInputPart = input.getPart(client.getCommonPartName());
481 LoansinCommon updatedLoaninCommon = null;
482 if (payloadInputPart != null) {
483 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
485 Assert.assertNotNull(updatedLoaninCommon);
487 // Check selected fields in the updated common part.
488 Assert.assertEquals(updatedLoaninCommon.getLoanInNumber(),
489 loaninCommon.getLoanInNumber(),
490 "Data in updated object did not match submitted data.");
492 if (logger.isDebugEnabled()) {
493 logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
494 + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
496 Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
497 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
498 + "' does not contain expected data '" + getUTF8DataFragment());
499 Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
500 loaninCommon.getLoanInNote(),
501 "Data in updated object did not match submitted data.");
505 // Placeholders until the three tests below can be uncommented.
506 // See Issue CSPACE-401.
509 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
512 public void updateWithEmptyEntityBody(String testName) throws Exception {
513 //Should this really be empty?
517 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
520 public void updateWithMalformedXml(String testName) throws Exception {
521 //Should this really be empty?
525 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
528 public void updateWithWrongXmlSchema(String testName) throws Exception {
529 //Should this really be empty?
534 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
535 dependsOnMethods = {"create", "update", "testSubmitRequest"})
536 public void updateWithEmptyEntityBody(String testName) throws Exception {
538 if (logger.isDebugEnabled()) {
539 logger.debug(testBanner(testName, CLASS_NAME));
542 setupUpdateWithEmptyEntityBody();
544 // Submit the request to the service and store the response.
545 String method = REQUEST_TYPE.httpMethodName();
546 String url = getResourceURL(knownResourceId);
547 String mediaType = MediaType.APPLICATION_XML;
548 final String entity = "";
549 int statusCode = submitRequest(method, url, mediaType, entity);
551 // Check the status code of the response: does it match
552 // the expected response(s)?
553 if(logger.isDebugEnabled()){
554 logger.debug(testName + ": url=" + url +
555 " status=" + statusCode);
557 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
558 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
559 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
563 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
564 dependsOnMethods = {"create", "update", "testSubmitRequest"})
565 public void updateWithMalformedXml(String testName) throws Exception {
567 if (logger.isDebugEnabled()) {
568 logger.debug(testBanner(testName, CLASS_NAME));
571 setupUpdateWithMalformedXml();
573 // Submit the request to the service and store the response.
574 String method = REQUEST_TYPE.httpMethodName();
575 String url = getResourceURL(knownResourceId);
576 String mediaType = MediaType.APPLICATION_XML;
577 final String entity = MALFORMED_XML_DATA;
578 int statusCode = submitRequest(method, url, mediaType, entity);
580 // Check the status code of the response: does it match
581 // the expected response(s)?
582 if(logger.isDebugEnabled()){
583 logger.debug(testName + ": url=" + url +
584 " status=" + statusCode);
586 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
587 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
588 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
593 dependsOnMethods = {"create", "update", "testSubmitRequest"})
594 public void updateWithWrongXmlSchema(String testName) throws Exception {
596 if (logger.isDebugEnabled()) {
597 logger.debug(testBanner(testName, CLASS_NAME));
600 setupUpdateWithWrongXmlSchema();
602 // Submit the request to the service and store the response.
603 String method = REQUEST_TYPE.httpMethodName();
604 String url = getResourceURL(knownResourceId);
605 String mediaType = MediaType.APPLICATION_XML;
606 final String entity = WRONG_XML_SCHEMA_DATA;
607 int statusCode = submitRequest(method, url, mediaType, entity);
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if(logger.isDebugEnabled()){
612 logger.debug(testName + ": url=" + url +
613 " status=" + statusCode);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
622 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
625 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
626 dependsOnMethods = {"update", "testSubmitRequest"})
627 public void updateNonExistent(String testName) throws Exception {
629 if (logger.isDebugEnabled()) {
630 logger.debug(testBanner(testName, CLASS_NAME));
633 setupUpdateNonExistent();
635 // Submit the request to the service and store the response.
636 // Note: The ID used in this 'create' call may be arbitrary.
637 // The only relevant ID may be the one used in update(), below.
638 LoaninClient client = new LoaninClient();
639 PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
640 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
642 int statusCode = res.getStatus();
644 // Check the status code of the response: does it match
645 // the expected response(s)?
646 if (logger.isDebugEnabled()) {
647 logger.debug(testName + ": status = " + statusCode);
649 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
650 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
651 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
653 res.releaseConnection();
657 // ---------------------------------------------------------------
658 // CRUD tests : DELETE tests
659 // ---------------------------------------------------------------
664 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
667 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
668 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
669 public void delete(String testName) throws Exception {
671 if (logger.isDebugEnabled()) {
672 logger.debug(testBanner(testName, CLASS_NAME));
677 // Submit the request to the service and store the response.
678 LoaninClient client = new LoaninClient();
679 ClientResponse<Response> res = client.delete(knownResourceId);
681 int statusCode = res.getStatus();
683 // Check the status code of the response: does it match
684 // the expected response(s)?
685 if (logger.isDebugEnabled()) {
686 logger.debug(testName + ": status = " + statusCode);
688 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
689 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
690 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 res.releaseConnection();
699 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
702 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
703 dependsOnMethods = {"delete"})
704 public void deleteNonExistent(String testName) throws Exception {
706 if (logger.isDebugEnabled()) {
707 logger.debug(testBanner(testName, CLASS_NAME));
710 setupDeleteNonExistent();
712 // Submit the request to the service and store the response.
713 LoaninClient client = new LoaninClient();
714 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
716 int statusCode = res.getStatus();
718 // Check the status code of the response: does it match
719 // the expected response(s)?
720 if (logger.isDebugEnabled()) {
721 logger.debug(testName + ": status = " + statusCode);
723 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
724 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
725 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
727 res.releaseConnection();
731 // ---------------------------------------------------------------
732 // Utility tests : tests of code used in tests above
733 // ---------------------------------------------------------------
736 * Tests the code for manually submitting data that is used by several
737 * of the methods above.
739 @Test(dependsOnMethods = {"create", "read"})
740 public void testSubmitRequest() {
742 // Expected status code: 200 OK
743 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
745 // Submit the request to the service and store the response.
746 String method = ServiceRequestType.READ.httpMethodName();
747 String url = getResourceURL(knownResourceId);
748 int statusCode = submitRequest(method, url);
750 // Check the status code of the response: does it match
751 // the expected response(s)?
752 if (logger.isDebugEnabled()) {
753 logger.debug("testSubmitRequest: url=" + url
754 + " status=" + statusCode);
756 Assert.assertEquals(statusCode, EXPECTED_STATUS);
760 // ---------------------------------------------------------------
761 // Utility methods used by tests above
762 // ---------------------------------------------------------------
765 public String getServiceName() {
770 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
773 public String getServicePathComponent() {
774 return SERVICE_PATH_COMPONENT;
778 protected PoxPayloadOut createInstance(String identifier) {
779 return createLoaninInstance(identifier);
783 * Creates the loanin instance.
785 * @param identifier the identifier
786 * @return the multipart output
788 private PoxPayloadOut createLoaninInstance(String identifier) {
789 return createLoaninInstance(
790 "loaninNumber-" + identifier,
791 "returnDate-" + identifier);
795 * Creates the loanin instance.
797 * @param loaninNumber the loanin number
798 * @param returnDate the return date
799 * @return the multipart output
801 private PoxPayloadOut createLoaninInstance(String loaninNumber,
804 LoansinCommon loaninCommon = new LoansinCommon();
805 loaninCommon.setLoanInNumber(loaninNumber);
806 loaninCommon.setLoanReturnDate(CURRENT_DATE_UTC);
807 LenderGroupList lenderGroupList = new LenderGroupList();
808 LenderGroup lenderGroup = new LenderGroup();
809 lenderGroup.setLender(LENDER_REF_NAME);
810 lenderGroupList.getLenderGroup().add(lenderGroup);
811 loaninCommon.setLenderGroupList(lenderGroupList);
812 loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
813 loaninCommon.setLoanInNote(getUTF8DataFragment());
815 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
816 PayloadOutputPart commonPart =
817 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
818 commonPart.setLabel(new LoaninClient().getCommonPartName());
820 if (logger.isDebugEnabled()) {
821 logger.debug("to be created, loanin common");
822 logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));