Package org.mule.munit.runner.mule.result

Examples of org.mule.munit.runner.mule.result.TestResult


    @org.junit.Test
    public void testRunSuccessful() throws MuleException
    {
        MunitTest test = new MockedTest(buildList(before), testFlow, buildList(after), handler);

        TestResult testResult = test.run();

        verify(testFlow, times(1)).process(muleEvent);
        verify(before, times(1)).process(muleEvent);
        verify(after, times(1)).process(muleEvent);

        assertTrue(testResult.hasSucceeded());
    }
View Full Code Here


    public void testRunWithFailure() throws MuleException
    {
        MunitTest test = new MockedTest(buildList(before), testFlow, buildList(after), handler);

        when(testFlow.process(muleEvent)).thenThrow(new AssertionError("Error"));
        TestResult testResult = test.run();

        verify(testFlow, times(1)).process(muleEvent);
        verify(before, times(1)).process(muleEvent);
        verify(after, times(1)).process(muleEvent);

        assertFalse(testResult.hasSucceeded());
        assertEquals("Error", testResult.getFailure().getShortMessage());
    }
View Full Code Here

        MunitTest test = new MockedTest(buildList(before), testFlow, buildList(after), handler);

        when(processorManager.getCalls()).thenReturn(createTestCalls());
        when(testFlow.process(muleEvent)).thenThrow(new DefaultMuleException("Error"));

        TestResult testResult = test.run();

        verify(testFlow, times(1)).process(muleEvent);
        verify(before, times(1)).process(muleEvent);
        verify(after, times(1)).process(muleEvent);

        assertFalse(testResult.hasSucceeded());
        assertEquals("Error", testResult.getError().getShortMessage());
        assertTrue(testResult.getError().getFullMessage().contains("namespace2"));
        assertTrue(testResult.getError().getFullMessage().contains("mp2"));
        assertTrue(testResult.getError().getFullMessage().contains("namespace1"));
        assertTrue(testResult.getError().getFullMessage().contains("mp1"));
    }
View Full Code Here

    {
        final MunitTest test = new MockedTest(Collections.<MunitFlow>emptyList(), testFlow, Collections.<MunitFlow>emptyList(), handler);
        when(testFlow.process(Matchers.<MuleEvent>anyObject())).thenThrow(new DefaultMuleException(new IllegalArgumentException()));
        when(testFlow.expectException(Matchers.<Exception>anyObject(), Matchers.<MuleEvent>anyObject())).thenReturn(true);

        final TestResult testResult = test.run();

        assertTrue(testResult.hasSucceeded());
    }
View Full Code Here

    {
        final MunitTest test = new MockedTest(Collections.<MunitFlow>emptyList(), testFlow, Collections.<MunitFlow>emptyList(), handler);
        when(testFlow.process(Matchers.<MuleEvent>anyObject())).thenThrow(new DefaultMuleException(new IllegalArgumentException()));
        when(testFlow.expectException(Matchers.<Exception>anyObject(), Matchers.<MuleEvent>anyObject())).thenReturn(false);

        final TestResult testResult = test.run();

        assertFalse(testResult.hasSucceeded());
    }
View Full Code Here

        final MunitTest test = new MockedTest(Collections.<MunitFlow>emptyList(), testFlow, Collections.<MunitFlow>emptyList(), handler);
        testFlow.setExpectExceptionThatSatisfies("something");
        when(testFlow.getExpectExceptionThatSatisfies()).thenReturn("something");
        when(testFlow.expectException(Matchers.<Exception>anyObject(), Matchers.<MuleEvent>anyObject())).thenReturn(false);

        final TestResult testResult = test.run();

        assertFalse(testResult.hasSucceeded());
        assertTrue(testResult.getFailure().getFullMessage().contains("something"));
    }
View Full Code Here

    public void callNotificationAndExecuteTestsWhenRun() throws Exception
    {
        MunitTest test = mock(MunitTest.class);
        NotificationListener listener = mock(NotificationListener.class);

        TestResult testResult = new TestResult("testResult");

        when(test.run()).thenReturn(testResult);

        MunitSuite suite = new MunitSuite("testSuite");
        suite.add(test);
View Full Code Here

        SuiteResult result = new SuiteResult(name);

        for (MunitTest test : munitTests)
        {
            notificationListener.notifyStartOf(test);
            TestResult testResult = test.run();
            result.add(testResult);
            notificationListener.notify(testResult);
        }

        notificationListener.notifyEnd(result);
View Full Code Here

        return test.getName();
    }

    public TestResult run()
    {
        TestResult result = new TestResult(getName());
        if (test.isIgnore())
        {
            result.setSkipped(true);
            return result;
        }

        long start = System.currentTimeMillis();
        MuleEvent event = muleEvent();

        try
        {
            run(event, before);
            showDescription();
            test.process(event);
            if (StringUtils.isNotBlank(test.getExpectExceptionThatSatisfies()))
            {
                fail("Exception matching '" + test.getExpectExceptionThatSatisfies() + "', but wasn't thrown");
            }
        }
        catch (final AssertionError t)
        {
            result.setFailure(buildNotifcationFrom(t));
        }
        catch (final MuleException e)
        {
            try
            {
                if (!test.expectException(e, event))
                {
                    e.setStackTrace(buildMuleStackTrace(event.getMuleContext())
                                            .toArray(new StackTraceElement[] {}));
                    result.setError(buildNotifcationFrom(e));
                }
            }
            catch (final AssertionError t)
            {
                t.setStackTrace(buildMuleStackTrace(event.getMuleContext())
                                        .toArray(new StackTraceElement[] {}));
                result.setFailure(buildNotifcationFrom(t));
            }
        }
        finally
        {
            MunitCore.reset(event.getMuleContext());
            runAfter(result, event);
        }

        long end = System.currentTimeMillis();
        result.setTime(new Float(end - start) / 1000);
        return result;

    }
View Full Code Here

TOP

Related Classes of org.mule.munit.runner.mule.result.TestResult

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.