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;
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.testng.Assert;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * LoanoutServiceTest, carries out tests against a
48 * deployed and running Loanout (aka Loans Out) Service.
50 * $LastChangedRevision$
53 public class LoanoutServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, LoansoutCommon> {
56 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
57 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
58 /** The known resource id. */
59 private final static String CURRENT_DATE_UTC =
60 GregorianCalendarDateTimeUtils.currentDateUTC();
63 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
66 protected CollectionSpaceClient getClientInstance() {
67 return new LoanoutClient();
71 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
72 return new LoanoutClient(clientPropertiesFilename);
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getCommonList(Response response) {
80 return response.readEntity(AbstractCommonList.class);
83 // ---------------------------------------------------------------
84 // CRUD tests : CREATE tests
85 // ---------------------------------------------------------------
88 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
91 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
92 public void create(String testName) throws Exception {
93 // Perform setup, such as initializing the type of service request
94 // (e.g. CREATE, DELETE), its valid and expected status codes, and
95 // its associated HTTP method name (e.g. POST, DELETE).
98 // Submit the request to the service and store the response.
99 LoanoutClient client = new LoanoutClient();
100 String identifier = createIdentifier();
101 PoxPayloadOut multipart = createLoanoutInstance(identifier);
103 Response res = client.create(multipart);
105 int statusCode = res.getStatus();
107 // Check the status code of the response: does it match
108 // the expected response(s)?
111 // Does it fall within the set of valid status codes?
112 // Does it exactly match the expected status code?
113 if (logger.isDebugEnabled()) {
114 logger.debug(testName + ": status = " + statusCode);
116 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
117 invalidStatusCodeMessage(testRequestType, statusCode));
118 Assert.assertEquals(statusCode, testExpectedStatusCode);
119 newId = extractId(res);
124 // Store the ID returned from the first resource created
125 // for additional tests below.
126 if (knownResourceId == null) {
127 knownResourceId = newId;
128 if (logger.isDebugEnabled()) {
129 logger.debug(testName + ": knownResourceId=" + knownResourceId);
133 // Store the IDs from every resource created by tests,
134 // so they can be deleted after tests have been run.
135 allResourceIdsCreated.add(newId);
139 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
142 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
143 // dependsOnMethods = {"create"})
144 public void createList(String testName) throws Exception {
145 for (int i = 0; i < 3; i++) {
151 // Placeholders until the three tests below can be uncommented.
152 // See Issue CSPACE-401.
154 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
157 public void createWithEmptyEntityBody(String testName) throws Exception {
158 //Should this really be empty?
162 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
165 public void createWithMalformedXml(String testName) throws Exception {
166 //Should this really be empty?
170 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
173 public void createWithWrongXmlSchema(String testName) throws Exception {
174 //Should this really be empty?
179 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
180 dependsOnMethods = {"create", "testSubmitRequest"})
181 public void createWithEmptyEntityBody(String testName) throws Exception {
183 if (logger.isDebugEnabled()) {
184 logger.debug(testBanner(testName, CLASS_NAME));
187 setupCreateWithEmptyEntityBody();
189 // Submit the request to the service and store the response.
190 String method = REQUEST_TYPE.httpMethodName();
191 String url = getServiceRootURL();
192 String mediaType = MediaType.APPLICATION_XML;
193 final String entity = "";
194 int statusCode = submitRequest(method, url, mediaType, entity);
196 // Check the status code of the response: does it match
197 // the expected response(s)?
198 if(logger.isDebugEnabled()){
199 logger.debug("createWithEmptyEntityBody url=" + url +
200 " status=" + statusCode);
202 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
203 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
204 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
208 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
209 dependsOnMethods = {"create", "testSubmitRequest"})
210 public void createWithMalformedXml(String testName) throws Exception {
212 if (logger.isDebugEnabled()) {
213 logger.debug(testBanner(testName, CLASS_NAME));
216 setupCreateWithMalformedXml();
218 // Submit the request to the service and store the response.
219 String method = REQUEST_TYPE.httpMethodName();
220 String url = getServiceRootURL();
221 String mediaType = MediaType.APPLICATION_XML;
222 final String entity = MALFORMED_XML_DATA; // Constant from base class.
223 int statusCode = submitRequest(method, url, mediaType, entity);
225 // Check the status code of the response: does it match
226 // the expected response(s)?
227 if(logger.isDebugEnabled()){
228 logger.debug(testName + ": url=" + url +
229 " status=" + statusCode);
231 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
232 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
233 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
237 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
238 dependsOnMethods = {"create", "testSubmitRequest"})
239 public void createWithWrongXmlSchema(String testName) throws Exception {
241 if (logger.isDebugEnabled()) {
242 logger.debug(testBanner(testName, CLASS_NAME));
245 setupCreateWithWrongXmlSchema();
247 // Submit the request to the service and store the response.
248 String method = REQUEST_TYPE.httpMethodName();
249 String url = getServiceRootURL();
250 String mediaType = MediaType.APPLICATION_XML;
251 final String entity = WRONG_XML_SCHEMA_DATA;
252 int statusCode = submitRequest(method, url, mediaType, entity);
254 // Check the status code of the response: does it match
255 // the expected response(s)?
256 if(logger.isDebugEnabled()){
257 logger.debug(testName + ": url=" + url +
258 " status=" + statusCode);
260 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
261 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
262 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265 // ---------------------------------------------------------------
266 // CRUD tests : READ tests
267 // ---------------------------------------------------------------
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
273 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
274 // dependsOnMethods = {"create"})
275 public void read(String testName) throws Exception {
279 // Submit the request to the service and store the response.
280 LoanoutClient client = new LoanoutClient();
281 Response res = client.read(knownResourceId);
282 LoansoutCommon loanoutCommon = null;
284 assertStatusCode(res, testName);
285 // Get the common part of the response and verify that it is not null.
286 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
287 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
288 if (payloadInputPart != null) {
289 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
291 Assert.assertNotNull(loanoutCommon);
298 // Check selected fields in the common part.
299 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
301 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
302 Assert.assertNotNull(statusGroupList);
303 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
304 Assert.assertNotNull(statusGroups);
305 Assert.assertTrue(statusGroups.size() > 0);
306 LoanStatusGroup statusGroup = statusGroups.get(0);
307 Assert.assertNotNull(statusGroup);
308 Assert.assertNotNull(statusGroup.getLoanStatus());
310 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
311 if (logger.isDebugEnabled()) {
312 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
313 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
315 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
316 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
317 + "' does not match expected data '" + getUTF8DataFragment());
322 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
325 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
326 // dependsOnMethods = {"read"})
327 public void readNonExistent(String testName) throws Exception {
329 setupReadNonExistent();
331 // Submit the request to the service and store the response.
332 LoanoutClient client = new LoanoutClient();
333 Response res = client.read(NON_EXISTENT_ID);
335 int statusCode = res.getStatus();
337 // Check the status code of the response: does it match
338 // the expected response(s)?
339 if (logger.isDebugEnabled()) {
340 logger.debug(testName + ": status = " + statusCode);
342 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
343 invalidStatusCodeMessage(testRequestType, statusCode));
344 Assert.assertEquals(statusCode, testExpectedStatusCode);
350 // ---------------------------------------------------------------
351 // CRUD tests : READ_LIST tests
352 // ---------------------------------------------------------------
355 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
358 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
359 // dependsOnMethods = {"createList", "read"})
360 public void readList(String testName) throws Exception {
364 // Submit the request to the service and store the response.
365 LoanoutClient client = new LoanoutClient();
366 Response res = client.readList();
367 AbstractCommonList list = null;
369 assertStatusCode(res, testName);
370 list = res.readEntity(getCommonListType());
376 // Optionally output additional data about list members for debugging.
377 boolean iterateThroughList = true;
378 if (iterateThroughList && logger.isDebugEnabled()){
379 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
386 // ---------------------------------------------------------------
387 // CRUD tests : UPDATE tests
388 // ---------------------------------------------------------------
391 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
394 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
395 // dependsOnMethods = {"read"})
396 public void update(String testName) throws Exception {
400 // Retrieve the contents of a resource to update.
401 LoanoutClient client = new LoanoutClient();
402 Response res = client.read(knownResourceId);
403 LoansoutCommon loanoutCommon = null;
405 assertStatusCode(res, testName);
406 // Extract the common part from the response.
407 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
408 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
409 if (payloadInputPart != null) {
410 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
412 Assert.assertNotNull(loanoutCommon);
419 // Update the content of this resource.
420 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
421 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
422 Assert.assertNotNull(statusGroupList);
423 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
424 Assert.assertNotNull(statusGroups);
425 Assert.assertTrue(statusGroups.size() > 0);
426 LoanStatusGroup statusGroup = statusGroups.get(0);
427 Assert.assertNotNull(statusGroup);
428 String loanStatus = statusGroup.getLoanStatus();
429 Assert.assertNotNull(loanStatus);
430 String updatedLoanStatus = "updated-" + loanStatus;
431 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
432 loanoutCommon.setLoanStatusGroupList(statusGroupList);
433 if (logger.isDebugEnabled()) {
434 logger.debug("to be updated object");
435 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
437 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
441 // Submit the updated resource in an update request to the service and store the response.
442 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
443 PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon);
445 res = client.update(knownResourceId, output);
446 LoansoutCommon updatedLoanoutCommon = null;
448 assertStatusCode(res, testName);
449 // Extract the updated common part from the response.
450 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
451 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
452 if (payloadInputPart != null) {
453 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
455 Assert.assertNotNull(updatedLoanoutCommon);
462 // Check selected fields in the updated resource.
463 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
464 loanoutCommon.getLoanOutNumber(),
465 "Data in updated object did not match submitted data.");
467 LoanStatusGroupList updatedStatusGroupList =
468 updatedLoanoutCommon.getLoanStatusGroupList();
469 Assert.assertNotNull(updatedStatusGroupList);
470 List<LoanStatusGroup> updatedStatusGroups =
471 updatedStatusGroupList.getLoanStatusGroup();
472 Assert.assertNotNull(updatedStatusGroups);
473 Assert.assertTrue(updatedStatusGroups.size() > 0);
474 Assert.assertNotNull(updatedStatusGroups.get(0));
475 Assert.assertEquals(updatedLoanStatus,
476 updatedStatusGroups.get(0).getLoanStatus(),
477 "Data in updated object did not match submitted data.");
479 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
480 if (logger.isDebugEnabled()) {
481 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
482 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
484 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
485 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
486 + "' does not contain expected data '" + getUTF8DataFragment());
487 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
488 loanoutCommon.getLoanOutNote(),
489 "Data in updated object did not match submitted data.");
493 // Placeholders until the three tests below can be uncommented.
494 // See Issue CSPACE-401.
496 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
499 public void updateWithEmptyEntityBody(String testName) throws Exception {
500 //Should this really be empty?
504 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
507 public void updateWithMalformedXml(String testName) throws Exception {
508 //Should this really be empty?
512 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
515 public void updateWithWrongXmlSchema(String testName) throws Exception {
516 //Should this really be empty?
521 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
522 dependsOnMethods = {"create", "update", "testSubmitRequest"})
523 public void updateWithEmptyEntityBody(String testName) throws Exception {
525 if (logger.isDebugEnabled()) {
526 logger.debug(testBanner(testName, CLASS_NAME));
529 setupUpdateWithEmptyEntityBody();
531 // Submit the request to the service and store the response.
532 String method = REQUEST_TYPE.httpMethodName();
533 String url = getResourceURL(knownResourceId);
534 String mediaType = MediaType.APPLICATION_XML;
535 final String entity = "";
536 int statusCode = submitRequest(method, url, mediaType, entity);
538 // Check the status code of the response: does it match
539 // the expected response(s)?
540 if(logger.isDebugEnabled()){
541 logger.debug(testName + ": url=" + url +
542 " status=" + statusCode);
544 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
545 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
546 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
550 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
551 dependsOnMethods = {"create", "update", "testSubmitRequest"})
552 public void updateWithMalformedXml(String testName) throws Exception {
554 if (logger.isDebugEnabled()) {
555 logger.debug(testBanner(testName, CLASS_NAME));
558 setupUpdateWithMalformedXml();
560 // Submit the request to the service and store the response.
561 String method = REQUEST_TYPE.httpMethodName();
562 String url = getResourceURL(knownResourceId);
563 String mediaType = MediaType.APPLICATION_XML;
564 final String entity = MALFORMED_XML_DATA;
565 int statusCode = submitRequest(method, url, mediaType, entity);
567 // Check the status code of the response: does it match
568 // the expected response(s)?
569 if(logger.isDebugEnabled()){
570 logger.debug(testName + ": url=" + url +
571 " status=" + statusCode);
573 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
574 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
575 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
579 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
580 dependsOnMethods = {"create", "update", "testSubmitRequest"})
581 public void updateWithWrongXmlSchema(String testName) throws Exception {
583 if (logger.isDebugEnabled()) {
584 logger.debug(testBanner(testName, CLASS_NAME));
587 setupUpdateWithWrongXmlSchema();
589 // Submit the request to the service and store the response.
590 String method = REQUEST_TYPE.httpMethodName();
591 String url = getResourceURL(knownResourceId);
592 String mediaType = MediaType.APPLICATION_XML;
593 final String entity = WRONG_XML_SCHEMA_DATA;
594 int statusCode = submitRequest(method, url, mediaType, entity);
596 // Check the status code of the response: does it match
597 // the expected response(s)?
598 if(logger.isDebugEnabled()){
599 logger.debug(testName + ": url=" + url +
600 " status=" + statusCode);
602 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
609 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
612 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
613 // dependsOnMethods = {"update", "testSubmitRequest"})
614 public void updateNonExistent(String testName) throws Exception {
616 setupUpdateNonExistent();
618 // Submit the request to the service and store the response.
619 // Note: The ID used in this 'create' call may be arbitrary.
620 // The only relevant ID may be the one used in update(), below.
621 LoanoutClient client = new LoanoutClient();
622 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
623 Response res = client.update(NON_EXISTENT_ID, multipart);
625 int statusCode = res.getStatus();
627 // Check the status code of the response: does it match
628 // the expected response(s)?
629 if (logger.isDebugEnabled()) {
630 logger.debug(testName + ": status = " + statusCode);
632 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
633 invalidStatusCodeMessage(testRequestType, statusCode));
634 Assert.assertEquals(statusCode, testExpectedStatusCode);
640 // ---------------------------------------------------------------
641 // CRUD tests : DELETE tests
642 // ---------------------------------------------------------------
645 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
648 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
649 // dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
650 public void delete(String testName) throws Exception {
654 // Submit the request to the service and store the response.
655 LoanoutClient client = new LoanoutClient();
656 Response res = client.delete(knownResourceId);
658 int statusCode = res.getStatus();
660 // Check the status code of the response: does it match
661 // the expected response(s)?
662 if (logger.isDebugEnabled()) {
663 logger.debug(testName + ": status = " + statusCode);
665 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
666 invalidStatusCodeMessage(testRequestType, statusCode));
667 Assert.assertEquals(statusCode, testExpectedStatusCode);
675 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
678 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
679 // dependsOnMethods = {"delete"})
680 public void deleteNonExistent(String testName) throws Exception {
682 setupDeleteNonExistent();
684 // Submit the request to the service and store the response.
685 LoanoutClient client = new LoanoutClient();
686 Response res = client.delete(NON_EXISTENT_ID);
688 int statusCode = res.getStatus();
690 // Check the status code of the response: does it match
691 // the expected response(s)?
692 if (logger.isDebugEnabled()) {
693 logger.debug(testName + ": status = " + statusCode);
695 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(testRequestType, statusCode));
697 Assert.assertEquals(statusCode, testExpectedStatusCode);
703 // ---------------------------------------------------------------
704 // Utility tests : tests of code used in tests above
705 // ---------------------------------------------------------------
707 * Tests the code for manually submitting data that is used by several
708 * of the methods above.
710 // @Test(dependsOnMethods = {"create", "read"})
711 public void testSubmitRequest() {
713 // Expected status code: 200 OK
714 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
716 // Submit the request to the service and store the response.
717 String method = ServiceRequestType.READ.httpMethodName();
718 String url = getResourceURL(knownResourceId);
719 int statusCode = submitRequest(method, url);
721 // Check the status code of the response: does it match
722 // the expected response(s)?
723 if (logger.isDebugEnabled()) {
724 logger.debug("testSubmitRequest: url=" + url
725 + " status=" + statusCode);
727 Assert.assertEquals(statusCode, EXPECTED_STATUS);
731 // ---------------------------------------------------------------
732 // Utility methods used by tests above
733 // ---------------------------------------------------------------
735 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
738 public String getServicePathComponent() {
739 return LoanoutClient.SERVICE_PATH_COMPONENT;
743 protected PoxPayloadOut createInstance(String identifier) {
744 return createLoanoutInstance(identifier);
748 * Creates the loanout instance.
750 * @param identifier the identifier
751 * @return the multipart output
753 private PoxPayloadOut createLoanoutInstance(String identifier) {
754 return createLoanoutInstance(
755 "loanoutNumber-" + identifier,
760 * Creates the loanout instance.
762 * @param loanOutNumber the loan out number
763 * @param returnDate the return date
764 * @return the multipart output
766 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
768 LoansoutCommon loanoutCommon = new LoansoutCommon();
769 loanoutCommon.setLoanOutNumber(loanOutNumber);
770 loanoutCommon.setLoanReturnDate(returnDate);
771 loanoutCommon.setBorrower(
772 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
773 loanoutCommon.setBorrowersContact(
774 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
775 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
776 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
777 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
778 LoanStatusGroup statusGroup = new LoanStatusGroup();
779 statusGroup.setLoanStatus("returned");
780 statusGroup.setLoanStatusNote("Left under the front mat.");
781 statusGroups.add(statusGroup);
782 loanoutCommon.setLoanStatusGroupList(statusGroupList);
783 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
785 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
786 PayloadOutputPart commonPart =
787 multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon);
789 if (logger.isDebugEnabled()) {
790 logger.debug("to be created, loanout common");
791 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
792 // logger.debug(multipart.toXML());
799 protected String getServiceName() {
800 return LoanoutClient.SERVICE_NAME;
804 public void CRUDTests(String testName) {
805 // TODO Auto-generated method stub
810 protected PoxPayloadOut createInstance(String commonPartName,
812 PoxPayloadOut result = createLoanoutInstance(identifier);
817 protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) {
818 // TODO Auto-generated method stub
823 protected void compareUpdatedInstances(LoansoutCommon original,
824 LoansoutCommon updated) throws Exception {
825 // TODO Auto-generated method stub