svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / geocoding / persistence / TestPersistenceLiteral.java @ 32479
History | View | Annotate | Download (3.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L main development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.persistence; |
29 |
|
30 |
import org.gvsig.geocoding.GeocodingTags; |
31 |
import org.gvsig.geocoding.address.Address; |
32 |
import org.gvsig.geocoding.address.Literal; |
33 |
import org.gvsig.geocoding.address.impl.DefaultLiteral; |
34 |
import org.gvsig.geocoding.address.impl.DefaultNumberAddress; |
35 |
import org.gvsig.geocoding.impl.DefaultGeocodingLibrary; |
36 |
import org.gvsig.tools.library.Library; |
37 |
import org.gvsig.utils.XMLEntity; |
38 |
import org.gvsig.utils.XMLException; |
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
/**
|
43 |
* Test
|
44 |
*
|
45 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
46 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
|
47 |
*/
|
48 |
|
49 |
public class TestPersistenceLiteral extends |
50 |
org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase { |
51 |
|
52 |
|
53 |
private static final Logger log = LoggerFactory |
54 |
.getLogger(TestPersistenceLiteral.class); |
55 |
|
56 |
/**
|
57 |
* tearDown
|
58 |
*/
|
59 |
public void tearDown() { |
60 |
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* test literal
|
65 |
* @throws XMLException
|
66 |
*/
|
67 |
public void testPersistLiteral() throws XMLException { |
68 |
|
69 |
Literal lit = new DefaultLiteral();
|
70 |
lit.put("key1", "value1"); |
71 |
lit.put("key2", "value2"); |
72 |
lit.put("key3", "value3"); |
73 |
|
74 |
XMLEntity xml = lit.getXMLEntity(); |
75 |
|
76 |
String key1 = xml.getStringProperty("key1"); |
77 |
String key3 = xml.getStringProperty("key3"); |
78 |
assertEquals("value1", key1);
|
79 |
assertEquals("value3", key3);
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* test literal
|
84 |
* @throws XMLException
|
85 |
*/
|
86 |
public void testPersistNumberAddress() throws XMLException { |
87 |
|
88 |
Literal lit = new DefaultLiteral();
|
89 |
lit.put("key1", "value1"); |
90 |
lit.put("key2", "value2"); |
91 |
lit.put("key3", "value3"); |
92 |
|
93 |
Address addr = new DefaultNumberAddress();
|
94 |
addr.setMainLiteral(lit); |
95 |
((DefaultNumberAddress)addr).setNumber(5);
|
96 |
|
97 |
XMLEntity xml = addr.getXMLEntity(); |
98 |
log.debug(xml.toString()); |
99 |
|
100 |
Literal lit2 = new DefaultLiteral();
|
101 |
lit2.setXMLEntity(xml.getChild(0));
|
102 |
String value11 = lit2.get("key1"); |
103 |
assertEquals("value1", value11);
|
104 |
int num = xml.getIntProperty(GeocodingTags.ADDRESSNUMBER);
|
105 |
assertEquals(5, num);
|
106 |
|
107 |
} |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
@Override
|
114 |
protected void doSetUp() throws Exception { |
115 |
|
116 |
Library geocoLib = new DefaultGeocodingLibrary();
|
117 |
geocoLib.initialize(); |
118 |
geocoLib.postInitialize(); |
119 |
|
120 |
|
121 |
} |
122 |
|
123 |
} |