f2par0 commented on code in PR #390: URL: https://github.com/apache/camel-karaf/pull/390#discussion_r1653321180
########## tests/features/camel-influxdb2/src/test/java/org/apache/karaf/camel/itest/CamelInfluxdb2ITest.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.camel.itest; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest; +import org.apache.karaf.camel.itests.CamelKarafTestHint; +import org.apache.karaf.camel.itests.GenericContainerResource; +import org.apache.karaf.camel.itests.PaxExamWithExternalResource; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.InfluxDBContainer; +import org.testcontainers.utility.DockerImageName; + +import java.util.function.Consumer; + + +@CamelKarafTestHint( + externalResourceProvider = CamelInfluxdb2ITest.ExternalResourceProviders.class, + isBlueprintTest = true, + additionalRequiredFeatures = "camel-groovy") +@RunWith(PaxExamWithExternalResource.class) +@ExamReactorStrategy(PerClass.class) +public class CamelInfluxdb2ITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); Review Comment: Since there are 2 routes, you can be more precise and have one route sending OK_PING and one for OK_INSERT , then check that "OK_INSERT" and "OK_PING" are the received bodies. ########## tests/features/camel-influxdb2/src/main/resources/OSGI-INF/blueprint/route.xml: ########## @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd + http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> + + + <bean id="myDbClient" class="com.influxdb.client.InfluxDBClientFactory" factory-method="create" > + <argument value="http://localhost:$[influxdb2.port]?token=$[admin.token]" /> + </bean> + + + <bean id="influxdbconn" class="org.apache.camel.component.influxdb2.InfluxDb2Component"> + <property name="influxDBClient" ref="myDbClient"/> + </bean> + + <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" /> + + <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/blueprint"> + + <route id="pingToInfluxDB2"> + <from uri="direct:camel-influxdb2-test"/> + <to uri="influxdb2:myDbClient?operation=ping&org=test-org&bucket=test-bucket&autoCreateBucket=true" /> + <setBody> + <constant>OK</constant> + </setBody> + <log message="Ping response: ${body}"/> + <to uri="mock:camel-influxdb2-test"/> + </route> + + <route id="writeToInfluxDB2"> + <from uri="direct:camel-influxdb2-write-test"/> + <setBody><groovy>def map = ["CamelInfluxDB2MeasurementName" : "cpu", "time": "1307816001290", "idle" : 90L, "user" : 9L]</groovy></setBody> + <to uri="influxdb2:myDbClient?operation=insert&org=test-bucket&bucket=test-bucket&autoCreateBucket=true" /> + <setBody> + <constant>OK</constant> + </setBody> Review Comment: if you want to log the inserted body, this line must be before the setBody part, otherwise, it will just log "OK" ########## tests/features/camel-influxdb2/src/test/java/org/apache/karaf/camel/itest/CamelInfluxdb2ITest.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.camel.itest; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest; +import org.apache.karaf.camel.itests.CamelKarafTestHint; +import org.apache.karaf.camel.itests.GenericContainerResource; +import org.apache.karaf.camel.itests.PaxExamWithExternalResource; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.InfluxDBContainer; +import org.testcontainers.utility.DockerImageName; + +import java.util.function.Consumer; + + +@CamelKarafTestHint( + externalResourceProvider = CamelInfluxdb2ITest.ExternalResourceProviders.class, + isBlueprintTest = true, + additionalRequiredFeatures = "camel-groovy") +@RunWith(PaxExamWithExternalResource.class) +@ExamReactorStrategy(PerClass.class) +public class CamelInfluxdb2ITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + + @Test + public void testResultMock() throws Exception { + assertMockEndpointsSatisfied(); + } + + public static final class ExternalResourceProviders { + private static final String ADMIN_TOKEN = "_QGcCkmN0_tzesB9OemUNR7c3WEqk35LV8ymQRhiSy6x9tQIPw0DgWCSpcnC0B_kIEeNG6aLpAoCAV1-lDRzKA=="; + + public static GenericContainerResource createInfluxdb2Container() { + + final GenericContainer<?> influxDBContainer = new InfluxDBContainer<>( + DockerImageName.parse("influxdb:2.0.7") + ) + .withAdminToken(ADMIN_TOKEN) + .withExposedPorts(8086); + + + return new GenericContainerResource(influxDBContainer, (Consumer<GenericContainerResource>) + resource -> { + resource.setProperty("influxdb2.port", Integer.toString(influxDBContainer.getMappedPort(8086))); + resource.setProperty("admin.token", ADMIN_TOKEN); + } + ); + //resource.setProperty("amqp.port", Integer.toString(rabbitMQContainer.getAmqpPort())); Review Comment: remove this unecessary comment -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
