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