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.jaxb.AbstractCommonList;
32 import org.collectionspace.services.loanout.LoanedObjectStatusGroup;
33 import org.collectionspace.services.loanout.LoanedObjectStatusGroupList;
34 import org.collectionspace.services.loanout.LoansoutCommon;
35 import org.collectionspace.services.loanout.LoansoutCommonList;
37 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.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * LoanoutServiceTest, carries out tests against a
50 * deployed and running Loanout (aka Loans Out) Service.
52 * $LastChangedRevision$
55 public class LoanoutServiceTest extends AbstractServiceTestImpl {
58 private final String CLASS_NAME = LoanoutServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 // Instance variables specific to this test.
62 /** The service path component. */
63 final String SERVICE_PATH_COMPONENT = "loansout";
65 /** The known resource id. */
66 private String knownResourceId = null;
69 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
72 protected CollectionSpaceClient getClientInstance() {
73 return new LoanoutClient();
77 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
80 protected AbstractCommonList getAbstractCommonList(
81 ClientResponse<AbstractCommonList> response) {
82 return response.getEntity(LoansoutCommonList.class);
85 // ---------------------------------------------------------------
86 // CRUD tests : CREATE tests
87 // ---------------------------------------------------------------
90 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
93 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
94 public void create(String testName) throws Exception {
96 if (logger.isDebugEnabled()) {
97 logger.debug(testBanner(testName, CLASS_NAME));
99 // Perform setup, such as initializing the type of service request
100 // (e.g. CREATE, DELETE), its valid and expected status codes, and
101 // its associated HTTP method name (e.g. POST, DELETE).
104 // Submit the request to the service and store the response.
105 LoanoutClient client = new LoanoutClient();
106 String identifier = createIdentifier();
107 MultipartOutput multipart = createLoanoutInstance(identifier);
108 ClientResponse<Response> res = client.create(multipart);
110 int statusCode = res.getStatus();
112 // Check the status code of the response: does it match
113 // the expected response(s)?
116 // Does it fall within the set of valid status codes?
117 // Does it exactly match the expected status code?
118 if(logger.isDebugEnabled()){
119 logger.debug(testName + ": status = " + statusCode);
121 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
122 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
123 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
125 // Store the ID returned from the first resource created
126 // for additional tests below.
127 if (knownResourceId == null){
128 knownResourceId = extractId(res);
129 if (logger.isDebugEnabled()) {
130 logger.debug(testName + ": knownResourceId=" + knownResourceId);
134 // Store the IDs from every resource created by tests,
135 // so they can be deleted after tests have been run.
136 allResourceIdsCreated.add(extractId(res));
140 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
143 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
144 dependsOnMethods = {"create"})
145 public void createList(String testName) throws Exception {
146 for(int i = 0; i < 3; i++){
152 // Placeholders until the three tests below can be uncommented.
153 // See Issue CSPACE-401.
155 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
158 public void createWithEmptyEntityBody(String testName) throws Exception {
159 //Should this really be empty?
163 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
166 public void createWithMalformedXml(String testName) throws Exception {
167 //Should this really be empty?
171 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
174 public void createWithWrongXmlSchema(String testName) throws Exception {
175 //Should this really be empty?
180 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
181 dependsOnMethods = {"create", "testSubmitRequest"})
182 public void createWithEmptyEntityBody(String testName) throws Exception {
184 if (logger.isDebugEnabled()) {
185 logger.debug(testBanner(testName, CLASS_NAME));
188 setupCreateWithEmptyEntityBody();
190 // Submit the request to the service and store the response.
191 String method = REQUEST_TYPE.httpMethodName();
192 String url = getServiceRootURL();
193 String mediaType = MediaType.APPLICATION_XML;
194 final String entity = "";
195 int statusCode = submitRequest(method, url, mediaType, entity);
197 // Check the status code of the response: does it match
198 // the expected response(s)?
199 if(logger.isDebugEnabled()){
200 logger.debug("createWithEmptyEntityBody url=" + url +
201 " status=" + statusCode);
203 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
204 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
205 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
210 dependsOnMethods = {"create", "testSubmitRequest"})
211 public void createWithMalformedXml(String testName) throws Exception {
213 if (logger.isDebugEnabled()) {
214 logger.debug(testBanner(testName, CLASS_NAME));
217 setupCreateWithMalformedXml();
219 // Submit the request to the service and store the response.
220 String method = REQUEST_TYPE.httpMethodName();
221 String url = getServiceRootURL();
222 String mediaType = MediaType.APPLICATION_XML;
223 final String entity = MALFORMED_XML_DATA; // Constant from base class.
224 int statusCode = submitRequest(method, url, mediaType, entity);
226 // Check the status code of the response: does it match
227 // the expected response(s)?
228 if(logger.isDebugEnabled()){
229 logger.debug(testName + ": url=" + url +
230 " status=" + statusCode);
232 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
233 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
234 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
238 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
239 dependsOnMethods = {"create", "testSubmitRequest"})
240 public void createWithWrongXmlSchema(String testName) throws Exception {
242 if (logger.isDebugEnabled()) {
243 logger.debug(testBanner(testName, CLASS_NAME));
246 setupCreateWithWrongXmlSchema();
248 // Submit the request to the service and store the response.
249 String method = REQUEST_TYPE.httpMethodName();
250 String url = getServiceRootURL();
251 String mediaType = MediaType.APPLICATION_XML;
252 final String entity = WRONG_XML_SCHEMA_DATA;
253 int statusCode = submitRequest(method, url, mediaType, entity);
255 // Check the status code of the response: does it match
256 // the expected response(s)?
257 if(logger.isDebugEnabled()){
258 logger.debug(testName + ": url=" + url +
259 " status=" + statusCode);
261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
263 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
267 // ---------------------------------------------------------------
268 // CRUD tests : READ tests
269 // ---------------------------------------------------------------
272 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
275 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
276 dependsOnMethods = {"create"})
277 public void read(String testName) throws Exception {
279 if (logger.isDebugEnabled()) {
280 logger.debug(testBanner(testName, CLASS_NAME));
285 // Submit the request to the service and store the response.
286 LoanoutClient client = new LoanoutClient();
287 ClientResponse<MultipartInput> res = client.read(knownResourceId);
288 int statusCode = res.getStatus();
290 // Check the status code of the response: does it match
291 // the expected response(s)?
292 if(logger.isDebugEnabled()){
293 logger.debug(testName + ": status = " + statusCode);
295 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
296 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
297 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
299 MultipartInput input = (MultipartInput) res.getEntity();
300 LoansoutCommon loanout = (LoansoutCommon) extractPart(input,
301 client.getCommonPartName(), LoansoutCommon.class);
302 Assert.assertNotNull(loanout);
303 Assert.assertNotNull(loanout.getLoanOutNumber());
304 LoanedObjectStatusGroupList statusGroupList = loanout.getLoanedObjectStatusGroupList();
305 Assert.assertNotNull(statusGroupList);
306 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
307 Assert.assertNotNull(statusGroups);
308 Assert.assertTrue(statusGroups.size() > 0);
309 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
310 Assert.assertNotNull(statusGroup);
311 Assert.assertNotNull(statusGroup.getLoanedObjectStatus());
316 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
319 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
320 dependsOnMethods = {"read"})
321 public void readNonExistent(String testName) throws Exception {
323 if (logger.isDebugEnabled()) {
324 logger.debug(testBanner(testName, CLASS_NAME));
327 setupReadNonExistent();
329 // Submit the request to the service and store the response.
330 LoanoutClient client = new LoanoutClient();
331 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
332 int statusCode = res.getStatus();
334 // Check the status code of the response: does it match
335 // the expected response(s)?
336 if(logger.isDebugEnabled()){
337 logger.debug(testName + ": status = " + statusCode);
339 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
340 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
341 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
344 // ---------------------------------------------------------------
345 // CRUD tests : READ_LIST tests
346 // ---------------------------------------------------------------
349 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
352 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
353 dependsOnMethods = {"createList", "read"})
354 public void readList(String testName) throws Exception {
356 if (logger.isDebugEnabled()) {
357 logger.debug(testBanner(testName, CLASS_NAME));
362 // Submit the request to the service and store the response.
363 LoanoutClient client = new LoanoutClient();
364 ClientResponse<LoansoutCommonList> res = client.readList();
365 LoansoutCommonList list = res.getEntity();
366 int statusCode = res.getStatus();
368 // Check the status code of the response: does it match
369 // the expected response(s)?
370 if(logger.isDebugEnabled()){
371 logger.debug(testName + ": status = " + statusCode);
373 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
374 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
375 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
377 // Optionally output additional data about list members for debugging.
378 boolean iterateThroughList = false;
379 if(iterateThroughList && logger.isDebugEnabled()){
380 List<LoansoutCommonList.LoanoutListItem> items =
381 list.getLoanoutListItem();
383 for(LoansoutCommonList.LoanoutListItem item : items){
384 logger.debug(testName + ": list-item[" + i + "] csid=" +
386 logger.debug(testName + ": list-item[" + i + "] loanOutNumber=" +
387 item.getLoanOutNumber());
388 logger.debug(testName + ": list-item[" + i + "] URI=" +
398 // ---------------------------------------------------------------
399 // CRUD tests : UPDATE tests
400 // ---------------------------------------------------------------
403 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
406 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
407 dependsOnMethods = {"read"})
408 public void update(String testName) throws Exception {
410 if (logger.isDebugEnabled()) {
411 logger.debug(testBanner(testName, CLASS_NAME));
416 // Retrieve the contents of a resource to update.
417 LoanoutClient client = new LoanoutClient();
418 ClientResponse<MultipartInput> res =
419 client.read(knownResourceId);
420 if(logger.isDebugEnabled()){
421 logger.debug(testName + ": read status = " + res.getStatus());
423 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
425 if(logger.isDebugEnabled()){
426 logger.debug("got object to update with ID: " + knownResourceId);
428 MultipartInput input = (MultipartInput) res.getEntity();
429 LoansoutCommon loanout = (LoansoutCommon) extractPart(input,
430 client.getCommonPartName(), LoansoutCommon.class);
431 Assert.assertNotNull(loanout);
433 // Update the content of this resource.
434 loanout.setLoanOutNumber("updated-" + loanout.getLoanOutNumber());
435 loanout.setLoanReturnDate("updated-" + loanout.getLoanReturnDate());
436 if(logger.isDebugEnabled()){
437 logger.debug("to be updated object");
438 logger.debug(objectAsXmlString(loanout, LoansoutCommon.class));
440 LoanedObjectStatusGroupList statusGroupList = loanout.getLoanedObjectStatusGroupList();
441 Assert.assertNotNull(statusGroupList);
442 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
443 Assert.assertNotNull(statusGroups);
444 Assert.assertTrue(statusGroups.size() > 0);
445 LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
446 Assert.assertNotNull(statusGroup);
447 String loanedObjectStatus = statusGroup.getLoanedObjectStatus();
448 Assert.assertNotNull(loanedObjectStatus);
449 String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus;
450 statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus);
451 loanout.setLoanedObjectStatusGroupList(statusGroupList);
453 // Submit the request to the service and store the response.
454 MultipartOutput output = new MultipartOutput();
455 OutputPart commonPart = output.addPart(loanout, MediaType.APPLICATION_XML_TYPE);
456 commonPart.getHeaders().add("label", client.getCommonPartName());
458 res = client.update(knownResourceId, output);
459 int statusCode = res.getStatus();
460 // Check the status code of the response: does it match the expected response(s)?
461 if(logger.isDebugEnabled()){
462 logger.debug(testName + ": status = " + statusCode);
464 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
465 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
466 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
469 input = (MultipartInput) res.getEntity();
470 LoansoutCommon updatedLoanout =
471 (LoansoutCommon) extractPart(input,
472 client.getCommonPartName(), LoansoutCommon.class);
473 Assert.assertNotNull(updatedLoanout);
475 Assert.assertEquals(updatedLoanout.getLoanReturnDate(),
476 loanout.getLoanReturnDate(),
477 "Data in updated object did not match submitted data.");
479 statusGroupList = updatedLoanout.getLoanedObjectStatusGroupList();
480 Assert.assertNotNull(statusGroupList);
481 statusGroups = statusGroupList.getLoanedObjectStatusGroup();
482 Assert.assertNotNull(statusGroups);
483 Assert.assertTrue(statusGroups.size() > 0);
484 Assert.assertNotNull(statusGroups.get(0));
485 Assert.assertEquals(updatedLoanedObjectStatus,
486 statusGroups.get(0).getLoanedObjectStatus(),
487 "Data in updated object did not match submitted data.");
492 // Placeholders until the three tests below can be uncommented.
493 // See Issue CSPACE-401.
495 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
498 public void updateWithEmptyEntityBody(String testName) throws Exception{
499 //Should this really be empty?
503 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
506 public void updateWithMalformedXml(String testName) throws Exception {
507 //Should this really be empty?
511 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
514 public void updateWithWrongXmlSchema(String testName) throws Exception {
515 //Should this really be empty?
520 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
521 dependsOnMethods = {"create", "update", "testSubmitRequest"})
522 public void updateWithEmptyEntityBody(String testName) throws Exception {
524 if (logger.isDebugEnabled()) {
525 logger.debug(testBanner(testName, CLASS_NAME));
528 setupUpdateWithEmptyEntityBody();
530 // Submit the request to the service and store the response.
531 String method = REQUEST_TYPE.httpMethodName();
532 String url = getResourceURL(knownResourceId);
533 String mediaType = MediaType.APPLICATION_XML;
534 final String entity = "";
535 int statusCode = submitRequest(method, url, mediaType, entity);
537 // Check the status code of the response: does it match
538 // the expected response(s)?
539 if(logger.isDebugEnabled()){
540 logger.debug(testName + ": url=" + url +
541 " status=" + statusCode);
543 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
550 dependsOnMethods = {"create", "update", "testSubmitRequest"})
551 public void updateWithMalformedXml(String testName) throws Exception {
553 if (logger.isDebugEnabled()) {
554 logger.debug(testBanner(testName, CLASS_NAME));
557 setupUpdateWithMalformedXml();
559 // Submit the request to the service and store the response.
560 String method = REQUEST_TYPE.httpMethodName();
561 String url = getResourceURL(knownResourceId);
562 String mediaType = MediaType.APPLICATION_XML;
563 final String entity = MALFORMED_XML_DATA;
564 int statusCode = submitRequest(method, url, mediaType, entity);
566 // Check the status code of the response: does it match
567 // the expected response(s)?
568 if(logger.isDebugEnabled()){
569 logger.debug(testName + ": url=" + url +
570 " status=" + statusCode);
572 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
573 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
574 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
579 dependsOnMethods = {"create", "update", "testSubmitRequest"})
580 public void updateWithWrongXmlSchema(String testName) throws Exception {
582 if (logger.isDebugEnabled()) {
583 logger.debug(testBanner(testName, CLASS_NAME));
586 setupUpdateWithWrongXmlSchema();
588 // Submit the request to the service and store the response.
589 String method = REQUEST_TYPE.httpMethodName();
590 String url = getResourceURL(knownResourceId);
591 String mediaType = MediaType.APPLICATION_XML;
592 final String entity = WRONG_XML_SCHEMA_DATA;
593 int statusCode = submitRequest(method, url, mediaType, entity);
595 // Check the status code of the response: does it match
596 // the expected response(s)?
597 if(logger.isDebugEnabled()){
598 logger.debug(testName + ": url=" + url +
599 " status=" + statusCode);
601 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
602 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
603 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
608 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
611 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
612 dependsOnMethods = {"update", "testSubmitRequest"})
613 public void updateNonExistent(String testName) throws Exception {
615 if (logger.isDebugEnabled()) {
616 logger.debug(testBanner(testName, CLASS_NAME));
619 setupUpdateNonExistent();
621 // Submit the request to the service and store the response.
622 // Note: The ID used in this 'create' call may be arbitrary.
623 // The only relevant ID may be the one used in update(), below.
624 LoanoutClient client = new LoanoutClient();
625 MultipartOutput multipart = createLoanoutInstance(NON_EXISTENT_ID);
626 ClientResponse<MultipartInput> res =
627 client.update(NON_EXISTENT_ID, multipart);
628 int statusCode = res.getStatus();
630 // Check the status code of the response: does it match
631 // the expected response(s)?
632 if(logger.isDebugEnabled()){
633 logger.debug(testName + ": status = " + statusCode);
635 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
636 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
637 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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 {
652 if (logger.isDebugEnabled()) {
653 logger.debug(testBanner(testName, CLASS_NAME));
658 // Submit the request to the service and store the response.
659 LoanoutClient client = new LoanoutClient();
660 ClientResponse<Response> res = client.delete(knownResourceId);
661 int statusCode = res.getStatus();
663 // Check the status code of the response: does it match
664 // the expected response(s)?
665 if(logger.isDebugEnabled()){
666 logger.debug(testName + ": status = " + statusCode);
668 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
669 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
670 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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 if (logger.isDebugEnabled()) {
683 logger.debug(testBanner(testName, CLASS_NAME));
686 setupDeleteNonExistent();
688 // Submit the request to the service and store the response.
689 LoanoutClient client = new LoanoutClient();
690 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
691 int statusCode = res.getStatus();
693 // Check the status code of the response: does it match
694 // the expected response(s)?
695 if(logger.isDebugEnabled()){
696 logger.debug(testName + ": status = " + statusCode);
698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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 SERVICE_PATH_COMPONENT;
743 * Creates the loanout instance.
745 * @param identifier the identifier
746 * @return the multipart output
748 private MultipartOutput createLoanoutInstance(String identifier) {
749 return createLoanoutInstance(
750 "loanoutNumber-" + identifier,
751 "returnDate-" + identifier);
755 * Creates the loanout instance.
757 * @param loanOutNumber the loan out number
758 * @param returnDate the return date
759 * @return the multipart output
761 private MultipartOutput createLoanoutInstance(String loanOutNumber,
763 LoansoutCommon loanout = new LoansoutCommon();
764 loanout.setLoanOutNumber(loanOutNumber);
765 loanout.setLoanReturnDate(returnDate);
767 "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
768 loanout.setBorrowersContact(
769 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
770 loanout.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
771 LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList();
772 List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
773 LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup();
774 statusGroup.setLoanedObjectStatus("returned");
775 statusGroup.setLoanedObjectStatusNote("Left under the front mat.");
776 statusGroups.add(statusGroup);
777 loanout.setLoanedObjectStatusGroupList(statusGroupList);
778 MultipartOutput multipart = new MultipartOutput();
779 OutputPart commonPart =
780 multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE);
781 commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName());
783 if(logger.isDebugEnabled()){
784 logger.debug("to be created, loanout common");
785 logger.debug(objectAsXmlString(loanout, LoansoutCommon.class));