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.CollectionSpaceClient;
30 import org.collectionspace.services.client.LoanoutClient;
31 import org.collectionspace.services.client.PayloadInputPart;
32 import org.collectionspace.services.client.PayloadOutputPart;
33 import org.collectionspace.services.client.PoxPayloadIn;
34 import org.collectionspace.services.client.PoxPayloadOut;
35 import org.collectionspace.services.common.AbstractCommonListUtils;
36 import org.collectionspace.services.common.datetime.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;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * LoanoutServiceTest, carries out tests against a
52 * deployed and running Loanout (aka Loans Out) Service.
54 * $LastChangedRevision$
57 public class LoanoutServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 /** The known resource id. */
63 private String knownResourceId = null;
64 private final static String CURRENT_DATE_UTC =
65 GregorianCalendarDateTimeUtils.currentDateUTC();
68 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71 protected CollectionSpaceClient getClientInstance() {
72 return new LoanoutClient();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getAbstractCommonList(
80 ClientResponse<AbstractCommonList> response) {
81 return response.getEntity(AbstractCommonList.class);
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
89 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
92 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
93 public void create(String testName) throws Exception {
95 if (logger.isDebugEnabled()) {
96 logger.debug(testBanner(testName, CLASS_NAME));
98 // Perform setup, such as initializing the type of service request
99 // (e.g. CREATE, DELETE), its valid and expected status codes, and
100 // its associated HTTP method name (e.g. POST, DELETE).
103 // Submit the request to the service and store the response.
104 LoanoutClient client = new LoanoutClient();
105 String identifier = createIdentifier();
106 PoxPayloadOut multipart = createLoanoutInstance(identifier);
107 ClientResponse<Response> res = client.create(multipart);
109 int statusCode = res.getStatus();
111 // Check the status code of the response: does it match
112 // the expected response(s)?
115 // Does it fall within the set of valid status codes?
116 // Does it exactly match the expected status code?
117 if (logger.isDebugEnabled()) {
118 logger.debug(testName + ": status = " + statusCode);
120 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
121 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
122 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
124 // Store the ID returned from the first resource created
125 // for additional tests below.
126 if (knownResourceId == null) {
127 knownResourceId = extractId(res);
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(extractId(res));
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 {
277 if (logger.isDebugEnabled()) {
278 logger.debug(testBanner(testName, CLASS_NAME));
283 // Submit the request to the service and store the response.
284 LoanoutClient client = new LoanoutClient();
285 ClientResponse<String> res = client.read(knownResourceId);
286 assertStatusCode(res, testName);
288 // Get the common part of the response and verify that it is not null.
289 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
290 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
291 LoansoutCommon loanoutCommon = null;
292 if (payloadInputPart != null) {
293 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
295 Assert.assertNotNull(loanoutCommon);
297 // Check selected fields in the common part.
298 Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
300 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
301 Assert.assertNotNull(statusGroupList);
302 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
303 Assert.assertNotNull(statusGroups);
304 Assert.assertTrue(statusGroups.size() > 0);
305 LoanStatusGroup statusGroup = statusGroups.get(0);
306 Assert.assertNotNull(statusGroup);
307 Assert.assertNotNull(statusGroup.getLoanStatus());
309 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
310 if (logger.isDebugEnabled()) {
311 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
312 + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
314 Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
315 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
316 + "' does not match expected data '" + getUTF8DataFragment());
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
324 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
325 dependsOnMethods = {"read"})
326 public void readNonExistent(String testName) throws Exception {
328 if (logger.isDebugEnabled()) {
329 logger.debug(testBanner(testName, CLASS_NAME));
332 setupReadNonExistent();
334 // Submit the request to the service and store the response.
335 LoanoutClient client = new LoanoutClient();
336 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
337 int statusCode = res.getStatus();
339 // Check the status code of the response: does it match
340 // the expected response(s)?
341 if (logger.isDebugEnabled()) {
342 logger.debug(testName + ": status = " + statusCode);
344 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
345 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
346 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
349 // ---------------------------------------------------------------
350 // CRUD tests : READ_LIST tests
351 // ---------------------------------------------------------------
354 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
357 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358 dependsOnMethods = {"createList", "read"})
359 public void readList(String testName) throws Exception {
361 if (logger.isDebugEnabled()) {
362 logger.debug(testBanner(testName, CLASS_NAME));
367 // Submit the request to the service and store the response.
368 LoanoutClient client = new LoanoutClient();
369 ClientResponse<AbstractCommonList> res = client.readList();
370 assertStatusCode(res, testName);
371 AbstractCommonList list = res.getEntity();
373 // Optionally output additional data about list members for debugging.
374 boolean iterateThroughList = true;
375 if(iterateThroughList && logger.isDebugEnabled()){
376 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
383 // ---------------------------------------------------------------
384 // CRUD tests : UPDATE tests
385 // ---------------------------------------------------------------
388 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
391 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
392 dependsOnMethods = {"read"})
393 public void update(String testName) throws Exception {
395 if (logger.isDebugEnabled()) {
396 logger.debug(testBanner(testName, CLASS_NAME));
401 // Retrieve the contents of a resource to update.
402 LoanoutClient client = new LoanoutClient();
403 ClientResponse<String> res = client.read(knownResourceId);
404 assertStatusCode(res, testName);
406 // Extract the common part from the response.
407 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
408 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
409 LoansoutCommon loanoutCommon = null;
410 if (payloadInputPart != null) {
411 loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
413 Assert.assertNotNull(loanoutCommon);
415 // Update the content of this resource.
416 loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
417 LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
418 Assert.assertNotNull(statusGroupList);
419 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
420 Assert.assertNotNull(statusGroups);
421 Assert.assertTrue(statusGroups.size() > 0);
422 LoanStatusGroup statusGroup = statusGroups.get(0);
423 Assert.assertNotNull(statusGroup);
424 String loanStatus = statusGroup.getLoanStatus();
425 Assert.assertNotNull(loanStatus);
426 String updatedLoanStatus = "updated-" + loanStatus;
427 statusGroups.get(0).setLoanStatus(updatedLoanStatus);
428 loanoutCommon.setLoanStatusGroupList(statusGroupList);
429 if (logger.isDebugEnabled()) {
430 logger.debug("to be updated object");
431 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
433 loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
435 // Submit the updated resource in an update request to the service and store the response.
436 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
437 PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
438 commonPart.setLabel(client.getCommonPartName());
439 res = client.update(knownResourceId, output);
440 assertStatusCode(res, testName);
442 // Extract the updated common part from the response.
443 input = new PoxPayloadIn(res.getEntity());
444 payloadInputPart = input.getPart(client.getCommonPartName());
445 LoansoutCommon updatedLoanoutCommon = null;
446 if (payloadInputPart != null) {
447 updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
449 Assert.assertNotNull(updatedLoanoutCommon);
451 // Check selected fields in the updated resource.
452 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
453 loanoutCommon.getLoanOutNumber(),
454 "Data in updated object did not match submitted data.");
456 LoanStatusGroupList updatedStatusGroupList =
457 updatedLoanoutCommon.getLoanStatusGroupList();
458 Assert.assertNotNull(updatedStatusGroupList);
459 List<LoanStatusGroup> updatedStatusGroups =
460 updatedStatusGroupList.getLoanStatusGroup();
461 Assert.assertNotNull(updatedStatusGroups);
462 Assert.assertTrue(updatedStatusGroups.size() > 0);
463 Assert.assertNotNull(updatedStatusGroups.get(0));
464 Assert.assertEquals(updatedLoanStatus,
465 updatedStatusGroups.get(0).getLoanStatus(),
466 "Data in updated object did not match submitted data.");
468 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
469 if (logger.isDebugEnabled()) {
470 logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
471 + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
473 Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
474 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
475 + "' does not contain expected data '" + getUTF8DataFragment());
476 Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
477 loanoutCommon.getLoanOutNote(),
478 "Data in updated object did not match submitted data.");
482 // Placeholders until the three tests below can be uncommented.
483 // See Issue CSPACE-401.
485 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
488 public void updateWithEmptyEntityBody(String testName) throws Exception {
489 //Should this really be empty?
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
496 public void updateWithMalformedXml(String testName) throws Exception {
497 //Should this really be empty?
501 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
504 public void updateWithWrongXmlSchema(String testName) throws Exception {
505 //Should this really be empty?
510 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
511 dependsOnMethods = {"create", "update", "testSubmitRequest"})
512 public void updateWithEmptyEntityBody(String testName) throws Exception {
514 if (logger.isDebugEnabled()) {
515 logger.debug(testBanner(testName, CLASS_NAME));
518 setupUpdateWithEmptyEntityBody();
520 // Submit the request to the service and store the response.
521 String method = REQUEST_TYPE.httpMethodName();
522 String url = getResourceURL(knownResourceId);
523 String mediaType = MediaType.APPLICATION_XML;
524 final String entity = "";
525 int statusCode = submitRequest(method, url, mediaType, entity);
527 // Check the status code of the response: does it match
528 // the expected response(s)?
529 if(logger.isDebugEnabled()){
530 logger.debug(testName + ": url=" + url +
531 " status=" + statusCode);
533 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
539 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
540 dependsOnMethods = {"create", "update", "testSubmitRequest"})
541 public void updateWithMalformedXml(String testName) throws Exception {
543 if (logger.isDebugEnabled()) {
544 logger.debug(testBanner(testName, CLASS_NAME));
547 setupUpdateWithMalformedXml();
549 // Submit the request to the service and store the response.
550 String method = REQUEST_TYPE.httpMethodName();
551 String url = getResourceURL(knownResourceId);
552 String mediaType = MediaType.APPLICATION_XML;
553 final String entity = MALFORMED_XML_DATA;
554 int statusCode = submitRequest(method, url, mediaType, entity);
556 // Check the status code of the response: does it match
557 // the expected response(s)?
558 if(logger.isDebugEnabled()){
559 logger.debug(testName + ": url=" + url +
560 " status=" + statusCode);
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
568 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569 dependsOnMethods = {"create", "update", "testSubmitRequest"})
570 public void updateWithWrongXmlSchema(String testName) throws Exception {
572 if (logger.isDebugEnabled()) {
573 logger.debug(testBanner(testName, CLASS_NAME));
576 setupUpdateWithWrongXmlSchema();
578 // Submit the request to the service and store the response.
579 String method = REQUEST_TYPE.httpMethodName();
580 String url = getResourceURL(knownResourceId);
581 String mediaType = MediaType.APPLICATION_XML;
582 final String entity = WRONG_XML_SCHEMA_DATA;
583 int statusCode = submitRequest(method, url, mediaType, entity);
585 // Check the status code of the response: does it match
586 // the expected response(s)?
587 if(logger.isDebugEnabled()){
588 logger.debug(testName + ": url=" + url +
589 " status=" + statusCode);
591 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
598 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
601 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
602 dependsOnMethods = {"update", "testSubmitRequest"})
603 public void updateNonExistent(String testName) throws Exception {
605 if (logger.isDebugEnabled()) {
606 logger.debug(testBanner(testName, CLASS_NAME));
609 setupUpdateNonExistent();
611 // Submit the request to the service and store the response.
612 // Note: The ID used in this 'create' call may be arbitrary.
613 // The only relevant ID may be the one used in update(), below.
614 LoanoutClient client = new LoanoutClient();
615 PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
616 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
617 int statusCode = res.getStatus();
619 // Check the status code of the response: does it match
620 // the expected response(s)?
621 if (logger.isDebugEnabled()) {
622 logger.debug(testName + ": status = " + statusCode);
624 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
625 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
626 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629 // ---------------------------------------------------------------
630 // CRUD tests : DELETE tests
631 // ---------------------------------------------------------------
634 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
637 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
638 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
639 public void delete(String testName) throws Exception {
641 if (logger.isDebugEnabled()) {
642 logger.debug(testBanner(testName, CLASS_NAME));
647 // Submit the request to the service and store the response.
648 LoanoutClient client = new LoanoutClient();
649 ClientResponse<Response> res = client.delete(knownResourceId);
650 int statusCode = res.getStatus();
652 // Check the status code of the response: does it match
653 // the expected response(s)?
654 if (logger.isDebugEnabled()) {
655 logger.debug(testName + ": status = " + statusCode);
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
664 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
667 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
668 dependsOnMethods = {"delete"})
669 public void deleteNonExistent(String testName) throws Exception {
671 if (logger.isDebugEnabled()) {
672 logger.debug(testBanner(testName, CLASS_NAME));
675 setupDeleteNonExistent();
677 // Submit the request to the service and store the response.
678 LoanoutClient client = new LoanoutClient();
679 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
680 int statusCode = res.getStatus();
682 // Check the status code of the response: does it match
683 // the expected response(s)?
684 if (logger.isDebugEnabled()) {
685 logger.debug(testName + ": status = " + statusCode);
687 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 // ---------------------------------------------------------------
693 // Utility tests : tests of code used in tests above
694 // ---------------------------------------------------------------
696 * Tests the code for manually submitting data that is used by several
697 * of the methods above.
699 @Test(dependsOnMethods = {"create", "read"})
700 public void testSubmitRequest() {
702 // Expected status code: 200 OK
703 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
705 // Submit the request to the service and store the response.
706 String method = ServiceRequestType.READ.httpMethodName();
707 String url = getResourceURL(knownResourceId);
708 int statusCode = submitRequest(method, url);
710 // Check the status code of the response: does it match
711 // the expected response(s)?
712 if (logger.isDebugEnabled()) {
713 logger.debug("testSubmitRequest: url=" + url
714 + " status=" + statusCode);
716 Assert.assertEquals(statusCode, EXPECTED_STATUS);
720 // ---------------------------------------------------------------
721 // Utility methods used by tests above
722 // ---------------------------------------------------------------
724 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
727 public String getServicePathComponent() {
728 return LoanoutClient.SERVICE_PATH_COMPONENT;
732 protected PoxPayloadOut createInstance(String identifier) {
733 return createLoanoutInstance(identifier);
737 * Creates the loanout instance.
739 * @param identifier the identifier
740 * @return the multipart output
742 private PoxPayloadOut createLoanoutInstance(String identifier) {
743 return createLoanoutInstance(
744 "loanoutNumber-" + identifier,
749 * Creates the loanout instance.
751 * @param loanOutNumber the loan out number
752 * @param returnDate the return date
753 * @return the multipart output
755 private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
757 LoansoutCommon loanoutCommon = new LoansoutCommon();
758 loanoutCommon.setLoanOutNumber(loanOutNumber);
759 loanoutCommon.setLoanReturnDate(returnDate);
760 loanoutCommon.setBorrower(
761 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
762 loanoutCommon.setBorrowersContact(
763 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
764 loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
765 LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
766 List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
767 LoanStatusGroup statusGroup = new LoanStatusGroup();
768 statusGroup.setLoanStatus("returned");
769 statusGroup.setLoanStatusNote("Left under the front mat.");
770 statusGroups.add(statusGroup);
771 loanoutCommon.setLoanStatusGroupList(statusGroupList);
772 loanoutCommon.setLoanOutNote(getUTF8DataFragment()); // For UTF-8 tests
774 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
775 PayloadOutputPart commonPart =
776 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
777 commonPart.setLabel(new LoanoutClient().getCommonPartName());
779 if (logger.isDebugEnabled()) {
780 logger.debug("to be created, loanout common");
781 logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
782 // logger.debug(multipart.toXML());
789 protected String getServiceName() {
790 return LoanoutClient.SERVICE_NAME;