# HG changeset patch # User Raimund Renkert # Date 1424771769 -3600 # Node ID bf387959b75e85b7ecdb464f89673e31e20e038e # Parent 1d4d6112ffeebeb94730db7bdfef87e802f7cbce Added validator tests. diff -r 1d4d6112ffee -r bf387959b75e src/test/java/de/intevation/lada/LadaValidatorTest.java --- a/src/test/java/de/intevation/lada/LadaValidatorTest.java Tue Feb 24 10:55:19 2015 +0100 +++ b/src/test/java/de/intevation/lada/LadaValidatorTest.java Tue Feb 24 10:56:09 2015 +0100 @@ -22,8 +22,10 @@ @Inject @ValidationConfig(type="Probe") private Validator probeValidator; + private Probe probeTest; public LadaValidatorTest() { + probeTest = new Probe(); testProtocol = new ArrayList(); } @@ -31,4 +33,64 @@ public static void beforeTests() { logger.info("---------- Testing Lada Validator ----------"); } + + @Test + public final void probeHasHauptprobenNr() { + probeTest.setValidator(probeValidator); + probeTest.hasHauptprobenNr(testProtocol); + } + + @Test + public final void probeHasNoHauptprobenNr() { + probeTest.setValidator(probeValidator); + probeTest.hasNoHauptprobenNr(testProtocol); + } + + @Test + public final void probeExistingHauptprobenNrNew() { + probeTest.setValidator(probeValidator); + probeTest.existingHauptprobenNrNew(testProtocol); + } + + @Test + public final void probeUniqueHauptprobenNrNew() { + probeTest.setValidator(probeValidator); + probeTest.uniqueHauptprobenNrNew(testProtocol); + } + + @Test + public final void probeExistingHauptprobenNrUpdate() { + probeTest.setValidator(probeValidator); + probeTest.existingHauptprobenNrUpdate(testProtocol); + } + + @Test + public final void probeUniqueHauptprobenNrUpdate() { + probeTest.setValidator(probeValidator); + probeTest.uniqueHauptprobenNrUpdate(testProtocol); + } + + @Test + public final void probeHasEntnahmeOrt() { + probeTest.setValidator(probeValidator); + probeTest.hasEntnahmeOrt(testProtocol); + } + + @Test + public final void probeHasNoEntnahmeOrt() { + probeTest.setValidator(probeValidator); + probeTest.hasNoEntnahmeOrt(testProtocol); + } + + @Test + public final void probeHasProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.hasProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeHasNoProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.hasNoProbeentnahmeBegin(testProtocol); + } } diff -r 1d4d6112ffee -r bf387959b75e src/test/java/de/intevation/lada/test/validator/Probe.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/validator/Probe.java Tue Feb 24 10:56:09 2015 +0100 @@ -0,0 +1,178 @@ +package de.intevation.lada.test.validator; + +import java.sql.Timestamp; +import java.util.List; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.validation.Validator; +import de.intevation.lada.validation.Violation; + +public class Probe { + + private Validator validator; + + public void setValidator(Validator validator) { + this.validator = validator; + } + + public final void hasHauptprobenNr(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has hauptprobenNr"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setHauptprobenNr("1234567890"); + Violation violation = validator.validate(probe); + if (violation.hasErrors()) { + Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr")); + prot.setPassed(true); + return; + } + prot.setPassed(true); + } + + public final void hasNoHauptprobenNr(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has no hauptprobenNr"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + Violation violation = validator.validate(probe); + Assert.assertTrue(violation.hasErrors()); + Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr")); + Assert.assertTrue(violation.getErrors().get("hauptprobenNr") == 631); + prot.setPassed(true); + } + + public final void existingHauptprobenNrNew(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("existing hauptprobenNr (new)"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setHauptprobenNr("120510002"); + prot.addInfo("hauptprobenNr", "120510002"); + Violation violation = validator.validate(probe); + Assert.assertTrue(violation.hasErrors()); + Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr")); + Assert.assertTrue(violation.getErrors().get("hauptprobenNr") == 611); + prot.setPassed(true); + } + + public final void uniqueHauptprobenNrNew(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("unique hauptprobenNr (new)"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setHauptprobenNr("1234567890"); + prot.addInfo("hauptprobenNr", "1234567890"); + Violation violation = validator.validate(probe); + if (violation.hasErrors()) { + Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr")); + return; + } + prot.setPassed(true); + } + + public final void uniqueHauptprobenNrUpdate(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("unique hauptprobenNr (update)"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setId(1); + probe.setHauptprobenNr("1234567890"); + prot.addInfo("hauptprobenNr", "1234567890"); + Violation violation = validator.validate(probe); + if (violation.hasErrors()) { + Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr")); + return; + } + prot.setPassed(true); + } + + public final void existingHauptprobenNrUpdate(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("existing hauptprobenNr (update)"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setId(1); + probe.setHauptprobenNr("120224003"); + prot.addInfo("hauptprobenNr", "120224003"); + Violation violation = validator.validate(probe); + Assert.assertTrue(violation.hasErrors()); + Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr")); + Assert.assertTrue(violation.getErrors().get("hauptprobenNr") == 611); + prot.setPassed(true); + } + + public final void hasEntnahmeOrt(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has entnahmeOrt"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setId(1); + Violation violation = validator.validate(probe); + if (violation.hasWarnings()) { + Assert.assertFalse(violation.getWarnings().containsKey("entnahmeOrt")); + } + prot.setPassed(true); + } + + public final void hasNoEntnahmeOrt(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has no entnahmeOrt"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setId(710); + Violation violation = validator.validate(probe); + Assert.assertTrue(violation.hasWarnings()); + Assert.assertTrue(violation.getWarnings().containsKey("entnahmeOrt")); + Assert.assertTrue(violation.getWarnings().get("entnahmeOrt") == 631); + prot.setPassed(true); + } + + public final void hasProbeentnahmeBegin(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has probeentnahmeBegin"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + probe.setProbeentnahmeBeginn(new Timestamp(1376287046510l)); + Violation violation = validator.validate(probe); + if (violation.hasWarnings()) { + Assert.assertFalse(violation.getWarnings().containsKey("probeentnahmeBegin")); + } + prot.setPassed(true); + } + + public final void hasNoProbeentnahmeBegin(List protocol) { + Protocol prot = new Protocol(); + prot.setName("ProbeValidator"); + prot.setType("has no probeentnahmeBegin"); + prot.setPassed(false); + protocol.add(prot); + LProbe probe = new LProbe(); + Violation violation = validator.validate(probe); + Assert.assertTrue(violation.hasWarnings()); + Assert.assertTrue(violation.getWarnings().containsKey("probeentnahmeBegin")); + Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin") == 631); + prot.setPassed(true); + } +}