From f3e3191c911992ae4b55cf1619206ad7dd2b7c9f Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 2 Nov 2009 22:21:03 +0000 Subject: Moving LDAP DAS to contrib folder at new SVN structure git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@832142 13f79535-47bb-0310-9956-ffa450edef68 --- .../setup/ADSEmbeddedConnectionTemplate.java | 129 ++++++ .../setup/ADSEmbeddedConnectionTemplateTest.java | 59 +++ .../setup/ADSEmbeddedHotPartitionTemplate.java | 157 +++++++ .../setup/ADSEmbeddedHotPartitionTemplateTest.java | 50 +++ .../testing/setup/JNDIConnectionTemplate.java | 103 +++++ .../testing/setup/JNDIConnectionTemplateTest.java | 66 +++ .../setup/JNDIHotPartitionConnectionTemplate.java | 117 ++++++ .../JNDIHotPartitionConnectionTemplateTest.java | 73 ++++ .../das/ldap/connect/ADSEmbeddedConnection.java | 175 ++++++++ .../tuscany/das/ldap/connect/JNDIConnection.java | 96 +++++ .../das/ldap/create/InitialContextCreator.java | 75 ++++ .../ldap/create/InitialContextCreatorHelper.java | 143 +++++++ .../das/ldap/create/MetaContextCreator.java | 65 +++ .../das/ldap/destroy/InitialContextDestroyer.java | 74 ++++ .../das/ldap/destroy/MetaContextDestroyer.java | 53 +++ .../org/apache/tuscany/das/ldap/emf/Context.java | 81 ++++ .../org/apache/tuscany/das/ldap/emf/LdapDAS.java | 379 +++++++++++++++++ .../apache/tuscany/das/ldap/emf/LdapDASHelper.java | 295 +++++++++++++ .../das/ldap/emf/create/EDataGraphCreator.java | 62 +++ .../ldap/emf/create/EDataGraphCreatorHelper.java | 97 +++++ .../das/ldap/emf/create/EDataObjectCreator.java | 137 ++++++ .../ldap/emf/create/EDataObjectCreatorHelper.java | 284 +++++++++++++ .../das/ldap/emf/read/EDataGraphReader.java | 131 ++++++ .../das/ldap/emf/read/EDataGraphReaderHelper.java | 365 ++++++++++++++++ .../das/ldap/emf/read/EDataObjectReader.java | 100 +++++ .../das/ldap/emf/read/EDataObjectReaderHelper.java | 161 ++++++++ .../das/ldap/emf/update/EDataGraphUpdater.java | 63 +++ .../ldap/emf/update/EDataGraphUpdaterHelper.java | 228 ++++++++++ .../encryption/constants/EncryptionConstants.java | 26 ++ .../das/ldap/encryption/util/ChecksumUtils.java | 38 ++ .../das/ldap/oid/create/ComplexTypeOIDCreator.java | 69 ++++ .../das/ldap/oid/create/OIDCreatorHelper.java | 73 ++++ .../das/ldap/oid/create/SimpleTypeOIDCreator.java | 66 +++ .../das/ldap/prototype/setup/Prototype.java | 74 ++++ .../ldap/prototype/setup/PrototypeUtilities.java | 243 +++++++++++ .../ldap/prototype/setup/test/CommonSetupTest.java | 264 ++++++++++++ .../prototype/setup/test/EDataGraphSetupTest.java | 138 +++++++ .../prototype/setup/test/EDataObjectSetupTest.java | 49 +++ .../prototype/setup/test/LdapDASSetupTest.java | 218 ++++++++++ .../create/AbstractAttributeTypeCreator.java | 40 ++ .../ldap/schema/create/AbstractTypeCreator.java | 59 +++ .../ldap/schema/create/ComplexTypeRDNCreator.java | 60 +++ .../ldap/schema/create/SimpleTypeRDNCreator.java | 63 +++ .../schema/create/SyntaxCheckerEntryCreator.java | 94 +++++ .../das/ldap/schema/create/SyntaxEntryCreator.java | 155 +++++++ .../embedded/setup/test/AbstractTestSetup.java | 87 ++++ .../embedded/setup/test/AbstractTestSetupTest.java | 46 +++ .../embedded/setup/test/DASContextSetup.java | 47 +++ .../embedded/setup/test/DASContextSetupTest.java | 54 +++ .../setup/test/DASSchemaContextsSetup.java | 191 +++++++++ .../setup/test/DASSchemaContextsSetupTest.java | 59 +++ .../setup/test/EcoreSchemaAndDASContextsSetup.java | 74 ++++ .../test/EcoreSchemaAndDASContextsSetupTest.java | 56 +++ .../setup/test/EcoreSchemaContextsSetup.java | 201 +++++++++ .../setup/test/EcoreSchemaContextsSetupTest.java | 64 +++ .../setup/test/XSDSchemaContextsSetup.java | 116 ++++++ .../setup/test/XSDSchemaContextsSetupTest.java | 49 +++ .../emf/create/DataTypeToADSSyntaxMapProvider.java | 54 +++ .../schema/emf/create/EAttributeTypeCreator.java | 113 +++++ .../schema/emf/create/EObjectClassCreator.java | 202 +++++++++ .../emf/create/EObjectClassCreatorHelper.java | 378 +++++++++++++++++ .../schema/emf/create/EReferenceTypeCreator.java | 95 +++++ .../schema/emf/create/EcoreTypeSystemHelper.java | 388 +++++++++++++++++ .../schema/emf/create/ModelTypeSystemCreator.java | 56 +++ .../destroy/ECascadingObjectClassDestroyer.java | 145 +++++++ .../schema/emf/destroy/EObjectClassDestroyer.java | 90 ++++ .../destroy/EStructuralFeatureTypeDestroyer.java | 61 +++ .../ldap/schema/emf/provide/SyntaxOIDProvider.java | 62 +++ .../ldap/schema/setup/test/AbstractTestSetup.java | 50 +++ .../ldap/schema/setup/test/DASContextSetup.java | 56 +++ .../schema/setup/test/DASContextSetupTest.java | 34 ++ .../schema/setup/test/DASSchemaContextsSetup.java | 191 +++++++++ .../setup/test/DASSchemaContextsSetupTest.java | 48 +++ .../setup/test/EcoreSchemaAndDASContextsSetup.java | 131 ++++++ .../test/EcoreSchemaAndDASContextsSetupTest.java | 56 +++ .../setup/test/EcoreSchemaContextsSetup.java | 132 ++++++ .../setup/test/EcoreSchemaContextsSetupTest.java | 45 ++ .../ldap/schema/setup/test/SchemaContextSetup.java | 21 + .../schema/setup/test/SchemaContextSetupTest.java | 25 ++ .../schema/setup/test/SchemaContextsSetup.java | 231 +++++++++++ .../schema/setup/test/SchemaContextsSetupTest.java | 71 ++++ .../schema/setup/test/XSDSchemaContextsSetup.java | 76 ++++ .../setup/test/XSDSchemaContextsSetupTest.java | 35 ++ .../testing/constants/DASTestingConstants.java | 9 + .../ldap/util/ComplexTypeNamespaceQualifier.java | 39 ++ .../apache/tuscany/das/ldap/util/IDGenerator.java | 10 + .../org/apache/tuscany/das/ldap/util/JNDIUtil.java | 168 ++++++++ .../tuscany/das/ldap/util/LDAPNormalizer.java | 38 ++ .../das/ldap/util/QualifiedNameNormalizer.java | 36 ++ .../ldap/util/SimpleTypeNamespaceQualifier.java | 39 ++ .../XSDNamespaceToInitialContextTransformer.java | 49 +++ .../das/ldap/util/XSDNamespaceURITokenizer.java | 26 ++ .../connect/test/ADSEmbeddedConnectionTest.java | 54 +++ .../test/InitialContextCreatorHelperTest.java | 189 +++++++++ .../create/test/InitialContextCreatorTest.java | 73 ++++ .../ldap/create/test/MetaContextCreatorTest.java | 69 ++++ .../create/test/UniqueOIDCreatorHelperTest.java | 53 +++ .../destroy/test/InitialContextDestroyerTest.java | 78 ++++ .../emf/create/test/EDataGraphCreatorTest.java | 126 ++++++ .../emf/create/test/EDataObjectCreatorTest.java | 85 ++++ .../ldap/emf/read/test/EDataGraphReaderTest.java | 156 +++++++ .../ldap/emf/read/test/EDataObjectReaderTest.java | 62 +++ .../das/ldap/emf/test/LdapDASHelperTest.java | 185 +++++++++ .../tuscany/das/ldap/emf/test/LdapDASTest.java | 437 ++++++++++++++++++++ .../ldap/emf/update/test/EDataGraphUpdateTest.java | 180 ++++++++ .../das/ldap/learning/test/LearningTest.java | 38 ++ .../emf/create/test/EAttributeTypeCreatorTest.java | 127 ++++++ .../create/test/EObjectClassCreatorHelperTest.java | 103 +++++ .../emf/create/test/EObjectClassCreatorTest.java | 411 ++++++++++++++++++ .../emf/create/test/EReferenceTypeCreatorTest.java | 125 ++++++ .../test/EcoreTypeSystemCreatorHelperTest.java | 58 +++ .../test/ECascadingObjectClassDestroyerTest.java | 397 ++++++++++++++++++ .../destroy/test/EObjectClassDestroyerTest.java | 457 +++++++++++++++++++++ .../tuscany/das/ldap/util/test/JNDIUtilTest.java | 109 +++++ .../util/test/QualifiedNameNormalizerTest.java | 42 ++ .../util/test/XSDNamespaceURITokenizerTest.java | 36 ++ .../das.ldap/src/test/resources/log4j.properties | 6 + 117 files changed, 13507 insertions(+) create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplate.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplateTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplate.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplateTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplate.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplateTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplate.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplateTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReaderHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReader.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReaderHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdater.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdaterHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/constants/EncryptionConstants.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/util/ChecksumUtils.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/ComplexTypeOIDCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/OIDCreatorHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/SimpleTypeOIDCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/Prototype.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/PrototypeUtilities.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/CommonSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataGraphSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataObjectSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/LdapDASSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractAttributeTypeCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractTypeCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/ComplexTypeRDNCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SimpleTypeRDNCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxCheckerEntryCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxEntryCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/AbstractTestSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetup.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetupTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/testing/constants/DASTestingConstants.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/connect/test/ADSEmbeddedConnectionTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorHelperTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/MetaContextCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/UniqueOIDCreatorHelperTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/destroy/test/InitialContextDestroyerTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataGraphCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataObjectCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataGraphReaderTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataObjectReaderTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASHelperTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/update/test/EDataGraphUpdateTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/learning/test/LearningTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/JNDIUtilTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/QualifiedNameNormalizerTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/XSDNamespaceURITokenizerTest.java create mode 100644 das-java/contrib/ldap/das.ldap/src/test/resources/log4j.properties (limited to 'das-java/contrib/ldap/das.ldap/src') diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplate.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplate.java new file mode 100644 index 0000000000..7977f60545 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplate.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.server.core.configuration.MutableStartupConfiguration; +import org.apache.directory.server.core.configuration.ShutdownConfiguration; +import org.apache.log4j.PropertyConfigurator; + +/** + * The Class JNDIEmbeddedConnectionTemplate. + */ +public abstract class ADSEmbeddedConnectionTemplate +extends JNDIConnectionTemplate +{ + public void tearDown() throws NamingException, Exception + { + Hashtable env = + new Hashtable(); + + env = createEnvironment(env); + + env.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory" ); + env.putAll( + new ShutdownConfiguration().toJndiEnvironment() ); + + new InitialContext( env ); + Runtime.getRuntime().gc(); + super.tearDown(); + } + + + + public void setUp() throws Exception + { + PropertyConfigurator. + configure(NLOG4J_CONFIGURATION_FILEPATH); + super.setUp(); + } + + /** + * Connect to an embedded ApacheDS server. + * + * @param providerPath the provider path ("ou=schema", ou="system", etc.) + * + * @return the ldap context + * + * @throws NamingException the naming exception + */ + public LdapContext connect( String providerPath ) throws NamingException + { + MutableStartupConfiguration mutableStartupConfiguration = + new MutableStartupConfiguration(); + + Hashtable adminEnv = + new Hashtable( ); + + adminEnv.putAll( + mutableStartupConfiguration. + toJndiEnvironment()); + + adminEnv.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + adminEnv.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + adminEnv.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + adminEnv.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE ); + new InitialLdapContext( adminEnv, null ); + + + + Hashtable env = + new Hashtable(); + + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory" ); + env.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + env.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + env.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE ); + env.put( Context.PROVIDER_URL, providerPath ); + + env.put( Context.PROVIDER_URL, providerPath ); + + return new InitialLdapContext( env, null ); + + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplateTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplateTest.java new file mode 100644 index 0000000000..f5426b3424 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedConnectionTemplateTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +public class ADSEmbeddedConnectionTemplateTest +extends ADSEmbeddedConnectionTemplate +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + } + + public void testSchemaConnect() throws NamingException + { + LdapContext ldapContext =null; + + ldapContext =connect("ou=schema"); + + assertEquals( + "ou=schema", + ldapContext.getNameInNamespace()); + } + + public void testRootDSEConnect() throws NamingException + { + LdapContext ldapContext =null; + + ldapContext =connect(""); + + assertEquals( + "", + ldapContext.getNameInNamespace()); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplate.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplate.java new file mode 100644 index 0000000000..fae915a0a2 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplate.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.server.core.configuration.Configuration; +import org.apache.directory.server.core.configuration.MutablePartitionConfiguration; +import org.apache.directory.server.core.configuration.MutableStartupConfiguration; +import org.apache.directory.server.core.configuration.ShutdownConfiguration; +import org.apache.log4j.PropertyConfigurator; + +/** + * The Class JNDIEmbeddedConnectionTemplate. + */ +public abstract class ADSEmbeddedHotPartitionTemplate +extends JNDIConnectionTemplate +{ + public void tearDown() throws NamingException, Exception + { + Hashtable env = + new Hashtable(); + + env = createEnvironment(env); + + env.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory" ); + env.putAll( + new ShutdownConfiguration().toJndiEnvironment() ); + + new InitialContext( env ); + Runtime.getRuntime().gc(); + super.tearDown(); + } + + + + public void setUp() throws Exception + { + PropertyConfigurator. + configure(NLOG4J_CONFIGURATION_FILEPATH); + super.setUp(); + } + + /** + * Connect to an embedded ApacheDS server. + * + * @param partitionName the provider path ("ou=schema", ou="system", etc.) + * + * @return the ldap context + * + * @throws NamingException the naming exception + */ + public LdapContext connect( String partitionName ) throws NamingException + { + MutableStartupConfiguration mutableStartupConfiguration = + new MutableStartupConfiguration(); + + Hashtable adminEnv = + new Hashtable( ); + + adminEnv.putAll( + mutableStartupConfiguration. + toJndiEnvironment()); + + adminEnv.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + adminEnv.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + adminEnv.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + adminEnv.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE ); + new InitialLdapContext( adminEnv, null ); + + + MutablePartitionConfiguration dasPartition = + new MutablePartitionConfiguration(); + + Attributes suffixAttributes = new BasicAttributes(); + suffixAttributes.put( "objectClass", "top"); + suffixAttributes.get( "objectClass" ).add( "organizationalUnit" ); + suffixAttributes.put( "ou", partitionName ); + + dasPartition.setId( partitionName); + dasPartition.setSuffix( "ou=" +partitionName ); + dasPartition.setContextEntry( suffixAttributes ); + + Set partitions = + new HashSet (); + + partitions.add( dasPartition ); + + mutableStartupConfiguration. + setPartitionConfigurations( partitions ); + + Hashtable env = + new Hashtable(); + + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory" ); + env.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + env.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + env.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE ); + env.put( + Context.PROVIDER_URL, + "ou=" + partitionName ); + + env.put( + Configuration.JNDI_KEY, + mutableStartupConfiguration ); + + return new InitialLdapContext( env, null ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplateTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplateTest.java new file mode 100644 index 0000000000..aba1ff7940 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/ADSEmbeddedHotPartitionTemplateTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +public class ADSEmbeddedHotPartitionTemplateTest +extends ADSEmbeddedHotPartitionTemplate +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + } + + public void testCreateHotPartition() throws NamingException + { + LdapContext ldapContext = + null; + + ldapContext = + connect("test"); + + assertEquals( + "ou=test", + ldapContext.getNameInNamespace()); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplate.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplate.java new file mode 100644 index 0000000000..ae267144eb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplate.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.ApacheDSConnectionConstants; + +import junit.framework.TestCase; + +/* + * Just a class template class + */ +public abstract class JNDIConnectionTemplate +extends TestCase +implements ApacheDSConnectionConstants +{ + protected String providerHost = + "ldap://localhost:10389/"; + + protected String providerPath = + SYSTEM_PROVIDER_PATH; + + private String providerURL = + providerHost + providerPath; + + protected String initialContextFactory = + SUN_CONTEXT_FACTORY; + + protected String securityAuthentication = + SIMPLE_SECURITY_AUTHENTICATION_VALUE; + + protected String securityPrincipal = + DEFAULT_SECURITY_PRINCIPAL_VALUE; + + protected String credentials = + DEFAULT_SECURITY_CREDENTIALS_VALUE; + + public Hashtable createEnvironment( + Hashtable env) + { + providerURL = + providerHost + providerPath; + + env.put( + Context.PROVIDER_URL, + providerURL); + + env.put( + Context.INITIAL_CONTEXT_FACTORY, + initialContextFactory ); + + env.put( + Context.SECURITY_AUTHENTICATION, + securityAuthentication); + + env.put( + Context.SECURITY_PRINCIPAL, + securityPrincipal ); + + env.put( + Context.SECURITY_CREDENTIALS, + credentials ); + + return env; + } + + public LdapContext connect() throws NamingException + { + Hashtable env = + new Hashtable(); + + return new InitialLdapContext( + createEnvironment(env), null); + } + + public void setUp() throws Exception + { + super.setUp(); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplateTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplateTest.java new file mode 100644 index 0000000000..883a556167 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIConnectionTemplateTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +/* + * These tests require a running server. + */ +public class JNDIConnectionTemplateTest extends JNDIConnectionTemplate +{ + private static LdapContext systemContext = null; + private static LdapContext schemaContext = null; + + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testSystemContextConnection() + throws NamingException + { + systemContext = connect(); + assertNotNull( systemContext ); + assertNotNull( connect() ); + assertEquals( + systemContext. + getNameInNamespace(), + "ou=system"); + } + + public void testSchemaContextConnection() + throws NamingException + { + providerPath = SCHEMA_PROVIDER_PATH; + schemaContext = connect(); + assertNotNull (schemaContext); + assertNotNull(connect()); + assertEquals( + schemaContext.getNameInNamespace(), + "ou=schema"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplate.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplate.java new file mode 100644 index 0000000000..546ccea0d5 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplate.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.server.core.configuration.Configuration; +import org.apache.directory.server.core.configuration.MutablePartitionConfiguration; +import org.apache.directory.server.core.configuration.MutableStartupConfiguration; +import org.apache.tuscany.das.ldap.constants.ApacheDSConnectionConstants; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +import junit.framework.TestCase; + +/* + * Just a class template class + */ +public abstract class JNDIHotPartitionConnectionTemplate +extends AbstractTestSetup +implements ApacheDSConnectionConstants +{ + + public Hashtable createEnvironment( + Hashtable env, + String partitionName) throws NamingException + { + MutableStartupConfiguration mutableStartupConfiguration = + new MutableStartupConfiguration(); + + MutablePartitionConfiguration dasPartition = + new MutablePartitionConfiguration(); + + Attributes suffixAttributes = new BasicAttributes(); + suffixAttributes.put( "objectClass", "top"); + suffixAttributes.get( "objectClass" ).add( "organizationalUnit" ); + suffixAttributes.put( "ou", partitionName ); + + dasPartition.setId( partitionName); + dasPartition.setSuffix( "ou=" +partitionName ); + dasPartition.setContextEntry( suffixAttributes ); + + Set partitions = + new HashSet (); + + partitions.add( dasPartition ); + + mutableStartupConfiguration. + setPartitionConfigurations( partitions ); + + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory" ); + + env.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + + env.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + + env.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE ); + + env.put( + Context.PROVIDER_URL, + "ou=" + partitionName ); + + env.put( + Configuration.JNDI_KEY, + mutableStartupConfiguration ); + + return env; + } + + public LdapContext connect( String partitionName ) + throws NamingException + { + Hashtable env = + new Hashtable(); + + return new InitialLdapContext( + createEnvironment(env, partitionName), null); + } + + public void setUp() throws Exception + { + super.setUp(); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplateTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplateTest.java new file mode 100644 index 0000000000..85b9f5eb10 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/directory/apacheds/testing/setup/JNDIHotPartitionConnectionTemplateTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.apacheds.testing.setup; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +/* + * These tests require a running server. + */ +public class JNDIHotPartitionConnectionTemplateTest +extends JNDIHotPartitionConnectionTemplate +{ + private static LdapContext testContext = null; + private static LdapContext systemContext = null; + private static LdapContext schemaContext = null; + + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testTestContextConnection() + throws NamingException + { + testContext = connect("test"); + assertNotNull(testContext ); + assertEquals( + testContext.getNameInNamespace(), "ou=test"); + } + + + public void testSystemContextConnection() + throws NamingException + { + systemContext = connect("system"); + assertNotNull( systemContext ); + assertEquals( + systemContext.getNameInNamespace(), "ou=system"); + } + + public void testSchemaContextConnection() + throws NamingException + { + schemaContext = connect("schema"); + assertNotNull( schemaContext ); + assertEquals( + schemaContext.getNameInNamespace(), + "ou=schema"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java new file mode 100644 index 0000000000..b547f1447b --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.connect; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.server.core.configuration.MutablePartitionConfiguration; +import org.apache.directory.server.core.configuration.MutableStartupConfiguration; +import org.apache.directory.server.core.configuration.ShutdownConfiguration; +import org.apache.log4j.PropertyConfigurator; +import org.apache.tuscany.model.Configuration; + +/** + * The Class JNDIEmbeddedConnectionTemplate. + */ +public class ADSEmbeddedConnection extends JNDIConnection { + private Configuration configuration = null; + + public ADSEmbeddedConnection(Configuration configuration) { + super(configuration); + this.configuration = configuration; + } + + /** + * Shutdown. + * + * Shuts down an embedded instance of ADS. + * + * @throws NamingException + * the naming exception + * @throws Exception + * the exception + */ + public void shutdown() throws NamingException, Exception { + Hashtable env = new Hashtable(); + + env = createEnvironment(env); + + env.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + env.put( + Context.INITIAL_CONTEXT_FACTORY, + APACHE_CONTEXT_FACTORY); + env.putAll( + new ShutdownConfiguration().toJndiEnvironment()); + + new InitialContext(env); + Runtime.getRuntime().gc(); + } + + /** + * Startup. + * + * Starts an embedded instance of ADS and creates the the DAS partition, if + * it does not already exist. + * + * @throws NamingException + * the naming exception + */ + public LdapContext startup(String partitionName) + throws NamingException { + PropertyConfigurator. + configure( + configuration. + getNlog4jConfigurationFilePath()); + + MutableStartupConfiguration mutableStartupConfiguration = + new MutableStartupConfiguration(); + + Hashtable adminEnv = + new Hashtable(); + + adminEnv.putAll(mutableStartupConfiguration.toJndiEnvironment()); + + adminEnv.put( + Context.PROVIDER_URL, + SYSTEM_PROVIDER_PATH); + adminEnv.put( + Context.SECURITY_PRINCIPAL, + configuration.getSecurityPrincipal()); + adminEnv.put( + Context.SECURITY_CREDENTIALS, + configuration.getSecurityCredentials()); + adminEnv.put( + Context.SECURITY_AUTHENTICATION, + configuration.getSecurityAuthenticationType()); + new InitialLdapContext(adminEnv, null); + + MutablePartitionConfiguration dasPartition = + new MutablePartitionConfiguration(); + + Attributes suffixAttributes = + new BasicAttributes(); + suffixAttributes.put(OBJECT_CLASS, TOP); + suffixAttributes.get(OBJECT_CLASS).add(ORGANIZATIONAL_UNIT); + suffixAttributes.put(OU, partitionName); + + dasPartition.setId(partitionName); + dasPartition.setSuffix(getProviderPath(partitionName)); + dasPartition.setContextEntry(suffixAttributes); + + Set partitions = + new HashSet(); + + partitions.add(dasPartition); + + mutableStartupConfiguration.setPartitionConfigurations(partitions); + + Hashtable env = + new Hashtable(); + + env.put( + Context.INITIAL_CONTEXT_FACTORY, + "org.apache.directory.server.core.jndi.CoreContextFactory"); + env.put( + Context.SECURITY_PRINCIPAL, + DEFAULT_SECURITY_PRINCIPAL_VALUE); + env.put( + Context.SECURITY_CREDENTIALS, + DEFAULT_SECURITY_CREDENTIALS_VALUE); + env.put( + Context.SECURITY_AUTHENTICATION, + SIMPLE_SECURITY_AUTHENTICATION_VALUE); + env.put( + Context.PROVIDER_URL, getProviderPath(partitionName)); + + env.put( + org.apache.directory.server.core.configuration.Configuration.JNDI_KEY, + mutableStartupConfiguration); + + return new InitialLdapContext(env, null); + } + + public LdapContext connect(String partitionName) throws NamingException + { + return startup(partitionName); + } + + /** + * Gets the provider path. TODO Move to helper + * + * @return the provider path + */ + public String getProviderPath(String partitionName) { + return OU + "=" + partitionName; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java new file mode 100644 index 0000000000..d36dacc952 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.connect; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; +import org.apache.tuscany.model.Configuration; + +import org.apache.tuscany.das.ldap.constants.ApacheDSConnectionConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +/* + * Just a class template class + */ +public class JNDIConnection +implements +ApacheDSConnectionConstants, +AttributeTypeConstants, +ObjectClassConstants +{ + private Configuration configuration = null; + + public JNDIConnection(Configuration configuration) + { + this.configuration=configuration; + } + + public Hashtable createEnvironment( + Hashtable env) + { + env.put( + Context.INITIAL_CONTEXT_FACTORY, + configuration.getInitialContextFactory() ); + + env.put( + Context.SECURITY_AUTHENTICATION, + configuration.getSecurityAuthenticationType()); + + env.put( + Context.SECURITY_PRINCIPAL, + configuration.getSecurityPrincipal() ); + + env.put( + Context.SECURITY_CREDENTIALS, + configuration.getSecurityCredentials() ); + + return env; + } + + public LdapContext connect(String partitionName) throws NamingException + { + Hashtable env = + new Hashtable(); + + env = createEnvironment(env); + + env.put( + Context.PROVIDER_URL, + getProviderURL(partitionName)); + + return new InitialLdapContext(env, null); + } + + public String getProviderURL(String partitionName) + { + return "ldap://" + + configuration.getHost() + + ":" + + configuration.getPort() + + "/" + + OU + + "=" + + partitionName; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java new file mode 100644 index 0000000000..8e50e72178 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.util.XSDNamespaceURITokenizer; +import org.eclipse.emf.common.util.URI; + +/** + * The InitialContextCreator for a model's directory namespace + */ +public class InitialContextCreator +{ + /** + * Creates the parent context for the root DataObject instance + * + * @param dasContext the dir context + * @param xsdNamespace the xml namespace of the DataObjects + * + * @return the directory context + * + * @throws NamingException the naming exception + */ + public static LdapContext create( + String xsdNamespace, + LdapContext dasContext) throws NamingException + { + URI xsdNamespaceURI = + URI.createURI( + xsdNamespace ); + + String[] pathTokens = + XSDNamespaceURITokenizer. + createPathTokens( + xsdNamespaceURI ); + + String[] authorityTokens = + XSDNamespaceURITokenizer. + createAuthorityTokens( + xsdNamespaceURI ); + + dasContext = + InitialContextCreatorHelper. + createAuthorityContext( + dasContext, + authorityTokens ); + + dasContext = + InitialContextCreatorHelper. + createPathContext( + dasContext, + pathTokens ); + + return dasContext; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java new file mode 100644 index 0000000000..0be0975082 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; + +/** + * The Class InitialContextCreatorHelper. + */ +public class InitialContextCreatorHelper +implements +ObjectClassConstants, +SchemaObjectClassConstants, +AttributeTypeConstants +{ + + /** + * Creates the sub context if it does not already exist. + * + * @param ldapContext the ldap context + * @param subContextRDN the sub context + * @param attributes the attributes + * + * @return the ldap context + * + * @throws NamingException the naming exception + */ + public static LdapContext createSubContext( + LdapContext ldapContext, + String subContextRDN, + Attributes attributes) + throws NamingException + { + try + { + ldapContext = + ( LdapContext ) + ldapContext. + lookup( subContextRDN ); + } + catch ( NamingException e ) + { + if (attributes == null) + { + ldapContext = + ( LdapContext ) + ldapContext. + createSubcontext( subContextRDN ); + } + else + { + ldapContext = + ( LdapContext ) + ldapContext. + createSubcontext( + subContextRDN, + attributes ); + } + } + return ldapContext; + } + + /** + * Creates the authority context. Authority + * means the Authority component of a URL. + * For example if the authority is "example.com", + * then the authority context will be "cn=example, cn=com". + * + * @param ldapContext the ldap context + * @param authorityTokens the authority tokens + * + * @return the ldap context + * + * @throws NamingException the naming exception + * + */ + public static LdapContext createAuthorityContext( + LdapContext ldapContext, + String[] authorityTokens) + throws NamingException + { + for (int i = authorityTokens.length-1; i >= (0); i--) + { + String subContext = CN+ "=" + authorityTokens[i]; + ldapContext = (LdapContext) createSubContext( + ldapContext, + subContext, null ); + } + return ldapContext; + } + + /** + * Creates the path context. + * Path means the path component of a URL. + * For example if the authority is "example.com/users/accounts", + * then the path context will be "cn=accounts, cn=users". The full + * model namespaced context will be "cn=accounts, cn=users, cn=example, cn=com" + * + * @param authorityContext the ldap context + * @param pathTokens the path tokens + * + * @return the ldap context + * + * @throws NamingException the naming exception + */ + public static LdapContext createPathContext( + LdapContext authorityContext, + String[] pathTokens) + throws NamingException + { + for (int i = 1; i < (pathTokens.length); i++) + { + String subContext = CN + "=" + pathTokens[i]; + authorityContext = (LdapContext) createSubContext( + authorityContext, + subContext, null ); + } + return authorityContext; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java new file mode 100644 index 0000000000..4caa380258 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; + +/** + * The Class MetaContextCreator. + */ +public class MetaContextCreator +implements +DASConstants, +AttributeTypeConstants +{ + /** + * Create a meta context below the provided parent context. + * + * @param metaParentContext the context + * + * @return the ldap context + * + * @throws NamingException the naming exception + */ + public static LdapContext create( + LdapContext metaParentContext) throws NamingException + { + String rdn = + CN + "=" + META_CONTEXT_NAME; + + try + { + return + ( LdapContext ) + metaParentContext.lookup( rdn ); + } + catch(Exception e) + { + return + ( LdapContext ) + metaParentContext. + createSubcontext( rdn ); + } + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java new file mode 100644 index 0000000000..2cc3fc7d36 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.util.JNDIUtil; + +// TODO: Auto-generated Javadoc +/** + * The Class InitialContextDestroyer. + */ +public class InitialContextDestroyer +{ + + /** + * Destroys the initial naming context + * when the parent entries do not contain + * other child entries. If the initial + * naming context also supports other + * entries, then a NamingException will + * be thrown. + * + * @param partitionContext the partition context + * @param initialContext the initial context + * + * @throws NamingException the naming exception + */ + public static void destroy( + DirContext initialContext, + DirContext partitionContext) + throws NamingException + { + String[] initialContextComponents = + JNDIUtil. + calculateDNComponents( initialContext ); + + String[] partitionContextComponents = + JNDIUtil.calculateDNComponents( partitionContext ); + + int numberOfPossibleSubcontexts = + initialContextComponents.length + - partitionContextComponents.length; + + for (int i = 0; i < numberOfPossibleSubcontexts; i++) + { + String rdn = initialContextComponents[i]; + + initialContext = JNDIUtil.getParentContext( + initialContext, + partitionContext ); + + initialContext.destroySubcontext( rdn ); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java new file mode 100644 index 0000000000..7849b33edb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; + +/** + * The Class MetaContextDestroyer. + */ +public class MetaContextDestroyer +implements +DASConstants, +AttributeTypeConstants +{ + /** + * Destroys an empty meta context + * + * @param initialContext the initial context + * + * @throws NamingException the naming exception thrown when the meta context has child entries + */ + public static void destroy( + DirContext initialContext) + throws NamingException + { + String rdn = + CN + "=" + META_CONTEXT_NAME; + + initialContext. + destroySubcontext( rdn ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java new file mode 100644 index 0000000000..31d6d8d11e --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java @@ -0,0 +1,81 @@ + +package org.apache.tuscany.das.ldap.emf; + +import java.util.Hashtable; +import java.util.Map; + +import javax.naming.ldap.LdapContext; + +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class Context +{ + private Map xsdNamespaceToLdapContextMap = null; + private Map dataObjectToRelativeDNCache = null; + + + private LdapContext dasContext = null; + private LdapContext schemaContext = null; + private LdapContext dasMetaContext = null; + private LdapContext ecoreObjectClassesContext = null; + private LdapContext ecoreAttributeTypesContext = null; + + public Context() + { + xsdNamespaceToLdapContextMap = + new Hashtable(); + + dataObjectToRelativeDNCache = + new Hashtable(); + } + + public LdapContext getDasContext() + { + return dasContext; + } + public void setDasContext( LdapContext dasContext ) + { + this.dasContext = dasContext; + } + public LdapContext getSchemaContext() + { + return schemaContext; + } + public void setSchemaContext( LdapContext schemaContext ) + { + this.schemaContext = schemaContext; + } + public LdapContext getDasMetaContext() + { + return dasMetaContext; + } + public void setDasMetaContext( LdapContext dasMetaContext ) + { + this.dasMetaContext = dasMetaContext; + } + public LdapContext getEcoreObjectClassesContext() + { + return ecoreObjectClassesContext; + } + public void setEcoreObjectClassesContext( LdapContext ecoreObjectClassesContext ) + { + this.ecoreObjectClassesContext = ecoreObjectClassesContext; + } + public LdapContext getEcoreAttributeTypesContext() + { + return ecoreAttributeTypesContext; + } + public void setEcoreAttributeTypesContext( LdapContext ecoreAttributeTypesContext ) + { + this.ecoreAttributeTypesContext = ecoreAttributeTypesContext; + } + public Map getXsdNamespaceToLdapContextMap() + { + return xsdNamespaceToLdapContextMap; + } + + public Map getDataObjectToRelativeDNCache() + { + return dataObjectToRelativeDNCache; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java new file mode 100644 index 0000000000..43e556714f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java @@ -0,0 +1,379 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf; + +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException; +import org.apache.tuscany.das.ldap.connect.ADSEmbeddedConnection; +import org.apache.tuscany.das.ldap.connect.JNDIConnection; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.create.MetaContextCreator; +import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreator; +import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader; +import org.apache.tuscany.das.ldap.emf.update.EDataGraphUpdater; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.apache.tuscany.das.ldap.schema.emf.create.ModelTypeSystemCreator; +import org.apache.tuscany.model.Configuration; +import org.apache.tuscany.model.DASMeta; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class LdapDAS +implements DASConstants +{ + private Map metaDataObjectToRelativeDNCache = null; + + private Configuration configuration = null; + private DASMeta dasMeta = null; + private EDataGraph dasMetaDataGraph = null; + private Context context = null; + private ADSEmbeddedConnection adsEmbeddedConnection = null; + + + public LdapDAS(Configuration configuration) + throws NamingException + { + metaDataObjectToRelativeDNCache = + new Hashtable(); + + + this.configuration = + configuration; + + context = + new Context(); + + JNDIConnection jndiConnection = null; + + if (configuration.isEmbedded()) + { + adsEmbeddedConnection = + new ADSEmbeddedConnection(configuration); + context. + setDasContext( + adsEmbeddedConnection. + connect( + configuration. + getDasPartitionName() )); + + context. + setSchemaContext( + adsEmbeddedConnection. + connect( + configuration. + getSchemaPartitionName() )); + } + else + { + jndiConnection = + new JNDIConnection(configuration); + + context. + setDasContext( + jndiConnection.connect( + configuration. + getDasPartitionName() )); + + context. + setSchemaContext( + jndiConnection.connect( + configuration. + getSchemaPartitionName() )); + } + + context. + setDasMetaContext( + MetaContextCreator. + create( + context. + getDasContext() )); + + context.setEcoreObjectClassesContext( + LdapDASHelper. + createEcoreObjectClassesContext( + context. + getSchemaContext() )); + + context.setEcoreAttributeTypesContext( + LdapDASHelper. + createEcoreAttributeTypesContext( + context. + getSchemaContext() )); + } + + /** + * Write. + * + * @param eDataGraph the e data graph + * @param dasContext the das context + * + * @return the map< E data object, string> + * + * @throws NamingException the naming exception + * + * First tries to find a LdapContext that matches the xsdNamespace + * of the DataGraph that is about to be written. If it finds one, then + * it know that the type system has been written, thus it can skip this + * step. + * + * If the LdapContext lookup fails, the type system may still exist + * the check: + * + * configuration.getSupportedSchemas().contains(xsdNamespace) + * + * is performed. + * + * If the supported schema list contains the xsdNamespace, the + * corresponding the LdapContext parent context of the root DataObject + * instance is created and the DataGraph written. + * + * If the xsdNamespace is not contained by the supported schemas list, + * a final check is performed to see whether the type system exists. If this + * check succeeds and exception is thrown, because it should not. This could happen + * if the configuration write that occurs as the supported schema list is updated failed, + * or the the read of the supported schemas from the DIT failed. + * + */ + public void create( + EDataGraph eDataGraph) + throws NamingException, Exception + { + + EObject rootEObject = + eDataGraph. + getERootObject(); + + EPackage ePackage = + rootEObject. + eClass(). + getEPackage(); + + String xsdNamespace = + ePackage. + getNsURI(); + + LdapContext rootContext = + context. + getXsdNamespaceToLdapContextMap(). + get(xsdNamespace); + + if (rootContext != null) + { + EDataGraphCreator.create( + eDataGraph, + rootContext, + context. + getDataObjectToRelativeDNCache()); + } + + /* + * The root context was not yet created so we check if the + * schema is written for the model instance, and if it is + * we create the root context and add it to the context map. + */ + metaDataObjectToRelativeDNCache = + new Hashtable(); + + dasMetaDataGraph = + LdapDASHelper.readDasMeta( + context, + metaDataObjectToRelativeDNCache ); + + dasMeta = ( DASMeta ) dasMetaDataGraph.getRootObject(); + + if (LdapDASHelper.isSchemaReady(xsdNamespace, dasMeta)) + { + rootContext = + InitialContextCreator. + create( + xsdNamespace, + context. + getDasContext() ); + + context.getXsdNamespaceToLdapContextMap(). + put(xsdNamespace, rootContext); + + EDataGraphCreator.create( + eDataGraph, + rootContext, + context.getDataObjectToRelativeDNCache()); + } + + /* + * The model's schema is not yet written (We also do a validation + * check to make sure the server is not in an inconsistent state) + * so we need to write the schema and then write the model instance. + */ + + if (LdapDASHelper.isSchemaWritten( + rootEObject.eClass(), + context. + getEcoreObjectClassesContext() )) + { + throw new RuntimeException("This should not happen");//TODO better message + constant + } + + List eClassifiers = + EcoreTypeSystemHelper. + createEClassifiersList(ePackage); + + rootContext = + InitialContextCreator. + create( + xsdNamespace, + context.getDasContext() ); + + context.getXsdNamespaceToLdapContextMap(). + put(xsdNamespace, rootContext); + + LdapContext dasModelMetaContext = + MetaContextCreator. + create(rootContext); + + ModelTypeSystemCreator.create( + dasModelMetaContext, + context.getEcoreAttributeTypesContext(), + context.getEcoreObjectClassesContext(), + eClassifiers, + TUSCANY_OID_PREFIX_VALUE); + + dasMetaDataGraph. + getChangeSummary(). + beginLogging(); + + dasMeta. + getSupportedSchemas(). + add(xsdNamespace); + + dasMetaDataGraph. + getChangeSummary(). + endLogging(); + + EDataGraphUpdater.update( + dasMetaDataGraph, + context.getDasMetaContext(), + metaDataObjectToRelativeDNCache); + + EDataGraphCreator.create( + eDataGraph, + rootContext, + context. + getDataObjectToRelativeDNCache()); + + } + + + public EDataGraph read( + EClass rootDataObjectEClass, + String id) + throws LdapNameNotFoundException, NamingException + { + String xsdNamespace = + rootDataObjectEClass. + getEPackage(). + getNsURI(); + + LdapContext rootContext = + context. + getXsdNamespaceToLdapContextMap(). + get(xsdNamespace); + + if (rootContext == null) + { + rootContext = + InitialContextCreator. + create( + xsdNamespace, + context. + getDasContext() ); + + context. + getXsdNamespaceToLdapContextMap(). + put(xsdNamespace, rootContext); + } + + return EDataGraphReader.read( + rootDataObjectEClass, + id, + rootContext, + context. + getDataObjectToRelativeDNCache()); + } + + public void update(EDataGraph eDataGraph) + throws NamingException + { + EDataObject rootDataObject = + ( EDataObject ) eDataGraph.getRootObject(); + + EClass rootDataObjectEClass = + rootDataObject.eClass(); + + String xsdNamespace = + rootDataObjectEClass. + getEPackage(). + getNsURI(); + + LdapContext rootContext = + context. + getXsdNamespaceToLdapContextMap(). + get(xsdNamespace); + + if (rootContext == null) + { + rootContext = + InitialContextCreator. + create( + xsdNamespace, + context. + getDasContext() ); + + context. + getXsdNamespaceToLdapContextMap(). + put(xsdNamespace, rootContext); + } + + EDataGraphUpdater.update( + eDataGraph, + rootContext, + context. + getDataObjectToRelativeDNCache()); + } + + public Context getContext() + { + return context; + } + + public ADSEmbeddedConnection getAdsEmbeddedConnection() + { + return adsEmbeddedConnection; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java new file mode 100644 index 0000000000..d9d2f9a0bd --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf; + +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreator; +import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.apache.tuscany.das.ldap.schema.emf.create.ModelTypeSystemCreator; +import org.apache.tuscany.model.ConfigurationFactory; +import org.apache.tuscany.model.DASMeta; +import org.apache.tuscany.model.impl.ConfigurationPackageImpl; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; +import org.eclipse.emf.ecore.sdo.SDOFactory; + +public class LdapDASHelper +implements +DASConstants, +ObjectClassConstants, +AttributeTypeConstants, +SchemaObjectClassConstants +{ + public static EDataGraph readDasMeta( + Context context, + Map metaDataObjectToRelativeDNCache) + throws Exception + { + EDataGraph dasMetaDataGraph = null; + + try + { + dasMetaDataGraph = + EDataGraphReader.read( + ConfigurationPackageImpl. + eINSTANCE.getDASMeta(), + DAS_META_ID_DEFAULT, + context. + getDasMetaContext(), + metaDataObjectToRelativeDNCache); + } + catch(NamingException e) + { + List eClassifiers = + EcoreTypeSystemHelper. + createEClassifiersList( + ConfigurationPackageImpl. + eINSTANCE); + + ModelTypeSystemCreator. + create( + context.getDasMetaContext(), + context.getEcoreAttributeTypesContext(), + context.getEcoreObjectClassesContext(), + eClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + DASMeta dasMeta = + ConfigurationFactory. + INSTANCE. + createDASMeta(); + + dasMetaDataGraph = + SDOFactory. + eINSTANCE. + createEDataGraph(); + + dasMetaDataGraph. + setERootObject( + ( EObject ) dasMeta ); + + EDataGraphCreator.create( + dasMetaDataGraph, + context. + getDasMetaContext(), + metaDataObjectToRelativeDNCache); + } + return dasMetaDataGraph; + } + + public static boolean isSchemaReady( + String xsdNamespace, + DASMeta dasMeta) + { + return + dasMeta. + getSupportedSchemas(). + contains(xsdNamespace); + } + + public static boolean isSchemaWritten( + EClass eClass, + LdapContext ecoreObjectClassesContext) + throws Exception + { + String xsdNamespace = + eClass.getEPackage().getNsURI(); + + String eObjectClassRDN = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClass.getName()); + try { + ecoreObjectClassesContext. + lookup( eObjectClassRDN ); + } + catch (Exception e) + { + return false; + } + return true; + } + + + public static boolean isSchemaSupported( + String xsdNamespaceURI, + DASMeta dasMeta) + { + return + dasMeta. + getSupportedSchemas(). + contains(xsdNamespaceURI); + } + + public static void initializeSchemaContexts( + LdapContext schemaContext, + LdapContext ecoreObjectClassesContext, + LdapContext ecoreAttributeTypesContext) + throws NamingException + { + LdapContext ecoreContext = + createEcoreContext(schemaContext); + + ecoreObjectClassesContext = + createEcoreObjectClassesContext(ecoreContext); + + ecoreAttributeTypesContext = + createEcoreAttributeTypesContext( ecoreContext ); + } + + + public static LdapContext createEcoreContext( + LdapContext schemaContext) + throws NamingException + { + String ecoreContextRDN = + CN + "=" + ECORE_CONTEXT_NAME; + + try + { + return ( LdapContext ) schemaContext.lookup( ecoreContextRDN ); + } + catch (Exception e) + { + //Create the context + } + + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + contextAttributes.put( objectClassAttribute ); + contextAttributes.put( CN, ECORE_CONTEXT_NAME ); + + return + ( LdapContext ) + schemaContext. + createSubcontext( + ecoreContextRDN, + contextAttributes ); + } + + public static LdapContext createEcoreObjectClassesContext( + LdapContext schemaContext) + throws NamingException + { + LdapContext ecoreContext = + createEcoreContext(schemaContext); + + String ecoreObjectClassesContextRDN = + OU + "=" + OBJECT_CLASSES_CONTEXT_NAME; + + try + { + return + ( LdapContext ) + ecoreContext. + lookup( + ecoreObjectClassesContextRDN ); + } + catch (Exception e) + { + //Create the context + } + + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return + ( LdapContext ) + ecoreContext. + createSubcontext( + ecoreObjectClassesContextRDN, + contextAttributes ); + } + + public static LdapContext createEcoreAttributeTypesContext( + LdapContext schemaContext) + throws NamingException + { + LdapContext ecoreContext = + createEcoreContext(schemaContext); + + String ecoreAttributeTypesContextRDN = + OU + "=" + ATTRIBUTE_TYPES_CONTEXT_NAME; + + try + { + return + ( LdapContext ) + ecoreContext. + lookup( + ecoreAttributeTypesContextRDN ); + } + catch (Exception e) + { + //Create the context + } + + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + contextAttributes.put( OU, ATTRIBUTE_TYPES_CONTEXT_NAME ); + contextAttributes.put( objectClassAttribute ); + + return + ( LdapContext ) + ecoreContext.createSubcontext( + ecoreAttributeTypesContextRDN, + contextAttributes ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java new file mode 100644 index 0000000000..bfba12d3b5 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create; + +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphCreator +implements AttributeTypeConstants +{ + public static void create( + EDataGraph eDataGraph, + LdapContext rootContext, + Map dataObjectToRelativeDNCache) + throws NamingException + { + EDataObject rootDataObject = + (EDataObject) + eDataGraph.getRootObject(); + + EDataObjectCreator.create( + rootDataObject, + rootContext, + dataObjectToRelativeDNCache); + + EList children = + rootDataObject.eContents(); + + if (children.size() > 0) + { + EDataGraphCreatorHelper.createChildren( + children, + rootContext, + dataObjectToRelativeDNCache); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java new file mode 100644 index 0000000000..ab1209224a --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create; + +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphCreatorHelper +implements AttributeTypeConstants +{ + /* + * TODO Make mutlithreaded + */ + public static void createChildren( + EList children, + LdapContext rootContext, + Map dataObjectToRelativeDNCache) + throws NamingException + { + LdapContext eContainmentFeatureContext = + null; + + for (EObject eObject : children) + { + String parentContextRDN = + dataObjectToRelativeDNCache.get(eObject.eContainer()); + + LdapContext parentContext = + (LdapContext) + rootContext. + lookup(parentContextRDN); + + EStructuralFeature eContainmentFeature = + eObject.eContainingFeature(); + + String eContainingFeatureContextName = + CN + "="+ eContainmentFeature.getName(); + + try + { + eContainmentFeatureContext = + (LdapContext) + parentContext.lookup( + eContainingFeatureContextName); + } + catch (Exception e) + { + eContainmentFeatureContext = + (LdapContext) + parentContext. + createSubcontext( + eContainingFeatureContextName); + } + + EDataObjectCreator.create(( + EDataObject) eObject, + eContainmentFeatureContext, + dataObjectToRelativeDNCache); + + children = + eObject.eContents(); + + if ( children.size()> 0) + { + createChildren( + children, + rootContext, + dataObjectToRelativeDNCache); + } + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java new file mode 100644 index 0000000000..5d79d40fb5 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create; + +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataObjectCreator +implements DASConstants +{ + /** + * Create the LDAP entry for the EDataObject argument + * + * @param eDataObject the e data object + * @param containerContext the container context + * + * @throws NamingException the naming exception + */ + public static void create( + EDataObject eDataObject, + LdapContext containerContext, + Map dataObjectToRelativeDNCache) + throws NamingException + { + String rdn = + null; + Object dataObjectID = + null; + + EClass eClass = + eDataObject.eClass(); + + EAttribute idEAttribute = + eClass.getEIDAttribute(); + + String namespaceURI = + eClass.getEPackage().getNsURI(); + + String qualifiedEAttributeName = + null; + String normalizedEAttributeName = + null; + + Attributes attributes = + new BasicAttributes(); + + attributes = + EDataObjectCreatorHelper.processEAttributes( + attributes, + eDataObject, + eClass, + namespaceURI); + + attributes = + EDataObjectCreatorHelper.processEReferences( + attributes, + eDataObject, + eClass, + namespaceURI); + + String qualifiedEClassName = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName() ); + + String normalizedEClassName = + QualifiedNameNormalizer. + normalize(qualifiedEClassName); + + Attribute objectClassAttribute = + new BasicAttribute("objectClass"); + + objectClassAttribute. + add(normalizedEClassName); + + attributes.put(objectClassAttribute); + + dataObjectID = + eDataObject.eGet(idEAttribute ); + + qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + idEAttribute.getName() ); + + normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + rdn = + normalizedEAttributeName + "=" + dataObjectID; + + containerContext.createSubcontext( + rdn, + attributes ); + + EDataObjectCreatorHelper. + updateDataObjectToRelativeDNCache( + eDataObject, + dataObjectToRelativeDNCache, + rdn); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java new file mode 100644 index 0000000000..90ec5701ad --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java @@ -0,0 +1,284 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create; + +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataObjectCreatorHelper +implements DASConstants +{ + + public static void updateDataObjectToRelativeDNCache( + EDataObject eDataObject, + Map dataObjectToRelativeDNCache, + String rdn) + { + EDataObject parentDataObject = + (EDataObject) eDataObject.eContainer(); + + if (parentDataObject !=null) + { + String parentRDN = + dataObjectToRelativeDNCache. + get(parentDataObject); + rdn = + rdn + + "," + + "cn=" + + eDataObject.eContainingFeature().getName() + + "," + + parentRDN; + dataObjectToRelativeDNCache.put(eDataObject, rdn); + } + else + { + dataObjectToRelativeDNCache.put(eDataObject, rdn); + } + } + + + /** + * Process EAttributes adding the normalized EAttribute instance's + * name and corresponding values to the attributes argument. + * + * @param attributes the attributes + * @param eDataObject the e data object + * @param eClass the e class + * @param namespaceURI the namespace URI + * + * @return the attributes + * + * @throws NamingException the naming exception + * + * Note that ApacheDS supports the Syntaxes (DataTypes) + * Boolean, Integer, String. This means that all values that + * are not Boolean or Integer are stored as Strings. + */ + public static Attributes processEAttributes( + Attributes attributes, + EDataObject eDataObject, + EClass eClass, + String namespaceURI) + throws NamingException + { + EcorePackage ecorePackage = + EcorePackage.eINSTANCE; + + EAttribute idEAttribute = + eClass.getEIDAttribute(); + + List eAttributes = + eClass.getEAllAttributes(); + + String qualifiedEAttributeName = + null; + String normalizedEAttributeName = + null; + + for (EAttribute eAttribute : eAttributes) + { + Attribute attribute = + processEAttribute( + eAttribute, + namespaceURI, + eClass, eDataObject); + attributes.put(attribute); + } + return attributes; + } + + /* + * TODO This is also used in updates so consider moving to a utility + */ + public static Attribute processEAttribute( + EAttribute eAttribute, + String namespaceURI, + EClass eClass, + EDataObject eDataObject) + { + String qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eAttribute.getName() ); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + Attribute attribute = + new BasicAttribute(normalizedEAttributeName); + + if (eAttribute.isMany()) + { + if ( !(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEBooleanObject() ) ) + { + EList eAttributeValues = + ( EList ) eDataObject.eGet( eAttribute ); + + for (Object eAttributeValue : eAttributeValues) + { + attribute.add(eAttributeValue.toString() ); + } + } + else + { + EList eAttributeValues = + ( EList ) eDataObject.eGet( eAttribute ); + + for (Boolean eAttributeValue : eAttributeValues) + { + if (eAttributeValue == false) + { + attribute.add(Boolean.FALSE.toString().toUpperCase() ); + } + else + { + attribute.add(Boolean.TRUE.toString().toUpperCase() ); + } + } + } + return attribute; + } + + if ( !(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEBooleanObject() ) ) + { + Object eAttributeValue = + eDataObject.eGet( eAttribute ); + + attribute.add(eAttributeValue.toString() ); + } + else + { + Boolean eAttributeValue = + (Boolean) eDataObject.eGet( eAttribute ); + + if (eAttributeValue == false) + { + attribute.add(Boolean.FALSE.toString().toUpperCase() ); + } + else + { + attribute.add(Boolean.TRUE.toString().toUpperCase() ); + } + } + return attribute; + } + + /** + * Process references adding the normalized EReference instance's + * name and corresponding id (IDs for multiplicity many references) + * to the attributes argument. + * + * @param attributes the attributes + * @param eDataObject the e data object + * @param eClass the e class + * @param namespaceURI the namespace URI + * + * @return the attributes + */ + public static Attributes processEReferences( + Attributes attributes, + EDataObject eDataObject, + EClass eClass, + String namespaceURI) + { + List eReferences = + eClass.getEAllReferences(); + + for (EReference eReference : eReferences) + { + String qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eReference.getName() ); + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + if (eReference.isMany()) + { + List referencedEDataObjects = + (List) eDataObject.eGet(eReference); + + Attribute idAttribute = + new BasicAttribute(normalizedEReferenceName); + + for (EDataObject containedEDataObject : referencedEDataObjects) + { + EClass containedEDataObjectEClass = + containedEDataObject.eClass(); + + String containedEDataObjectID = + (String) containedEDataObject.eGet( + containedEDataObjectEClass. + getEIDAttribute()); + + idAttribute.add(containedEDataObjectID); + } + attributes.put(idAttribute); + } + else + { + EDataObject containedEDataObject = + (EDataObject) + eDataObject.eGet(eReference); + + if (containedEDataObject != null) + { + EClass containedEDataObjectEClass = + containedEDataObject.eClass(); + + String containedEDataObjectID = + (String) containedEDataObject.eGet( + containedEDataObjectEClass. + getEIDAttribute()); + + attributes.put( + normalizedEReferenceName, + containedEDataObjectID); + } + } + } + return attributes; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java new file mode 100644 index 0000000000..9add9b7677 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read; + +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; +import org.eclipse.emf.ecore.sdo.SDOFactory; + +public class EDataGraphReader +implements DASConstants +{ + public static EDataGraph read( + EClass rootDataObjectEClass, + String id, + LdapContext rootContext, + Map dataObjectToRelativeDNCache) + throws NamingException, LdapNameNotFoundException + { + EDataGraph eDataGraph = + SDOFactory.eINSTANCE.createEDataGraph(); + + String namespaceURI = + rootDataObjectEClass.getEPackage(). + getNsURI(); + + EAttribute idEAttribute = + rootDataObjectEClass.getEIDAttribute(); + + String qualifiedIDEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + rootDataObjectEClass.getName(), + idEAttribute.getName() ); + + String normalizedIDEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedIDEAttributeName); + + String eDataObjectRDN = + normalizedIDEAttributeName + "=" + id; + + LdapContext eDataObjectContext = + (LdapContext) + rootContext. + lookup(eDataObjectRDN); + + Attributes attributes = + rootContext. + getAttributes(eDataObjectRDN); + + Map>> crossReferenceIDCache = + new Hashtable>>(); + + EDataObject rootDataObject = + EDataGraphReaderHelper. + restoreEDataObject( + crossReferenceIDCache, + rootDataObjectEClass, + namespaceURI, + attributes); + + String relativeDN = + EDataGraphReaderHelper.calculateRelativeDN( + rootContext, + eDataObjectContext); + + dataObjectToRelativeDNCache. + put(rootDataObject, relativeDN); + + List eReferences = + rootDataObjectEClass.getEAllContainments(); + + if (rootDataObjectEClass.getEAllContainments().size() > 0) + { + EDataGraphReaderHelper. + addContainmentDataObjects( + crossReferenceIDCache, + dataObjectToRelativeDNCache, + rootDataObject, + attributes, + namespaceURI, + eDataObjectContext, + rootContext); + } + + eDataGraph.setERootObject(rootDataObject); + + Resource resource = eDataGraph.getRootResource(); + + EDataGraphReaderHelper.restoreCrossReferences( + crossReferenceIDCache, + resource); + + return eDataGraph; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReaderHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReaderHelper.java new file mode 100644 index 0000000000..1496d91dab --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReaderHelper.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.impl.EClassImpl; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphReaderHelper +implements DASConstants +{ + public static String calculateRelativeDN( + LdapContext containerContext, + LdapContext dataObjectContext) throws NamingException + { + String containerDN = containerContext.getNameInNamespace(); + String dataObjectDN = dataObjectContext.getNameInNamespace(); + + int beginIndex = 0; + int endIndex = + dataObjectDN.length() - containerDN.length() - 1; + + String result = + dataObjectDN.substring( + beginIndex, + endIndex); + + return result; + } + + + public static EDataObject restoreEDataObject( + Map>> crossReferenceIDCache, + EClass eClass, + String namespaceURI, + Attributes attributes) + throws NamingException + { + EDataObject eDataObject = + (EDataObject) + eClass.getEPackage(). + getEFactoryInstance(). + create(eClass); + + EDataObjectReaderHelper. + restoreEAttributes( + eClass, + eDataObject, + namespaceURI, + attributes ); + + EStructuralFeature[] eCrossReferences = + ((EClassImpl.FeatureSubsetSupplier) + eDataObject. + eClass(). + getEAllStructuralFeatures()). + crossReferences(); + + if (eCrossReferences != null) + { + Map> eReferenceToEObjectIDs = + new Hashtable>(); + + for (EStructuralFeature eReference : eCrossReferences) + { + String qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eReference.getName() ); + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + if (eReference.isMany()) + { + List idList = + new ArrayList(); + + Attribute eReferenceAttribute = + attributes.get(normalizedEReferenceName); + + NamingEnumeration namingEnumeration = + eReferenceAttribute.getAll(); + + while (namingEnumeration.hasMore()) + { + String id = (String) namingEnumeration.next(); + idList.add(id); + eReferenceToEObjectIDs.put(eReference, idList); + } + } + else + { + List idList = + new ArrayList(); + + String value = + (String) + attributes. + get(normalizedEReferenceName). + get(); + + idList.add(value); + eReferenceToEObjectIDs.put(eReference, idList); + } + crossReferenceIDCache.put( + eDataObject, + eReferenceToEObjectIDs); + } + } + return eDataObject; + } + + public static void restoreCrossReferences( + Map>> crossReferenceIDCache, + Resource resource) + { + for (EDataObject eDataObject : crossReferenceIDCache.keySet()) + { + Map> eReferenceToIDListMap = + crossReferenceIDCache.get(eDataObject); + + for (EStructuralFeature eStructuralFeature : eReferenceToIDListMap.keySet()) + { + if (eStructuralFeature.isMany()) + { + List eReferenceIDs = + eReferenceToIDListMap. + get(eStructuralFeature); + + EList multiplicityManyList = null; + if (eReferenceIDs.size() > 0) + { + multiplicityManyList = + new BasicEList(); + } + for (String eReferenceID : eReferenceIDs) + { + Object referencedDataObject = resource.getEObject(eReferenceID); + multiplicityManyList.add((EDataObject) referencedDataObject); + eDataObject.eSet( + eStructuralFeature, + multiplicityManyList); + } + } + else + { + String eReferenceID = + eReferenceToIDListMap. + get(eStructuralFeature). + get(0); + + Object referencedDataObject = resource.getEObject(eReferenceID); + eDataObject.eSet( + eStructuralFeature, + referencedDataObject); + } + } + } + } + + public static void addContainmentDataObjects( + Map crossReferenceIDCache, + Map dataObjectToRelativeDNCache, + EDataObject containerDataObject, + Attributes attributes, + String namespaceURI, + LdapContext eDataObjectContext, + LdapContext rootContext) throws NamingException + { + EClass eClass = + containerDataObject.eClass(); + + List eReferences = + eClass.getEAllContainments(); + + for (EReference eReference : eReferences) + { + String qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eReference.getName() ); + + String normalizedReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + Attribute attribute = + attributes. + get(normalizedReferenceName); + + if (attribute.size() > 0) + { + LdapContext eReferenceContainmentContext = + (LdapContext) + eDataObjectContext. + lookup("cn=" + eReference.getName()); + + EClass eReferenceType = + (EClass) eReference.getEType(); + + EAttribute eReferenceTypeEIDAttribute = + eReferenceType.getEIDAttribute(); + + String qualifiedEReferenceTypeIDEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eReferenceType.getName(), + eReferenceTypeEIDAttribute.getName() ); + + String normalizedReferenceTypeEIDAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceTypeIDEAttributeName); + + if (eReference.isMany()) + { + EList containmentList = + new BasicEList(); + + NamingEnumeration idNamingEnumeration = + attribute.getAll(); + + while(idNamingEnumeration.hasMore()) + { + String containedDataObjectID = + (String) idNamingEnumeration.next(); + + String containedDataObjectEntryRDN = + normalizedReferenceTypeEIDAttributeName + + "=" + containedDataObjectID; + + Attributes eReferenceAttributes = + eReferenceContainmentContext. + getAttributes(containedDataObjectEntryRDN); + + + EDataObject eReferenceDataObject = + EDataGraphReaderHelper. + restoreEDataObject( + crossReferenceIDCache, + eReferenceType, + namespaceURI, + eReferenceAttributes); + + //TODO Consider using aspects + String relativeDN = + calculateRelativeDN( + rootContext, + (LdapContext) + eReferenceContainmentContext. + lookup(containedDataObjectEntryRDN)); + dataObjectToRelativeDNCache.put(eReferenceDataObject, relativeDN); + //End of Aspect + + containmentList.add(eReferenceDataObject); + + if (eReferenceDataObject.eClass().getEAllContainments().size() > 0) + { + addContainmentDataObjects( + crossReferenceIDCache, + dataObjectToRelativeDNCache, + eReferenceDataObject, + eReferenceAttributes, + namespaceURI, + (LdapContext) eReferenceContainmentContext. + lookup(containedDataObjectEntryRDN), + rootContext); + } + } + containerDataObject.eSet(eReference, containmentList); + } + else + { + String containedDataObjectID = + (String) attribute.get(); + + String containedDataObjectEntryRDN = + normalizedReferenceTypeEIDAttributeName + + "=" + containedDataObjectID; + + Attributes eReferenceAttributes = + eReferenceContainmentContext. + getAttributes(containedDataObjectEntryRDN); + + EDataObject eReferenceDataObject = + EDataGraphReaderHelper. + restoreEDataObject( + crossReferenceIDCache, + eReferenceType, + namespaceURI, + eReferenceAttributes); + + //TODO Consider using aspects + String relativeDN = + calculateRelativeDN( + rootContext, + (LdapContext) + eReferenceContainmentContext. + lookup(containedDataObjectEntryRDN)); + + dataObjectToRelativeDNCache.put(eReferenceDataObject, relativeDN); + //End of Aspect + + containerDataObject.eSet(eReference, eReferenceDataObject); + + if (eReferenceDataObject.eClass().getEAllContainments().size() > 0) + { + addContainmentDataObjects( + crossReferenceIDCache, + dataObjectToRelativeDNCache, + eReferenceDataObject, + eReferenceAttributes, + namespaceURI, + (LdapContext) eReferenceContainmentContext. + lookup(containedDataObjectEntryRDN), + rootContext); + } + } + } + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReader.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReader.java new file mode 100644 index 0000000000..0c812f4bfc --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReader.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataObjectReader +implements DASConstants +{ + /** + * Read. + * + * @param eClass the e class + * @param id the id + * @param containerContext the container context + * + * @return the e data object + * + * @throws NamingException the naming exception + * + * Note that this is more of a utility, as only this class's + * helper is used in restoring the EDataGraph. + */ + public static EDataObject read( + EClass eClass, + String id, + LdapContext containerContext) + throws NamingException + { + String namespaceURI = + eClass.getEPackage(). + getNsURI(); + + EAttribute idEAttribute = + eClass.getEIDAttribute(); + + String qualifiedIDEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + idEAttribute.getName() ); + + String normalizedIDEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedIDEAttributeName); + + String eDataObjectRDN = + normalizedIDEAttributeName + "=" + id; + + LdapContext eDataObjectContext = + (LdapContext) + containerContext. + lookup(eDataObjectRDN); + + Attributes attributes = + eDataObjectContext.getAttributes(""); + + EDataObject eDataObject = + (EDataObject) + eClass.getEPackage(). + getEFactoryInstance(). + create(eClass); + + EDataObjectReaderHelper. + restoreEAttributes( + eClass, + eDataObject, + namespaceURI, + attributes ); + + return eDataObject; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReaderHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReaderHelper.java new file mode 100644 index 0000000000..2fa6321a65 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataObjectReaderHelper.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read; + +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.sdo.EDataObject; +import org.eclipse.emf.ecore.util.EcoreUtil; + +public class EDataObjectReaderHelper +implements DASConstants +{ + public static void restoreEAttributes( + EClass eClass, + EDataObject eDataObject, + String namespaceURI, + Attributes attributes) + throws NamingException + { + List eAttributes = + eClass.getEAllAttributes(); + + for (EAttribute eAttribute : eAttributes) + { + String qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eAttribute.getName() ); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + if (eAttribute.isMany()) + { + EList values = + new BasicEList(); + + Attribute attribute = + attributes. + get(normalizedEAttributeName); + + for (int i = 0; i < attribute.size(); i++) + { + String value = (String) attribute.get(i); + + values.add(EcoreUtil.createFromString( + eAttribute.getEAttributeType(), + value)); + } + + eDataObject.eSet( + eAttribute, values); + } + else + { + String value = + (String) + attributes. + get(normalizedEAttributeName). + get(); + + eDataObject.eSet( + eAttribute, + EcoreUtil.createFromString( + eAttribute.getEAttributeType(), + value)); + } + } + } + + + //TODO Test all of these verifying that we get out what we put in + //TODO Move to helper + //TODO Note that we are using eDataObject.eSet(eAttribute, EcoreUtil.createFromString(eAttribute.getEAttributeType(), value)); instead + /* + public static void setEDataObjectFeature( + EDataObject eDataObject, + String value, + EAttribute eAttribute) + { + if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEString()) + { + eDataObject.eSet(eAttribute, value); + } + else if ( + eAttribute.getEType() == EcorePackage.eINSTANCE.getEInt() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) + { + eDataObject.eSet(eAttribute, new Integer(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) + { + eDataObject.eSet(eAttribute, new Boolean(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEFloat() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEFloatObject()) + { + eDataObject.eSet(eAttribute, new Float(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) + { + eDataObject.eSet(eAttribute, new Double(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEBigDecimal()) + { + eDataObject.eSet(eAttribute, new BigDecimal(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEBigInteger() ) + { + eDataObject.eSet(eAttribute, new BigInteger(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByte() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteObject()) + { + eDataObject.eSet(eAttribute, new Byte(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByte() || + eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteObject()) + { + eDataObject.eSet(eAttribute, new Byte(value)); + } + else if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteArray()) + { + throw new RuntimeException("Sorry - ByteArrays are not supported."); + } + } + */ +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdater.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdater.java new file mode 100644 index 0000000000..4c22faf1ce --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdater.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.update; + +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.eclipse.emf.ecore.sdo.EChangeSummary; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphUpdater +implements DASConstants +{ + public static void update( + EDataGraph eDataGraph, + LdapContext rootContext, + Map dataObjectToRelativeDNCache ) + throws NamingException + { + EChangeSummary eChangeSummary = + (EChangeSummary) + eDataGraph.getChangeSummary(); + + EDataGraphUpdaterHelper. + processChangedDataObjects( + eChangeSummary, + rootContext, + dataObjectToRelativeDNCache); + + EDataGraphUpdaterHelper. + processCreatedDataObjects( + eChangeSummary, + rootContext, + dataObjectToRelativeDNCache); + + EDataGraphUpdaterHelper. + processDestroyedDataObjects( + eChangeSummary, + rootContext, + dataObjectToRelativeDNCache); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdaterHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdaterHelper.java new file mode 100644 index 0000000000..a53b5547fb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/update/EDataGraphUpdaterHelper.java @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.update; + +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreatorHelper; +import org.apache.tuscany.das.ldap.emf.create.EDataObjectCreatorHelper; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.change.FeatureChange; +import org.eclipse.emf.ecore.sdo.EChangeSummary; +import org.eclipse.emf.ecore.sdo.EDataObject; + + +public class EDataGraphUpdaterHelper +{ + public static void processDestroyedDataObjects( + EChangeSummary eChangeSummary, + LdapContext containerContext, + Map dataObjectToRelativeDNCache) + throws NamingException + { + EList destroyedObjects = + eChangeSummary. + getObjectsToAttach(); + + for (EObject destroyedObject : destroyedObjects) + { + String destroyedObjectRelativeDN = dataObjectToRelativeDNCache.get(destroyedObject); + containerContext.destroySubcontext(destroyedObjectRelativeDN); + dataObjectToRelativeDNCache.remove(destroyedObject); + } + } + + public static void processCreatedDataObjects( + EChangeSummary eChangeSummary, + LdapContext rootContext, + Map dataObjectToRelativeDNCache ) + throws NamingException + { + EList createdObjects = + eChangeSummary. + getObjectsToDetach(); + + EDataGraphCreatorHelper.createChildren( + createdObjects, + rootContext, + dataObjectToRelativeDNCache); + } + + public static void processChangedDataObjects( + EChangeSummary eChangeSummary, + LdapContext containerContext, + Map dataObjectToRelativeDNCache ) + throws NamingException + { + EMap> objectChanges = + eChangeSummary.getObjectChanges(); + + for (EObject changedDataObject : objectChanges.keySet()) + { + EList featureChanges = + objectChanges.get(changedDataObject); + + ModificationItem[] modificationItems = + new ModificationItem[featureChanges.size()]; + + EClass changedDataObjectEClass = + changedDataObject.eClass(); + + String namespaceURI = + changedDataObjectEClass. + getEPackage(). + getNsURI(); + + for (int i = 0; i < featureChanges.size(); i++) + { + FeatureChange featureChange = + featureChanges.get(i); + + EStructuralFeature eStructuralFeature = + featureChange.getFeature(); + + if (eStructuralFeature instanceof EAttribute) + { + //TODO Note that we are not checking multiplicity many on EAttributes + String qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + changedDataObjectEClass.getName(), + eStructuralFeature.getName() ); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + //TODO PUt processEAttribute in a more generic class + Attribute attribute = + EDataObjectCreatorHelper.processEAttribute( + (EAttribute)eStructuralFeature, + namespaceURI, + changedDataObjectEClass, + (EDataObject) changedDataObject); + + modificationItems[i] = + new ModificationItem( + DirContext.REPLACE_ATTRIBUTE, + attribute); + } + else + { + String qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + changedDataObjectEClass.getName(), + eStructuralFeature.getName() ); + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + Attribute attribute = + new BasicAttribute(normalizedEReferenceName); + + if (eStructuralFeature.isMany()) + { + EList referenceList = + (EList) changedDataObject.eGet(eStructuralFeature); + + if (referenceList.size() > 0 && referenceList!=null) + { + for (EDataObject eDataObject : referenceList) + { + attribute.add( + eDataObject. + eGet( + eDataObject. + eClass(). + getEIDAttribute())); + + modificationItems[i] = + new ModificationItem( + DirContext.REPLACE_ATTRIBUTE, + attribute); + } + } + else + { + modificationItems[i] = + new ModificationItem( + DirContext.REMOVE_ATTRIBUTE, + attribute); + } + } + else + { + EDataObject eDataObject = + (EDataObject) + changedDataObject. + eGet(eStructuralFeature); + + if (eDataObject != null) + { + attribute.add( + eDataObject. + eGet( + eDataObject. + eClass(). + getEIDAttribute())); + + modificationItems[i] = + new ModificationItem( + DirContext.REPLACE_ATTRIBUTE, + attribute); + } + else + { + modificationItems[i] = + new ModificationItem( + DirContext.REMOVE_ATTRIBUTE, + attribute); + } + } + } + } + String relativeDN = + dataObjectToRelativeDNCache. + get(changedDataObject); + + containerContext.modifyAttributes( + relativeDN, + modificationItems); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/constants/EncryptionConstants.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/constants/EncryptionConstants.java new file mode 100644 index 0000000000..59b726b4f3 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/constants/EncryptionConstants.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.encryption.constants; + +public interface EncryptionConstants +{ + String MD5 = "MD5"; + String SHA1 = "SHA-1";//Produces longer hashes than MD5 +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/util/ChecksumUtils.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/util/ChecksumUtils.java new file mode 100644 index 0000000000..7c77ddf510 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/encryption/util/ChecksumUtils.java @@ -0,0 +1,38 @@ + +package org.apache.tuscany.das.ldap.encryption.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.tuscany.das.ldap.encryption.constants.EncryptionConstants; + +public class ChecksumUtils +implements EncryptionConstants +{ + public static String computeMD5Hash(String string) + throws NoSuchAlgorithmException + { + MessageDigest messageDigest = MessageDigest.getInstance(MD5); + + byte[] digest = + messageDigest.digest(string.getBytes()); + + StringBuffer hexString = new StringBuffer(); + for (int i=0;i MAX_OID_SEGMENT_LENGTH ) + { + segmentedOID += oid.substring( endIndex + 1,endIndex + 9 ) + "."; + segmentedOID += oid.substring( endIndex + 10, oid.length() ); + } + else + { + segmentedOID += oid.substring( endIndex + 1, oid.length() ); + } + return segmentedOID; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/SimpleTypeOIDCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/SimpleTypeOIDCreator.java new file mode 100644 index 0000000000..3c083fc42f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/oid/create/SimpleTypeOIDCreator.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.oid.create; + +import org.apache.tuscany.das.ldap.encryption.constants.EncryptionConstants; +import org.apache.tuscany.das.ldap.encryption.util.ChecksumUtils; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; + +/** + * The Class SimpleTypeOIDCreator. + * Creates unique OIDs for namespaced + * metadata such as the XSD DataType + * with (Class specific term) qualifiedNameURI + * http://www.w3.org/2001/XMLSchema/string + * + */ +public class SimpleTypeOIDCreator implements EncryptionConstants +{ + /** + * Creates a unique OID. + * + * @param instanceClassName the instance class name + * @param oidPrefix the OID Branch + * @param complexTypeName the name + * @param namespaceURI the metadata namespace URI + * + * @return the string + * + * @throws Exception the exception + */ + public static String create( + String oidPrefix, + String namespaceURI, + String complexTypeName, + String simpleTypeName) + throws Exception + { + String qualifiedNameURI = + SimpleTypeNamespaceQualifier.qualify( + namespaceURI, + complexTypeName, + simpleTypeName); + + String postfixOID = ChecksumUtils.computeMD5Hash(qualifiedNameURI); + + postfixOID = OIDCreatorHelper.calculateSegmentedOID(postfixOID); + return oidPrefix + "." + postfixOID; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/Prototype.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/Prototype.java new file mode 100644 index 0000000000..17f011e971 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/Prototype.java @@ -0,0 +1,74 @@ +package org.apache.tuscany.das.ldap.prototype.setup; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EFactory; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +public interface Prototype { + EClass userEClass = + PrototypeUtilities.createUserEClass(); + EClass authorizationEClass = + PrototypeUtilities.createAuthorizationEClass(); + EClass configurationEClass = + PrototypeUtilities.createConfigurationEClass(); + + EAttribute userNameEAttribute = + PrototypeUtilities.createUserNameEAttribute(); + EAttribute userAliasesEAttribute = + PrototypeUtilities.createUserAliasesEAttribute(); + + EAttribute userPasswordEAttribute = + PrototypeUtilities.createUserPasswordEAttribute(); + EAttribute userIDEAttribute = + PrototypeUtilities.createUserIDEAttribute(); + EAttribute userAgeEAttribute = + PrototypeUtilities.createUserAgeEAttribute(); + EAttribute userHeightEAttribute = + PrototypeUtilities.createUserHeightEAttribute(); + EAttribute userIsMaleEAttribute = + PrototypeUtilities.createUserIsMaleEAttribute(); + EReference userAuthorizationEReference = + PrototypeUtilities.createUserAuthorizationEReference(); + + EReference userConfigurationEReference = + PrototypeUtilities.createUserConfigurationEReference(); + + + + + EAttribute authorizationFileEAttribute = + PrototypeUtilities.createFileEAttribute(); + EAttribute authorizationReadEAttribute = + PrototypeUtilities.createReadAuthorizationEAttribute(); + EAttribute authorizationWriteEAttribute= + PrototypeUtilities.createWriteAuthorizationEAttribute(); + EAttribute authorizationExecuteEAttribute = + PrototypeUtilities.createExecuteAuthorizationEAttribute(); + EAttribute authorizationIDEAttribute = + PrototypeUtilities.createAuthorizationIDEAttribute(); + + EAttribute configurationIDEAttribute = + PrototypeUtilities.createConfigurationIDEAttribute(); + + EReference configurationAuthorizationEReference = + PrototypeUtilities.createConfigurationAuthorizationEReference(); + + EReference configurationAuthorizationsEReference = + PrototypeUtilities.createConfigurationAuthorizationsEReference(); + + + EPackage userEPackage = + PrototypeUtilities.createUserEPackage(); + + EFactory userEFactory = + userEPackage.getEFactoryInstance(); + + EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + EcorePackage ecorePackage = + EcorePackage.eINSTANCE; +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/PrototypeUtilities.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/PrototypeUtilities.java new file mode 100644 index 0000000000..11af604dfa --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/PrototypeUtilities.java @@ -0,0 +1,243 @@ +package org.apache.tuscany.das.ldap.prototype.setup; + +import org.apache.tuscany.das.ldap.testing.constants.DASTestingConstants; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.sdo.impl.DynamicEDataObjectImpl; + +public class PrototypeUtilities +implements DASTestingConstants { + + /* + * The User EClass is intended to be the root of the DataGraph + * It should have a multiplicity many containment reference of type + * Authorization and a containment reference of type Configuration + * The Configuration should have a single non-containment reference + * of type Authorization. + */ + + public static EClass createUserEClass() + { + EClass userEClass = + EcoreFactory.eINSTANCE.createEClass(); + + userEClass.setName("User"); + + return userEClass; + } + + public static EAttribute createUserIDEAttribute() + { + EAttribute id = + EcoreFactory.eINSTANCE.createEAttribute(); + id.setName( "id" ); + id.setEType( EcorePackage.eINSTANCE.getEString() ); + id.setID(true); + return id; + } + + public static EAttribute createUserNameEAttribute() + { + EAttribute userName = + EcoreFactory.eINSTANCE.createEAttribute(); + userName.setName( "userName" ); + userName.setEType( EcorePackage.eINSTANCE.getEString() ); + return userName; + } + + public static EAttribute createUserAliasesEAttribute() + { + EAttribute userAliases = + EcoreFactory.eINSTANCE.createEAttribute(); + userAliases.setName( "userAliases" ); + userAliases.setLowerBound( 0 ); + userAliases.setUpperBound( -1 ); + userAliases.setEType( EcorePackage.eINSTANCE.getEString() ); + return userAliases; + } + + public static EAttribute createUserPasswordEAttribute() + { + EAttribute userPassword = + EcoreFactory.eINSTANCE.createEAttribute(); + userPassword.setName( "userPassword" ); + userPassword.setEType( EcorePackage.eINSTANCE.getEString() ); + return userPassword; + } + + public static EAttribute createUserAgeEAttribute() + { + EAttribute userAge = + EcoreFactory.eINSTANCE.createEAttribute(); + userAge.setName( "userAge" ); + userAge.setEType( EcorePackage.eINSTANCE.getEInt() ); + return userAge; + } + + public static EAttribute createUserHeightEAttribute() + { + EAttribute userHeight = + EcoreFactory.eINSTANCE.createEAttribute(); + userHeight.setName( "userHeight" ); + userHeight.setEType( EcorePackage.eINSTANCE.getEDouble() ); + return userHeight; + } + + public static EAttribute createUserIsMaleEAttribute() + { + EAttribute isMale = + EcoreFactory.eINSTANCE.createEAttribute(); + isMale.setName( "isMale" ); + isMale.setEType( EcorePackage.eINSTANCE.getEBoolean() ); + return isMale; + } + + public static EReference createUserAuthorizationEReference() + { + EReference userAuthorizationEReference = + EcoreFactory.eINSTANCE.createEReference(); + userAuthorizationEReference.setLowerBound(0); + userAuthorizationEReference.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); + userAuthorizationEReference.setContainment(true); + userAuthorizationEReference.setName("authorizationList"); + + return userAuthorizationEReference; + } + + public static EReference createUserConfigurationEReference() + { + EReference userConfigurationEReference = + EcoreFactory.eINSTANCE.createEReference(); + userConfigurationEReference.setLowerBound(0); + userConfigurationEReference.setUpperBound(1); + userConfigurationEReference.setContainment(true); + userConfigurationEReference.setName("configuration"); + + return userConfigurationEReference; + } + + + public static EPackage createUserEPackage() + { + EPackage userEPackage = + EcoreFactory.eINSTANCE.createEPackage(); + userEPackage.setName( "userPackage" ); + userEPackage.setNsPrefix( "user" ); + userEPackage.setNsURI( xsdNamespace ); + + userEPackage.setEFactoryInstance( + new DynamicEDataObjectImpl.FactoryImpl()); + + return userEPackage; + } + + public static EClass createAuthorizationEClass() + { + EClass authorizationEClass = + EcoreFactory.eINSTANCE.createEClass(); + + authorizationEClass.setName("Authorization"); + + return authorizationEClass; + } + + public static EAttribute createAuthorizationIDEAttribute() + { + EAttribute id = + EcoreFactory.eINSTANCE.createEAttribute(); + id.setName( "id" ); + id.setEType( EcorePackage.eINSTANCE.getEString() ); + id.setID(true); + return id; + } + + public static EAttribute createFileEAttribute() + { + EAttribute fileNameEAttribute = + EcoreFactory.eINSTANCE.createEAttribute(); + fileNameEAttribute.setName( "fileName" ); + fileNameEAttribute.setEType( EcorePackage.eINSTANCE.getEString() ); + return fileNameEAttribute; + + } + + public static EAttribute createWriteAuthorizationEAttribute() + { + EAttribute writeAuthorizationEAttribute = + EcoreFactory.eINSTANCE.createEAttribute(); + writeAuthorizationEAttribute.setName( "writeAuthorization" ); + writeAuthorizationEAttribute.setEType( EcorePackage.eINSTANCE.getEBoolean() ); + return writeAuthorizationEAttribute; + } + + public static EAttribute createReadAuthorizationEAttribute() + { + EAttribute readAuthorizationEAttribute = + EcoreFactory.eINSTANCE.createEAttribute(); + readAuthorizationEAttribute.setName( "readAuthorization" ); + readAuthorizationEAttribute.setEType( EcorePackage.eINSTANCE.getEBoolean() ); + return readAuthorizationEAttribute; + } + + public static EAttribute createExecuteAuthorizationEAttribute() + { + EAttribute readExecuteEAttribute = + EcoreFactory.eINSTANCE.createEAttribute(); + readExecuteEAttribute.setName( "executeAuthorization" ); + readExecuteEAttribute.setEType( EcorePackage.eINSTANCE.getEBoolean() ); + return readExecuteEAttribute; + } + + + public static EClass createConfigurationEClass() + { + EClass configurationEClass = + EcoreFactory.eINSTANCE.createEClass(); + + configurationEClass.setName("Configuration"); + + return configurationEClass; + } + + public static EAttribute createConfigurationIDEAttribute() + { + EAttribute id = + EcoreFactory.eINSTANCE.createEAttribute(); + id.setName( "id" ); + id.setEType( EcorePackage.eINSTANCE.getEString() ); + id.setID(true); + return id; + } + + public static EReference createConfigurationAuthorizationEReference() + { + EReference authorizationEReference = + EcoreFactory.eINSTANCE.createEReference(); + authorizationEReference.setLowerBound(0); + authorizationEReference.setUpperBound(1); + authorizationEReference.setContainment(false); + //authorizationEReference.setEType(createAuthorizationEClass()); Do this in the testing code. + authorizationEReference.setName("authorization"); + + return authorizationEReference; + } + + public static EReference createConfigurationAuthorizationsEReference() + { + EReference authorizationsEReference = + EcoreFactory.eINSTANCE.createEReference(); + authorizationsEReference.setLowerBound(0); + authorizationsEReference.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); + authorizationsEReference.setContainment(false); + //authorizationEReference.setEType(createAuthorizationEClass()); Do this in the testing code. + authorizationsEReference.setName("authorizations"); + + return authorizationsEReference; + } + +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/CommonSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/CommonSetupTest.java new file mode 100644 index 0000000000..9b7673efe6 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/CommonSetupTest.java @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.prototype.setup.test; + +import java.io.File; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.commons.io.FileUtils; +import org.apache.tuscany.das.ldap.prototype.setup.Prototype; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class CommonSetupTest +extends EcoreSchemaAndDASContextsSetup +implements Prototype +{ + protected EObjectClassCreator eObjectClassCreator = null; + + protected EDataObject userDataObject = null; + protected EDataObject authorizationDataObject0 = null; + protected EDataObject authorizationDataObject1 = null; + protected EDataObject configurationDataObject = null; + + protected static List + processedEClassifiers = null; + + protected String userDataObjectRDN = + "example-com-users-accounts-User-id=1"; + protected String authorizationDataObject1RDN = + "example-com-users-accounts-Authorization-id=2,cn=authorizationList,example-com-users-accounts-User-id=1"; + protected String authorizationDataObject2RDN = + "example-com-users-accounts-Authorization-id=3,cn=authorizationList,example-com-users-accounts-User-id=1"; + protected String configurationDataObjectRDN = + "example-com-users-accounts-Configuration-id=5,cn=configuration,example-com-users-accounts-User-id=1"; + + protected String configurationContainingFeatureRDN = + "cn=configuration"; + protected String authorizationListContainingFeatureRDN= + "cn=authorizationList"; + + protected LdapContext authorizationContainerContext = null; + protected LdapContext configurationContainerContext = null; + protected LdapContext userContainerContext = null; + + protected Map dataObjectToRelativeDNCache = null; + + public void tearDown() throws NamingException, Exception + { + rootContext.destroySubcontext(userDataObjectRDN); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + userEClass, + TUSCANY_OID_PREFIX_VALUE ); + + super.tearDown(); + } + + public void setUp() throws Exception + { + FileUtils.deleteDirectory(new File("server-work")); + + dataObjectToRelativeDNCache = + new Hashtable(); + + super.setUp(); + + userAuthorizationEReference. + setEType(authorizationEClass); + + userConfigurationEReference. + setEType(configurationEClass); + + configurationAuthorizationEReference. + setEType(authorizationEClass); + + configurationAuthorizationsEReference. + setEType(authorizationEClass); + + userEClass. + getEStructuralFeatures(). + add( userNameEAttribute ); + + userEClass. + getEStructuralFeatures(). + add( userAliasesEAttribute ); + + userEClass. + getEStructuralFeatures(). + add( userPasswordEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userAgeEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userHeightEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userIsMaleEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userIDEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userAuthorizationEReference ); + userEClass. + getEStructuralFeatures(). + add( userConfigurationEReference ); + + userEPackage.getEClassifiers().add(userEClass); + + userDataObject = + (EDataObject) + userEFactory.create(userEClass); + + userDataObject.eSet(userNameEAttribute,"ole"); + userDataObject.eSet(userPasswordEAttribute,"secret"); + userDataObject.eSet(userIDEAttribute, "1"); + userDataObject.eSet(userAgeEAttribute, 33); + userDataObject.eSet(userHeightEAttribute, 6.11); + userDataObject.eSet(userIsMaleEAttribute, true); + + EList userAliases = new BasicEList(); + userAliases.add("neo"); + userAliases.add("trinity"); + userAliases.add("morpheus"); + + userDataObject.eSet( userAliasesEAttribute, userAliases ); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationFileEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationWriteEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationReadEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationExecuteEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationIDEAttribute); + + userEPackage.getEClassifiers(). + add(authorizationEClass); + + authorizationDataObject0 = + (EDataObject) + userEFactory.create(authorizationEClass); + + authorizationDataObject1 = + (EDataObject) + userEFactory.create(authorizationEClass); + + authorizationDataObject0.eSet(authorizationFileEAttribute,"somefile.text"); + authorizationDataObject0.eSet(authorizationWriteEAttribute, true); + authorizationDataObject0.eSet(authorizationReadEAttribute,true); + authorizationDataObject0.eSet(authorizationExecuteEAttribute,true); + authorizationDataObject0.eSet(authorizationIDEAttribute, "2"); + + authorizationDataObject1.eSet(authorizationFileEAttribute,"someOtherfile.text"); + authorizationDataObject1.eSet(authorizationWriteEAttribute,Boolean.TRUE); + authorizationDataObject1.eSet(authorizationReadEAttribute,true); + authorizationDataObject1.eSet(authorizationExecuteEAttribute,true); + authorizationDataObject1.eSet(authorizationIDEAttribute, "3"); + + EList userDataObjectAuthorizationList = + new BasicEList(); + + userDataObjectAuthorizationList.add(authorizationDataObject0); + userDataObjectAuthorizationList.add(authorizationDataObject1); + + userDataObject.eSet( + userAuthorizationEReference, + userDataObjectAuthorizationList); + + configurationEClass. + getEStructuralFeatures(). + add(configurationIDEAttribute); + + configurationEClass. + getEStructuralFeatures(). + add(configurationAuthorizationEReference); + + configurationEClass. + getEStructuralFeatures(). + add(configurationAuthorizationsEReference); + + userEPackage.getEClassifiers(). + add(configurationEClass); + + configurationDataObject = + (EDataObject) + userEFactory.create(configurationEClass); + + userDataObject.eSet( + userConfigurationEReference, + configurationDataObject); + + configurationDataObject.eSet( + configurationIDEAttribute, + "5"); + + configurationDataObject.eSet( + configurationAuthorizationEReference, + authorizationDataObject0); + + configurationDataObject.eSet( + configurationAuthorizationsEReference, + userDataObjectAuthorizationList); + + processedEClassifiers = + new ArrayList(); + + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + userEClass, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataGraphSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataGraphSetupTest.java new file mode 100644 index 0000000000..c05db9f7e2 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataGraphSetupTest.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.prototype.setup.test; + +import javax.naming.NamingException; + +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.SDOFactory; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl; + +public class EDataGraphSetupTest +extends CommonSetupTest +{ + protected EDataGraph eDataGraph = null; + protected boolean readException = false; + + public void tearDown() throws NamingException, Exception + { + if (dataObjectToRelativeDNCache.containsValue(authorizationDataObject1RDN) + || readException) + { + rootContext.destroySubcontext(authorizationDataObject1RDN); + } + if (dataObjectToRelativeDNCache.containsValue(authorizationDataObject2RDN) + || readException) + { + rootContext.destroySubcontext(authorizationDataObject2RDN); + } + if (dataObjectToRelativeDNCache.containsValue(configurationDataObjectRDN) + || readException) + { + rootContext.destroySubcontext(configurationDataObjectRDN); + } + userContainerContext.destroySubcontext(configurationContainingFeatureRDN); + + userContainerContext.destroySubcontext(authorizationListContainingFeatureRDN); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + authorizationEClass, + TUSCANY_OID_PREFIX_VALUE ); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + configurationEClass, + TUSCANY_OID_PREFIX_VALUE ); + + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + authorizationEClass, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + configurationEClass, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + eDataGraph = + SDOFactory. + eINSTANCE. + createEDataGraph(); + + eDataGraph.setERootObject(userDataObject); + + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry(). + getExtensionToFactoryMap().put + ("xml", + new XMLResourceFactoryImpl()); + + eDataGraph.setResourceSet(resourceSet); + + EDataGraphCreator.create( + eDataGraph, + rootContext, + dataObjectToRelativeDNCache); + + userContainerContext = + (LdapContext) + rootContext. + lookup(userDataObjectRDN); + + authorizationContainerContext = + (LdapContext) + userContainerContext. + lookup(authorizationListContainingFeatureRDN); + + configurationContainerContext = + (LdapContext) + userContainerContext. + lookup(configurationContainingFeatureRDN); + + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataObjectSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataObjectSetupTest.java new file mode 100644 index 0000000000..4c91f34e07 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/EDataObjectSetupTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.prototype.setup.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.emf.create.EDataObjectCreator; + +public class EDataObjectSetupTest +extends CommonSetupTest +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + + EDataObjectCreator.create( + userDataObject, + rootContext, + dataObjectToRelativeDNCache); + + userContainerContext = + (LdapContext) + rootContext. + lookup(userDataObjectRDN); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/LdapDASSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/LdapDASSetupTest.java new file mode 100644 index 0000000000..3225868ffe --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/prototype/setup/test/LdapDASSetupTest.java @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.prototype.setup.test; + +import java.io.File; +import java.util.Hashtable; +import java.util.Map; + +import javax.naming.NamingException; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.apache.tuscany.das.ldap.prototype.setup.Prototype; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; +import org.eclipse.emf.ecore.sdo.SDOFactory; + +public class LdapDASSetupTest +extends TestCase +implements Prototype +{ + protected Map dataObjectToRelativeDNCache = null; + protected EDataGraph eDataGraph = null; + protected EDataObject userDataObject = null; + protected EDataObject authorizationDataObject0 = null; + protected EDataObject authorizationDataObject1 = null; + protected EDataObject configurationDataObject = null; + + public void tearDown() throws NamingException, Exception + { + FileUtils.deleteDirectory(new File("server-work")); + } + + public void setUp() throws Exception + { + dataObjectToRelativeDNCache = + new Hashtable(); + + userAuthorizationEReference. + setEType(authorizationEClass); + + userConfigurationEReference. + setEType(configurationEClass); + + configurationAuthorizationEReference. + setEType(authorizationEClass); + + configurationAuthorizationsEReference. + setEType(authorizationEClass); + + userEClass. + getEStructuralFeatures(). + add( userNameEAttribute ); + + userEClass. + getEStructuralFeatures(). + add( userAliasesEAttribute ); + + userEClass. + getEStructuralFeatures(). + add( userPasswordEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userAgeEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userHeightEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userIsMaleEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userIDEAttribute ); + userEClass. + getEStructuralFeatures(). + add( userAuthorizationEReference ); + userEClass. + getEStructuralFeatures(). + add( userConfigurationEReference ); + + userEPackage.getEClassifiers().add(userEClass); + + userDataObject = + (EDataObject) + userEFactory.create(userEClass); + + userDataObject.eSet(userNameEAttribute,"ole"); + userDataObject.eSet(userPasswordEAttribute,"secret"); + userDataObject.eSet(userIDEAttribute, "1"); + userDataObject.eSet(userAgeEAttribute, 33); + userDataObject.eSet(userHeightEAttribute, 6.11); + userDataObject.eSet(userIsMaleEAttribute, true); + + EList userAliases = new BasicEList(); + userAliases.add("neo"); + userAliases.add("trinity"); + userAliases.add("morpheus"); + + userDataObject.eSet( userAliasesEAttribute, userAliases ); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationFileEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationWriteEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationReadEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationExecuteEAttribute); + + authorizationEClass. + getEStructuralFeatures(). + add(authorizationIDEAttribute); + + userEPackage.getEClassifiers(). + add(authorizationEClass); + + authorizationDataObject0 = + (EDataObject) + userEFactory.create(authorizationEClass); + + authorizationDataObject1 = + (EDataObject) + userEFactory.create(authorizationEClass); + + authorizationDataObject0.eSet(authorizationFileEAttribute,"somefile.text"); + authorizationDataObject0.eSet(authorizationWriteEAttribute, true); + authorizationDataObject0.eSet(authorizationReadEAttribute,true); + authorizationDataObject0.eSet(authorizationExecuteEAttribute,true); + authorizationDataObject0.eSet(authorizationIDEAttribute, "2"); + + authorizationDataObject1.eSet(authorizationFileEAttribute,"someOtherfile.text"); + authorizationDataObject1.eSet(authorizationWriteEAttribute,Boolean.TRUE); + authorizationDataObject1.eSet(authorizationReadEAttribute,true); + authorizationDataObject1.eSet(authorizationExecuteEAttribute,true); + authorizationDataObject1.eSet(authorizationIDEAttribute, "3"); + + EList userDataObjectAuthorizationList = + new BasicEList(); + + userDataObjectAuthorizationList.add(authorizationDataObject0); + userDataObjectAuthorizationList.add(authorizationDataObject1); + + userDataObject.eSet( + userAuthorizationEReference, + userDataObjectAuthorizationList); + + configurationEClass. + getEStructuralFeatures(). + add(configurationIDEAttribute); + + configurationEClass. + getEStructuralFeatures(). + add(configurationAuthorizationEReference); + + configurationEClass. + getEStructuralFeatures(). + add(configurationAuthorizationsEReference); + + userEPackage.getEClassifiers(). + add(configurationEClass); + + configurationDataObject = + (EDataObject) + userEFactory.create(configurationEClass); + + userDataObject.eSet( + userConfigurationEReference, + configurationDataObject); + + configurationDataObject.eSet( + configurationIDEAttribute, + "5"); + + configurationDataObject.eSet( + configurationAuthorizationEReference, + authorizationDataObject0); + + configurationDataObject.eSet( + configurationAuthorizationsEReference, + userDataObjectAuthorizationList); + + + eDataGraph = + SDOFactory. + eINSTANCE. + createEDataGraph(); + + eDataGraph.setERootObject(userDataObject); + + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractAttributeTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractAttributeTypeCreator.java new file mode 100644 index 0000000000..c021607a2c --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractAttributeTypeCreator.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +/** + * The Class AbstractAttributeTypeCreator. + */ +public abstract class AbstractAttributeTypeCreator +extends AbstractTypeCreator +{ + + public AbstractAttributeTypeCreator() + { + super(); + + objectClassAttribute.add( META_ATTRIBUTE_TYPE ); + basicAttributes.put( M_COLLECTIVE, LDAP_FALSE ); + basicAttributes.put( M_EQUALITY, M_EQUALITY__NAME_OR_NUMERIC_ID_MATCH ); + basicAttributes.put( M_NO_USER_MODIFICATION, LDAP_FALSE); + basicAttributes.put( M_SINGLE_VALUE, LDAP_FALSE ); + basicAttributes.put( M_USAGE, LDAP_USER_APPLICATIONS); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractTypeCreator.java new file mode 100644 index 0000000000..6fbf988646 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/AbstractTypeCreator.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.EnumeratedSchemaAttributeTypeValues; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; + +public abstract class AbstractTypeCreator +implements +EnumeratedSchemaAttributeTypeValues, +SchemaAttributeTypeConstants, +AttributeTypeConstants, +SchemaObjectClassConstants, +ObjectClassConstants, +DASConstants +{ + protected Attribute objectClassAttribute; + protected Attributes basicAttributes; + + public AbstractTypeCreator() + { + objectClassAttribute = + new BasicAttribute( + OBJECT_CLASS, TOP ); + + objectClassAttribute.add( + META_TOP ); + + basicAttributes = new BasicAttributes(); + basicAttributes.put(objectClassAttribute); + basicAttributes.put( M_OBSOLETE, LDAP_FALSE ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/ComplexTypeRDNCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/ComplexTypeRDNCreator.java new file mode 100644 index 0000000000..47e3e8a716 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/ComplexTypeRDNCreator.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +import org.apache.tuscany.das.ldap.oid.create.ComplexTypeOIDCreator; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; + +/** + * The Class DataTypeRDNCreator. + */ +public class ComplexTypeRDNCreator +implements SchemaAttributeTypeConstants +{ + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param namespaceURI the namespace URI + * @param complexTypeName the complex type name + * + * @return the string that is the rdn + * + * @throws Exception the exception + */ + public static String create( + String oidPrefix, + String namespaceURI, + String complexTypeName + ) + throws Exception + { + String oid = + ComplexTypeOIDCreator.create( + oidPrefix, + namespaceURI, + complexTypeName ); + + String rdn = + M_OID + "=" + oid; + + return rdn; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SimpleTypeRDNCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SimpleTypeRDNCreator.java new file mode 100644 index 0000000000..6e8eaba018 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SimpleTypeRDNCreator.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +import org.apache.tuscany.das.ldap.oid.create.SimpleTypeOIDCreator; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; + +/** + * The Class DataTypeRDNCreator. + */ +public class SimpleTypeRDNCreator +implements SchemaAttributeTypeConstants +{ + + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param namespaceURI the namespace URI + * @param complexTypeName the name + * @param simpleTypeName the simple type name + * + * @return the string + * + * @throws Exception the exception + */ + public static String create( + String oidPrefix, + String namespaceURI, + String complexTypeName, + String simpleTypeName) + throws Exception + { + String oid = + SimpleTypeOIDCreator.create( + oidPrefix, + namespaceURI, + complexTypeName, + simpleTypeName); + + String rdn = + M_OID + "=" + oid; + + return rdn; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxCheckerEntryCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxCheckerEntryCreator.java new file mode 100644 index 0000000000..6b115fd71f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxCheckerEntryCreator.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; + +/** + * The Class SyntaxEntryCreator. + */ +public class SyntaxCheckerEntryCreator +implements +AttributeTypeConstants, +SchemaAttributeTypeConstants, +ObjectClassConstants, +SchemaObjectClassConstants +{ + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param namespaceURI the namespace URI + * @param dataTypeName the name of the DataType + * @param syntaxesContext the directory context + * + * @throws Exception the exception + */ + public static void create( + String rdn, + LdapContext syntaxCheckerContext) + throws Exception + { + + Attributes attributes = + prepareSyntaxCheckerAttributes(); + + syntaxCheckerContext.createSubcontext( + rdn, + attributes); + } + + /** + * TODO - Move to helper + * Prepare SyntaxChecker attributes. + * + * @return the attributes + */ + public static Attributes prepareSyntaxCheckerAttributes() + { + Attribute objectClassAttribute = + new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add( META_TOP ); + objectClassAttribute.add( META_SYNTAX_CHECKER ); + + Attribute fqcnAttribute = + new BasicAttribute( + M_FQCN, + M_FQCN_DEFAULT_VALUE); + + Attributes attributes = new BasicAttributes(); + + attributes.put( objectClassAttribute ); + attributes.put( fqcnAttribute ); + + return attributes; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxEntryCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxEntryCreator.java new file mode 100644 index 0000000000..024ef1e7b9 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/create/SyntaxEntryCreator.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.create; + +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; + +/** + * The Class SyntaxEntryCreator. + */ +public class SyntaxEntryCreator +implements +AttributeTypeConstants, +SchemaAttributeTypeConstants, +ObjectClassConstants, +SchemaObjectClassConstants +{ + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param namespaceURI the namespace URI + * @param dataTypeName the name of the DataType + * @param syntaxesContext the directory context + * + * @throws Exception the exception + */ + public static void create( + String oidPrefix, + String namespaceURI, + String dataTypeName, + LdapContext syntaxesContext, + LdapContext syntaxCheckersContext) + throws Exception + { + String syntaxDescription = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + dataTypeName); + + String rdn = + ComplexTypeRDNCreator. + create( + oidPrefix, + namespaceURI, + dataTypeName); + + Attributes syntaxAttributes = + prepareSyntaxAttributes( + syntaxDescription ); + + Attributes syntaxCheckerAttributes = + prepareSyntaxCheckerAttributes(); + + //TODO Put back in when bug gets resolved. + //TODO Remember to apply the namespace qualifier or we could just leave because it's in the description effectively + //attributes.put(M_NAME, name ); + //attributes.put("x-humandReadible", "false"); + //attributes.put("m-obsolete, "false"); + syntaxesContext.createSubcontext( + rdn, + syntaxAttributes); + + syntaxCheckersContext.createSubcontext( + rdn, + syntaxCheckerAttributes); + } + + /** + * TODO - Move to helper + * TODO - Optimize - we are prepping these each time when they could be cached + * Prepare syntax attributes. + * + * @param syntaxDescription the syntax description + * + * @return the attributes + */ + public static Attributes prepareSyntaxAttributes( + String syntaxDescription) + { + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, TOP); + objectClassAttribute.add( META_TOP ); + objectClassAttribute.add( META_SYNTAX ); + + Attribute descriptionAttribute = new BasicAttribute( + M_DESCRIPTION, + syntaxDescription); + + Attributes attributes = new BasicAttributes(); + + attributes.put( objectClassAttribute ); + attributes.put( descriptionAttribute ); + + return attributes; + } + + /** + * TODO - Move to helper + * TODO - Optimize - we are prepping these each time when they could be cached + * Prepare SyntaxChecker attributes. + * + * @return the attributes + */ + public static Attributes prepareSyntaxCheckerAttributes() + { + Attribute objectClassAttribute = + new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add( META_TOP ); + objectClassAttribute.add( META_SYNTAX_CHECKER ); + + Attribute fqcnAttribute = + new BasicAttribute( + M_FQCN, + M_FQCN_DEFAULT_VALUE); + + Attributes attributes = new BasicAttributes(); + + attributes.put( objectClassAttribute ); + attributes.put( fqcnAttribute ); + + return attributes; + } + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetup.java new file mode 100644 index 0000000000..010baa800b --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetup.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.apacheds.testing.setup.ADSEmbeddedHotPartitionTemplate; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.EnumeratedSchemaAttributeTypeValues; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; +import org.apache.tuscany.das.ldap.testing.constants.DASTestingConstants; + +public abstract class AbstractTestSetup +extends ADSEmbeddedHotPartitionTemplate +implements +EnumeratedSchemaAttributeTypeValues, +SchemaAttributeTypeConstants, +AttributeTypeConstants, +SchemaObjectClassConstants, +ObjectClassConstants, +DASConstants, +DASTestingConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + + dasPartitionContext = + connect("das"); + + schemaPartitionContext = + connect("schema"); + } + + protected LdapContext schemaPartitionContext = + null; + + protected LdapContext dasPartitionContext = + null; + + protected static final String SYNTAXES_CONTEXT_RDN = + OU + "=" + SYNTAXES_CONTEXT_NAME; + + protected static final String SYNTAX_CHECKERS_CONTEXT_RDN = + OU + "=" + SYNTAX_CHECKERS_CONTEXT_NAME; + + protected static final String ATTRIBUTE_TYPES_CONTEXT_RDN = + OU + "=" + ATTRIBUTE_TYPES_CONTEXT_NAME; + + protected static final String OBJECT_CLASSES_CONTEXT_RDN = + OU + "=" + OBJECT_CLASSES_CONTEXT_NAME; + + + + protected static final String XSD_CONTEXT_RDN = + CN + "=" + XSD_CONTEXT_NAME; + protected static final String DAS_CONTEXT_RDN = + CN + "=" + DAS_CONTEXT_NAME; + protected static final String ECORE_CONTEXT_RDN = + CN + "=" + ECORE_CONTEXT_NAME; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetupTest.java new file mode 100644 index 0000000000..6477225e1c --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/AbstractTestSetupTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +public class AbstractTestSetupTest +extends AbstractTestSetup +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + dasPartitionContext = + connect("das"); + schemaPartitionContext = + connect("schema"); + } + + public void testConnect() throws NamingException + { + assertNotNull(dasPartitionContext); + assertNotNull(schemaPartitionContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetup.java new file mode 100644 index 0000000000..fafd0144fb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetup.java @@ -0,0 +1,47 @@ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.create.MetaContextCreator; +import org.apache.tuscany.das.ldap.destroy.InitialContextDestroyer; +import org.apache.tuscany.das.ldap.destroy.MetaContextDestroyer; + +public class DASContextSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + MetaContextDestroyer. + destroy( modelContext ); + + InitialContextDestroyer. + destroy( + modelContext, + dasPartitionContext ); + super.tearDown(); + + dasPartitionContext.close(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + modelContext = + InitialContextCreator. + create( + xsdNamespace, + dasPartitionContext); + + metaContext = + MetaContextCreator. + create( modelContext); + } + + protected LdapContext modelContext = null; + protected LdapContext metaContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetupTest.java new file mode 100644 index 0000000000..d6ecc250c6 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASContextSetupTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class DASContextSetupTest +extends DASContextSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testModelContext() throws NamingException + { + assertNotNull(modelContext); + assertEquals( + "cn=accounts,cn=users,cn=example,cn=com,ou=das", + modelContext.getNameInNamespace()); + } + + public void testMetaContext() throws NamingException + { + assertNotNull(metaContext); + assertEquals("cn=meta,cn=accounts,cn=users,cn=example,cn=com,ou=das", + metaContext.getNameInNamespace()); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetup.java new file mode 100644 index 0000000000..da620aaf34 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetup.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; + +public class DASSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + dasSyntaxesContext.close(); + + dasSchemaSubContext.destroySubcontext( + SYNTAXES_CONTEXT_RDN ); + + dasAttributeTypesContext.close(); + + dasSchemaSubContext.destroySubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN ); + + dasSchemaSubContext.destroySubcontext( + OBJECT_CLASSES_CONTEXT_RDN ); + + dasSchemaSubContext.close(); + + schemaPartitionContext.destroySubcontext( + DAS_CONTEXT_RDN ); + + schemaPartitionContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + dasSchemaSubContext = + createDasSchemaSubContext(); + dasSyntaxesContext = + createDasSyntaxesContext(); + dasAttributeTypesContext = + createDasAttributeTypesContext(); + dasObjectClassesContext = + createDasObjectClassesContext(); + + mComplexMayRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + M_COMPLEX_MAY); + + mComplexMustRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + M_COMPLEX_MUST); + + idRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + ID); + + metaTopSDORDN = + ComplexTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS); + } + + private DirContext createDasSchemaSubContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + DAS_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaPartitionContext.createSubcontext( + DAS_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasAttributeTypesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return dasSchemaSubContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return dasSchemaSubContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute attributeTypes = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( attributeTypes ); + contextAttributes.put( objectClassAttribute ); + + return dasSchemaSubContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, + contextAttributes ); + } + + protected DirContext dasSchemaSubContext = null; + protected DirContext dasAttributeTypesContext = null; + protected DirContext dasSyntaxesContext = null; + protected DirContext dasObjectClassesContext = null; + + protected String mComplexMayRDN = null; + protected String mComplexMustRDN = null; + protected String idRDN = null; + protected String metaTopSDORDN = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetupTest.java new file mode 100644 index 0000000000..9adbe07463 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/DASSchemaContextsSetupTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class DASSchemaContextsSetupTest +extends DASSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testCreateDASSchemaSubContext() + { + assertNotNull(dasSchemaSubContext); + } + + public void testCreateDasAttributeTypesContext() + { + assertNotNull(dasAttributeTypesContext); + } + + public void testCreateDasSyntaxesContext() + { + assertNotNull(dasSyntaxesContext); + } + + public void testCreateDasObjectClassesContext() + { + assertNotNull(dasObjectClassesContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetup.java new file mode 100644 index 0000000000..4fdaaea4b2 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetup.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.create.MetaContextCreator; +import org.apache.tuscany.das.ldap.destroy.InitialContextDestroyer; +import org.apache.tuscany.das.ldap.destroy.MetaContextDestroyer; + +/* + * TODO Document that the name of a root object cannot be "meta" + * TODO Change "meta" to meta-inf + */ +public class EcoreSchemaAndDASContextsSetup +extends EcoreSchemaContextsSetup +implements DASConstants +{ + public void tearDown() + throws NamingException, Exception + { + MetaContextDestroyer. + destroy( rootContext ); + + InitialContextDestroyer. + destroy( + rootContext, + dasPartitionContext ); + + super.tearDown(); + + dasPartitionContext.close(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + + rootContext = + (LdapContext) + InitialContextCreator. + create( + xsdNamespace, + dasPartitionContext); + + metaContext = + (LdapContext) + MetaContextCreator. + create( rootContext); + } + + protected LdapContext rootContext = null; + protected LdapContext metaContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetupTest.java new file mode 100644 index 0000000000..e272262998 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaAndDASContextsSetupTest.java @@ -0,0 +1,56 @@ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaAndDASContextsSetupTest +extends EcoreSchemaAndDASContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaPartitionContext); + } + + public void testCreateEcoreSchemaSubContext() + { + assertNotNull(ecoreSchemaSubContext); + } + + public void testCreateEcoreObjectClassesContext() + { + assertNotNull(ecoreObjectClassesContext); + } + + public void testCreateEcoreAttributeTypesContext() + { + assertNotNull(ecoreAttributeTypesContext); + } + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(ecoreSyntaxesContext); + } + + public void testCreateDasModelContext() + { + assertNotNull(rootContext); + } + + public void testCreateDasMetaContext() + { + assertNotNull(metaContext); + } + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetup.java new file mode 100644 index 0000000000..88bd21f318 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetup.java @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() + throws NamingException, Exception + { + ecoreSyntaxesContext. + close(); + + ecoreSchemaSubContext. + destroySubcontext( + SYNTAXES_CONTEXT_RDN ); + + ecoreSyntaxCheckersContext. + close(); + + ecoreSchemaSubContext. + destroySubcontext( + SYNTAX_CHECKERS_CONTEXT_RDN ); + + ecoreAttributeTypesContext. + close(); + ecoreSchemaSubContext. + destroySubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN ); + + ecoreObjectClassesContext. + close(); + + ecoreSchemaSubContext. + destroySubcontext( + OBJECT_CLASSES_CONTEXT_RDN ); + + ecoreSchemaSubContext. + close(); + schemaPartitionContext. + destroySubcontext( + ECORE_CONTEXT_RDN ); + + schemaPartitionContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + ecoreSchemaSubContext = createEcoreSchemaSubContext(); + ecoreSyntaxesContext = createEcoreSyntaxesContext(); + ecoreSyntaxCheckersContext = createEcoreSyntaxCheckersContext(); + ecoreObjectClassesContext = createEcoreObjectClassesContext(); + ecoreAttributeTypesContext = createEcoreAttributeTypesContext(); + } + + private LdapContext createEcoreSchemaSubContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + ECORE_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) + schemaPartitionContext.createSubcontext( + ECORE_CONTEXT_RDN, contextAttributes ); + } + + + private LdapContext createEcoreObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) + ecoreSchemaSubContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, contextAttributes ); + } + + + + private LdapContext createEcoreAttributeTypesContext() + throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) + ecoreSchemaSubContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + private LdapContext createEcoreSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) + ecoreSchemaSubContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + private LdapContext createEcoreSyntaxCheckersContext() + throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAX_CHECKERS_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) + ecoreSchemaSubContext.createSubcontext( + SYNTAX_CHECKERS_CONTEXT_RDN, + contextAttributes); + } + + protected LdapContext ecoreSchemaSubContext = null; + protected LdapContext ecoreObjectClassesContext = null; + protected LdapContext ecoreAttributeTypesContext = null; + protected LdapContext ecoreSyntaxesContext = null; + protected LdapContext ecoreSyntaxCheckersContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetupTest.java new file mode 100644 index 0000000000..f2c746dceb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/EcoreSchemaContextsSetupTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaContextsSetupTest +extends EcoreSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testCreateEcoreSchemaSubContext() + { + assertNotNull(ecoreSchemaSubContext); + } + + public void testCreateEcoreObjectClassesContext() + { + assertNotNull(ecoreObjectClassesContext); + } + + public void testCreateEcoreAttributeTypesContext() + { + assertNotNull(ecoreAttributeTypesContext); + } + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(ecoreSyntaxesContext); + } + + public void testCreateEcoreSyntaxCheckersContext() + { + assertNotNull(ecoreSyntaxCheckersContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetup.java new file mode 100644 index 0000000000..619bc7a94f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetup.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class XSDSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + xsdSyntaxesContext. + close(); + + xsdContext. + destroySubcontext( + SYNTAXES_CONTEXT_RDN ); + + xsdContext. + close(); + + schemaPartitionContext. + destroySubcontext( + XSD_CONTEXT_RDN ); + + schemaPartitionContext. + close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + xsdContext = + createXsdContext(); + xsdSyntaxesContext = + createXsdSyntaxesContext(); + } + + private LdapContext createXsdContext() throws NamingException + { + Attributes contextAttributes = + new BasicAttributes(); + + Attribute objectClassAttribute = + new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = + new BasicAttribute( + CN, + XSD_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) schemaPartitionContext.createSubcontext( + XSD_CONTEXT_RDN, contextAttributes ); + } + + private LdapContext createXsdSyntaxesContext() throws NamingException + { + Attributes contextAttributes = + new BasicAttributes(); + + Attribute objectClassAttribute = + new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = + new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return (LdapContext) xsdContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + protected LdapContext xsdContext = + null; + protected LdapContext xsdSyntaxCheckersContext = + null; + protected LdapContext xsdSyntaxesContext = + null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetupTest.java new file mode 100644 index 0000000000..24ce5e6df1 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/embedded/setup/test/XSDSchemaContextsSetupTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.embedded.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class XSDSchemaContextsSetupTest +extends XSDSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testCreateXsdContext() + { + assertNotNull(xsdContext); + } + + public void testCreateXsdSyntaxesContext() + { + assertNotNull(xsdSyntaxesContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java new file mode 100644 index 0000000000..8bd50fb4cc --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java @@ -0,0 +1,54 @@ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EcorePackage; + +public class DataTypeToADSSyntaxMapProvider +implements SyntaxOIDValues { + + EcorePackage ecorePackage = + EcorePackage.eINSTANCE; + + private static Map dataTypeToADSSyntaxOIDMap = null; + + //TODO Make this a singleton + public DataTypeToADSSyntaxMapProvider() + { + dataTypeToADSSyntaxOIDMap = new HashMap(); + create(); + } + + public Map getDataTypeToADSSyntaxMap() + { + return dataTypeToADSSyntaxOIDMap; + } + + private Map create() + { + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEString(), + SYNTAX_STRING_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEInt(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEIntegerObject(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEBoolean(), + SYNTAX_BOOLEAN_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEBooleanObject(), + SYNTAX_BOOLEAN_OID_VALUE); + + return dataTypeToADSSyntaxOIDMap; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java new file mode 100644 index 0000000000..5b8e65c221 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.provide.SyntaxOIDProvider; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; + +public class EAttributeTypeCreator +extends AbstractAttributeTypeCreator +{ + public EAttributeTypeCreator() + { + super(); + } + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param eAttribute the e attribute + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public void create( + DirContext attributeTypesContext, + EAttribute eAttribute, + String oidPrefix) + throws NamingException, Exception + { + String eAttributeName = + eAttribute.getName(); + + EClass eContainingClass = + eAttribute.getEContainingClass(); + + String eContainingClassName = + eContainingClass.getName(); + + String namespaceURI = + eContainingClass. + getEPackage().getNsURI(); + + String qualifiedEAttributeNameURI = + SimpleTypeNamespaceQualifier.qualify( + namespaceURI, + eContainingClassName, + eAttributeName); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeNameURI); + + EClassifier eDataType = + eAttribute.getEType(); + + SyntaxOIDProvider dataTypeToADSSyntaxMapProvider = + new SyntaxOIDProvider(); + + String syntaxOID = + dataTypeToADSSyntaxMapProvider. + getSyntaxOID(eDataType); + + basicAttributes.put( + M_DESCRIPTION, + eAttributeName); + + basicAttributes.put( + M_SYNTAX, + syntaxOID); + + basicAttributes.put( + M_NAME, + normalizedEAttributeName ); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eAttributeName); + + attributeTypesContext.createSubcontext( + rdn, + basicAttributes); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java new file mode 100644 index 0000000000..684509e0d9 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.List; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.eclipse.emf.ecore.EClass; + +public class EObjectClassCreator +extends AbstractTypeCreator +{ + public EObjectClassCreator() + { + super(); + } + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param eAttribute the e attribute + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + * + * Note that null can passed for the processedEClassifiers list + * only when the EClass has not parents. + */ + public void create( + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + List processedEClassifiers, + String oidPrefix) + throws NamingException, Exception + { + if ( processedEClassifiers != null ) + { + EClass eClassParent = + EcoreTypeSystemHelper. + getEClassParent( eClass ); + + if (eClassParent != null) + { + boolean isEClassProcessed = + EObjectClassCreatorHelper. + isEClassProcessed( + eClassParent, + processedEClassifiers); + + if (!isEClassProcessed) + { + this.create( + metaContext, + attributeTypesContext, + objectClassesContext, + eClassParent, + processedEClassifiers, + oidPrefix); + } + } + } + + objectClassAttribute.add( META_OBJECT_CLASS ); + + EcoreTypeSystemHelper. + createAttributeTypes( + attributeTypesContext, + eClass, + oidPrefix ); + + String namespaceURI = + eClass.getEPackage(). + getNsURI(); + + String qualifiedEClassNameURI = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName()); + + String normalizedEObjectName = + QualifiedNameNormalizer. + normalize(qualifiedEClassNameURI); + + + basicAttributes.put( + M_NAME, + normalizedEObjectName ); + + basicAttributes.put( + M_DESCRIPTION, + eClass.getName() ); + + basicAttributes.put( + M_OBSOLETE, + LDAP_FALSE ); + + //TODO Remember to test with parent combination. + EObjectClassCreatorHelper. + addParentAttribute( + basicAttributes, + namespaceURI, + eClass ); + + if (!eClass.isAbstract()) + { + basicAttributes.put( + M_TYPE_OBJECT_CLASS, + STRUCTURAL ); + } + else + { + basicAttributes.put( + M_TYPE_OBJECT_CLASS, + ABSTRACT ); + } + + + /* + EObjectClassCreatorHelper. + addEAttributes( + basicAttributes, + namespaceURI, + eClass ); + + EObjectClassCreatorHelper. + addEReferences( + basicAttributes, + namespaceURI, + eClass ); + */ + + + EObjectClassCreatorHelper. + addEStructuralFeatures( + basicAttributes, + namespaceURI, + eClass ); + + String rdn = + ComplexTypeRDNCreator. + create( + oidPrefix, + namespaceURI, + eClass.getName()); + + EObjectClassCreatorHelper. + createInheritanceMetaData( + metaContext, + eClass ); + + /* TODO - Remove once everything is simmered down + NamingEnumeration namingEnumeration = + basicAttributes.getAll(); + + while (namingEnumeration.hasMore()) + { + Attribute attribute = (Attribute) namingEnumeration.next(); + System.out.println(attribute); + } + */ + + + objectClassesContext. + createSubcontext( + rdn, + basicAttributes ); + + + if ( processedEClassifiers != null ) + { + processedEClassifiers.add(eClass); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java new file mode 100644 index 0000000000..2a99ef8fb8 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java @@ -0,0 +1,378 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.Iterator; +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.EnumeratedSchemaAttributeTypeValues; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * The Class EObjectClassCreatorHelper. + */ +public class EObjectClassCreatorHelper +implements +EnumeratedSchemaAttributeTypeValues, +SchemaAttributeTypeConstants, +AttributeTypeConstants, +SchemaObjectClassConstants, +ObjectClassConstants, +DASConstants +{ + /** + * Adds the parent attribute. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addParentAttribute( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + EClass eClassParent = + EcoreTypeSystemHelper.getEClassParent( eClass ); + + if(eClassParent !=null) + { + String qualifiedEClassParentNameURI = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + eClassParent. + getName()); + + String normalizedEObjectName = + QualifiedNameNormalizer. + normalize(qualifiedEClassParentNameURI); + + objectClassAttributes.put( + M_SUP_OBJECT_CLASS, + normalizedEObjectName); + } + else + { + objectClassAttributes.put( + M_SUP_OBJECT_CLASS, + META_OBJECT_CLASS ); + } + } + + /** + * Adds the E attributes. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEAttributes( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List eAttributes = + eClass.getEAttributes(); + + Iterator eAttributeIterator = + eAttributes.iterator(); + + EAttribute eAttribute = + null; + + String qualifiedEAttributeName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while( eAttributeIterator.hasNext()) + { + eAttribute = eAttributeIterator.next(); + + qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eAttribute.getName()); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + if (!eAttribute.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add(normalizedEAttributeName); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add(normalizedEAttributeName); + } + } + + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + } + + /** + * Adds the E references. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEReferences( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List eReferences = + eClass.getEReferences(); + + Iterator eReferenceIterator = + eReferences.iterator(); + + EReference eReference = + null; + + String qualifiedEReferenceName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while ( eReferenceIterator.hasNext()) + { + eReference = eReferenceIterator.next(); + + qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eReference.getName()); + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + if (!eReference.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add( normalizedEReferenceName ); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add( normalizedEReferenceName ); + } + } + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + } + + /** + * Adds the E references. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEStructuralFeatures( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List eStructuralFeatures = + eClass.getEStructuralFeatures(); + + Iterator eStructuralFeatureIterator = + eStructuralFeatures.iterator(); + + EStructuralFeature eStructuralFeature = + null; + + String qualifiedEStructuralFeatureName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while ( eStructuralFeatureIterator.hasNext()) + { + eStructuralFeature = + eStructuralFeatureIterator.next(); + + qualifiedEStructuralFeatureName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eStructuralFeature.getName()); + + String normalizedEStructuralFeatureName = + QualifiedNameNormalizer. + normalize(qualifiedEStructuralFeatureName); + + + if (!eStructuralFeature.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add( normalizedEStructuralFeatureName ); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add( normalizedEStructuralFeatureName ); + } + } + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + + } + + + /** + * Checks if is E class processed. + * + * @param processedEClassifiers the processed E classifiers + * @param eClass the e class + * + * @return true, if is E class processed + */ + public static boolean isEClassProcessed( + EClass eClass, + List processedEClassifiers) + { + return processedEClassifiers.contains( eClass ); + } + + /** + * Creates the inheritance meta data. + * + * @param metaContext the das model meta context + * @param eClass the e class + * + * @throws NamingException the naming exception + */ + public static void createInheritanceMetaData( + DirContext metaContext, + EClass eClass) + throws NamingException + { + EClass eClassParent = + EcoreTypeSystemHelper.getEClassParent( eClass ); + + String rdn = null; + + if (eClassParent != null) + { + DirContext eClassParentMetaContext = + null; + try + { + eClassParentMetaContext = + ( DirContext ) + metaContext. + lookup(eClassParent.getName()); + } + catch ( NamingException e ) + { + rdn = + CN + "=" + eClassParent.getName(); + + eClassParentMetaContext = + ( DirContext ) + metaContext. + createSubcontext( rdn ); + } + + rdn = CN + "=" + eClass.getName(); + + eClassParentMetaContext. + createSubcontext( rdn ); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java new file mode 100644 index 0000000000..74c7faff71 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; + +public class EReferenceTypeCreator +extends AbstractAttributeTypeCreator +implements SyntaxOIDValues +{ + public EReferenceTypeCreator() + { + super(); + } + + public void create( + DirContext attributeTypesContext, + EReference eReference, + String oidPrefix) + throws NamingException, Exception + { + String eReferenceName = + eReference.getName(); + + EClass eContainingClass = + eReference.getEContainingClass(); + + String eContainingClassName = + eContainingClass.getName(); + + String namespaceURI = + eContainingClass. + getEPackage(). + getNsURI(); + + String qualifiedEReferenceNameURI = + SimpleTypeNamespaceQualifier.qualify( + namespaceURI, + eContainingClassName, + eReferenceName); + + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceNameURI); + + basicAttributes.put( + M_DESCRIPTION, + eReferenceName); + + basicAttributes.put( + M_SYNTAX, + SYNTAX_STRING_OID_VALUE); + + basicAttributes.put( + M_NAME, + normalizedEReferenceName ); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eReferenceName); + + attributeTypesContext.createSubcontext( + rdn, + basicAttributes); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java new file mode 100644 index 0000000000..b9e8fac0fa --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java @@ -0,0 +1,388 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.create.SyntaxEntryCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * The Class EcoreTypeSystemCreatorHelper. + */ +public class EcoreTypeSystemHelper +{ + + /** + * Creates the E data types list. + * + * @param ePackage the e package + * + * @return the list< E data type> + */ + public static List createEDataTypesList( + EPackage ePackage) + { + List list = ePackage.eContents(); + List eDataTypes = new ArrayList(); + Iterator iterator = list.iterator(); + while (iterator.hasNext()) + { + Object object = iterator.next(); + if (object instanceof EDataType ) + { + eDataTypes.add( ( EDataType ) object ); + } + } + return eDataTypes; + } + + public static void createSyntaxCheckerEntries( + String oidPrefix, + LdapContext syntaxCheckersContext) throws Exception + + { + + } + + /** + * Creates the syntax entries. + * + * @param oidPrefix the oid prefix + * @param eDataTypes the e data types + * @param syntaxesContext the syntaxes context + * + * @throws Exception the exception + */ + public static void createSyntaxEntries( + List eDataTypes, + String oidPrefix, + LdapContext syntaxesContext, + LdapContext syntaxCheckersContext) throws Exception + { + Iterator eDataTypeIterator = + eDataTypes.iterator(); + + String eDataTypeName = + null; + String eDataTypeNamespaceURI = + null; + + while (eDataTypeIterator.hasNext()) + { + EDataType eDataType = + eDataTypeIterator.next(); + eDataTypeName = + eDataType.getName(); + eDataTypeNamespaceURI = + eDataType.getEPackage().getNsURI(); + + SyntaxEntryCreator.create( + oidPrefix, + eDataTypeNamespaceURI, + eDataTypeName, + syntaxesContext, + syntaxCheckersContext); + } + } + + /** + * Creates the E classifiers list. + * + * @param ePackage the e package + * + * @return the list< E class> + */ + public static List createEClassifiersList( + EPackage ePackage) + { + List list = ePackage.eContents(); + List eClassifiers = new ArrayList(); + Iterator iterator = list.iterator(); + while (iterator.hasNext()) + { + Object object = iterator.next(); + if (object instanceof EClassifier ) + { + eClassifiers.add( ( EClass ) object ); + } + } + return eClassifiers; + } + + /** + * Creates the E classifier entries. + * + * @param eClassifiers the e classifiers + */ + public static void createEClassifierEntries( + List eClassifiers) + { + + } + + /** + * Load parent E classifier stack. + * + * @param parentEClassifierStack the parent E classifier stack + * @param eClass the e class + * + * @return the stack< E class> + * + * Note that clients should pass null for the + * parentEClassifierStack argument. The method + * creates the stack when needed, and uses + * it during recursion. + */ + public static Stack loadParentEClassifierStack( + EClass eClass, + Stack parentEClassifierStack) + { + List eClassParents = + eClass.getESuperTypes(); + + if (eClassParents.size() > 0) + { + Iterator eClassParentIterator = + eClassParents.iterator(); + + while(eClassParentIterator.hasNext()) + { + EClass parentEClass = + eClassParentIterator.next(); + + if (!parentEClass.isInterface()) + { + if (parentEClassifierStack == null) + { + parentEClassifierStack = new Stack(); + } + + parentEClassifierStack.push( parentEClass ); + + eClassParents = parentEClass.getESuperTypes(); + + if (eClassParents.size() == 0) + { + return parentEClassifierStack; + } + else + { + loadParentEClassifierStack( + parentEClass, + parentEClassifierStack ); + } + } + } + } + return parentEClassifierStack; + } + + /** + * Creates the E object class parents. + * + * @param oidPrefix the oid prefix + * @param objectClassesContext the object classes context + * @param eClass the e class + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public static void createEObjectClassParents( + DirContext dasModelMetaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + Stack parentEClassifierStack = + EcoreTypeSystemHelper. + loadParentEClassifierStack( + eClass, + null); + + EClass parentEClass = null; + + for (int i=0; i eAttributes = + eClass.getEAttributes(); + + Iterator eAttributeIterator = + eAttributes.iterator(); + + while (eAttributeIterator.hasNext()) + { + EAttribute eAttribute = eAttributeIterator.next(); + + EAttributeTypeCreator + eAttributeTypeCreator = + new EAttributeTypeCreator(); + + eAttributeTypeCreator.create( + attributeTypesContext, + eAttribute, + oidPrefix ); + } + + List eReferences = + eClass.getEReferences(); + + Iterator eReferenceIterator = + eReferences.iterator(); + + while(eReferenceIterator.hasNext()) + { + EReference eReference = + eReferenceIterator. + next(); + + EReferenceTypeCreator + eReferenceTypeCreator = + new EReferenceTypeCreator(); + + eReferenceTypeCreator.create( + attributeTypesContext, + eReference, + oidPrefix); + } + } + + /** + * Destroy attribute types. + * + * @param oidPrefix the oid prefix + * @param eClass the e class + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public static void destroyAttributeTypes( + DirContext attributeTypesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + List + eStructuralFeatures = + eClass. + getEStructuralFeatures(); + + Iterator + eStructuralFeatureIterator = + eStructuralFeatures.iterator(); + + while (eStructuralFeatureIterator.hasNext()) + { + EStructuralFeature + eStructuralFeature = + eStructuralFeatureIterator.next(); + + EStructuralFeatureTypeDestroyer.destroy( + attributeTypesContext, + eStructuralFeature, + oidPrefix ); + } + } + + /** + * Gets the E class parent. + * + * @param eClass the e class + * + * @return the e class parent + */ + public static EClass getEClassParent(EClass eClass) + { + List eClassParents = + eClass.getESuperTypes(); + + if (eClassParents.size() > 0) + { + Iterator eClassParentIterator = + eClassParents.iterator(); + + while(eClassParentIterator.hasNext()) + { + EClass parentEClass = + eClassParentIterator.next(); + + if (!parentEClass.isInterface()) + { + return parentEClass; + } + else + { + return null; + } + } + } + return null; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java new file mode 100644 index 0000000000..3a92143dc5 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.ldap.LdapContext; + +import org.eclipse.emf.ecore.EClass; + +public class ModelTypeSystemCreator +{ + private static List processedEClassifiers = + new ArrayList(); + + public static void create( + LdapContext dasModelMetaContext, + LdapContext attributeTypesContext, + LdapContext objectClassesContext, + List eClassifiers, + String oidPrefix) + throws Exception + { + EObjectClassCreator eObjectClassCreator = + new EObjectClassCreator(); + + for (EClass eClass : eClassifiers) + { + eObjectClassCreator.create( + dasModelMetaContext, + attributeTypesContext, + objectClassesContext, + eClass, + processedEClassifiers, + oidPrefix ); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java new file mode 100644 index 0000000000..1ad3a1eb21 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy; + +import java.util.Map; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.SearchResult; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.eclipse.emf.ecore.EClass; + +/** + * The Class ECascadingObjectClassDestroyer. + * + * The purose of this class is to destroy a ObjectClass + * that is the parent of other ObjectClass entries. + * + * It first checks to see whether the EClass instance + * is a parent of other EClassifiers by examining + * whether the metaContext contains the EClass + * instance's name. + * + * If the EClass instance has an an metaContext child entry, + * then this instance is a parent of other EClassifiers. + * Therefore we check to see whether there are EClass + * instances left to delete that inherit from this EClass. + * + * If none are left we delete the parentMetaContext entry. + * If there are more children left, we leave the parentMetaContext + * entry in place and delete the children. + * + * If there is no parentMetaEntryContext, it means that this + * EClass instance does not have any children. Therefore it's + * safe to delete the corresponding ObjectClass. + */ +public class ECascadingObjectClassDestroyer +implements AttributeTypeConstants +{ + + + public static void destroy( + Map eClassNameToEClassMap, + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + String rdn = + null; + DirContext eClassParentMetaContext = + null; + try + { + eClassParentMetaContext = + ( DirContext ) + metaContext. + lookup( CN + "=" + eClass.getName() ); + } + catch (Exception e) + { + //This eClass can be deleted, because it is not used a super class. + } + + if (eClassParentMetaContext == null) + { + EObjectClassDestroyer.destroy( + metaContext, + attributeTypesContext, + objectClassesContext, + eClass, + oidPrefix ); + } + else + { + Attributes searchAttributes = + new BasicAttributes(true); + + searchAttributes.put(new BasicAttribute(CN)); + + NamingEnumeration childEntries = + eClassParentMetaContext.search("", searchAttributes); + + if (childEntries.hasMore()) + { + while (childEntries.hasMore()) + { + SearchResult childEntry = + childEntries.next(); + + Attributes childEntryAttributes = + childEntry.getAttributes(); + + String eClassName = + ( String ) + childEntryAttributes.get( CN ).get(); + + EClass childEClass = + eClassNameToEClassMap.get( eClassName ); + + destroy( + eClassNameToEClassMap, + metaContext, + attributeTypesContext, + objectClassesContext, + childEClass, + oidPrefix ); + + EObjectClassDestroyer.destroy( + metaContext, + attributeTypesContext, + objectClassesContext, + eClass, + oidPrefix ); + + rdn = CN + "=" + eClass.getName(); + metaContext.destroySubcontext( rdn ); + } + } + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java new file mode 100644 index 0000000000..16c7f893d6 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.eclipse.emf.ecore.EClass; + +/** + * The Class EObjectClassDestroyer. + */ +public class EObjectClassDestroyer +implements AttributeTypeConstants +{ + public static void destroy( + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + String namespaceURI = + eClass.getEPackage(). + getNsURI(); + + String rdn = + ComplexTypeRDNCreator. + create( + oidPrefix, + namespaceURI, + eClass.getName()); + + objectClassesContext. + destroySubcontext( + rdn); + + EcoreTypeSystemHelper. + destroyAttributeTypes( + attributeTypesContext, + eClass, + oidPrefix ); + + LdapContext parentMetaContext = + null; + + EClass eClassParent = + EcoreTypeSystemHelper. + getEClassParent( eClass ); + + /* + * After destroying the ObjecClass and its attributes + * we must also clean up the meta context. + */ + + if (eClassParent != null) + { + rdn = CN + "=" + eClassParent.getName(); + + parentMetaContext = + ( LdapContext ) + metaContext.lookup( rdn ); + + rdn = CN + "=" + eClass.getName(); + + parentMetaContext.destroySubcontext( rdn ); + } + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java new file mode 100644 index 0000000000..2d88bc8803 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +public class EStructuralFeatureTypeDestroyer +extends AbstractAttributeTypeCreator +{ + public static void destroy( + DirContext attributeTypesContext, + EStructuralFeature eStructuralFeature, + String oidPrefix) + throws NamingException, Exception + { + EClass eContainingClass = + eStructuralFeature. + getEContainingClass(); + + String eContainingClassName = + eContainingClass. + getName(); + + String namespaceURI = + eContainingClass. + getEPackage(). + getNsURI(); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eStructuralFeature.getName()); + + attributeTypesContext.destroySubcontext( + rdn); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java new file mode 100644 index 0000000000..be0da66292 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java @@ -0,0 +1,62 @@ +package org.apache.tuscany.das.ldap.schema.emf.provide; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EcorePackage; + +public class SyntaxOIDProvider +implements SyntaxOIDValues { + + private static Map dataTypeToADSSyntaxOIDMap = null; + + private EcorePackage ecorePackage = EcorePackage.eINSTANCE; + + //TODO Make this a singleton + public SyntaxOIDProvider() + { + dataTypeToADSSyntaxOIDMap = + new HashMap(); + + this.create(); + ecorePackage = + EcorePackage.eINSTANCE; + } + + public String getSyntaxOID(EClassifier eClassifier) + { + String syntaxOID = dataTypeToADSSyntaxOIDMap.get(eClassifier); + if (syntaxOID == null) + { + return SYNTAX_STRING_OID_VALUE; + } + return syntaxOID; + } + + private Map create() + { + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEString(), + SYNTAX_STRING_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEInt(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEIntegerObject(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEBoolean(), + SYNTAX_BOOLEAN_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEBooleanObject(), + SYNTAX_BOOLEAN_OID_VALUE); + + return dataTypeToADSSyntaxOIDMap; + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/AbstractTestSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/AbstractTestSetup.java new file mode 100644 index 0000000000..95bbd23f8b --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/AbstractTestSetup.java @@ -0,0 +1,50 @@ + +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.apacheds.testing.setup.JNDIConnectionTemplate; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.EnumeratedSchemaAttributeTypeValues; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; + +public abstract class AbstractTestSetup +extends JNDIConnectionTemplate +implements +EnumeratedSchemaAttributeTypeValues, +SchemaAttributeTypeConstants, +AttributeTypeConstants, +SchemaObjectClassConstants, +ObjectClassConstants, +DASConstants +{ + protected LdapContext schemaContext = + null; + + protected static String PROVIDER_URL_VALUE = + "ldap://localhost:10389/ou=schema"; + + protected static final String SYNTAXES_CONTEXT_RDN = + OU + "=" + SYNTAXES_CONTEXT_NAME; + + protected static final String ATTRIBUTE_TYPES_CONTEXT_RDN = + OU + "=" + ATTRIBUTE_TYPES_CONTEXT_NAME; + + protected static final String OBJECT_CLASSES_CONTEXT_RDN = + OU + "=" + OBJECT_CLASSES_CONTEXT_NAME; + + protected static final String XSD_CONTEXT_RDN = + CN + "=" + XSD_CONTEXT_NAME; + protected static final String DAS_CONTEXT_RDN = + CN + "=" + DAS_CONTEXT_NAME; + protected static final String ECORE_CONTEXT_RDN = + CN + "=" + ECORE_CONTEXT_NAME; + + protected String xsdNamespace = + "http://example.com/users/accounts"; + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetup.java new file mode 100644 index 0000000000..7eef04e56d --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetup.java @@ -0,0 +1,56 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.apacheds.testing.setup.JNDIHotPartitionConnectionTemplate; +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.create.MetaContextCreator; +import org.apache.tuscany.das.ldap.destroy.InitialContextDestroyer; +import org.apache.tuscany.das.ldap.destroy.MetaContextDestroyer; + +public class DASContextSetup +extends JNDIHotPartitionConnectionTemplate +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + MetaContextDestroyer. + destroy( modelContext ); + + InitialContextDestroyer. + destroy( + modelContext, + dasPartitionContext ); + super.tearDown(); + + dasPartitionContext.close(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + dasPartitionContext = + connect("das"); + + modelContext = + (LdapContext) + InitialContextCreator. + create( + xsdNamespace, + dasPartitionContext); + + //Meta Context + //---------------------------------------------- + metaContext = + (LdapContext) MetaContextCreator. + create( + modelContext); + } + protected LdapContext dasPartitionContext = null; + protected LdapContext modelContext = null; + protected LdapContext metaContext = null; + protected LdapContext schemaContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetupTest.java new file mode 100644 index 0000000000..8e0d4674dc --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASContextSetupTest.java @@ -0,0 +1,34 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class DASContextSetupTest +extends DASContextSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testCreateDASPartitionContext() + { + assertNotNull(dasPartitionContext); + } + + public void testModelContext() + { + assertNotNull(modelContext); + } + public void testMetaContext() + { + assertNotNull(metaContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetup.java new file mode 100644 index 0000000000..9f4d2bb330 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetup.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; + +public class DASSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + dasSyntaxesContext.close(); + + dasContext.destroySubcontext( + SYNTAXES_CONTEXT_RDN ); + + dasAttributeTypesContext.close(); + + dasContext.destroySubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN ); + + dasContext.destroySubcontext( + OBJECT_CLASSES_CONTEXT_RDN ); + + dasContext.close(); + + schemaContext.destroySubcontext( + DAS_CONTEXT_RDN ); + + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect(); + dasContext = (LdapContext) createDasContext(); + dasSyntaxesContext = (LdapContext) createDasSyntaxesContext(); + dasAttributeTypesContext = (LdapContext) createDasAttributeTypesContext(); + dasObjectClassesContext = (LdapContext) createDasObjectClassesContext(); + + mComplexMayRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + M_COMPLEX_MAY); + + mComplexMustRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + M_COMPLEX_MUST); + + idRDN = + SimpleTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS, + ID); + + + metaTopSDORDN = + ComplexTypeRDNCreator.create( + TUSCANY_OID_PREFIX_VALUE, + DAS_XSD_NAMESPACE, + M_META_TOP_SDO_OBJECT_CLASS); + } + + private DirContext createDasContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + DAS_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + DAS_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasAttributeTypesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return dasContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return dasContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createDasObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute attributeTypes = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( attributeTypes ); + contextAttributes.put( objectClassAttribute ); + + return dasContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, + contextAttributes ); + } + + protected LdapContext dasContext = null; + protected LdapContext dasAttributeTypesContext = null; + protected LdapContext dasSyntaxesContext = null; + protected LdapContext dasObjectClassesContext = null; + + protected String mComplexMayRDN = null; + protected String mComplexMustRDN = null; + protected String idRDN = null; + protected String metaTopSDORDN = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetupTest.java new file mode 100644 index 0000000000..35c1f79524 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/DASSchemaContextsSetupTest.java @@ -0,0 +1,48 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class DASSchemaContextsSetupTest +extends DASSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + + public void testConnect() + { + assertNotNull(schemaContext); + } + + public void testCreateEcoreContext() + { + assertNotNull(dasContext); + } + + + public void testCreateDasAttributeTypesContext() + { + assertNotNull(dasAttributeTypesContext); + } + + public void testCreateDasSyntaxesContext() + { + assertNotNull(dasSyntaxesContext); + } + + public void testCreateDasObjectClassesContext() + { + assertNotNull(dasObjectClassesContext); + } + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetup.java new file mode 100644 index 0000000000..6d9164c755 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetup.java @@ -0,0 +1,131 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaAndDASContextsSetup +extends DASContextSetup +implements DASConstants +{ + public void tearDown() + throws NamingException, Exception + { + ecoreSyntaxesContext.close(); + ecoreContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + + ecoreAttributeTypesContext.close(); + ecoreContext.destroySubcontext( ATTRIBUTE_TYPES_CONTEXT_RDN ); + + ecoreObjectClassesContext.close(); + ecoreContext.destroySubcontext( OBJECT_CLASSES_CONTEXT_RDN ); + + ecoreContext.close(); + schemaContext.destroySubcontext( ECORE_CONTEXT_RDN ); + + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect("schema"); + ecoreContext = createEcoreContext(); + ecoreSyntaxesContext = createEcoreSyntaxesContext(); + ecoreObjectClassesContext = createEcoreObjectClassesContext(); + ecoreAttributeTypesContext = createEcoreAttributeTypesContext(); + } + + private DirContext createEcoreContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + ECORE_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + ECORE_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createEcoreObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, contextAttributes ); + } + + + + private DirContext createEcoreAttributeTypesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createEcoreSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + protected DirContext ecoreContext = null; + protected DirContext ecoreObjectClassesContext = null; + protected DirContext ecoreAttributeTypesContext = null; + protected DirContext ecoreSyntaxesContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetupTest.java new file mode 100644 index 0000000000..b7a7a7834b --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaAndDASContextsSetupTest.java @@ -0,0 +1,56 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaAndDASContextsSetupTest +extends EcoreSchemaAndDASContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaContext); + } + + public void testCreateEcoreContext() + { + assertNotNull(ecoreContext); + } + + public void testCreateEcoreObjectClassesContext() + { + assertNotNull(ecoreObjectClassesContext); + } + + public void testCreateEcoreAttributeTypesContext() + { + assertNotNull(ecoreAttributeTypesContext); + } + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(ecoreSyntaxesContext); + } + + public void testCreateDasModelContext() + { + assertNotNull(modelContext); + } + + public void testCreateDasMetaContext() + { + assertNotNull(metaContext); + } + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetup.java new file mode 100644 index 0000000000..fb8ca08b5f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetup.java @@ -0,0 +1,132 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() + throws NamingException, Exception + { + ecoreSyntaxesContext.close(); + ecoreContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + + ecoreAttributeTypesContext.close(); + ecoreContext.destroySubcontext( ATTRIBUTE_TYPES_CONTEXT_RDN ); + + ecoreObjectClassesContext.close(); + ecoreContext.destroySubcontext( OBJECT_CLASSES_CONTEXT_RDN ); + + ecoreContext.close(); + schemaContext.destroySubcontext( ECORE_CONTEXT_RDN ); + + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect(); + ecoreContext = createEcoreContext(); + ecoreSyntaxesContext = createEcoreSyntaxesContext(); + ecoreObjectClassesContext = createEcoreObjectClassesContext(); + ecoreAttributeTypesContext = createEcoreAttributeTypesContext(); + } + + private DirContext createEcoreContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + ECORE_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + ECORE_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createEcoreObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, contextAttributes ); + } + + + + private DirContext createEcoreAttributeTypesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createEcoreSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + protected DirContext ecoreContext = null; + protected DirContext ecoreObjectClassesContext = null; + protected DirContext ecoreAttributeTypesContext = null; + protected DirContext ecoreSyntaxesContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetupTest.java new file mode 100644 index 0000000000..060f017e35 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/EcoreSchemaContextsSetupTest.java @@ -0,0 +1,45 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class EcoreSchemaContextsSetupTest +extends EcoreSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaContext); + } + + public void testCreateEcoreContext() + { + assertNotNull(ecoreContext); + } + + public void testCreateEcoreObjectClassesContext() + { + assertNotNull(ecoreObjectClassesContext); + } + + public void testCreateEcoreAttributeTypesContext() + { + assertNotNull(ecoreAttributeTypesContext); + } + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(ecoreSyntaxesContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetup.java new file mode 100644 index 0000000000..11fb2a3af9 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetup.java @@ -0,0 +1,21 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class SchemaContextSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect(); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetupTest.java new file mode 100644 index 0000000000..dacbf2b2ec --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextSetupTest.java @@ -0,0 +1,25 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class SchemaContextSetupTest +extends SchemaContextSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetup.java new file mode 100644 index 0000000000..92f86bc402 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetup.java @@ -0,0 +1,231 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; + +public class SchemaContextsSetup +extends AbstractTestSetup +{ + public void tearDown() throws NamingException, Exception + { + dasSyntaxesContext.close(); + dasContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + + dasAttributeTypesContext.close(); + dasContext.destroySubcontext( ATTRIBUTE_TYPES_CONTEXT_RDN ); + + dasObjectClassesContext.close(); + dasContext.destroySubcontext( OBJECT_CLASSES_CONTEXT_RDN ); + dasContext.close(); + + xsdSyntaxesContext.close(); + xsdContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + + xsdContext.close(); + schemaContext.destroySubcontext( XSD_CONTEXT_RDN ); + + ecoreSyntaxesContext.close(); + ecoreContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + + ecoreContext.close(); + schemaContext.destroySubcontext( ECORE_CONTEXT_RDN ); + + schemaContext.destroySubcontext( DAS_CONTEXT_RDN ); + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect(); + dasContext = createDASContext(); + dasSyntaxesContext = createSyntaxesContext(); + dasAttributeTypesContext = createAttributeTypesContext(); + dasObjectClassesContext = createObjectClassesContext(); + xsdContext = createXSDContext(); + xsdSyntaxesContext = createXSDSyntaxesContext(); + ecoreContext = createEcoreContext(); + ecoreSyntaxesContext = createEcoreSyntaxesContext(); + } + + private DirContext createDASContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute dasAttribute = new BasicAttribute( + CN, + DAS_CONTEXT_NAME); + + contextAttributes.put( dasAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + DAS_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createXSDContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute xsdAttribute = new BasicAttribute( + CN, + XSD_CONTEXT_NAME); + + contextAttributes.put( xsdAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + XSD_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createXSDSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute xsdAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( xsdAttribute ); + contextAttributes.put( objectClassAttribute ); + + return xsdContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createEcoreContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + ECORE_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + ECORE_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createEcoreSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return ecoreContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute syntaxesRDNAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( objectClassAttribute ); + contextAttributes.put( syntaxesRDNAttribute ); + + return dasContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + + private DirContext createAttributeTypesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute attributeTypes = new BasicAttribute( + OU, + ATTRIBUTE_TYPES_CONTEXT_NAME); + + contextAttributes.put( attributeTypes ); + contextAttributes.put( objectClassAttribute ); + + return dasContext.createSubcontext( + ATTRIBUTE_TYPES_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createObjectClassesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute attributeTypes = new BasicAttribute( + OU, + OBJECT_CLASSES_CONTEXT_NAME); + + contextAttributes.put( attributeTypes ); + contextAttributes.put( objectClassAttribute ); + + return dasContext.createSubcontext( + OBJECT_CLASSES_CONTEXT_RDN, + contextAttributes ); + } + + protected DirContext dasContext = null; + protected DirContext xsdContext = null; + protected DirContext xsdSyntaxesContext = null; + protected DirContext ecoreContext = null; + protected DirContext ecoreSyntaxesContext = null; + protected DirContext dasSyntaxesContext = null; + protected DirContext dasAttributeTypesContext = null; + protected DirContext dasObjectClassesContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetupTest.java new file mode 100644 index 0000000000..dfea532518 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/SchemaContextsSetupTest.java @@ -0,0 +1,71 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +public class SchemaContextsSetupTest +extends SchemaContextsSetup +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaContext); + } + + + public void testCreateDASContext() + { + assertNotNull(dasContext); + } + + + public void testCreateXSDContext() + { + assertNotNull(xsdContext); + } + + + + public void testCreateXSDSyntaxesContext() + { + assertNotNull(xsdSyntaxesContext); + } + + + public void testCreateEcoreContext() + { + assertNotNull(ecoreContext); + } + + + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(ecoreSyntaxesContext); + } + + public void testCreateSyntaxesContext() + { + assertNotNull(dasSyntaxesContext); + } + + public void testCreateAttributeTypesContext() + { + assertNotNull(dasAttributeTypesContext); + } + + + public void testCreateObjectClassesContext() + { + assertNotNull(dasObjectClassesContext); + } + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetup.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetup.java new file mode 100644 index 0000000000..4b9cd22e44 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetup.java @@ -0,0 +1,76 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class XSDSchemaContextsSetup +extends AbstractTestSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + xsdSyntaxesContext.close(); + xsdContext.destroySubcontext( SYNTAXES_CONTEXT_RDN ); + xsdContext.close(); + schemaContext.destroySubcontext( XSD_CONTEXT_RDN ); + schemaContext.close(); + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + schemaContext = connect(); + xsdContext = createXsdContext(); + xsdSyntaxesContext = createXsdSyntaxesContext(); + } + + private DirContext createXsdContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(META_SCHEMA); + + Attribute ecoreAttribute = new BasicAttribute( + CN, + XSD_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return schemaContext.createSubcontext( + XSD_CONTEXT_RDN, contextAttributes ); + } + + private DirContext createXsdSyntaxesContext() throws NamingException + { + Attributes contextAttributes = new BasicAttributes(); + + Attribute objectClassAttribute = new BasicAttribute( + OBJECT_CLASS, + TOP); + objectClassAttribute.add(ORGANIZATIONAL_UNIT); + + Attribute ecoreAttribute = new BasicAttribute( + OU, + SYNTAXES_CONTEXT_NAME); + + contextAttributes.put( ecoreAttribute ); + contextAttributes.put( objectClassAttribute ); + + return xsdContext.createSubcontext( + SYNTAXES_CONTEXT_RDN, contextAttributes ); + } + + protected DirContext xsdContext = null; + protected DirContext xsdSyntaxesContext = null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetupTest.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetupTest.java new file mode 100644 index 0000000000..a0bb8fb69d --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/setup/test/XSDSchemaContextsSetupTest.java @@ -0,0 +1,35 @@ +package org.apache.tuscany.das.ldap.schema.setup.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.constants.DASConstants; + +public class XSDSchemaContextsSetupTest +extends XSDSchemaContextsSetup +implements DASConstants +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void testConnect() + { + assertNotNull(schemaContext); + } + + public void testCreateEcoreContext() + { + assertNotNull(xsdContext); + } + + public void testCreateEcoreSyntaxesContext() + { + assertNotNull(xsdSyntaxesContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/testing/constants/DASTestingConstants.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/testing/constants/DASTestingConstants.java new file mode 100644 index 0000000000..2ee1d37650 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/testing/constants/DASTestingConstants.java @@ -0,0 +1,9 @@ +package org.apache.tuscany.das.ldap.testing.constants; + +public interface DASTestingConstants { + + String xsdNamespace = + "http://example.com/users/accounts"; + + +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java new file mode 100644 index 0000000000..1185d968d3 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.util; + +// TODO: Auto-generated Javadoc +/** + * The Class DataTypeNamespaceQualifier. + */ +public class ComplexTypeNamespaceQualifier +{ + /** + * Qualify. + * + * @param namespaceURI the namespace URI + * @param complexTypeName the name + * + * @return the string + */ + public static String qualify(String namespaceURI, String complexTypeName ) + { + return namespaceURI + "/" + complexTypeName; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java new file mode 100644 index 0000000000..f41d192bd0 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java @@ -0,0 +1,10 @@ +package org.apache.tuscany.das.ldap.util; + +public class IDGenerator { + + static long currentID= System.currentTimeMillis(); + + static public synchronized long generate(){ + return currentID++; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java new file mode 100644 index 0000000000..be19f0b6c4 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java @@ -0,0 +1,168 @@ + +package org.apache.tuscany.das.ldap.util; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +/** + * The Class JNDIUtil. + */ +public class JNDIUtil +{ + /** + * Calculate DN components. + * + * @param context the context + * + * @return the string[] containing the components of the DN + * + * @throws NamingException the naming exception + */ + public static String[] calculateDNComponents( + DirContext context) + throws NamingException + { + String contextDN = + context.getNameInNamespace(); + + String[] initialContextComponents = + contextDN.split( "[,]" ); + + return initialContextComponents; + } + + + /** + * Calculate DN components. + * + * @param contextDN the context DN + * + * @return the string[] containing the components of the DN + * + * @throws NamingException the naming exception + */ + public static String[] calculateDNComponents( + String contextDN) + throws NamingException + { + String[] initialContextComponents = + contextDN.split( "[,]" ); + + return initialContextComponents; + } + + /** + * Gets the parent context. + * + * @param partitionContext the partition context + * @param childContext the child context + * + * @return the parent context (Null if the child context is the root) + * + * @throws NamingException the naming exception + */ + public static DirContext getParentContext( + DirContext childContext, + DirContext partitionContext) + throws NamingException + { + String[] childContextDNComponents = + calculateDNComponents( childContext ); + + String[] partitionDNComponents = + calculateDNComponents( partitionContext ); + + DirContext parentContext = null; + + if (childContextDNComponents.length == partitionDNComponents.length) + { + return null; + } + else if ( (childContextDNComponents.length - 1) == partitionDNComponents.length) + { + return partitionContext; + } + else + { + String parentLookupDN = + calculateParentRelativeDN( + childContext, partitionContext.getNameInNamespace() ); + + + + parentContext = + ( DirContext ) partitionContext.lookup( parentLookupDN ); + } + return parentContext; + } + + + /** + * Calculate parent relative DN. + * The parent relative DN is the + * DN of the parent context, relative + * to the partition context. + * + * So if the partition context is + * ou=system and + * the child context has DN + * cn=accounts, cn=users, cn=example, ou=system + * + * then the parent relative DN is + * cn=users, cn=example + * + * @param childContext the child context + * @param partitionDN the partition DN + * + * @return the string + * + * @throws NamingException the naming exception + */ + public static String calculateParentRelativeDN( + DirContext childContext, + String partitionDN) + throws NamingException + { + String parentRelativeDN = null; + + String[] childContextDNComponents = + calculateDNComponents( childContext ); + + String[] partitionDNComponents = + calculateDNComponents( partitionDN ); + + if (childContextDNComponents.length == + partitionDNComponents.length) + { + return null; + } + else if (childContextDNComponents.length == + partitionDNComponents.length + 1) + { + String childRDN = childContextDNComponents[0]; + String childContextDN = childContext.getNameInNamespace(); + + int beginIndex = childRDN.length() + 1; + int endIndex = childContextDN.length(); + + parentRelativeDN = childContextDN.substring( + beginIndex, endIndex ); + + return parentRelativeDN; + } + else + { + String childRDN = childContextDNComponents[0]; + String childContextDN = childContext.getNameInNamespace(); + + int beginIndex = childRDN.length() + 1; + int endIndex = + childContextDN.length() - + ( partitionDN.length() +1); + + parentRelativeDN = childContextDN.substring( + beginIndex, endIndex ); + } + return parentRelativeDN; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java new file mode 100644 index 0000000000..2d0be469bc --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.util; + +public class LDAPNormalizer +{ + + /** + * Normalize a qualified string for LDAP + * by replacing periods with dashes. + * + * @param qualifiedName the qualified name + */ + public static void normalize(String qualifiedName) + { + qualifiedName = qualifiedName.replace( ".", "-" ); + } + + + +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java new file mode 100644 index 0000000000..51b34f5d0f --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.util; + +public class QualifiedNameNormalizer +{ + /** + * Normalize a qualified string for LDAP + * by replacing periods with dashes. + * + * @param qualifiedName the qualified name + */ + public static String normalize(String qualifiedName) + { + qualifiedName = qualifiedName.replace("http://", ""); + qualifiedName = qualifiedName.replace("/", "-"); + return qualifiedName.replace(".", "-"); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java new file mode 100644 index 0000000000..40dc6e0b09 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.util; + +// TODO: Auto-generated Javadoc +/** + * The Class DataTypeNamespaceQualifier. + */ +public class SimpleTypeNamespaceQualifier +{ + /** + * Qualify. + * + * @param namespaceURI the namespace URI + * @param complexTypeName the name + * + * @return the string + */ + public static String qualify(String namespaceURI, String complexTypeName, String simpleTypeName ) + { + return namespaceURI + "/" + complexTypeName + "/" + simpleTypeName; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java new file mode 100644 index 0000000000..87ff89071a --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java @@ -0,0 +1,49 @@ + +package org.apache.tuscany.das.ldap.util; + +import org.eclipse.emf.common.util.URI; + +/** + * The Class XSDNamespaceToInitialContextTransformer. + * + * Takes the XSD Namespace used by the DataObjects + * and transforms it into the DN of the initial context + * used for the root DataObject entry. + */ +public class XSDNamespaceToInitialContextTransformer +{ + /** + * Transform. + * + * @param namespaceURIString the namespace URI string + * + * @return the DN of the initial context + * + * @throws Exception the exception + */ + public static String transform(String namespaceURIString) throws Exception + { + URI namespaceURI = URI.createURI(namespaceURIString); + String authority = namespaceURI.authority(); + + String path = namespaceURI.path(); + + String[] authorityTokens = authority.split( "[.]" ); + String[] pathTokens = path.split("[/]"); + + String DN = new String(""); + + for (int i = (pathTokens.length-1); i > 0; i--) + { + DN = DN + "cn=" + pathTokens[i] + ", "; + } + + for (int i = 0; i <= (authorityTokens.length-2); i++) + { + DN = DN + "cn=" + authorityTokens[i] + ", "; + } + + DN = DN + "ou=" + authorityTokens[authorityTokens.length-1]; + return DN; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java new file mode 100644 index 0000000000..833cf0e7ae --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java @@ -0,0 +1,26 @@ + +package org.apache.tuscany.das.ldap.util; + +import org.eclipse.emf.common.util.URI; + +public class XSDNamespaceURITokenizer +{ + + public static String[] createAuthorityTokens( URI xsdNamespaceURI ) + { + String authority = xsdNamespaceURI.authority(); + String[] authorityTokens = authority.split( "[.]" ); + return authorityTokens; + } + + public static String[] createPathTokens(URI xsdNamespace) + { + String path = xsdNamespace.path(); + if (path != null) + { + return path.split("[/]"); + } + else + return null; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/connect/test/ADSEmbeddedConnectionTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/connect/test/ADSEmbeddedConnectionTest.java new file mode 100644 index 0000000000..d77b4491a4 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/connect/test/ADSEmbeddedConnectionTest.java @@ -0,0 +1,54 @@ +package org.apache.tuscany.das.ldap.connect.test; + +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.connect.ADSEmbeddedConnection; +import org.apache.tuscany.model.Configuration; +import org.apache.tuscany.model.ConfigurationFactory; + +import junit.framework.TestCase; + +public class ADSEmbeddedConnectionTest extends TestCase { + + public void testConnect() throws Exception + { + Configuration configuration = + ConfigurationFactory. + INSTANCE. + createConfiguration(); + + ADSEmbeddedConnection adsEmbeddedConnection = + new ADSEmbeddedConnection(configuration); + + LdapContext dasContext = + adsEmbeddedConnection. + connect( + configuration. + getDasPartitionName()); + + assertEquals( + dasContext.getNameInNamespace(), + "ou=das"); + + LdapContext schemaContext = + adsEmbeddedConnection. + connect( + configuration. + getSchemaPartitionName()); + + assertEquals( + schemaContext.getNameInNamespace(), + "ou=schema"); + + configuration.setDasPartitionName("system"); + + LdapContext systemContext = + adsEmbeddedConnection.connect(configuration.getDasPartitionName()); + + assertEquals( + systemContext.getNameInNamespace(), + "ou=system"); + + adsEmbeddedConnection.shutdown(); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorHelperTest.java new file mode 100644 index 0000000000..96c449099d --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorHelperTest.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.create.InitialContextCreatorHelper; + +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; +import org.apache.tuscany.das.ldap.util.XSDNamespaceURITokenizer; +import org.eclipse.emf.common.util.URI; + +/* + * Note these tests require a running instance of ApacheDS + */ + +public class InitialContextCreatorHelperTest +extends AbstractTestSetup +{ + protected String xsdNamespace = "http://example.com/users/accounts"; + protected URI xsdNamespaceURI = URI.createURI( xsdNamespace ); + + LdapContext comContext = null; + LdapContext exampleContext = null; + LdapContext usersContext = null; + + public void setUp() throws Exception + { + super.setUp(); + } + + public void tearDown() throws Exception + { + super.tearDown(); + } + + public void testCreateSystemSubContext() throws NamingException + { + String testContextRDN = "cn=newContext"; + + Object testContext = null; + + try { + testContext = dasPartitionContext.lookup( testContextRDN ); + } + catch (Exception e) + { + //good + } + + assertNull(testContext); + + InitialContextCreatorHelper.createSubContext( + dasPartitionContext, + testContextRDN, + null); + + testContext = dasPartitionContext.lookup( testContextRDN ); + + assertNotNull(testContext); + dasPartitionContext.destroySubcontext( testContextRDN ); + } + + public void testCreateExistingSystemSubContext() throws NamingException + { + String testContextRDN = "cn=newContext"; + Object testContext = null; + + try { + testContext = dasPartitionContext.lookup( testContextRDN ); + } + catch (Exception e) + { + //good + } + + assertNull(testContext); + + InitialContextCreatorHelper.createSubContext( + dasPartitionContext, + testContextRDN, + null); + + //Run the same code again. + InitialContextCreatorHelper.createSubContext( + dasPartitionContext, + testContextRDN, + null); + + testContext = dasPartitionContext.lookup( testContextRDN ); + + assertNotNull(testContext); + dasPartitionContext.destroySubcontext( testContextRDN ); + } + + + public void testCreateAuthorityContext() + throws NamingException + { + try + { + comContext = + ( LdapContext ) + dasPartitionContext.lookup("cn=com"); + } + catch ( NamingException e ) + { + //Good - the subcontext does not exist + } + assertTrue(comContext==null); + + String[] authorityTokens = + XSDNamespaceURITokenizer.createAuthorityTokens(xsdNamespaceURI); + + InitialContextCreatorHelper.createAuthorityContext( + dasPartitionContext, + authorityTokens ); + + comContext = + ( LdapContext ) dasPartitionContext.lookup("cn=com"); + + assertNotNull(comContext); + + exampleContext = + ( LdapContext ) comContext.lookup("cn=example"); + + assertNotNull(exampleContext); + + comContext.destroySubcontext( "cn=example" ); + dasPartitionContext.destroySubcontext( "cn=com" ); + } + + public void testCreatePathContext() throws NamingException + { + String[] authorityTokens = + XSDNamespaceURITokenizer. + createAuthorityTokens(xsdNamespaceURI); + + exampleContext = + InitialContextCreatorHelper. + createAuthorityContext( + dasPartitionContext, + authorityTokens ); + + String[] pathTokens = + XSDNamespaceURITokenizer. + createPathTokens(xsdNamespaceURI); + + InitialContextCreatorHelper. + createPathContext( + exampleContext, + pathTokens ); + + comContext = + ( LdapContext ) + dasPartitionContext. + lookup("cn=com"); + + exampleContext = + ( LdapContext ) + comContext. + lookup("cn=example"); + + usersContext = ( LdapContext ) exampleContext.lookup("cn=users"); + + usersContext.destroySubcontext( "cn=accounts" ); + exampleContext.destroySubcontext( "cn=users" ); + comContext.destroySubcontext( "cn=example" ); + dasPartitionContext.destroySubcontext( "cn=com" ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorTest.java new file mode 100644 index 0000000000..75834a7502 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +public class InitialContextCreatorTest +extends AbstractTestSetup +{ + public void testCreate() throws NamingException + { + LdapContext comContext = null; + LdapContext exampleContext = null; + LdapContext usersContext = null; + LdapContext accountsContext = null; + LdapContext rootContext = null; + + rootContext = + InitialContextCreator.create( + xsdNamespace, + dasPartitionContext ); + + assertEquals( + rootContext.getNameInNamespace(), + "cn=accounts,cn=users,cn=example,cn=com,ou=das"); + + comContext = + ( LdapContext ) + dasPartitionContext.lookup( "cn=com" ); + exampleContext = ( LdapContext )comContext.lookup( "cn=example" ); + usersContext = ( LdapContext ) exampleContext.lookup( "cn=users" ); + accountsContext = ( LdapContext ) usersContext.lookup( "cn=accounts" ); + accountsContext = ( LdapContext ) usersContext.lookup( "cn=accounts" ); + + assertNotNull(comContext); + assertNotNull(exampleContext); + assertNotNull(usersContext); + assertNotNull(accountsContext); + + usersContext. + destroySubcontext( "cn=accounts" ); + + exampleContext. + destroySubcontext( "cn=users" ); + + comContext. + destroySubcontext( "cn=example" ); + + dasPartitionContext. + destroySubcontext( "cn=com" ); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/MetaContextCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/MetaContextCreatorTest.java new file mode 100644 index 0000000000..904ef2f2c6 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/MetaContextCreatorTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create.test; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.create.InitialContextCreator; +import org.apache.tuscany.das.ldap.create.MetaContextCreator; +import org.apache.tuscany.das.ldap.destroy.InitialContextDestroyer; +import org.apache.tuscany.das.ldap.destroy.MetaContextDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +public class MetaContextCreatorTest +extends AbstractTestSetup +{ + private LdapContext modelContext = null; + private LdapContext metaContext = null; + + public void tearDown() + throws NamingException + { + MetaContextDestroyer.destroy( modelContext ); + + InitialContextDestroyer.destroy( + modelContext, + dasPartitionContext ); + } + + public void setUp() throws Exception + { + super.setUp(); + modelContext = + InitialContextCreator. + create( + xsdNamespace, + dasPartitionContext); + + metaContext = + MetaContextCreator. + create(modelContext ); + } + + public void testCreate() throws NamingException + { + assertTrue(true); + + assertEquals( + "cn=meta,cn=accounts,cn=users,cn=example,cn=com,ou=das", + metaContext.getNameInNamespace() ); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/UniqueOIDCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/UniqueOIDCreatorHelperTest.java new file mode 100644 index 0000000000..6e9ba56779 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/UniqueOIDCreatorHelperTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.create.test; + +import org.apache.tuscany.das.ldap.oid.create.OIDCreatorHelper; + +import junit.framework.TestCase; + +public class UniqueOIDCreatorHelperTest +extends TestCase +{ + public void testCalculateSegmentedOID() throws Exception + { + String input1 = "56102578"; + String input2 = "5610257834"; + + String result = + "will not pass if exception not caught"; + try { + result = + OIDCreatorHelper. + calculateSegmentedOID( input1 ); + } + catch (Exception e) + { + result = "passed"; + } + assertEquals(result, "passed"); + + result = + OIDCreatorHelper. + calculateSegmentedOID( input2 ); + + assertEquals(result, "56102578.4"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/destroy/test/InitialContextDestroyerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/destroy/test/InitialContextDestroyerTest.java new file mode 100644 index 0000000000..5ce43587df --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/destroy/test/InitialContextDestroyerTest.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.destroy.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.destroy.InitialContextDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +public class InitialContextDestroyerTest extends AbstractTestSetup +{ + DirContext test1Context = null; + DirContext test2Context = null; + DirContext test3Context = null; + + /* + * Tests that the initial context destroyer + * destroys child projects before parent projects. + */ + public void testDestroy() throws NamingException + { + test1Context = + ( DirContext ) + dasPartitionContext. + createSubcontext( "cn=test1" ); + + test2Context = + ( DirContext ) + test1Context. + createSubcontext( "cn=test2" ); + + test3Context = + ( DirContext ) + test2Context. + createSubcontext( "cn=test3" ); + + Object test = null; + test = + dasPartitionContext. + lookup( "cn=test1" ); + + assertNotNull(test); + + InitialContextDestroyer. + destroy( + test3Context, + dasPartitionContext); + + try + { + test = dasPartitionContext.lookup( "cn=test1" ); + } + catch (Exception e) + { + test = "caught"; + } + + assertSame("caught", test); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataGraphCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataGraphCreatorTest.java new file mode 100644 index 0000000000..2f2b8a24de --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataGraphCreatorTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.prototype.setup.test.EDataGraphSetupTest; + + +public class EDataGraphCreatorTest +extends EDataGraphSetupTest +{ + public void testCreate() throws NamingException + { + assertEquals( + "example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + userContainerContext.getNameInNamespace()); + + Attributes userEntryAttributes = + userContainerContext.getAttributes(""); + + assertEquals( + userEntryAttributes.get( + "example-com-users-accounts-User-userPassword").get(), + "secret"); + + assertEquals( + userEntryAttributes.get( + "example-com-users-accounts-User-authorizationList").get(0), "2"); + + assertEquals( + userEntryAttributes.get( + "example-com-users-accounts-User-authorizationList").get(1), "3"); + + assertEquals( + userEntryAttributes.get("example-com-users-accounts-User-userName").get(), + "ole"); + + assertEquals( + "cn=authorizationList,example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + authorizationContainerContext.getNameInNamespace()); + + LdapContext authorizationEntry1Context = + (LdapContext) + rootContext. + lookup(authorizationDataObject1RDN); + + assertEquals( + "example-com-users-accounts-Authorization-id=2,cn=authorizationList,example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + authorizationEntry1Context.getNameInNamespace()); + + Attributes authorizationEntry1Attributes = + rootContext. + getAttributes(authorizationDataObject1RDN); + + assertEquals( + authorizationEntry1Attributes.get("example-com-users-accounts-Authorization-fileName").get(), + "somefile.text"); + + assertEquals( + authorizationEntry1Attributes.get("example-com-users-accounts-Authorization-writeAuthorization").get(), + "TRUE"); + + + LdapContext authorizationEntry2Context = + (LdapContext) + rootContext. + lookup(authorizationDataObject2RDN); + + assertEquals( + "example-com-users-accounts-Authorization-id=3,cn=authorizationList,example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + authorizationEntry2Context.getNameInNamespace()); + + + Attributes authorizationEntry2Attributes = + rootContext. + getAttributes(authorizationDataObject2RDN); + + assertEquals( + authorizationEntry2Attributes.get("example-com-users-accounts-Authorization-fileName").get(), + "someOtherfile.text"); + + assertEquals( + "cn=configuration,example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + configurationContainerContext.getNameInNamespace()); + + String configurationEntryRDN = + "example-com-users-accounts-Configuration-id=5"; + + LdapContext configurationEntryContext = + (LdapContext) + configurationContainerContext. + lookup(configurationEntryRDN); + + assertEquals( + "example-com-users-accounts-Configuration-id=5,cn=configuration,example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + configurationEntryContext.getNameInNamespace()); + + Attributes configurationEntryAttributes = + configurationContainerContext. + getAttributes(configurationEntryRDN); + + assertEquals( + configurationEntryAttributes.get("example-com-users-accounts-Configuration-authorization").get(), + "2"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataObjectCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataObjectCreatorTest.java new file mode 100644 index 0000000000..c3b6fc5475 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataObjectCreatorTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.prototype.setup.test.EDataObjectSetupTest; + +public class EDataObjectCreatorTest +extends EDataObjectSetupTest +{ + protected String eDataObjectRDN = null; + protected LdapContext namedContainerContext = null; + + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + } + + public void testCreate() throws NamingException + { + assertEquals( + "example-com-users-accounts-User-id=1,cn=accounts,cn=users,cn=example,cn=com,ou=das", + userContainerContext.getNameInNamespace()); + + Attributes attributes = + userContainerContext.getAttributes(""); + + assertEquals( + attributes.get("example-com-users-accounts-User-userPassword").get(), + "secret"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userName").get(), + "ole"); + assertEquals( + attributes.get("example-com-users-accounts-User-userPassword").get(), + "secret"); + assertEquals( + attributes.get("example-com-users-accounts-User-userAge").get(), + "33"); + assertEquals( + attributes.get("example-com-users-accounts-User-userHeight").get(), + "6.11"); + + assertEquals( + attributes.get("example-com-users-accounts-User-authorizationList").size(), + 2); + + Attribute aliasesAttribute = attributes.get("example-com-users-accounts-User-userAliases"); + + assertEquals( + aliasesAttribute.size(), + 3); + + assertEquals(aliasesAttribute.get(0), "neo"); + assertEquals(aliasesAttribute.get(1), "trinity"); + assertEquals(aliasesAttribute.get(2), "morpheus"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataGraphReaderTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataGraphReaderTest.java new file mode 100644 index 0000000000..ea609544cf --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataGraphReaderTest.java @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read.test; + +import java.util.Hashtable; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader; +import org.apache.tuscany.das.ldap.prototype.setup.test.EDataGraphSetupTest; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphReaderTest +extends EDataGraphSetupTest +{ + public void testRead() throws NamingException + { + dataObjectToRelativeDNCache = + new Hashtable(); + + eDataGraph = + EDataGraphReader.read( + userEClass, + "1", + rootContext, + dataObjectToRelativeDNCache); + + EDataObject retrievedUserDataObject = + (EDataObject) eDataGraph.getRootObject(); + + assertEquals( + dataObjectToRelativeDNCache. + get(retrievedUserDataObject).toString(), + "example-com-users-accounts-User-id=1"); + + assertEquals(retrievedUserDataObject.eGet(userNameEAttribute), "ole"); + assertEquals(retrievedUserDataObject.eGet(userPasswordEAttribute), "secret"); + assertEquals(retrievedUserDataObject.eGet(userAgeEAttribute), 33); + assertEquals(retrievedUserDataObject.eGet(userHeightEAttribute), 6.11); + assertEquals(retrievedUserDataObject.eGet(userIsMaleEAttribute), true); + + EList retrievedAuthorizationContainmentList = + (EList) + retrievedUserDataObject. + eGet(userAuthorizationEReference); + + assertEquals(retrievedAuthorizationContainmentList.size(), 2); + + EDataObject retrievedAuthorizationEDataObject1 = + retrievedAuthorizationContainmentList.get(0); + + assertEquals( + dataObjectToRelativeDNCache. + get(retrievedAuthorizationEDataObject1).toString(), + "example-com-users-accounts-Authorization-id=2,cn=authorizationList,example-com-users-accounts-User-id=1"); + + assertEquals( + retrievedAuthorizationEDataObject1. + eGet(authorizationIDEAttribute), "2"); + assertEquals( + retrievedAuthorizationEDataObject1. + eGet(authorizationFileEAttribute), "somefile.text"); + assertEquals( + retrievedAuthorizationEDataObject1. + eGet(authorizationWriteEAttribute), true); + assertEquals( + retrievedAuthorizationEDataObject1. + eGet(authorizationReadEAttribute), true); + assertEquals( + retrievedAuthorizationEDataObject1. + eGet(authorizationExecuteEAttribute), true); + + EDataObject retrievedAuthorizationEDataObject2 = + retrievedAuthorizationContainmentList.get(1); + + assertEquals( + dataObjectToRelativeDNCache. + get(retrievedAuthorizationEDataObject2).toString(), + "example-com-users-accounts-Authorization-id=3,cn=authorizationList,example-com-users-accounts-User-id=1"); + + assertEquals( + retrievedAuthorizationEDataObject2. + eGet(authorizationIDEAttribute), "3"); + + EDataObject retrievedConfigurationEDataObject = + (EDataObject) retrievedUserDataObject. + eGet(userConfigurationEReference); + + assertEquals( + dataObjectToRelativeDNCache. + get(retrievedConfigurationEDataObject).toString(), + "example-com-users-accounts-Configuration-id=5,cn=configuration,example-com-users-accounts-User-id=1"); + + assertEquals( + "5", + retrievedConfigurationEDataObject. + eGet(configurationIDEAttribute)); + + EDataObject referencedAuthorizationDataObject = + (EDataObject) retrievedConfigurationEDataObject. + eGet(configurationAuthorizationEReference); + + assertSame( + retrievedAuthorizationEDataObject1, + referencedAuthorizationDataObject); + + EList referenceAuthorizationsList = + (EList) retrievedConfigurationEDataObject. + eGet(configurationAuthorizationsEReference); + + assertEquals(2, referenceAuthorizationsList.size() ); + } + + public void testReadException() + { + dataObjectToRelativeDNCache = + new Hashtable(); + + try + { + eDataGraph = + EDataGraphReader.read( + userEClass, + "1", + metaContext, + dataObjectToRelativeDNCache); + } + catch ( NamingException e ) + { + readException = true; + } + + assertTrue(readException); + } + + + +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataObjectReaderTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataObjectReaderTest.java new file mode 100644 index 0000000000..9617599acb --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataObjectReaderTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.read.test; + +import javax.naming.NamingException; + +import org.apache.tuscany.das.ldap.emf.read.EDataObjectReader; +import org.apache.tuscany.das.ldap.prototype.setup.test.EDataObjectSetupTest; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataObjectReaderTest +extends EDataObjectSetupTest +{ + public void tearDown() throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() throws Exception + { + super.setUp(); + } + + public void testRead() throws NamingException + { + EDataObject eDataObject = + EDataObjectReader.read( + userEClass, + "1", + rootContext); + + assertEquals(eDataObject.eGet(userNameEAttribute), "ole"); + assertEquals(eDataObject.eGet(userPasswordEAttribute), "secret"); + assertEquals(eDataObject.eGet(userAgeEAttribute), 33); + assertEquals(eDataObject.eGet(userHeightEAttribute), 6.11); + assertEquals(eDataObject.eGet(userIsMaleEAttribute), true); + + EList userAliases = ( EList ) eDataObject.eGet(userAliasesEAttribute); + assertEquals(userAliases.size(), 3); + assertEquals(userAliases.get(0), "neo"); + assertEquals(userAliases.get(1), "trinity"); + assertEquals(userAliases.get(2), "morpheus"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASHelperTest.java new file mode 100644 index 0000000000..ef8a197f7c --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASHelperTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.test; + +import java.io.File; +import java.util.Hashtable; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.apache.tuscany.das.ldap.connect.ADSEmbeddedConnection; +import org.apache.tuscany.das.ldap.emf.Context; +import org.apache.tuscany.das.ldap.emf.LdapDAS; +import org.apache.tuscany.das.ldap.emf.LdapDASHelper; +import org.apache.tuscany.model.Configuration; +import org.apache.tuscany.model.ConfigurationFactory; +import org.apache.tuscany.model.DASMeta; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class LdapDASHelperTest extends TestCase +{ + + private LdapContext schemaContext = null; + private ADSEmbeddedConnection adsEmbeddedConnection; + Configuration configuration = null; + + public void tearDown() throws NamingException, Exception + { + adsEmbeddedConnection.shutdown(); + } + + public void setUp() throws Exception + { + /* + * Note that I had to move the schemaContext + * creation inside each test method due to a + * bug in ADS. + */ + FileUtils.deleteDirectory(new File("server-work")); + + configuration = + ConfigurationFactory. + INSTANCE. + createConfiguration(); + + adsEmbeddedConnection = + new ADSEmbeddedConnection( + configuration); + } + + + public void testReadDasMeta() throws Exception + { + Configuration configuration = + ConfigurationFactory. + INSTANCE. + createConfiguration(); + + configuration.setEmbedded( true ); + + LdapDAS ldapDAS = new LdapDAS(configuration); + + Context context = ldapDAS.getContext(); + + + Map metaDataObjectToRelativeDNCache = + new Hashtable(); + + EDataGraph dasMetaDataGraph = + LdapDASHelper.readDasMeta( + context, + metaDataObjectToRelativeDNCache ); + + assertEquals( + "org-apache-tuscany-das-ldap-configuration-model-ecore-v100-DASMeta-id=0", + metaDataObjectToRelativeDNCache.values().toArray()[0]); + + DASMeta dasMeta = ( DASMeta ) dasMetaDataGraph.getRootObject(); + + assertEquals( + dasMeta, + metaDataObjectToRelativeDNCache.keySet().toArray()[0] ); + + assertEquals( + "org-apache-tuscany-das-ldap-configuration-model-ecore-v100-DASMeta-id=0", + metaDataObjectToRelativeDNCache.get(dasMeta)); + } + + public void testCreateEcoreContext() throws NamingException + { + schemaContext = + adsEmbeddedConnection. + connect( + configuration.getSchemaPartitionName() ); + + LdapContext ecoreContext = + LdapDASHelper.createEcoreContext( + schemaContext); + + assertEquals( + ecoreContext.getNameInNamespace(), + "cn=ecore,ou=schema" ); + + schemaContext.destroySubcontext( "cn=ecore" ); + } + + public void testCreateEcoreObjectClassesContext() throws NamingException + { + schemaContext = + adsEmbeddedConnection. + connect( + configuration.getSchemaPartitionName() ); + + LdapContext ecoreContext = + LdapDASHelper.createEcoreContext( + schemaContext); + + LdapContext ecoreObjectClassesContext = + LdapDASHelper. + createEcoreObjectClassesContext( + schemaContext ); + + ecoreObjectClassesContext = + LdapDASHelper. + createEcoreObjectClassesContext( + schemaContext ); + + assertEquals( + ecoreObjectClassesContext.getNameInNamespace(), + "ou=objectClasses,cn=ecore,ou=schema"); + + + ecoreContext.destroySubcontext( "ou=objectClasses" ); + schemaContext.destroySubcontext( "cn=ecore" ); + } + + public void testCreateEcoreAttributeTypesContext() throws NamingException + { + schemaContext = + adsEmbeddedConnection. + connect( + configuration.getSchemaPartitionName() ); + + LdapContext ecoreContext = + LdapDASHelper.createEcoreContext( + schemaContext); + + LdapContext ecoreAttributeTypesContext = + LdapDASHelper. + createEcoreAttributeTypesContext( schemaContext ); + + ecoreAttributeTypesContext = + LdapDASHelper. + createEcoreAttributeTypesContext( schemaContext ); + + assertEquals( + ecoreAttributeTypesContext.getNameInNamespace(), + "ou=attributeTypes,cn=ecore,ou=schema"); + + ecoreContext.destroySubcontext( "ou=attributeTypes" ); + schemaContext.destroySubcontext( "cn=ecore" ); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASTest.java new file mode 100644 index 0000000000..feeed1e253 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASTest.java @@ -0,0 +1,437 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.test; + +import java.util.Map; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.emf.Context; +import org.apache.tuscany.das.ldap.emf.LdapDAS; +import org.apache.tuscany.das.ldap.prototype.setup.test.LdapDASSetupTest; +import org.apache.tuscany.model.Configuration; +import org.apache.tuscany.model.ConfigurationFactory; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.sdo.EChangeSummary; +import org.eclipse.emf.ecore.sdo.EDataGraph; +import org.eclipse.emf.ecore.sdo.EDataObject; + + +public class LdapDASTest extends LdapDASSetupTest +{ + Configuration configuration = null; + LdapDAS ldapDAS = null; + + public void setUp() throws Exception + { + super.setUp(); + configuration = + ConfigurationFactory. + INSTANCE. + createConfiguration(); + + configuration.setEmbedded( true ); + ldapDAS = new LdapDAS(configuration); + } + + public void tearDown() throws NamingException, Exception + { + ldapDAS.getAdsEmbeddedConnection().shutdown(); + super.tearDown(); + } + + public void testConstructor() throws NamingException + { + Context context = ldapDAS.getContext(); + assertEquals( + "ou=das", + context.getDasContext().getNameInNamespace()); + assertEquals( + "cn=meta,ou=das", + context.getDasMetaContext().getNameInNamespace()); + assertEquals( + "ou=attributeTypes,cn=ecore,ou=schema", + context.getEcoreAttributeTypesContext().getNameInNamespace()); + assertEquals( + "ou=objectClasses,cn=ecore,ou=schema", + context.getEcoreObjectClassesContext().getNameInNamespace()); + } + + public void testCreate() throws Exception, NamingException + { + ldapDAS.create( eDataGraph ); + + Context context = + ldapDAS.getContext(); + + dataObjectToRelativeDNCache = + context.getDataObjectToRelativeDNCache(); + + Map xsdNamespaceToLdapContextMap = + context. + getXsdNamespaceToLdapContextMap(); + + EDataObject rootObject = + ( EDataObject ) + eDataGraph.getRootObject(); + + String namespace = + rootObject. + eClass(). + getEPackage(). + getNsURI(); + + assertEquals( + "http://example.com/users/accounts", + namespace); + + LdapContext rootContext = + xsdNamespaceToLdapContextMap. + get( namespace ); + + assertEquals( + "cn=accounts,cn=users,cn=example,cn=com,ou=das", + rootContext.getNameInNamespace() ); + + String userDataObjectRDN = + dataObjectToRelativeDNCache.get( rootObject ); + + //============================================================ + //Verify the RDN + //============================================================ + + assertEquals( + "example-com-users-accounts-User-id=1", + userDataObjectRDN ); + + //============================================================ + //Verify the attribute values + //============================================================ + + Attributes attributes = + rootContext. + getAttributes( userDataObjectRDN ); + + assertEquals( + attributes.get("objectClass").get(), + "example-com-users-accounts-User"); + + assertEquals( + attributes.get("objectClass").get(1), + "metaObjectClass"); + + assertEquals( + attributes.get("objectClass").get(2), + "metaTop"); + + assertEquals( + attributes.get("objectClass").get(3), + "top"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userAge").get(), + "33"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userName").get(), + "ole"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userPassword").get(), + "secret"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userHeight").get(), + "6.11"); + + assertEquals( + attributes.get("example-com-users-accounts-User-id").get(), + "1"); + + assertEquals( + attributes.get("example-com-users-accounts-User-isMale").get(), + "TRUE"); + + + assertEquals( + attributes.get("example-com-users-accounts-User-userAliases").get(), + "neo"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userAliases").get(1), + "trinity"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userAliases").get(2), + "morpheus"); + + assertEquals( + attributes.get("example-com-users-accounts-User-configuration").get(), + "5"); + + assertEquals( + attributes.get("example-com-users-accounts-User-authorizationList").get(), + "2"); + + assertEquals( + attributes.get("example-com-users-accounts-User-authorizationList").get(1), + "3"); + + + EDataObject configurationObject = + ( EDataObject ) rootObject. + eGet( userConfigurationEReference ); + + String userConfigurationDataObjectRDN = + dataObjectToRelativeDNCache. + get( configurationObject ); + + //============================================================ + //Verify the RDN + //============================================================ + + assertEquals( + "example-com-users-accounts-Configuration-id=5,cn=configuration,example-com-users-accounts-User-id=1", + userConfigurationDataObjectRDN); + + attributes = rootContext.getAttributes( userConfigurationDataObjectRDN ); + + //============================================================ + //Verify the Attributes + //============================================================ + + assertEquals( + attributes.get("objectClass").get(), + "example-com-users-accounts-Configuration"); + + assertEquals( + attributes.get("objectClass").get(1), + "metaObjectClass"); + + assertEquals( + attributes.get("objectClass").get(2), + "metaTop"); + + assertEquals( + attributes.get("objectClass").get(3), + "top"); + + assertEquals( + attributes.get("example-com-users-accounts-Configuration-authorization").get(), + "2"); + + assertEquals( + attributes.get("example-com-users-accounts-Configuration-id").get(), + "5"); + + assertEquals( + attributes.get("example-com-users-accounts-Configuration-authorizations").get(), + "2"); + + assertEquals( + attributes.get("example-com-users-accounts-Configuration-authorizations").get(1), + "3"); + + EList authorizationList = + ( EList ) rootObject. + eGet( userAuthorizationEReference ); + + EDataObject authorizationDataObject1 = + authorizationList.get( 0 ); + + String userAuthorizationDataObject1RDN = + dataObjectToRelativeDNCache. + get( authorizationDataObject1 ); + + //============================================================ + //Verify the RDN + //============================================================ + + assertEquals( + "example-com-users-accounts-Authorization-id=2,cn=authorizationList,example-com-users-accounts-User-id=1", + userAuthorizationDataObject1RDN); + + attributes = rootContext.getAttributes( userAuthorizationDataObject1RDN ); + + //============================================================ + //Verify the Attributes + //============================================================ + + assertEquals( + attributes.get("objectClass").get(), + "example-com-users-accounts-Authorization"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-id").get(), + "2"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-executeAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-readAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-writeAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-fileName").get(), + "somefile.text"); + + + EDataObject authorizationDataObject2 = + authorizationList.get( 1 ); + + String userAuthorizationDataObject2RDN = + dataObjectToRelativeDNCache. + get( authorizationDataObject2 ); + + //============================================================ + //Verify the RDN + //============================================================ + + assertEquals( + "example-com-users-accounts-Authorization-id=3,cn=authorizationList,example-com-users-accounts-User-id=1", + userAuthorizationDataObject2RDN); + + attributes = rootContext.getAttributes( userAuthorizationDataObject2RDN ); + + //============================================================ + //Verify the Attributes + //============================================================ + + assertEquals( + attributes.get("objectClass").get(), + "example-com-users-accounts-Authorization"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-id").get(), + "3"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-executeAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-readAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-writeAuthorization").get(), + "TRUE"); + + assertEquals( + attributes.get("example-com-users-accounts-Authorization-fileName").get(), + "someOtherfile.text"); + + + /* Finding out the values of the attributes + NamingEnumeration namingEnumeration = attributes.getAll(); + while (namingEnumeration.hasMore()) + { + Attribute attribute = ( Attribute ) namingEnumeration.next(); + System.out.println(attribute); + } + */ + } + + public void testRead() throws NamingException, Exception + { + /* + * More exhaustive testing has been done on the + * class that LdapDAS.read() delegates to. + */ + ldapDAS.create( eDataGraph ); + + EDataGraph newEDataGraph = + ldapDAS.read( userEClass, "1" ); + + EDataObject rootObject = + ( EDataObject ) newEDataGraph.getRootObject(); + + assertEquals( + rootObject.eGet( userNameEAttribute), + "ole"); + + EDataObject configurationObject = + ( EDataObject ) + rootObject.eGet( userConfigurationEReference ); + + assertEquals( + configurationObject.eGet( configurationIDEAttribute), + "5"); + + } + + public void testUpdate() throws NamingException, Exception + { + /* + * More exhaustive testing has been done on the + * class that LdapDAS.update() delegates to. + */ + ldapDAS.create( eDataGraph ); + + EDataGraph newEDataGraph = ldapDAS.read( userEClass, "1" ); + + + //newEDataGraph.getChangeSummary().beginLogging(); + EChangeSummary eChangeSummary = ( EChangeSummary ) newEDataGraph.getChangeSummary(); + eChangeSummary.beginLogging(); + + EDataObject rootObject = + ( EDataObject ) newEDataGraph.getRootObject(); + + rootObject.eSet( userNameEAttribute, "Brooke" ); + rootObject.eSet( userAgeEAttribute, 5 ); + + //newEDataGraph.getChangeSummary().endLogging(); + + eChangeSummary.endLogging(); + ldapDAS.update( newEDataGraph ); + + LdapContext rootContext = ldapDAS.getContext(). + getXsdNamespaceToLdapContextMap(). + get( + rootObject. + eClass(). + getEPackage(). + getNsURI()); + + Attributes attributes = + rootContext. + getAttributes( + "example-com-users-accounts-User-id=1" ); + + assertEquals( + attributes.get("example-com-users-accounts-User-userAge").get(), + "5"); + + assertEquals( + attributes.get("example-com-users-accounts-User-userName").get(), + "Brooke"); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/update/test/EDataGraphUpdateTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/update/test/EDataGraphUpdateTest.java new file mode 100644 index 0000000000..d76ccccac0 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/update/test/EDataGraphUpdateTest.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.emf.update.test; + +import java.util.Hashtable; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; + +import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader; +import org.apache.tuscany.das.ldap.emf.update.EDataGraphUpdater; +import org.apache.tuscany.das.ldap.prototype.setup.test.EDataGraphSetupTest; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.sdo.EChangeSummary; +import org.eclipse.emf.ecore.sdo.EDataObject; + +public class EDataGraphUpdateTest +extends EDataGraphSetupTest +{ + public void testUpdate() throws NamingException + { + dataObjectToRelativeDNCache = + new Hashtable(); + + eDataGraph = + EDataGraphReader.read( + userEClass, + "1", + rootContext, + dataObjectToRelativeDNCache); + + assertTrue( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject1RDN)); + assertTrue( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject2RDN)); + + userDataObject = + (EDataObject) eDataGraph.getRootObject(); + + String userEntryRDN = dataObjectToRelativeDNCache.get(userDataObject); + Attributes attributes = rootContext.getAttributes(userEntryRDN); + + assertEquals(userDataObject.eGet(userNameEAttribute), "ole"); + assertEquals(userDataObject.eGet(userPasswordEAttribute), "secret"); + assertEquals(userDataObject.eGet(userAgeEAttribute), 33); + assertEquals(userDataObject.eGet(userHeightEAttribute), 6.11); + assertEquals(userDataObject.eGet(userIsMaleEAttribute), true); + assertEquals("2", attributes.get("example-com-users-accounts-User-authorizationList").get(0)); + assertEquals("3", attributes.get("example-com-users-accounts-User-authorizationList").get(1)); + + EChangeSummary eChangeSummary = + (EChangeSummary) eDataGraph.getChangeSummary(); + + eChangeSummary.beginLogging(); + + userDataObject.eSet(userIsMaleEAttribute, false); + userDataObject.eSet(userHeightEAttribute, 2.00); + userDataObject.eSet(userAgeEAttribute, 80); + userDataObject.eSet(userPasswordEAttribute, "totallysecret"); + + EList userAuthorizationReferenceList = + (EList)userDataObject + .eGet(userAuthorizationEReference); + + userAuthorizationReferenceList.remove(0); + + assertEquals(userDataObject.eGet(userIsMaleEAttribute), false); + assertEquals(userDataObject.eGet(userHeightEAttribute), 2.00); + assertEquals(userDataObject.eGet(userAgeEAttribute), 80); + assertEquals(userDataObject.eGet(userPasswordEAttribute), "totallysecret"); + + eChangeSummary.endLogging(); + + EDataGraphUpdater.update( + eDataGraph, + rootContext, + dataObjectToRelativeDNCache); + + attributes = rootContext.getAttributes(userEntryRDN); + + assertEquals("FALSE", attributes.get("example-com-users-accounts-User-isMale").get()); + assertEquals("2.0", attributes.get("example-com-users-accounts-User-userHeight").get()); + assertEquals("80", attributes.get("example-com-users-accounts-User-userAge").get()); + assertEquals("totallysecret", attributes.get("example-com-users-accounts-User-userPassword").get()); + assertEquals("5", attributes.get("example-com-users-accounts-User-configuration").get()); + + /* + * Test that the ID of the Authorization instance with id 2 was removed + */ + assertEquals( + "3", + attributes. + get("example-com-users-accounts-User-authorizationList"). + get(0)); + + /* + * Also make sure that the dataObjectToRelativeDNCache was updated + */ + assertFalse( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject1RDN)); + + eChangeSummary.beginLogging(); + + userDataObject.eUnset(userConfigurationEReference); + userAuthorizationReferenceList.remove(0); + + eChangeSummary.endLogging(); + + EDataGraphUpdater.update( + eDataGraph, + rootContext, + dataObjectToRelativeDNCache); + + attributes = rootContext.getAttributes(userEntryRDN); + + boolean isConfigurationAttributeDeleted = false; + + try { + attributes.get("example-com-users-accounts-User-configuration").get(); + } + catch (Exception e) + { + isConfigurationAttributeDeleted = true; + } + assertTrue(isConfigurationAttributeDeleted); + + boolean isAuthorizationlListAttributeDeleted = false; + + try { + attributes.get("example-com-users-accounts-User-authorizationList").get(); + } + catch (Exception e) + { + isAuthorizationlListAttributeDeleted = true; + } + assertTrue(isAuthorizationlListAttributeDeleted); + assertFalse( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject2RDN)); + + eChangeSummary.beginLogging(); + + userAuthorizationReferenceList.add(authorizationDataObject0); + userAuthorizationReferenceList.add(authorizationDataObject1); + + eChangeSummary.endLogging(); + + EDataGraphUpdater.update( + eDataGraph, + rootContext, + dataObjectToRelativeDNCache); + + assertTrue( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject1RDN)); + assertTrue( + dataObjectToRelativeDNCache. + containsValue(authorizationDataObject2RDN)); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/learning/test/LearningTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/learning/test/LearningTest.java new file mode 100644 index 0000000000..ce603e17f0 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/learning/test/LearningTest.java @@ -0,0 +1,38 @@ +package org.apache.tuscany.das.ldap.learning.test; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.SearchResult; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +public class LearningTest extends AbstractTestSetup { + + public void testSearch() throws NamingException + { + LdapContext contextL0 = + (LdapContext) + dasPartitionContext.createSubcontext("cn=L0"); + + contextL0.createSubcontext("cn=L1"); + + Attributes searchAttributes = + new BasicAttributes(true); + + searchAttributes.put(new BasicAttribute("cn")); + + NamingEnumeration answer = contextL0.search("", searchAttributes); + while (answer.hasMore()) { + + SearchResult result = (SearchResult)answer.next(); + Attributes attributes = result.getAttributes(); + assertEquals("L1", attributes.get("cn").get().toString()); + } + dasPartitionContext.destroySubcontext("cn=L1, cn=L0"); + dasPartitionContext.destroySubcontext("cn=L0"); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java new file mode 100644 index 0000000000..c52a9ede1c --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaContextsSetup; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +public class EAttributeTypeCreatorTest +extends EcoreSchemaContextsSetup +{ + private static final String namespaceURI = + "http://org.apache.tuscany/datatypes"; + + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private static EcorePackage ecorePackage = + EcorePackage.eINSTANCE; + + private static EAttribute eAttribute = + ecoreFactory.createEAttribute(); + + private static String eAttributeName = + "ole"; + + private static DirContext eAttributeEntryContext = + null; + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void tearDown() throws NamingException, Exception + { + EStructuralFeatureTypeDestroyer. + destroy( + ecoreAttributeTypesContext, + eAttribute, + TUSCANY_OID_PREFIX_VALUE); + + super.tearDown(); + } + + public void testCreate() throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(namespaceURI); + + EClass eContainingClass = + ecoreFactory. + createEClass(); + + String eContainingClassName = + eContainingClass.getName(); + + ePackage. + getEClassifiers(). + add( eContainingClass ); + + eContainingClass. + getEStructuralFeatures(). + add(eAttribute); + + eAttribute. + setName(eAttributeName); + + eAttribute. + setEType(ecorePackage.getEString()); + + EAttributeTypeCreator + eAttributeTypeCreator = + new EAttributeTypeCreator(); + + eAttributeTypeCreator. + create( + ecoreAttributeTypesContext, + eAttribute, + TUSCANY_OID_PREFIX_VALUE ); + + String rdn = + SimpleTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + namespaceURI, + eContainingClassName, + eAttributeName); + + eAttributeEntryContext = + ( DirContext ) + ecoreAttributeTypesContext. + lookup( rdn ); + + assertNotNull(eAttributeEntryContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java new file mode 100644 index 0000000000..056658b3c1 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreatorHelper; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.DASContextSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EcoreFactory; + +public class EObjectClassCreatorHelperTest +extends DASContextSetup +{ + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private EClass eClassL0 = + null; + + private EClass eClassL1 = + null; + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + eClassL0 = + ecoreFactory. + createEClass(); + eClassL0.setName( "L0" ); + + eClassL1 = + ecoreFactory. + createEClass(); + eClassL1.setName( "L1" ); + + eClassL1. + getESuperTypes(). + add(eClassL0); + } + + public void testCreateInheritanceMetaData() + throws NamingException + { + EObjectClassCreatorHelper. + createInheritanceMetaData( + metaContext, + eClassL1 ); + + DirContext parentContext = + ( DirContext ) + metaContext. + lookup( "cn=" + eClassL0.getName() ); + + assertNotNull(parentContext); + + DirContext childContext = + ( DirContext ) + parentContext. + lookup( "cn=" + eClassL1.getName() ); + + assertNotNull(childContext); + + parentContext.destroySubcontext( + "cn=" + eClassL1.getName() ); + + metaContext.destroySubcontext( + "cn=" + eClassL0.getName() ); + } + + public void testGetEClassParent() + { + EClass eClassParent = + null; + + eClassParent = + EcoreTypeSystemHelper. + getEClassParent(eClassL1); + + assertSame(eClassL0, eClassParent); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java new file mode 100644 index 0000000000..9ef6f6e086 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +public class EObjectClassCreatorTest +extends EcoreSchemaAndDASContextsSetup +{ + boolean isObjectClassL0Created = false; + boolean isObjectClassL1Created = false; + + public void tearDown() + throws NamingException, Exception + { + if (isObjectClassL1Created) + { + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + TUSCANY_OID_PREFIX_VALUE ); + + metaContext. + destroySubcontext( + "cn="+eClassL0.getName() ); + } + + if (isObjectClassL0Created) + { + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + } + + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + processedEClassifiers = + new ArrayList(); + + eClassL0 = + ecoreFactory.createEClass(); + + eClassL1 = + ecoreFactory.createEClass(); + + eClassL0.setName( "L0" ); + eClassL1.setName( "L1" ); + + isObjectClassL0Created = false; + isObjectClassL1Created = false; + + } + + /* + * Tests that eClassL0 and eClassL1 are both + * created an the corresponding entries exist + * in the meta section of the model. + */ + public void testCreate0() + throws NamingException, Exception + { + eClassL1. + getESuperTypes(). + add(eClassL0); + + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + assertNotNull( + eObjectClassL0EntryContext); + + isObjectClassL0Created = true; + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL1EntryContext); + + isObjectClassL1Created = true; + } + + /* + * Test that eClassL0 is added to the list + * of processed eClassifiers and that the + * corresponding ObjectClass is created. + * + * Also test the employeeNameEAttribute + * and departmentEReferences are added. + */ + public void testCreate1() + throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + + EAttribute employeeNameEAttribute = + ecoreFactory.createEAttribute(); + employeeNameEAttribute.setName( + "employeeName" ); + employeeNameEAttribute.setEType( + ecorePackage.getEString() ); + + eClassL0. + getEStructuralFeatures(). + add(employeeNameEAttribute); + + EReference departmentEReference = + ecoreFactory.createEReference(); + departmentEReference.setName( "department" ); + departmentEReference.setEType( eClassL0 ); + + eClassL0. + getEStructuralFeatures(). + add(departmentEReference); + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + assertTrue(processedEClassifiers.contains( eClassL0 )); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + assertNotNull( + eObjectClassL0EntryContext); + + isObjectClassL0Created = true; + + Attributes attributes = + eObjectClassL0EntryContext.getAttributes( "" ); + + NamingEnumeration namingEnumeration = + attributes.get( M_MAY ).getAll(); + + boolean hasDepartmentValue = + false; + boolean hasEmployeeNameValue = + false; + + String departmentValue = + "example-com-users-accounts-L0-department"; + + String employeeNameValue = + "example-com-users-accounts-L0-employeeName"; + + + while (namingEnumeration.hasMore()) + { + String attributeValue = + namingEnumeration.next().toString(); + if (departmentValue.equals(attributeValue)) + { + hasDepartmentValue = true; + } + if (employeeNameValue.equals(attributeValue)) + { + hasEmployeeNameValue = true; + } + } + assertTrue(hasDepartmentValue); + assertTrue(hasEmployeeNameValue); + } + + /* + * Test that both ObjectClasses are created + * when eClassL1 inherits from eClassL0, + * but eClass0's ObjectClass entry + * is already created. + */ + public void testCreate3() + throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + isObjectClassL0Created = true; + + eClassL1. + getESuperTypes(). + add(eClassL0); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + assertNotNull( + eObjectClassL0EntryContext); + + isObjectClassL0Created = true; + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL1EntryContext); + + isObjectClassL1Created = true; + } + + private static EcoreFactory ecoreFactory = + null; + + private static EcorePackage ecorePackage = + null; + + private static EClass eClassL0 = + null; + + private static EClass eClassL1 = + null; + + + private static List + processedEClassifiers = + null; + + private static LdapContext + eObjectClassL0EntryContext = + null; + + private static LdapContext + eObjectClassL1EntryContext = + null; + + private static LdapContext + eClassL0MetaContext = + null; + + private static LdapContext + eClassL1MetaContext = + null; + } \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java new file mode 100644 index 0000000000..c316231c99 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EReferenceTypeCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; + +public class EReferenceTypeCreatorTest +extends EcoreSchemaContextsSetup +{ + private static final String namespaceURI = + "http://org.apache.tuscany/datatypes"; + + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private static EReference eReference = + ecoreFactory.createEReference(); + + private static String eReferenceName = + "ole"; + + private static DirContext eReferenceEntryContext = + null; + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + } + + public void tearDown() + throws NamingException, Exception + { + EStructuralFeatureTypeDestroyer. + destroy( + ecoreAttributeTypesContext, + eReference, + TUSCANY_OID_PREFIX_VALUE); + + super.tearDown(); + } + + public void testCreate() throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(namespaceURI); + + EClass eContainingClass = + ecoreFactory. + createEClass(); + + String eContainingClassName = + eContainingClass.getName(); + + ePackage. + getEClassifiers(). + add( eContainingClass ); + + eContainingClass. + getEStructuralFeatures(). + add(eReference); + + eReference. + setName(eReferenceName); + + eReference. + setEType(eContainingClass); + + EReferenceTypeCreator + eReferenceTypeCreator = + new EReferenceTypeCreator(); + + eReferenceTypeCreator. + create( + ecoreAttributeTypesContext, + eReference, + TUSCANY_OID_PREFIX_VALUE ); + + String rdn = + SimpleTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + namespaceURI, + eContainingClassName, + eReferenceName); + + eReferenceEntryContext = + ( DirContext ) + ecoreAttributeTypesContext. + lookup( rdn ); + + assertNotNull(eReferenceEntryContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java new file mode 100644 index 0000000000..02ffe54627 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import java.util.Stack; + +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EcoreFactory; + +import junit.framework.TestCase; + +public class EcoreTypeSystemCreatorHelperTest +extends TestCase +{ + EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + public void testLoadParentEClassifierStack() + { + EClass eClassL0 = + ecoreFactory.createEClass(); + + EClass eClassL1 = + ecoreFactory.createEClass(); + + EClass eClassL2 = + ecoreFactory.createEClass(); + + eClassL2.getESuperTypes().add(eClassL1); + + eClassL1.getESuperTypes().add(eClassL0); + + Stack testStack = + EcoreTypeSystemHelper. + loadParentEClassifierStack( + eClassL2, + null); + + assertEquals(testStack.size(), 2); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java new file mode 100644 index 0000000000..9de0d189ba --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java @@ -0,0 +1,397 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.ECascadingObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +/* + * TODO Make sure that we test EAttribute deletion as well. + */ +public class ECascadingObjectClassDestroyerTest +extends EcoreSchemaAndDASContextsSetup +{ + public void tearDown() + throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + processedEClassifiers = + new ArrayList(); + + eClassL0 = + ecoreFactory. + createEClass(); + + eClassL1 = + ecoreFactory. + createEClass(); + + eClassL0.setName( "L0" ); + eClassL1.setName( "L1" ); + + eClassNameToEClassMap = + new HashMap(); + + eClassNameToEClassMap.put( + eClassL0.getName(), + eClassL0 ); + + eClassNameToEClassMap.put( + eClassL1.getName(), + eClassL1 ); + + } + + /* + * Test the deletion of two + * single level hierarchy ObjectClasses + */ + public void testCreate1() + throws NamingException, Exception + { + eClassL1. + getESuperTypes(). + add(eClassL0); + + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL0EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + eObjectClassL1EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL0EntryContext); + + assertNotNull( + eObjectClassL1EntryContext); + + eClassL0MetaContext = + ( DirContext ) + metaContext. + lookup( + "cn=" + eClassL0.getName() ); + + assertNotNull( + eClassL0MetaContext ); + + eClassL1MetaContext = + ( DirContext ) + eClassL0MetaContext. + lookup( + "cn=" + eClassL1.getName() ); + + assertNotNull( + eClassL0MetaContext ); + + assertNotNull( + eClassL1MetaContext ); + + + ECascadingObjectClassDestroyer. + destroy( + eClassNameToEClassMap, + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + + try + { + eObjectClassL0EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + } + catch (Exception e) + { + eObjectClassL0EntryContext = + null; + } + + try + { + eObjectClassL1EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + } + catch (Exception e) + { + eObjectClassL1EntryContext = + null; + } + + assertNull( + eObjectClassL0EntryContext); + + assertNull( + eObjectClassL1EntryContext); + + try + { + eClassL0MetaContext = + ( DirContext ) + metaContext. + lookup( + "cn=" + eClassL0.getName() ); + + } + catch (Exception e) + { + assertNotNull( + eClassL0MetaContext ); + } + } + + + private static EcoreFactory ecoreFactory = + null; + + private static EcorePackage ecorePackage = + null; + + private static EClass eClassL0 = + null; + + private static EClass eClassL1 = + null; + + private static List + processedEClassifiers = + null; + + private static DirContext + eObjectClassL0EntryContext = + null; + + private static DirContext + eObjectClassL1EntryContext = + null; + + private static DirContext + eClassL0MetaContext = + null; + + private static DirContext + eClassL1MetaContext = + null; + + private Map eClassNameToEClassMap = + null; + + /* + * Test the deletion of two + * single level hierarchy ObjectClasses + */ + public void testCreate0() + throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL0EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + eObjectClassL1EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL0EntryContext); + + assertNotNull( + eObjectClassL1EntryContext); + + ECascadingObjectClassDestroyer. + destroy( + eClassNameToEClassMap, + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + + ECascadingObjectClassDestroyer. + destroy( + eClassNameToEClassMap, + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + TUSCANY_OID_PREFIX_VALUE ); + try + { + eObjectClassL0EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + } + catch (Exception e) + { + eObjectClassL0EntryContext = + null; + } + + try + { + eObjectClassL1EntryContext = + ( DirContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + } + catch (Exception e) + { + eObjectClassL1EntryContext = + null; + } + + assertNull( + eObjectClassL0EntryContext); + + assertNull( + eObjectClassL1EntryContext); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java new file mode 100644 index 0000000000..8370eaff52 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java @@ -0,0 +1,457 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy.test; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.prototype.setup.Prototype; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +/* + * TODO Make sure that we test EAttribute deletion as well. + */ +public class EObjectClassDestroyerTest +extends EcoreSchemaAndDASContextsSetup +implements Prototype +{ + public void tearDown() + throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + + processedEClassifiers = + new ArrayList(); + + eClassL0 = + ecoreFactory. + createEClass(); + + eClassL1 = + ecoreFactory. + createEClass(); + + eClassL0.setName( "L0" ); + eClassL1.setName( "L1" ); + } + + /* + * Test the deletion of two + * single level hierarchy ObjectClasses + */ + public void testDestroy0() + throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL0EntryContext); + + assertNotNull( + eObjectClassL1EntryContext); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + TUSCANY_OID_PREFIX_VALUE ); + + try + { + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + } + catch (Exception e) + { + eObjectClassL0EntryContext = + null; + } + + try + { + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + } + catch (Exception e) + { + eObjectClassL1EntryContext = + null; + } + + assertNull( + eObjectClassL0EntryContext); + + assertNull( + eObjectClassL1EntryContext); + } + + /* + * Testt the deletion of two + * ObjectClasses where L1 inherits from + * L0 + */ + + public void testDestroy1() + throws NamingException, Exception + { + eClassL1. + getESuperTypes(). + add(eClassL0); + + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( eClassL0 ); + + ePackage. + getEClassifiers(). + add( eClassL1 ); + + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL0.getName()); + + String rdnL1 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + eClassL1.getName()); + + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + + assertNotNull( + eObjectClassL0EntryContext); + + assertNotNull( + eObjectClassL1EntryContext); + + eClassL0MetaContext = + ( LdapContext ) + metaContext. + lookup( + "cn=" + eClassL0.getName() ); + + assertNotNull( + eClassL0MetaContext ); + + eClassL1MetaContext = + ( LdapContext ) + eClassL0MetaContext. + lookup( + "cn=" + eClassL1.getName() ); + + assertNotNull( + eClassL0MetaContext ); + + assertNotNull( + eClassL1MetaContext ); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + TUSCANY_OID_PREFIX_VALUE ); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + + try + { + eObjectClassL0EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL0 ); + } + catch (Exception e) + { + eObjectClassL0EntryContext = + null; + } + + try + { + eObjectClassL1EntryContext = + ( LdapContext ) + ecoreObjectClassesContext. + lookup( rdnL1 ); + } + catch (Exception e) + { + eObjectClassL1EntryContext = + null; + } + + assertNull( + eObjectClassL0EntryContext); + + assertNull( + eObjectClassL1EntryContext); + + + eClassL0MetaContext = + ( LdapContext ) + metaContext. + lookup( + "cn=" + eClassL0.getName() ); + + assertNotNull( + eClassL0MetaContext ); + + try + { + eClassL1MetaContext = + ( LdapContext ) + eClassL0MetaContext. + lookup( + "cn=" + eClassL1.getName() ); + + } + catch (Exception e) + { + eClassL1MetaContext = + null; + } + + assertNull( + eClassL1MetaContext); + + metaContext. + destroySubcontext( + "cn=" + eClassL0.getName() ); + } + + /* + * Test the deletion of an ObjectClass that has + * has attributes. + */ + public void testDestroy2() throws NamingException, Exception + { + userEClass.getEStructuralFeatures().add(userIDEAttribute); + userEClass.getEStructuralFeatures().add(userNameEAttribute); + userEClass.getEStructuralFeatures().add(userPasswordEAttribute); + userEClass.getEStructuralFeatures().add(userAuthorizationEReference); + + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(xsdNamespace); + + ePackage. + getEClassifiers(). + add( userEClass ); + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator. + create( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + userEClass, + processedEClassifiers, + TUSCANY_OID_PREFIX_VALUE ); + + String rdnL0 = + ComplexTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + xsdNamespace, + userEClass.getName()); + + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + userEClass, + TUSCANY_OID_PREFIX_VALUE ); + } + + private static EcoreFactory ecoreFactory = + null; + + private static EcorePackage ecorePackage = + null; + + private static EClass eClassL0 = + null; + + private static EClass eClassL1 = + null; + + private static List + processedEClassifiers = + null; + + private static LdapContext + eObjectClassL0EntryContext = + null; + + private static LdapContext + eObjectClassL1EntryContext = + null; + + private static LdapContext + eClassL0MetaContext = + null; + + private static LdapContext + eClassL1MetaContext = + null; +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/JNDIUtilTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/JNDIUtilTest.java new file mode 100644 index 0000000000..a962484c8d --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/JNDIUtilTest.java @@ -0,0 +1,109 @@ +package org.apache.tuscany.das.ldap.util.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; +import org.apache.tuscany.das.ldap.util.JNDIUtil; + +/* + * Note that these tests rely on the ADS Partition + * ou=system, which is also the directoryContext + * that the tests start with. + */ +public class JNDIUtilTest +extends AbstractTestSetup +{ + DirContext test1Context = null; + DirContext test2Context = null; + DirContext test3Context = null; + + public void setUp() throws Exception + { + super.setUp(); + test1Context = + ( DirContext ) + dasPartitionContext. + createSubcontext( "cn=test1" ); + + test2Context = + ( DirContext ) + test1Context. + createSubcontext( "cn=test2" ); + + test3Context = + ( DirContext ) + test2Context. + createSubcontext( "cn=test3" ); + } + + public void tearDown() throws Exception + { + test2Context.destroySubcontext( "cn=test3" ); + test1Context.destroySubcontext("cn=test2"); + dasPartitionContext.destroySubcontext("cn=test1"); + super.tearDown(); + } + + public void testCalculateParentRelativeDN() throws NamingException + { + String partitionDN = "ou=das"; + + String testA = + JNDIUtil.calculateParentRelativeDN( + test2Context, partitionDN ); + + String testB = + JNDIUtil.calculateParentRelativeDN( + test3Context, partitionDN ); + + String testC = + JNDIUtil.calculateParentRelativeDN( test1Context, partitionDN ); + + assertTrue(testA.equals( "cn=test1" )); + assertTrue(testB.equals( "cn=test2,cn=test1" )); + assertTrue(testC.equals( "ou=das" )); + + } + + public void testCalculateDNComponents() throws NamingException + { + String[] contextComponents = JNDIUtil.calculateDNComponents( test3Context ); + assertTrue(contextComponents.length==4); + + contextComponents = null; + + contextComponents = JNDIUtil.calculateDNComponents( test3Context.getNameInNamespace() ); + assertTrue(contextComponents.length==4); + } + + public void testGetParentContext() throws NamingException + { + DirContext parentContext = + JNDIUtil. + getParentContext( + test3Context, + dasPartitionContext ); + + assertTrue( + parentContext.getNameInNamespace(). + equals("cn=test2,cn=test1,ou=das")); + + parentContext = + JNDIUtil.getParentContext( + test1Context, + dasPartitionContext ); + + assertTrue( + parentContext.getNameInNamespace(). + equals("ou=das")); + + parentContext = + JNDIUtil. + getParentContext( + dasPartitionContext, + dasPartitionContext ); + + assertTrue(null == parentContext); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/QualifiedNameNormalizerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/QualifiedNameNormalizerTest.java new file mode 100644 index 0000000000..30b37dee91 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/QualifiedNameNormalizerTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.util.test; + +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; + +import junit.framework.TestCase; + +public class QualifiedNameNormalizerTest +extends TestCase +{ + public void testNormalize() + { + String qualifiedName = + "http://example.com/users/accounts/L0"; + + String normalizedName = + QualifiedNameNormalizer. + normalize(qualifiedName); + + assertEquals( + "example-com-users-accounts-L0", + normalizedName); + } +} \ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/XSDNamespaceURITokenizerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/XSDNamespaceURITokenizerTest.java new file mode 100644 index 0000000000..708eae7920 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/XSDNamespaceURITokenizerTest.java @@ -0,0 +1,36 @@ + +package org.apache.tuscany.das.ldap.util.test; + +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.AbstractTestSetup; + +import org.apache.tuscany.das.ldap.util.XSDNamespaceURITokenizer; +import org.eclipse.emf.common.util.URI; + +public class XSDNamespaceURITokenizerTest +extends AbstractTestSetup +{ + public void testCreateAuthorityTokens() + { + String[] authorityTokens = + XSDNamespaceURITokenizer. + createAuthorityTokens( + URI.createURI(xsdNamespace)); + + assertTrue(authorityTokens[0].equals( "example")); + assertTrue(authorityTokens[1].equals( "com")); + assertTrue(authorityTokens.length == 2); + } + + public void testCreatePathTokens() + { + String[] pathTokens = + XSDNamespaceURITokenizer. + createPathTokens( + URI.createURI(xsdNamespace)); + + assertTrue(pathTokens[1].equals("users")); + assertTrue(pathTokens[2].equals("accounts")); + assertTrue(pathTokens.length == 3); + } + +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/resources/log4j.properties b/das-java/contrib/ldap/das.ldap/src/test/resources/log4j.properties new file mode 100644 index 0000000000..75e557ac3b --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootCategory=ERROR, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n + -- cgit v1.2.3