Package org.apache.tuscany.sca.node

Examples of org.apache.tuscany.sca.node.SCANode2


import calculator.CalculatorService;

public class LaunchCalculatorNodeA {
    public static void main(String[] args) throws Exception {
       
        SCANode2 node = null;
        try {
           
            NodeLauncher nodeLauncher = NodeLauncher.newInstance();
            node = nodeLauncher.createNode("http://localhost:9990/node-image/NodeA");

            node.start();
           
            // get a reference to the calculator component
            SCAClient client = (SCAClient)node;
            CalculatorService calculatorService =
                client.getService(CalculatorService.class, "CalculatorServiceComponentA");
           
            // Calculate
            System.out.println("3 + 2=" + calculatorService.add(3, 2));
            System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
            System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
            System.out.println("3 / 2=" + calculatorService.divide(3, 2));
           
            if (args.length > 1){
                for (int i=0; i < 1000; i++){
                    // Calculate
                    System.out.println("3 + 2=" + calculatorService.add(3, 2));
                    System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
                    System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
                    System.out.println("3 / 2=" + calculatorService.divide(3, 2));
                }
            }
           
            node.stop();
           
        } catch (Exception e) {
            throw new ServiceRuntimeException(e);
        }       
    }
View Full Code Here


     * and reference injection is complete.
     */
    @Test
    public void atInitProper() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(),
                new SCAContribution("TestContribution",
                                    new File("src/main/resources/proper").toURL().toString()));
        node.start();
        AService aService = ((SCAClient)node).getService(AService.class, "AComponent");
        Assert.assertTrue(aService.isInitProper());
        Assert.assertEquals("Hello Pandu", aService.getGreetings("Pandu"));
        node.stop();
    }
View Full Code Here

     */
    @Test
    public void atInitProtectedMethod() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err1").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Initializer must be a public method."));
        }
    }
View Full Code Here

     */
    @Test
    public void atInitPrivateMethod() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err2").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Initializer must be a public method."));
        }
    }
View Full Code Here

     */
    @Test
    public void atInitNonVoidReturnType() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err3/HelloWorldErr3.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err3").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Initializer must return void."));
        }
    }
View Full Code Here

     */
    @Test
    public void atInitMethodWithArgs() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err4/HelloWorldErr4.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err4").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Initializer must not have argments"));
        }
    }
View Full Code Here

     * with void return type.
     */
    @Test
    public void atDestroyProper() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(),
                new SCAContribution("TestContribution",
                                    new File("src/main/resources/proper").toURL().toString()));
        node.start();
        AService aService = ((SCAClient)node).getService(AService.class, "AComponent");
        Assert.assertEquals("Hello Pandu", aService.getGreetings("Pandu"));
        node.stop();
    }
View Full Code Here

     */
    @Test
    public void atDestroyProtectedMethod() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err1").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Destructor must be a public method."));
        }
    }
View Full Code Here

     */
    @Test
    public void atDestroyPrivateMethod() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err2").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Destructor must be a public method."));
        }
    }
View Full Code Here

     */
    @Test
    public void atDestroyNonVoidReturnType() throws Exception {
        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
        try {
            SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err3/AServiceErr3.composite").toURL().toString(),
                    new SCAContribution("TestContribution",
                                        new File("src/main/resources/err3").toURL().toString()));
            Assert.fail();
            node.stop();
        } catch(ServiceRuntimeException e) {
            //expected
            Assert.assertNotSame(-1, e.getMessage().indexOf("Destructor must return void."));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.node.SCANode2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.