Mercurial > lada > lada-server
annotate src/test/java/de/intevation/lada/importer/TestLAFImporter.java @ 315:79cbc672d8e4
Updates systemproperty keys and testcases.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 21 Aug 2013 08:58:28 +0200 |
parents | eeb5d3a5e194 |
children | fab1e6c74044 |
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 @Ignore |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 public void loadLafFiles() { |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
36 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
|
37 String incomplete = |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
38 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
|
39 try { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 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
|
41 byte[] encodedIncomplete = |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 Files.readAllBytes(Paths.get(incomplete)); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 Charset encoding = Charset.defaultCharset(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 singleProbe = |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 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
|
46 incompleteProbe = |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 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
|
48 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 catch (IOException ioe) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 singleProbe = ""; |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 incompleteProbe = ""; |
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 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
55 @Test |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 public void testConfigFileNotFound() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 LAFFormat format = new LAFFormat(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 boolean success = format.readConfigFile("/file/not/found"); |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
59 assertEquals(false, success); |
311
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 |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 @Test |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 public void testConfigFileLoading() { |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
64 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
|
65 LAFFormat format = new LAFFormat(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 boolean success = format.readConfigFile(fileName); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 assertEquals(true, success); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 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
|
69 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
|
70 assertEquals( |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 "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
|
72 32, |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 probeFormat.size()); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
74 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
|
75 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
|
76 assertEquals( |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 "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
|
78 10, |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 messungFormat.size()); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 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
|
81 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
|
82 assertEquals( |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 "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
|
84 20, |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 ortFormat.size()); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
88 @Test |
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); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 try { |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
93 boolean success = parser.parse(PROBE_HEADER_FAIL); |
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
94 assertEquals(false, success); |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 assertEquals( |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 "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
|
99 "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
|
100 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 @Test |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 @Ignore |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
105 public void testIncompleteProbe() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 LAFParser parser = new LAFParser(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 parser.setDryRun(true); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 try { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 parser.parse(incompleteProbe); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
111 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
112 e.printStackTrace(); |
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 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 @Test |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 public void testCompleteParser() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 LAFParser parser = new LAFParser(); |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
119 parser.setDryRun(true); |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 try { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 parser.parse(singleProbe); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 e.printStackTrace(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 } |