info.java: remove date and hosts fields.
[olsrd.git] / lib / info.java / org.olsr.v1.info.api / test / org / olsr / v1 / info / api / dto / TestJsonInfoStartup.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 import java.util.LinkedList;
10 import java.util.List;
11
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15
16 @SuppressWarnings("static-method")
17 public class TestJsonInfoStartup {
18   private JsonInfoStartup impl = null;
19
20   @Before
21   public void setUp() {
22     this.impl = new JsonInfoStartup();
23   }
24
25   @After
26   public void tearDown() {
27     this.impl = null;
28   }
29
30   @Test(timeout = 8000)
31   public void testGettersAndSetters() {
32     /* initial */
33     assertThat(this.impl.getVersion(), notNullValue());
34     assertThat(this.impl.getPlugins(), notNullValue());
35     assertThat(Integer.valueOf(this.impl.getPlugins().size()), equalTo(Integer.valueOf(0)));
36     assertThat(this.impl.getConfig(), notNullValue());
37
38     /* set */
39     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
40     version.setVersion("now");
41
42     final List<JsonInfoPluginsEntry> plugins = new LinkedList<>();
43     final JsonInfoPluginsEntry pluginsEntry = new JsonInfoPluginsEntry();
44     plugins.add(pluginsEntry);
45
46     final JsonInfoConfigEntry config = new JsonInfoConfigEntry();
47     config.setExitValue(11);
48
49     this.impl.setVersion(version);
50     this.impl.setPlugins(plugins);
51     this.impl.setConfig(config);
52
53     /* get */
54     assertThat(this.impl.getVersion(), equalTo(version));
55     assertThat(this.impl.getPlugins(), equalTo(plugins));
56     assertThat(Integer.valueOf(this.impl.getPlugins().size()), equalTo(Integer.valueOf(1)));
57     assertThat(this.impl.getConfig(), equalTo(config));
58
59     /* set */
60     this.impl.setVersion(null);
61     this.impl.setPlugins(null);
62     this.impl.setConfig(null);
63
64     /* get */
65     assertThat(this.impl.getVersion(), notNullValue());
66     assertThat(this.impl.getPlugins(), notNullValue());
67     assertThat(Integer.valueOf(this.impl.getPlugins().size()), equalTo(Integer.valueOf(0)));
68     assertThat(this.impl.getConfig(), notNullValue());
69   }
70
71   @Test(timeout = 8000)
72   public void testEquals() {
73     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
74     version.setVersion("now");
75
76     final List<JsonInfoPluginsEntry> plugins = new LinkedList<>();
77     final JsonInfoPluginsEntry pluginsEntry = new JsonInfoPluginsEntry();
78     plugins.add(pluginsEntry);
79
80     final JsonInfoConfigEntry config = new JsonInfoConfigEntry();
81     config.setExitValue(11);
82
83     boolean r;
84     final Object otherNull = null;
85     final JsonInfoStartup otherEqual = new JsonInfoStartup();
86     final JsonInfoStartup otherSuperNotEqual = new JsonInfoStartup();
87     otherSuperNotEqual.setTimeSinceStartup(321);
88
89     r = this.impl.equals(this.impl);
90     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
91
92     r = this.impl.equals(otherNull);
93     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
94
95     r = this.impl.equals(otherSuperNotEqual);
96     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
97
98     /* version */
99
100     this.impl.setVersion(null);
101     otherEqual.setVersion(null);
102     r = this.impl.equals(otherEqual);
103     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
104
105     this.impl.setVersion(null);
106     otherEqual.setVersion(version);
107     r = this.impl.equals(otherEqual);
108     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
109
110     this.impl.setVersion(version);
111     otherEqual.setVersion(null);
112     r = this.impl.equals(otherEqual);
113     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
114
115     this.impl.setVersion(version);
116     otherEqual.setVersion(version);
117     r = this.impl.equals(otherEqual);
118     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
119
120     this.impl.setVersion(null);
121     otherEqual.setVersion(null);
122
123     /* plugins */
124
125     this.impl.setPlugins(plugins);
126     r = this.impl.equals(otherEqual);
127     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
128     this.impl.setPlugins(null);
129
130     /* config */
131
132     this.impl.setConfig(null);
133     otherEqual.setConfig(null);
134     r = this.impl.equals(otherEqual);
135     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
136
137     this.impl.setConfig(null);
138     otherEqual.setConfig(config);
139     r = this.impl.equals(otherEqual);
140     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
141
142     this.impl.setConfig(config);
143     otherEqual.setConfig(null);
144     r = this.impl.equals(otherEqual);
145     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
146
147     this.impl.setConfig(config);
148     otherEqual.setConfig(config);
149     r = this.impl.equals(otherEqual);
150     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
151
152     this.impl.setConfig(null);
153     otherEqual.setConfig(null);
154   }
155
156   @Test(timeout = 8000)
157   public void testHashCode() {
158     int r = this.impl.hashCode();
159     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1731827376)));
160
161     /* set */
162     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
163     version.setVersion("now");
164
165     final List<JsonInfoPluginsEntry> plugins = new LinkedList<>();
166     final JsonInfoPluginsEntry pluginsEntry = new JsonInfoPluginsEntry();
167     plugins.add(pluginsEntry);
168
169     final JsonInfoConfigEntry config = new JsonInfoConfigEntry();
170     config.setExitValue(11);
171
172     this.impl.setVersion(version);
173     this.impl.setPlugins(plugins);
174     this.impl.setConfig(config);
175
176     r = this.impl.hashCode();
177     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(814643292)));
178
179     /* set */
180     this.impl.setVersion(null);
181     this.impl.setPlugins(null);
182     this.impl.setConfig(null);
183
184     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(814643292)));
185   }
186
187   @Test(timeout = 8000)
188   public void testToString() {
189     final String r = this.impl.toString();
190     assertThat(r, notNullValue());
191   }
192
193   @Test(timeout = 8000)
194   public void testJSON() throws IOException {
195     final String fn = "doc/examples/startup.json";
196
197     final String output = Helpers.readFile(new File(fn));
198     final JsonInfoStartup gws = Helpers.objectMapper.readValue(output, JsonInfoStartup.class);
199     assertThat(gws, notNullValue());
200   }
201 }