]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
f65752ce9edbfec1c71d9a65ae277754953b9da1
[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.math.BigDecimal;
26 import java.math.BigInteger;
27 import java.util.List;
28
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 //import org.collectionspace.services.client.AbstractServiceClientImpl;
46 import org.collectionspace.services.client.CollectionObjectClient;
47 import org.collectionspace.services.client.CollectionObjectFactory;
48 import org.collectionspace.services.client.CollectionSpaceClient;
49 import org.collectionspace.services.client.PayloadOutputPart;
50 import org.collectionspace.services.client.PoxPayloadOut;
51 import org.collectionspace.services.collectionobject.BriefDescriptionList;
52 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
53 import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory;
54 import org.collectionspace.services.collectionobject.DimensionSubGroup;
55 import org.collectionspace.services.collectionobject.DimensionSubGroupList;
56 import org.collectionspace.services.collectionobject.MeasuredPartGroup;
57 import org.collectionspace.services.collectionobject.MeasuredPartGroupList;
58 import org.collectionspace.services.collectionobject.ObjectNameGroup;
59 import org.collectionspace.services.collectionobject.ObjectNameList;
60 import org.collectionspace.services.collectionobject.OtherNumberList;
61 import org.collectionspace.services.collectionobject.OtherNumber;
62 import org.collectionspace.services.collectionobject.ResponsibleDepartmentList;
63 import org.collectionspace.services.collectionobject.TitleGroup;
64 import org.collectionspace.services.collectionobject.TitleGroupList;
65 import org.collectionspace.services.jaxb.AbstractCommonList;
66 import org.testng.Assert;
67 import org.testng.annotations.Test;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70
71 /**
72  * CollectionObjectServiceTest, carries out tests against a
73  * deployed and running CollectionObject Service.
74  *
75  * $LastChangedRevision$
76  * $LastChangedDate$
77  */
78 public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, CollectionobjectsCommon> {
79
80     /** The logger. */
81     private final String CLASS_NAME = CollectionObjectServiceTest.class.getName();
82     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
83     
84     private final String OBJECT_NAME_VALUE = "an object name";
85     private final BigInteger AGE_VALUE = new BigInteger("55");
86     private final String MEASURED_PART = "light box frame";
87     private final BigDecimal DIMENSION_VALUE_LENGTH = new BigDecimal("0.009");
88     private final BigDecimal DIMENSION_VALUE_WIDTH = new BigDecimal("3087.56");
89     private final String UPDATED_MEASUREMENT_UNIT = "Angstroms";
90     private final String UTF8_DATA_SAMPLE = "Audiorecording album cover signed by Lech "
91             + "Wa" + '\u0142' + '\u0119' + "sa";
92
93 //    /* (non-Javadoc)
94 //     * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
95 //     */
96 //    @Override
97 //    protected String getServicePathComponent() {
98 //        return new CollectionObjectClient().getServicePathComponent();
99 //    }
100
101         @Override
102         protected String getServiceName() {
103                 return CollectionObjectClient.SERVICE_NAME;
104         }
105     
106     /* (non-Javadoc)
107      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
108      */
109     @Override
110     protected CollectionSpaceClient getClientInstance() throws Exception {
111         return new CollectionObjectClient();
112     }
113
114         @Override
115         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
116         return new CollectionObjectClient(clientPropertiesFilename);
117         }
118      
119     // ---------------------------------------------------------------
120     // CRUD tests : CREATE tests
121     // ---------------------------------------------------------------
122     // Expected success outcomes
123     
124     /*
125      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
126      * refer to this method in their @Test annotation declarations.
127      */
128     @Override
129     @Test(dataProvider = "testName",
130                 dependsOnMethods = {
131                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
132     public void CRUDTests(String testName) {
133         // Do nothing.  Simply here to for a TestNG execution order for our tests
134     }
135         
136     /*
137      * Tests to diagnose and verify the fixed status of CSPACE-1026,
138      * "Whitespace at certain points in payload cause failure"
139      */
140     
141     /**
142      * Creates the from xml cambridge.
143      *
144      * @param testName the test name
145      * @throws Exception the exception
146      */
147     @Test(dataProvider = "testName",
148         dependsOnMethods = {"CRUDTests"})
149     public void createFromXmlCambridge(String testName) throws Exception {
150         String newId =
151             createFromXmlFile(testName, "./test-data/testCambridge.xml", true);
152         testSubmitRequest(newId);
153     }
154
155    /*
156     * Tests to diagnose and fix CSPACE-2242.
157     *
158     * This is a bug identified in release 0.8 in which value instances of a
159     * repeatable field are not stored when the first value instance of that
160     * field is blank.
161     */
162
163     // Verify that record creation occurs successfully when the first value instance
164     // of a single, repeatable String scalar field is non-blank.
165     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
166         dependsOnMethods = {"CRUDTests"}, groups = {"cspace2242group"})
167     public void createFromXmlNonBlankFirstValueInstance(String testName) throws Exception {
168         String newId =
169             createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-nonblank.xml", true);
170         CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
171         // Verify that at least one value instance of the repeatable field was successfully persisted.
172         BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
173         List<String> descriptions = descriptionList.getBriefDescription();
174         Assert.assertTrue(descriptions.size() > 0);
175     }
176
177     // Verify that record creation occurs successfully when the first value instance
178     // of a single, repeatable String scalar field is blank.
179     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
180         dependsOnMethods = {"CRUDTests"}, groups = {"cspace2242group"})
181     public void createFromXmlBlankFirstValueInstance(String testName) throws Exception {
182         String newId =
183             createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-blank.xml", true);
184         CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
185         // Verify that at least one value instance of the repeatable field was successfully persisted.
186         BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
187         List<String> descriptions = descriptionList.getBriefDescription();
188         Assert.assertTrue(descriptions.size() > 0);
189     }
190
191      // Verify that values are preserved when enclosed in double quote marks.
192     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
193         dependsOnMethods = {"CRUDTests"}, groups = {"cspace3237group"})
194     public void doubleQuotesEnclosingFieldContents(String testName) throws Exception {
195         String newId =
196             createFromXmlFile(testName, "./test-data/cspace-3237-double-quotes.xml", true);
197         CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
198
199         Assert.assertTrue(collectionObject.getDistinguishingFeatures().matches("^\\\".+?\\\"$"));
200
201         BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
202         List<String> descriptions = descriptionList.getBriefDescription();
203         Assert.assertTrue(descriptions.size() > 0);
204         Assert.assertNotNull(descriptions.get(0));
205         Assert.assertTrue(descriptions.get(0).matches("^\\\".+?\\\"$"));
206
207         if (logger.isDebugEnabled()) {
208             logger.debug(objectAsXmlString(collectionObject,
209                     CollectionobjectsCommon.class));
210         }
211     }
212
213     /**
214      * Creates the from xml rfw s1.
215      *
216      * @param testName the test name
217      * @throws Exception the exception
218      */
219     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
220         dependsOnMethods = {"CRUDTests"})
221     public void createFromXmlRFWS1(String testName) throws Exception {
222         String testDataDir = System.getProperty("test-data.fileName");
223         String newId =
224             //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp1.xml", false);
225                 createFromXmlFile(testName, testDataDir + "/repfield_whitesp1.xml", false);
226         testSubmitRequest(newId);
227     }
228
229     /**
230      * Creates the from xml rfw s2.
231      *
232      * @param testName the test name
233      * @throws Exception the exception
234      */
235     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
236         dependsOnMethods = {"CRUDTests"})
237     public void createFromXmlRFWS2(String testName) throws Exception {
238         String testDataDir = System.getProperty("test-data.fileName");
239         String newId =
240             //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp2.xml", false);
241                 createFromXmlFile(testName, testDataDir + "/repfield_whitesp2.xml", false);
242         testSubmitRequest(newId);
243     }
244
245     /**
246      * Creates the from xml rfw s3.
247      *
248      * @param testName the test name
249      * @throws Exception the exception
250      */
251     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
252         dependsOnMethods = {"CRUDTests"})
253     public void createFromXmlRFWS3(String testName) throws Exception {
254         String testDataDir = System.getProperty("test-data.fileName");
255         String newId =
256             //createFromXmlFile(testName, "./target/test-classes/test-data/repfield_whitesp3.xml", false);
257                 createFromXmlFile(testName, testDataDir + "/repfield_whitesp3.xml", false);
258         testSubmitRequest(newId);
259     }
260
261     /**
262      * Creates the from xml rfw s4.
263      *
264      * @param testName the test name
265      * @throws Exception the exception
266      */
267     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268         dependsOnMethods = {"CRUDTests"})
269     public void createFromXmlRFWS4(String testName) throws Exception {
270         String testDataDir = System.getProperty("test-data.fileName");
271         String newId =
272             createFromXmlFile(testName, testDataDir + "/repfield_whitesp4.xml", false);
273         testSubmitRequest(newId);
274     }
275
276     /*
277      * Tests to diagnose and verify the fixed status of CSPACE-1248,
278      * "Wedged records created!" (i.e. records with child repeatable
279      * fields, which contain null values, can be successfully created
280      * but an error occurs on trying to retrieve those records).
281      */
282
283     /**
284      * Creates a CollectionObject resource with a null value repeatable field.
285      *
286      * @param testName the test name
287      * @throws Exception the exception
288      */
289     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
290         dependsOnMethods = {"CRUDTests"})
291     public void createWithNullValueRepeatableField(String testName) throws Exception {
292         String testDataDir = System.getProperty("test-data.fileName");
293         String newId =
294             createFromXmlFile(testName, testDataDir + "/repfield_null1.xml", false);
295         if (logger.isDebugEnabled()) {
296             logger.debug("Successfully created record with null value repeatable field.");
297             logger.debug("Attempting to retrieve just-created record ...");
298         }
299         testSubmitRequest(newId);
300     }
301
302     /**
303      * Creates a CollectionObject resource, one of whose fields contains
304      * non-Latin 1 Unicode UTF-8 characters.
305      *
306      * @param testName the test name
307      * @throws Exception the exception
308      */
309     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
310         dependsOnMethods = {"CRUDTests"}, groups={"utf8-create"})
311     public void createWithUTF8Data(String testName) throws Exception {
312         String testDataDir = System.getProperty("test-data.fileName");
313         String newId =
314             createFromXmlFile(testName, testDataDir + "/cspace-2779-utf-8-create.xml", false);
315         if (logger.isDebugEnabled()) {
316             logger.debug("Created record with UTF-8 chars in payload.");
317             logger.debug("Attempting to retrieve just-created record ...");
318         }
319         CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
320         String distinguishingFeatures = collectionObject.getDistinguishingFeatures();
321         if (logger.isDebugEnabled()) {
322             logger.debug("Sent distinguishingFeatures: " + UTF8_DATA_SAMPLE);
323             logger.debug("Received distinguishingFeatures: " + distinguishingFeatures);
324         }
325         Assert.assertTrue(distinguishingFeatures.equals(UTF8_DATA_SAMPLE));
326     }
327
328     // Failure outcomes
329     // Placeholders until the three tests below can be uncommented.
330     // See Issue CSPACE-401.
331     /* (non-Javadoc)
332      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
333      */
334     @Override
335     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
336     public void createWithEmptyEntityBody(String testName) throws Exception {
337         //FIXME: Should this test really be empty?
338     }
339
340    /**
341     * Test how the service handles XML that is not well formed,
342     * when sent in the payload of a Create request.
343     *
344     * @param testName  The name of this test method.  This name is supplied
345     *     automatically, via reflection, by a TestNG 'data provider' in
346     *     a base class.
347     */
348     @Override
349     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
350     public void createWithMalformedXml(String testName) throws Exception {
351         //FIXME: Should this test really be empty?
352     }
353
354     /* (non-Javadoc)
355      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
356      */
357     @Override
358     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
359     public void createWithWrongXmlSchema(String testName) throws Exception {
360         //FIXME: Should this test really be empty?
361     }
362
363
364 /*
365     @Override
366     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
367     dependsOnMethods = {"create", "testSubmitRequest"})
368     public void createWithEmptyEntityBody(String testName) throwsException {
369
370         if (logger.isDebugEnabled()) {
371             logger.debug(testBanner(testName, CLASS_NAME));
372         }
373         // Perform setup.
374         setupCreateWithEmptyEntityBody();
375
376         // Submit the request to the service and store the response.
377         String method = REQUEST_TYPE.httpMethodName();
378         String url = getServiceRootURL();
379         String mediaType = MediaType.APPLICATION_XML;
380         final String entity = "";
381         int statusCode = submitRequest(method, url, mediaType, entity);
382
383         // Check the status code of the response: does it match
384         // the expected response(s)?
385         if(logger.isDebugEnabled()){
386         logger.debug(testName + ": url=" + url +
387         " status=" + statusCode);
388         }
389         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
390         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
391         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
392     }
393
394     @Override
395     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
396     dependsOnMethods = {"create", "testSubmitRequest"})
397     public void createWithMalformedXml(String testName) throws Exception {
398
399         if (logger.isDebugEnabled()) {
400             logger.debug(testBanner(testName, CLASS_NAME));
401         }
402         // Perform setup.
403         setupCreateWithMalformedXml();
404
405         // Submit the request to the service and store the response.
406         String method = REQUEST_TYPE.httpMethodName();
407         String url = getServiceRootURL();
408         String mediaType = MediaType.APPLICATION_XML;
409         final String entity = MALFORMED_XML_DATA; // Constant from base class.
410         int statusCode = submitRequest(method, url, mediaType, entity);
411
412         // Check the status code of the response: does it match
413         // the expected response(s)?
414         if(logger.isDebugEnabled()){
415         logger.debug(testName + ": url=" + url +
416         " status=" + statusCode);
417         }
418         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
419         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
420         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
421     }
422
423     @Override
424     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
425     dependsOnMethods = {"create", "testSubmitRequest"})
426     public void createWithWrongXmlSchema(String testName) throws Exception {
427
428         if (logger.isDebugEnabled()) {
429             logger.debug(testBanner(testName, CLASS_NAME));
430         }
431         // Perform setup.
432         setupCreateWithWrongXmlSchema();
433
434         // Submit the request to the service and store the response.
435         String method = REQUEST_TYPE.httpMethodName();
436         String url = getServiceRootURL();
437         String mediaType = MediaType.APPLICATION_XML;
438         final String entity = WRONG_XML_SCHEMA_DATA;
439         int statusCode = submitRequest(method, url, mediaType, entity);
440
441         // Check the status code of the response: does it match
442         // the expected response(s)?
443         if(logger.isDebugEnabled()){
444         logger.debug(testName + ": url=" + url +
445         " status=" + statusCode);
446         }
447         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
448         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
449         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
450     }
451 */
452
453    /**
454     * Test how the service handles, in a Create request, payloads
455     * containing null values (or, in the case of String fields,
456     * empty String values) in one or more fields which must be
457     * present and are required to contain non-empty values.
458     *
459     * This is a test of code and/or configuration in the service's
460     * validation routine(s).
461     *
462     * @param testName  The name of this test method.  This name is supplied
463     *     automatically, via reflection, by a TestNG 'data provider' in
464     *     a base class.
465     * @throws Exception 
466     */
467     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
468     public void createWithRequiredValuesNullOrEmpty(String testName) throws Exception {
469         setupCreate();
470
471         // Build a payload with invalid content, by omitting a
472         // field (objectNumber) which must be present, and in which
473         // a non-empty value is required, as enforced by the service's
474         // validation routine(s).
475         CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
476
477         TitleGroupList titleGroupList = new TitleGroupList();
478         List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
479         TitleGroup titleGroup = new TitleGroup();
480         titleGroup.setTitle("a title");
481         titleGroups.add(titleGroup);
482         collectionObject.setTitleGroupList(titleGroupList);
483
484         ObjectNameList objNameList = new ObjectNameList();
485         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
486         ObjectNameGroup objectNameGroup = new ObjectNameGroup();
487         objectNameGroup.setObjectName("an object name");
488         objNameGroups.add(objectNameGroup);
489         collectionObject.setObjectNameList(objNameList);
490
491         // Submit the request to the service and store the response.
492         CollectionObjectClient client = new CollectionObjectClient();
493         PoxPayloadOut multipart =
494                 createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
495         Response res = client.create(multipart);
496         try {
497                 int statusCode = res.getStatus();
498                 // Read the response and verify that the create attempt failed.
499                 if (logger.isDebugEnabled()) {
500                     logger.debug(testName + ": status = " + statusCode);
501                 }
502                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
503                         invalidStatusCodeMessage(testRequestType, statusCode));
504                 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
505         } finally {
506                 res.close();
507         }
508         
509         // FIXME: Consider splitting off the following into its own test method.
510         
511         // Build a payload with invalid content, by setting a value to the
512         // empty String, in a field (objectNumber) that requires a non-empty
513         // value, as enforced by the service's validation routine(s).
514         collectionObject = new CollectionobjectsCommon();
515         collectionObject.setObjectNumber("");
516         collectionObject.setDistinguishingFeatures("Distinguishing features.");
517
518         objNameList = new ObjectNameList();
519         objNameGroups = objNameList.getObjectNameGroup();
520         objectNameGroup = new ObjectNameGroup();
521         objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
522         objNameGroups.add(objectNameGroup);
523         collectionObject.setObjectNameList(objNameList);
524
525         // Submit the request to the service and store the response.
526         multipart = createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
527         res = client.create(multipart);
528         try {
529                 int statusCode = res.getStatus();
530         
531                 // Read the response and verify that the create attempt failed.
532                 if (logger.isDebugEnabled()) {
533                     logger.debug(testName + ": status = " + statusCode);
534                 }
535                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
536                         invalidStatusCodeMessage(testRequestType, statusCode));
537                 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
538         } finally {
539                 res.close();
540         }
541     }
542     
543     /**
544      * Update retrieve.
545      *
546      * @param testName the test name
547      * @param id the id
548      * @return the client response
549      * @throws Exception 
550      */
551     private Response updateRetrieve(String testName, String id) throws Exception {
552         setupRead();
553         CollectionObjectClient client = new CollectionObjectClient();
554         Response res = client.read(knownResourceId);
555         int statusCode = res.getStatus();
556         // Check the status code of the response: does it match
557         // the expected response(s)?
558         if (logger.isDebugEnabled()) {
559             logger.debug(testName + ": read status = " + statusCode);
560         }
561         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
562                 invalidStatusCodeMessage(testRequestType, statusCode));
563         Assert.assertEquals(statusCode, testExpectedStatusCode);
564         if(logger.isDebugEnabled()){
565             logger.debug("got object to update with ID: " + knownResourceId);
566         }
567         
568         return res;
569     }
570
571     /**
572      * Update send.
573      *
574      * @param testName the test name
575      * @param id the id
576      * @return the client response
577      * @throws Exception 
578      */
579     private Response updateSend(String testName, String id,
580             CollectionobjectsCommon collectionObjectCommon) throws Exception {
581         setupUpdate();
582         PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
583         PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
584         CollectionObjectClient client = new CollectionObjectClient();
585         commonPart.setLabel(client.getCommonPartName());
586         
587         Response res = client.update(knownResourceId, output);
588         int statusCode = res.getStatus();
589         // Check the status code of the response: does it match
590         // the expected response(s)?
591         if (logger.isDebugEnabled()) {
592             logger.debug(testName + ": read status = " + statusCode);
593         }
594         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
595                 invalidStatusCodeMessage(testRequestType, statusCode));
596         Assert.assertEquals(statusCode, testExpectedStatusCode);
597         
598         return res; // Calling needs to make sure they call res.close();
599     }
600
601     // Failure outcomes
602     // Placeholders until the three tests below can be uncommented.
603     // See Issue CSPACE-401.
604     /* (non-Javadoc)
605      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
606      */
607     @Override
608     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
609         dependsOnMethods = {"CRUDTests"})
610     public void updateWithEmptyEntityBody(String testName) throws Exception {
611         //FIXME: Should this test really be empty?
612     }
613
614    /**
615     * Test how the service handles XML that is not well formed,
616     * when sent in the payload of an Update request.
617     *
618     * @param testName  The name of this test method.  This name is supplied
619     *     automatically, via reflection, by a TestNG 'data provider' in
620     *     a base class.
621     */
622     @Override
623     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
624         dependsOnMethods = {"CRUDTests"})
625     public void updateWithMalformedXml(String testName) throws Exception {
626         //FIXME: Should this test really be empty?
627     }
628
629     /* (non-Javadoc)
630      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
631      */
632     @Override
633     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
634         dependsOnMethods = {"CRUDTests"})
635     public void updateWithWrongXmlSchema(String testName) throws Exception {
636         //FIXME: Should this test really be empty?
637     }
638
639 /*
640     @Override
641     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
642     dependsOnMethods = {"create", "update", "testSubmitRequest"})
643     public void updateWithEmptyEntityBody(String testName) throws Exception {
644
645         if (logger.isDebugEnabled()) {
646             logger.debug(testBanner(testName, CLASS_NAME));
647         }
648         // Perform setup.
649         setupUpdateWithEmptyEntityBody();
650
651         // Submit the request to the service and store the response.
652         String method = REQUEST_TYPE.httpMethodName();
653         String url = getResourceURL(knownResourceId);
654         String mediaType = MediaType.APPLICATION_XML;
655         final String entity = "";
656         int statusCode = submitRequest(method, url, mediaType, entity);
657
658         // Check the status code of the response: does it match
659         // the expected response(s)?
660         if(logger.isDebugEnabled()){
661         logger.debug(testName + ": url=" + url +
662         " status=" + statusCode);
663         }
664         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667     }
668
669     @Override
670     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
671     dependsOnMethods = {"create", "update", "testSubmitRequest"})
672     public void updateWithMalformedXml() throws Exception {
673
674         if (logger.isDebugEnabled()) {
675             logger.debug(testBanner(testName, CLASS_NAME));
676         }
677         // Perform setup.
678         setupUpdateWithMalformedXml();
679
680         // Submit the request to the service and store the response.
681         String method = REQUEST_TYPE.httpMethodName();
682         String url = getResourceURL(knownResourceId);
683         final String entity = MALFORMED_XML_DATA;
684         String mediaType = MediaType.APPLICATION_XML;
685         int statusCode = submitRequest(method, url, mediaType, entity);
686
687         // Check the status code of the response: does it match
688         // the expected response(s)?
689         if(logger.isDebugEnabled()){
690         logger.debug(testName + ": url=" + url +
691         " status=" + statusCode);
692         }
693         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
694         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
695         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
696     }
697
698     @Override
699     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
700     dependsOnMethods = {"create", "update", "testSubmitRequest"})
701     public void updateWithWrongXmlSchema(String testName) throws Exception {
702
703         if (logger.isDebugEnabled()) {
704             logger.debug(testBanner(testName, CLASS_NAME));
705         }
706         // Perform setup.
707         setupUpdateWithWrongXmlSchema();
708
709         // Submit the request to the service and store the response.
710         String method = REQUEST_TYPE.httpMethodName();
711         String url = getResourceURL(knownResourceId);
712         String mediaType = MediaType.APPLICATION_XML;
713         final String entity = WRONG_XML_SCHEMA_DATA;
714         int statusCode = submitRequest(method, url, mediaType, entity);
715
716         // Check the status code of the response: does it match
717         // the expected response(s)?
718         if(logger.isDebugEnabled()){
719         logger.debug(testName + ": url=" + url +
720         " status=" + statusCode);
721         }
722         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
723         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
724         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725     }
726 */
727
728     @Override
729     public void updateNonExistent(String testName) throws Exception {
730         // Perform setup.
731         setupUpdateNonExistent();
732
733         // Submit the request to the service and store the response.
734         //
735         // Note: The ID used in this 'create' call may be arbitrary.
736         // The only relevant ID may be the one used in updateCollectionObject(), below.
737         CollectionObjectClient client = new CollectionObjectClient();
738         PoxPayloadOut multipart =
739                 createInstance(client.getCommonPartName(), NON_EXISTENT_ID);
740         Response res = client.update(NON_EXISTENT_ID, multipart);
741         try {
742                 int statusCode = res.getStatus();
743                 // Check the status code of the response: does it match
744                 // the expected response(s)?
745                 if (logger.isDebugEnabled()) {
746                     logger.debug(testName + ": status = " + statusCode);
747                 }
748                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
749                         invalidStatusCodeMessage(testRequestType, statusCode));
750                 Assert.assertEquals(statusCode, testExpectedStatusCode);
751         } finally {
752                 res.close();
753         }
754     }
755
756    /**
757     * Test how the service handles, in an Update request, payloads
758     * containing null values (or, in the case of String fields,
759     * empty String values) in one or more fields in which non-empty
760     * values are required.
761     *
762     * This is a test of code and/or configuration in the service's
763     * validation routine(s).
764     *
765     * @param testName  The name of this test method.  This name is supplied
766     *     automatically, via reflection, by a TestNG 'data provider' in
767     *     a base class.
768     * @throws Exception 
769     */
770     // @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) // REM - Disabled this test because of issues raised in CSPACE-6705
771     public void updateWithRequiredValuesNullOrEmpty(String testName) throws Exception {
772         // Read an existing record for updating.
773         Response res = updateRetrieve(testName, knownResourceId);
774         CollectionobjectsCommon collectionObjectCommon = null;
775         try {
776                 // Extract its common part.
777                 collectionObjectCommon = extractCommonPartValue(res);
778         } finally {
779                 res.close();
780         }
781
782         // Update the common part with invalid content, by setting a value to
783         // the empty String, in a field that requires a non-empty value,
784         // as enforced by the service's validation routine(s).
785         collectionObjectCommon.setObjectNumber("");
786
787         if (logger.isDebugEnabled()) {
788             logger.debug(testName + " updated object");
789             logger.debug(objectAsXmlString(collectionObjectCommon,
790                     CollectionobjectsCommon.class));
791         }
792
793         // Submit the request to the service and store the response.
794         setupUpdate();
795         PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
796         CollectionObjectClient client = new CollectionObjectClient();
797         output.addPart(client.getCommonPartName(), collectionObjectCommon);
798         res = client.update(knownResourceId, output);
799         
800         try {
801                 int statusCode = res.getStatus();
802                 // Read the response and verify that the update attempt failed.
803                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
804                         invalidStatusCodeMessage(testRequestType, statusCode));
805                 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
806         } finally {
807                 res.close();
808         }
809     }
810
811     // ---------------------------------------------------------------
812     // CRUD tests : DELETE tests
813     // ---------------------------------------------------------------
814     // Success outcomes
815     
816     @Override
817     public void delete(String testName) throws Exception {
818         //
819         // Create an object to delete, save the current 'knownResourceId' since we don't want to delete it yet
820         // and temporarily set it to the csid of the resource we just created.
821         //
822         String tempCsid = knownResourceId;
823         // the super.delete() method uses the knownResourceId member
824         knownResourceId = newCollectionObject(true);
825         
826         try {
827                 super.delete(testName);
828         } finally {
829                 // reset the 'knownResourceId'
830                 knownResourceId = tempCsid;
831         }        
832     }
833
834     //
835     // Expected failure outcome tests
836     //
837
838     @Override
839     public void deleteNonExistent(String testName) throws Exception {
840         // Perform setup.
841         setupDeleteNonExistent();
842
843         // Submit the request to the service and store the response.
844         CollectionObjectClient client = new CollectionObjectClient();
845         Response res = client.delete(NON_EXISTENT_ID);
846         try {
847                 int statusCode = res.getStatus();
848         
849                 // Check the status code of the response: does it match
850                 // the expected response(s)?
851                 if (logger.isDebugEnabled()) {
852                     logger.debug(testName + ": status = " + statusCode);
853                 }
854                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
855                         invalidStatusCodeMessage(testRequestType, statusCode));
856                 Assert.assertEquals(statusCode, testExpectedStatusCode);
857         } finally {
858                 res.close();
859         }
860     }
861
862     // ---------------------------------------------------------------
863     // Utility tests : tests of code used in tests above
864     // ---------------------------------------------------------------
865     
866     /**
867      * Tests the code for manually submitting data that is used by several
868      * of the methods above.
869      * @throws Exception 
870      */
871
872     // ---------------------------------------------------------------
873     // Utility methods used by tests above
874     // ---------------------------------------------------------------
875         
876     private Response newCollectionObject() throws Exception {
877         Response result = null;
878         
879         CollectionObjectClient client = new CollectionObjectClient();
880         String identifier = createIdentifier();
881         PoxPayloadOut multipart =
882                 createInstance(client.getCommonPartName(), identifier);
883         result = client.create(multipart);
884         
885         return result;
886     }
887     
888     private String newCollectionObject(boolean assertStatus) throws Exception {
889         String result = null;
890         
891         Response res = newCollectionObject();
892         try {
893                 int statusCode = res.getStatus();
894                 Assert.assertEquals(statusCode, STATUS_CREATED);
895                 result = extractId(res);
896         } finally {
897                 res.close();
898         }
899
900         return result;
901     }
902             
903     @Override
904     protected PoxPayloadOut createInstance(String identifier) {
905         String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME;
906         return createInstance(commonPartName, identifier);
907     }
908     
909     /**
910      * Creates the collection object instance.
911      *
912      * @param commonPartName the common part name
913      * @param identifier the identifier
914      * @return the multipart output
915      */
916     @Override
917     protected PoxPayloadOut createInstance(String commonPartName,
918             String identifier) {
919         return createCollectionObjectInstance(commonPartName,
920                 "objectNumber-" + identifier,
921                 "objectName-" + identifier);
922     }
923
924     /**
925      * Creates the collection object instance.
926      *
927      * @param commonPartName the common part name
928      * @param objectNumber the object number
929      * @param objectName the object name
930      * @return the multipart output
931      */
932     private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
933             String objectNumber, String objectName) {
934         CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
935
936         // Scalar fields
937         collectionObject.setObjectNumber(objectNumber);
938         collectionObject.setAge(AGE_VALUE); //test for null string
939         
940         // Repeatable structured groups
941
942         TitleGroupList titleGroupList = new TitleGroupList();
943         List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
944         Assert.assertNotNull(titleGroups);
945         TitleGroup titleGroup = new TitleGroup();
946         titleGroup.setTitle("a title");
947         titleGroups.add(titleGroup);
948         collectionObject.setTitleGroupList(titleGroupList);
949
950         ObjectNameList objNameList = new ObjectNameList();
951         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
952         ObjectNameGroup objectNameGroup = new ObjectNameGroup();
953         objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
954         objNameGroups.add(objectNameGroup);
955         collectionObject.setObjectNameList(objNameList);
956
957         MeasuredPartGroupList measuredPartGroupList = new MeasuredPartGroupList();
958         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
959         Assert.assertNotNull(measuredPartGroups, "Measured part groups are null");
960         MeasuredPartGroup measuredPartGroup = new MeasuredPartGroup();
961         measuredPartGroup.setMeasuredPart(MEASURED_PART);
962
963         DimensionSubGroupList dimensionSubGroupList = new DimensionSubGroupList();
964         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
965         Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups are null");
966
967         DimensionSubGroup lengthDimension = new DimensionSubGroup();
968         lengthDimension.setDimension("length");
969         lengthDimension.setValue(DIMENSION_VALUE_LENGTH);
970         lengthDimension.setMeasurementUnit("cm");
971         dimensionSubGroups.add(lengthDimension);
972         
973         DimensionSubGroup widthDimension = new DimensionSubGroup();
974         widthDimension.setDimension("width");
975         widthDimension.setValue(DIMENSION_VALUE_WIDTH);
976         widthDimension.setMeasurementUnit("m");
977         widthDimension.setValueQualifier(""); // test empty string
978         dimensionSubGroups.add(widthDimension);
979         
980         measuredPartGroup.setDimensionSubGroupList(dimensionSubGroupList);
981         measuredPartGroups.add(measuredPartGroup);
982         collectionObject.setMeasuredPartGroupList(measuredPartGroupList);
983
984         // Repeatable scalar fields
985         
986         BriefDescriptionList descriptionList = new BriefDescriptionList();
987         List<String> descriptions = descriptionList.getBriefDescription();
988         descriptions.add("Papier mache bird cow mask with horns, "
989                 + "painted red with black and yellow spots. "
990                 + "Puerto Rico. ca. 8&quot; high, 6&quot; wide, projects 10&quot; (with horns).");
991         descriptions.add("Acrylic rabbit mask with wings, "
992                 + "painted red with green and aquamarine spots. "
993                 + "Puerto Rico. ca. 8&quot; high, 6&quot; wide, projects 10&quot; (with wings).");
994         collectionObject.setBriefDescriptions(descriptionList);
995
996         ResponsibleDepartmentList deptList = new ResponsibleDepartmentList();
997         List<String> depts = deptList.getResponsibleDepartment();
998         // @TODO Use properly formatted refNames for representative departments
999         // in this example test record. The following are mere placeholders.
1000         depts.add("urn:org.collectionspace.services.department:Registrar");
1001         depts.add("urn:org.walkerart.department:Fine Art");
1002         collectionObject.setResponsibleDepartments(deptList);
1003
1004         OtherNumberList otherNumList = new OtherNumberList();
1005         List<OtherNumber> otherNumbers = otherNumList.getOtherNumber();
1006         OtherNumber otherNumber1 = new OtherNumber();        
1007         otherNumber1.setNumberValue("101." + objectName);
1008         otherNumber1.setNumberType("integer");
1009         otherNumbers.add(otherNumber1);
1010         OtherNumber otherNumber2 = new OtherNumber();
1011         otherNumber2.setNumberValue("101.502.23.456." + objectName);
1012         otherNumber2.setNumberType("ipaddress");
1013         otherNumbers.add(otherNumber2);
1014         collectionObject.setOtherNumberList(otherNumList);
1015
1016         // Add instances of fields from an extension schema
1017
1018         CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
1019       // Laramie20110524 removed for build:   conh.setNhString("test-string");
1020       // Laramie20110524 removed for build:   conh.setNhInt(999);
1021       // Laramie20110524 removed for build:   conh.setNhLong(9999);
1022
1023         PoxPayloadOut multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
1024         return multipart;
1025     }
1026
1027     /**
1028      * Creates the collection object instance.
1029      *
1030      * @param commonPartName the common part name
1031      * @param collectionObject the collection object
1032      * @param conh the conh
1033      * @return the multipart output
1034      */
1035     private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1036             CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
1037
1038         PoxPayloadOut multipart = CollectionObjectFactory.createCollectionObjectInstance(
1039                 commonPartName, collectionObject, getNHPartName(), conh);
1040         if (logger.isDebugEnabled()) {
1041             logger.debug("to be created, collectionobject common");
1042             logger.debug(objectAsXmlString(collectionObject,
1043                     CollectionobjectsCommon.class));
1044         }
1045
1046         if (conh != null) {
1047             if (logger.isDebugEnabled()) {
1048                 logger.debug("to be created, collectionobject nhistory");
1049                 logger.debug(objectAsXmlString(conh,
1050                         CollectionobjectsNaturalhistory.class));
1051             }
1052         }
1053         
1054         return multipart;
1055     }
1056
1057     /**
1058      * createCollectionObjectInstanceFromXml uses JAXB unmarshaller to retrieve
1059      * collectionobject from given file
1060      * @param commonPartName
1061      * @param commonPartFileName
1062      * @return
1063      * @throws Exception
1064      */
1065     private PoxPayloadOut createCollectionObjectInstanceFromXml(String testName, String commonPartName,
1066             String commonPartFileName) throws Exception {
1067
1068         CollectionobjectsCommon collectionObject =
1069                 (CollectionobjectsCommon) getObjectFromFile(CollectionobjectsCommon.class,
1070                 commonPartFileName);
1071         PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1072         PayloadOutputPart commonPart = multipart.addPart(collectionObject,
1073                 MediaType.APPLICATION_XML_TYPE);
1074         CollectionObjectClient client = new CollectionObjectClient();
1075         commonPart.setLabel(client.getCommonPartName());
1076
1077         if (logger.isDebugEnabled()) {
1078             logger.debug(testName + " to be created, collectionobject common");
1079             logger.debug(objectAsXmlString(collectionObject,
1080                     CollectionobjectsCommon.class));
1081         }
1082         
1083         return multipart;
1084     }
1085
1086     /**
1087      * createCollectionObjectInstanceFromRawXml uses stringified collectionobject
1088      * retrieve from given file
1089      * @param commonPartName
1090      * @param commonPartFileName
1091      * @return
1092      * @throws Exception
1093      */
1094     private PoxPayloadOut createCollectionObjectInstanceFromRawXml(String testName, String commonPartName,
1095             String commonPartFileName) throws Exception {
1096
1097         PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1098         String stringObject = getXmlDocumentAsString(commonPartFileName);
1099         if (logger.isDebugEnabled()) {
1100             logger.debug(testName + " to be created, collectionobject common " + "\n" + stringObject);
1101         }
1102         PayloadOutputPart commonPart = multipart.addPart(commonPartName, stringObject);
1103 //        commonPart.setLabel(commonPartName);
1104
1105         return multipart;
1106     }
1107
1108     /**
1109      * Gets the nH part name.
1110      *
1111      * @return the nH part name
1112      */
1113     private String getNHPartName() {
1114         return "collectionobjects_naturalhistory";
1115     }
1116
1117     /**
1118      * Creates the from xml file.
1119      *
1120      * @param testName the test name
1121      * @param fileName the file name
1122      * @param useJaxb the use jaxb
1123      * @return the string
1124      * @throws Exception the exception
1125      */
1126     private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
1127         // Perform setup.
1128         setupCreate();
1129
1130         PoxPayloadOut multipart = null;
1131
1132         CollectionObjectClient client = new CollectionObjectClient();
1133         if (useJaxb) {
1134             multipart = createCollectionObjectInstanceFromXml(testName,
1135                     client.getCommonPartName(), fileName);
1136         } else {
1137             multipart = createCollectionObjectInstanceFromRawXml(testName,
1138                     client.getCommonPartName(), fileName);
1139         }
1140         
1141         Response res = client.create(multipart);
1142         String newId = null;
1143         try {
1144                 int statusCode = res.getStatus();
1145                 if (logger.isDebugEnabled()) {
1146                     logger.debug(testName + ": status = " + statusCode);
1147                 }
1148                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1149                         invalidStatusCodeMessage(testRequestType, statusCode));
1150                 Assert.assertEquals(statusCode, testExpectedStatusCode);
1151                 newId = extractId(res);
1152                 allResourceIdsCreated.add(newId);
1153         } finally {
1154                 res.close();
1155         }
1156         
1157         return newId;
1158     }
1159
1160     // FIXME: This duplicates code in read(), and should be consolidated.
1161     // This is an expedient to support reading and verifying the contents
1162     // of resources that have been created from test data XML files.
1163     private CollectionobjectsCommon readCollectionObjectCommonPart(String csid)
1164         throws Exception {
1165
1166         String testName = "readCollectionObjectCommonPart";
1167
1168         setupRead();
1169
1170         // Submit the request to the service and store the response.
1171         CollectionObjectClient client = new CollectionObjectClient();
1172         Response res = client.read(csid);
1173         CollectionobjectsCommon collectionObject = null;
1174         try {
1175                 int statusCode = res.getStatus();
1176         
1177                 // Check the status code of the response: does it match
1178                 // the expected response(s)?
1179                 if (logger.isDebugEnabled()) {
1180                     logger.debug(testName + ": status = " + statusCode);
1181                 }
1182                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1183                         invalidStatusCodeMessage(testRequestType, statusCode));
1184                 Assert.assertEquals(statusCode, testExpectedStatusCode);
1185         
1186                 // Extract the common part.
1187                 collectionObject = extractCommonPartValue(res);
1188                 Assert.assertNotNull(collectionObject);
1189         } finally {
1190                 res.close();
1191         }
1192
1193         return collectionObject;
1194      }
1195
1196         @Override
1197         protected String getServicePathComponent() {
1198                 // TODO Auto-generated method stub
1199                 return CollectionObjectClient.SERVICE_PATH_COMPONENT;
1200         }
1201
1202         @Override
1203         protected CollectionobjectsCommon updateInstance(CollectionobjectsCommon collectionObjectCommon) {
1204         collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber());
1205
1206         // Change the object name in the first value instance in the
1207         // object name repeatable group.
1208         ObjectNameList objNameList = collectionObjectCommon.getObjectNameList();
1209         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1210         Assert.assertNotNull(objNameGroups);
1211         Assert.assertTrue(objNameGroups.size() >= 1);
1212         String objectName = objNameGroups.get(0).getObjectName();
1213         Assert.assertEquals(objectName, OBJECT_NAME_VALUE);
1214         String updatedObjectName = "updated-" + objectName;
1215         objNameGroups.get(0).setObjectName(updatedObjectName);
1216         collectionObjectCommon.setObjectNameList(objNameList);
1217
1218         // Replace the existing value instances in the dimensions repeatable group
1219         // with entirely new value instances, also changing the number of such instances.
1220         MeasuredPartGroupList measuredPartGroupList = collectionObjectCommon.getMeasuredPartGroupList();
1221         Assert.assertNotNull(measuredPartGroupList);
1222         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1223         Assert.assertNotNull(measuredPartGroups);
1224         Assert.assertTrue(measuredPartGroups.size() > 0);
1225         MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1226         Assert.assertNotNull(mpGroup.getMeasuredPart());
1227         
1228         DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1229         Assert.assertNotNull(dimensionSubGroupList);
1230         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1231         Assert.assertNotNull(dimensionSubGroups);
1232         int originalDimensionSubGroupSize = dimensionSubGroups.size();
1233         Assert.assertTrue(dimensionSubGroups.size() > 0);
1234         dimensionSubGroups.clear();
1235         
1236         DimensionSubGroup heightDimension = new DimensionSubGroup();
1237         heightDimension.setDimension("height");
1238         heightDimension.setMeasurementUnit(UPDATED_MEASUREMENT_UNIT);
1239         dimensionSubGroups.add(heightDimension);
1240         
1241         int updatedDimensionGroupSize = dimensionSubGroups.size();
1242         Assert.assertTrue(updatedDimensionGroupSize > 0);
1243         Assert.assertTrue(updatedDimensionGroupSize != originalDimensionSubGroupSize);
1244         
1245         collectionObjectCommon.setMeasuredPartGroupList(measuredPartGroupList);
1246         
1247         return collectionObjectCommon;
1248         }
1249
1250         @Override
1251         protected void compareReadInstances(CollectionobjectsCommon original,
1252                         CollectionobjectsCommon fromRead) throws Exception {
1253                 // Verify the number and contents of values in repeatable fields,
1254                 // as created in the instance record used for testing.
1255                 MeasuredPartGroupList measuredPartGroupList = fromRead.getMeasuredPartGroupList();
1256                 Assert.assertNotNull(measuredPartGroupList, "Measured part group list was null");
1257                 List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1258                 Assert.assertNotNull(measuredPartGroups, "Measured part groups were null");
1259                 Assert.assertTrue(measuredPartGroups.size() > 0, "No measured part groups were returned");
1260                 MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1261                 Assert.assertNotNull(mpGroup.getMeasuredPart(), "Measured part was null");
1262                 Assert.assertEquals(mpGroup.getMeasuredPart(), MEASURED_PART,
1263                                 "Measured part value returned didn't match expected value");
1264
1265                 DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1266                 Assert.assertNotNull(dimensionSubGroupList, "Dimension subgroup list was null");
1267                 List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1268                 Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups were null");
1269                 Assert.assertTrue(dimensionSubGroups.size() > 0, "No dimension subgroups were returned");
1270                 DimensionSubGroup lengthDimension = dimensionSubGroups.get(0);
1271                 Assert.assertNotNull(lengthDimension, "Length dimension was null");
1272                 Assert.assertTrue(lengthDimension.getValue().compareTo(DIMENSION_VALUE_LENGTH) == 0,
1273                                 "Dimension length value returned didn't match expected value");
1274         }
1275         
1276         @Override
1277         protected void compareUpdatedInstances(CollectionobjectsCommon original,
1278                         CollectionobjectsCommon updated) throws Exception {
1279                 
1280         ObjectNameList objNameList = updated.getObjectNameList();
1281         Assert.assertNotNull(objNameList);
1282         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1283         Assert.assertNotNull(objNameGroups);
1284         Assert.assertTrue(objNameGroups.size() >= 1);
1285         Assert.assertEquals(original.getObjectNameList().getObjectNameGroup().get(0).getObjectName(),
1286                 objNameGroups.get(0).getObjectName(),
1287                 "Data in updated object did not match submitted data.");
1288         //
1289         // Get the dimension group size of the original
1290         //
1291         MeasuredPartGroupList measuredPartGroupList = original.getMeasuredPartGroupList();
1292         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1293         MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1294         DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1295         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1296         int updatedDimensionGroupSize = dimensionSubGroups.size();
1297         //
1298         // Now get the dimension group size of the updated
1299         //
1300         measuredPartGroupList = updated.getMeasuredPartGroupList();
1301         Assert.assertNotNull(measuredPartGroupList);
1302         measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1303         Assert.assertNotNull(measuredPartGroups);
1304         Assert.assertTrue(measuredPartGroups.size() > 0);
1305         mpGroup = measuredPartGroups.get(0);
1306         Assert.assertNotNull(mpGroup.getMeasuredPart());
1307         dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1308         Assert.assertNotNull(dimensionSubGroupList);
1309         dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1310         Assert.assertNotNull(dimensionSubGroups);
1311                 Assert.assertTrue(dimensionSubGroups.size() == updatedDimensionGroupSize);
1312                 
1313         Assert.assertEquals(UPDATED_MEASUREMENT_UNIT,
1314                 dimensionSubGroups.get(0).getMeasurementUnit(),
1315                 "Data in updated object did not match submitted data.");
1316         }
1317 }