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