Open Kilda Java Documentation
FlowStatusResponseTest.java
Go to the documentation of this file.
1 package org.openkilda.messaging.info.flow;
2 
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import org.junit.Assert;
5 import org.junit.Test;
10 
11 import java.io.IOException;
12 
13 import static org.openkilda.messaging.Utils.MAPPER;
14 
15 
16 public class FlowStatusResponseTest {
17 
18  /*
19  * JSON: { "clazz":"org.openkilda.messaging.info.InfoMessage",
20  * "destination":"NORTHBOUND",
21  * "payload":{
22  * "clazz":"org.openkilda.messaging.info.flow.FlowStatusResponse",
23  * "payload":{
24  * "flowid":"FLOW",
25  * "status":"UP"},
26  * "timestamp":1520475170274},
27  * "timestamp":10,
28  * "correlation_id":"CORRELATION"}
29 
30  */
31 
32  private final String json = "{" +
33  "\"clazz\":\"org.openkilda.messaging.info.InfoMessage\"," +
34  "\"destination\":\"NORTHBOUND\"," +
35  "\"payload\":{" +
36  "\"clazz\":\"org.openkilda.messaging.info.flow.FlowStatusResponse\"," +
37  "\"payload\":{" +
38  "\"flowid\":\"FLOW\"," +
39  "\"status\":\"UP\"}," +
40  "\"timestamp\":1520474258050}," +
41  "\"timestamp\":10," +
42  "\"correlation_id\":\"CORRELATION\"}";
43 
44  @Test
45  public void testJsonSerialization() throws IOException {
46  /*
47  * Start with serializing to JSON.
48  * Then re-populate from JSON.
49  */
50  InfoMessage msg = new InfoMessage(new FlowStatusResponse(new FlowIdStatusPayload("FLOW", FlowState.UP)), 10L,"CORRELATION", Destination.NORTHBOUND);
51 
52  InfoMessage fromJson = MAPPER.readValue(json, InfoMessage.class);
53  FlowStatusResponse fsrJson = (FlowStatusResponse) fromJson.getData();
55 
56  Assert.assertEquals(fsrJson.getPayload().getId(), fsrObj.getPayload().getId());
57  Assert.assertEquals(fsrJson.getPayload().getStatus(), fsrObj.getPayload().getStatus());
58  Assert.assertEquals(fsrJson.getPayload().getStatus(), FlowState.UP);
59  Assert.assertEquals(fromJson.getCorrelationId(), msg.getCorrelationId());
60 
61 
62  System.out.println("JSON: " + MAPPER.writeValueAsString(msg));
63  }
64 }
static final ObjectMapper MAPPER
Definition: Utils.java:31