Преглед изворни кода

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
     }
75
     }
76
 
76
 
77
     /**
77
     /**
78
-     * Fake method to test order posting
78
+     * Fake method to test order posting.<br/>
79
      * Conventions for testing:
79
      * Conventions for testing:
80
      * <ul>
80
      * <ul>
81
      * <li>if the unmarshalled OrderRequest has a field clientNotes that is a ZincErrorCode, then a ZincError will be returned.</li>
81
      * <li>if the unmarshalled OrderRequest has a field clientNotes that is a ZincErrorCode, then a ZincError will be returned.</li>
82
      * <li>else a response containing the idemPotency in the requestId is returned</li>
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
      * </ul>
85
      * </ul>
84
      */
86
      */
85
     @SuppressWarnings("unused")
87
     @SuppressWarnings("unused")
138
         orderRequest.getWebhooks()
140
         orderRequest.getWebhooks()
139
                 .forEach((zincWebhookType, url) -> {
141
                 .forEach((zincWebhookType, url) -> {
140
                             log.info("Calling webhook for zincWebhookType: " + zincWebhookType + " and URL: " + url);
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
                             restTemplate.postForObject(url, orderResponse, String.class);
148
                             restTemplate.postForObject(url, orderResponse, String.class);
142
                         }
149
                         }
143
                 );
150
                 );

+ 1
- 3
src/test/java/fr/sayasoft/fake/zinc/FakeZincControllerUnitTest.java Прегледај датотеку

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