diff options
Diffstat (limited to 'das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema')
7 files changed, 1678 insertions, 0 deletions
diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java new file mode 100644 index 0000000000..c52a9ede1c --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EAttributeTypeCreatorTest.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaContextsSetup; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +public class EAttributeTypeCreatorTest +extends EcoreSchemaContextsSetup +{ + private static final String namespaceURI = + "http://org.apache.tuscany/datatypes"; + + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private static EcorePackage ecorePackage = + EcorePackage.eINSTANCE; + + private static EAttribute eAttribute = + ecoreFactory.createEAttribute(); + + private static String eAttributeName = + "ole"; + + private static DirContext eAttributeEntryContext = + null; + + public void setUp() throws NamingException, Exception + { + super.setUp(); + } + + public void tearDown() throws NamingException, Exception + { + EStructuralFeatureTypeDestroyer. + destroy( + ecoreAttributeTypesContext, + eAttribute, + TUSCANY_OID_PREFIX_VALUE); + + super.tearDown(); + } + + public void testCreate() throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(namespaceURI); + + EClass eContainingClass = + ecoreFactory. + createEClass(); + + String eContainingClassName = + eContainingClass.getName(); + + ePackage. + getEClassifiers(). + add( eContainingClass ); + + eContainingClass. + getEStructuralFeatures(). + add(eAttribute); + + eAttribute. + setName(eAttributeName); + + eAttribute. + setEType(ecorePackage.getEString()); + + EAttributeTypeCreator + eAttributeTypeCreator = + new EAttributeTypeCreator(); + + eAttributeTypeCreator. + create( + ecoreAttributeTypesContext, + eAttribute, + TUSCANY_OID_PREFIX_VALUE ); + + String rdn = + SimpleTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + namespaceURI, + eContainingClassName, + eAttributeName); + + eAttributeEntryContext = + ( DirContext ) + ecoreAttributeTypesContext. + lookup( rdn ); + + assertNotNull(eAttributeEntryContext); + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java new file mode 100644 index 0000000000..056658b3c1 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorHelperTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreatorHelper; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.DASContextSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EcoreFactory; + +public class EObjectClassCreatorHelperTest +extends DASContextSetup +{ + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private EClass eClassL0 = + null; + + private EClass eClassL1 = + null; + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + eClassL0 = + ecoreFactory. + createEClass(); + eClassL0.setName( "L0" ); + + eClassL1 = + ecoreFactory. + createEClass(); + eClassL1.setName( "L1" ); + + eClassL1. + getESuperTypes(). + add(eClassL0); + } + + public void testCreateInheritanceMetaData() + throws NamingException + { + EObjectClassCreatorHelper. + createInheritanceMetaData( + metaContext, + eClassL1 ); + + DirContext parentContext = + ( DirContext ) + metaContext. + lookup( "cn=" + eClassL0.getName() ); + + assertNotNull(parentContext); + + DirContext childContext = + ( DirContext ) + parentContext. + lookup( "cn=" + eClassL1.getName() ); + + assertNotNull(childContext); + + parentContext.destroySubcontext( + "cn=" + eClassL1.getName() ); + + metaContext.destroySubcontext( + "cn=" + eClassL0.getName() ); + } + + public void testGetEClassParent() + { + EClass eClassParent = + null; + + eClassParent = + EcoreTypeSystemHelper. + getEClassParent(eClassL1); + + assertSame(eClassL0, eClassParent); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java new file mode 100644 index 0000000000..9ef6f6e086 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EObjectClassCreatorTest.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +public class EObjectClassCreatorTest +extends EcoreSchemaAndDASContextsSetup +{ + boolean isObjectClassL0Created = false; + boolean isObjectClassL1Created = false; + + public void tearDown() + throws NamingException, Exception + { + if (isObjectClassL1Created) + { + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL1, + TUSCANY_OID_PREFIX_VALUE ); + + metaContext. + destroySubcontext( + "cn="+eClassL0.getName() ); + } + + if (isObjectClassL0Created) + { + EObjectClassDestroyer. + destroy( + metaContext, + ecoreAttributeTypesContext, + ecoreObjectClassesContext, + eClassL0, + TUSCANY_OID_PREFIX_VALUE ); + } + + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + processedEClassifiers = + new ArrayList<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/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java new file mode 100644 index 0000000000..c316231c99 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EReferenceTypeCreatorTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EReferenceTypeCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; + +public class EReferenceTypeCreatorTest +extends EcoreSchemaContextsSetup +{ + private static final String namespaceURI = + "http://org.apache.tuscany/datatypes"; + + private static EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + private static EReference eReference = + ecoreFactory.createEReference(); + + private static String eReferenceName = + "ole"; + + private static DirContext eReferenceEntryContext = + null; + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + } + + public void tearDown() + throws NamingException, Exception + { + EStructuralFeatureTypeDestroyer. + destroy( + ecoreAttributeTypesContext, + eReference, + TUSCANY_OID_PREFIX_VALUE); + + super.tearDown(); + } + + public void testCreate() throws NamingException, Exception + { + EPackage ePackage = + ecoreFactory. + createEPackage(); + + ePackage. + setNsURI(namespaceURI); + + EClass eContainingClass = + ecoreFactory. + createEClass(); + + String eContainingClassName = + eContainingClass.getName(); + + ePackage. + getEClassifiers(). + add( eContainingClass ); + + eContainingClass. + getEStructuralFeatures(). + add(eReference); + + eReference. + setName(eReferenceName); + + eReference. + setEType(eContainingClass); + + EReferenceTypeCreator + eReferenceTypeCreator = + new EReferenceTypeCreator(); + + eReferenceTypeCreator. + create( + ecoreAttributeTypesContext, + eReference, + TUSCANY_OID_PREFIX_VALUE ); + + String rdn = + SimpleTypeRDNCreator. + create( + TUSCANY_OID_PREFIX_VALUE, + namespaceURI, + eContainingClassName, + eReferenceName); + + eReferenceEntryContext = + ( DirContext ) + ecoreAttributeTypesContext. + lookup( rdn ); + + assertNotNull(eReferenceEntryContext); + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java new file mode 100644 index 0000000000..02ffe54627 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/create/test/EcoreTypeSystemCreatorHelperTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.das.ldap.schema.emf.create.test; + +import java.util.Stack; + +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EcoreFactory; + +import junit.framework.TestCase; + +public class EcoreTypeSystemCreatorHelperTest +extends TestCase +{ + EcoreFactory ecoreFactory = + EcoreFactory.eINSTANCE; + + public void testLoadParentEClassifierStack() + { + EClass eClassL0 = + ecoreFactory.createEClass(); + + EClass eClassL1 = + ecoreFactory.createEClass(); + + EClass eClassL2 = + ecoreFactory.createEClass(); + + eClassL2.getESuperTypes().add(eClassL1); + + eClassL1.getESuperTypes().add(eClassL0); + + Stack<EClass> testStack = + EcoreTypeSystemHelper. + loadParentEClassifierStack( + eClassL2, + null); + + assertEquals(testStack.size(), 2); + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java new file mode 100644 index 0000000000..9de0d189ba --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/ECascadingObjectClassDestroyerTest.java @@ -0,0 +1,397 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.ECascadingObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +/* + * TODO Make sure that we test EAttribute deletion as well. + */ +public class ECascadingObjectClassDestroyerTest +extends EcoreSchemaAndDASContextsSetup +{ + public void tearDown() + throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + processedEClassifiers = + new ArrayList<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/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java new file mode 100644 index 0000000000..8370eaff52 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/test/java/org/apache/tuscany/das/ldap/schema/emf/destroy/test/EObjectClassDestroyerTest.java @@ -0,0 +1,457 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tuscany.das.ldap.schema.emf.destroy.test; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.prototype.setup.Prototype; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EObjectClassCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EObjectClassDestroyer; +import org.apache.tuscany.das.ldap.schema.embedded.setup.test.EcoreSchemaAndDASContextsSetup; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; + +/* + * TODO Make sure that we test EAttribute deletion as well. + */ +public class EObjectClassDestroyerTest +extends EcoreSchemaAndDASContextsSetup +implements Prototype +{ + public void tearDown() + throws NamingException, Exception + { + super.tearDown(); + } + + public void setUp() + throws NamingException, Exception + { + super.setUp(); + + ecoreFactory = + EcoreFactory.eINSTANCE; + ecorePackage = + EcorePackage.eINSTANCE; + + + processedEClassifiers = + new ArrayList<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 |