Package org.jmock

Examples of org.jmock.Mock


    }

    protected void setUp() throws Exception {
        _txm = new GeronimoTransactionManager();

        mexDao = new Mock(MessageExchangeDAO.class);
        SimpleScheduler scheduler = new SimpleScheduler("node", null, new Properties());
        scheduler.setTransactionManager(_txm);

        contexts = new Contexts();
        contexts.scheduler = scheduler;
View Full Code Here


    protected void setUp() throws Exception {
        // Override testService in test case.
        _testService = mock(TestService.class);
        // We use one partner to simulate failing service and receive message upon process completion.
        final Mock partner = mock(MessageExchangeContext.class);
        // Some processes will complete, but not all.
        partner.expects(atMostOnce()).match(invokeOnOperation("respond")).will(new CustomStub("process completed") {
            public Object invoke(Invocation invocation) {
                ((TestService)_testService.proxy()).completed();
                return null;
            }
        });
        // There will be multiple calls to invoke.
        partner.expects(atLeastOnce()).match(invokeOnOperation("invoke")).will(new CustomStub("invoke failing service") {
            public Object invoke(Invocation invocation) {
                PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) invocation.parameterValues.get(0);
                if (((TestService)_testService.proxy()).invoke()) {
                    Message response = mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
                    response.setMessage(DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:ResponseElement"));
                    mex.reply(response);
                } else {
                    mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, "BangGoesInvoke", null);
                }
                return null;
            }
        });
        // Faulting a process would send the fault message asynchronously.
        // (Which might be a bug, but right now we swallow it).
        partner.expects(atMostOnce()).method("onAsyncReply").will(new CustomStub("async reply") {
            public Object invoke(Invocation invocation) {
                return null;
            }
        });

        _server = new MockBpelServer() {
            protected MessageExchangeContext createMessageExchangeContext() {
                return (MessageExchangeContext) partner.proxy();
            }
        };
        _server.deploy(new File(new URI(this.getClass().getResource("/recovery").toString())));
        _management = new BpelManagementFacadeImpl(_server._server,_server._store);
    }
View Full Code Here

    public interface Foo {
        String getSomething(String arg);
    }

    public void setUp() throws Exception {
        fooMock = new Mock(Foo.class);
        decoratorMock = new Mock(InvocationDecorator.class);
        decoratorMock.stubs();
        assertNotNull(fooMock.proxy());
        foo = (Foo)Decorating.object(Foo.class, fooMock.proxy(), (InvocationDecorator)decoratorMock.proxy());
    }
View Full Code Here

    public interface FooBar extends Foo, Bar {
    }

    public void testCallsAreDispatchedBetweenObjects() throws Exception {
        Mock fooMock = mock(Foo.class);
        Mock barMock = mock(Bar.class);

        Object foobar = Dispatching.object(new Class[]{Foo.class, Bar.class}, new Object[]{
                fooMock.proxy(), barMock.proxy()}, getFactory());

        fooMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));
        barMock.expects(once()).method("doSomething").with(eq("some thing"));

        assertEquals("some thing", ((Foo)foobar).getSomething());
        ((Bar)foobar).doSomething("some thing");
    }
View Full Code Here

        ((Bar)foobar).doSomething("some thing");
    }

    // This is a proxy limitation ... unfortunately
    public void testOnlyFirstOfMethodsWithSameSignaturesIsCalled() throws Exception {
        Mock fooMock = mock(Foo.class);
        Mock fooMimicMock = mock(FooMimic.class);

        Object foo = Dispatching.object(new Class[]{Foo.class, FooMimic.class}, new Object[]{
                fooMock.proxy(), fooMimicMock.proxy()}, getFactory());

        fooMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));
        // should be fooMimicMock ...
        fooMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));
View Full Code Here

        assertEquals("some thing", ((Foo)foo).getSomething());
        assertEquals("some thing", ((FooMimic)foo).getSomething());
    }

    public void testMethodsWithSameNameButDifferentSignatureAreDistinct() throws Exception {
        Mock barMock = mock(Bar.class);
        Mock barSimilarMock = mock(BarSimilar.class);

        Object bar = Dispatching.object(new Class[]{Bar.class, BarSimilar.class}, new Object[]{
                barMock.proxy(), barSimilarMock.proxy()}, getFactory());

        barMock.expects(once()).method("doSomething").with(eq("some thing"));
        barSimilarMock.expects(once()).method("doSomething").with(eq(1));

        ((Bar)bar).doSomething("some thing");
        ((BarSimilar)bar).doSomething(1);
    }
View Full Code Here

        ((Bar)bar).doSomething("some thing");
        ((BarSimilar)bar).doSomething(1);
    }

    public void testOneDelegateCanMatchMultipleTypes() throws Exception {
        Mock fooBarMock = mock(FooBar.class);

        Object foobar = Dispatching.object(
                new Class[]{Foo.class, Bar.class}, new Object[]{fooBarMock.proxy()}, getFactory());

        fooBarMock.expects(once()).method("doSomething").with(eq("some thing"));
        fooBarMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));

        assertEquals("some thing", ((Foo)foobar).getSomething());
        ((Bar)foobar).doSomething("some thing");
    }
View Full Code Here

        assertEquals(0, pool.getAvailable());
        assertEquals(0, pool.size());
    }

    public void testReturnedElementIsResetted() throws Exception {
        final Mock mockResetter = mock(Resetter.class);
        mockResetter.expects(once()).method("reset").will(returnValue(true));

        final Pool pool = new Pool(Identifiable.class, (Resetter)mockResetter.proxy(), getFactory());
        pool.add(createIdentifiables(1));
        Object borrowed = pool.get();
        ((Poolable)borrowed).returnInstanceToPool();
    }
View Full Code Here

        Object borrowed = pool.get();
        ((Poolable)borrowed).returnInstanceToPool();
    }

    public void testGarbageCollectedElementIsResetted() throws Exception {
        final Mock mockResetter = mock(Resetter.class);
        mockResetter.expects(once()).method("reset").will(returnValue(true));

        final Pool pool = new Pool(Identifiable.class, (Resetter)mockResetter.proxy(), getFactory());
        pool.add(createIdentifiables(1));
        Object borrowed = pool.get();
        assertNotNull(borrowed);
        borrowed = null;
        System.gc();
View Full Code Here

        assertEquals("some thing", ((Foo)foobar).getSomething());
        ((Bar)foobar).doSomething("some thing");
    }

    public void testAllTypesMustBeMatchedByOneDelegate() throws Exception {
        Mock fooMock = mock(Foo.class);

        try {
            Dispatching.object(new Class[]{Foo.class, Bar.class}, new Object[]{fooMock.proxy()}, getFactory());
            fail("DispatchingException expected");
        } catch (final DispatchingException e) {
            assertEquals(Bar.class, e.getType());
        }
    }
View Full Code Here

TOP

Related Classes of org.jmock.Mock

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.