comparison src/test/java/de/intevation/lada/test/validator/Messung.java @ 564:7a10b1e85c79

Added testclass for messung validator.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 13 Mar 2015 16:49:33 +0100
parents
children 261095b700a0
comparison
equal deleted inserted replaced
563:4a78dad2c31f 564:7a10b1e85c79
1 package de.intevation.lada.test.validator;
2
3 import java.util.List;
4
5 import org.junit.Assert;
6
7 import de.intevation.lada.Protocol;
8 import de.intevation.lada.model.land.LMessung;
9 import de.intevation.lada.validation.Validator;
10 import de.intevation.lada.validation.Violation;
11
12 public class Messung {
13
14 private Validator validator;
15
16 public void setValidator(Validator validator) {
17 this.validator = validator;
18 }
19
20 public final void hasNebenprobenNr(List<Protocol> protocol) {
21 Protocol prot = new Protocol();
22 prot.setName("MessungValidator");
23 prot.setType("has nebenprobenNr");
24 prot.setPassed(false);
25 protocol.add(prot);
26 LMessung messung = new LMessung();
27 messung.setNebenprobenNr("10R1");
28 Violation violation = validator.validate(messung);
29 if (violation.hasWarnings()) {
30 Assert.assertFalse(violation.getWarnings().containsKey("nebenprobenNr"));
31 }
32 prot.setPassed(true);
33 }
34
35 public final void hasNoNebenprobenNr(List<Protocol> protocol) {
36 Protocol prot = new Protocol();
37 prot.setName("MessungValidator");
38 prot.setType("has no nebenprobenNr");
39 prot.setPassed(false);
40 protocol.add(prot);
41 LMessung messung = new LMessung();
42 Violation violation = validator.validate(messung);
43 Assert.assertTrue(violation.hasWarnings());
44 Assert.assertTrue(violation.getWarnings().containsKey("nebenprobenNr"));
45 Assert.assertTrue(violation.getWarnings().get("nebenprobenNr").contains(631));
46 prot.setPassed(true);
47 }
48
49 public final void hasEmptyNebenprobenNr(List<Protocol> protocol) {
50 Protocol prot = new Protocol();
51 prot.setName("MessungValidator");
52 prot.setType("has empty nebenprobenNr");
53 prot.setPassed(false);
54 protocol.add(prot);
55 LMessung messung = new LMessung();
56 messung.setNebenprobenNr("");
57 Violation violation = validator.validate(messung);
58 Assert.assertTrue(violation.hasWarnings());
59 Assert.assertTrue(violation.getWarnings().containsKey("nebenprobenNr"));
60 Assert.assertTrue(violation.getWarnings().get("nebenprobenNr").contains(631));
61 prot.setPassed(true);
62 }
63
64 public final void existingNebenprobenNrNew(List<Protocol> protocol) {
65 Protocol prot = new Protocol();
66 prot.setName("MessungValidator");
67 prot.setType("existing nebenprobenNr (new)");
68 prot.setPassed(false);
69 protocol.add(prot);
70 LMessung messung = new LMessung();
71 messung.setNebenprobenNr("00G1");
72 messung.setProbeId(4);
73 Violation violation = validator.validate(messung);
74 Assert.assertTrue(violation.hasErrors());
75 Assert.assertTrue(violation.getErrors().containsKey("nebenprobenNr"));
76 Assert.assertTrue(violation.getErrors().get("nebenprobenNr").contains(611));
77 prot.setPassed(true);
78 }
79
80 public final void uniqueNebenprobenNrNew(List<Protocol> protocol) {
81 Protocol prot = new Protocol();
82 prot.setName("MessungValidator");
83 prot.setType("unique nebenprobenNr (new)");
84 prot.setPassed(false);
85 protocol.add(prot);
86 LMessung messung = new LMessung();
87 messung.setNebenprobenNr("00G2");
88 messung.setProbeId(4);
89 Violation violation = validator.validate(messung);
90 if (violation.hasErrors()) {
91 Assert.assertFalse(violation.getErrors().containsKey("nebenprobenNr"));
92 }
93 prot.setPassed(true);
94 }
95
96 public final void uniqueNebenprobenNrUpdate(List<Protocol> protocol) {
97 Protocol prot = new Protocol();
98 prot.setName("MessungValidator");
99 prot.setType("unique nebenprobenNr (update)");
100 prot.setPassed(false);
101 protocol.add(prot);
102 LMessung messung = new LMessung();
103 messung.setId(45);
104 messung.setProbeId(4);
105 messung.setNebenprobenNr("00G2");
106 Violation violation = validator.validate(messung);
107 if (violation.hasErrors()) {
108 Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
109 return;
110 }
111 prot.setPassed(true);
112 }
113
114 public final void existingHauptprobenNrUpdate(List<Protocol> protocol) {
115 Protocol prot = new Protocol();
116 prot.setName("MessungValidator");
117 prot.setType("existing nebenprobenNr (update)");
118 prot.setPassed(false);
119 protocol.add(prot);
120 LMessung messung = new LMessung();
121 messung.setId(776);
122 messung.setProbeId(1);
123 messung.setNebenprobenNr("0003");
124 Violation violation = validator.validate(messung);
125 Assert.assertTrue(violation.hasErrors());
126 Assert.assertTrue(violation.getErrors().containsKey("nebenprobenNr"));
127 Assert.assertTrue(violation.getErrors().get("nebenprobenNr").contains(611));
128 prot.setPassed(true);
129 }
130
131 public final void hasMesswert(List<Protocol> protocol) {
132 Protocol prot = new Protocol();
133 prot.setName("MessungValidator");
134 prot.setType("has messwert");
135 prot.setPassed(false);
136 protocol.add(prot);
137 LMessung messung = new LMessung();
138 messung.setId(1);
139 Violation violation = validator.validate(messung);
140 if (violation.hasWarnings()) {
141 Assert.assertFalse(violation.getWarnings().containsKey("messwert"));
142 }
143 prot.setPassed(true);
144 }
145
146 public final void hasNoMesswert(List<Protocol> protocol) {
147 Protocol prot = new Protocol();
148 prot.setName("MessungValidator");
149 prot.setType("has no messwert");
150 prot.setPassed(false);
151 protocol.add(prot);
152 LMessung messung = new LMessung();
153 messung.setId(990);
154 Violation violation = validator.validate(messung);
155 Assert.assertTrue(violation.hasWarnings());
156 Assert.assertTrue(violation.getWarnings().containsKey("messwert"));
157 Assert.assertTrue(violation.getWarnings().get("messwert").contains(631));
158 prot.setPassed(true);
159 }
160 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)