diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-11 06:26:33 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-11 06:26:33 +0000 |
commit | cf9fccdc66de888137a8d33c3ca9c6f206dcc633 (patch) | |
tree | 7c50060ff2d8d4077108f4e81ce9ca6be25c0cf0 /java/sca/modules/assembly/src/test | |
parent | 06276a5d3f34b5e0ee35c9a7e2c2b794cb81ca11 (diff) |
Merge modules to assembly module as discussed on ML
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@813673 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/assembly/src/test')
3 files changed, 520 insertions, 0 deletions
diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java new file mode 100644 index 0000000000..acdaae799e --- /dev/null +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java @@ -0,0 +1,395 @@ +/* + * 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.sca.interfacedef.impl; + +import static org.junit.Assert.fail; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.junit.Before; +import org.junit.Test; + +/** + * TODO some tests commented out due to DataType.equals() needing to be strict + * + * @version $Rev$ $Date$ + */ +public class ContractCompatibilityTestCase { + + private InterfaceContractMapper mapper; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + mapper = utilities.getUtility(InterfaceContractMapper.class); + } + + @Test + public void testNoOperation() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + InterfaceContract target = new MockContract("FooContract"); + mapper.checkCompatibility(source, target, false, false); + } + + @Test + public void testBasic() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + Operation opSource1 = newOperation("op1"); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + InterfaceContract target = new MockContract("FooContract"); + Operation opSource2 = newOperation("op1"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opSource2); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + @Test + public void testBasicIncompatibleOperationNames() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + Operation opSource1 = newOperation("op1"); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + InterfaceContract target = new MockContract("FooContract"); + Operation opSource2 = newOperation("op2"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op2", opSource2); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + @Test + public void testInputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + List<DataType> sourceInputTypes = new ArrayList<DataType>(); + sourceInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class)); + DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + Operation opSource1 = newOperation("op1"); + opSource1.setInputType(inputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + List<DataType> targetInputTypes = new ArrayList<DataType>(); + targetInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class)); + DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + + Operation opTarget = newOperation("op1"); + opTarget.setInputType(targetInputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + @Test + public void testIncompatibleInputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + List<DataType> sourceInputTypes = new ArrayList<DataType>(); + sourceInputTypes.add(new DataTypeImpl<Type>(Integer.class, Integer.class)); + DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + Operation opSource1 = newOperation("op1"); + opSource1.setInputType(inputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + List<DataType> targetInputTypes = new ArrayList<DataType>(); + targetInputTypes.add(new DataTypeImpl<Type>(String.class, String.class)); + DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + + Operation opTarget = newOperation("op1"); + opTarget.setInputType(targetInputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + /** + * Verifies source input types can be super types of the target + */ + @Test + public void testSourceSuperTypeInputCompatibility() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // List<DataType> sourceInputTypes = new ArrayList<DataType>(); + // sourceInputTypes.add(new DataTypeImpl<Type>(Object.class, + // Object.class)); + // DataType<List<DataType>> inputType = new + // DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + // Operation opSource1 = newOperationImpl("op1", inputType, null, null, + // false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // List<DataType> targetInputTypes = new ArrayList<DataType>(); + // targetInputTypes.add(new DataTypeImpl<Type>(String.class, + // String.class)); + // DataType<List<DataType>> targetInputType = + // new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + // + // Operation opTarget = newOperationImpl("op1", targetInputType, null, + // null, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + @Test + public void testOutputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opSource1 = newOperation("op1"); + opSource1.setOutputType(sourceOutputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opTarget = newOperation("op1"); + opTarget.setOutputType(targetOutputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + /** + * Verifies a return type that is a supertype of of the target is compatible + */ + @Test + public void testSupertypeOutputTypes() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceOutputType = new DataTypeImpl<Type>(Object.class, + // Object.class); + // Operation opSource1 = newOperationImpl("op1", null, + // sourceOutputType, null, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetOutputType = new DataTypeImpl<Type>(String.class, + // String.class); + // Operation opTarget = newOperationImpl("op1", null, targetOutputType, + // null, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + @Test + public void testIncompatibleOutputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opSource1 = newOperation("op1"); + opSource1.setOutputType(sourceOutputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetOutputType = new DataTypeImpl<Type>(Integer.class, Integer.class); + Operation opTarget = newOperation("op1"); + opTarget.setOutputType(targetOutputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + @Test + public void testFaultTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + sourceFaultTypes.add(0, sourceFaultType); + Operation opSource1 = newOperation("op1"); + opSource1.setFaultTypes(sourceFaultTypes); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> targetFaultTypes = new ArrayList<DataType>(); + targetFaultTypes.add(0, targetFaultType); + + Operation opTarget = newOperation("op1"); + opTarget.setFaultTypes(targetFaultTypes); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + @Test + public void testSourceFaultTargetNoFaultCompatibility() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + sourceFaultTypes.add(0, sourceFaultType); + Operation opSource1 = newOperation("op1"); + opSource1.setFaultTypes(sourceFaultTypes); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + Operation opTarget = newOperation("op1"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + /** + * Verifies a source's fault which is a supertype of the target's fault are + * compatible + * + * @throws Exception + */ + @Test + public void testFaultSuperTypes() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class, + // Exception.class); + // List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + // sourceFaultTypes.add(0, sourceFaultType); + // Operation opSource1 = newOperationImpl("op1", null, null, + // sourceFaultTypes, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetFaultType = new + // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class); + // List<DataType> targetFaultTypes = new ArrayList<DataType>(); + // targetFaultTypes.add(0, targetFaultType); + // + // Operation opTarget = newOperationImpl("op1", null, null, + // targetFaultTypes, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + /** + * Verifies a source's faults which are supertypes and a superset of the + * target's faults are compatible + */ + @Test + public void testFaultSuperTypesAndSuperset() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class, + // Exception.class); + // DataType sourceFaultType2 = new + // DataTypeImpl<Type>(RuntimeException.class, RuntimeException.class); + // List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + // sourceFaultTypes.add(0, sourceFaultType); + // sourceFaultTypes.add(1, sourceFaultType2); + // Operation opSource1 = newOperationImpl("op1", null, null, + // sourceFaultTypes, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetFaultType = new + // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class); + // List<DataType> targetFaultTypes = new ArrayList<DataType>(); + // targetFaultTypes.add(0, targetFaultType); + // + // Operation opTarget = newOperationImpl("op1", null, null, + // targetFaultTypes, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + private static class MockInterface extends InterfaceImpl { + + } + + private class MockContract<T> extends InterfaceContractImpl { + public MockContract() { + } + + public MockContract(String interfaceClass) { + Interface jInterface = new MockInterface(); + setInterface(jInterface); + } + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java new file mode 100644 index 0000000000..d1faa5cf2b --- /dev/null +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java @@ -0,0 +1,70 @@ +/* + * 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.sca.interfacedef.impl; + + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class InterfaceContractTestCase { + private InterfaceContract contract; + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + contract = new MockInterfaceContract(); + Interface i1 = new MockInterface(); + contract.setInterface(i1); + Operation op1 = newOperation("op1"); + i1.getOperations().add(op1); + Interface i2 = new MockInterface(); + contract.setCallbackInterface(i2); + Operation callbackOp1 = newOperation("callbackOp1"); + i2.getOperations().add(callbackOp1); + } + + @Test + public void testClone() throws Exception { + InterfaceContract copy = (InterfaceContract) contract.clone(); + Assert.assertNotNull(copy); + Assert.assertNotSame(copy.getCallbackInterface(), contract.getCallbackInterface()); + Assert.assertNotSame(copy.getInterface(), contract.getInterface()); + } + + private static class MockInterfaceContract extends InterfaceContractImpl implements InterfaceContract { + } + + private static class MockInterface extends InterfaceImpl implements Interface { + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java new file mode 100644 index 0000000000..2775c4ac71 --- /dev/null +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java @@ -0,0 +1,55 @@ +/* + * 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.sca.policy; + +import static org.junit.Assert.assertEquals; + +import javax.xml.namespace.QName; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test building of policy model instances using the policy factory. + * + * @version $Rev$ $Date$ + */ +public class PolicyFactoryTestCase { + + PolicyFactory factory; + + @Before + public void setUp() throws Exception { + factory = new DefaultPolicyFactory(); + } + + @Test + public void testCreateIntent() { + Intent intent = factory.createIntent(); + intent.setName(new QName("http://test", "reliability")); + assertEquals(intent.getName(), new QName("http://test", "reliability")); + } + + @Test + public void testCreatePolicySet() { + PolicySet policySet = factory.createPolicySet(); + policySet.setName(new QName("http://test", "reliability")); + assertEquals(policySet.getName(), new QName("http://test", "reliability")); + } +} |