Search in sources :

Example 1 with EventMessageImpl

use of com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl in project flowgate by vmware.

the class MessageProcessingTest method testMessage.

@Test
public void testMessage() {
    ObjectMapper mapper = new ObjectMapper();
    String template = "{\"type\":\"InfoBlox\",\"eventUser\":null,\"source\":null,\"target\":null,\"createTime\":%s,\"content\":\"nihao\"}";
    long time = new Date().getTime();
    EventMessage message = new EventMessageImpl(EventType.InfoBlox, null, null, null, time, "nihao");
    String bb;
    try {
        bb = mapper.writeValueAsString(message);
        Assert.assertEquals(String.format(template, time), bb);
        EventMessage mess2 = mapper.readValue(bb, EventMessageImpl.class);
        Assert.assertEquals("nihao", mess2.getContent());
        String gg = "{\"type\":\"InfoBlox\",\"createTime\":1539073715966,\"content\":\"helloworld\"}";
        EventMessage mess3 = mapper.readValue(gg, EventMessageImpl.class);
        Assert.assertEquals("helloworld", mess3.getContent());
    } catch (IOException e) {
        Assert.fail();
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)1 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1