Examples of RuntimeContext


Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Creates a default {@link RuntimeContext} configured with support for Java component implementations
     */
    public static RuntimeContext createCoreRuntime() {
        NullMonitorFactory monitorFactory = new NullMonitorFactory();
        RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory), null);
        runtime.start();
        return runtime;
    }
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component
     */
    public void testEPtoJavaModuleScopeInvoke() throws Throwable {
        RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
        PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
                .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null);

        MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
        MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
        registry.registerTargetBuilder(interceptorBuilder);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module"));
        CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module");
        child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.MODULE));
        child.publish(new ModuleStart(this));
        Object id = new Object();
        child.publish(new RequestStart(this, id));
        EntryPointContext ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        InvocationHandler handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(0, mockInterceptor.getCount());
        Object response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(1, mockInterceptor.getCount());
        Object id2 = new Object();
        child.publish(new RequestStart(this, id2));

        // second request
        Object id3 = new Object();
        child.publish(new RequestStart(this, id3));
        ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(1, mockInterceptor.getCount());
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(2, mockInterceptor.getCount());
        HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(2, service1.count());
        child.publish(new RequestEnd(this, id3));

        child.publish(new ModuleStop(this));
        runtime.stop();
    }
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests creation and wire of an entry point wired to a session-scoped service offered by a Java component
     */
    public void testEPtoJavaSessionScopeInvoke() throws Throwable {
        RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
        PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
                .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null);
        MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
        MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
        registry.registerTargetBuilder(interceptorBuilder);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module"));
        CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module");
        child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.SESSION));
        child.publish(new ModuleStart(this));

        // first session
        Object session = new Object();
        Object id = new Object();
        child.publish(new RequestStart(this, id));
        child.publish(new HttpSessionBound(this, session));

        EntryPointContext ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        InvocationHandler handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(0, mockInterceptor.getCount());
        Object response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(1, mockInterceptor.getCount());
        child.publish(new RequestEnd(this, id));

        Object id2 = new Object();
        child.publish(new RequestStart(this, id2));
        child.publish(new HttpSessionBound(this, session));
        EntryPointContext ctx2 = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx2);
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(2, mockInterceptor.getCount());
        HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(2, service1.count());
        child.publish(new RequestEnd(this, id2));
        child.publish(new HttpSessionEnd(this, session));

        // second session
        Object session2 = new Object();
        child.publish(new RequestStart(this, new Object()));
        child.publish(new HttpSessionBound(this, session2));

        ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        Assert.assertEquals(2, mockInterceptor.getCount());
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(3, mockInterceptor.getCount());
        child.publish(new HttpSessionBound(this, session2));

        Object id3 = new Object();
        child.publish(new RequestStart(this, id3));
        child.publish(new HttpSessionBound(this, session2));
        ctx2 = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx2);
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(4, mockInterceptor.getCount());
        HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(2, service2.count());
        Assert.assertEquals(2, service1.count()); //ensure sessions not crossed
        child.publish(new RequestEnd(this, session2));
        child.publish(new HttpSessionBound(this, session2));

        child.publish(new ModuleStop(this));
        runtime.stop();
    }
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component
     */
    public void testEPtoJavaStatelessInvoke() throws Throwable {
        RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
        PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
                .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null);
        MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
        MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
        registry.registerTargetBuilder(interceptorBuilder);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module"));
        CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module");
        child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.INSTANCE));
        child.publish(new ModuleStart(this));
        Object id = new Object();
        child.publish(new RequestStart(this, id));
        EntryPointContext ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        InvocationHandler handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(0, mockInterceptor.getCount());
        Object response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(1, mockInterceptor.getCount());
        child.publish(new RequestEnd(this, id));

        // second request
        Object id2 = new Object();
        child.publish(new RequestStart(this, id2));
        ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(1, mockInterceptor.getCount());
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(2, mockInterceptor.getCount());
        HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(0, service1.count());
        child.publish(new RequestEnd(this, id));

        child.publish(new ModuleStop(this));
        runtime.stop();
    }
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

        child.publish(new ModuleStop(this));
        runtime.stop();
    }

    public void testEPtoJavaRequestInvoke() throws Throwable {
        RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
        PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
                .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null);
        MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
        MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
        registry.registerTargetBuilder(interceptorBuilder);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module"));
        CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module");
        child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.REQUEST));
        child.publish(new ModuleStart(this));
        Object id = new Object();
        child.publish(new RequestStart(this, id));
        EntryPointContext ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        InvocationHandler handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(0, mockInterceptor.getCount());
        Object response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(1, mockInterceptor.getCount());

        ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        handler = (InvocationHandler) ctx.getHandler();
        response = handler.invoke(null, hello, new Object[]{"foo"});
        HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(2, service1.count());

        child.publish(new RequestEnd(this, id));

        // second request
        Object id2 = new Object();
        child.publish(new RequestStart(this, id2));
        ctx = (EntryPointContext) child.getContext("source");
        Assert.assertNotNull(ctx);
        handler = (InvocationHandler) ctx.getHandler();
        Assert.assertEquals(2, mockInterceptor.getCount());
        response = handler.invoke(null, hello, new Object[]{"foo"});
        Assert.assertEquals("Hello foo", response);
        Assert.assertEquals(3, mockInterceptor.getCount());
        HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null);
        Assert.assertEquals(1, service2.count());
        child.publish(new RequestEnd(this, id2));

        child.publish(new ModuleStop(this));
        runtime.stop();
    }
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests a module-to-module scoped wire is setup properly by the runtime
     */
    public void testModuleToModule() throws Exception{
        RuntimeContext runtime = MockFactory.createJavaRuntime();
        Context ctx = runtime.getSystemContext().getContext("tuscany.system.child");
        Assert.assertNotNull(ctx);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test"));
        CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test");
        Assert.assertNotNull(testCtx);
        testCtx.registerModelObject(MockFactory.createModule());
        testCtx.publish(new ModuleStart(this));
        GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
        Assert.assertNotNull(source);
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

*/
public class IntraCompositeWireIntegrationTestCase extends TestCase {

 
    public void testWireConstruction2() throws Exception {
        RuntimeContext runtime = MockFactory.createCoreRuntime();
        ModuleComponent moduleComponent = createSystemCompositeComponent("test.system");
        Module module = MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE);
        moduleComponent.setImplementation(module);
        runtime.getSystemContext().registerModelObject(moduleComponent);
        CompositeContext context = (CompositeContext) runtime.getSystemContext().getContext("test.system");
        context.publish(new ModuleStart(this));
        //context.registerModelObject(module);
        Source source = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance();
        Assert.assertNotNull(source);
        Target targetRef = source.getTarget();
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

        return sc;
    }
   
   
    public void testWireConstruction() throws ConfigurationException {
        RuntimeContext runtime = MockFactory.createCoreRuntime();
        runtime.getSystemContext().registerModelObject(MockFactory.createSystemCompositeComponent("test.system"));
        CompositeContext context = (CompositeContext) runtime.getSystemContext().getContext("test.system");

        context.publish(new ModuleStart(this));
        context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE,Scope.MODULE));
        Source source = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance();
        Assert.assertNotNull(source);
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests a module-to-session scoped wire is setup properly by the runtime
     */
    public void testModuleToSession() throws Exception{
        RuntimeContext runtime = MockFactory.createJavaRuntime();
        Context ctx = runtime.getSystemContext().getContext("tuscany.system.child");
        Assert.assertNotNull(ctx);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test"));
        CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test");
        Assert.assertNotNull(testCtx);
        testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.SESSION));
        testCtx.publish(new ModuleStart(this));
       
        // first session
View Full Code Here

Examples of org.apache.tuscany.core.runtime.RuntimeContext

    /**
     * Tests a module-to-request scoped wire is setup properly by the runtime
     */
    public void testModuleToRequest() throws Exception{
        RuntimeContext runtime = MockFactory.createJavaRuntime();
        Context ctx = runtime.getSystemContext().getContext("tuscany.system.child");
        Assert.assertNotNull(ctx);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test"));
        CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test");
        Assert.assertNotNull(testCtx);
        testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.REQUEST));
        testCtx.publish(new ModuleStart(this));
       
        // first request
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.