changeset 311:eeb5d3a5e194

JUnit test cases and small test application for LAF importer. !! Currently the tests are ignored when running with maven. !! Some system properties are still missing in maven (coming soon ;))
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 20 Aug 2013 16:19:20 +0200
parents 821557a17e5e
children fb47c445af20
files src/test/java/de/intevation/lada/ImporterTest.java src/test/java/de/intevation/lada/importer/TestLAFImporter.java
diffstat 2 files changed, 201 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/ImporterTest.java	Tue Aug 20 16:19:20 2013 +0200
@@ -0,0 +1,60 @@
+package de.intevation.lada;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Ignore;
+
+import de.intevation.lada.auth.AuthenticationResponse;
+import de.intevation.lada.importer.TestLAFImporter;
+
+
+@Ignore
+public class ImporterTest
+{
+    @Ignore
+    public static void main(String[] args) {
+        System.setProperty(
+            "de_intevation_lada_test_singleprobe",
+            "/home/rrenkert/single.laf");
+        System.setProperty(
+            "de_intevation_lada_test_incompleteprobe",
+            "/home/rrenkert/incomplete.laf");
+        System.setProperty(
+            "de_intevation_lada_import",
+            "/opt/lada/config/import.json");
+        System.out.println("ImporterTest started.");
+        TestLAFImporter test = new TestLAFImporter();
+        test.loadLafFiles();
+
+        System.out.print("Testing config file not found: ");
+        test.testConfigFileNotFound();
+        System.out.print("success.\n");
+
+        System.out.print("Testing config file: ");
+        test.testConfigFileLoading();
+        System.out.print("success.\n");
+
+        System.out.print("Testing Parser:\n  1. Wrong header: ");
+        test.testProbeHeaderFail();
+        System.out.print("success.\n  2. Complete probe: ");
+        test.testCompleteParser();
+        System.out.print("success.\n");
+
+        //Prepare simulated authorization.
+        List<String> netzbetreiber = new ArrayList<String>();
+        netzbetreiber.add("0611");
+        List<String> mst = new ArrayList<String>();
+        mst.add("06110");
+        mst.add("06112");
+        AuthenticationResponse auth = new AuthenticationResponse();
+        auth.setUser("testeins");
+        auth.setNetzbetreiber(netzbetreiber);
+        auth.setMst(mst);
+        auth.setNetzbetreiber(netzbetreiber);
+
+
+        System.out.println("end.");
+        return;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/importer/TestLAFImporter.java	Tue Aug 20 16:19:20 2013 +0200
@@ -0,0 +1,141 @@
+package de.intevation.lada.importer;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import de.intevation.lada.data.importer.EntryFormat;
+import de.intevation.lada.data.importer.LAFFormat;
+import de.intevation.lada.data.importer.LAFParser;
+import de.intevation.lada.data.importer.LAFParserException;
+
+
+public class TestLAFImporter
+{
+
+    private static final String PROBE_HEADER_FAIL =
+        "%OBE%\n";
+    private String singleProbe;
+    private String incompleteProbe;
+
+    @Before
+    @Ignore
+    public void loadLafFiles() {
+        String single = System.getProperty("de_intevation_lada_test_singleprobe");
+        String incomplete =
+            System.getProperty("de_intevation_lada_test_incompleteprobe");
+        try {
+            byte[] encodedSingle = Files.readAllBytes(Paths.get(single));
+            byte[] encodedIncomplete =
+                Files.readAllBytes(Paths.get(incomplete));
+            Charset encoding = Charset.defaultCharset();
+            singleProbe =
+                encoding.decode(ByteBuffer.wrap(encodedSingle)).toString();
+            incompleteProbe =
+                encoding.decode(ByteBuffer.wrap(encodedIncomplete)).toString();
+        }
+        catch (IOException ioe) {
+            singleProbe = "";
+            incompleteProbe = "";
+        }
+    }
+
+    @Test(expected = IOException.class)
+    @Ignore
+    public void testConfigFileNotFound() {
+        LAFFormat format = new LAFFormat();
+        boolean success = format.readConfigFile("/file/not/found");
+    }
+
+    @Test
+    @Ignore
+    public void testConfigFileLoading() {
+        String fileName = System.getProperty("de_intevation_lada_import");
+        LAFFormat format = new LAFFormat();
+        boolean success = format.readConfigFile(fileName);
+        assertEquals(true, success);
+        List<EntryFormat> probeFormat = format.getFormat("probe");
+        assertNotNull("No probe format available", probeFormat);
+        assertEquals(
+            "Not enough configuration elements for probe.",
+            32,
+            probeFormat.size());
+        List<EntryFormat> messungFormat = format.getFormat("messung");
+        assertNotNull("No messung format available", messungFormat);
+        assertEquals(
+            "Not enough configuration elements for messung.",
+            10,
+            messungFormat.size());
+        List<EntryFormat> ortFormat = format.getFormat("ort");
+        assertNotNull("No ort format available", ortFormat);
+        assertEquals(
+            "Not enough configuration elements for ort.",
+            20,
+            ortFormat.size());
+    }
+
+    @Test(expected = LAFParserException.class)
+    @Ignore
+    public void testProbeHeaderFail() {
+        LAFParser parser = new LAFParser();
+        parser.setDryRun(true);
+        try {
+            parser.parse(PROBE_HEADER_FAIL);
+        }
+        catch (LAFParserException e) {
+            assertEquals(
+                "Exception cause not expected: " + e.getMessage(),
+                "No %PROBE% at the begining.", e.getMessage());
+        }
+    }
+
+    @Test
+    @Ignore
+    public void testIncompleteProbe() {
+        LAFParser parser = new LAFParser();
+        parser.setDryRun(true);
+        try {
+            parser.parse(incompleteProbe);
+        }
+        catch (LAFParserException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    @Ignore
+    public void testCompleteParser() {
+        LAFParser parser = new LAFParser();
+        //parser.setDryRun(true);
+        try {
+            parser.parse(singleProbe);
+        }
+        catch (LAFParserException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    @Ignore
+    public void testMessungParser() {
+        fail("Not yet implemented");
+    }
+
+    @Test
+    @Ignore
+    public void testOrtParser() {
+        fail("Not yet implemented");
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)