FabricService fabricService = this.fabricService.getOptional();
// lets find the camel contexts to test in this container
MBeanServer mbeanServerValue = mbeanServer;
if (mbeanServerValue != null && fabricService != null) {
Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames();
for (CamelContext camelContext : camelContexts.values()) {
String camelContextID = camelContext.getName();
// check we only add testing stuff to each context once
if (camelContext instanceof ModelCamelContext) {
final ModelCamelContext modelCamelContext = (ModelCamelContext) camelContext;
List<RouteDefinition> routeDefinitions = modelCamelContext.getRouteDefinitions();
if (camelContextsConfigured.add(camelContextID)) {
NodeIdFactory nodeIdFactory = camelContext.getNodeIdFactory();
if (mockInputs || mockOutputs) {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
modelCamelContext.stopRoute(routeId);
final String routeKey = camelContextID + "." + routeId;
LOG.info("Mocking Camel route: " + routeKey);
routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
if (mockOutputs) {
modelCamelContext.addRegisterEndpointCallback(strategy);
}
}
});
// the advised route is automatic restarted
}
}
String path = messageFolder;
if (Strings.isNotBlank(path)) {
path += "/";
}
path += camelContextID;
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
try {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
String routePath = path + "/" + routeId + "/";
List<FromDefinition> inputs = routeDefinition.getInputs();
for (FromDefinition input : inputs) {
Endpoint endpoint = input.getEndpoint();
if (endpoint == null) {
String uri = input.getUri();
if (Strings.isNullOrBlank(uri)) {
String ref = input.getRef();
if (Strings.isNotBlank(ref)) {
uri = "ref:" + ref;
}
}
if (Strings.isNotBlank(uri)) {
endpoint = camelContext.getEndpoint(uri);
}
}
if (endpoint == null) {
LOG.warn("Cannot find endpoint, uri or ref of input " + input + " on route " + routeId + " camelContext: " + camelContextID);
} else {
for (String configFile : configurationFileNames) {
if (configFile.startsWith(routePath)) {
LOG.info("Sending file: " + configFile + " to " + endpoint);
byte[] data = effectiveProfile.getFileConfiguration(configFile);
if (data != null) {
// lest send this message to this endpoint
producerTemplate.sendBody(endpoint, data);
}
}