summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl')
-rw-r--r--sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java93
-rw-r--r--sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseManagerTestCase.java50
-rw-r--r--sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseSorterTestCase.java67
3 files changed, 210 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java
new file mode 100644
index 0000000000..38306317b4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * 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.core.invocation.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImplTestCase {
+
+ @Test
+ public void testInsertAtEnd() throws Exception {
+ Operation op = newOperation("foo");
+ InvocationChain chain = new InvocationChainImpl(op, op, true, new PhaseManager(new DefaultExtensionPointRegistry()), false);
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(inter1);
+ chain.addInterceptor(inter2);
+ Interceptor head = (Interceptor)chain.getHeadInvoker();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ }
+
+ @Test
+ public void testAddByPhase() throws Exception {
+ Operation op = newOperation("foo");
+ InvocationChain chain = new InvocationChainImpl(op, op, false, new PhaseManager(new DefaultExtensionPointRegistry()), false);
+ Interceptor inter1 = new MockInterceptor();
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter3 = new MockInterceptor();
+ Interceptor inter4 = new MockInterceptor();
+ chain.addInterceptor(inter3); // SERVICE
+ chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, inter4);
+ chain.addInterceptor(Phase.SERVICE_POLICY, inter2);
+ chain.addInterceptor(Phase.SERVICE_BINDING, inter1);
+ Interceptor head = (Interceptor)chain.getHeadInvoker();
+ assertEquals(inter1, head);
+ assertEquals(inter2, inter1.getNext());
+ assertEquals(inter3, inter2.getNext());
+ assertEquals(inter4, inter3.getNext());
+ }
+
+ private class MockInterceptor implements Interceptor {
+
+ private Invoker next;
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseManagerTestCase.java b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseManagerTestCase.java
new file mode 100644
index 0000000000..8fcead004d
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseManagerTestCase.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation.impl;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhaseManagerTestCase {
+
+ @Test
+ public void testDiscovery() {
+ PhaseManager pm = new PhaseManager("org.apache.tuscany.sca.invocation.PhaseTest");
+ List<String> phases = pm.getAllPhases();
+ System.out.println(phases.size());
+ System.out.println(phases);
+ // Assert.assertEquals(15, phases.size());
+ Assert.assertEquals("reference.first", phases.get(0));
+
+ int rt = phases.indexOf("reference.transaction");
+ Assert.assertTrue(rt > phases.indexOf("reference.interface"));
+
+ int st = phases.indexOf("service.transaction");
+ Assert.assertTrue(st > phases.indexOf("service.binding"));
+
+ int it = phases.indexOf("implementation.transaction");
+ Assert.assertTrue(it < phases.indexOf("implementation.policy"));
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseSorterTestCase.java b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseSorterTestCase.java
new file mode 100644
index 0000000000..c268e133e4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/PhaseSorterTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * 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.core.invocation.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PhaseSorterTestCase {
+ private PhaseSorter<String> graph;
+
+ @Before
+ public void setUp() throws Exception {
+ graph = new PhaseSorter<String>();
+ }
+
+ @Test
+ public void testSort() {
+ graph.addEdge("a", "b");
+ graph.addEdge("a", "c");
+ graph.addEdge("c", "d");
+ graph.addEdge("b", "c");
+ List<String> order = graph.topologicalSort(true);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(!graph.getVertices().isEmpty());
+
+ graph.addEdge("d", "a");
+ try {
+ order = graph.topologicalSort(true);
+ assertTrue("Should have failed", false);
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ graph.removeEdge("d", "a");
+ order = graph.topologicalSort(false);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(graph.getVertices().isEmpty());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+}