1 | package tudelft.mentalhealth.perfectfit.updatefuncs;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 |
|
---|
7 | import org.junit.Test;
|
---|
8 |
|
---|
9 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
10 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
11 |
|
---|
12 | import tudelft.dialogmanager.parameters.DoubleValue;
|
---|
13 | import tudelft.dialogmanager.parameters.Parameters;
|
---|
14 | import tudelft.dialogmanager.updatefunctions.UpdateFunction;
|
---|
15 |
|
---|
16 | public class DateStringTest {
|
---|
17 |
|
---|
18 | private static final String DATE = "11-11-2011";
|
---|
19 | private final static double DATE_EPOCH = 1321005600d;
|
---|
20 | private final String serialized = "{\"DateString\":[\"epoch\",\"datestring\"]}";
|
---|
21 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
22 |
|
---|
23 | private final DateString ds;
|
---|
24 |
|
---|
25 | public DateStringTest() throws IOException {
|
---|
26 | jackson.registerSubtypes(Example.class, Time.class, CheckDeadline.class,
|
---|
27 | TimeDifference.class, StringLength.class, DateString.class);
|
---|
28 | ds = new DateString("epoch", "datestring");
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void testSerialize() throws JsonProcessingException {
|
---|
33 | System.out.println(jackson.writeValueAsString(ds));
|
---|
34 | assertEquals(serialized, jackson.writeValueAsString(ds));
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Test
|
---|
38 | public void testDeserialize() throws JsonProcessingException {
|
---|
39 | assertEquals(ds, jackson.readValue(serialized, UpdateFunction.class));
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Test
|
---|
43 | public void callTestInPast() {
|
---|
44 |
|
---|
45 | Parameters params = new Parameters().with("epoch",
|
---|
46 | new DoubleValue(DATE_EPOCH));
|
---|
47 | Parameters newparams = ds.call(params);
|
---|
48 | assertEquals(DATE, newparams.get("datestring").getValue());
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|