소스 검색

wait for 30s between each call to the webhooks

Jonathan LALOU 7 년 전
부모
커밋
ab09ccb40c

+ 8
- 1
src/main/java/fr/sayasoft/fake/zinc/FakeZincController.java 파일 보기

@@ -75,11 +75,13 @@ public class FakeZincController {
75 75
     }
76 76
 
77 77
     /**
78
-     * Fake method to test order posting
78
+     * Fake method to test order posting.<br/>
79 79
      * Conventions for testing:
80 80
      * <ul>
81 81
      * <li>if the unmarshalled OrderRequest has a field clientNotes that is a ZincErrorCode, then a ZincError will be returned.</li>
82 82
      * <li>else a response containing the idemPotency in the requestId is returned</li>
83
+     * <li>when webhooks are given in the OrderRequest in parameter, then these webhooks are called in the order they are written, with a pause
84
+     * (<code>Thread.sleep</code>) of 30 seconds</li>
83 85
      * </ul>
84 86
      */
85 87
     @SuppressWarnings("unused")
@@ -138,6 +140,11 @@ public class FakeZincController {
138 140
         orderRequest.getWebhooks()
139 141
                 .forEach((zincWebhookType, url) -> {
140 142
                             log.info("Calling webhook for zincWebhookType: " + zincWebhookType + " and URL: " + url);
143
+                            try {
144
+                                Thread.sleep(30000);
145
+                            } catch (InterruptedException e) {
146
+                                e.printStackTrace();
147
+                            }
141 148
                             restTemplate.postForObject(url, orderResponse, String.class);
142 149
                         }
143 150
                 );

+ 1
- 3
src/test/java/fr/sayasoft/fake/zinc/FakeZincControllerUnitTest.java 파일 보기

@@ -202,13 +202,11 @@ public class FakeZincControllerUnitTest {
202 202
     }
203 203
 
204 204
     @Test
205
-    @Ignore
205
+    @Ignore("Run this test only when a webserver can receive and handle the request")
206 206
     public void postOrder_withWebHooks() throws Exception {
207 207
         final String idempotencyKey = "Carina-β-Carinae-Miaplacidus";
208 208
         orderRequest.setIdempotencyKey(idempotencyKey);
209 209
         orderRequest.setWebhooks(new HashMap<>(2));
210
-//        orderRequest.getWebhooks().put(ZincWebhookType.statusUpdated, "https://reqres.in/api/users");
211
-//        orderRequest.getWebhooks().put(ZincWebhookType.requestSucceeded, "https://reqres.in/api/users");
212 210
         orderRequest.getWebhooks().put(ZincWebhookType.statusUpdated, "http://localhost:8080/hook/zinc?eventType=statusUpdated&uuid=abcd");
213 211
         orderRequest.getWebhooks().put(ZincWebhookType.requestSucceeded, "http://localhost:8080/hook/zinc?eventType=requestSucceeded&uuid=abcd");
214 212
         this.mockMvc.perform(post("/v1/order")