annotate src/test/java/de/intevation/lada/importer/TestLAFImporter.java @ 339:17904ad125f3

Ignore parser tests cause the parser uses authentication now.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 29 Aug 2013 10:05:27 +0200
parents fab1e6c74044
children a3c79dfe60a7
rev   line source
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.lada.importer;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 import static org.junit.Assert.assertEquals;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import static org.junit.Assert.assertNotNull;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import static org.junit.Assert.fail;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 import java.io.IOException;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import java.nio.ByteBuffer;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import java.nio.charset.Charset;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import java.nio.file.Files;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import java.nio.file.Paths;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import java.util.List;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 import org.junit.Before;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import org.junit.Ignore;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 import org.junit.Test;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 import de.intevation.lada.data.importer.EntryFormat;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 import de.intevation.lada.data.importer.LAFFormat;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 import de.intevation.lada.data.importer.LAFParser;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 import de.intevation.lada.data.importer.LAFParserException;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 public class TestLAFImporter
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 private static final String PROBE_HEADER_FAIL =
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 "%OBE%\n";
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 private String singleProbe;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 private String incompleteProbe;
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 @Before
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 public void loadLafFiles() {
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
35 String single = System.getProperty("de.intevation.lada.test.singleprobe");
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 String incomplete =
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
37 System.getProperty("de.intevation.lada.test.incompleteprobe");
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 try {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 byte[] encodedSingle = Files.readAllBytes(Paths.get(single));
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 byte[] encodedIncomplete =
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 Files.readAllBytes(Paths.get(incomplete));
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 Charset encoding = Charset.defaultCharset();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 singleProbe =
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 encoding.decode(ByteBuffer.wrap(encodedSingle)).toString();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 incompleteProbe =
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 encoding.decode(ByteBuffer.wrap(encodedIncomplete)).toString();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 catch (IOException ioe) {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 singleProbe = "";
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 incompleteProbe = "";
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
54 @Test
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 public void testConfigFileNotFound() {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 LAFFormat format = new LAFFormat();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 boolean success = format.readConfigFile("/file/not/found");
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
58 assertEquals(false, success);
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 @Test
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 public void testConfigFileLoading() {
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
63 String fileName = System.getProperty("de.intevation.lada.import");
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 LAFFormat format = new LAFFormat();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 boolean success = format.readConfigFile(fileName);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 assertEquals(true, success);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 List<EntryFormat> probeFormat = format.getFormat("probe");
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 assertNotNull("No probe format available", probeFormat);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 assertEquals(
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 "Not enough configuration elements for probe.",
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 32,
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 probeFormat.size());
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 List<EntryFormat> messungFormat = format.getFormat("messung");
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 assertNotNull("No messung format available", messungFormat);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 assertEquals(
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 "Not enough configuration elements for messung.",
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 10,
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 messungFormat.size());
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 List<EntryFormat> ortFormat = format.getFormat("ort");
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 assertNotNull("No ort format available", ortFormat);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 assertEquals(
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 "Not enough configuration elements for ort.",
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 20,
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 ortFormat.size());
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
87 @Test
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
88 @Ignore
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 public void testProbeHeaderFail() {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 LAFParser parser = new LAFParser();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 parser.setDryRun(true);
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
92 /*
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 try {
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
94 boolean success = parser.parse(PROBE_HEADER_FAIL);
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
95 assertEquals(false, success);
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 catch (LAFParserException e) {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 assertEquals(
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 "Exception cause not expected: " + e.getMessage(),
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 "No %PROBE% at the begining.", e.getMessage());
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 }
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
102 */
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 @Test
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 @Ignore
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 public void testIncompleteProbe() {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 LAFParser parser = new LAFParser();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 parser.setDryRun(true);
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
110 /*
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 try {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 parser.parse(incompleteProbe);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 catch (LAFParserException e) {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 e.printStackTrace();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 }
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
117 */
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 @Test
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
121 @Ignore
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 public void testCompleteParser() {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 LAFParser parser = new LAFParser();
315
79cbc672d8e4 Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents: 311
diff changeset
124 parser.setDryRun(true);
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
125 /*
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 try {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 parser.parse(singleProbe);
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 catch (LAFParserException e) {
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130 e.printStackTrace();
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131 }
339
17904ad125f3 Ignore parser tests cause the parser uses authentication now.
Raimund Renkert <rrenkert@intevation.de>
parents: 318
diff changeset
132 */
311
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 }
eeb5d3a5e194 JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)