Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8AD24EB8E for ; Tue, 19 Mar 2013 12:57:28 +0000 (UTC) Received: (qmail 51579 invoked by uid 500); 19 Mar 2013 12:57:27 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 51485 invoked by uid 500); 19 Mar 2013 12:57:25 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 51440 invoked by uid 99); 19 Mar 2013 12:57:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Mar 2013 12:57:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Mar 2013 12:57:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0206F23888E7; Tue, 19 Mar 2013 12:57:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1458261 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/ chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemi... Date: Tue, 19 Mar 2013 12:57:01 -0000 To: commits@chemistry.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130319125702.0206F23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmui Date: Tue Mar 19 12:57:01 2013 New Revision: 1458261 URL: http://svn.apache.org/r1458261 Log: TCK: extended type creation tests Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java?rev=1458261&r1=1458260&r2=1458261&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java Tue Mar 19 12:57:01 2013 @@ -477,6 +477,10 @@ public class XMLConverter { return; } + if (source.getPropertyType() == null) { + throw new CmisRuntimeException("Property type for property definition '" + source.getId() + "' is not set!"); + } + switch (source.getPropertyType()) { case STRING: writer.writeStartElement(PREFIX_CMIS, TAG_TYPE_PROP_DEF_STRING, NAMESPACE_CMIS); Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1458261&r1=1458260&r2=1458261&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java Tue Mar 19 12:57:01 2013 @@ -64,6 +64,7 @@ import org.apache.chemistry.opencmis.com import org.apache.chemistry.opencmis.commons.data.Acl; import org.apache.chemistry.opencmis.commons.data.AllowableActions; import org.apache.chemistry.opencmis.commons.data.ContentStream; +import org.apache.chemistry.opencmis.commons.data.NewTypeSettableAttributes; import org.apache.chemistry.opencmis.commons.data.ObjectData; import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities; import org.apache.chemistry.opencmis.commons.data.RepositoryInfo; @@ -585,6 +586,80 @@ public abstract class AbstractSessionTes } } + // --- type helpers --- + + /** + * Creates a new type. + */ + protected ObjectType createType(Session session, TypeDefinition typeDef) { + + NewTypeSettableAttributes settableAttributes = session.getRepositoryInfo().getCapabilities() + .getNewTypeSettableAttributes(); + if (settableAttributes == null) { + addResult(createResult(WARNING, "Repository Info does not indicate, which type attributes can be set!")); + } else { + // TODO: add more tests + } + + ObjectType newType = null; + try { + newType = session.createType(typeDef); + addResult(createInfoResult("Created type '" + typeDef.getId() + + "'. Repository assigned the following type id: " + newType.getId())); + } catch (CmisBaseException e) { + addResult(createResult(FAILURE, "Creating type '" + typeDef.getId() + "' failed: " + e.getMessage(), e, + false)); + return null; + } + + addResult(checkTypeDefinition(session, newType, "Newly created type spec compliance.")); + + if (newType.getTypeMutability() == null) { + addResult(createResult(FAILURE, + "Newly created type does not provide type mutability data! Id: " + newType.getId())); + } + + return newType; + } + + /** + * Deletes a type. + */ + protected void deleteType(Session session, String typeId) { + ObjectType type = session.getTypeDefinition(typeId); + + if (type == null) { + addResult(createResult(FAILURE, "Type does not exist and therefore cannot be deleted! Id: " + typeId)); + return; + } + + // check if type can be deleted + if (type.getTypeMutability() == null) { + addResult(createResult(FAILURE, "Type does not provide type mutability data! Id: " + typeId)); + } else { + if (!Boolean.TRUE.equals(type.getTypeMutability().canDelete())) { + addResult(createResult(WARNING, "Type indicates that it cannot be deleted. Trying it anyway. Id: " + + typeId)); + } + } + + // delete it + try { + session.deleteType(typeId); + } catch (CmisBaseException e) { + addResult(createResult(FAILURE, "Deleting type '" + typeId + "' failed: " + e.getMessage(), e, false)); + return; + } + + // check if the type still exists + try { + session.getTypeDefinition(typeId); + addResult(createResult(FAILURE, "Type should not exist anymore but it is still there! Id: " + typeId, true)); + } catch (CmisObjectNotFoundException e) { + // expected result + } + } + // --- test folder methods --- /** Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java?rev=1458261&r1=1458260&r2=1458261&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java Tue Mar 19 12:57:01 2013 @@ -20,17 +20,31 @@ package org.apache.chemistry.opencmis.tc import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE; import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED; -import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import org.apache.chemistry.opencmis.client.api.ObjectType; import org.apache.chemistry.opencmis.client.api.Session; +import org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes; +import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; +import org.apache.chemistry.opencmis.commons.enums.Cardinality; import org.apache.chemistry.opencmis.commons.enums.CmisVersion; import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed; -import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException; +import org.apache.chemistry.opencmis.commons.enums.PropertyType; +import org.apache.chemistry.opencmis.commons.enums.Updatability; import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition; import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl; import org.apache.chemistry.opencmis.tck.CmisTestResult; import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest; @@ -51,69 +65,168 @@ public class CreateAndDeleteTypeTest ext ObjectType parentType = session.getTypeDefinition(getDocumentTestTypeId()); if (parentType.getTypeMutability() == null || !Boolean.TRUE.equals(parentType.getTypeMutability().canCreate())) { - addResult(createResult(SKIPPED, "Test type doesn't allow creating a sub-type. Test skipped!")); + addResult(createResult(SKIPPED, "Test document type doesn't allow creating a sub-type. Test skipped!")); return; } + createTypeWithoutProperties(session, parentType); + createTypeWithProperties(session, parentType); + } + + private void createTypeWithoutProperties(Session session, ObjectType parentType) { CmisTestResult failure = null; // define the type - DocumentTypeDefinitionImpl newTypeDef = new DocumentTypeDefinitionImpl(); - - newTypeDef.setId("tck:testid"); - newTypeDef.setBaseTypeId(parentType.getBaseTypeId()); - newTypeDef.setParentTypeId(parentType.getId()); - newTypeDef.setLocalName("tck:testlocal"); - newTypeDef.setLocalNamespace("tck:testlocalnamespace"); - newTypeDef.setDisplayName("TCK Document Type"); - newTypeDef.setDescription("This is the TCK document type"); - newTypeDef.setQueryName("tck:testqueryname"); - newTypeDef.setIsQueryable(false); - newTypeDef.setIsFulltextIndexed(false); - newTypeDef.setIsIncludedInSupertypeQuery(true); - newTypeDef.setIsControllableAcl(false); - newTypeDef.setIsControllablePolicy(false); - newTypeDef.setIsCreatable(true); - newTypeDef.setIsFileable(true); - newTypeDef.setIsVersionable(false); - newTypeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED); + DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition("tck:testid_without_properties", + parentType); // create the type - ObjectType newType = null; - try { - newType = session.createType(newTypeDef); - } catch (CmisBaseException e) { - addResult(createResult(FAILURE, "Creating type '" + newTypeDef.getId() + "' failed: " + e.getMessage())); + ObjectType newType = createType(session, newTypeDef); + if (newType == null) { return; } - // check type - addResult(checkTypeDefinition(session, newType, "Newly created type spec compliance.")); - // get the type ObjectType newType2 = null; try { newType2 = session.getTypeDefinition(newType.getId()); + + // assert type definitions + failure = createResult(FAILURE, + "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!"); + addResult(assertEquals(newType, newType2, null, failure)); } catch (CmisObjectNotFoundException e) { - addResult(createResult(FAILURE, "Newly created type '" + newType.getId() + "' can not be fetched.")); + addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false)); } - // assert type definitions - failure = createResult(FAILURE, - "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!"); - addResult(assertEquals(newType, newType2, null, failure)); + // delete the type + deleteType(session, newType.getId()); + } + + private void createTypeWithProperties(Session session, ObjectType parentType) { + CmisTestResult failure = null; - // check if type can be deleted - if (newType.getTypeMutability() == null || !Boolean.TRUE.equals(newType.getTypeMutability().canDelete())) { - addResult(createResult(WARNING, "Newly created type indicates that it cannot be deleted. Trying it anyway.")); + CreatablePropertyTypes cpt = session.getRepositoryInfo().getCapabilities().getCreatablePropertyTypes(); + if (cpt == null || cpt.canCreate() == null || cpt.canCreate().isEmpty()) { + addResult(createResult(FAILURE, "Repository Info does not indicate, which property types can be created!")); + return; } - // delete the type + // define the type + DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition("tck:testid_with_properties", parentType); + + // add a property for each creatable property type + for (PropertyType propType : PropertyType.values()) { + if (!cpt.canCreate().contains(propType)) { + continue; + } + + newTypeDef.addPropertyDefinition(createPropertyDefinition(propType)); + } + + // create the type + ObjectType newType = createType(session, newTypeDef); + if (newType == null) { + return; + } + + // get the type + ObjectType newType2 = null; try { - session.deleteType(newType.getId()); - } catch (CmisBaseException e) { - addResult(createResult(FAILURE, "Deleting type '" + newType.getId() + "' failed: " + e.getMessage())); + newType2 = session.getTypeDefinition(newType.getId()); + + // assert type definitions + failure = createResult(FAILURE, + "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!"); + addResult(assertEquals(newType, newType2, null, failure)); + } catch (CmisObjectNotFoundException e) { + addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false)); } + + // check properties + List> newPropDefs = new ArrayList>(); + for (Map.Entry> propDef : newType.getPropertyDefinitions().entrySet()) { + if (Boolean.FALSE.equals(propDef.getValue().isInherited())) { + newPropDefs.add(propDef.getValue()); + } + } + + failure = createResult(FAILURE, + "The number of defined properties and the number of non-inherited properties don't match!"); + addResult(assertEquals(newTypeDef.getPropertyDefinitions().size(), newPropDefs.size(), null, failure)); + + // delete the type + deleteType(session, newType.getId()); + } + + private DocumentTypeDefinitionImpl createDocumentTypeDefinition(String typeId, ObjectType parentType) { + DocumentTypeDefinitionImpl result = new DocumentTypeDefinitionImpl(); + + result.setId(typeId); + result.setBaseTypeId(parentType.getBaseTypeId()); + result.setParentTypeId(parentType.getId()); + result.setLocalName("tck:testlocal"); + result.setLocalNamespace("tck:testlocalnamespace"); + result.setDisplayName("TCK Document Type"); + result.setDescription("This is the TCK document type"); + result.setQueryName("tck:testqueryname"); + result.setIsQueryable(false); + result.setIsFulltextIndexed(false); + result.setIsIncludedInSupertypeQuery(true); + result.setIsControllableAcl(false); + result.setIsControllablePolicy(false); + result.setIsCreatable(true); + result.setIsFileable(true); + result.setIsVersionable(false); + result.setContentStreamAllowed(ContentStreamAllowed.ALLOWED); + + return result; } -} + private AbstractPropertyDefinition createPropertyDefinition(PropertyType propertyType) { + AbstractPropertyDefinition result = null; + + switch (propertyType) { + case BOOLEAN: + result = new PropertyBooleanDefinitionImpl(); + break; + case ID: + result = new PropertyIdDefinitionImpl(); + break; + case INTEGER: + result = new PropertyIntegerDefinitionImpl(); + break; + case DATETIME: + result = new PropertyDateTimeDefinitionImpl(); + break; + case DECIMAL: + result = new PropertyDecimalDefinitionImpl(); + break; + case HTML: + result = new PropertyHtmlDefinitionImpl(); + break; + case URI: + result = new PropertyUriDefinitionImpl(); + break; + default: + result = new PropertyStringDefinitionImpl(); + } + + result.setPropertyType(propertyType); + result.setId("tck:" + propertyType.value()); + result.setLocalName("tck:local_" + propertyType.value()); + result.setLocalNamespace("tck:testlocalnamespace"); + result.setDisplayName("TCK " + propertyType.value() + " propertry"); + result.setQueryName("tck:" + propertyType.value()); + result.setDescription("TCK " + propertyType.value() + " propertry"); + result.setCardinality(Cardinality.SINGLE); + result.setUpdatability(Updatability.READWRITE); + result.setIsInherited(false); + result.setIsQueryable(false); + result.setIsOrderable(false); + result.setIsRequired(false); + result.setIsOpenChoice(true); + + return result; + } +} \ No newline at end of file