comparison src/test/java/de/intevation/lada/test/validator/ProbeTest.java @ 1028:1c41c7b8f7c2 schema-update

Updated server application to new database model. THIS IS STILL WIP!!!
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 08 Jul 2016 15:32:36 +0200
parents
children
comparison
equal deleted inserted replaced
1027:9971471d562c 1028:1c41c7b8f7c2
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8 package de.intevation.lada.test.validator;
9
10 import java.sql.Timestamp;
11 import java.util.List;
12
13 import org.junit.Assert;
14
15 import de.intevation.lada.Protocol;
16 import de.intevation.lada.model.land.Probe;
17 import de.intevation.lada.validation.Validator;
18 import de.intevation.lada.validation.Violation;
19
20 public class ProbeTest {
21
22 private Validator validator;
23
24 public void setValidator(Validator validator) {
25 this.validator = validator;
26 }
27
28 public final void hasHauptprobenNr(List<Protocol> protocol) {
29 Protocol prot = new Protocol();
30 prot.setName("ProbeValidator");
31 prot.setType("has hauptprobenNr");
32 prot.setPassed(false);
33 protocol.add(prot);
34 Probe probe = new Probe();
35 probe.setHauptprobenNr("4554567890");
36 Violation violation = validator.validate(probe);
37 if (violation.hasErrors()) {
38 Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
39 }
40 prot.setPassed(true);
41 }
42
43 public final void hasNoHauptprobenNr(List<Protocol> protocol) {
44 Protocol prot = new Protocol();
45 prot.setName("ProbeValidator");
46 prot.setType("has no hauptprobenNr");
47 prot.setPassed(false);
48 protocol.add(prot);
49 Probe probe = new Probe();
50 Violation violation = validator.validate(probe);
51 Assert.assertTrue(violation.hasErrors());
52 Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
53 Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(631));
54 prot.setPassed(true);
55 }
56
57 public final void existingHauptprobenNrNew(List<Protocol> protocol) {
58 Protocol prot = new Protocol();
59 prot.setName("ProbeValidator");
60 prot.setType("existing hauptprobenNr (new)");
61 prot.setPassed(false);
62 protocol.add(prot);
63 Probe probe = new Probe();
64 probe.setHauptprobenNr("120510002");
65 prot.addInfo("hauptprobenNr", "120510002");
66 Violation violation = validator.validate(probe);
67 Assert.assertTrue(violation.hasErrors());
68 Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
69 Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(611));
70 prot.setPassed(true);
71 }
72
73 public final void uniqueHauptprobenNrNew(List<Protocol> protocol) {
74 Protocol prot = new Protocol();
75 prot.setName("ProbeValidator");
76 prot.setType("unique hauptprobenNr (new)");
77 prot.setPassed(false);
78 protocol.add(prot);
79 Probe probe = new Probe();
80 probe.setHauptprobenNr("4564567890");
81 prot.addInfo("hauptprobenNr", "4564567890");
82 Violation violation = validator.validate(probe);
83 if (violation.hasErrors()) {
84 Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
85 }
86 prot.setPassed(true);
87 }
88
89 public final void uniqueHauptprobenNrUpdate(List<Protocol> protocol) {
90 Protocol prot = new Protocol();
91 prot.setName("ProbeValidator");
92 prot.setType("unique hauptprobenNr (update)");
93 prot.setPassed(false);
94 protocol.add(prot);
95 Probe probe = new Probe();
96 probe.setId(1);
97 probe.setHauptprobenNr("4564567890");
98 prot.addInfo("hauptprobenNr", "4564567890");
99 Violation violation = validator.validate(probe);
100 if (violation.hasErrors()) {
101 Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
102 }
103 prot.setPassed(true);
104 }
105
106 public final void existingHauptprobenNrUpdate(List<Protocol> protocol) {
107 Protocol prot = new Protocol();
108 prot.setName("ProbeValidator");
109 prot.setType("existing hauptprobenNr (update)");
110 prot.setPassed(false);
111 protocol.add(prot);
112 Probe probe = new Probe();
113 probe.setId(1);
114 probe.setHauptprobenNr("120224003");
115 prot.addInfo("hauptprobenNr", "120224003");
116 Violation violation = validator.validate(probe);
117 Assert.assertTrue(violation.hasErrors());
118 Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
119 Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(611));
120 prot.setPassed(true);
121 }
122
123 public final void hasEntnahmeOrt(List<Protocol> protocol) {
124 Protocol prot = new Protocol();
125 prot.setName("ProbeValidator");
126 prot.setType("has entnahmeOrt");
127 prot.setPassed(false);
128 protocol.add(prot);
129 Probe probe = new Probe();
130 probe.setId(1);
131 Violation violation = validator.validate(probe);
132 if (violation.hasWarnings()) {
133 Assert.assertFalse(violation.getWarnings().containsKey("entnahmeOrt"));
134 }
135 prot.setPassed(true);
136 }
137
138 public final void hasNoEntnahmeOrt(List<Protocol> protocol) {
139 Protocol prot = new Protocol();
140 prot.setName("ProbeValidator");
141 prot.setType("has no entnahmeOrt");
142 prot.setPassed(false);
143 protocol.add(prot);
144 Probe probe = new Probe();
145 probe.setId(710);
146 Violation violation = validator.validate(probe);
147 Assert.assertTrue(violation.hasWarnings());
148 Assert.assertTrue(violation.getWarnings().containsKey("entnahmeOrt"));
149 Assert.assertTrue(violation.getWarnings().get("entnahmeOrt").contains(631));
150 prot.setPassed(true);
151 }
152
153 public final void hasProbeentnahmeBegin(List<Protocol> protocol) {
154 Protocol prot = new Protocol();
155 prot.setName("ProbeValidator");
156 prot.setType("has probeentnahmeBegin");
157 prot.setPassed(false);
158 protocol.add(prot);
159 Probe probe = new Probe();
160 probe.setProbeentnahmeBeginn(new Timestamp(1376287046510l));
161 probe.setProbeentnahmeEnde(new Timestamp(1376287046511l));
162 Violation violation = validator.validate(probe);
163 if (violation.hasWarnings()) {
164 Assert.assertFalse(violation.getWarnings().containsKey("probeentnahmeBeginn"));
165 }
166 prot.setPassed(true);
167 }
168
169 public final void hasNoProbeentnahmeBegin(List<Protocol> protocol) {
170 Protocol prot = new Protocol();
171 prot.setName("ProbeValidator");
172 prot.setType("has no probeentnahmeBegin");
173 prot.setPassed(false);
174 protocol.add(prot);
175 Probe probe = new Probe();
176 Violation violation = validator.validate(probe);
177 Assert.assertTrue(violation.hasWarnings());
178 Assert.assertTrue(violation.getWarnings().containsKey("probeentnahmeBeginn"));
179 Assert.assertTrue(violation.getWarnings().get("probeentnahmeBeginn").contains(631));
180 prot.setPassed(true);
181 }
182
183 public final void timeNoEndProbeentnahmeBegin(List<Protocol> protocol) {
184 Protocol prot = new Protocol();
185 prot.setName("ProbeValidator");
186 prot.setType("time no end probeentnahmeBegin");
187 prot.setPassed(false);
188 protocol.add(prot);
189 Probe probe = new Probe();
190 probe.setProbeentnahmeBeginn(new Timestamp(1376287046510l));
191 Violation violation = validator.validate(probe);
192 if (violation.hasWarnings()) {
193 Assert.assertFalse(violation.getWarnings().containsKey("probeentnahmeBeginn"));
194 }
195 prot.setPassed(true);
196 }
197
198 public final void timeNoBeginProbeentnahmeBegin(List<Protocol> protocol) {
199 Protocol prot = new Protocol();
200 prot.setName("ProbeValidator");
201 prot.setType("time no begin probeentnahmeBegin");
202 prot.setPassed(false);
203 protocol.add(prot);
204 Probe probe = new Probe();
205 probe.setProbeentnahmeEnde(new Timestamp(1376287046510l));
206 Violation violation = validator.validate(probe);
207 Assert.assertTrue(violation.getWarnings().get("probeentnahmeBeginn").contains(631));
208 Assert.assertTrue(violation.getWarnings().get("probeentnahmeBeginn").contains(662));
209 prot.setPassed(true);
210 }
211
212 public final void timeBeginAfterEndProbeentnahmeBegin(List<Protocol> protocol) {
213 Protocol prot = new Protocol();
214 prot.setName("ProbeValidator");
215 prot.setType("time begin after end probeentnahmeBegin");
216 prot.setPassed(false);
217 protocol.add(prot);
218 Probe probe = new Probe();
219 probe.setProbeentnahmeBeginn(new Timestamp(1376287046511l));
220 probe.setProbeentnahmeEnde(new Timestamp(1376287046510l));
221 Violation violation = validator.validate(probe);
222 Assert.assertTrue(violation.getWarnings().get("probeentnahmeBeginn").contains(662));
223 prot.setPassed(true);
224 }
225
226 public final void timeBeginFutureProbeentnahmeBegin(List<Protocol> protocol) {
227 Protocol prot = new Protocol();
228 prot.setName("ProbeValidator");
229 prot.setType("time begin in future probeentnahmeBegin");
230 prot.setPassed(false);
231 protocol.add(prot);
232 Probe probe = new Probe();
233 probe.setProbeentnahmeBeginn(new Timestamp(2376287046511l));
234 Violation violation = validator.validate(probe);
235 Assert.assertTrue(violation.getWarnings().get("probeentnahmeBeginn").contains(661));
236 prot.setPassed(true);
237 }
238
239 public final void hasUmwelt(List<Protocol> protocol) {
240 Protocol prot = new Protocol();
241 prot.setName("ProbeValidator");
242 prot.setType("has Umwelt");
243 prot.setPassed(false);
244 protocol.add(prot);
245 Probe probe = new Probe();
246 probe.setUmwId("A4");
247 Violation violation = validator.validate(probe);
248 if (violation.hasWarnings()) {
249 Assert.assertFalse(violation.getWarnings().containsKey("umwId"));
250 }
251 prot.setPassed(true);
252 }
253
254 public final void hasNoUmwelt(List<Protocol> protocol) {
255 Protocol prot = new Protocol();
256 prot.setName("ProbeValidator");
257 prot.setType("has no Umwelt");
258 prot.setPassed(false);
259 protocol.add(prot);
260 Probe probe = new Probe();
261 Violation violation = validator.validate(probe);
262 Assert.assertTrue(violation.hasWarnings());
263 Assert.assertTrue(violation.getWarnings().containsKey("umwId"));
264 Assert.assertTrue(violation.getWarnings().get("umwId").contains(631));
265 prot.setPassed(true);
266 }
267
268 public final void hasEmptyUmwelt(List<Protocol> protocol) {
269 Protocol prot = new Protocol();
270 prot.setName("ProbeValidator");
271 prot.setType("has empty Umwelt");
272 prot.setPassed(false);
273 protocol.add(prot);
274 Probe probe = new Probe();
275 probe.setUmwId("");
276 Violation violation = validator.validate(probe);
277 Assert.assertTrue(violation.hasWarnings());
278 Assert.assertTrue(violation.getWarnings().containsKey("umwId"));
279 Assert.assertTrue(violation.getWarnings().get("umwId").contains(631));
280 prot.setPassed(true);
281 }
282 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)