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 @ 47607
History | View | Annotate | Download (6.63 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(null, 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 testCopyDeclaracion2() throws Exception { |
57 |
try {
|
58 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
59 |
|
60 |
String xmlfname = "Declaracion4.xml"; |
61 |
InputStream xml = this.getClass().getResourceAsStream(xmlfname); |
62 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), "dec_", null); |
63 |
|
64 |
File dbfile = utils().getFile(new File("databases/declaracion_r10")); |
65 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(null, dbfile, xmlinfo, null); |
66 |
|
67 |
xml = this.getClass().getResourceAsStream(xmlfname);
|
68 |
manager.copyXml2Db(xml, null, dbparams, "dec_", null); |
69 |
|
70 |
//importaci?n de otra estructura sobre esta
|
71 |
xmlfname = "r10graf.xml";
|
72 |
xml = this.getClass().getResourceAsStream(xmlfname);
|
73 |
xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), "r10g_", null); |
74 |
|
75 |
dbparams = manager.addToDatabase(null, dbfile, xmlinfo, null); |
76 |
|
77 |
xml = this.getClass().getResourceAsStream(xmlfname);
|
78 |
manager.copyXml2Db(xml, null, dbparams, "r10g_", null); |
79 |
|
80 |
} catch (Throwable t) { |
81 |
t.printStackTrace(); |
82 |
throw t;
|
83 |
} |
84 |
} |
85 |
|
86 |
public void testCopyR10graf() throws Exception { |
87 |
testCopyR10graf(null);
|
88 |
} |
89 |
|
90 |
public void testCopyR10grafWithTablesPrefix(String tablesPrefix) throws Exception { |
91 |
testCopyR10graf("R10G_");
|
92 |
} |
93 |
|
94 |
public void testCopyR10graf(String tablesPrefix) throws Exception { |
95 |
// String xmlfname = "BDA_R10_graf18_1728062018_004.xml";
|
96 |
// String xmlfname = "BDA_R10_graf18_1728062018_002.xml";
|
97 |
String xmlfname = "r10graf.xml"; |
98 |
try {
|
99 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
100 |
InputStream xml = this.getClass().getResourceAsStream(xmlfname); |
101 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), tablesPrefix, null); |
102 |
|
103 |
File dbfile = utils().getFile(new File("databases/"+FilenameUtils.removeExtension(xmlfname))); |
104 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(null, dbfile, xmlinfo, null); |
105 |
|
106 |
xml = this.getClass().getResourceAsStream(xmlfname);
|
107 |
manager.copyXml2Db(xml, null, dbparams, tablesPrefix, null); |
108 |
} catch(Throwable t) { |
109 |
LOGGER.warn("Test testCopyR10graf failed",t);
|
110 |
throw t;
|
111 |
} |
112 |
} |
113 |
|
114 |
public void testCopyArena2() throws Exception { |
115 |
// Fallan cosas del estilo de la linea 281 o 282, parece que no reconoce el
|
116 |
// StructureStractor a PRES_INFRAC_VEL_COND como una tabla.
|
117 |
// Hay que repasar tambien que pasa con cosas como la linea 497.
|
118 |
try {
|
119 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
120 |
|
121 |
InputStream xml = this.getClass().getResourceAsStream("victimas.xml"); |
122 |
XMLInfo xmlinfo = manager.extractStructure(xml, null, null, Locale.getDefault(), null, null); |
123 |
|
124 |
File dbfile = utils().getFile(new File("databases/victimas")); |
125 |
JDBCServerExplorerParameters dbparams = manager.createDatabase(null, dbfile, xmlinfo, null); |
126 |
|
127 |
xml = this.getClass().getResourceAsStream("victimas.xml"); |
128 |
// manager.copyXml2Db(xml, null, dbparams);
|
129 |
} catch(Throwable t) { |
130 |
LOGGER.warn("Test testCopyArena2 failed",t);
|
131 |
throw t;
|
132 |
} |
133 |
} |
134 |
|
135 |
public void testCopyR10grafAndExpedienteEnric() throws Exception { |
136 |
// String xmlfname = "BDA_R10_graf18_1728062018_004.xml";
|
137 |
// String xmlfname = "BDA_R10_graf18_1728062018_002.xml";
|
138 |
String xmlfname1 = "r10graf.xml"; |
139 |
String xmlfname2 = "export-expedientes.xml"; |
140 |
try {
|
141 |
Xml2dbManager manager = new DefaultXml2dbManager();
|
142 |
File dbfile = utils().getFile(new File("databases/"+FilenameUtils.removeExtension("r10graf+exp"))); |
143 |
|
144 |
|
145 |
InputStream xml1 = this.getClass().getResourceAsStream(xmlfname1); |
146 |
XMLInfo xmlinfo1 = manager.extractStructure(xml1, null, null, Locale.getDefault(), "R10G_", null); |
147 |
|
148 |
JDBCServerExplorerParameters dbparams1 = manager.createDatabase(null, dbfile, xmlinfo1, null); |
149 |
|
150 |
xml1 = this.getClass().getResourceAsStream(xmlfname1);
|
151 |
manager.copyXml2Db(xml1, null, dbparams1, "R10G_", null); |
152 |
|
153 |
|
154 |
InputStream xml2 = this.getClass().getResourceAsStream(xmlfname2); |
155 |
XMLInfo xmlinfo2 = manager.extractStructure(xml2, null, null, Locale.getDefault(), "EXP_", null); |
156 |
|
157 |
JDBCServerExplorerParameters dbparams2 = manager.createDatabase(null, dbfile, xmlinfo2, null); |
158 |
|
159 |
xml2 = this.getClass().getResourceAsStream(xmlfname2);
|
160 |
manager.copyXml2Db(xml2, null, dbparams2, "EXP_", null); |
161 |
|
162 |
} catch(Throwable t) { |
163 |
LOGGER.warn("Test testCopyR10graf failed",t);
|
164 |
throw t;
|
165 |
} |
166 |
} |
167 |
|
168 |
} |