Package org.easymock

Examples of org.easymock.MockControl


                new Class[] {Rule.class, Object.class, Method.class, Argument[].class},
                new Object[] {null, null, null, null});
    }

    public void testPojoMethodThrowsException() throws Exception {
        MockControl controlTuple = mocks.createControl(Tuple.class);
        Tuple mockTuple = (Tuple)controlTuple.getMock();
        MockControl controlRuleMethod = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod = (RuleReflectMethod) controlRuleMethod.getMock();
        controlRuleMethod.expectAndThrow(mockRuleMethod.invokeMethod(mockTuple),
                new RuntimeException("test-exception"));
        RuleReflectMethod[] mockRuleMethods = new RuleReflectMethod[]{mockRuleMethod};

        mocks.replay();
View Full Code Here


        mocks.verify();
    }

    public void testInvoke() throws Exception {
        MockControl controlTuple = mocks.createControl(Tuple.class);
        Tuple mockTuple = (Tuple)controlTuple.getMock();
        MockControl controlRuleMethod = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod = (RuleReflectMethod) controlRuleMethod.getMock();
        controlRuleMethod.expectAndReturn(mockRuleMethod.invokeMethod(mockTuple), null);
        RuleReflectMethod[] mockRuleMethods = new RuleReflectMethod[]{mockRuleMethod};

        mocks.replay();

        PojoConsequence pojoConsequence = new PojoConsequence(mockRuleMethods);
View Full Code Here

        mocks.verify();
    }

    public void testInvokeMulti() throws Exception {
        MockControl controlTuple = mocks.createControl(Tuple.class);
        Tuple mockTuple = (Tuple)controlTuple.getMock();
        MockControl controlRuleMethod_1 = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod_1 = (RuleReflectMethod) controlRuleMethod_1.getMock();
        controlRuleMethod_1.expectAndReturn(mockRuleMethod_1.invokeMethod(mockTuple), null);
        MockControl controlRuleMethod_2 = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod_2 = (RuleReflectMethod) controlRuleMethod_2.getMock();
        controlRuleMethod_2.expectAndReturn(mockRuleMethod_2.invokeMethod(mockTuple), null);
        RuleReflectMethod[] mockRuleMethods = new RuleReflectMethod[]{mockRuleMethod_1, mockRuleMethod_2};

        mocks.replay();

        PojoConsequence pojoConsequence = new PojoConsequence(mockRuleMethods);
View Full Code Here

    private static final SocketAddress ADDRESS = new InetSocketAddress(8080);

    public void testServiceLifecycle() throws Exception {
        IoServiceListenerSupport support = new IoServiceListenerSupport();

        MockControl listenerControl = MockControl
                .createStrictControl(IoServiceListener.class);
        IoServiceListener listener = (IoServiceListener) listenerControl
                .getMock();

        // Test activation
        listener.serviceActivated(null, ADDRESS, null, null);

        listenerControl.replay();

        support.add(listener);
        support.fireServiceActivated(null, ADDRESS, null, null);

        listenerControl.verify();

        Assert.assertEquals(1, support.getManagedServiceAddresses().size());
        Assert.assertTrue(support.getManagedServiceAddresses()
                .contains(ADDRESS));

        // Test deactivation & other side effects
        listenerControl.reset();
        listener.serviceDeactivated(null, ADDRESS, null, null);

        listenerControl.replay();
        //// Activate more than once
        support.fireServiceActivated(null, ADDRESS, null, null);
        //// Deactivate
        support.fireServiceDeactivated(null, ADDRESS, null, null);
        //// Deactivate more than once
        support.fireServiceDeactivated(null, ADDRESS, null, null);

        listenerControl.verify();

        Assert.assertEquals(0, support.getManagedServiceAddresses().size());
        Assert.assertFalse(support.getManagedServiceAddresses().contains(
                ADDRESS));
    }
View Full Code Here

    public void testSessionLifecycle() throws Exception {
        IoServiceListenerSupport support = new IoServiceListenerSupport();

        TestSession session = new TestSession(ADDRESS);

        MockControl chainControl = MockControl
                .createStrictControl(IoFilterChain.class);
        IoFilterChain chain = (IoFilterChain) chainControl.getMock();
        session.setFilterChain(chain);

        MockControl listenerControl = MockControl
                .createStrictControl(IoServiceListener.class);
        IoServiceListener listener = (IoServiceListener) listenerControl
                .getMock();

        // Test creation
        listener.sessionCreated(session);
        chain.fireSessionCreated(session);
        chain.fireSessionOpened(session);

        listenerControl.replay();
        chainControl.replay();

        support.add(listener);
        support.fireSessionCreated(session);

        listenerControl.verify();
        chainControl.verify();

        Assert.assertEquals(1, support.getManagedSessions(ADDRESS).size());
        Assert
                .assertTrue(support.getManagedSessions(ADDRESS).contains(
                        session));

        // Test destruction & other side effects
        listenerControl.reset();
        chainControl.reset();
        chain.fireSessionClosed(session);
        listener.sessionDestroyed(session);

        listenerControl.replay();
        //// Activate more than once
        support.fireSessionCreated(session);
        //// Deactivate
        support.fireSessionDestroyed(session);
        //// Deactivate more than once
        support.fireSessionDestroyed(session);

        listenerControl.verify();

        Assert.assertFalse(session.isClosing());
        Assert.assertEquals(0, support.getManagedSessions(ADDRESS).size());
        Assert.assertFalse(support.getManagedSessions(ADDRESS)
                .contains(session));
View Full Code Here

    }

    public void testDisconnectOnUnbind() throws Exception {
        final IoServiceListenerSupport support = new IoServiceListenerSupport();

        MockControl acceptorControl = MockControl
                .createStrictControl(IoAcceptor.class);
        IoAcceptor acceptor = (IoAcceptor) acceptorControl.getMock();

        final TestSession session = new TestSession(acceptor, ADDRESS);

        MockControl configControl = MockControl
                .createStrictControl(IoAcceptorConfig.class);
        IoAcceptorConfig config = (IoAcceptorConfig) configControl.getMock();

        MockControl chainControl = MockControl
                .createStrictControl(IoFilterChain.class);
        IoFilterChain chain = (IoFilterChain) chainControl.getMock();
        session.setFilterChain(chain);

        MockControl listenerControl = MockControl
                .createStrictControl(IoServiceListener.class);
        IoServiceListener listener = (IoServiceListener) listenerControl
                .getMock();

        // Activate a service and create a session.
        listener.serviceActivated(acceptor, ADDRESS, null, config);
        listener.sessionCreated(session);
        chain.fireSessionCreated(session);
        chain.fireSessionOpened(session);

        listenerControl.replay();
        chainControl.replay();

        support.add(listener);
        support.fireServiceActivated(acceptor, ADDRESS, null, config);
        support.fireSessionCreated(session);

        listenerControl.verify();
        chainControl.verify();

        // Deactivate a service and make sure the session is closed & destroyed.
        listenerControl.reset();
        chainControl.reset();

        listener.serviceDeactivated(acceptor, ADDRESS, null, config);
        configControl.expectAndReturn(config.isDisconnectOnUnbind(), true);
        listener.sessionDestroyed(session);
        chain.fireSessionClosed(session);

        listenerControl.replay();
        configControl.replay();
        chainControl.replay();

        new Thread() {
            // Emulate I/O service
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
                support.fireSessionDestroyed(session);
            }
        }.start();

        support.fireServiceDeactivated(acceptor, ADDRESS, null, config);

        Thread.sleep(1000);

        listenerControl.verify();
        configControl.verify();
        chainControl.verify();

        Assert.assertTrue(session.isClosing());
        Assert.assertEquals(0, support.getManagedSessions(ADDRESS).size());
View Full Code Here

    }

    public void testConnectorActivation() throws Exception {
        IoServiceListenerSupport support = new IoServiceListenerSupport();

        MockControl connectorControl = MockControl
                .createStrictControl(IoConnector.class);
        IoConnector connector = (IoConnector) connectorControl.getMock();

        final TestSession session = new TestSession(connector, ADDRESS);

        MockControl chainControl = MockControl
                .createStrictControl(IoFilterChain.class);
        IoFilterChain chain = (IoFilterChain) chainControl.getMock();
        session.setFilterChain(chain);

        MockControl listenerControl = MockControl
                .createStrictControl(IoServiceListener.class);
        IoServiceListener listener = (IoServiceListener) listenerControl
                .getMock();

        // Creating a session should activate a service automatically.
        listener.serviceActivated(connector, ADDRESS, null, null);
        listener.sessionCreated(session);
        chain.fireSessionCreated(session);
        chain.fireSessionOpened(session);

        listenerControl.replay();
        chainControl.replay();

        support.add(listener);
        support.fireSessionCreated(session);

        listenerControl.verify();
        chainControl.verify();

        // Destroying a session should deactivate a service automatically.
        listenerControl.reset();
        chainControl.reset();
        listener.sessionDestroyed(session);
        chain.fireSessionClosed(session);
        listener.serviceDeactivated(connector, ADDRESS, null, null);

        listenerControl.replay();
        chainControl.replay();

        support.fireSessionDestroyed(session);

        listenerControl.verify();
        chainControl.verify();

        Assert.assertEquals(0, support.getManagedSessions(ADDRESS).size());
        Assert.assertFalse(support.getManagedSessions(ADDRESS)
                .contains(session));
View Full Code Here

     */
    public void testContribution() throws Exception
    {
        // Use unordered Mockcontrol, since ordered has a bug with
        // matchers and multiple method calls of a method with return value
        MockControl serverControl = MockControl.createControl(MBeanServer.class);
        addControl(serverControl);
        MBeanServer server = (MBeanServer) serverControl.getMock();

        List contributions = new ArrayList();

        // Add some loggers
        Logger.getLogger("package1.logger1");
View Full Code Here

public class TestSchemaProcessor extends HiveMindTestCase
{

    public void testGetContentTranslator()
    {
        MockControl control = newControl(Module.class);
        Module m = (Module) control.getMock();

        ElementModelImpl em = new ElementModelImpl();

        em.setElementName("fred");
        em.setContentTranslator("smart");

        em.addRule(new CreateObjectRule(StringHolderImpl.class.getName()));

        ReadContentRule rule = new ReadContentRule();
        rule.setPropertyName("value");

        em.addRule(rule);

        em.addRule(new InvokeParentRule("addElement"));

        SchemaImpl schema = new SchemaImpl();
        schema.addElementModel(em);
        schema.setModule(m);

        SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);

        ElementImpl element = new ElementImpl();
        element.setElementName("fred");
        element.setContent("flintstone");

        List elements = Collections.singletonList(element);

        m.resolveType("hivemind.test.services.impl.StringHolderImpl");
        control.setReturnValue(StringHolderImpl.class);

        m.expandSymbols("flintstone", null);
        control.setReturnValue("flintstone");

        m.getTranslator("smart");
        control.setReturnValue(new NullTranslator());

        replayControls();

        p.process(elements, m);
View Full Code Here

        verifyControls();
    }

    public void testGetContentTranslatorUnspecified()
    {
        MockControl control = newControl(Module.class);
        Module m = (Module) control.getMock();

        ElementModelImpl em = new ElementModelImpl();

        em.setElementName("fred");
        // No content handler specified

        em.addRule(new CreateObjectRule(StringHolderImpl.class.getName()));

        ReadContentRule rule = new ReadContentRule();
        rule.setPropertyName("value");

        em.addRule(rule);

        em.addRule(new InvokeParentRule("addElement"));

        SchemaImpl schema = new SchemaImpl();
        schema.addElementModel(em);
        schema.setModule(m);

        SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);

        ElementImpl element = new ElementImpl();
        element.setElementName("fred");
        element.setContent("flintstone");

        List elements = Collections.singletonList(element);

        m.resolveType("hivemind.test.services.impl.StringHolderImpl");
        control.setReturnValue(StringHolderImpl.class);

        m.expandSymbols("flintstone", null);
        control.setReturnValue("flintstone");

        replayControls();

        p.process(elements, m);
View Full Code Here

TOP

Related Classes of org.easymock.MockControl

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.