-
Notifications
You must be signed in to change notification settings - Fork 13
Test your plugins
Ilya edited this page Aug 27, 2014
·
6 revisions
You can test your aggregators and processors using Camelot testing api.
First of all add dependency on camelot-test module
<dependency>
<groupId>ru.yandex.qatools.camelot</groupId>
<artifactId>camelot-test</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
Then you should specify in camelot.xml
plugins which you need to test
<?xml version="1.0" encoding="UTF-8"?>
<plugins-config xmlns="urn:config.camelot.qatools.yandex.ru">
<source>
<plugin id="test-processor">
<processor>ru.yandex.qatools.camelot.test.TestProcessor</processor>
</plugin>
<plugin id="test-aggregator" source="test-processor">
<aggregator>ru.yandex.qatools.camelot.test.TestAggregator</aggregator>
</plugin>
</source>
</plugins-config>
Finally you can use Camelot JUnit Runner to start camelot context and test your plugins:
@RunWith(CamelotTestRunner.class)
public class PluginTest {
@PluginMock(id = "test-aggregator")
TestAggregator aggMock;
@PluginMock(id = "test-processor")
TestProcessor prcMock;
@Helper
TestHelper helper;
@AggregatorState("test-aggregator")
AggregatorStateStorage aggStates;
@Test
public void testRoute() throws Exception {
helper.send("test", UUID, "uuid");
verify(prcMock, timeout(3000)).onNodeEvent(eq("test"));
verify(aggMock, timeout(3000)).onNodeEvent(any(TestState.class), eq("test-processed"));
TestState state = aggStates.get(TestState.class, "uuid");
assertNotNull(state);
assertEquals("test-processed", state.message);
}
}
You can inject the following beans to you tests:
- PluginMock
- Helper
- AggregatorState
In test you can override some camelot components. For example if your processor checks a page response code, you can always override this behaviour using your mocked components.
@CamelotTestConfig(components = {
@OverrideComponent(from = HttpClient.class, to = TestHttpClient.class),
@OverrideComponent(from = WebDriverAdapter.class, to = TestWebDriverAdapter.class)
})
public class TestHttpClient extends HttpClient {
@Override
public int getStatusCode(Link link) throws IOException {
return HttpStatus.SC_OK;
}
}