이 끝점의 작동 방식 은 아직 작동하지 않습니다. 다르게 발생하는 것은 Mock 엔드포인트가 삽입되고 메시지를 먼저 수신한 다음 메시지를 대상 엔드포인트에 위임한다는 것입니다. 이를 일종의 intercept 및 delegate 또는 endpoint listener로 볼 수 있습니다.
Copy to ClipboardCopied!Toggle word wrapToggle overflow
그 런 다음 다음과 같이 Camel의 조언 을 사용하여 단위 테스트에서 지정된 경로의 모든 엔드 포인트를 이동할 수 있습니다.
모든 끝점 을 모방하는 조언
public void testAdvisedMockEndpoints() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock all endpoints
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"));
}
public void testAdvisedMockEndpoints() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock all endpoints
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 끝점에는 URI mock:< endpoint>(예:mock:direct:foo )가 제공됩니다. INFO (정보) 수준에서 Camel 로그:
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
참고
모킹된 엔드포인트는 매개변수가없는 것입니다. 분말된 엔드 포인트에는 매개변수가 제거되었습니다. 예를 들어, 끝점 log:foo?showAll=true 는 다음 끝점 mock:log:foo 로 이동합니다. 매개 변수가 제거되었습니다.
또한 패턴을 사용하여 특정 엔드 포인트를 모을 수도 있습니다. 예를 들어 다음과 같이 모든 로그 끝점을 모으려면 다음을 수행하십시오.
adviceWith mocking only log endpoints using a pattern
public void testAdvisedMockEndpointsWithPattern() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock only log endpoints
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"));
}
public void testAdvisedMockEndpointsWithPattern() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock only log endpoints
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
지원되는 패턴은 와일드카드 또는 정규식일 수 있습니다. Intercept에서 이에 대한 자세한 내용은 Camel에서 사용하는 것과 동일한 일치 함수로 참조하십시오.
참고
mocking 엔드포인트는 메시지가 모방에 도착하면 복사되도록 합니다. 즉 Camel은 더 많은 메모리를 사용합니다. 많은 메시지에서 보낼 때 적합하지 않을 수 있습니다.