1 | package tudelft.mentalhealth.perfectfit.updatefuncs;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertNotEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.IOException;
|
---|
8 |
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
12 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
13 |
|
---|
14 | import tudelft.dialogmanager.parameters.DoubleValue;
|
---|
15 | import tudelft.dialogmanager.parameters.Parameters;
|
---|
16 | import tudelft.dialogmanager.parameters.StringValue;
|
---|
17 | import tudelft.dialogmanager.updatefunctions.UpdateFunction;
|
---|
18 |
|
---|
19 | public class CheckDeadlineTest {
|
---|
20 |
|
---|
21 | private final String serialized = "{\"CheckDeadline\":[\"date\",\"time\",\"message\"]}";
|
---|
22 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
23 |
|
---|
24 | private final CheckDeadline dl1;
|
---|
25 |
|
---|
26 | public CheckDeadlineTest() throws IOException {
|
---|
27 | jackson.registerSubtypes(Example.class, Time.class, CheckDeadline.class,
|
---|
28 | TimeDifference.class, StringLength.class);
|
---|
29 | dl1 = new CheckDeadline("date", "time", "message");
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Test
|
---|
33 | public void testSerialize() throws JsonProcessingException {
|
---|
34 | System.out.println(jackson.writeValueAsString(dl1));
|
---|
35 | assertEquals(serialized, jackson.writeValueAsString(dl1));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void testDeserialize() throws JsonProcessingException {
|
---|
40 | assertEquals(dl1, jackson.readValue(serialized, UpdateFunction.class));
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Test
|
---|
44 | public void callTestInPast() {
|
---|
45 | Parameters params = new Parameters().with("date",
|
---|
46 | new StringValue("11-11-2011"));
|
---|
47 | Parameters newparams = dl1.call(params);
|
---|
48 | // we should get an error
|
---|
49 | assertEquals(new DoubleValue(-1d), newparams.get("time"));
|
---|
50 | assertTrue(((StringValue) newparams.get("message")).getValue()
|
---|
51 | .contains("in the past"));
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Test
|
---|
55 | public void callTestInFuture() {
|
---|
56 | Parameters params = new Parameters().with("date",
|
---|
57 | new StringValue("11-11-2399"));
|
---|
58 | Parameters newparams = dl1.call(params);
|
---|
59 | // should give legal value
|
---|
60 | assertNotEquals(new DoubleValue(-1d), newparams.get("time"));
|
---|
61 | assertTrue(((StringValue) newparams.get("message")).getValue()
|
---|
62 | .contains("Okay!"));
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|