Java Code Examples for org.apache.camel.ProducerTemplate#requestBodyAndHeaders()
The following examples show how to use
org.apache.camel.ProducerTemplate#requestBodyAndHeaders() .
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: CDIEarResourceLoadingTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCamelCdiEarResourceLoading() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("sub-deployment-a"); Assert.assertNotNull("Expected sub-deployment-a to not be null", camelctx); String moduleNameA = TestUtils.getClassLoaderModuleName(camelctx.getApplicationContextClassLoader()); Assert.assertEquals("deployment.resource-loading.ear.resource-loading-a.war", moduleNameA); Assert.assertNotNull("Expected resource template.mustache to not be null", camelctx.getClassResolver().loadResourceAsURL("/template.mustache")); Map<String, Object> headers = new HashMap<>(); headers.put("greeting", "Hello"); headers.put("name", "camelctxA"); ProducerTemplate template = camelctx.createProducerTemplate(); String result = template.requestBodyAndHeaders("direct:startA", null, headers, String.class); Assert.assertEquals("Hello camelctxA!", result); headers.put("name", "camelctxB"); template = camelctx.createProducerTemplate(); result = template.requestBodyAndHeaders("direct:startB", null, headers, String.class); Assert.assertEquals("Hello camelctxB!", result); }
Example 2
Source File: InfinispanIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCachePut() throws Exception { camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:put") .to("infinispan://" + cacheName + "?cacheContainer=#" + CONTAINER_NAME + "&command=PUT"); } }); camelctx.start(); try { Map<String, Object> headers = new HashMap<>(); headers.put(InfinispanConstants.KEY, CACHE_KEY_NAME); headers.put(InfinispanConstants.VALUE, CACHE_VALUE_KERMIT); ProducerTemplate template = camelctx.createProducerTemplate(); template.requestBodyAndHeaders("direct:put", null, headers); String name = (String) cacheContainer.getCache().get(CACHE_KEY_NAME); Assert.assertEquals("Kermit", name); } finally { camelctx.close(); } }
Example 3
Source File: GoogleDriveIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
private static File uploadTestFile(ProducerTemplate template, String testName) { File fileMetadata = new File(); fileMetadata.setTitle(GoogleDriveIntegrationTest.class.getName()+"."+testName+"-"+ UUID.randomUUID().toString()); final String content = "Camel rocks!\n" // + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + "\n" // + "user: " + System.getProperty("user.name"); HttpContent mediaContent = new ByteArrayContent("text/plain", content.getBytes(StandardCharsets.UTF_8)); final Map<String, Object> headers = new HashMap<>(); // parameter type is com.google.api.services.drive.model.File headers.put("CamelGoogleDrive.content", fileMetadata); // parameter type is com.google.api.client.http.AbstractInputStreamContent headers.put("CamelGoogleDrive.mediaContent", mediaContent); return template.requestBodyAndHeaders("google-drive://drive-files/insert", null, headers, File.class); }
Example 4
Source File: MailIntegrationCDITest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMailEndpointWithCDIContext() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("camel-mail-cdi-context"); Assert.assertNotNull("Camel context not null", camelctx); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.setExpectedMessageCount(1); Map<String, Object> mailHeaders = new HashMap<>(); mailHeaders.put("from", "user1@localhost"); mailHeaders.put("to", "user2@localhost"); mailHeaders.put("message", "Hello Kermit"); ProducerTemplate template = camelctx.createProducerTemplate(); template.requestBodyAndHeaders("direct:start", null, mailHeaders); mockEndpoint.assertIsSatisfied(5000); }
Example 5
Source File: MailIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testMailEndpoint() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("smtp://localhost:10025?session=#java:jboss/mail/greenmail"); from("pop3://user2@localhost:10110?delay=1000&session=#java:jboss/mail/greenmail&delete=true") .to("mock:result"); } }); try { deployer.deploy(GREENMAIL_WAR); camelctx.start(); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.setExpectedMessageCount(1); Map<String, Object> mailHeaders = new HashMap<>(); mailHeaders.put("from", "user1@localhost"); mailHeaders.put("to", "user2@localhost"); mailHeaders.put("message", "Hello Kermit"); ProducerTemplate template = camelctx.createProducerTemplate(); template.requestBodyAndHeaders("direct:start", null, mailHeaders); mockEndpoint.assertIsSatisfied(5000); } finally { camelctx.close(); deployer.undeploy(GREENMAIL_WAR); } }
Example 6
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testUpdateWithIDInHeader() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Map<String, String> map = createIndexedData("testUpdateWithIDInHeader"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); Assert.assertEquals("indexId should be equals to the provided id", "123", indexId); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Update); indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); Assert.assertEquals("indexId should be equals to the provided id", "123", indexId); } finally { camelctx.close(); } }
Example 7
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNotExistsWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:exists") .to("elasticsearch-rest://elasticsearch?operation=Exists&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testNotExistsWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Exists); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter-tweet"); Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class); Assert.assertNotNull("response should not be null", exists); Assert.assertFalse("Index should not exist", exists); } finally { camelctx.close(); } }
Example 8
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testExistsWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:exists") .to("elasticsearch-rest://elasticsearch?operation=Exists&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testExistsWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Exists); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class); Assert.assertNotNull("response should not be null", exists); Assert.assertTrue("Index should exist", exists); } finally { camelctx.close(); } }
Example 9
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testGetWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testGetWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNotNull("response source should not be null", response.getSource()); } finally { camelctx.close(); } }
Example 10
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testUpdate() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:index") .to("elasticsearch-rest://elasticsearch?operation=Index&indexName=twitter&hostAddresses=" + getElasticsearchHost()); from("direct:update") .to("elasticsearch-rest://elasticsearch?operation=Update&indexName=twitter&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Map<String, String> map = createIndexedData("testUpdate"); String indexId = template.requestBody("direct:index", map, String.class); Assert.assertNotNull("indexId should be set", indexId); Map<String, String> newMap = new HashMap<>(); newMap.put(PREFIX + "key2", PREFIX + "value2"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId); indexId = template.requestBodyAndHeaders("direct:update", newMap, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); } finally { camelctx.close(); } }
Example 11
Source File: ManagementBusInvocationPluginScript.java From container with Apache License 2.0 | 5 votes |
/** * Invokes the Management Bus. */ private Object invokeManagementBusEngine(final Map<String, String> paramsMap, final Map<String, Object> headers) { LOG.debug("Invoking the Management Bus..."); final ProducerTemplate template = camelContext.createProducerTemplate(); final Object response = template.requestBodyAndHeaders("bean:managementBusService?method=invokeIA", paramsMap, headers); LOG.debug("Invocation finished: {}", response); return response; }
Example 12
Source File: JcrIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testJcrProducer() throws Exception { WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("repository", repository); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { getContext().setUseBreadcrumb(false); from("direct:a").to("jcr://user:pass@repository/home/test"); } }); camelctx.start(); try { String content = "<hello>world!</hello>"; HashMap<String, Object> headers = new HashMap<>(); headers.put(JcrConstants.JCR_NODE_NAME, "node"); headers.put("my.contents.property", content); ProducerTemplate template = camelctx.createProducerTemplate(); String result = template.requestBodyAndHeaders("direct:a", null, headers, String.class); Assert.assertNotNull(result); Session session = openSession(); try { Node node = session.getNodeByIdentifier(result); Assert.assertEquals("/home/test/node", node.getPath()); Assert.assertEquals(content, node.getProperty("my.contents.property").getString()); } finally { session.logout(); } } finally { camelctx.close(); } }
Example 13
Source File: InfinispanIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testCacheRemove() throws Exception { camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:remove") .to("infinispan://" + cacheName + "?cacheContainer=#" + CONTAINER_NAME + "&command=REMOVE"); } }); cacheContainer.getCache().put(CACHE_KEY_NAME, CACHE_VALUE_KERMIT); camelctx.start(); try { Assert.assertTrue(cacheContainer.getCache().containsKey(CACHE_KEY_NAME)); Map<String, Object> headers = new HashMap<>(); headers.put(InfinispanConstants.KEY, CACHE_KEY_NAME); ProducerTemplate template = camelctx.createProducerTemplate(); template.requestBodyAndHeaders("direct:remove", null, headers); Assert.assertFalse(cacheContainer.getCache().containsKey(CACHE_KEY_NAME)); } finally { camelctx.close(); } }
Example 14
Source File: InfinispanIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testCacheGet() throws Exception { camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:get") .to("infinispan://" + cacheName + "?cacheContainer=#" + CONTAINER_NAME + "&command=GET") .to("mock:end"); } }); cacheContainer.getCache().put(CACHE_KEY_NAME, CACHE_VALUE_KERMIT); camelctx.start(); try { Map<String, Object> headers = new HashMap<>(); headers.put(InfinispanConstants.KEY, CACHE_KEY_NAME); ProducerTemplate template = camelctx.createProducerTemplate(); String name = template.requestBodyAndHeaders("direct:get", null, headers, String.class); Assert.assertEquals("Kermit", name); } finally { camelctx.close(); } }
Example 15
Source File: ServiceNowIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testSearchIncidents() throws Exception { Map<String, Object> serviceNowOptions = createServiceNowOptions(); Assume.assumeTrue("[#1674] Enable ServiceNow testing in Jenkins", serviceNowOptions.size() == ServiceNowIntegrationTest.ServiceNowOption.values().length); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("servicenow:{{env:SERVICENOW_INSTANCE}}" + "?userName={{env:SERVICENOW_USERNAME}}" + "&password={{env:SERVICENOW_PASSWORD}}" + "&oauthClientId={{env:SERVICENOW_CLIENT_ID}}" + "&oauthClientSecret={{env:SERVICENOW_CLIENT_SECRET}}" + "&release={{env:SERVICENOW_RELEASE}}" + "&model.incident=org.wildfly.camel.test.servicenow.subA.Incident"); } }); camelctx.start(); try { Map<String, Object> headers = new HashMap<>(); headers.put(ServiceNowConstants.RESOURCE, "table"); headers.put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE); headers.put(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), "incident"); ProducerTemplate producer = camelctx.createProducerTemplate(); List<Incident> result = producer.requestBodyAndHeaders("direct:start", null, headers, List.class); Assert.assertNotNull(result); Assert.assertTrue(result.size() > 0); } finally { camelctx.close(); } }
Example 16
Source File: CmisIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testCmisProducer() throws Exception { deleteAllContent(); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("cmis://http://127.0.0.1:8080/chemistry-opencmis-server-inmemory/atom11"); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); String content = "Some content to be store"; String rootFolderId = createSession().getRootFolder().getId(); Map<String,Object> headers = new HashMap<>(); headers.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8"); headers.put(CamelCMISConstants.CMIS_OBJECT_ID, rootFolderId); headers.put(CamelCMISConstants.CMIS_ACTION, CamelCMISActions.CREATE); headers.put(PropertyIds.NAME, "test.file"); CmisObject object = template.requestBodyAndHeaders("direct:start", "Some content to be store", headers, CmisObject.class); Assert.assertNotNull(object); String nodeContent = getDocumentContentAsString(object.getId()); Assert.assertEquals(content, nodeContent); } finally { camelctx.close(); } }
Example 17
Source File: Olingo4IntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testRead() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() { // test routes for read from("direct://readmetadata").to("olingo4://read/$metadata"); from("direct://readdocument").to("olingo4://read/"); from("direct://readentities").to("olingo4://read/People?$top=5&$orderby=FirstName asc"); from("direct://readcount").to("olingo4://read/People/$count"); from("direct://readvalue").to("olingo4://read/People('russellwhyte')/Gender/$value"); from("direct://readsingleprop").to("olingo4://read/Airports('KSFO')/Name"); from("direct://readcomplexprop").to("olingo4://read/Airports('KSFO')/Location"); from("direct://readentitybyid").to("olingo4://read/People('russellwhyte')"); from("direct://callunboundfunction").to("olingo4://read/GetNearestAirport(lat=33,lon=-118)"); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); final Map<String, Object> headers = new HashMap<String, Object>(); // Read metadata ($metadata) object final Edm metadata = (Edm) template.requestBodyAndHeaders("direct://readmetadata", null, headers); Assert.assertNotNull(metadata); Assert.assertEquals(1, metadata.getSchemas().size()); // Read service document object final ClientServiceDocument document = (ClientServiceDocument) template.requestBodyAndHeaders("direct://readdocument", null, headers); Assert.assertNotNull(document); Assert.assertTrue(document.getEntitySets().size() > 1); LOG.info("Service document has {} entity sets", document.getEntitySets().size()); // Read entity set of the People object final ClientEntitySet entities = (ClientEntitySet) template.requestBodyAndHeaders("direct://readentities", null, headers); Assert.assertNotNull(entities); Assert.assertEquals(5, entities.getEntities().size()); // Read object count with query options passed through header final Long count = (Long) template.requestBodyAndHeaders("direct://readcount", null, headers); Assert.assertEquals(20, count.intValue()); final ClientPrimitiveValue value = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readvalue", null, headers); LOG.info("Client value \"{}\" has type {}", value.toString(), value.getTypeName()); Assert.assertEquals("Male", value.asPrimitive().toString()); final ClientPrimitiveValue singleProperty = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readsingleprop", null, headers); Assert.assertTrue(singleProperty.isPrimitive()); Assert.assertEquals("San Francisco International Airport", singleProperty.toString()); final ClientComplexValue complexProperty = (ClientComplexValue) template.requestBodyAndHeaders("direct://readcomplexprop", null, headers); Assert.assertTrue(complexProperty.isComplex()); Assert.assertEquals("San Francisco", complexProperty.get("City").getComplexValue().get("Name").getValue().toString()); final ClientEntity entity = (ClientEntity) template.requestBodyAndHeaders("direct://readentitybyid", null, headers); Assert.assertNotNull(entity); Assert.assertEquals("Russell", entity.getProperty("FirstName").getValue().toString()); final ClientEntity unbFuncReturn = (ClientEntity) template.requestBodyAndHeaders("direct://callunboundfunction", null, headers); Assert.assertNotNull(unbFuncReturn); } finally { camelctx.close(); } }
Example 18
Source File: BoxIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testBoxComponent() throws Exception { Map<String, Object> boxOptions = createBoxOptions(); // Do nothing if the required credentials are not present Assume.assumeTrue(boxOptions.size() == BoxOption.values().length); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start"). to("box://folders/createFolder"); } }); BoxConfiguration configuration = new BoxConfiguration(); configuration.setAuthenticationType(BoxConfiguration.STANDARD_AUTHENTICATION); IntrospectionSupport.setProperties(configuration, boxOptions); BoxComponent component = new BoxComponent(camelctx); component.setConfiguration(configuration); camelctx.addComponent("box", component); BoxFolder folder = null; camelctx.start(); try { Map<String, Object> headers = new HashMap<>(); headers.put("CamelBox.parentFolderId", "0"); headers.put("CamelBox.folderName", "TestFolder"); ProducerTemplate template = camelctx.createProducerTemplate(); folder = template.requestBodyAndHeaders("direct:start", null, headers, BoxFolder.class); Assert.assertNotNull("Folder was null", folder); Assert.assertEquals("Expected folder name to be TestFolder", "TestFolder", folder.getInfo().getName()); } finally { // Clean up if (folder != null) { folder.delete(true); } camelctx.close(); } }
Example 19
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testDeleteWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:delete") .to("elasticsearch-rest://elasticsearch?operation=Delete&indexName=twitter&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testDeleteWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNotNull("response source should not be null", response.getSource()); //now, perform Delete headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Delete); DocWriteResponse.Result deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DocWriteResponse.Result.class); Assert.assertEquals("response should not be null", DocWriteResponse.Result.DELETED, deleteResponse); //now, verify GET fails to find the indexed value headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNull("response source should be null", response.getSource()); } finally { camelctx.close(); } }
Example 20
Source File: EC2IntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testCreateInstance() throws Exception { AmazonEC2Client ec2Client = provider.getClient(); Assume.assumeNotNull("AWS client not null", ec2Client); assertNoStaleInstances(ec2Client, "before"); try { WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("ec2Client", ec2Client); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:createAndRun").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=createAndRunInstances"); from("direct:terminate").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=terminateInstances"); } }); camelctx.start(); try { // Create and run an instance Map<String, Object> headers = new HashMap<>(); headers.put(EC2Constants.IMAGE_ID, "ami-02ace471"); headers.put(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro); headers.put(EC2Constants.SUBNET_ID, EC2Utils.getSubnetId(ec2Client)); headers.put(EC2Constants.INSTANCE_MIN_COUNT, 1); headers.put(EC2Constants.INSTANCE_MAX_COUNT, 1); headers.put(EC2Constants.INSTANCES_TAGS, Arrays.asList(new Tag("Name", "wildfly-camel"))); ProducerTemplate template = camelctx.createProducerTemplate(); RunInstancesResult result1 = template.requestBodyAndHeaders("direct:createAndRun", null, headers, RunInstancesResult.class); String instanceId = result1.getReservation().getInstances().get(0).getInstanceId(); System.out.println("InstanceId: " + instanceId); // Terminate the instance headers = new HashMap<>(); headers.put(EC2Constants.INSTANCES_IDS, Collections.singleton(instanceId)); TerminateInstancesResult result2 = template.requestBodyAndHeaders("direct:terminate", null, headers, TerminateInstancesResult.class); Assert.assertEquals(instanceId, result2.getTerminatingInstances().get(0).getInstanceId()); } finally { camelctx.close(); } } finally { assertNoStaleInstances(ec2Client, "after"); } }