You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/04/08 07:49:09 UTC

[GitHub] [camel-quarkus] zhfeng commented on a diff in pull request #3709: Fix #3656 Improve camel-quarkus-paho-mqtt5 test coverage

zhfeng commented on code in PR #3709:
URL: https://github.com/apache/camel-quarkus/pull/3709#discussion_r845836407


##########
integration-tests/paho-mqtt5/src/main/java/org/apache/camel/quarkus/component/paho/mqtt5/it/PahoMqtt5Resource.java:
##########
@@ -60,12 +86,94 @@ public Response producePahoMessage(
             @PathParam("protocol") String protocol,
             @PathParam("queueName") String queueName,
             String message) throws Exception {
+        if ("ssl".equals(protocol)) {
+            setKeyStore(keystore, password);
+        }
         producerTemplate.sendBody("paho-mqtt5:" + queueName + "?retained=true&brokerUrl=" + brokerUrl(protocol), message);
+        if ("ssl".equals(protocol)) {
+            removeKeyStore(keystore);
+        }
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/override/{queueName}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    public Response overrideQueueName(
+            @PathParam("queueName") String queueName,
+            String message) throws Exception {
+        producerTemplate.sendBodyAndHeader("paho-mqtt5:test?retained=true&brokerUrl=" + brokerUrl("tcp"), message,
+                PahoMqtt5Constants.CAMEL_PAHO_OVERRIDE_TOPIC, queueName);
+        return Response.created(new URI("https://camel.apache.org/")).build();
+    }
+
+    @Path("/readThenWriteWithFilePersistenceShouldSucceed")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String readThenWriteWithFilePersistenceShouldSucceed(@QueryParam("message") String message) throws Exception {
+        producerTemplate.sendBody(
+                "paho-mqtt5:withFilePersistence?retained=true&persistence=FILE&brokerUrl="
+                        + brokerUrl("tcp"),
+                message);
+        return consumerTemplate.receiveBody(
+                "paho-mqtt5:withFilePersistence?persistence=FILE&brokerUrl=" + brokerUrl("tcp"),
+                5000,
+                String.class);
+    }
+
+    @Path("/routeStatus/{id}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String routeStatus(@PathParam("id") String routeId,
+            @QueryParam("waitForContainerStarted") @DefaultValue("false") boolean wait) throws Exception {
+        RouteController routeController = context.getRouteController();
+        if (wait) {
+            counter.await(30, TimeUnit.SECONDS);
+        }
+        return routeController.getRouteStatus(routeId).name();
+    }
+
+    @Path("/mock")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public String mock(String message) throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:test", MockEndpoint.class);
+        endpoint.expectedBodiesReceived(message);
+
+        endpoint.assertIsSatisfied();
+        return "OK";
+    }
+
+    @Path("/send")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response send(String message) throws Exception {
+        producerTemplate.sendBody("direct:test", message);
         return Response.created(new URI("https://camel.apache.org/")).build();
     }
 
     private String brokerUrl(String protocol) {
         return ConfigProvider.getConfig().getValue("paho5.broker." + protocol + ".url", String.class);
     }
 
+    private void setKeyStore(String keystore, String password) {
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore);
+
+        try {
+            Files.copy(in, Paths.get(keystore));
+        } catch (Exception e) {
+        }
+
+        System.setProperty("javax.net.ssl.keyStore", keystore);
+        System.setProperty("javax.net.ssl.keyStorePassword", password);
+        System.setProperty("javax.net.ssl.trustStore", keystore);
+        System.setProperty("javax.net.ssl.trustStorePassword", password);
+    }
+
+    private void removeKeyStore(String keystore) {
+        try {
+            Files.delete(Paths.get(keystore));

Review Comment:
   good catch! I will unset these properties.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org