This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch 3.2.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit adcc34ced0ff2fd49cb5277399729f9c416822db
Author: Lucia Drozdova <ldro...@redhat.com>
AuthorDate: Fri Sep 22 09:25:57 2023 +0200

    Create basic Azure Servicebus tests
---
 integration-tests-jvm/azure-servicebus/pom.xml     | 21 ++++++++
 ...sResource.java => AzureServiceBusResource.java} | 40 +++++++++-------
 .../azure/servicebus/it/AzureServiceBusRoutes.java | 45 +++++++++++++++++
 .../src/main/resources/application.properties      | 17 +++++++
 .../azure/servicebus/it/AzureServiceBusTest.java   | 56 ++++++++++++++++++++++
 .../azure/servicebus/it/AzureServicebusTest.java   | 34 -------------
 6 files changed, 163 insertions(+), 50 deletions(-)

diff --git a/integration-tests-jvm/azure-servicebus/pom.xml 
b/integration-tests-jvm/azure-servicebus/pom.xml
index 6ae9bd81f5..b2dd0f646f 100644
--- a/integration-tests-jvm/azure-servicebus/pom.xml
+++ b/integration-tests-jvm/azure-servicebus/pom.xml
@@ -58,6 +58,22 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-mock</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy-jsonb</artifactId>
+        </dependency>
 
         <!-- test dependencies -->
         <dependency>
@@ -70,6 +86,11 @@
             <artifactId>rest-assured</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>
diff --git 
a/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusResource.java
 
b/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusResource.java
similarity index 56%
rename from 
integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusResource.java
rename to 
integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusResource.java
index d1a03193bd..d095a81e5b 100644
--- 
a/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusResource.java
+++ 
b/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusResource.java
@@ -16,35 +16,43 @@
  */
 package org.apache.camel.quarkus.component.azure.servicebus.it;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 import jakarta.enterprise.context.ApplicationScoped;
 import jakarta.inject.Inject;
 import jakarta.ws.rs.GET;
 import jakarta.ws.rs.Path;
 import jakarta.ws.rs.Produces;
 import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response;
 import org.apache.camel.CamelContext;
-import org.jboss.logging.Logger;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
 
 @Path("/azure-servicebus")
 @ApplicationScoped
-public class AzureServicebusResource {
-
-    private static final Logger LOG = 
Logger.getLogger(AzureServicebusResource.class);
-
-    private static final String COMPONENT_AZURE_SERVICEBUS = 
"azure-servicebus";
+public class AzureServiceBusResource {
+    @Inject
+    ProducerTemplate producerTemplate;
     @Inject
     CamelContext context;
 
-    @Path("/load/component/azure-servicebus")
+    @Path("/producer")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<String> getBasicProducer() throws Exception {
+        return producerTemplate.requestBody("direct:producer-test", null, 
List.class);
+    }
+
+    @Path("/consumer")
     @GET
-    @Produces(MediaType.TEXT_PLAIN)
-    public Response loadComponentAzureServicebus() throws Exception {
-        /* This is an autogenerated test */
-        if (context.getComponent(COMPONENT_AZURE_SERVICEBUS) != null) {
-            return Response.ok().build();
-        }
-        LOG.warnf("Could not load [%s] from the Camel context", 
COMPONENT_AZURE_SERVICEBUS);
-        return Response.status(500, COMPONENT_AZURE_SERVICEBUS + " could not 
be loaded from the Camel context").build();
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<String> getBasicConsumer() throws Exception {
+        final MockEndpoint mockEndpoint = 
context.getEndpoint("mock:azure-servicebus-consumed", MockEndpoint.class);
+        return mockEndpoint.getReceivedExchanges().stream()
+                .map(Exchange::getMessage)
+                .map(m -> m.getBody(String.class))
+                .collect(Collectors.toList());
     }
 }
diff --git 
a/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusRoutes.java
 
b/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusRoutes.java
new file mode 100644
index 0000000000..9ed3c4fc01
--- /dev/null
+++ 
b/integration-tests-jvm/azure-servicebus/src/main/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusRoutes.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.azure.servicebus.it;
+
+import java.util.Arrays;
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.builder.RouteBuilder;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+@ApplicationScoped
+public class AzureServiceBusRoutes extends RouteBuilder {
+
+    @ConfigProperty(name = "azure.servicebus.connection-string")
+    String azureServiceBusConnectionString;
+
+    @Override
+    public void configure() {
+        from("direct:producer-test")
+                .process(exchange -> {
+                    final List<String> inputBatch = Arrays.asList("Bulbasaur", 
"Pikachu", "Charizard", "Squirtle");
+                    exchange.getIn().setBody(inputBatch);
+                })
+                .to("azure-servicebus:test?connectionString=RAW(" + 
azureServiceBusConnectionString + ")");
+
+        from("azure-servicebus:test?connectionString=RAW(" + 
azureServiceBusConnectionString + ")")
+                .log("${body}")
+                .to("mock:azure-servicebus-consumed");
+    }
+}
diff --git 
a/integration-tests-jvm/azure-servicebus/src/main/resources/application.properties
 
b/integration-tests-jvm/azure-servicebus/src/main/resources/application.properties
new file mode 100644
index 0000000000..8b6c11687c
--- /dev/null
+++ 
b/integration-tests-jvm/azure-servicebus/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+azure.servicebus.connection-string=${AZURE_SERVICEBUS_CONNECTION_STRING}
diff --git 
a/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusTest.java
 
b/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusTest.java
new file mode 100644
index 0000000000..889738f9b9
--- /dev/null
+++ 
b/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServiceBusTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.component.azure.servicebus.it;
+
+import java.util.Arrays;
+import java.util.List;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+@EnabledIfEnvironmentVariable(named = "AZURE_SERVICEBUS_CONNECTION_STRING", 
matches = ".+")
+@QuarkusTest
+class AzureServiceBusTest {
+
+    final List<String> inputBatch = Arrays.asList("Bulbasaur", "Pikachu", 
"Charizard", "Squirtle");
+
+    @Test
+    public void basicProducerConsumerTest() {
+        final List sentMessages = RestAssured.given()
+                .get("/azure-servicebus/producer")
+                .then().statusCode(200).extract().body().as(List.class);
+
+        Assertions.assertEquals(inputBatch, sentMessages);
+    }
+
+    @Test
+    public void basicConsumerTest() {
+        final List consumedMessages = RestAssured.given()
+                .contentType(ContentType.JSON)
+                .get("/azure-servicebus/consumer")
+                .then()
+                .extract().body().as(List.class);
+
+        Assertions.assertFalse(consumedMessages.isEmpty());
+        
Assertions.assertTrue(consumedMessages.stream().anyMatch(inputBatch::contains));
+    }
+
+}
diff --git 
a/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusTest.java
 
b/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusTest.java
deleted file mode 100644
index 166b446805..0000000000
--- 
a/integration-tests-jvm/azure-servicebus/src/test/java/org/apache/camel/quarkus/component/azure/servicebus/it/AzureServicebusTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-package org.apache.camel.quarkus.component.azure.servicebus.it;
-
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
-
-@QuarkusTest
-class AzureServicebusTest {
-
-    @Test
-    public void loadComponentAzureServicebus() {
-        /* A simple autogenerated test */
-        RestAssured.get("/azure-servicebus/load/component/azure-servicebus")
-                .then()
-                .statusCode(200);
-    }
-
-}

Reply via email to