Search in sources :

Example 71 with CamelContext

use of org.apache.camel.CamelContext in project camel by apache.

the class CamelGroovyTest method testCamelGroovy.

@Test
public void testCamelGroovy() throws Exception {
    // install the camel blueprint xml file we use in this test
    URL url = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelGroovyTest.xml", CamelGroovyTest.class.getClassLoader());
    installBlueprintAsBundle("CamelGroovyTest", url, true);
    // lookup Camel from OSGi
    CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
    // test camel
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedBodiesReceived(6);
    camel.createProducerTemplate().sendBody("direct:start", 3);
    mock.assertIsSatisfied();
}
Also used : CamelContext(org.apache.camel.CamelContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) URL(java.net.URL) AbstractFeatureTest(org.apache.camel.test.karaf.AbstractFeatureTest) Test(org.junit.Test)

Example 72 with CamelContext

use of org.apache.camel.CamelContext in project camel by apache.

the class CamelTypeConverterTest method testTypeConverterInSameBundleAsCamelRoute.

@Test
public void testTypeConverterInSameBundleAsCamelRoute() throws Exception {
    // install the camel blueprint xml file and the Camel converter we use in this test
    URL blueprintUrl = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelTypeConverterTest.xml", CamelTypeConverterTest.class.getClassLoader());
    installBlueprintAsBundle("CamelTypeConverterTest", blueprintUrl, true, bundle -> {
        ((TinyBundle) bundle).add("META-INF/services/org/apache/camel/TypeConverter", new ByteArrayInputStream("org.apache.camel.itest.typeconverter.MyConverter".getBytes())).add(MyConverter.class, InnerClassStrategy.NONE).set(Constants.DYNAMICIMPORT_PACKAGE, "*");
    });
    // lookup Camel from OSGi
    CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
    final Pojo pojo = new Pojo();
    String pojoName = "Constantine";
    pojo.setName(pojoName);
    final DefaultExchange exchange = new DefaultExchange(camel);
    final String string = camel.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo);
    LOG.info("POJO -> String: {}", string);
    final Pojo copy = camel.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string);
    LOG.info("String -> POJO: {}", copy);
    Assert.assertEquals(pojoName, copy.getName());
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteArrayInputStream(java.io.ByteArrayInputStream) MyConverter(org.apache.camel.itest.typeconverter.MyConverter) URL(java.net.URL) Test(org.junit.Test) AbstractFeatureTest(org.apache.camel.test.karaf.AbstractFeatureTest)

Example 73 with CamelContext

use of org.apache.camel.CamelContext in project camel by apache.

the class DataFormatComponentConfigurationAndDocumentationTest method testUniVocityTsvEscapeChar.

@Test
public void testUniVocityTsvEscapeChar() throws Exception {
    CamelContext context = new DefaultCamelContext();
    String json = context.getEipParameterJsonSchema("univocity-tsv");
    assertNotNull(json);
    assertTrue(json.contains("\"name\": \"univocity-tsv"));
    // the default value is a bit tricky as its \, which is written escaped as \\
    assertTrue(json.contains("\"escapeChar\": { \"kind\": \"attribute\", \"displayName\": \"Escape Char\", \"required\": false, \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": false, \"secret\": false, \"defaultValue\": \"\\\\\", \"description\": \"The escape character.\""));
    List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
    assertEquals(16, rows.size());
    Map<String, String> found = null;
    for (Map<String, String> row : rows) {
        if ("escapeChar".equals(row.get("name"))) {
            found = row;
            break;
        }
    }
    assertNotNull(found);
    assertEquals("escapeChar", found.get("name"));
    assertEquals("attribute", found.get("kind"));
    assertEquals("false", found.get("required"));
    assertEquals("string", found.get("type"));
    assertEquals("java.lang.String", found.get("javaType"));
    assertEquals("false", found.get("deprecated"));
    assertEquals("false", found.get("secret"));
    assertEquals("\\", found.get("defaultValue"));
    assertEquals("The escape character.", found.get("description"));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Map(java.util.Map) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 74 with CamelContext

use of org.apache.camel.CamelContext in project camel by apache.

the class DataFormatComponentConfigurationAndDocumentationTest method testFlatpackDefaultValue.

@Test
public void testFlatpackDefaultValue() throws Exception {
    CamelContext context = new DefaultCamelContext();
    String json = context.getEipParameterJsonSchema("flatpack");
    assertNotNull(json);
    assertTrue(json.contains("\"name\": \"flatpack"));
    // the default value is a bit tricky as its ", which is written escaped as \"
    assertTrue(json.contains("\"textQualifier\": { \"kind\": \"attribute\", \"displayName\": \"Text Qualifier\", \"required\": false, \"type\": \"string\"" + ", \"javaType\": \"java.lang.String\", \"deprecated\": false, \"secret\": false, \"defaultValue\": \"\\\"\""));
    List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
    assertEquals(10, rows.size());
    Map<String, String> found = null;
    for (Map<String, String> row : rows) {
        if ("textQualifier".equals(row.get("name"))) {
            found = row;
            break;
        }
    }
    assertNotNull(found);
    assertEquals("textQualifier", found.get("name"));
    assertEquals("attribute", found.get("kind"));
    assertEquals("false", found.get("required"));
    assertEquals("string", found.get("type"));
    assertEquals("java.lang.String", found.get("javaType"));
    assertEquals("false", found.get("deprecated"));
    assertEquals("false", found.get("secret"));
    assertEquals("\"", found.get("defaultValue"));
    assertEquals("If the text is qualified with a char such as \"", found.get("description"));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Map(java.util.Map) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 75 with CamelContext

use of org.apache.camel.CamelContext in project camel by apache.

the class EipDocumentationTest method testFailOverDocumentation.

@Test
public void testFailOverDocumentation() throws Exception {
    CamelContext context = new DefaultCamelContext();
    String json = context.getEipParameterJsonSchema("failover");
    log.info(json);
    assertNotNull("Should have found json for failover", json);
    assertTrue(json.contains("\"name\": \"failover\""));
    assertTrue(json.contains("\"exception\": { \"kind\": \"element\", \"displayName\": \"Exception\", \"required\": false, \"type\": \"array\"" + ", \"javaType\": \"java.util.List<java.lang.String>\", \"deprecated\": false"));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)1478 Test (org.junit.Test)691 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)684 RouteBuilder (org.apache.camel.builder.RouteBuilder)448 ProducerTemplate (org.apache.camel.ProducerTemplate)434 ConnectionFactory (javax.jms.ConnectionFactory)220 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)210 Exchange (org.apache.camel.Exchange)109 HashMap (java.util.HashMap)93 Endpoint (org.apache.camel.Endpoint)52 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 IOException (java.io.IOException)46 Map (java.util.Map)45 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)44 CountDownLatch (java.util.concurrent.CountDownLatch)42 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)42 ArrayList (java.util.ArrayList)41 Processor (org.apache.camel.Processor)40 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)37 CamelExecutionException (org.apache.camel.CamelExecutionException)33