]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
673b14f47edd5ced955972d46da88ee06a78f12d
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29
30 import org.collectionspace.services.client.CollectionSpaceClient;
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.client.ReportClient;
36 import org.collectionspace.services.report.ReportsCommon;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38
39 import org.jboss.resteasy.client.ClientResponse;
40 import org.testng.Assert;
41 //import org.testng.annotations.AfterClass;
42 import org.testng.annotations.Test;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
49  * ReportServiceTest, carries out tests against a
50  * deployed and running Report Service.
51  *
52  * $LastChangedRevision: 2261 $
53  * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $
54  */
55 public class ReportServiceTest extends AbstractServiceTestImpl {
56
57     /** The logger. */
58     private final String CLASS_NAME = ReportServiceTest.class.getName();
59     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60     final String SERVICE_NAME = "reports";
61     final String SERVICE_PATH_COMPONENT = "reports";
62     // Instance variables specific to this test.
63     /** The known resource id. */
64     private String knownResourceId = null;
65     
66     private String testDocType = "Acquisition";
67
68     /* (non-Javadoc)
69      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
70      */
71     @Override
72     protected CollectionSpaceClient getClientInstance() {
73         return new ReportClient();
74     }
75
76 //    @Override
77 //    protected PoxPayloadOut createInstance(String identifier) {
78 //        PoxPayloadOut multipart = createReportInstance(identifier);
79 //        return multipart;
80 //    }
81         
82     // ---------------------------------------------------------------
83     // CRUD tests : CREATE tests
84     // ---------------------------------------------------------------
85     // Success outcomes
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
88      */
89     @Override
90     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
91     public void create(String testName) throws Exception {
92
93         if (logger.isDebugEnabled()) {
94             logger.debug(testBanner(testName, CLASS_NAME));
95         }
96         // Perform setup, such as initializing the type of service request
97         // (e.g. CREATE, DELETE), its valid and expected status codes, and
98         // its associated HTTP method name (e.g. POST, DELETE).
99         setupCreate();
100
101         // Submit the request to the service and store the response.
102         ReportClient client = new ReportClient();
103         String identifier = createIdentifier();
104         PoxPayloadOut multipart = createReportInstance(identifier);
105         ClientResponse<Response> res = client.create(multipart);
106
107         // Check the status code of the response: does it match
108         // the expected response(s)?
109         //
110         // Specifically:
111         // Does it fall within the set of valid status codes?
112         // Does it exactly match the expected status code?
113         int statusCode = res.getStatus();
114         if (logger.isDebugEnabled()) {
115             logger.debug(testName + ": status = " + statusCode);
116         }
117         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
118                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
119         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
120
121         // Store the ID returned from the first resource created
122         // for additional tests below.
123         if (knownResourceId == null) {
124             knownResourceId = extractId(res);
125             if (logger.isDebugEnabled()) {
126                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
127             }
128         }
129
130         // Store the IDs from every resource created by tests,
131         // so they can be deleted after tests have been run.
132         allResourceIdsCreated.add(extractId(res));
133     }
134
135     /* (non-Javadoc)
136      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
137      */
138     @Override
139     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
140     dependsOnMethods = {"create"})
141     public void createList(String testName) throws Exception {
142         for (int i = 0; i < 3; i++) {
143             create(testName);
144         }
145     }
146
147     // Failure outcomes
148     // Placeholders until the three tests below can be uncommented.
149     // See Issue CSPACE-401.
150     /* (non-Javadoc)
151      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
152      */
153     @Override
154     public void createWithEmptyEntityBody(String testName) throws Exception {
155         //Should this really be empty?
156     }
157
158     /* (non-Javadoc)
159      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
160      */
161     @Override
162     public void createWithMalformedXml(String testName) throws Exception {
163         //Should this really be empty?
164     }
165
166     /* (non-Javadoc)
167      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
168      */
169     @Override
170     public void createWithWrongXmlSchema(String testName) throws Exception {
171         //Should this really be empty?
172     }
173
174     // ---------------------------------------------------------------
175     // CRUD tests : READ tests
176     // ---------------------------------------------------------------
177     // Success outcomes
178     /* (non-Javadoc)
179      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
180      */
181     @Override
182     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
183     dependsOnMethods = {"create"})
184     public void read(String testName) throws Exception {
185
186         if (logger.isDebugEnabled()) {
187             logger.debug(testBanner(testName, CLASS_NAME));
188         }
189         // Perform setup.
190         setupRead();
191
192         // Submit the request to the service and store the response.
193         ReportClient client = new ReportClient();
194         ClientResponse<String> res = client.read(knownResourceId);
195
196         // Check the status code of the response: does it match
197         // the expected response(s)?
198         int statusCode = res.getStatus();
199         if (logger.isDebugEnabled()) {
200             logger.debug(testName + ": status = " + statusCode);
201         }
202         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
203                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
204         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
205
206         // Get the common part of the response and verify that it is not null.
207         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
208         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
209         ReportsCommon reportCommon = null;
210         if (payloadInputPart != null) {
211             reportCommon = (ReportsCommon) payloadInputPart.getBody();
212         }
213         Assert.assertNotNull(reportCommon);
214
215         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
216         if (logger.isDebugEnabled()) {
217             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
218                     + "UTF-8 data received=" + reportCommon.getNotes());
219         }
220         Assert.assertEquals(reportCommon.getNotes(), getUTF8DataFragment(),
221                 "UTF-8 data retrieved '" + reportCommon.getNotes()
222                 + "' does not match expected data '" + getUTF8DataFragment());
223     }
224
225     // Failure outcomes
226     /* (non-Javadoc)
227      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
228      */
229     @Override
230     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
231     dependsOnMethods = {"read"})
232     public void readNonExistent(String testName) throws Exception {
233
234         if (logger.isDebugEnabled()) {
235             logger.debug(testBanner(testName, CLASS_NAME));
236         }
237         // Perform setup.
238         setupReadNonExistent();
239
240         // Submit the request to the service and store the response.
241         ReportClient client = new ReportClient();
242         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
243         int statusCode = res.getStatus();
244
245         // Check the status code of the response: does it match
246         // the expected response(s)?
247         if (logger.isDebugEnabled()) {
248             logger.debug(testName + ": status = " + statusCode);
249         }
250         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
251                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
252         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
253     }
254
255     // ---------------------------------------------------------------
256     // CRUD tests : READ_LIST tests
257     // ---------------------------------------------------------------
258     // Success outcomes
259     /* (non-Javadoc)
260      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
261      */
262     @Override
263     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
264     dependsOnMethods = {"createList", "read"})
265     public void readList(String testName) throws Exception {
266
267         if (logger.isDebugEnabled()) {
268             logger.debug(testBanner(testName, CLASS_NAME));
269         }
270         // Perform setup.
271         setupReadList();
272
273         // Submit the request to the service and store the response.
274         ReportClient client = new ReportClient();
275         ClientResponse<AbstractCommonList> res = client.readList();
276         AbstractCommonList list = res.getEntity();
277         int statusCode = res.getStatus();
278
279         // Check the status code of the response: does it match
280         // the expected response(s)?
281         if (logger.isDebugEnabled()) {
282             logger.debug(testName + ": status = " + statusCode);
283         }
284         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
285                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
286         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
287
288         // Optionally output additional data about list members for debugging.
289         boolean iterateThroughList = false;
290         if (iterateThroughList && logger.isDebugEnabled()) {
291                 ListItemsInAbstractCommonList(list, logger, testName);
292         }
293     }
294
295     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
296                 dependsOnMethods = {"readList"})
297     public void readListFiltered(String testName) throws Exception {
298         if (logger.isDebugEnabled()) {
299                 logger.debug(testBanner(testName, CLASS_NAME));
300         }
301         // Perform setup.
302         setupReadList();
303
304         // Submit the request to the service and store the response.
305         ReportClient client = new ReportClient();
306         ClientResponse<AbstractCommonList> res = client.readListFiltered(
307                         testDocType, "single");
308         AbstractCommonList list = res.getEntity();
309         int statusCode = res.getStatus();
310
311         // Check the status code of the response: does it match
312         // the expected response(s)?
313         if (logger.isDebugEnabled()) {
314                 logger.debug(testName + ": status = " + statusCode);
315         }
316         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
317                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
318         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
319
320         List<AbstractCommonList.ListItem> items =
321                 list.getListItem();
322         // We must find the basic one we created
323         boolean fFoundBaseItem = false;
324                 for (AbstractCommonList.ListItem item : items) {
325                         if(knownResourceId.equalsIgnoreCase(ListItemGetCSID(item))) {
326                                 fFoundBaseItem = true;
327                                 break;
328                         }
329                 }
330                 if(!fFoundBaseItem)
331                         Assert.fail("readListFiltered failed to return base item");
332                 
333                 // Now filter for something else, and ensure it is NOT returned
334         res = client.readListFiltered("Intake", "single");
335         list = res.getEntity();
336         statusCode = res.getStatus();
337
338         // Check the status code of the response: does it match
339         // the expected response(s)?
340         if (logger.isDebugEnabled()) {
341                 logger.debug(testName + ": status = " + statusCode);
342         }
343         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
344                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
345         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
346
347         items = list.getListItem();
348         // We must NOT find the basic one we created
349                 for (AbstractCommonList.ListItem item : items) {
350                         Assert.assertNotSame(ListItemGetCSID(item), knownResourceId, 
351                                 "readListFiltered(\"Intake\", \"single\") incorrectly returned base item");
352                 }
353                 
354                 // Now filter for something else, and ensure it is NOT returned
355         res = client.readListFiltered(testDocType, "group");
356         list = res.getEntity();
357         statusCode = res.getStatus();
358
359         // Check the status code of the response: does it match
360         // the expected response(s)?
361         if (logger.isDebugEnabled()) {
362                 logger.debug(testName + ": status = " + statusCode);
363         }
364         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
365                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
366         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
367
368         items = list.getListItem();
369         // We must NOT find the basic one we created
370                 for (AbstractCommonList.ListItem item : items) {
371                         Assert.assertNotSame(ListItemGetCSID(item), knownResourceId, 
372                                 "readListFiltered(\""+testDocType+"\", \"group\") incorrectly returned base item");
373                 }
374     }
375
376     // ---------------------------------------------------------------
377     // CRUD tests : UPDATE tests
378     // ---------------------------------------------------------------
379     // Success outcomes
380     /* (non-Javadoc)
381      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
382      */
383     @Override
384     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385     dependsOnMethods = {"read", "readListFiltered"})
386     public void update(String testName) throws Exception {
387
388         if (logger.isDebugEnabled()) {
389             logger.debug(testBanner(testName, CLASS_NAME));
390         }
391         // Perform setup.
392         setupUpdate();
393
394         // Retrieve the contents of a resource to update.
395         ReportClient client = new ReportClient();
396         ClientResponse<String> res = client.read(knownResourceId);
397         if (logger.isDebugEnabled()) {
398             logger.debug(testName + ": read status = " + res.getStatus());
399         }
400         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
401         if (logger.isDebugEnabled()) {
402             logger.debug("got object to update with ID: " + knownResourceId);
403         }
404
405         // Extract the common part from the response.
406         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
407         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
408         ReportsCommon reportCommon = null;
409         if (payloadInputPart != null) {
410             reportCommon = (ReportsCommon) payloadInputPart.getBody();
411         }
412         Assert.assertNotNull(reportCommon);
413
414         // Update its content.
415         reportCommon.setName("updated-" + reportCommon.getName());
416         reportCommon.setOutputMIME("updated-" + reportCommon.getOutputMIME());
417         if (logger.isDebugEnabled()) {
418             logger.debug("to be updated object");
419             logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class));
420         }
421         reportCommon.setNotes("updated-" + reportCommon.getNotes());
422
423         // Submit the updated common part in an update request to the service
424         // and store the response.
425         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
426         PayloadOutputPart commonPart = output.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE);
427         commonPart.setLabel(client.getCommonPartName());
428         res = client.update(knownResourceId, output);
429
430         // Check the status code of the response: does it match the expected response(s)?
431         int statusCode = res.getStatus();
432         if (logger.isDebugEnabled()) {
433             logger.debug(testName + ": status = " + statusCode);
434         }
435         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
436                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
437         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
438
439         // Extract the updated common part from the response.
440         input = new PoxPayloadIn(res.getEntity());
441         payloadInputPart = input.getPart(client.getCommonPartName());
442         ReportsCommon updatedReportCommon = null;
443         if (payloadInputPart != null) {
444             updatedReportCommon = (ReportsCommon) payloadInputPart.getBody();
445         }
446         Assert.assertNotNull(updatedReportCommon);
447         if (logger.isDebugEnabled()) {
448             logger.debug("updated object");
449             logger.debug(objectAsXmlString(updatedReportCommon, ReportsCommon.class));
450         }
451
452         // Check selected fields in the updated common part.
453         Assert.assertEquals(updatedReportCommon.getName(),
454                 reportCommon.getName(),
455                 "Data in updated object did not match submitted data.");
456
457         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
458         if (logger.isDebugEnabled()) {
459             logger.debug("UTF-8 data sent=" + reportCommon.getNotes() + "\n"
460                     + "UTF-8 data received=" + updatedReportCommon.getNotes());
461         }
462         Assert.assertTrue(updatedReportCommon.getNotes().contains(getUTF8DataFragment()),
463                 "UTF-8 data retrieved '" + updatedReportCommon.getNotes()
464                 + "' does not contain expected data '" + getUTF8DataFragment());
465         Assert.assertEquals(updatedReportCommon.getNotes(),
466                 reportCommon.getNotes(),
467                 "Data in updated object did not match submitted data.");
468     }
469
470     // Failure outcomes
471     // Placeholders until the three tests below can be uncommented.
472     // See Issue CSPACE-401.
473     /* (non-Javadoc)
474      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
475      */
476     @Override
477     public void updateWithEmptyEntityBody(String testName) throws Exception {
478         //Should this really be empty?
479     }
480
481     /* (non-Javadoc)
482      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
483      */
484     @Override
485     public void updateWithMalformedXml(String testName) throws Exception {
486         //Should this really be empty?
487     }
488
489     /* (non-Javadoc)
490      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
491      */
492     @Override
493     public void updateWithWrongXmlSchema(String testName) throws Exception {
494         //Should this really be empty?
495     }
496
497     /* (non-Javadoc)
498      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
499      */
500     @Override
501     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
502     dependsOnMethods = {"update", "testSubmitRequest"})
503     public void updateNonExistent(String testName) throws Exception {
504
505         if (logger.isDebugEnabled()) {
506             logger.debug(testBanner(testName, CLASS_NAME));
507         }
508         // Perform setup.
509         setupUpdateNonExistent();
510
511         // Submit the request to the service and store the response.
512         // Note: The ID used in this 'create' call may be arbitrary.
513         // The only relevant ID may be the one used in update(), below.
514         ReportClient client = new ReportClient();
515         PoxPayloadOut multipart = createReportInstance(NON_EXISTENT_ID);
516         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
517         int statusCode = res.getStatus();
518
519         // Check the status code of the response: does it match
520         // the expected response(s)?
521         if (logger.isDebugEnabled()) {
522             logger.debug(testName + ": status = " + statusCode);
523         }
524         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
527     }
528
529     // ---------------------------------------------------------------
530     // CRUD tests : DELETE tests
531     // ---------------------------------------------------------------
532     // Success outcomes
533     /* (non-Javadoc)
534      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
535      */
536     @Override
537     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
538     dependsOnMethods = {"create", "readListFiltered", "testSubmitRequest", "update", "readWorkflow"})
539     public void delete(String testName) throws Exception {
540
541         if (logger.isDebugEnabled()) {
542             logger.debug(testBanner(testName, CLASS_NAME));
543         }
544         // Perform setup.
545         setupDelete();
546
547         // Submit the request to the service and store the response.
548         ReportClient client = new ReportClient();
549         ClientResponse<Response> res = client.delete(knownResourceId);
550         int statusCode = res.getStatus();
551
552         // Check the status code of the response: does it match
553         // the expected response(s)?
554         if (logger.isDebugEnabled()) {
555             logger.debug(testName + ": status = " + statusCode);
556         }
557         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
558                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
559         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
560     }
561
562     // Failure outcomes
563     /* (non-Javadoc)
564      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
565      */
566     @Override
567     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
568     dependsOnMethods = {"delete"})
569     public void deleteNonExistent(String testName) throws Exception {
570
571         if (logger.isDebugEnabled()) {
572             logger.debug(testBanner(testName, CLASS_NAME));
573         }
574         // Perform setup.
575         setupDeleteNonExistent();
576
577         // Submit the request to the service and store the response.
578         ReportClient client = new ReportClient();
579         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
580         int statusCode = res.getStatus();
581
582         // Check the status code of the response: does it match
583         // the expected response(s)?
584         if (logger.isDebugEnabled()) {
585             logger.debug(testName + ": status = " + statusCode);
586         }
587         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
590     }
591
592     // ---------------------------------------------------------------
593     // Utility tests : tests of code used in tests above
594     // ---------------------------------------------------------------
595     /**
596      * Tests the code for manually submitting data that is used by several
597      * of the methods above.
598      */
599     @Test(dependsOnMethods = {"create", "read"})
600     public void testSubmitRequest() {
601
602         // Expected status code: 200 OK
603         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
604
605         // Submit the request to the service and store the response.
606         String method = ServiceRequestType.READ.httpMethodName();
607         String url = getResourceURL(knownResourceId);
608         int statusCode = submitRequest(method, url);
609
610         // Check the status code of the response: does it match
611         // the expected response(s)?
612         if (logger.isDebugEnabled()) {
613             logger.debug("testSubmitRequest: url=" + url
614                     + " status=" + statusCode);
615         }
616         Assert.assertEquals(statusCode, EXPECTED_STATUS);
617
618     }
619
620     // ---------------------------------------------------------------
621     // Utility methods used by tests above
622     // ---------------------------------------------------------------
623     @Override
624     protected String getServiceName() {
625         return SERVICE_NAME;
626     }
627
628     /* (non-Javadoc)
629      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
630      */
631     @Override
632     public String getServicePathComponent() {
633         return SERVICE_PATH_COMPONENT;
634     }
635
636     /**
637      * Creates the report instance.
638      *
639      * @param identifier the identifier
640      * @return the multipart output
641      */
642     private PoxPayloadOut createReportInstance(String identifier) {
643         List<String> docTypes = new ArrayList<String>();
644         docTypes.add(testDocType);
645         return createReportInstance(
646                 "Acquisition Summary", 
647                 docTypes, true, false, false, true,
648                 "acq_basic.jasper",
649                 "application/pdf");
650     }
651
652     /**
653      * Creates the report instance.
654      *
655      * @param name the report name
656      * @param filename the relative path to the report
657      * @param outputMIME the MIME type we will return for this report
658      * @return the multipart output
659      */
660     private PoxPayloadOut createReportInstance(String name,
661                 List<String> forDocTypeList,
662                 boolean supportsSingle, boolean supportsList, 
663                 boolean supportsGroup, boolean supportsNoContext, 
664             String filename,
665             String outputMIME) {
666         ReportsCommon reportCommon = new ReportsCommon();
667         reportCommon.setName(name);
668         ReportsCommon.ForDocTypes forDocTypes = new ReportsCommon.ForDocTypes(); 
669         List<String> docTypeList = forDocTypes.getForDocType();
670         docTypeList.addAll(forDocTypeList);
671         reportCommon.setForDocTypes(forDocTypes);
672         reportCommon.setSupportsSingleDoc(supportsSingle);
673         reportCommon.setSupportsDocList(supportsList);
674         reportCommon.setSupportsGroup(supportsGroup);
675         reportCommon.setSupportsNoContext(supportsNoContext);
676         reportCommon.setFilename(filename);
677         reportCommon.setOutputMIME(outputMIME);
678         reportCommon.setNotes(getUTF8DataFragment()); // For UTF-8 tests
679
680         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
681         PayloadOutputPart commonPart =
682                 multipart.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE);
683         commonPart.setLabel(new ReportClient().getCommonPartName());
684
685         if (logger.isDebugEnabled()) {
686             logger.debug("to be created, report common");
687             logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class));
688             logger.debug(multipart.toXML());
689         }
690
691         return multipart;
692     }
693 }