[
https://issues.apache.org/jira/browse/ISIS-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14048598#comment-14048598
]
Dan Haywood commented on ISIS-813:
----------------------------------
Implemented, example in todo app integration tests:
/**
* This test demonstrates how a single service can be replaced, eg to
use a mock.
*/
public static class Completed2 extends ToDoItemIntegTest {
private EventBusService originalEventBusService;
@Mock
private EventBusService mockEventBusService;
@Before
public void setUpMockEventBusService() throws Exception {
originalEventBusService =
scenarioExecution().service(EventBusService.class);
context.checking(new Expectations() {{
ignoring(mockEventBusService).register(with(any(Object.class)));
ignoring(mockEventBusService).unregister(with(any(Object.class)));
}});
scenarioExecution().replaceService(originalEventBusService,
mockEventBusService);
scenarioExecution().closeSession();
scenarioExecution().openSession();
}
@After
public void reinstateOriginalEventBusService() throws Exception {
scenarioExecution().replaceService(mockEventBusService,
originalEventBusService);
}
@Test
public void raisesEvent() throws Exception {
// then
context.checking(new Expectations() {{
oneOf(mockEventBusService).post(with(completedEvent()));
}});
// when
toDoItem.completed();
}
private Matcher<Object> completedEvent() {
return new TypeSafeMatcher<Object>() {
@Override
protected boolean matchesSafely(Object item) {
return item instanceof ToDoItem.CompletedEvent;
}
@Override
public void describeTo(Description description) {
description.appendText(" instance of a
ToDoItem.CompletedEvent");
}
};
}
}
> Provide the ability to mock out domain services in integration tests.
> ---------------------------------------------------------------------
>
> Key: ISIS-813
> URL: https://issues.apache.org/jira/browse/ISIS-813
> Project: Isis
> Issue Type: New Feature
> Components: Core
> Affects Versions: core-1.5.0
> Reporter: Dan Haywood
> Assignee: Dan Haywood
> Priority: Minor
> Fix For: core-1.6.0
>
>
> As inspired by this thread: http://markmail.org/thread/v3qptyjsrvsxi2j2
> Usually in an integration test we want the "real" implementations of our
> domain services. That's certainly the case for repositories etc that connect
> to "our" database.
> But for domain services that connect to the outside world (eg hit an external
> web service), it'd be useful to be able to replace the real implementation
> with a mock, and have this mock be used in the running system instead.
> That mock would probably need to have a fairy liberal set of expectations, eg
> (in JMock) use allowing() or ignoring(); so I can see a bit of
> experimentation might be needed to make this work smoothly. But it
> undoubtedly would be valuable.
--
This message was sent by Atlassian JIRA
(v6.2#6252)