svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.xml2db / org.gvsig.xml2db.lib / org.gvsig.xml2db.lib.impl / src / test / java / org / gvsig / xml2db / lib / impl / TestCopyXml2db.java @ 47472
History | View | Annotate | Download (5.33 KB)
1 |
package org.gvsig.xml2db.lib.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.InputStream; |
5 |
import java.util.Locale; |
6 |
import org.apache.commons.io.FilenameUtils; |
7 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
8 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
9 |
import org.gvsig.xml2db.lib.api.Xml2dbManager; |
10 |
import org.gvsig.xml2db.lib.api.xmlinfo.XMLInfo; |
11 |
import org.slf4j.Logger; |
12 |
import org.slf4j.LoggerFactory; |
13 |
|
14 |
|
15 |
@SuppressWarnings("UseSpecificCatch") |
16 |
public class TestCopyXml2db extends AbstractLibraryAutoInitTestCase { |
17 |
|
18 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCopyXml2db.class); |
19 |
|
20 |
private TestUtilsXml2db utils;
|
21 |
|
22 |
public TestCopyXml2db(String testName) { |
23 |
super(testName);
|
24 |
} |
25 |
|
26 |
@Override
|
27 |
protected void doSetUp() throws Exception { |
28 |
|
29 |
} |
30 |
|
31 |
public TestUtilsXml2db utils() {
|
32 |
if( this.utils == null ) { |
33 |
this.utils = new TestUtilsXml2db(); |
34 |
} |
35 |
return this.utils; |
36 |
} |
37 |
|
38 |
public void testCopyDeclaracion() throws Exception { |
39 |
try {
|
40 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
41 |
|
42 |
InputStream xml = this.getClass().getResourceAsStream("Declaracion4.xml"); |
43 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), null, null); |
44 |
|
45 |
File dbfile = utils().getFile(new File("databases/declaracion4")); |
46 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(dbfile, xmlinfo, null);
|
47 |
|
48 |
xml = this.getClass().getResourceAsStream("Declaracion4.xml"); |
49 |
manager.copyXml2Db(xml, null, dbparams, null, null); |
50 |
} catch (Throwable t) { |
51 |
t.printStackTrace(); |
52 |
throw t;
|
53 |
} |
54 |
} |
55 |
|
56 |
public void testCopyR10graf() throws Exception { |
57 |
testCopyR10graf(null);
|
58 |
} |
59 |
|
60 |
public void testCopyR10grafWithTablesPrefix(String tablesPrefix) throws Exception { |
61 |
testCopyR10graf("R10G_");
|
62 |
} |
63 |
|
64 |
public void testCopyR10graf(String tablesPrefix) throws Exception { |
65 |
// String xmlfname = "BDA_R10_graf18_1728062018_004.xml";
|
66 |
// String xmlfname = "BDA_R10_graf18_1728062018_002.xml";
|
67 |
String xmlfname = "r10graf.xml"; |
68 |
try {
|
69 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
70 |
InputStream xml = this.getClass().getResourceAsStream(xmlfname); |
71 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), tablesPrefix, null); |
72 |
|
73 |
File dbfile = utils().getFile(new File("databases/"+FilenameUtils.removeExtension(xmlfname))); |
74 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(dbfile, xmlinfo, null);
|
75 |
|
76 |
xml = this.getClass().getResourceAsStream(xmlfname);
|
77 |
manager.copyXml2Db(xml, null, dbparams, tablesPrefix, null); |
78 |
} catch(Throwable t) { |
79 |
LOGGER.warn("Test testCopyR10graf failed",t);
|
80 |
throw t;
|
81 |
} |
82 |
} |
83 |
|
84 |
public void testCopyArena2() throws Exception { |
85 |
// Fallan cosas del estilo de la linea 281 o 282, parece que no reconoce el
|
86 |
// StructureStractor a PRES_INFRAC_VEL_COND como una tabla.
|
87 |
// Hay que repasar tambien que pasa con cosas como la linea 497.
|
88 |
try {
|
89 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
90 |
|
91 |
InputStream xml = this.getClass().getResourceAsStream("victimas.xml"); |
92 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), null, null); |
93 |
|
94 |
File dbfile = utils().getFile(new File("databases/victimas")); |
95 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(dbfile, xmlinfo, null);
|
96 |
|
97 |
xml = this.getClass().getResourceAsStream("victimas.xml"); |
98 |
// manager.copyXml2Db(xml, null, dbparams);
|
99 |
} catch(Throwable t) { |
100 |
LOGGER.warn("Test testCopyArena2 failed",t);
|
101 |
throw t;
|
102 |
} |
103 |
} |
104 |
|
105 |
public void testCopyR10grafAndExpedienteEnric() throws Exception { |
106 |
// String xmlfname = "BDA_R10_graf18_1728062018_004.xml";
|
107 |
// String xmlfname = "BDA_R10_graf18_1728062018_002.xml";
|
108 |
String xmlfname1 = "r10graf.xml"; |
109 |
String xmlfname2 = "export-expedientes.xml"; |
110 |
try {
|
111 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
112 |
File dbfile = utils().getFile(new File("databases/"+FilenameUtils.removeExtension("r10graf+exp"))); |
113 |
|
114 |
|
115 |
InputStream xml1 = this.getClass().getResourceAsStream(xmlfname1); |
116 |
XMLInfo xmlinfo1 = manager.extractStructure(xml1, null, null, Locale.getDefault(), "R10G_", null); |
117 |
|
118 |
JDBCServerExplorerParameters dbparams1 = manager.createDatabase(dbfile, xmlinfo1, null);
|
119 |
|
120 |
xml1 = this.getClass().getResourceAsStream(xmlfname1);
|
121 |
manager.copyXml2Db(xml1, null, dbparams1, "R10G_", null); |
122 |
|
123 |
|
124 |
InputStream xml2 = this.getClass().getResourceAsStream(xmlfname2); |
125 |
XMLInfo xmlinfo2 = manager.extractStructure(xml2, null, null, Locale.getDefault(), "EXP_", null); |
126 |
|
127 |
JDBCServerExplorerParameters dbparams2 = manager.createDatabase(dbfile, xmlinfo2, null);
|
128 |
|
129 |
xml2 = this.getClass().getResourceAsStream(xmlfname2);
|
130 |
manager.copyXml2Db(xml2, null, dbparams2, "EXP_", null); |
131 |
|
132 |
} catch(Throwable t) { |
133 |
LOGGER.warn("Test testCopyR10graf failed",t);
|
134 |
throw t;
|
135 |
} |
136 |
} |
137 |
|
138 |
} |