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