diff options
Diffstat (limited to 'java/das/ldap/das.ldap/src/test')
25 files changed, 3656 insertions, 0 deletions
diff --git a/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/connect/test/ADSEmbeddedConnectionTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorHelperTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/InitialContextCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/MetaContextCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/create/test/UniqueOIDCreatorHelperTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/destroy/test/InitialContextDestroyerTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataGraphCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/create/test/EDataObjectCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataGraphReaderTest.java b/java/das/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/java/das/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<EDataObject, String>(); + + 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<EDataObject> retrievedAuthorizationContainmentList = + (EList<EDataObject>) + 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<EDataObject> referenceAuthorizationsList = + (EList<EDataObject>) retrievedConfigurationEDataObject. + eGet(configurationAuthorizationsEReference); + + assertEquals(2, referenceAuthorizationsList.size() ); + } + + public void testReadException() + { + dataObjectToRelativeDNCache = + new Hashtable<EDataObject, String>(); + + try + { + eDataGraph = + EDataGraphReader.read( + userEClass, + "1", + metaContext, + dataObjectToRelativeDNCache); + } + catch ( NamingException e ) + { + readException = true; + } + + assertTrue(readException); + } + + + +}
\ No newline at end of file diff --git a/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/read/test/EDataObjectReaderTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASHelperTest.java b/java/das/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/java/das/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<EDataObject, String> metaDataObjectToRelativeDNCache = + new Hashtable<EDataObject, String>(); + + 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/test/LdapDASTest.java b/java/das/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/java/das/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<String, LdapContext> 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<EDataObject> authorizationList = + ( EList<EDataObject> ) 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/emf/update/test/EDataGraphUpdateTest.java b/java/das/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/java/das/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<EDataObject, String>(); + + 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<EDataObject> 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/learning/test/LearningTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java b/java/das/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/java/das/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<EClass>(); + + 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<EClass> + 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java b/java/das/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/java/das/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<EClass> testStack = + EcoreTypeSystemHelper. + loadParentEClassifierStack( + eClassL2, + null); + + assertEquals(testStack.size(), 2); + } +} diff --git a/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java b/java/das/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/java/das/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<EClass>(); + + eClassL0 = + ecoreFactory. + createEClass(); + + eClassL1 = + ecoreFactory. + createEClass(); + + eClassL0.setName( "L0" ); + eClassL1.setName( "L1" ); + + eClassNameToEClassMap = + new HashMap<String, EClass>(); + + 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<EClass> + processedEClassifiers = + null; + + private static DirContext + eObjectClassL0EntryContext = + null; + + private static DirContext + eObjectClassL1EntryContext = + null; + + private static DirContext + eClassL0MetaContext = + null; + + private static DirContext + eClassL1MetaContext = + null; + + private Map<String, EClass> 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java b/java/das/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/java/das/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<EClass>(); + + 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<EClass> + 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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/JNDIUtilTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/QualifiedNameNormalizerTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/util/test/XSDNamespaceURITokenizerTest.java b/java/das/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/java/das/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/java/das/ldap/das.ldap/src/test/resources/log4j.properties b/java/das/ldap/das.ldap/src/test/resources/log4j.properties new file mode 100644 index 0000000000..75e557ac3b --- /dev/null +++ b/java/das/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 + |