From a3c48da9bb8971497d414f86e352123d95b9c3da Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 20 Nov 2009 23:53:35 +0000 Subject: Moving 2.x trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882795 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/itest/ClientNode.java | 92 ------- .../src/test/java/itest/ServiceNode.java | 58 ---- .../test/java/itest/StopStartNodesTestCase.java | 102 ------- .../src/test/java/itest/TestCaseRunner.java | 292 --------------------- .../src/test/java/itest/TwoNodesTestCase.java | 105 -------- 5 files changed, 649 deletions(-) delete mode 100644 java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ClientNode.java delete mode 100644 java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ServiceNode.java delete mode 100644 java/sca/itest/nodes/two-nodes-test/src/test/java/itest/StopStartNodesTestCase.java delete mode 100644 java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TestCaseRunner.java delete mode 100644 java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TwoNodesTestCase.java (limited to 'java/sca/itest/nodes/two-nodes-test/src/test/java') diff --git a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ClientNode.java b/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ClientNode.java deleted file mode 100644 index 5f9453a5d6..0000000000 --- a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ClientNode.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 itest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import itest.nodes.Helloworld; - -import java.io.File; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.apache.tuscany.sca.node.configuration.NodeConfiguration; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.oasisopen.sca.client.SCAClient; - -/** - * This shows how to test the Calculator service component. - */ -public class ClientNode { - private final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - private static Node clientNode; - private static TestCaseRunner runner; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - runner = new TestCaseRunner(ServiceNode.class); - runner.beforeClass(); - System.setProperty("org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint.enabled", - "false"); - NodeFactory factory = NodeFactory.newInstance(); - NodeConfiguration conf = - factory.createNodeConfiguration().setURI("clientNode"). - addBinding(new QName(SCA11_NS, "binding.sca"), "http://localhost:8085/sca https://localhost:9085/sca") - .addBinding(new QName(SCA11_NS, "binding.ws"), "http://localhost:8086/ws") - .addContribution("client", new File("../helloworld-client/target/classes").toURI().toString()); - clientNode = factory.createNode(conf).start(); - Thread.sleep(1000); - } - - @Test - public void testCalculator() throws Exception { - - Helloworld client = clientNode.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - } - - @Test - @Ignore("SCAClient needs to leverage the EndpointRegistry to invoke services that are not hosted on the local node") - public void testCalculatorClientAPI() throws Exception { - Helloworld service = SCAClient.getService(Helloworld.class, "HelloworldService"); - assertNotNull(service); - assertEquals("Hello Petra", service.sayHello("Petra")); - - Helloworld client = SCAClient.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (clientNode != null) { - clientNode.stop(); - } - if (runner != null) { - runner.afterClass(); - } - } -} diff --git a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ServiceNode.java b/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ServiceNode.java deleted file mode 100644 index b413825106..0000000000 --- a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/ServiceNode.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 itest; - -import java.io.File; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.apache.tuscany.sca.node.configuration.NodeConfiguration; -import org.junit.AfterClass; -import org.junit.BeforeClass; - -/** - * This shows how to test the Calculator service component. - */ -public class ServiceNode { - private final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - private static Node serviceNode; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - System.setProperty("org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint.enabled", - "false"); - NodeFactory factory = NodeFactory.newInstance(); - NodeConfiguration conf = - factory.createNodeConfiguration().setURI("serviceNode") - .addBinding(new QName(SCA11_NS, "binding.sca"), "http://localhost:8087/sca") - .addBinding(new QName(SCA11_NS, "binding.ws"), "http://localhost:8088/ws") - .addContribution("service", new File("../helloworld-service/target/classes").toURI().toString()); - serviceNode = factory.createNode(conf).start(); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (serviceNode != null) { - serviceNode.stop(); - } - } -} diff --git a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/StopStartNodesTestCase.java b/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/StopStartNodesTestCase.java deleted file mode 100644 index 4a41ae8133..0000000000 --- a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/StopStartNodesTestCase.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 itest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import itest.nodes.Helloworld; - -import java.io.File; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.Test; - -/** - * Tests using two nodes and stopping and restarting a service node. - */ -public class StopStartNodesTestCase { - - private static Node serviceNode; - private static Node clientNode; - - @Test - public void testCalculator() throws Exception { - NodeFactory factory = NodeFactory.newInstance(); - serviceNode = factory.createNode(new Contribution("service", getJar("../helloworld-service/target"))); - serviceNode.start(); - clientNode = factory.createNode(new Contribution("client", getJar("../helloworld-client/target"))); - clientNode.start(); - - Helloworld service = serviceNode.getService(Helloworld.class, "HelloworldService"); - assertNotNull(service); - assertEquals("Hello Petra", service.sayHello("Petra")); - - Helloworld client = clientNode.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - - serviceNode.stop(); - - client = clientNode.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - try { - client.sayHello("Petra"); - fail(); - } catch (Exception e) { - // expected - // TODO: better exception than NPE - } - - serviceNode = factory.createNode(new Contribution("service", getJar("../helloworld-service/target"))); - serviceNode.start(); - - client = clientNode.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - } - - /** - * Get the jar in the target folder without being dependent on the version name to - * make tuscany releases easier - */ - private static String getJar(String targetDirectory) { - File f = new File(targetDirectory); - for (File file : f.listFiles()) { - if (file.getName().endsWith(".jar")) { - return file.toURI().toString(); - } - } - throw new IllegalStateException("Can't find jar in: " + targetDirectory); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (serviceNode != null) { - serviceNode.stop(); - } - if (clientNode != null) { - clientNode.stop(); - } - } -} diff --git a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TestCaseRunner.java b/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TestCaseRunner.java deleted file mode 100644 index 7dfa6e66cc..0000000000 --- a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TestCaseRunner.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * 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 itest; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedAction; - -/** - * A helper class that can be used to run an SCA JUnit test case. The test case will run in an isolated class loader. - * - * @version $Rev$ $Date$ - */ -public class TestCaseRunner { - - private ClassLoader classLoader; - private Class testSuiteClass; - private Object testSuite; - private Class testResultClass; - private Class testCaseClass; - private Object testCase; - - private Class beforeAnnotation; - private Class beforeClassAnnotation; - private Class afterAnnotation; - private Class afterClassAnnotation; - private Class junit4AdapterClass; - private Class junit3TestCaseClass; - - /** - * Constructs a new TestCase runner. - * - * @param testClass - */ - public TestCaseRunner(Class testClass) { - try { - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - classLoader = testClass.getClassLoader(); - if (classLoader instanceof URLClassLoader) { - URL[] urls = ((URLClassLoader)classLoader).getURLs(); - classLoader = new URLClassLoader(urls, classLoader.getParent()); - } else if (classLoader == tccl || classLoader.getParent() == tccl) { - classLoader = new URLClassLoader(new URL[0], classLoader); - } else { - classLoader = tccl; - } - - try { - // Thread.currentThread().setContextClassLoader(classLoader); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finalClassLoader = classLoader; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finalClassLoader); - return null; - } - }); - - testCaseClass = Class.forName(testClass.getName(), true, classLoader); - testCase = testCaseClass.newInstance(); - ClassLoader testClassLoader = testCaseClass.getClassLoader(); - - junit3TestCaseClass = Class.forName("junit.framework.TestCase", true, testClassLoader); - - testSuiteClass = Class.forName("junit.framework.TestSuite", true, testClassLoader); - Constructor testSuiteConstructor = testSuiteClass.getConstructor(Class.class); - testSuite = testSuiteConstructor.newInstance(testCaseClass); - - testResultClass = Class.forName("junit.framework.TestResult", true, testClassLoader); - - try { - beforeAnnotation = Class.forName("org.junit.Before", true, testClassLoader); - afterAnnotation = Class.forName("org.junit.After", true, testClassLoader); - beforeClassAnnotation = Class.forName("org.junit.BeforeClass", true, testClassLoader); - afterClassAnnotation = Class.forName("org.junit.AfterClass", true, testClassLoader); - junit4AdapterClass = Class.forName("junit.framework.JUnit4TestAdapter", true, testClassLoader); - } catch (Exception e) { - // Unexpected - throw new AssertionError(e); - } - } catch (Throwable e) { - e.printStackTrace(); - } finally { - // Thread.currentThread().setContextClassLoader(tccl); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finaltccl = tccl; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finaltccl); - return null; - } - }); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Run the test case - */ - public void run() { - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - try { - // Thread.currentThread().setContextClassLoader(classLoader); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finalClassLoader = classLoader; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finalClassLoader); - return null; - } - }); - - if (junit3TestCaseClass.isAssignableFrom(testCaseClass)) { - Object testResult = testResultClass.newInstance(); - Method runMethod = testSuiteClass.getMethod("run", testResultClass); - runMethod.invoke(testSuite, testResult); - } else { - Object junit4Adapter = junit4AdapterClass.getConstructor(Class.class).newInstance(testCaseClass); - Object testResult = testResultClass.newInstance(); - Method runMethod = junit4AdapterClass.getMethod("run", testResultClass); - runMethod.invoke(junit4Adapter, testResult); - } - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - // Thread.currentThread().setContextClassLoader(tccl); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finaltccl = tccl; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finaltccl); - return null; - } - }); - } - } - - /** - * Invoke the setUp method - */ - public void setUp() { - execute("setUp"); - } - - /** - * Invoke the before methods - */ - public void before() { - execute(beforeAnnotation); - } - - /** - * Invoke the beforeClass methods - */ - public void beforeClass() { - execute(beforeClassAnnotation); - } - - /** - * Invoke the tearDown method - */ - public void tearDown() { - execute("tearDown"); - } - - /** - * Invoke the after methods - */ - public void after() { - execute(afterAnnotation); - } - - /** - * Invoke the afterClass methods - */ - public void afterClass() { - execute(afterClassAnnotation); - } - - /** - * Invoke the specified test method. - */ - public void run(String methodName) { - execute(methodName); - } - - /** - * Invoke the methods annotated with the specified annotation. - */ - private void execute(Class annotationClass) { - if (annotationClass == null) { - throw new RuntimeException(new NoSuchMethodException()); - } - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - try { - // Thread.currentThread().setContextClassLoader(classLoader); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finalClassLoader = classLoader; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finalClassLoader); - return null; - } - }); - - for (Method method : testCaseClass.getDeclaredMethods()) { - for (Annotation annotation : method.getAnnotations()) { - if (annotation.annotationType() == annotationClass) { - method.invoke(testCase); - } - } - } - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - // Thread.currentThread().setContextClassLoader(tccl); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finaltccl = tccl; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finaltccl); - return null; - } - }); - } - } - - /** - * Invoke the specified method - */ - private void execute(String methodName) { - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - try { - // Thread.currentThread().setContextClassLoader(classLoader); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finalClassLoader = classLoader; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finalClassLoader); - return null; - } - }); - Method setUpMethod = testCaseClass.getDeclaredMethod(methodName); - setUpMethod.setAccessible(true); - setUpMethod.invoke(testCase); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - // Thread.currentThread().setContextClassLoader(tccl); - // Allow privileged access to set class loader. Requires RuntimePermission - // setContextClassLoader in security policy. - final ClassLoader finaltccl = tccl; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(finaltccl); - return null; - } - }); - } - } - -} - diff --git a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TwoNodesTestCase.java b/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TwoNodesTestCase.java deleted file mode 100644 index 769aad1940..0000000000 --- a/java/sca/itest/nodes/two-nodes-test/src/test/java/itest/TwoNodesTestCase.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 itest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import itest.nodes.Helloworld; - -import java.io.File; - -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.apache.tuscany.sca.node.configuration.NodeConfiguration; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.oasisopen.sca.client.SCAClient; - -/** - * This shows how to test the Calculator service component. - */ -public class TwoNodesTestCase { - - private static Node serviceNode; - private static Node clientNode; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - System.setProperty("org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint.enabled", - "false"); - NodeFactory factory = NodeFactory.newInstance(); - NodeConfiguration configuration1 = - factory.createNodeConfiguration().setURI("serviceNode") - .addContribution("service", getJar("../helloworld-service/target")); - serviceNode = factory.createNode(configuration1).start(); - - NodeConfiguration configuration2 = - factory.createNodeConfiguration().setURI("clientNode") - .addContribution("client", getJar("../helloworld-client/target")); - clientNode = factory.createNode(configuration2).start(); - } - - /** - * Get the jar in the target folder without being dependent on the version name to - * make tuscany releases easier - */ - private static String getJar(String targetDirectory) { - File f = new File(targetDirectory); - for (File file : f.listFiles()) { - if (file.getName().endsWith(".jar")) { - return file.toURI().toString(); - } - } - throw new IllegalStateException("Can't find jar in: " + targetDirectory); - } - - @Test - public void testCalculator() throws Exception { - Helloworld service = serviceNode.getService(Helloworld.class, "HelloworldService"); - assertNotNull(service); - assertEquals("Hello Petra", service.sayHello("Petra")); - - Helloworld client = clientNode.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - } - - @Test - public void testCalculatorClientAPI() throws Exception { - Helloworld service = SCAClient.getService(Helloworld.class, "HelloworldService"); - assertNotNull(service); - assertEquals("Hello Petra", service.sayHello("Petra")); - - Helloworld client = SCAClient.getService(Helloworld.class, "HelloworldClient"); - assertNotNull(client); - assertEquals("Hi Hello Petra", client.sayHello("Petra")); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (serviceNode != null) { - serviceNode.stop(); - } - if (clientNode != null) { - clientNode.stop(); - } - } -} -- cgit v1.2.3