Java Code Examples for org.apache.camel.CamelContext#getName()

The following examples show how to use org.apache.camel.CamelContext#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NagiosIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendToNagios() throws Exception {

    CamelContext camelctx = createCamelContext();

    MessagePayload expectedPayload = new MessagePayload("localhost", Level.OK, camelctx.getName(),  "Hello Nagios");

    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.allMessages().body().isInstanceOf(String.class);
    mock.expectedBodiesReceived("Hello Nagios");

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBody("direct:start", "Hello Nagios");

        mock.assertIsSatisfied();

        Mockito.verify(nagiosPassiveCheckSender, Mockito.times(1)).send(expectedPayload);
    } finally {
        camelctx.close();
    }
}
 
Example 2
Source File: NagiosIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendToNagiosWarn() throws Exception {

    CamelContext camelctx = createCamelContext();

    MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.WARNING, camelctx.getName(),  "Hello Nagios");

    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Hello Nagios");

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:start", "Hello Nagios", NagiosConstants.LEVEL, Level.WARNING);

        mock.assertIsSatisfied();
        Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1);
    } finally {
        camelctx.close();
    }
}
 
Example 3
Source File: NagiosIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendToNagiosWarnAsText() throws Exception {

    CamelContext camelctx = createCamelContext();

    MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.WARNING, camelctx.getName(),  "Hello Nagios");

    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Hello Nagios");

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:start", "Hello Nagios", NagiosConstants.LEVEL, "WARNING");

        mock.assertIsSatisfied();

        Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1);
    } finally {
        camelctx.close();
    }
}
 
Example 4
Source File: MicroProfileMetricsIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private void assertComplexMetricValue(CamelContext camelctx, String metricName, Number metricValue) throws Exception {
    String metrics = getMetrics();

    JsonParser parser = Json.createParser(new StringReader(metrics));
    Assert.assertTrue("Metrics endpoint content is empty", parser.hasNext());
    parser.next();

    JsonObject jsonObject = parser.getObject();
    JsonNumber result = null;
    String[] nameParts = metricName.split("\\.");
    for (int i = 0; i < nameParts.length; i++) {
        String jsonKey = i + 1 == nameParts.length ? nameParts[i] + ";camelContext=" + camelctx.getName() : nameParts[i];

        if (i + 1 == nameParts.length) {
            result = jsonObject.getJsonNumber(jsonKey);
            break;
        } else {
            jsonObject = jsonObject.getJsonObject(jsonKey);
        }
    }

    Assert.assertNotNull("Expected to find metric " + metricName, result);
    Assert.assertEquals("Expected metric " + metricName + " to have value " + metricValue, metricValue, result.intValue());
}
 
Example 5
Source File: CamelContextActivationService.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    ClassLoader tccl = SecurityActions.getContextClassLoader();
    for (SpringCamelContextBootstrap bootstrap : bootstraps) {
        try {
            SecurityActions.setContextClassLoader(bootstrap.getClassLoader());
            try {
                for (CamelContext camelctx : bootstrap.createSpringCamelContexts()) {
                    try {
                        ProxyUtils.invokeProxied(new ProxiedAction() {
                            @Override
                            public void run() throws Exception {
                                camelctx.start();
                            }
                        }, bootstrap.getClassLoader());
                    } catch (Exception ex) {
                        throw new StartException("Cannot start camel context: " + camelctx.getName(), ex);
                    }
                }
            } catch (Exception e) {
                throw new StartException("Cannot create camel context: " + runtimeName, e);
            }
        } finally {
            SecurityActions.setContextClassLoader(tccl);
        }
    }
}
 
Example 6
Source File: NagiosIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendTwoToNagios() throws Exception {

    CamelContext camelctx = createCamelContext();

    MessagePayload expectedPayload1 = new MessagePayload("localhost", Level.OK, camelctx.getName(),  "Hello Nagios");
    MessagePayload expectedPayload2 = new MessagePayload("localhost", Level.OK, camelctx.getName(),  "Bye Nagios");

    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(2);
    mock.allMessages().body().isInstanceOf(String.class);
    mock.expectedBodiesReceived("Hello Nagios", "Bye Nagios");

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBody("direct:start", "Hello Nagios");
        template.sendBody("direct:start", "Bye Nagios");

        mock.assertIsSatisfied();

        Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload1);
        Mockito.verify(nagiosPassiveCheckSender).send(expectedPayload2);
    } finally {
        camelctx.close();
    }
}