[44] | 1 | package geniusweb.inform;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 |
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.util.Arrays;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
| 9 | import org.junit.Before;
|
---|
| 10 | import org.junit.Test;
|
---|
| 11 |
|
---|
| 12 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
| 13 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 14 |
|
---|
| 15 | import geniusweb.actions.Action;
|
---|
| 16 | import geniusweb.actions.EndNegotiation;
|
---|
| 17 | import geniusweb.actions.PartyId;
|
---|
| 18 | import tudelft.utilities.junit.GeneralTests;
|
---|
| 19 |
|
---|
| 20 | public class ActionDoneTest extends GeneralTests<ActionDone> {
|
---|
| 21 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
| 22 |
|
---|
| 23 | private static final PartyId id = new PartyId("party1");
|
---|
| 24 | private static final PartyId id2 = new PartyId("party2");
|
---|
| 25 |
|
---|
| 26 | private final String actiondonestr = "{\"ActionDone\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}}}}";
|
---|
| 27 |
|
---|
| 28 | private final static Action act1 = new EndNegotiation(id);
|
---|
| 29 | private final static Action act2 = new EndNegotiation(id2);
|
---|
| 30 |
|
---|
| 31 | private final static ActionDone done1 = new ActionDone(act1);
|
---|
| 32 | private final static ActionDone done1a = new ActionDone(act1);
|
---|
| 33 | private final static ActionDone done2 = new ActionDone(act2);
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
| 36 | public List<List<ActionDone>> getGeneralTestData() {
|
---|
| 37 | return Arrays.asList(Arrays.asList(done1, done1a),
|
---|
| 38 | Arrays.asList(done2));
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public List<String> getGeneralTestStrings() {
|
---|
| 43 | return Arrays.asList("ActionDone.*EndNegotiation.*party1.*",
|
---|
| 44 | "ActionDone.*EndNegotiation.*party2.*");
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | @Before
|
---|
| 48 | public void before() {
|
---|
| 49 |
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | @Test
|
---|
| 53 | public void serializeAcceptTest() throws JsonProcessingException {
|
---|
| 54 | System.out.println(jackson.writeValueAsString(done1));
|
---|
| 55 | assertEquals(actiondonestr, jackson.writeValueAsString(done1));
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @Test
|
---|
| 59 | public void deserializeAcceptTest() throws IOException {
|
---|
| 60 | Inform act = jackson.readValue(actiondonestr, Inform.class);
|
---|
| 61 | assertEquals(done1, act);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | @Test
|
---|
| 65 | public void testGet() {
|
---|
| 66 | assertEquals(act1, done1.getAction());
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | }
|
---|