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.jaxb.AbstractCommonList;
33 import org.collectionspace.services.loanin.LenderGroup;
34 import org.collectionspace.services.loanin.LenderGroupList;
35 import org.collectionspace.services.loanin.LoansinCommon;
36 import org.collectionspace.services.loanin.LoansinCommonList;
38 import org.jboss.resteasy.client.ClientResponse;
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
41 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
42 import org.testng.Assert;
43 //import org.testng.annotations.AfterClass;
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);
62 // Instance variables specific to this test.
63 /** The service path component. */
64 final String SERVICE_PATH_COMPONENT = "loansin";
66 /** The known resource id. */
67 private String knownResourceId = null;
69 private String LENDER_REF_NAME =
70 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
73 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
76 protected CollectionSpaceClient getClientInstance() {
77 return new LoaninClient();
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
84 protected AbstractCommonList getAbstractCommonList(
85 ClientResponse<AbstractCommonList> response) {
86 return response.getEntity(LoansinCommonList.class);
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
97 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
98 public void create(String testName) throws Exception {
100 if (logger.isDebugEnabled()) {
101 logger.debug(testBanner(testName, CLASS_NAME));
103 // Perform setup, such as initializing the type of service request
104 // (e.g. CREATE, DELETE), its valid and expected status codes, and
105 // its associated HTTP method name (e.g. POST, DELETE).
108 // Submit the request to the service and store the response.
109 LoaninClient client = new LoaninClient();
110 String identifier = createIdentifier();
111 MultipartOutput multipart = createLoaninInstance(identifier);
113 ClientResponse<Response> res = client.create(multipart);
115 int statusCode = res.getStatus();
117 // Check the status code of the response: does it match
118 // the expected response(s)?
121 // Does it fall within the set of valid status codes?
122 // Does it exactly match the expected status code?
123 if(logger.isDebugEnabled()){
124 logger.debug(testName + ": status = " + statusCode);
126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
130 newID = extractId(res);
132 res.releaseConnection();
135 // Store the ID returned from the first resource created
136 // for additional tests below.
137 if (knownResourceId == null){
138 knownResourceId = newID;
139 if (logger.isDebugEnabled()) {
140 logger.debug(testName + ": knownResourceId=" + knownResourceId);
144 // Store the IDs from every resource created by tests,
145 // so they can be deleted after tests have been run.
146 allResourceIdsCreated.add(newID);
150 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
153 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
154 dependsOnMethods = {"create"})
155 public void createList(String testName) throws Exception {
156 for(int i = 0; i < 3; i++){
162 // Placeholders until the three tests below can be uncommented.
163 // See Issue CSPACE-401.
165 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
168 public void createWithEmptyEntityBody(String testName) throws Exception {
169 //Should this really be empty?
173 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
176 public void createWithMalformedXml(String testName) throws Exception {
177 //Should this really be empty?
181 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
184 public void createWithWrongXmlSchema(String testName) throws Exception {
185 //Should this really be empty?
190 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
191 dependsOnMethods = {"create", "testSubmitRequest"})
192 public void createWithEmptyEntityBody(String testName) throws Exception {
194 if (logger.isDebugEnabled()) {
195 logger.debug(testBanner(testName, CLASS_NAME));
198 setupCreateWithEmptyEntityBody();
200 // Submit the request to the service and store the response.
201 String method = REQUEST_TYPE.httpMethodName();
202 String url = getServiceRootURL();
203 String mediaType = MediaType.APPLICATION_XML;
204 final String entity = "";
205 int statusCode = submitRequest(method, url, mediaType, entity);
207 // Check the status code of the response: does it match
208 // the expected response(s)?
209 if(logger.isDebugEnabled()){
210 logger.debug("createWithEmptyEntityBody url=" + url +
211 " status=" + statusCode);
213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
220 dependsOnMethods = {"create", "testSubmitRequest"})
221 public void createWithMalformedXml(String testName) throws Exception {
223 if (logger.isDebugEnabled()) {
224 logger.debug(testBanner(testName, CLASS_NAME));
227 setupCreateWithMalformedXml(testName, logger);
229 // Submit the request to the service and store the response.
230 String method = REQUEST_TYPE.httpMethodName();
231 String url = getServiceRootURL();
232 String mediaType = MediaType.APPLICATION_XML;
233 final String entity = MALFORMED_XML_DATA; // Constant from base class.
234 int statusCode = submitRequest(method, url, mediaType, entity);
236 // Check the status code of the response: does it match
237 // the expected response(s)?
238 if(logger.isDebugEnabled()){
239 logger.debug(testName + ": url=" + url +
240 " status=" + statusCode);
242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
244 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
249 dependsOnMethods = {"create", "testSubmitRequest"})
250 public void createWithWrongXmlSchema(String testName) throws Exception {
252 if (logger.isDebugEnabled()) {
253 logger.debug(testBanner(testName, CLASS_NAME));
256 setupCreateWithWrongXmlSchema(testName, logger);
258 // Submit the request to the service and store the response.
259 String method = REQUEST_TYPE.httpMethodName();
260 String url = getServiceRootURL();
261 String mediaType = MediaType.APPLICATION_XML;
262 final String entity = WRONG_XML_SCHEMA_DATA;
263 int statusCode = submitRequest(method, url, mediaType, entity);
265 // Check the status code of the response: does it match
266 // the expected response(s)?
267 if(logger.isDebugEnabled()){
268 logger.debug(testName + ": url=" + url +
269 " status=" + statusCode);
271 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
272 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
273 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
277 // ---------------------------------------------------------------
278 // CRUD tests : READ tests
279 // ---------------------------------------------------------------
282 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
285 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
286 dependsOnMethods = {"create"})
287 public void read(String testName) throws Exception {
289 if (logger.isDebugEnabled()) {
290 logger.debug(testBanner(testName, CLASS_NAME));
295 // Submit the request to the service and store the response.
296 MultipartInput input = null;
297 LoaninClient client = new LoaninClient();
298 ClientResponse<MultipartInput> res = client.read(knownResourceId);
300 int statusCode = res.getStatus();
302 // Check the status code of the response: does it match
303 // the expected response(s)?
304 if(logger.isDebugEnabled()){
305 logger.debug(testName + ": status = " + statusCode);
307 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
308 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
309 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
311 input = res.getEntity();
313 res.releaseConnection();
316 LoansinCommon loanin = (LoansinCommon) extractPart(input,
317 client.getCommonPartName(), LoansinCommon.class);
318 Assert.assertNotNull(loanin);
320 LenderGroupList lenderGroupList = loanin.getLenderGroupList();
321 Assert.assertNotNull(lenderGroupList);
322 List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
323 Assert.assertNotNull(lenderGroups);
324 Assert.assertTrue(lenderGroups.size() > 0);
325 String lender = lenderGroups.get(0).getLender();
326 Assert.assertEquals(lender, LENDER_REF_NAME);
332 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
335 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
336 dependsOnMethods = {"read"})
337 public void readNonExistent(String testName) throws Exception {
339 if (logger.isDebugEnabled()) {
340 logger.debug(testBanner(testName, CLASS_NAME));
343 setupReadNonExistent();
345 // Submit the request to the service and store the response.
346 LoaninClient client = new LoaninClient();
347 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
349 int statusCode = res.getStatus();
351 // Check the status code of the response: does it match
352 // the expected response(s)?
353 if(logger.isDebugEnabled()){
354 logger.debug(testName + ": status = " + statusCode);
356 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
357 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
358 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
360 res.releaseConnection();
364 // ---------------------------------------------------------------
365 // CRUD tests : READ_LIST tests
366 // ---------------------------------------------------------------
369 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
372 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
373 dependsOnMethods = {"createList", "read"})
374 public void readList(String testName) throws Exception {
376 if (logger.isDebugEnabled()) {
377 logger.debug(testBanner(testName, CLASS_NAME));
382 // Submit the request to the service and store the response.
383 LoansinCommonList list = null;
384 LoaninClient client = new LoaninClient();
385 ClientResponse<LoansinCommonList> res = client.readList();
387 int statusCode = res.getStatus();
389 // Check the status code of the response: does it match
390 // the expected response(s)?
391 if(logger.isDebugEnabled()){
392 logger.debug(testName + ": status = " + statusCode);
394 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
398 list = res.getEntity();
400 res.releaseConnection();
403 // Optionally output additional data about list members for debugging.
404 boolean iterateThroughList = false;
405 if (iterateThroughList && logger.isDebugEnabled()){
406 List<LoansinCommonList.LoaninListItem> items =
407 list.getLoaninListItem();
409 for(LoansinCommonList.LoaninListItem item : items){
410 logger.debug(testName + ": list-item[" + i + "] csid=" +
412 logger.debug(testName + ": list-item[" + i + "] loanInNumber=" +
413 item.getLoanInNumber());
414 logger.debug(testName + ": list-item[" + i + "] URI=" +
423 // ---------------------------------------------------------------
424 // CRUD tests : UPDATE tests
425 // ---------------------------------------------------------------
428 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
431 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
432 dependsOnMethods = {"read"})
433 public void update(String testName) throws Exception {
435 if (logger.isDebugEnabled()) {
436 logger.debug(testBanner(testName, CLASS_NAME));
441 // Retrieve the contents of a resource to update.
442 MultipartInput input = null;
443 LoaninClient client = new LoaninClient();
444 ClientResponse<MultipartInput> res =
445 client.read(knownResourceId);
447 if(logger.isDebugEnabled()){
448 logger.debug(testName + ": read status = " + res.getStatus());
450 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
452 if(logger.isDebugEnabled()){
453 logger.debug("got object to update with ID: " + knownResourceId);
455 input = res.getEntity();
457 res.releaseConnection();
460 LoansinCommon loanin = (LoansinCommon) extractPart(input,
461 client.getCommonPartName(), LoansinCommon.class);
462 Assert.assertNotNull(loanin);
464 // Update the content of this resource.
465 loanin.setLoanInNumber("updated-" + loanin.getLoanInNumber());
466 loanin.setLoanReturnDate("updated-" + loanin.getLoanReturnDate());
467 if(logger.isDebugEnabled()){
468 logger.debug("to be updated object");
469 logger.debug(objectAsXmlString(loanin, LoansinCommon.class));
471 // Submit the request to the service and store the response.
472 MultipartOutput output = new MultipartOutput();
473 OutputPart commonPart = output.addPart(loanin, MediaType.APPLICATION_XML_TYPE);
474 commonPart.getHeaders().add("label", client.getCommonPartName());
476 res = client.update(knownResourceId, output);
478 int statusCode = res.getStatus();
479 // Check the status code of the response: does it match the expected response(s)?
480 if(logger.isDebugEnabled()){
481 logger.debug(testName + ": status = " + statusCode);
483 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
484 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
485 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
488 input = (MultipartInput) res.getEntity();
490 res.releaseConnection();
493 LoansinCommon updatedLoanin =
494 (LoansinCommon) extractPart(input,
495 client.getCommonPartName(), LoansinCommon.class);
496 Assert.assertNotNull(updatedLoanin);
498 Assert.assertEquals(updatedLoanin.getLoanReturnDate(),
499 loanin.getLoanReturnDate(),
500 "Data in updated object did not match submitted data.");
504 // Placeholders until the three tests below can be uncommented.
505 // See Issue CSPACE-401.
507 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
510 public void updateWithEmptyEntityBody(String testName) throws Exception {
511 //Should this really be empty?
515 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
518 public void updateWithMalformedXml(String testName) throws Exception {
519 //Should this really be empty?
523 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
526 public void updateWithWrongXmlSchema(String testName) throws Exception {
527 //Should this really be empty?
532 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
533 dependsOnMethods = {"create", "update", "testSubmitRequest"})
534 public void updateWithEmptyEntityBody(String testName) throws Exception {
536 if (logger.isDebugEnabled()) {
537 logger.debug(testBanner(testName, CLASS_NAME));
540 setupUpdateWithEmptyEntityBody();
542 // Submit the request to the service and store the response.
543 String method = REQUEST_TYPE.httpMethodName();
544 String url = getResourceURL(knownResourceId);
545 String mediaType = MediaType.APPLICATION_XML;
546 final String entity = "";
547 int statusCode = submitRequest(method, url, mediaType, entity);
549 // Check the status code of the response: does it match
550 // the expected response(s)?
551 if(logger.isDebugEnabled()){
552 logger.debug(testName + ": url=" + url +
553 " status=" + statusCode);
555 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
556 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
557 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
561 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
562 dependsOnMethods = {"create", "update", "testSubmitRequest"})
563 public void updateWithMalformedXml(String testName) throws Exception {
565 if (logger.isDebugEnabled()) {
566 logger.debug(testBanner(testName, CLASS_NAME));
569 setupUpdateWithMalformedXml();
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 = MALFORMED_XML_DATA;
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 updateWithWrongXmlSchema(String testName) throws Exception {
594 if (logger.isDebugEnabled()) {
595 logger.debug(testBanner(testName, CLASS_NAME));
598 setupUpdateWithWrongXmlSchema();
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 = WRONG_XML_SCHEMA_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);
620 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
624 dependsOnMethods = {"update", "testSubmitRequest"})
625 public void updateNonExistent(String testName) throws Exception {
627 if (logger.isDebugEnabled()) {
628 logger.debug(testBanner(testName, CLASS_NAME));
631 setupUpdateNonExistent();
633 // Submit the request to the service and store the response.
634 // Note: The ID used in this 'create' call may be arbitrary.
635 // The only relevant ID may be the one used in update(), below.
636 LoaninClient client = new LoaninClient();
637 MultipartOutput multipart = createLoaninInstance(NON_EXISTENT_ID);
638 ClientResponse<MultipartInput> res =
639 client.update(NON_EXISTENT_ID, multipart);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 res.releaseConnection();
656 // ---------------------------------------------------------------
657 // CRUD tests : DELETE tests
658 // ---------------------------------------------------------------
661 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
664 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
665 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
666 public void delete(String testName) throws Exception {
668 if (logger.isDebugEnabled()) {
669 logger.debug(testBanner(testName, CLASS_NAME));
674 // Submit the request to the service and store the response.
675 LoaninClient client = new LoaninClient();
676 ClientResponse<Response> res = client.delete(knownResourceId);
678 int statusCode = res.getStatus();
680 // Check the status code of the response: does it match
681 // the expected response(s)?
682 if(logger.isDebugEnabled()){
683 logger.debug(testName + ": status = " + statusCode);
685 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
686 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
687 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
689 res.releaseConnection();
695 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
698 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
699 dependsOnMethods = {"delete"})
700 public void deleteNonExistent(String testName) throws Exception {
702 if (logger.isDebugEnabled()) {
703 logger.debug(testBanner(testName, CLASS_NAME));
706 setupDeleteNonExistent();
708 // Submit the request to the service and store the response.
709 LoaninClient client = new LoaninClient();
710 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
712 int statusCode = res.getStatus();
714 // Check the status code of the response: does it match
715 // the expected response(s)?
716 if(logger.isDebugEnabled()){
717 logger.debug(testName + ": status = " + statusCode);
719 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
720 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
721 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
723 res.releaseConnection();
727 // ---------------------------------------------------------------
728 // Utility tests : tests of code used in tests above
729 // ---------------------------------------------------------------
731 * Tests the code for manually submitting data that is used by several
732 * of the methods above.
734 @Test(dependsOnMethods = {"create", "read"})
735 public void testSubmitRequest() {
737 // Expected status code: 200 OK
738 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
740 // Submit the request to the service and store the response.
741 String method = ServiceRequestType.READ.httpMethodName();
742 String url = getResourceURL(knownResourceId);
743 int statusCode = submitRequest(method, url);
745 // Check the status code of the response: does it match
746 // the expected response(s)?
747 if(logger.isDebugEnabled()){
748 logger.debug("testSubmitRequest: url=" + url +
749 " status=" + statusCode);
751 Assert.assertEquals(statusCode, EXPECTED_STATUS);
755 // ---------------------------------------------------------------
756 // Utility methods used by tests above
757 // ---------------------------------------------------------------
759 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
762 public String getServicePathComponent() {
763 return SERVICE_PATH_COMPONENT;
767 * Creates the loanin instance.
769 * @param identifier the identifier
770 * @return the multipart output
772 private MultipartOutput createLoaninInstance(String identifier) {
773 return createLoaninInstance(
774 "loaninNumber-" + identifier,
775 "returnDate-" + identifier);
779 * Creates the loanin instance.
781 * @param loaninNumber the loanin number
782 * @param returnDate the return date
783 * @return the multipart output
785 private MultipartOutput createLoaninInstance(String loaninNumber,
787 LoansinCommon loanin = new LoansinCommon();
788 loanin.setLoanInNumber(loaninNumber);
789 loanin.setLoanReturnDate(returnDate);
790 LenderGroupList lenderGroupList = new LenderGroupList();
791 LenderGroup lenderGroup = new LenderGroup();
792 lenderGroup.setLender(LENDER_REF_NAME);
793 lenderGroupList.getLenderGroup().add(lenderGroup);
794 loanin.setLenderGroupList(lenderGroupList);
795 loanin.setLoanPurpose("For Surfboards of the 1960s exhibition.");
796 MultipartOutput multipart = new MultipartOutput();
797 OutputPart commonPart =
798 multipart.addPart(loanin, MediaType.APPLICATION_XML_TYPE);
799 commonPart.getHeaders().add("label", new LoaninClient().getCommonPartName());
801 if(logger.isDebugEnabled()){
802 logger.debug("to be created, loanin common");
803 logger.debug(objectAsXmlString(loanin, LoansinCommon.class));