ソースを参照

* bulk:

    * [master d492966] FakeZinc: (failed) retrieve, extract and return idempotency from OrderRequest to requestId
    * [master 8c33d50] updated default baseURL for ZincAPI
    * [master 8c33d50] populated method AssetHelper.buildOrderRequest()
    * [master bb30937] added OrderRequestUnitTest
    * [master d95d1b1] added added unit test
    * [master 2f98f2d] fake-zinc: added dependency to commons-lang
Jonathan LALOU 7 年 前
コミット
399a5785eb
共有3 個のファイルを変更した25 個の追加6 個の削除を含む
  1. 5
    0
      pom.xml
  2. 17
    4
      src/main/java/fr/sayasoft/fake/zinc/FakeZincController.java
  3. 3
    2
      test/java/fr/sayasoft/fake/zinc/FakeZincControllerUnitTest.java

+ 5
- 0
pom.xml ファイルの表示

@@ -43,6 +43,11 @@
43 43
             <artifactId>zinc-java-sdk</artifactId>
44 44
             <version>1.0-SNAPSHOT</version>
45 45
         </dependency>
46
+        <dependency>
47
+            <groupId>org.apache.commons</groupId>
48
+            <artifactId>commons-lang3</artifactId>
49
+            <version>3.3.2</version>
50
+        </dependency>
46 51
     </dependencies>
47 52
 
48 53
     <properties>

+ 17
- 4
src/main/java/fr/sayasoft/fake/zinc/FakeZincController.java ファイルの表示

@@ -1,6 +1,9 @@
1 1
 package fr.sayasoft.fake.zinc;
2 2
 
3 3
 import fr.sayasoft.zinc.sdk.domain.OrderRequest;
4
+import lombok.extern.log4j.Log4j;
5
+import org.apache.commons.lang3.builder.ToStringBuilder;
6
+import org.apache.commons.lang3.builder.ToStringStyle;
4 7
 import org.springframework.http.HttpStatus;
5 8
 import org.springframework.http.ResponseEntity;
6 9
 import org.springframework.web.bind.annotation.PathVariable;
@@ -13,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
13 16
 import java.util.concurrent.atomic.AtomicLong;
14 17
 
15 18
 @RestController
19
+@Log4j
16 20
 public class FakeZincController {
17 21
 
18 22
     private static final String template = "Hello, %s!";
@@ -42,8 +46,9 @@ public class FakeZincController {
42 46
             "  ]\n" +
43 47
             "}";
44 48
 
49
+    public static final String POST_ORDER_RESPONSE_TO_BE_REPLACED = "XXX";
45 50
     public static final String POST_ORDER_RESPONSE = "{\n" +
46
-            "  \"request_id\": \"3f1c939065cf58e7b9f0aea70640dffc\"\n" +
51
+            "  \"request_id\": \"fakeRequestIdStart-" + POST_ORDER_RESPONSE_TO_BE_REPLACED + "-fakeRequestIdEnd\"\n" +
47 52
             "}";
48 53
 
49 54
     private final AtomicLong counter = new AtomicLong();
@@ -57,7 +62,7 @@ public class FakeZincController {
57 62
 
58 63
     @SuppressWarnings("unused")
59 64
     @RequestMapping(
60
-            value = "/order/{request_id}",
65
+            value = "/v1/order/{request_id}",
61 66
             method = RequestMethod.GET,
62 67
             produces = "application/json; charset=UTF-8"
63 68
     )
@@ -67,11 +72,19 @@ public class FakeZincController {
67 72
 
68 73
     @SuppressWarnings("unused")
69 74
     @RequestMapping(
70
-            value = "/order",
75
+            value = "/v1/order",
71 76
             method = RequestMethod.POST,
72 77
             produces = "application/json; charset=UTF-8"
73 78
     )
74
-    public ResponseEntity<?> postOrder(@RequestBody OrderRequest requestBody) {
79
+    public ResponseEntity<?> postOrder(@RequestBody OrderRequest orderRequest) {
80
+// FIXME: at this point, the orderRequest, for an unknown reason, is not well deserialized
81
+        // (except the field 'retailer'). But it *was* well serialized on the client side...
82
+
83
+//        if (log.isDebugEnabled()) {
84
+//            log.debug(ToStringBuilder.reflectionToString(orderRequest));
85
+//        }
86
+        System.out.println(ToStringBuilder.reflectionToString(orderRequest, ToStringStyle.MULTI_LINE_STYLE));
75 87
         return new ResponseEntity<>(POST_ORDER_RESPONSE, HttpStatus.CREATED);
88
+//        return new ResponseEntity<>(POST_ORDER_RESPONSE.replace(POST_ORDER_RESPONSE_TO_BE_REPLACED, orderRequest.getIdempotencyKey()), HttpStatus.CREATED);
76 89
     }
77 90
 }

+ 3
- 2
test/java/fr/sayasoft/fake/zinc/FakeZincControllerUnitTest.java ファイルの表示

@@ -40,6 +40,7 @@ public class FakeZincControllerUnitTest {
40 40
 
41 41
     public static final String POST_ORDER_REQUEST = "{\n" +
42 42
             "  \"client_token\": \"public\",\n" +
43
+            "  \"idempotency_key\": \"XXX\", \n" +
43 44
             "  \"retailer\": \"amazon\",\n" +
44 45
             "  \"products\": [{\"product_id\": \"0923568964\", \"quantity\": 1}],\n" +
45 46
             "  \"max_price\": 2300,\n" +
@@ -110,7 +111,7 @@ public class FakeZincControllerUnitTest {
110 111
     @Test
111 112
     public void getOrder() throws Exception {
112 113
 
113
-        this.mockMvc.perform(get("/order/1234546"))
114
+        this.mockMvc.perform(get("/v1/order/1234546"))
114 115
                 .andDo(print()).andExpect(status().isOk())
115 116
                 .andExpect(content().string(FakeZincController.GET_ORDER_RESPONSE));
116 117
     }
@@ -120,7 +121,7 @@ public class FakeZincControllerUnitTest {
120 121
         MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
121 122
                 MediaType.APPLICATION_JSON.getSubtype(),
122 123
                 Charset.forName("utf8"));
123
-        this.mockMvc.perform(post("/order")
124
+        this.mockMvc.perform(post("/v1/order")
124 125
                 .contentType(contentType)
125 126
                 .content(POST_ORDER_REQUEST))
126 127
                 .andDo(print())