You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2023/10/23 11:21:50 UTC

Re: [PR] camel-lra: provide additional unit tests [camel]

orpiske commented on code in PR #11809:
URL: https://github.com/apache/camel/pull/11809#discussion_r1368507578


##########
components/camel-lra/src/test/java/org/apache/camel/service/lra/LRAClientTest.java:
##########
@@ -56,11 +62,92 @@ void testCannotCreateLRAClientWithoutHttpClient() throws Exception {
                 "no client should result in IllegalArgumentException");
     }
 
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from newLRA()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInNewLra() {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.newLRA(exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }
+    }
+
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from compensate()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInCompensate() throws MalformedURLException {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.complete(new URL("https://localhost/saga"), exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }

Review Comment:
   Dito.



##########
components/camel-lra/src/test/java/org/apache/camel/service/lra/LRAClientTest.java:
##########
@@ -56,11 +62,92 @@ void testCannotCreateLRAClientWithoutHttpClient() throws Exception {
                 "no client should result in IllegalArgumentException");
     }
 
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from newLRA()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInNewLra() {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.newLRA(exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }

Review Comment:
   This is usually better done using `assertThrows`.



##########
components/camel-lra/src/test/java/org/apache/camel/service/lra/LRAClientTest.java:
##########
@@ -56,11 +62,92 @@ void testCannotCreateLRAClientWithoutHttpClient() throws Exception {
                 "no client should result in IllegalArgumentException");
     }
 
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from newLRA()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInNewLra() {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.newLRA(exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }
+    }
+
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from compensate()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInCompensate() throws MalformedURLException {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.complete(new URL("https://localhost/saga"), exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }
+    }
+
+    @DisplayName("Tests whether LRAClient is calling prepareRequest with exchange from complete()")
+    @Test
+    void testCallsPrepareRequestWithExchangeInComplete() throws MalformedURLException {
+        LRASagaService sagaService = new LRASagaService();
+        applyMockProperties(sagaService);
+        LRAClient client = new LRAClient(sagaService) {
+            protected HttpRequest.Builder prepareRequest(URI uri, Exchange exchange) {
+                throw new ExchangeRuntimeException(exchange);
+            }
+        };
+        Exchange exchange = Mockito.mock(Exchange.class);
+        try {
+            client.complete(new URL("https://localhost/saga"), exchange);
+            Assertions.fail("there should have been the special testing exception ExchangeRuntimeException");
+        } catch (ExchangeRuntimeException ex) {
+            Assertions.assertSame(exchange, ex.get());
+        }

Review Comment:
   Dito for this and others.



-- 
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