source: PerfectFit/Dialog/src/test/java/tudelft/mentalhealth/perfectfit/updatefuncs/CheckDeadlineTest.java

Last change on this file was 7, checked in by Wouter Pasman, 10 months ago

#124 release PerfectFit sources

File size: 2.0 KB
Line 
1package tudelft.mentalhealth.perfectfit.updatefuncs;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8
9import org.junit.Test;
10
11import com.fasterxml.jackson.core.JsonProcessingException;
12import com.fasterxml.jackson.databind.ObjectMapper;
13
14import tudelft.dialogmanager.parameters.DoubleValue;
15import tudelft.dialogmanager.parameters.Parameters;
16import tudelft.dialogmanager.parameters.StringValue;
17import tudelft.dialogmanager.updatefunctions.UpdateFunction;
18
19public 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}
Note: See TracBrowser for help on using the repository browser.