Package org.jmock

Examples of org.jmock.Mockery


        context.assertIsSatisfied();
    }

    public void testNotShouldAddRemoteAndRemoteHomeAnnotationsForLocalBeans() throws Exception {
        Mockery context = new Mockery();
        final IJDTFacade facade = context.mock(IJDTFacade.class);

        AppModule module = new TestFixture().getAppModule("single-session-bean-local.xml", null);
        new SessionBeanRemoteAnnotationAdder(facade).convert(module);

        context.assertIsSatisfied();
    }
View Full Code Here


        context.assertIsSatisfied();
    }

    public void testNotShouldAddRemoteAndRemoteHomeAnnotationsForBadSessionBean() throws Exception {
        Mockery context = new Mockery();
        final IJDTFacade facade = context.mock(IJDTFacade.class);

        AppModule module = new TestFixture().getAppModule("badsession-ejb-jar.xml", null);
        new SessionBeanRemoteAnnotationAdder(facade).convert(module);

        context.assertIsSatisfied();
    }
View Full Code Here

        context.assertIsSatisfied();
    }

    public void testNotShouldAddRemoteAndRemoteHomeAnnotationsForEmptySessionBean() throws Exception {
        Mockery context = new Mockery();
        final IJDTFacade facade = context.mock(IJDTFacade.class);

        AppModule module = new TestFixture().getAppModule("emptysession-ejb-jar.xml", null);
        new SessionBeanRemoteAnnotationAdder(facade).convert(module);

        context.assertIsSatisfied();
    }
View Full Code Here

    private HashMap<Thread, Throwable> exceptions = new HashMap<Thread, Throwable>();

    @Test
    public void testShutdownWithoutTransportRestart() throws Exception {

        Mockery context = new Mockery() {{
            setImposteriser(ClassImposteriser.INSTANCE);
        }};

        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                LOG.error("unexpected exception {} on thread {}", e, t);
                exceptions.put(t, e);
            }
        });

        final BrokerService brokerService = context.mock(BrokerService.class);
        final JDBCPersistenceAdapter jdbcPersistenceAdapter = context.mock(JDBCPersistenceAdapter.class);
        final Locker locker = context.mock(Locker.class);

        final States jdbcConn = context.states("jdbc").startsAs("down");
        final States broker = context.states("broker").startsAs("started");

        // simulate jdbc up between hasLock and checkpoint, so hasLock fails to verify
        context.checking(new Expectations() {{
            allowing(brokerService).isRestartAllowed();
            will(returnValue(false));
            allowing(brokerService).stopAllConnectors(with(any(ServiceStopper.class)));
            allowing(brokerService).getPersistenceAdapter();
            will(returnValue(jdbcPersistenceAdapter));
            allowing(jdbcPersistenceAdapter).getLocker();
            will(returnValue(locker));
            allowing(locker).keepAlive();
            when(jdbcConn.is("down"));
            will(returnValue(true));
            allowing(locker).keepAlive();
            when(jdbcConn.is("up"));
            will(returnValue(false));

            allowing(jdbcPersistenceAdapter).checkpoint(with(true));
            then(jdbcConn.is("up"));
            allowing(brokerService).stop();
            then(broker.is("stopped"));

        }});

        JDBCIOExceptionHandler underTest = new JDBCIOExceptionHandler();
        underTest.setBrokerService(brokerService);

        try {
            underTest.handle(new IOException());
            fail("except suppress reply ex");
        } catch (SuppressReplyException expected) {
        }

        assertTrue("broker stopped state triggered", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                LOG.info("broker state {}", broker);
                return broker.is("stopped").isActive();
            }
        }));
        context.assertIsSatisfied();

        assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
    }
