source: events/src/test/java/geniusweb/events/ActionEventTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.3 KB
Line 
1package geniusweb.events;
2
3import static org.junit.Assert.assertEquals;
4import static org.mockito.Mockito.mock;
5
6import java.io.IOException;
7import java.util.Arrays;
8import java.util.List;
9
10import org.junit.Test;
11
12import com.fasterxml.jackson.core.JsonProcessingException;
13import com.fasterxml.jackson.databind.ObjectMapper;
14
15import geniusweb.actions.Action;
16import geniusweb.actions.EndNegotiation;
17import geniusweb.actions.PartyId;
18import tudelft.utilities.junit.GeneralTests;
19
20public class ActionEventTest extends GeneralTests<ActionEvent> {
21 private static final long NOW = 101l;
22 private final ObjectMapper jackson = new ObjectMapper();
23 private final String string = "{\"ActionEvent\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}},\"time\":101}}";
24 private final PartyId id = new PartyId("party1");
25 private final Action action = new EndNegotiation(id);
26 private final ActionEvent evt = new ActionEvent(action, NOW);
27 private final ActionEvent evt1 = new ActionEvent(action, NOW);
28 private final ActionEvent evtb = new ActionEvent(action, NOW + 1);
29
30 @Override
31 public List<List<ActionEvent>> getGeneralTestData() {
32 return Arrays.asList(Arrays.asList(evt, evt1), Arrays.asList(evtb));
33 }
34
35 @Override
36 public List<String> getGeneralTestStrings() {
37 return Arrays.asList("ActionEvent\\[.*" + NOW + ".*EndNegotiation.*\\]",
38 "ActionEvent\\[.*" + (NOW + 1) + ".*EndNegotiation.*\\]");
39 }
40
41 @Test
42 public void smoketest() {
43 Action action = mock(EndNegotiation.class);
44 ActionEvent evt = new ActionEvent(action, 0l);
45 }
46
47 @Test
48 public void serializeTest() throws JsonProcessingException {
49 System.out.println(jackson.writeValueAsString(evt));
50 assertEquals(string, jackson.writeValueAsString(evt));
51 }
52
53 @Test
54 public void deserializeTestReadActionEvent() throws IOException {
55 ActionEvent evt1 = jackson.readValue(string, ActionEvent.class);
56 // compare fields, as evt is a derived/new inner class
57 assertEquals(EndNegotiation.class, evt1.getAction().getClass());
58 assertEquals((Long) 101l, evt1.getTime());
59 }
60
61 @Test
62 public void deserializeTestReadEvent() throws IOException {
63 NegotiationEvent evt1 = jackson.readValue(string,
64 NegotiationEvent.class);
65 assertEquals(ActionEvent.class, evt1.getClass());
66 ActionEvent ev1 = (ActionEvent) evt1;
67 assertEquals(EndNegotiation.class, ev1.getAction().getClass());
68 assertEquals((Long) 101l, ev1.getTime());
69 }
70
71}
Note: See TracBrowser for help on using the repository browser.