info.java: remove date and hosts fields.
[olsrd.git] / lib / info.java / org.olsr.v1.info.api / test / org / olsr / v1 / info / api / dto / TestJsonInfoVersion.java
1 package org.olsr.v1.info.api.dto;
2
3 import static org.hamcrest.core.IsEqual.equalTo;
4 import static org.hamcrest.core.IsNull.notNullValue;
5 import static org.junit.Assert.assertThat;
6
7 import java.io.File;
8 import java.io.IOException;
9
10 import org.junit.After;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 @SuppressWarnings("static-method")
15 public class TestJsonInfoVersion {
16   private JsonInfoVersion impl = null;
17
18   @Before
19   public void setUp() {
20     this.impl = new JsonInfoVersion();
21   }
22
23   @After
24   public void tearDown() {
25     this.impl = null;
26   }
27
28   @Test(timeout = 8000)
29   public void testGettersAndSetters() {
30
31     /* initial */
32     assertThat(this.impl.getVersion(), notNullValue());
33
34     /* set */
35     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
36     version.setVersion("version2");
37     this.impl.setVersion(version);
38
39     /* get */
40     assertThat(this.impl.getVersion(), equalTo(version));
41   }
42
43   @Test(timeout = 8000)
44   public void testEquals() {
45     final JsonInfoVersionEntry entry = new JsonInfoVersionEntry();
46     entry.setVersion("version");
47     this.impl.setVersion(entry);
48
49     boolean r;
50     final Object otherNull = null;
51     final JsonInfoVersion otherSuperNotEqual = new JsonInfoVersion();
52     otherSuperNotEqual.setTimeSinceStartup(321);
53
54     final JsonInfoVersion otherSame = new JsonInfoVersion();
55     final JsonInfoVersionEntry versionOtherSame = new JsonInfoVersionEntry();
56     versionOtherSame.setVersion("version");
57     otherSame.setVersion(versionOtherSame);
58
59     final JsonInfoVersion otherNotSame1 = new JsonInfoVersion();
60     final JsonInfoVersionEntry versionOtherNotSame1 = new JsonInfoVersionEntry();
61     versionOtherNotSame1.setVersion("version otherNotSame1");
62     otherNotSame1.setVersion(versionOtherNotSame1);
63
64     r = this.impl.equals(this.impl);
65     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
66
67     r = this.impl.equals(otherNull);
68     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
69
70     r = this.impl.equals(otherSuperNotEqual);
71     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
72
73     r = this.impl.equals(otherNotSame1);
74     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
75
76     r = this.impl.equals(otherSame);
77     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
78
79     this.impl.setVersion(null);
80     r = this.impl.equals(otherNotSame1);
81     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
82
83     otherNotSame1.setVersion(null);
84     r = this.impl.equals(otherNotSame1);
85     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
86   }
87
88   @Test(timeout = 8000)
89   public void testComapreTo() {
90     int r;
91
92     r = this.impl.compareTo(null);
93     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
94
95     final JsonInfoVersion v = new JsonInfoVersion();
96     v.setError("error");
97     r = this.impl.compareTo(v);
98     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
99   }
100
101   @Test(timeout = 8000)
102   public void testHashCode() {
103     int r = this.impl.hashCode();
104     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1771439486)));
105
106     /* set */
107     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
108     version.setVersion("version2");
109     this.impl.setVersion(version);
110
111     r = this.impl.hashCode();
112     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1623836376)));
113   }
114
115   @Test(timeout = 8000)
116   public void testToString() {
117     final String r = this.impl.toString();
118     assertThat(r, notNullValue());
119   }
120
121   @Test(timeout = 8000)
122   public void testJSON() throws IOException {
123     final String fn = "doc/examples/version.json";
124
125     final String output = Helpers.readFile(new File(fn));
126     final JsonInfoVersion version = Helpers.objectMapper.readValue(output, JsonInfoVersion.class);
127     assertThat(version, notNullValue());
128   }
129 }