View Full Code Here

        assertEquals("no adjust when under limit", 0, callDiffOffset(underTest,System.currentTimeMillis() - 40000 ));
    }

    public long callDiffOffset(LeaseDatabaseLocker underTest, final long dbTime) throws Exception {

        Mockery context = new Mockery() {{
            setImposteriser(ClassImposteriser.INSTANCE);
        }};
        final Statements statements = context.mock(Statements.class);
        final JDBCPersistenceAdapter jdbcPersistenceAdapter = context.mock(JDBCPersistenceAdapter.class);
        final Connection connection = context.mock(Connection.class);
        final PreparedStatement preparedStatement = context.mock(PreparedStatement.class);
        final ResultSet resultSet = context.mock(ResultSet.class);
        final Timestamp timestamp = context.mock(Timestamp.class);

        context.checking(new Expectations() {{
            allowing(jdbcPersistenceAdapter).getStatements();
            will(returnValue(statements));
            allowing(jdbcPersistenceAdapter);
            allowing(statements);
            allowing(connection).prepareStatement(with(any(String.class)));
View Full Code Here

    }

    @Test
    public void testBuildResourceWithNoMethodsWithMock() throws Exception {
        WADLGenerator generator = new WADLGenerator();
        Mockery mockContext = new Mockery() {
            {
                setImposteriser(ClassImposteriser.INSTANCE);
            }
        };

        final ClassMetadata metadata = mockContext.mock(ClassMetadata.class);

        mockContext.checking(new Expectations() {
            {
                oneOf(metadata).getResourceClass();
                will(returnValue(null));

                oneOf(metadata).getPath();
                will(returnValue("myPath"));

                oneOf(metadata).getResourceMethods();
                will(returnValue(null));

                oneOf(metadata).getInjectableFields();
                will(returnValue(null));

                oneOf(metadata).getSubResourceMethods();
                will(returnValue(null));

                oneOf(metadata).getSubResourceLocators();
                will(returnValue(null));
            }
        });

        Resource actualRes = generator.buildResource(metadata);
        assertNull(actualRes.getId());
        assertEquals(MediaType.APPLICATION_FORM_URLENCODED, actualRes.getQueryType());
        assertEquals(0, actualRes.getType().size());
        assertEquals(0, actualRes.getDoc().size());
        assertEquals("myPath", actualRes.getPath());
        assertEquals(0, actualRes.getParam().size());
        assertEquals(0, actualRes.getMethodOrResource().size());

        mockContext.assertIsSatisfied();
    }
View Full Code Here

    }

    @Test
    public void testBuildResourceWithMock() throws Exception {
        WADLGenerator generator = new WADLGenerator();
        Mockery mockContext = new Mockery() {
            {
                setImposteriser(ClassImposteriser.INSTANCE);
            }
        };

        final ClassMetadata metadata = mockContext.mock(ClassMetadata.class);
        final MethodMetadata methodMeta = mockContext.mock(MethodMetadata.class);
        final java.lang.reflect.Method method =
            BasicResourceWithVoidReturn.class.getMethod("basicReturn");

        mockContext.checking(new Expectations() {
            {
                oneOf(metadata).getResourceClass();
                will(returnValue(BasicResourceWithVoidReturn.class));

                oneOf(metadata).getPath();
                will(returnValue("myResourcePath"));

                oneOf(metadata).getResourceMethods();
                will(returnValue(Collections.singletonList(methodMeta)));

                oneOf(methodMeta).getHttpMethod();
                will(returnValue(HttpMethod.GET));

                oneOf(methodMeta).getFormalParameters();
                will(returnValue(Collections.emptyList()));

                oneOf(methodMeta).getProduces();
                will(returnValue(Collections.emptySet()));

                exactly(2).of(methodMeta).getReflectionMethod();
                will(returnValue(method));

                oneOf(methodMeta).getFormalParameters();
                will(returnValue(null));

                oneOf(metadata).getInjectableFields();
                will(returnValue(null));

                oneOf(metadata).getSubResourceMethods();
                will(returnValue(null));

                oneOf(metadata).getSubResourceLocators();
                will(returnValue(null));
            }
        });

        Resource actualRes = generator.buildResource(metadata);
        assertNull(actualRes.getId());
        assertEquals(MediaType.APPLICATION_FORM_URLENCODED, actualRes.getQueryType());
        assertEquals(0, actualRes.getType().size());
        assertEquals(0, actualRes.getDoc().size());
        assertEquals("myResourcePath", actualRes.getPath());
        assertEquals(0, actualRes.getParam().size());

        /* method */
        assertEquals(1, actualRes.getMethodOrResource().size());
        Method m = ((Method)actualRes.getMethodOrResource().get(0));
        assertEquals(HttpMethod.GET, m.getName());
        assertNull(m.getId());
        assertEquals(0, m.getDoc().size());
        assertNull(m.getHref());
        assertNull(m.getRequest());
        assertEquals(1, m.getResponse().size());
        List<Response> resps = m.getResponse();
        assertEquals(Collections.singletonList(Long.valueOf(204)), resps.get(0).getStatus());
        assertEquals(0, resps.get(0).getAny().size());
        assertEquals(0, resps.get(0).getDoc().size());
        assertEquals(0, resps.get(0).getOtherAttributes().size());
        assertEquals(0, resps.get(0).getParam().size());

        mockContext.assertIsSatisfied();
    }
View Full Code Here

    }

    @Test
    public void testBuildBasicMethodMetadataWithMock() throws Exception {
        WADLGenerator generator = new WADLGenerator();
        Mockery mockContext = new Mockery() {
            {
                setImposteriser(ClassImposteriser.INSTANCE);
            }
        };
        final MethodMetadata metadata = mockContext.mock(MethodMetadata.class);
        final ClassMetadata classMeta = mockContext.mock(ClassMetadata.class);
        final java.lang.reflect.Method method =
            BasicResourceWithVoidReturn.class.getMethod("basicReturn");

        mockContext.checking(new Expectations() {
            {
                oneOf(metadata).getHttpMethod();
                will(returnValue("myHttpMethod"));

                oneOf(metadata).getFormalParameters();
                will(returnValue(null));

                oneOf(metadata).getProduces();
                will(returnValue(Collections.emptySet()));

                exactly(2).of(metadata).getReflectionMethod();
                will(returnValue(method));
            }
        });

        Method m = generator.buildMethod(classMeta, metadata);
        assertEquals("myHttpMethod", m.getName());
        assertEquals(0, m.getDoc().size());
        assertEquals(0, m.getAny().size());
        assertNull(m.getHref());
        assertNull(m.getId());
        assertNull(m.getRequest());
        assertEquals(1, m.getResponse().size());
        List<Response> resps = m.getResponse();
        assertEquals(Collections.singletonList(Long.valueOf(204)), resps.get(0).getStatus());
        assertEquals(0, resps.get(0).getAny().size());
        assertEquals(0, resps.get(0).getDoc().size());
        assertEquals(0, resps.get(0).getOtherAttributes().size());
        assertEquals(0, resps.get(0).getParam().size());

        mockContext.assertIsSatisfied();
    }
View Full Code Here

    }

    @Test
    public void testBuildBasicRequestWithMock() {
        WADLGenerator generator = new WADLGenerator();
        Mockery mockContext = new Mockery() {
            {
                setImposteriser(ClassImposteriser.INSTANCE);
            }
        };
        final MethodMetadata metadata = mockContext.mock(MethodMetadata.class);
        final ClassMetadata classMeta = mockContext.mock(ClassMetadata.class);

        mockContext.checking(new Expectations() {
            {
                oneOf(metadata).getFormalParameters();
                will(returnValue(null));
            }
        });

        Request r = generator.buildRequest(classMeta, metadata);
        /*
         * should be null otherwise a no-value request element might be added
         */
        assertNull(r);
        mockContext.assertIsSatisfied();
    }
View Full Code Here

public class ApacheClientTest extends BaseTest {

    @Override
    public void setUp() throws Exception {
        super.setUp();
        Mockery mockery = new Mockery();
        final RuntimeContext context = mockery.mock(RuntimeContext.class);
        mockery.checking(new Expectations() {{
            allowing(context).getAttribute(WinkConfiguration.class); will(returnValue(null));
        }});
       
        RuntimeContextTLS.setRuntimeContext(context);
    }
View Full Code Here

TOP

Related Classes of org.jmock.Mockery

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.