use of won.protocol.service.WonNodeInfoBuilder in project webofneeds by researchstudio-sat.
the class WonMessageRoutesTest method configureMockEndpoint.
@Before
public void configureMockEndpoint() throws Exception {
camelContext.setTracing(true);
ModelCamelContext context = (ModelCamelContext) camelContext;
AdviceWith.adviceWith(context.getRouteDefinition("activemq:queue:" + FROM_NODE_QUEUENAME), context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:fromNodeMock");
}
});
AdviceWith.adviceWith(context.getRouteDefinition("activemq:queue:" + FROM_OWNER_QUEUENAME), context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:fromOwnerMock");
}
});
AdviceWith.adviceWith(context.getRouteDefinition("activemq:queue:" + FROM_MATCHER_QUEUENAME), context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:fromMatcherMock");
}
});
// for some reason, we have to add the advice to each route
// don't try to do it by iterating over routes etc. Doesn't work.
AdviceWith.adviceWith(context.getRouteDefinition("direct:sendToOwner"), context, adviceForOwnerProtocolOut());
AdviceWith.adviceWith(context.getRouteDefinition("direct:reactToMessage"), context, adviceForMatcherProtocolOut());
//
// MockEndpoint intercepting messages to owners
toOwnerMockEndpoint.reset();
toOwnerMockEndpoint.setResultWaitTime(5000);
toOwnerMockEndpoint.setReporter(exchange -> {
Optional<String> ownerAppId = WonCamelHelper.getOwnerApplicationId(exchange);
String ownerAppString = ownerAppId.isPresent() ? " [" + ownerAppId.get() + "]" : "";
logMessageRdf(makeMessageBox("message NODE => OWNER" + ownerAppString), WonMessage.of(RdfUtils.readDatasetFromString((String) exchange.getIn().getBody(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE)));
});
//
// MockEndpoint intercepting messages to registered matchers
// camelContext.addRoutes(new RouteBuilder() {
// @Override
// public void configure() throws Exception {
// from("direct:toMatcherMock").to("mock:seda:MatcherProtocolOut");
// }
// });
toMatcherMockEndpoint.reset();
toMatcherMockEndpoint.setResultWaitTime(5000);
toMatcherMockEndpoint.setReporter(exchange -> {
try {
Optional<String> ownerAppId = WonCamelHelper.getOwnerApplicationId(exchange);
Optional<String> wonMessageString = Optional.ofNullable((String) exchange.getIn().getBody());
if (wonMessageString.isPresent() && wonMessageString.get().trim().length() > 0) {
logMessageRdf(makeMessageBox("message NODE => MATCHER"), WonMessage.of(RdfUtils.readDatasetFromString(wonMessageString.get(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE)));
} else {
logger.debug(makeMessageBox("message NODE => MATCHER (no WonMessage)"));
}
} catch (WonMessageNotWellFormedException e) {
logger.info("swallowed WonMessageNotWellFormedException - this can happen");
}
});
Mockito.when(wonNodeInformationService.generateAtomURI(any(URI.class))).then(x -> newAtomURI());
Mockito.when(wonNodeInformationService.generateConnectionURI(any(URI.class))).then(invocation -> newConnectionURI((URI) invocation.getArguments()[0]));
Mockito.when(wonNodeInformationService.generateAtomURI()).then(x -> newAtomURI());
Mockito.when(wonNodeInformationService.getWonNodeInformation(URI_NODE_1)).then(x -> new WonNodeInfoBuilder().setAtomURIPrefix(URI_NODE_1 + "/atom").setWonNodeURI(URI_NODE_1.toString()).setConnectionURIPrefix(URI_NODE_1 + "/connection").build());
Mockito.when(uriService.isAtomURI(any(URI.class))).thenReturn(true);
Mockito.when(uriService.getAtomResourceURIPrefix()).then(x -> URI_NODE_1.toString() + "/atom");
Mockito.when(uriService.getResourceURIPrefix()).then(x -> URI_NODE_1.toString());
Mockito.when(uriService.createSysInfoGraphURIForAtomURI(any(URI.class))).thenCallRealMethod();
// Mockito.when(linkedDataSource.getDataForResource(any(URI.class),
// any(URI.class)))
// .thenThrow(new UnsupportedOperationException("cannot do linkeddata lookups
// during tests"));
// Mockito.when(linkedDataSource.getDataForResource(any(URI.class)))
// .thenThrow(new UnsupportedOperationException("cannot do linkeddata lookups
// during tests"));
Mockito.when(linkedDataSource.getDataForPublicResource(eq(URI_NODE_1))).then(x -> linkedDataService.getNodeDataset());
mockForMessageFromNode1ToNode1();
}
Aggregations