This project has retired. For details please refer to its Attic page.
TypeValidationTest xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.inmemory;
20  
21  import java.math.BigDecimal;
22  import java.math.BigInteger;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  import junit.framework.TestCase;
30  
31  import org.apache.chemistry.opencmis.commons.PropertyIds;
32  import org.apache.chemistry.opencmis.commons.data.Properties;
33  import org.apache.chemistry.opencmis.commons.data.PropertyData;
34  import org.apache.chemistry.opencmis.commons.definitions.Choice;
35  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
36  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
37  import org.apache.chemistry.opencmis.commons.enums.Cardinality;
38  import org.apache.chemistry.opencmis.commons.enums.Updatability;
39  import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
40  import org.apache.chemistry.opencmis.commons.impl.dataobjects.BindingsObjectFactoryImpl;
41  import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChoiceImpl;
42  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl;
43  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
44  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl;
45  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl;
46  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
47  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
48  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
49  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
50  import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
51  import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
52  import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
53  import org.apache.chemistry.opencmis.server.support.TypeManager;
54  import org.apache.chemistry.opencmis.server.support.TypeValidator;
55  import org.junit.Test;
56  
57  /**
58   * @author Jens
59   */
60  public class TypeValidationTest extends TestCase {
61  
62      private static final String MY_DOC_TYPE = "MyDocType1";
63      private static final String STRING_DOC_TYPE = "StringDocType";
64      private static final String STRING_PROP_TYPE = "StringProp";
65      private static final String INT_DOC_TYPE = "IntegerDocType";
66      private static final String INT_PROP_TYPE = "IntegerProp";
67      private static final String DECIMAL_DOC_TYPE = "DecimalDocType";
68      private static final String DECIMAL_PROP_TYPE = "DecimalProp";
69      private static final String PICK_LIST_DOC_TYPE = "PickListDocType";
70      private static final String PICK_LIST_PROP_DEF = "PickListProp";
71      private static final String DOC_TYPE_SUPER = "SuperDocType";
72      private static final String DOC_TYPE_SUB = "SubDocType";
73      private static final String STRING_PROP_TYPE_SUPER = "StringPropSuper";
74      private static final String STRING_PROP_TYPE_SUB = "StringPropSub";
75      private static final BindingsObjectFactory FACTORY = new BindingsObjectFactoryImpl();
76  
77      private static List<PropertyData<?>> createPropertiesWithNameAndTypeId(String typeId) {
78          List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
79          properties.add(FACTORY.createPropertyIdData(PropertyIds.NAME, "Document_1"));
80          properties.add(FACTORY.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
81          return properties;
82      }
83  
84      @Test
85      public void testMandatoryPropertyValidation() {
86          // create properties in the same way as we would pass them to a
87          // createDocument call
88          // of the ObjectService
89  
90          List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(MY_DOC_TYPE);
91          Properties props = FACTORY.createPropertiesData(properties);
92  
93          // validate properties according to type
94          TypeDefinition typeDef = buildMyType();
95  
96          // try missing mandatory Boolean property
97          try {
98              TypeValidator.validateProperties(typeDef, props, true);
99              fail("TypeValidator should throw CMISConstraintException if mandatory property is missing.");
100         } catch (CmisConstraintException e) {
101             assertTrue(e.getMessage().contains("mandatory properties are missing"));
102         }
103 
104         // add missing mandatory Boolean property and try again
105         properties.add(FACTORY.createPropertyBooleanData("BooleanProp", true));
106         props = FACTORY.createPropertiesData(properties);
107         try {
108             TypeValidator.validateProperties(typeDef, props, true);
109         } catch (CmisConstraintException e) {
110             fail("TypeValidator should not throw CMISConstraintException if mandatory property is present.");
111         }
112     }
113 
114     @Test
115     public void testStringPropertyValidation() {
116         TypeDefinition typeDef = buildTypeWithStringProp(); // we only have one
117 
118         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(STRING_DOC_TYPE);
119         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE,
120                 "A String property with quite a long value exceeding the max. length."));
121         Properties props = FACTORY.createPropertiesData(properties);
122 
123         // try exceeding string length
124         try {
125             TypeValidator.validateProperties(typeDef, props, true);
126             fail("TypeValidator should throw CMISConstraintException if max string length is exceeded");
127         } catch (Exception e) {
128             assertTrue(e instanceof CmisConstraintException);
129         }
130 
131         properties = createPropertiesWithNameAndTypeId(STRING_DOC_TYPE);
132         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE, "short val"));
133         props = FACTORY.createPropertiesData(properties);
134         try {
135             TypeValidator.validateProperties(typeDef, props, true);
136         } catch (Exception e) {
137             fail("TypeValidator should not throw exception if string length is valid" + e);
138         }
139     }
140 
141     @Test
142     public void testIntegerPropertyValidation() {
143 
144         TypeDefinition typeDef = buildTypeWithIntegerProp();
145 
146         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(INT_DOC_TYPE);
147         properties.add(FACTORY.createPropertyIntegerData(INT_PROP_TYPE, BigInteger.valueOf(-100))); // try
148         // wrong
149         // value
150         Properties props = FACTORY.createPropertiesData(properties);
151 
152         // try exceeding string length
153         try {
154             TypeValidator.validateProperties(typeDef, props, true);
155             fail("TypeValidator should throw CMISConstraintException if integer value is out of range");
156         } catch (Exception e) {
157             assertTrue(e instanceof CmisConstraintException);
158         }
159 
160         properties = createPropertiesWithNameAndTypeId(INT_DOC_TYPE);
161         properties.add(FACTORY.createPropertyIntegerData(INT_PROP_TYPE, BigInteger.valueOf(1))); // try
162         // correct
163         // value
164         props = FACTORY.createPropertiesData(properties);
165         try {
166             TypeValidator.validateProperties(typeDef, props, true);
167         } catch (Exception e) {
168             fail("TypeValidator should not throw exception if integer value is valid. " + e);
169         }
170 
171     }
172 
173     @Test
174     public void testDecimalPropertyValidation() {
175         TypeDefinition typeDef = buildTypeWithDecimalProp();
176 
177         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(DECIMAL_DOC_TYPE);
178         properties.add(FACTORY.createPropertyDecimalData(DECIMAL_PROP_TYPE, BigDecimal.valueOf(-11.11)));
179         Properties props = FACTORY.createPropertiesData(properties);
180 
181         // try exceeding string length
182         try {
183             TypeValidator.validateProperties(typeDef, props, true);
184             fail("TypeValidator should throw CMISConstraintException if decimal value is out of range");
185         } catch (Exception e) {
186             assertTrue(e instanceof CmisConstraintException);
187         }
188 
189         properties = createPropertiesWithNameAndTypeId(DECIMAL_DOC_TYPE);
190         properties.add(FACTORY.createPropertyDecimalData(DECIMAL_PROP_TYPE, BigDecimal.valueOf(1.23)));
191         props = FACTORY.createPropertiesData(properties);
192         try {
193             TypeValidator.validateProperties(typeDef, props, true);
194         } catch (Exception e) {
195             fail("TypeValidator should not throw exception if decimal value is valid. " + e);
196         }
197     }
198 
199     @Test
200     public void testPickListValidationSingleValue() {
201         TypeDefinition typeDef = buildTypeWithPickList(Cardinality.SINGLE);
202 
203         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
204         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, "pink"));
205         Properties props = FACTORY.createPropertiesData(properties);
206 
207         // try wrong value
208         try {
209             TypeValidator.validateProperties(typeDef, props, true);
210             fail("TypeValidator should throw CMISConstraintException if choice value is not in list of valid values");
211         } catch (Exception e) {
212             assertTrue(e instanceof CmisConstraintException);
213         }
214 
215         properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
216         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, "blue"));
217         props = FACTORY.createPropertiesData(properties);
218 
219         try {
220             TypeValidator.validateProperties(typeDef, props, true);
221         } catch (Exception e) {
222             fail("TypeValidator should not throw CMISConstraintException if choice value is in list of valid values"
223                     + e);
224         }
225     }
226 
227     @Test
228     public void testPickListValidationMultiValue() {
229         TypeDefinition typeDef = buildTypeWithPickList(Cardinality.MULTI);
230 
231         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
232         List<String> propValues = new ArrayList<String>();
233         propValues.add("red");
234         propValues.add("pink");
235         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
236         Properties props = FACTORY.createPropertiesData(properties);
237 
238         // try wrong value
239         try {
240             TypeValidator.validateProperties(typeDef, props, true);
241             fail("TypeValidator should throw CMISConstraintException if choice value is not in list of valid values");
242         } catch (Exception e) {
243             assertTrue(e instanceof CmisConstraintException);
244         }
245 
246         properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
247         propValues = new ArrayList<String>();
248         propValues.add("red");
249         propValues.add("green");
250         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
251         props = FACTORY.createPropertiesData(properties);
252         try {
253             TypeValidator.validateProperties(typeDef, props, true);
254         } catch (Exception e) {
255             fail("TypeValidator should not throw CMISConstraintException if choice value is in list of valid values"
256                     + e);
257         }
258     }
259 
260     @Test
261     public void testPickListValidationMultiUsingMultipleValueLists() {
262         TypeDefinition typeDef = buildTypeWithMultiPickList();
263 
264         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
265         List<String> propValues = new ArrayList<String>();
266         propValues.add("red");
267         propValues.add("green");
268         propValues.add("pink");
269         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
270         Properties props = FACTORY.createPropertiesData(properties);
271 
272         // try wrong value
273         try {
274             TypeValidator.validateProperties(typeDef, props, true);
275             fail("TypeValidator should throw CMISConstraintException if choice value is not in list of valid values");
276         } catch (Exception e) {
277             assertTrue(e instanceof CmisConstraintException);
278         }
279 
280         properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
281         propValues = new ArrayList<String>();
282         propValues.add("red");
283         propValues.add("green");
284         propValues.add("blue");
285         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
286         props = FACTORY.createPropertiesData(properties);
287 
288         try {
289             TypeValidator.validateProperties(typeDef, props, true);
290         } catch (Exception e) {
291             fail("TypeValidator should not throw CMISConstraintException if choice value is in list of valid values"
292                     + e);
293         }
294     }
295 
296     @Test
297     public void testHierachicalPickListValidationSingleValue() {
298         TypeDefinition typeDef = buildTypeWithHierachicalPickList(Cardinality.SINGLE);
299 
300         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
301         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, "frankfurt"));
302         Properties props = FACTORY.createPropertiesData(properties);
303 
304         // try wrong value
305         try {
306             TypeValidator.validateProperties(typeDef, props, true);
307             fail("TypeValidator should throw CMISConstraintException if choice value is not in list of valid values");
308         } catch (Exception e) {
309             assertTrue(e instanceof CmisConstraintException);
310         }
311 
312         properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
313         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, "munich"));
314         props = FACTORY.createPropertiesData(properties);
315 
316         try {
317             TypeValidator.validateProperties(typeDef, props, true);
318         } catch (Exception e) {
319             fail("TypeValidator should not throw CMISConstraintException if choice value is in list of valid values"
320                     + e);
321         }
322     }
323 
324     @Test
325     public void testHierachicalPickListValidationMultiValue() {
326         TypeDefinition typeDef = buildTypeWithHierachicalPickList(Cardinality.MULTI);
327 
328         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
329         List<String> propValues = new ArrayList<String>();
330         propValues.add("stuttgart");
331         propValues.add("hintertupfingen");
332         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
333         Properties props = FACTORY.createPropertiesData(properties);
334 
335         // try wrong value
336         try {
337             TypeValidator.validateProperties(typeDef, props, true);
338             fail("TypeValidator should throw CMISConstraintException if choice value is not in list of valid values");
339         } catch (Exception e) {
340             assertTrue(e instanceof CmisConstraintException);
341         }
342 
343         properties = createPropertiesWithNameAndTypeId(PICK_LIST_DOC_TYPE);
344         propValues = new ArrayList<String>();
345         propValues.add("munich");
346         propValues.add("walldorf");
347         properties.add(FACTORY.createPropertyStringData(PICK_LIST_PROP_DEF, propValues));
348         props = FACTORY.createPropertiesData(properties);
349 
350         try {
351             TypeValidator.validateProperties(typeDef, props, true);
352         } catch (Exception e) {
353             fail("TypeValidator should not throw CMISConstraintException if choice value is in list of valid values"
354                     + e);
355         }
356     }
357 
358     @Test
359     public void testInheritedPropertyValidation() {
360         TypeManager tm = buildInheritedTypes();
361         TypeDefinition superType = tm.getTypeById(DOC_TYPE_SUPER).getTypeDefinition();
362         TypeDefinition subType = tm.getTypeById(DOC_TYPE_SUB).getTypeDefinition();
363 
364         List<PropertyData<?>> properties = createPropertiesWithNameAndTypeId(DOC_TYPE_SUB);
365         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE_SUB,
366                 "A String property with quite a long value exceeding the max. length."));
367         Properties props = FACTORY.createPropertiesData(properties);
368 
369         // try exceeding string length on org property
370         try {
371             TypeValidator.validateProperties(superType, props, true);
372             fail("TypeValidator should throw CMISConstraintException if max string length is exceeded");
373         } catch (Exception e) {
374             assertTrue(e instanceof CmisConstraintException);
375         }
376 
377         // try exceeding string length on inherited property
378         properties = createPropertiesWithNameAndTypeId(DOC_TYPE_SUB);
379         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE_SUPER,
380                 "A String property with quite a long value exceeding the max. length."));
381         props = FACTORY.createPropertiesData(properties);
382 
383         // try exceeding string length
384         try {
385             TypeValidator.validateProperties(subType, props, true);
386             fail("TypeValidator should throw CMISConstraintException if max string length is exceeded");
387         } catch (Exception e) {
388             assertTrue(e instanceof CmisConstraintException);
389         }
390 
391         properties = createPropertiesWithNameAndTypeId(DOC_TYPE_SUB);
392         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE_SUPER, "super val"));
393         properties.add(FACTORY.createPropertyStringData(STRING_PROP_TYPE_SUB, "sub val"));
394         props = FACTORY.createPropertiesData(properties);
395         try {
396             TypeValidator.validateProperties(subType, props, true);
397         } catch (Exception e) {
398             fail("TypeValidator should not throw exception if string length is valid" + e);
399         }
400     }
401 
402     /**
403      * create sample type
404      * 
405      * @return type definition of sample type
406      */
407     private static InMemoryDocumentTypeDefinition buildMyType() {
408         // always add CMIS default types
409 
410         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(MY_DOC_TYPE,
411                 "Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
412 
413         // create a boolean property definition
414 
415         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
416 
417         PropertyDefinition<Boolean> prop = PropertyCreationHelper.createBooleanDefinition("BooleanProp",
418                 "Sample Boolean Property", Updatability.READONLY);
419         ((PropertyBooleanDefinitionImpl) prop).setIsRequired(true);
420         propertyDefinitions.put(prop.getId(), prop);
421 
422         prop = PropertyCreationHelper.createBooleanMultiDefinition("BooleanPropMV",
423                 "Sample Boolean multi-value Property", Updatability.READONLY);
424         propertyDefinitions.put(prop.getId(), prop);
425 
426         PropertyDateTimeDefinitionImpl prop2 = PropertyCreationHelper.createDateTimeDefinition("DateTimeProp",
427                 "Sample DateTime Property", Updatability.READONLY);
428         propertyDefinitions.put(prop2.getId(), prop2);
429 
430         prop2 = PropertyCreationHelper.createDateTimeMultiDefinition("DateTimePropMV",
431                 "Sample DateTime multi-value Property", Updatability.READONLY);
432         propertyDefinitions.put(prop2.getId(), prop2);
433 
434         PropertyDecimalDefinitionImpl prop3 = PropertyCreationHelper.createDecimalDefinition("DecimalProp",
435                 "Sample Decimal Property", Updatability.READONLY);
436         propertyDefinitions.put(prop3.getId(), prop3);
437 
438         prop3 = PropertyCreationHelper.createDecimalDefinition("DecimalPropMV", "Sample Decimal multi-value Property",
439                 Updatability.READONLY);
440         propertyDefinitions.put(prop3.getId(), prop3);
441 
442         PropertyHtmlDefinitionImpl prop4 = PropertyCreationHelper.createHtmlDefinition("HtmlProp",
443                 "Sample Html Property", Updatability.READONLY);
444         propertyDefinitions.put(prop4.getId(), prop4);
445 
446         prop4 = PropertyCreationHelper.createHtmlDefinition("HtmlPropMV", "Sample Html multi-value Property",
447                 Updatability.READONLY);
448         propertyDefinitions.put(prop4.getId(), prop4);
449 
450         PropertyIdDefinitionImpl prop5 = PropertyCreationHelper.createIdDefinition("IdProp", "Sample Id Property",
451                 Updatability.READONLY);
452         propertyDefinitions.put(prop5.getId(), prop5);
453 
454         prop5 = PropertyCreationHelper.createIdDefinition("IdPropMV", "Sample Id Html multi-value Property",
455                 Updatability.READONLY);
456         propertyDefinitions.put(prop5.getId(), prop5);
457 
458         PropertyIntegerDefinitionImpl prop6 = PropertyCreationHelper.createIntegerDefinition("IntProp",
459                 "Sample Int Property", Updatability.READONLY);
460         propertyDefinitions.put(prop6.getId(), prop6);
461 
462         prop6 = PropertyCreationHelper.createIntegerDefinition("IntPropMV", "Sample Int multi-value Property",
463                 Updatability.READONLY);
464         propertyDefinitions.put(prop6.getId(), prop6);
465 
466         PropertyStringDefinitionImpl prop7 = PropertyCreationHelper.createStringDefinition("StringProp",
467                 "Sample String Property", Updatability.READONLY);
468         propertyDefinitions.put(prop7.getId(), prop7);
469 
470         PropertyUriDefinitionImpl prop8 = PropertyCreationHelper.createUriDefinition("UriProp", "Sample Uri Property",
471                 Updatability.READONLY);
472         propertyDefinitions.put(prop8.getId(), prop8);
473 
474         prop8 = PropertyCreationHelper.createUriDefinition("UriPropMV", "Sample Uri multi-value Property",
475                 Updatability.READONLY);
476         propertyDefinitions.put(prop8.getId(), prop8);
477 
478         PropertyStringDefinitionImpl prop9 = PropertyCreationHelper.createStringDefinition(PICK_LIST_PROP_DEF,
479                 "Sample Pick List Property", Updatability.READONLY);
480 
481         PropertyCreationHelper.addElemToPicklist(prop9, "red");
482         PropertyCreationHelper.addElemToPicklist(prop9, "green");
483         PropertyCreationHelper.addElemToPicklist(prop9, "blue");
484         PropertyCreationHelper.addElemToPicklist(prop9, "black");
485         PropertyCreationHelper.setDefaultValue(prop9, "blue");
486 
487         cmisType.setPropertyDefinitions(propertyDefinitions);
488 
489         return cmisType;
490     }
491 
492     private static InMemoryDocumentTypeDefinition buildTypeWithStringProp() {
493         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(STRING_DOC_TYPE,
494                 "String Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
495 
496         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
497         // create a String property definition
498 
499         PropertyStringDefinitionImpl propDef = PropertyCreationHelper.createStringDefinition(STRING_PROP_TYPE,
500                 "Sample String Property", Updatability.READONLY);
501         propDef.setMaxLength(BigInteger.valueOf(10));
502         propertyDefinitions.put(propDef.getId(), propDef);
503 
504         cmisType.setPropertyDefinitions(propertyDefinitions);
505 
506         return cmisType;
507     }
508 
509     private static InMemoryDocumentTypeDefinition buildTypeWithIntegerProp() {
510         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(INT_DOC_TYPE,
511                 "Int Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
512 
513         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
514         // create a String property definition
515 
516         PropertyIntegerDefinitionImpl propDef = PropertyCreationHelper.createIntegerDefinition(INT_PROP_TYPE,
517                 "Sample Integer Property", Updatability.READONLY);
518         propDef.setMinValue(BigInteger.valueOf(-1));
519         propDef.setMaxValue(BigInteger.valueOf(1));
520         propertyDefinitions.put(propDef.getId(), propDef);
521 
522         cmisType.setPropertyDefinitions(propertyDefinitions);
523 
524         return cmisType;
525     }
526 
527     private static InMemoryDocumentTypeDefinition buildTypeWithDecimalProp() {
528         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(DECIMAL_DOC_TYPE,
529                 "Decimal Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
530 
531         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
532         // create a String property definition
533 
534         PropertyDecimalDefinitionImpl propDef = PropertyCreationHelper.createDecimalDefinition(DECIMAL_PROP_TYPE,
535                 "Sample Decimal Property", Updatability.READONLY);
536         propDef.setMinValue(BigDecimal.valueOf(-1.5));
537         propDef.setMaxValue(BigDecimal.valueOf(1.5));
538         propertyDefinitions.put(propDef.getId(), propDef);
539 
540         cmisType.setPropertyDefinitions(propertyDefinitions);
541 
542         return cmisType;
543     }
544 
545     public static InMemoryDocumentTypeDefinition buildTypeWithPickList(Cardinality cardinality) {
546         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(PICK_LIST_DOC_TYPE,
547                 "PickList Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
548 
549         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
550         // create a String property definition
551 
552         PropertyStringDefinitionImpl propDef = PropertyCreationHelper.createStringDefinition(PICK_LIST_PROP_DEF,
553                 "Sample PickList (choice) Property", Updatability.READONLY);
554         List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
555         ChoiceImpl<String> elem = new ChoiceImpl<String>();
556         elem.setValue(Collections.singletonList("red"));
557         elem.setDisplayName("Red");
558         choiceList.add(elem);
559         elem = new ChoiceImpl<String>();
560         elem.setValue(Collections.singletonList("green"));
561         elem.setDisplayName("Green");
562         choiceList.add(elem);
563         elem = new ChoiceImpl<String>();
564         elem.setValue(Collections.singletonList("blue"));
565         elem.setDisplayName("Blue");
566         choiceList.add(elem);
567         elem = new ChoiceImpl<String>();
568         elem.setValue(Collections.singletonList("black"));
569         elem.setDisplayName("Black");
570         choiceList.add(elem);
571         propDef.setChoices(choiceList);
572         propDef.setDefaultValue(Collections.singletonList("blue"));
573         propDef.setCardinality(cardinality);
574         propertyDefinitions.put(propDef.getId(), propDef);
575         cmisType.setPropertyDefinitions(propertyDefinitions);
576 
577         return cmisType;
578     }
579 
580     public static InMemoryDocumentTypeDefinition buildTypeWithMultiPickList() {
581         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(PICK_LIST_DOC_TYPE,
582                 "PickList Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
583 
584         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
585         // create a String property definition
586 
587         PropertyStringDefinitionImpl propDef = PropertyCreationHelper.createStringDefinition(PICK_LIST_PROP_DEF,
588                 "Sample PickList (choice) Property", Updatability.READONLY);
589         List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
590         ChoiceImpl<String> elem = new ChoiceImpl<String>();
591         List<String> valueList = new ArrayList<String>();
592         valueList.add("red");
593         valueList.add("green");
594         valueList.add("blue");
595         elem.setValue(valueList);
596         elem.setDisplayName("RGB");
597         choiceList.add(elem);
598 
599         elem = new ChoiceImpl<String>();
600         valueList = new ArrayList<String>();
601         valueList.add("cyan");
602         valueList.add("magenta");
603         valueList.add("yellow");
604         valueList.add("black");
605         elem.setValue(valueList);
606         elem.setDisplayName("CMYK");
607         choiceList.add(elem);
608 
609         propDef.setChoices(choiceList);
610         // propDef.setDefaultValue(...);
611         propDef.setCardinality(Cardinality.MULTI);
612         propertyDefinitions.put(propDef.getId(), propDef);
613         cmisType.setPropertyDefinitions(propertyDefinitions);
614 
615         return cmisType;
616     }
617 
618     public static InMemoryDocumentTypeDefinition buildTypeWithHierachicalPickList(Cardinality cardinality) {
619         InMemoryDocumentTypeDefinition cmisType = new InMemoryDocumentTypeDefinition(PICK_LIST_DOC_TYPE,
620                 "PickList Document Type for Validation", InMemoryDocumentTypeDefinition.getRootDocumentType());
621 
622         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
623         // create a String property definition
624 
625         // Create a two-level pick list with an outer property list state and an
626         // inner
627         // list of city
628         PropertyStringDefinitionImpl propDef = PropertyCreationHelper.createStringDefinition(PICK_LIST_PROP_DEF,
629                 "Sample PickList (choice) Property", Updatability.READONLY);
630         List<Choice<String>> choiceListOuter = new ArrayList<Choice<String>>();
631 
632         ChoiceImpl<String> elemOuter = new ChoiceImpl<String>();
633         elemOuter.setDisplayName("Bavaria");
634         List<Choice<String>> choiceListInner = new ArrayList<Choice<String>>();
635         ChoiceImpl<String> elemInner = new ChoiceImpl<String>();
636         elemInner.setDisplayName("Munich");
637         elemInner.setValue(Collections.singletonList("munich"));
638         choiceListInner.add(elemInner);
639         elemInner = new ChoiceImpl<String>();
640         elemInner.setDisplayName("Ingolstadt");
641         elemInner.setValue(Collections.singletonList("ingolstadt"));
642         choiceListInner.add(elemInner);
643         elemInner = new ChoiceImpl<String>();
644         elemInner.setDisplayName("Passau");
645         elemInner.setValue(Collections.singletonList("passau"));
646         choiceListInner.add(elemInner);
647         elemOuter.setChoice(choiceListInner);
648         choiceListOuter.add(elemOuter);
649 
650         elemOuter = new ChoiceImpl<String>();
651         elemOuter.setDisplayName("Baden Wurtemberg");
652         choiceListInner = new ArrayList<Choice<String>>();
653         elemInner = new ChoiceImpl<String>();
654         elemInner.setDisplayName("Stuttgart");
655         elemInner.setValue(Collections.singletonList("stuttgart"));
656         choiceListInner.add(elemInner);
657         elemInner = new ChoiceImpl<String>();
658         elemInner.setDisplayName("Karlsruhe");
659         elemInner.setValue(Collections.singletonList("karlsruhe"));
660         choiceListInner.add(elemInner);
661         elemInner = new ChoiceImpl<String>();
662         elemInner.setDisplayName("Walldorf");
663         elemInner.setValue(Collections.singletonList("walldorf"));
664         choiceListInner.add(elemInner);
665         elemOuter.setChoice(choiceListInner);
666         choiceListOuter.add(elemOuter);
667 
668         propDef.setChoices(choiceListOuter);
669         propDef.setCardinality(cardinality);
670         propertyDefinitions.put(propDef.getId(), propDef);
671         cmisType.setPropertyDefinitions(propertyDefinitions);
672 
673         return cmisType;
674     }
675 
676     private static TypeManager buildInheritedTypes() {
677 
678         TypeManagerImpl tm = new TypeManagerImpl();
679         tm.initTypeSystem(null); // create CMIS default types
680 
681         // create super type
682         InMemoryDocumentTypeDefinition cmisSuperType = new InMemoryDocumentTypeDefinition(DOC_TYPE_SUPER,
683                 "Document Type With a child", InMemoryDocumentTypeDefinition.getRootDocumentType());
684 
685         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
686         // create a String property definition
687         PropertyStringDefinitionImpl propDef = PropertyCreationHelper.createStringDefinition(STRING_PROP_TYPE_SUPER,
688                 "Sample String Property SuperType", Updatability.READONLY);
689         propDef.setMaxLength(BigInteger.valueOf(10));
690         propertyDefinitions.put(propDef.getId(), propDef);
691         cmisSuperType.setPropertyDefinitions(propertyDefinitions);
692 
693         // create sub type
694         InMemoryDocumentTypeDefinition cmisSubType = new InMemoryDocumentTypeDefinition(DOC_TYPE_SUB,
695                 "Document Type With a parent", cmisSuperType);
696 
697         propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
698         // create a String property definition
699         propDef = PropertyCreationHelper.createStringDefinition(STRING_PROP_TYPE_SUB, "Sample String Property Subtype",
700                 Updatability.READONLY);
701         propDef.setMaxLength(BigInteger.valueOf(20));
702         propertyDefinitions.put(propDef.getId(), propDef);
703         cmisSubType.setPropertyDefinitions(propertyDefinitions);
704 
705         tm.addTypeDefinition(cmisSuperType);
706         tm.addTypeDefinition(cmisSubType);
707 
708         return tm;
709     }
710 
711 }