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.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.AbstractCommonListUtils;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoanoutClient;
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.api.GregorianCalendarDateTimeUtils;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.loanout.LoanStatusGroup;
39 import org.collectionspace.services.loanout.LoanStatusGroupList;
40 import org.collectionspace.services.loanout.LoansoutCommon;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * LoanoutServiceTest, carries out tests against a
51 * deployed and running Loanout (aka Loans Out) Service.
53 * $LastChangedRevision$
56 public class LoanoutServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, LoansoutCommon> {
59 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
60 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 /** The known resource id. */
62 private final static String CURRENT_DATE_UTC =
63 GregorianCalendarDateTimeUtils.currentDateUTC();
66 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
69 protected CollectionSpaceClient getClientInstance() {
70 return new LoanoutClient();
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
77 protected AbstractCommonList getCommonList(Response response) {
78 return response.readEntity(AbstractCommonList.class);
81 // ---------------------------------------------------------------
82 // CRUD tests : CREATE tests
83 // ---------------------------------------------------------------
86 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
89 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
90 public void create(String testName) throws Exception {
91 // Perform setup, such as initializing the type of service request
92 // (e.g. CREATE, DELETE), its valid and expected status codes, and
93 // its associated HTTP method name (e.g. POST, DELETE).
96 // Submit the request to the service and store the response.
97 LoanoutClient client = new LoanoutClient();
98 String identifier = createIdentifier();
99 PoxPayloadOut multipart = createLoanoutInstance(identifier);
101 Response res = client.create(multipart);
103 int statusCode = res.getStatus();
105 // Check the status code of the response: does it match
106 // the expected response(s)?
109 // Does it fall within the set of valid status codes?
110 // Does it exactly match the expected status code?
111 if (logger.isDebugEnabled()) {
112 logger.debug(testName + ": status = " + statusCode);
114 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
115 invalidStatusCodeMessage(testRequestType, statusCode));
116 Assert.assertEquals(statusCode, testExpectedStatusCode);
117 newId = extractId(res);
122 // Store the ID returned from the first resource created
123 // for additional tests below.
124 if (knownResourceId == null) {
125 knownResourceId = newId;
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": knownResourceId=" + knownResourceId);
131 // Store the IDs from every resource created by tests,
132 // so they can be deleted after tests have been run.
133 allResourceIdsCreated.add(newId);
137 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
140 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
141 // dependsOnMethods = {"create"})
142 public void createList(String testName) throws Exception {
143 for (int i = 0; i < 3; i++) {
149 // Placeholders until the three tests below can be uncommented.
150 // See Issue CSPACE-401.
152 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
155 public void createWithEmptyEntityBody(String testName) throws Exception {
156 //Should this really be empty?
160 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
163 public void createWithMalformedXml(String testName) throws Exception {
164 //Should this really be empty?
168 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
171 public void createWithWrongXmlSchema(String testName) throws Exception {
172 //Should this really be empty?
177 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
178 dependsOnMethods = {"create", "testSubmitRequest"})
179 public void createWithEmptyEntityBody(String testName) throws Exception {
181 if (logger.isDebugEnabled()) {
182 logger.debug(testBanner(testName, CLASS_NAME));
185 setupCreateWithEmptyEntityBody();
187 // Submit the request to the service and store the response.
188 String method = REQUEST_TYPE.httpMethodName();
189 String url = getServiceRootURL();
190 String mediaType = MediaType.APPLICATION_XML;
191 final String entity = "";
192 int statusCode = submitRequest(method, url, mediaType, entity);
194 // Check the status code of the response: does it match
195 // the expected response(s)?
196 if(logger.isDebugEnabled()){
197 logger.debug("createWithEmptyEntityBody url=" + url +
198 " status=" + statusCode);
200 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
201 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
202 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
206 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
207 dependsOnMethods = {"create", "testSubmitRequest"})
208 public void createWithMalformedXml(String testName) throws Exception {
210 if (logger.isDebugEnabled()) {
211 logger.debug(testBanner(testName, CLASS_NAME));
214 setupCreateWithMalformedXml();
216 // Submit the request to the service and store the response.
217 String method = REQUEST_TYPE.httpMethodName();
218 String url = getServiceRootURL();
219 String mediaType = MediaType.APPLICATION_XML;
220 final String entity = MALFORMED_XML_DATA; // Constant from base class.
221 int statusCode = submitRequest(method, url, mediaType, entity);
223 // Check the status code of the response: does it match
224 // the expected response(s)?
225 if(logger.isDebugEnabled()){
226 logger.debug(testName + ": url=" + url +
227 " status=" + statusCode);
229 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
230 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
231 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
235 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
236 dependsOnMethods = {"create", "testSubmitRequest"})
237 public void createWithWrongXmlSchema(String testName) throws Exception {
239 if (logger.isDebugEnabled()) {
240 logger.debug(testBanner(testName, CLASS_NAME));
243 setupCreateWithWrongXmlSchema();
245 // Submit the request to the service and store the response.
246 String method = REQUEST_TYPE.httpMethodName();
247 String url = getServiceRootURL();
248 String mediaType = MediaType.APPLICATION_XML;
249 final String entity = WRONG_XML_SCHEMA_DATA;
250 int statusCode = submitRequest(method, url, mediaType, entity);
252 // Check the status code of the response: does it match
253 // the expected response(s)?
254 if(logger.isDebugEnabled()){
255 logger.debug(testName + ": url=" + url +
256 " status=" + statusCode);
258 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
259 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
260 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
263 // ---------------------------------------------------------------
264 // CRUD tests : READ tests
265 // ---------------------------------------------------------------
268 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
271 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
272 // dependsOnMethods = {"create"})
273 public void read(String testName) throws Exception {
277 // Submit the request to the service and store the response.
278 LoanoutClient client = new LoanoutClient();
279 Response res = client.read(knownResourceId);
280 LoansoutCommon loanoutCommon = null;
282 assertStatusCode(res, testName);
283 // Get the common part of the response and verify that it is not null.
284 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
285 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
286 if (payloadInputPart != null) {
287 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
289 Assert.assertNotNull(loanoutCommon);
296 // Check selected fields in the common part.
297 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
299 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
300 Assert.assertNotNull(statusGroupList);
301 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
302 Assert.assertNotNull(statusGroups);
303 Assert.assertTrue(statusGroups.size() > 0);
304 LoanStatusGroup statusGroup = statusGroups.get(0);
305 Assert.assertNotNull(statusGroup);
306 Assert.assertNotNull(statusGroup.getLoanStatus());
308 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
309 if (logger.isDebugEnabled()) {
310 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
311 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
313 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
314 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
315 + "' does not match expected data '" + getUTF8DataFragment());
320 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
323 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
324 // dependsOnMethods = {"read"})
325 public void readNonExistent(String testName) throws Exception {
327 setupReadNonExistent();
329 // Submit the request to the service and store the response.
330 LoanoutClient client = new LoanoutClient();
331 Response res = client.read(NON_EXISTENT_ID);
333 int statusCode = res.getStatus();
335 // Check the status code of the response: does it match
336 // the expected response(s)?
337 if (logger.isDebugEnabled()) {
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(testRequestType, statusCode));
342 Assert.assertEquals(statusCode, testExpectedStatusCode);
348 // ---------------------------------------------------------------
349 // CRUD tests : READ_LIST tests
350 // ---------------------------------------------------------------
353 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
356 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
357 // dependsOnMethods = {"createList", "read"})
358 public void readList(String testName) throws Exception {
362 // Submit the request to the service and store the response.
363 LoanoutClient client = new LoanoutClient();
364 Response res = client.readList();
365 AbstractCommonList list = null;
367 assertStatusCode(res, testName);
368 list = res.readEntity(getCommonListType());
374 // Optionally output additional data about list members for debugging.
375 boolean iterateThroughList = true;
376 if (iterateThroughList && logger.isDebugEnabled()){
377 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
384 // ---------------------------------------------------------------
385 // CRUD tests : UPDATE tests
386 // ---------------------------------------------------------------
389 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
392 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
393 // dependsOnMethods = {"read"})
394 public void update(String testName) throws Exception {
398 // Retrieve the contents of a resource to update.
399 LoanoutClient client = new LoanoutClient();
400 Response res = client.read(knownResourceId);
401 LoansoutCommon loanoutCommon = null;
403 assertStatusCode(res, testName);
404 // Extract the common part from the response.
405 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
406 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
407 if (payloadInputPart != null) {
408 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
410 Assert.assertNotNull(loanoutCommon);
417 // Update the content of this resource.
418 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
419 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
420 Assert.assertNotNull(statusGroupList);
421 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
422 Assert.assertNotNull(statusGroups);
423 Assert.assertTrue(statusGroups.size() > 0);
424 LoanStatusGroup statusGroup = statusGroups.get(0);
425 Assert.assertNotNull(statusGroup);
426 String loanStatus = statusGroup.getLoanStatus();
427 Assert.assertNotNull(loanStatus);
428 String updatedLoanStatus = "updated-" + loanStatus;
429 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
430 loanoutCommon.setLoanStatusGroupList(statusGroupList);
431 if (logger.isDebugEnabled()) {
432 logger.debug("to be updated object");
433 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
435 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
439 // Submit the updated resource in an update request to the service and store the response.
440 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
441 PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon);
443 res = client.update(knownResourceId, output);
444 LoansoutCommon updatedLoanoutCommon = null;
446 assertStatusCode(res, testName);
447 // Extract the updated common part from the response.
448 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
449 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
450 if (payloadInputPart != null) {
451 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
453 Assert.assertNotNull(updatedLoanoutCommon);
460 // Check selected fields in the updated resource.
461 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
462 loanoutCommon.getLoanOutNumber(),
463 "Data in updated object did not match submitted data.");
465 LoanStatusGroupList updatedStatusGroupList =
466 updatedLoanoutCommon.getLoanStatusGroupList();
467 Assert.assertNotNull(updatedStatusGroupList);
468 List<LoanStatusGroup> updatedStatusGroups =
469 updatedStatusGroupList.getLoanStatusGroup();
470 Assert.assertNotNull(updatedStatusGroups);
471 Assert.assertTrue(updatedStatusGroups.size() > 0);
472 Assert.assertNotNull(updatedStatusGroups.get(0));
473 Assert.assertEquals(updatedLoanStatus,
474 updatedStatusGroups.get(0).getLoanStatus(),
475 "Data in updated object did not match submitted data.");
477 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
478 if (logger.isDebugEnabled()) {
479 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
480 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
482 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
483 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
484 + "' does not contain expected data '" + getUTF8DataFragment());
485 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
486 loanoutCommon.getLoanOutNote(),
487 "Data in updated object did not match submitted data.");
491 // Placeholders until the three tests below can be uncommented.
492 // See Issue CSPACE-401.
494 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
497 public void updateWithEmptyEntityBody(String testName) throws Exception {
498 //Should this really be empty?
502 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
505 public void updateWithMalformedXml(String testName) throws Exception {
506 //Should this really be empty?
510 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
513 public void updateWithWrongXmlSchema(String testName) throws Exception {
514 //Should this really be empty?
519 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
520 dependsOnMethods = {"create", "update", "testSubmitRequest"})
521 public void updateWithEmptyEntityBody(String testName) throws Exception {
523 if (logger.isDebugEnabled()) {
524 logger.debug(testBanner(testName, CLASS_NAME));
527 setupUpdateWithEmptyEntityBody();
529 // Submit the request to the service and store the response.
530 String method = REQUEST_TYPE.httpMethodName();
531 String url = getResourceURL(knownResourceId);
532 String mediaType = MediaType.APPLICATION_XML;
533 final String entity = "";
534 int statusCode = submitRequest(method, url, mediaType, entity);
536 // Check the status code of the response: does it match
537 // the expected response(s)?
538 if(logger.isDebugEnabled()){
539 logger.debug(testName + ": url=" + url +
540 " status=" + statusCode);
542 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
543 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
544 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
548 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
549 dependsOnMethods = {"create", "update", "testSubmitRequest"})
550 public void updateWithMalformedXml(String testName) throws Exception {
552 if (logger.isDebugEnabled()) {
553 logger.debug(testBanner(testName, CLASS_NAME));
556 setupUpdateWithMalformedXml();
558 // Submit the request to the service and store the response.
559 String method = REQUEST_TYPE.httpMethodName();
560 String url = getResourceURL(knownResourceId);
561 String mediaType = MediaType.APPLICATION_XML;
562 final String entity = MALFORMED_XML_DATA;
563 int statusCode = submitRequest(method, url, mediaType, entity);
565 // Check the status code of the response: does it match
566 // the expected response(s)?
567 if(logger.isDebugEnabled()){
568 logger.debug(testName + ": url=" + url +
569 " status=" + statusCode);
571 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
572 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
573 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
577 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
578 dependsOnMethods = {"create", "update", "testSubmitRequest"})
579 public void updateWithWrongXmlSchema(String testName) throws Exception {
581 if (logger.isDebugEnabled()) {
582 logger.debug(testBanner(testName, CLASS_NAME));
585 setupUpdateWithWrongXmlSchema();
587 // Submit the request to the service and store the response.
588 String method = REQUEST_TYPE.httpMethodName();
589 String url = getResourceURL(knownResourceId);
590 String mediaType = MediaType.APPLICATION_XML;
591 final String entity = WRONG_XML_SCHEMA_DATA;
592 int statusCode = submitRequest(method, url, mediaType, entity);
594 // Check the status code of the response: does it match
595 // the expected response(s)?
596 if(logger.isDebugEnabled()){
597 logger.debug(testName + ": url=" + url +
598 " status=" + statusCode);
600 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
601 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
602 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
610 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
611 // dependsOnMethods = {"update", "testSubmitRequest"})
612 public void updateNonExistent(String testName) throws Exception {
614 setupUpdateNonExistent();
616 // Submit the request to the service and store the response.
617 // Note: The ID used in this 'create' call may be arbitrary.
618 // The only relevant ID may be the one used in update(), below.
619 LoanoutClient client = new LoanoutClient();
620 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
621 Response res = client.update(NON_EXISTENT_ID, multipart);
623 int statusCode = res.getStatus();
625 // Check the status code of the response: does it match
626 // the expected response(s)?
627 if (logger.isDebugEnabled()) {
628 logger.debug(testName + ": status = " + statusCode);
630 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
631 invalidStatusCodeMessage(testRequestType, statusCode));
632 Assert.assertEquals(statusCode, testExpectedStatusCode);
638 // ---------------------------------------------------------------
639 // CRUD tests : DELETE tests
640 // ---------------------------------------------------------------
643 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
646 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
647 // dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
648 public void delete(String testName) throws Exception {
652 // Submit the request to the service and store the response.
653 LoanoutClient client = new LoanoutClient();
654 Response res = client.delete(knownResourceId);
656 int statusCode = res.getStatus();
658 // Check the status code of the response: does it match
659 // the expected response(s)?
660 if (logger.isDebugEnabled()) {
661 logger.debug(testName + ": status = " + statusCode);
663 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(testRequestType, statusCode));
665 Assert.assertEquals(statusCode, testExpectedStatusCode);
673 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
676 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
677 // dependsOnMethods = {"delete"})
678 public void deleteNonExistent(String testName) throws Exception {
680 setupDeleteNonExistent();
682 // Submit the request to the service and store the response.
683 LoanoutClient client = new LoanoutClient();
684 Response res = client.delete(NON_EXISTENT_ID);
686 int statusCode = res.getStatus();
688 // Check the status code of the response: does it match
689 // the expected response(s)?
690 if (logger.isDebugEnabled()) {
691 logger.debug(testName + ": status = " + statusCode);
693 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
694 invalidStatusCodeMessage(testRequestType, statusCode));
695 Assert.assertEquals(statusCode, testExpectedStatusCode);
701 // ---------------------------------------------------------------
702 // Utility tests : tests of code used in tests above
703 // ---------------------------------------------------------------
705 * Tests the code for manually submitting data that is used by several
706 * of the methods above.
708 // @Test(dependsOnMethods = {"create", "read"})
709 public void testSubmitRequest() {
711 // Expected status code: 200 OK
712 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
714 // Submit the request to the service and store the response.
715 String method = ServiceRequestType.READ.httpMethodName();
716 String url = getResourceURL(knownResourceId);
717 int statusCode = submitRequest(method, url);
719 // Check the status code of the response: does it match
720 // the expected response(s)?
721 if (logger.isDebugEnabled()) {
722 logger.debug("testSubmitRequest: url=" + url
723 + " status=" + statusCode);
725 Assert.assertEquals(statusCode, EXPECTED_STATUS);
729 // ---------------------------------------------------------------
730 // Utility methods used by tests above
731 // ---------------------------------------------------------------
733 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
736 public String getServicePathComponent() {
737 return LoanoutClient.SERVICE_PATH_COMPONENT;
741 protected PoxPayloadOut createInstance(String identifier) {
742 return createLoanoutInstance(identifier);
746 * Creates the loanout instance.
748 * @param identifier the identifier
749 * @return the multipart output
751 private PoxPayloadOut createLoanoutInstance(String identifier) {
752 return createLoanoutInstance(
753 "loanoutNumber-" + identifier,
758 * Creates the loanout instance.
760 * @param loanOutNumber the loan out number
761 * @param returnDate the return date
762 * @return the multipart output
764 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
766 LoansoutCommon loanoutCommon = new LoansoutCommon();
767 loanoutCommon.setLoanOutNumber(loanOutNumber);
768 loanoutCommon.setLoanReturnDate(returnDate);
769 loanoutCommon.setBorrower(
770 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
771 loanoutCommon.setBorrowersContact(
772 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
773 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
774 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
775 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
776 LoanStatusGroup statusGroup = new LoanStatusGroup();
777 statusGroup.setLoanStatus("returned");
778 statusGroup.setLoanStatusNote("Left under the front mat.");
779 statusGroups.add(statusGroup);
780 loanoutCommon.setLoanStatusGroupList(statusGroupList);
781 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
783 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
784 PayloadOutputPart commonPart =
785 multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon);
787 if (logger.isDebugEnabled()) {
788 logger.debug("to be created, loanout common");
789 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
790 // logger.debug(multipart.toXML());
797 protected String getServiceName() {
798 return LoanoutClient.SERVICE_NAME;
802 public void CRUDTests(String testName) {
803 // TODO Auto-generated method stub
808 protected PoxPayloadOut createInstance(String commonPartName,
810 PoxPayloadOut result = createLoanoutInstance(identifier);
815 protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) {
816 // TODO Auto-generated method stub
821 protected void compareUpdatedInstances(LoansoutCommon original,
822 LoansoutCommon updated) throws Exception {
823 // TODO Auto-generated method stub