]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1ab3c75d3dc9ea2270faae1adcf130e6b5fdccd5
[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         ClientResponse<Response> res = client.create(multipart);
483         int statusCode = res.getStatus();
484
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
493         // FIXME: Consider splitting off the following into its own test method.
494         
495         // Build a payload with invalid content, by setting a value to the
496         // empty String, in a field (objectNumber) that requires a non-empty
497         // value, as enforced by the service's validation routine(s).
498         collectionObject = new CollectionobjectsCommon();
499         collectionObject.setObjectNumber("");
500         collectionObject.setDistinguishingFeatures("Distinguishing features.");
501
502         objNameList = new ObjectNameList();
503         objNameGroups = objNameList.getObjectNameGroup();
504         objectNameGroup = new ObjectNameGroup();
505         objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
506         objNameGroups.add(objectNameGroup);
507         collectionObject.setObjectNameList(objNameList);
508
509         // Submit the request to the service and store the response.
510         multipart =
511             createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
512         res = client.create(multipart);
513         statusCode = res.getStatus();
514
515         // Read the response and verify that the create attempt failed.
516         if (logger.isDebugEnabled()) {
517             logger.debug(testName + ": status = " + statusCode);
518         }
519         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
520                 invalidStatusCodeMessage(testRequestType, statusCode));
521         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
522     }
523     
524     /**
525      * Update retrieve.
526      *
527      * @param testName the test name
528      * @param id the id
529      * @return the client response
530      */
531     private ClientResponse<String> updateRetrieve(String testName, String id) {
532         setupRead();
533         CollectionObjectClient client = new CollectionObjectClient();
534         ClientResponse<String> res = client.read(knownResourceId);
535         int statusCode = res.getStatus();
536         // Check the status code of the response: does it match
537         // the expected response(s)?
538         if (logger.isDebugEnabled()) {
539             logger.debug(testName + ": read status = " + statusCode);
540         }
541         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
542                 invalidStatusCodeMessage(testRequestType, statusCode));
543         Assert.assertEquals(statusCode, testExpectedStatusCode);
544         if(logger.isDebugEnabled()){
545             logger.debug("got object to update with ID: " + knownResourceId);
546         }
547         return res;
548     }
549
550     /**
551      * Update send.
552      *
553      * @param testName the test name
554      * @param id the id
555      * @return the client response
556      */
557     private ClientResponse<String> updateSend(String testName, String id,
558             CollectionobjectsCommon collectionObjectCommon) {
559         setupUpdate();
560         PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
561         PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE);
562         CollectionObjectClient client = new CollectionObjectClient();
563         commonPart.setLabel(client.getCommonPartName());
564         ClientResponse<String> res = client.update(knownResourceId, output);
565         int statusCode = res.getStatus();
566         // Check the status code of the response: does it match
567         // the expected response(s)?
568         if (logger.isDebugEnabled()) {
569             logger.debug(testName + ": read status = " + statusCode);
570         }
571         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
572                 invalidStatusCodeMessage(testRequestType, statusCode));
573         Assert.assertEquals(statusCode, testExpectedStatusCode);
574         return res;
575     }
576
577     // Failure outcomes
578     // Placeholders until the three tests below can be uncommented.
579     // See Issue CSPACE-401.
580     /* (non-Javadoc)
581      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
582      */
583     @Override
584     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
585         dependsOnMethods = {"CRUDTests"})
586     public void updateWithEmptyEntityBody(String testName) throws Exception {
587         //FIXME: Should this test really be empty?
588     }
589
590    /**
591     * Test how the service handles XML that is not well formed,
592     * when sent in the payload of an Update request.
593     *
594     * @param testName  The name of this test method.  This name is supplied
595     *     automatically, via reflection, by a TestNG 'data provider' in
596     *     a base class.
597     */
598     @Override
599     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
600         dependsOnMethods = {"CRUDTests"})
601     public void updateWithMalformedXml(String testName) throws Exception {
602         //FIXME: Should this test really be empty?
603     }
604
605     /* (non-Javadoc)
606      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
607      */
608     @Override
609     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
610         dependsOnMethods = {"CRUDTests"})
611     public void updateWithWrongXmlSchema(String testName) throws Exception {
612         //FIXME: Should this test really be empty?
613     }
614
615 /*
616     @Override
617     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
618     dependsOnMethods = {"create", "update", "testSubmitRequest"})
619     public void updateWithEmptyEntityBody(String testName) throws Exception {
620
621         if (logger.isDebugEnabled()) {
622             logger.debug(testBanner(testName, CLASS_NAME));
623         }
624         // Perform setup.
625         setupUpdateWithEmptyEntityBody();
626
627         // Submit the request to the service and store the response.
628         String method = REQUEST_TYPE.httpMethodName();
629         String url = getResourceURL(knownResourceId);
630         String mediaType = MediaType.APPLICATION_XML;
631         final String entity = "";
632         int statusCode = submitRequest(method, url, mediaType, entity);
633
634         // Check the status code of the response: does it match
635         // the expected response(s)?
636         if(logger.isDebugEnabled()){
637         logger.debug(testName + ": url=" + url +
638         " status=" + statusCode);
639         }
640         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
643     }
644
645     @Override
646     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
647     dependsOnMethods = {"create", "update", "testSubmitRequest"})
648     public void updateWithMalformedXml() throws Exception {
649
650         if (logger.isDebugEnabled()) {
651             logger.debug(testBanner(testName, CLASS_NAME));
652         }
653         // Perform setup.
654         setupUpdateWithMalformedXml();
655
656         // Submit the request to the service and store the response.
657         String method = REQUEST_TYPE.httpMethodName();
658         String url = getResourceURL(knownResourceId);
659         final String entity = MALFORMED_XML_DATA;
660         String mediaType = MediaType.APPLICATION_XML;
661         int statusCode = submitRequest(method, url, mediaType, entity);
662
663         // Check the status code of the response: does it match
664         // the expected response(s)?
665         if(logger.isDebugEnabled()){
666         logger.debug(testName + ": url=" + url +
667         " status=" + statusCode);
668         }
669         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
672     }
673
674     @Override
675     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
676     dependsOnMethods = {"create", "update", "testSubmitRequest"})
677     public void updateWithWrongXmlSchema(String testName) throws Exception {
678
679         if (logger.isDebugEnabled()) {
680             logger.debug(testBanner(testName, CLASS_NAME));
681         }
682         // Perform setup.
683         setupUpdateWithWrongXmlSchema();
684
685         // Submit the request to the service and store the response.
686         String method = REQUEST_TYPE.httpMethodName();
687         String url = getResourceURL(knownResourceId);
688         String mediaType = MediaType.APPLICATION_XML;
689         final String entity = WRONG_XML_SCHEMA_DATA;
690         int statusCode = submitRequest(method, url, mediaType, entity);
691
692         // Check the status code of the response: does it match
693         // the expected response(s)?
694         if(logger.isDebugEnabled()){
695         logger.debug(testName + ": url=" + url +
696         " status=" + statusCode);
697         }
698         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701     }
702 */
703
704     @Override
705     public void updateNonExistent(String testName) throws Exception {
706         // Perform setup.
707         setupUpdateNonExistent();
708
709         // Submit the request to the service and store the response.
710         //
711         // Note: The ID used in this 'create' call may be arbitrary.
712         // The only relevant ID may be the one used in updateCollectionObject(), below.
713         CollectionObjectClient client = new CollectionObjectClient();
714         PoxPayloadOut multipart =
715                 createInstance(client.getCommonPartName(), NON_EXISTENT_ID);
716         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
717         int statusCode = res.getStatus();
718
719         // Check the status code of the response: does it match
720         // the expected response(s)?
721         if (logger.isDebugEnabled()) {
722             logger.debug(testName + ": status = " + statusCode);
723         }
724         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
725                 invalidStatusCodeMessage(testRequestType, statusCode));
726         Assert.assertEquals(statusCode, testExpectedStatusCode);
727     }
728
729    /**
730     * Test how the service handles, in an Update request, payloads
731     * containing null values (or, in the case of String fields,
732     * empty String values) in one or more fields in which non-empty
733     * values are required.
734     *
735     * This is a test of code and/or configuration in the service's
736     * validation routine(s).
737     *
738     * @param testName  The name of this test method.  This name is supplied
739     *     automatically, via reflection, by a TestNG 'data provider' in
740     *     a base class.
741     * @throws Exception 
742     */
743     @Test(dataProvider = "testName",
744                 dependsOnMethods = {"CRUDTests"})
745     public void updateWithRequiredValuesNullOrEmpty(String testName) throws Exception {
746         // Read an existing record for updating.
747         ClientResponse<String> res = updateRetrieve(testName, knownResourceId);
748         CollectionobjectsCommon collectionObjectCommon = null;
749         try {
750                 // Extract its common part.
751                 collectionObjectCommon = extractCommonPartValue(res);
752         } finally {
753                 res.releaseConnection();
754         }
755
756         // Update the common part with invalid content, by setting a value to
757         // the empty String, in a field that requires a non-empty value,
758         // as enforced by the service's validation routine(s).
759         collectionObjectCommon.setObjectNumber("");
760
761         if (logger.isDebugEnabled()) {
762             logger.debug(testName + " updated object");
763             logger.debug(objectAsXmlString(collectionObjectCommon,
764                     CollectionobjectsCommon.class));
765         }
766
767         // Submit the request to the service and store the response.
768         setupUpdate();
769         PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
770         CollectionObjectClient client = new CollectionObjectClient();
771         output.addPart(client.getCommonPartName(), collectionObjectCommon);
772         res = client.update(knownResourceId, output);
773         
774         try {
775                 int statusCode = res.getStatus();
776                 // Read the response and verify that the update attempt failed.
777                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
778                         invalidStatusCodeMessage(testRequestType, statusCode));
779                 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
780         } finally {
781                 res.releaseConnection();
782         }
783     }
784
785     // ---------------------------------------------------------------
786     // CRUD tests : DELETE tests
787     // ---------------------------------------------------------------
788     // Success outcomes
789     
790     @Override
791     public void delete(String testName) throws Exception {
792         //
793         // Create an object to delete, save the current 'knownResourceId' since we don't want to delete it yet
794         // and temporarily set it to the csid of the resource we just created.
795         //
796         String tempCsid = knownResourceId;
797         // the super.delete() method uses the knownResourceId member
798         knownResourceId = newCollectionObject(true);
799         
800         try {
801                 super.delete(testName);
802         } finally {
803                 // reset the 'knownResourceId'
804                 knownResourceId = tempCsid;
805         }        
806     }
807
808     //
809     // Expected failure outcome tests
810     //
811
812     @Override
813     public void deleteNonExistent(String testName) throws Exception {
814         // Perform setup.
815         setupDeleteNonExistent();
816
817         // Submit the request to the service and store the response.
818         CollectionObjectClient client = new CollectionObjectClient();
819         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
820         try {
821                 int statusCode = res.getStatus();
822         
823                 // Check the status code of the response: does it match
824                 // the expected response(s)?
825                 if (logger.isDebugEnabled()) {
826                     logger.debug(testName + ": status = " + statusCode);
827                 }
828                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
829                         invalidStatusCodeMessage(testRequestType, statusCode));
830                 Assert.assertEquals(statusCode, testExpectedStatusCode);
831         } finally {
832                 res.releaseConnection();
833         }
834     }
835
836     // ---------------------------------------------------------------
837     // Utility tests : tests of code used in tests above
838     // ---------------------------------------------------------------
839     
840     /**
841      * Tests the code for manually submitting data that is used by several
842      * of the methods above.
843      * @throws Exception 
844      */
845
846     // ---------------------------------------------------------------
847     // Utility methods used by tests above
848     // ---------------------------------------------------------------
849         
850     private ClientResponse<Response> newCollectionObject() {
851         ClientResponse<Response> result = null;
852         
853         CollectionObjectClient client = new CollectionObjectClient();
854         String identifier = createIdentifier();
855         PoxPayloadOut multipart =
856                 createInstance(client.getCommonPartName(), identifier);
857         result = client.create(multipart);
858         
859         return result;
860     }
861     
862     private String newCollectionObject(boolean assertStatus) {
863         String result = null;
864         
865         ClientResponse<Response> res = newCollectionObject();
866         try {
867                 int statusCode = res.getStatus();
868                 Assert.assertEquals(statusCode, STATUS_CREATED);
869                 result = extractId(res);
870         } finally {
871                 res.releaseConnection();
872         }
873
874         return result;
875     }
876             
877     @Override
878     protected PoxPayloadOut createInstance(String identifier) {
879         String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME;
880         return createInstance(commonPartName, identifier);
881     }
882     
883     /**
884      * Creates the collection object instance.
885      *
886      * @param commonPartName the common part name
887      * @param identifier the identifier
888      * @return the multipart output
889      */
890     @Override
891     protected PoxPayloadOut createInstance(String commonPartName,
892             String identifier) {
893         return createCollectionObjectInstance(commonPartName,
894                 "objectNumber-" + identifier,
895                 "objectName-" + identifier);
896     }
897
898     /**
899      * Creates the collection object instance.
900      *
901      * @param commonPartName the common part name
902      * @param objectNumber the object number
903      * @param objectName the object name
904      * @return the multipart output
905      */
906     private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
907             String objectNumber, String objectName) {
908         CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
909
910         // Scalar fields
911         collectionObject.setObjectNumber(objectNumber);
912         collectionObject.setAge(AGE_VALUE); //test for null string
913         
914         // Repeatable structured groups
915
916         TitleGroupList titleGroupList = new TitleGroupList();
917         List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
918         Assert.assertNotNull(titleGroups);
919         TitleGroup titleGroup = new TitleGroup();
920         titleGroup.setTitle("a title");
921         titleGroups.add(titleGroup);
922         collectionObject.setTitleGroupList(titleGroupList);
923
924         ObjectNameList objNameList = new ObjectNameList();
925         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
926         ObjectNameGroup objectNameGroup = new ObjectNameGroup();
927         objectNameGroup.setObjectName(OBJECT_NAME_VALUE);
928         objNameGroups.add(objectNameGroup);
929         collectionObject.setObjectNameList(objNameList);
930
931         MeasuredPartGroupList measuredPartGroupList = new MeasuredPartGroupList();
932         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
933         Assert.assertNotNull(measuredPartGroups, "Measured part groups are null");
934         MeasuredPartGroup measuredPartGroup = new MeasuredPartGroup();
935         measuredPartGroup.setMeasuredPart(MEASURED_PART);
936
937         DimensionSubGroupList dimensionSubGroupList = new DimensionSubGroupList();
938         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
939         Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups are null");
940
941         DimensionSubGroup lengthDimension = new DimensionSubGroup();
942         lengthDimension.setDimension("length");
943         lengthDimension.setValue(DIMENSION_VALUE_LENGTH);
944         lengthDimension.setMeasurementUnit("cm");
945         dimensionSubGroups.add(lengthDimension);
946         
947         DimensionSubGroup widthDimension = new DimensionSubGroup();
948         widthDimension.setDimension("width");
949         widthDimension.setValue(DIMENSION_VALUE_WIDTH);
950         widthDimension.setMeasurementUnit("m");
951         widthDimension.setValueQualifier(""); // test empty string
952         dimensionSubGroups.add(widthDimension);
953         
954         measuredPartGroup.setDimensionSubGroupList(dimensionSubGroupList);
955         measuredPartGroups.add(measuredPartGroup);
956         collectionObject.setMeasuredPartGroupList(measuredPartGroupList);
957
958         // Repeatable scalar fields
959         
960         BriefDescriptionList descriptionList = new BriefDescriptionList();
961         List<String> descriptions = descriptionList.getBriefDescription();
962         descriptions.add("Papier mache bird cow mask with horns, "
963                 + "painted red with black and yellow spots. "
964                 + "Puerto Rico. ca. 8&quot; high, 6&quot; wide, projects 10&quot; (with horns).");
965         descriptions.add("Acrylic rabbit mask with wings, "
966                 + "painted red with green and aquamarine spots. "
967                 + "Puerto Rico. ca. 8&quot; high, 6&quot; wide, projects 10&quot; (with wings).");
968         collectionObject.setBriefDescriptions(descriptionList);
969
970         ResponsibleDepartmentList deptList = new ResponsibleDepartmentList();
971         List<String> depts = deptList.getResponsibleDepartment();
972         // @TODO Use properly formatted refNames for representative departments
973         // in this example test record. The following are mere placeholders.
974         depts.add("urn:org.collectionspace.services.department:Registrar");
975         depts.add("urn:org.walkerart.department:Fine Art");
976         collectionObject.setResponsibleDepartments(deptList);
977
978         OtherNumberList otherNumList = new OtherNumberList();
979         List<OtherNumber> otherNumbers = otherNumList.getOtherNumber();
980         OtherNumber otherNumber1 = new OtherNumber();        
981         otherNumber1.setNumberValue("101." + objectName);
982         otherNumber1.setNumberType("integer");
983         otherNumbers.add(otherNumber1);
984         OtherNumber otherNumber2 = new OtherNumber();
985         otherNumber2.setNumberValue("101.502.23.456." + objectName);
986         otherNumber2.setNumberType("ipaddress");
987         otherNumbers.add(otherNumber2);
988         collectionObject.setOtherNumberList(otherNumList);
989
990         // Add instances of fields from an extension schema
991
992         CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
993       // Laramie20110524 removed for build:   conh.setNhString("test-string");
994       // Laramie20110524 removed for build:   conh.setNhInt(999);
995       // Laramie20110524 removed for build:   conh.setNhLong(9999);
996
997         PoxPayloadOut multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
998         return multipart;
999     }
1000
1001     /**
1002      * Creates the collection object instance.
1003      *
1004      * @param commonPartName the common part name
1005      * @param collectionObject the collection object
1006      * @param conh the conh
1007      * @return the multipart output
1008      */
1009     private PoxPayloadOut createCollectionObjectInstance(String commonPartName,
1010             CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
1011
1012         PoxPayloadOut multipart = CollectionObjectFactory.createCollectionObjectInstance(
1013                 commonPartName, collectionObject, getNHPartName(), conh);
1014         if (logger.isDebugEnabled()) {
1015             logger.debug("to be created, collectionobject common");
1016             logger.debug(objectAsXmlString(collectionObject,
1017                     CollectionobjectsCommon.class));
1018         }
1019
1020         if (conh != null) {
1021             if (logger.isDebugEnabled()) {
1022                 logger.debug("to be created, collectionobject nhistory");
1023                 logger.debug(objectAsXmlString(conh,
1024                         CollectionobjectsNaturalhistory.class));
1025             }
1026         }
1027         
1028         return multipart;
1029     }
1030
1031     /**
1032      * createCollectionObjectInstanceFromXml uses JAXB unmarshaller to retrieve
1033      * collectionobject from given file
1034      * @param commonPartName
1035      * @param commonPartFileName
1036      * @return
1037      * @throws Exception
1038      */
1039     private PoxPayloadOut createCollectionObjectInstanceFromXml(String testName, String commonPartName,
1040             String commonPartFileName) throws Exception {
1041
1042         CollectionobjectsCommon collectionObject =
1043                 (CollectionobjectsCommon) getObjectFromFile(CollectionobjectsCommon.class,
1044                 commonPartFileName);
1045         PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1046         PayloadOutputPart commonPart = multipart.addPart(collectionObject,
1047                 MediaType.APPLICATION_XML_TYPE);
1048         CollectionObjectClient client = new CollectionObjectClient();
1049         commonPart.setLabel(client.getCommonPartName());
1050
1051         if (logger.isDebugEnabled()) {
1052             logger.debug(testName + " to be created, collectionobject common");
1053             logger.debug(objectAsXmlString(collectionObject,
1054                     CollectionobjectsCommon.class));
1055         }
1056         
1057         return multipart;
1058     }
1059
1060     /**
1061      * createCollectionObjectInstanceFromRawXml uses stringified collectionobject
1062      * retrieve from given file
1063      * @param commonPartName
1064      * @param commonPartFileName
1065      * @return
1066      * @throws Exception
1067      */
1068     private PoxPayloadOut createCollectionObjectInstanceFromRawXml(String testName, String commonPartName,
1069             String commonPartFileName) throws Exception {
1070
1071         PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
1072         String stringObject = getXmlDocumentAsString(commonPartFileName);
1073         if (logger.isDebugEnabled()) {
1074             logger.debug(testName + " to be created, collectionobject common " + "\n" + stringObject);
1075         }
1076         PayloadOutputPart commonPart = multipart.addPart(commonPartName, stringObject);
1077 //        commonPart.setLabel(commonPartName);
1078
1079         return multipart;
1080     }
1081
1082     /**
1083      * Gets the nH part name.
1084      *
1085      * @return the nH part name
1086      */
1087     private String getNHPartName() {
1088         return "collectionobjects_naturalhistory";
1089     }
1090
1091     /**
1092      * Creates the from xml file.
1093      *
1094      * @param testName the test name
1095      * @param fileName the file name
1096      * @param useJaxb the use jaxb
1097      * @return the string
1098      * @throws Exception the exception
1099      */
1100     private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
1101   
1102         // Perform setup.
1103         setupCreate();
1104
1105         PoxPayloadOut multipart = null;
1106
1107         CollectionObjectClient client = new CollectionObjectClient();
1108         if (useJaxb) {
1109             multipart = createCollectionObjectInstanceFromXml(testName,
1110                     client.getCommonPartName(), fileName);
1111         } else {
1112             multipart = createCollectionObjectInstanceFromRawXml(testName,
1113                     client.getCommonPartName(), fileName);
1114         }
1115         ClientResponse<Response> res = client.create(multipart);
1116         int statusCode = res.getStatus();
1117
1118         if (logger.isDebugEnabled()) {
1119             logger.debug(testName + ": status = " + statusCode);
1120         }
1121         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1122                 invalidStatusCodeMessage(testRequestType, statusCode));
1123         Assert.assertEquals(statusCode, testExpectedStatusCode);
1124         String newId = extractId(res);
1125         allResourceIdsCreated.add(newId);
1126         return newId;
1127     }
1128
1129     // FIXME: This duplicates code in read(), and should be consolidated.
1130     // This is an expedient to support reading and verifying the contents
1131     // of resources that have been created from test data XML files.
1132     private CollectionobjectsCommon readCollectionObjectCommonPart(String csid)
1133         throws Exception {
1134
1135         String testName = "readCollectionObjectCommonPart";
1136
1137         setupRead();
1138
1139         // Submit the request to the service and store the response.
1140         CollectionObjectClient client = new CollectionObjectClient();
1141         ClientResponse<String> res = client.read(csid);
1142         int statusCode = res.getStatus();
1143
1144         // Check the status code of the response: does it match
1145         // the expected response(s)?
1146         if (logger.isDebugEnabled()) {
1147             logger.debug(testName + ": status = " + statusCode);
1148         }
1149         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1150                 invalidStatusCodeMessage(testRequestType, statusCode));
1151         Assert.assertEquals(statusCode, testExpectedStatusCode);
1152
1153         // Extract the common part.
1154         CollectionobjectsCommon collectionObject = extractCommonPartValue(res);
1155         Assert.assertNotNull(collectionObject);
1156
1157         return collectionObject;
1158      }
1159
1160         @Override
1161         protected String getServicePathComponent() {
1162                 // TODO Auto-generated method stub
1163                 return CollectionObjectClient.SERVICE_PATH_COMPONENT;
1164         }
1165
1166         @Override
1167         protected CollectionobjectsCommon updateInstance(CollectionobjectsCommon collectionObjectCommon) {
1168         collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber());
1169
1170         // Change the object name in the first value instance in the
1171         // object name repeatable group.
1172         ObjectNameList objNameList = collectionObjectCommon.getObjectNameList();
1173         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1174         Assert.assertNotNull(objNameGroups);
1175         Assert.assertTrue(objNameGroups.size() >= 1);
1176         String objectName = objNameGroups.get(0).getObjectName();
1177         Assert.assertEquals(objectName, OBJECT_NAME_VALUE);
1178         String updatedObjectName = "updated-" + objectName;
1179         objNameGroups.get(0).setObjectName(updatedObjectName);
1180         collectionObjectCommon.setObjectNameList(objNameList);
1181
1182         // Replace the existing value instances in the dimensions repeatable group
1183         // with entirely new value instances, also changing the number of such instances.
1184         MeasuredPartGroupList measuredPartGroupList = collectionObjectCommon.getMeasuredPartGroupList();
1185         Assert.assertNotNull(measuredPartGroupList);
1186         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1187         Assert.assertNotNull(measuredPartGroups);
1188         Assert.assertTrue(measuredPartGroups.size() > 0);
1189         MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1190         Assert.assertNotNull(mpGroup.getMeasuredPart());
1191         
1192         DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1193         Assert.assertNotNull(dimensionSubGroupList);
1194         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1195         Assert.assertNotNull(dimensionSubGroups);
1196         int originalDimensionSubGroupSize = dimensionSubGroups.size();
1197         Assert.assertTrue(dimensionSubGroups.size() > 0);
1198         dimensionSubGroups.clear();
1199         
1200         DimensionSubGroup heightDimension = new DimensionSubGroup();
1201         heightDimension.setDimension("height");
1202         heightDimension.setMeasurementUnit(UPDATED_MEASUREMENT_UNIT);
1203         dimensionSubGroups.add(heightDimension);
1204         
1205         int updatedDimensionGroupSize = dimensionSubGroups.size();
1206         Assert.assertTrue(updatedDimensionGroupSize > 0);
1207         Assert.assertTrue(updatedDimensionGroupSize != originalDimensionSubGroupSize);
1208         
1209         collectionObjectCommon.setMeasuredPartGroupList(measuredPartGroupList);
1210         
1211         return collectionObjectCommon;
1212         }
1213
1214         @Override
1215         protected void compareReadInstances(CollectionobjectsCommon original,
1216                         CollectionobjectsCommon fromRead) throws Exception {
1217                 // Verify the number and contents of values in repeatable fields,
1218                 // as created in the instance record used for testing.
1219                 MeasuredPartGroupList measuredPartGroupList = fromRead.getMeasuredPartGroupList();
1220                 Assert.assertNotNull(measuredPartGroupList, "Measured part group list was null");
1221                 List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1222                 Assert.assertNotNull(measuredPartGroups, "Measured part groups were null");
1223                 Assert.assertTrue(measuredPartGroups.size() > 0, "No measured part groups were returned");
1224                 MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1225                 Assert.assertNotNull(mpGroup.getMeasuredPart(), "Measured part was null");
1226                 Assert.assertEquals(mpGroup.getMeasuredPart(), MEASURED_PART,
1227                                 "Measured part value returned didn't match expected value");
1228
1229                 DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1230                 Assert.assertNotNull(dimensionSubGroupList, "Dimension subgroup list was null");
1231                 List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1232                 Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups were null");
1233                 Assert.assertTrue(dimensionSubGroups.size() > 0, "No dimension subgroups were returned");
1234                 DimensionSubGroup lengthDimension = dimensionSubGroups.get(0);
1235                 Assert.assertNotNull(lengthDimension, "Length dimension was null");
1236                 Assert.assertTrue(lengthDimension.getValue().compareTo(DIMENSION_VALUE_LENGTH) == 0,
1237                                 "Dimension length value returned didn't match expected value");
1238         }
1239         
1240         @Override
1241         protected void compareUpdatedInstances(CollectionobjectsCommon original,
1242                         CollectionobjectsCommon updated) throws Exception {
1243                 
1244         ObjectNameList objNameList = updated.getObjectNameList();
1245         Assert.assertNotNull(objNameList);
1246         List<ObjectNameGroup> objNameGroups = objNameList.getObjectNameGroup();
1247         Assert.assertNotNull(objNameGroups);
1248         Assert.assertTrue(objNameGroups.size() >= 1);
1249         Assert.assertEquals(original.getObjectNameList().getObjectNameGroup().get(0).getObjectName(),
1250                 objNameGroups.get(0).getObjectName(),
1251                 "Data in updated object did not match submitted data.");
1252         //
1253         // Get the dimension group size of the original
1254         //
1255         MeasuredPartGroupList measuredPartGroupList = original.getMeasuredPartGroupList();
1256         List<MeasuredPartGroup> measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1257         MeasuredPartGroup mpGroup = measuredPartGroups.get(0);
1258         DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1259         List<DimensionSubGroup> dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1260         int updatedDimensionGroupSize = dimensionSubGroups.size();
1261         //
1262         // Now get the dimension group size of the updated
1263         //
1264         measuredPartGroupList = updated.getMeasuredPartGroupList();
1265         Assert.assertNotNull(measuredPartGroupList);
1266         measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup();
1267         Assert.assertNotNull(measuredPartGroups);
1268         Assert.assertTrue(measuredPartGroups.size() > 0);
1269         mpGroup = measuredPartGroups.get(0);
1270         Assert.assertNotNull(mpGroup.getMeasuredPart());
1271         dimensionSubGroupList = mpGroup.getDimensionSubGroupList();
1272         Assert.assertNotNull(dimensionSubGroupList);
1273         dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup();
1274         Assert.assertNotNull(dimensionSubGroups);
1275                 Assert.assertTrue(dimensionSubGroups.size() == updatedDimensionGroupSize);
1276                 
1277         Assert.assertEquals(UPDATED_MEASUREMENT_UNIT,
1278                 dimensionSubGroups.get(0).getMeasurementUnit(),
1279                 "Data in updated object did not match submitted data.");
1280         }
1281 }