Mercurial > lada > lada-server
annotate src/test/java/de/intevation/lada/importer/TestLAFImporter.java @ 318:fab1e6c74044
Commented out the main in Importertest and removed some annotations.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 23 Aug 2013 11:29:08 +0200 |
parents | 79cbc672d8e4 |
children | 17904ad125f3 |
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 |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 public void testProbeHeaderFail() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 LAFParser parser = new LAFParser(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 parser.setDryRun(true); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 try { |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
92 boolean success = parser.parse(PROBE_HEADER_FAIL); |
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
93 assertEquals(false, success); |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 assertEquals( |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 "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
|
98 "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
|
99 } |
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 @Test |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 @Ignore |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 public void testIncompleteProbe() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
105 LAFParser parser = new LAFParser(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 parser.setDryRun(true); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 try { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 parser.parse(incompleteProbe); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
111 e.printStackTrace(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
112 } |
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 @Test |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 public void testCompleteParser() { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 LAFParser parser = new LAFParser(); |
315
79cbc672d8e4
Updates systemproperty keys and testcases.
Raimund Renkert <rrenkert@intevation.de>
parents:
311
diff
changeset
|
118 parser.setDryRun(true); |
311
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 try { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 parser.parse(singleProbe); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 } |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 catch (LAFParserException e) { |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 e.printStackTrace(); |
eeb5d3a5e194
JUnit test cases and small test application for LAF importer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 } |
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 } |