@Test
public void testAdvisedMockEndpoints() throws Exception {
// advice the start route using the inlined AdviceWith lambda style route builder
// which has extended capabilities than the regular route builder
AdviceWith.adviceWith(context, "start", a ->
// mock all endpoints
a.mockEndpoints());
getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("direct:foo"));
assertNotNull(context.hasEndpoint("log:foo"));
assertNotNull(context.hasEndpoint("mock:result"));
// all the endpoints was mocked
assertNotNull(context.hasEndpoint("mock:direct:start"));
assertNotNull(context.hasEndpoint("mock:direct:foo"));
assertNotNull(context.hasEndpoint("mock:log:foo"));
}
@Test
public void testAdvisedMockEndpoints() throws Exception {
// advice the start route using the inlined AdviceWith lambda style route builder
// which has extended capabilities than the regular route builder
AdviceWith.adviceWith(context, "start", a ->
// mock all endpoints
a.mockEndpoints());
getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("direct:foo"));
assertNotNull(context.hasEndpoint("log:foo"));
assertNotNull(context.hasEndpoint("mock:result"));
// all the endpoints was mocked
assertNotNull(context.hasEndpoint("mock:direct:start"));
assertNotNull(context.hasEndpoint("mock:direct:foo"));
assertNotNull(context.hasEndpoint("mock:log:foo"));
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
モックエンドポイントには、mock:direct:foo などの URI mock:<endpoint> が指定されていることに注意してください。Camel は、モックされているエンドポイントを INFO レベルでログに記録します。
INFO Adviced endpoint [direct://foo] with mock endpoint [mock:direct:foo]
INFO Adviced endpoint [direct://foo] with mock endpoint [mock:direct:foo]
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@Test
public void testAdvisedMockEndpointsWithPattern() throws Exception {
// advice the start route using the inlined AdviceWith lambda style route builder
// which has extended capabilities than the regular route builder
AdviceWith.adviceWith(context, "start", a ->
// mock only log endpoints
a.mockEndpoints("log*"));
// now we can refer to log:foo as a mock and set our expectations
getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("direct:foo"));
assertNotNull(context.hasEndpoint("log:foo"));
assertNotNull(context.hasEndpoint("mock:result"));
// only the log:foo endpoint was mocked
assertNotNull(context.hasEndpoint("mock:log:foo"));
assertNull(context.hasEndpoint("mock:direct:start"));
assertNull(context.hasEndpoint("mock:direct:foo"));
}
@Test
public void testAdvisedMockEndpointsWithPattern() throws Exception {
// advice the start route using the inlined AdviceWith lambda style route builder
// which has extended capabilities than the regular route builder
AdviceWith.adviceWith(context, "start", a ->
// mock only log endpoints
a.mockEndpoints("log*"));
// now we can refer to log:foo as a mock and set our expectations
getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("direct:foo"));
assertNotNull(context.hasEndpoint("log:foo"));
assertNotNull(context.hasEndpoint("mock:result"));
// only the log:foo endpoint was mocked
assertNotNull(context.hasEndpoint("mock:log:foo"));
assertNull(context.hasEndpoint("mock:direct:start"));
assertNull(context.hasEndpoint("mock:direct:foo"));
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow