]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bfbf7a9ae67eee12aab9d745fb853f2948800d30
[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.common.AbstractCommonListUtils;
37 import org.collectionspace.services.report.ReportsCommon;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39
40 import org.jboss.resteasy.client.ClientResponse;
41 import org.testng.Assert;
42 //import org.testng.annotations.AfterClass;
43 import org.testng.annotations.Test;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
50  * ReportServiceTest, carries out tests against a
51  * deployed and running Report Service.
52  *
53  * $LastChangedRevision: 2261 $
54  * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $
55  */
56 public class ReportServiceTest extends AbstractServiceTestImpl {
57
58     /** The logger. */
59     private final String CLASS_NAME = ReportServiceTest.class.getName();
60     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61     final String SERVICE_NAME = "reports";
62     final String SERVICE_PATH_COMPONENT = "reports";
63     // Instance variables specific to this test.
64     /** The known resource id. */
65     private String knownResourceId = null;
66     
67     private String testDocType = "Acquisition";
68
69     /* (non-Javadoc)
70      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71      */
72     @Override
73     protected CollectionSpaceClient getClientInstance() {
74         return new ReportClient();
75     }
76
77 //    @Override
78 //    protected PoxPayloadOut createInstance(String identifier) {
79 //        PoxPayloadOut multipart = createReportInstance(identifier);
80 //        return multipart;
81 //    }
82         
83     // ---------------------------------------------------------------
84     // CRUD tests : CREATE tests
85     // ---------------------------------------------------------------
86     // Success outcomes
87     /* (non-Javadoc)
88      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
89      */
90     @Override
91     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
92     public void create(String testName) throws Exception {
93
94         if (logger.isDebugEnabled()) {
95             logger.debug(testBanner(testName, CLASS_NAME));
96         }
97         // Perform setup, such as initializing the type of service request
98         // (e.g. CREATE, DELETE), its valid and expected status codes, and
99         // its associated HTTP method name (e.g. POST, DELETE).
100         setupCreate();
101
102         // Submit the request to the service and store the response.
103         ReportClient client = new ReportClient();
104         String identifier = createIdentifier();
105         PoxPayloadOut multipart = createReportInstance(identifier);
106         ClientResponse<Response> res = client.create(multipart);
107
108         // Check the status code of the response: does it match
109         // the expected response(s)?
110         //
111         // Specifically:
112         // Does it fall within the set of valid status codes?
113         // Does it exactly match the expected status code?
114         int statusCode = res.getStatus();
115         if (logger.isDebugEnabled()) {
116             logger.debug(testName + ": status = " + statusCode);
117         }
118         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
119                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
120         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
121
122         // Store the ID returned from the first resource created
123         // for additional tests below.
124         if (knownResourceId == null) {
125             knownResourceId = extractId(res);
126             if (logger.isDebugEnabled()) {
127                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
128             }
129         }
130
131         // Store the IDs from every resource created by tests,
132         // so they can be deleted after tests have been run.
133         allResourceIdsCreated.add(extractId(res));
134     }
135
136     /* (non-Javadoc)
137      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
138      */
139     @Override
140     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
141     dependsOnMethods = {"create"})
142     public void createList(String testName) throws Exception {
143         for (int i = 0; i < 3; i++) {
144             create(testName);
145         }
146     }
147
148     // Failure outcomes
149     // Placeholders until the three tests below can be uncommented.
150     // See Issue CSPACE-401.
151     /* (non-Javadoc)
152      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
153      */
154     @Override
155     public void createWithEmptyEntityBody(String testName) throws Exception {
156         //Should this really be empty?
157     }
158
159     /* (non-Javadoc)
160      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
161      */
162     @Override
163     public void createWithMalformedXml(String testName) throws Exception {
164         //Should this really be empty?
165     }
166
167     /* (non-Javadoc)
168      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
169      */
170     @Override
171     public void createWithWrongXmlSchema(String testName) throws Exception {
172         //Should this really be empty?
173     }
174
175     // ---------------------------------------------------------------
176     // CRUD tests : READ tests
177     // ---------------------------------------------------------------
178     // Success outcomes
179     /* (non-Javadoc)
180      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
181      */
182     @Override
183     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
184     dependsOnMethods = {"create"})
185     public void read(String testName) throws Exception {
186
187         if (logger.isDebugEnabled()) {
188             logger.debug(testBanner(testName, CLASS_NAME));
189         }
190         // Perform setup.
191         setupRead();
192
193         // Submit the request to the service and store the response.
194         ReportClient client = new ReportClient();
195         ClientResponse<String> res = client.read(knownResourceId);
196
197         // Check the status code of the response: does it match
198         // the expected response(s)?
199         int statusCode = res.getStatus();
200         if (logger.isDebugEnabled()) {
201             logger.debug(testName + ": status = " + statusCode);
202         }
203         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
204                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
205         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
206
207         // Get the common part of the response and verify that it is not null.
208         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
209         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
210         ReportsCommon reportCommon = null;
211         if (payloadInputPart != null) {
212             reportCommon = (ReportsCommon) payloadInputPart.getBody();
213         }
214         Assert.assertNotNull(reportCommon);
215
216         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
217         if (logger.isDebugEnabled()) {
218             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
219                     + "UTF-8 data received=" + reportCommon.getNotes());
220         }
221         Assert.assertEquals(reportCommon.getNotes(), getUTF8DataFragment(),
222                 "UTF-8 data retrieved '" + reportCommon.getNotes()
223                 + "' does not match expected data '" + getUTF8DataFragment());
224     }
225
226     // Failure outcomes
227     /* (non-Javadoc)
228      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
229      */
230     @Override
231     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
232     dependsOnMethods = {"read"})
233     public void readNonExistent(String testName) throws Exception {
234
235         if (logger.isDebugEnabled()) {
236             logger.debug(testBanner(testName, CLASS_NAME));
237         }
238         // Perform setup.
239         setupReadNonExistent();
240
241         // Submit the request to the service and store the response.
242         ReportClient client = new ReportClient();
243         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
244         int statusCode = res.getStatus();
245
246         // Check the status code of the response: does it match
247         // the expected response(s)?
248         if (logger.isDebugEnabled()) {
249             logger.debug(testName + ": status = " + statusCode);
250         }
251         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
252                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
253         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
254     }
255
256     // ---------------------------------------------------------------
257     // CRUD tests : READ_LIST tests
258     // ---------------------------------------------------------------
259     // Success outcomes
260     /* (non-Javadoc)
261      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
262      */
263     @Override
264     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
265     dependsOnMethods = {"createList", "read"})
266     public void readList(String testName) throws Exception {
267
268         if (logger.isDebugEnabled()) {
269             logger.debug(testBanner(testName, CLASS_NAME));
270         }
271         // Perform setup.
272         setupReadList();
273
274         // Submit the request to the service and store the response.
275         ReportClient client = new ReportClient();
276         ClientResponse<AbstractCommonList> res = client.readList();
277         AbstractCommonList list = res.getEntity();
278         int statusCode = res.getStatus();
279
280         // Check the status code of the response: does it match
281         // the expected response(s)?
282         if (logger.isDebugEnabled()) {
283             logger.debug(testName + ": status = " + statusCode);
284         }
285         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
286                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
287         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
288
289         // Optionally output additional data about list members for debugging.
290         if(logger.isTraceEnabled()){
291                 AbstractCommonListUtils.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(AbstractCommonListUtils.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(AbstractCommonListUtils.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(AbstractCommonListUtils.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 }