svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / test / java / org / gvsig / fmap / dal / explorer / filesystem / FileSystemExplorerTest.java @ 43020
History | View | Annotate | Download (5.18 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | |||
25 | package org.gvsig.fmap.dal.explorer.filesystem; |
||
26 | |||
27 | import java.io.File; |
||
28 | import java.util.Iterator; |
||
29 | import java.util.List; |
||
30 | |||
31 | import org.gvsig.fmap.dal.DALLocator; |
||
32 | import org.gvsig.fmap.dal.DataManager; |
||
33 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
34 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
35 | import org.gvsig.fmap.dal.DataTypes; |
||
36 | import org.gvsig.fmap.dal.NewDataStoreParameters; |
||
37 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
38 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
39 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
40 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
41 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
||
42 | import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
||
43 | import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
||
44 | import org.gvsig.fmap.dal.store.dbf.TestDBF; |
||
45 | import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
||
46 | |||
47 | public class FileSystemExplorerTest extends AbstractLibraryAutoInitTestCase { |
||
48 | |||
49 | private static DataManager dataManager = null; |
||
50 | public static final File dbf_data = new File(TestDBF.class.getResource( |
||
51 | "data/prueba.dbf").getFile()).getParentFile();
|
||
52 | |||
53 | protected void doSetUp() throws Exception { |
||
54 | dataManager = DALLocator.getDataManager(); |
||
55 | } |
||
56 | |||
57 | public void testList() throws Exception { |
||
58 | FilesystemServerExplorerParameters exParam = (FilesystemServerExplorerParameters) dataManager |
||
59 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
60 | |||
61 | exParam.setRoot(dbf_data.getPath()); |
||
62 | |||
63 | 43020 | jjdelcerro | DataServerExplorer ex = dataManager.openServerExplorer(exParam.getExplorerName(),exParam); |
64 | 40435 | jjdelcerro | |
65 | List list = ex.list();
|
||
66 | |||
67 | assertEquals(2, list.size());
|
||
68 | |||
69 | if (((FilesystemStoreParameters) list.get(0)).getFile().getPath() |
||
70 | .equals(TestDBF.dbf_prueba.getPath())) { |
||
71 | assertEquals(((FilesystemStoreParameters) list.get(1)).getFile()
|
||
72 | .getPath(), TestDBF.dbf_pruebaNull.getPath()); |
||
73 | |||
74 | } else {
|
||
75 | assertEquals(((FilesystemStoreParameters) list.get(0)).getFile()
|
||
76 | .getPath(), TestDBF.dbf_pruebaNull.getPath()); |
||
77 | assertEquals(((FilesystemStoreParameters) list.get(1)).getFile()
|
||
78 | .getPath(), TestDBF.dbf_prueba.getPath()); |
||
79 | } |
||
80 | |||
81 | Iterator iter = list.iterator();
|
||
82 | TestDBF testDBF = new TestDBF();
|
||
83 | while (iter.hasNext()) {
|
||
84 | testDBF.testSimpleIteration((DBFStoreParameters) iter.next()); |
||
85 | } |
||
86 | |||
87 | |||
88 | |||
89 | } |
||
90 | |||
91 | private boolean deleteDir(File dir) { |
||
92 | File[] files = dir.listFiles(); |
||
93 | for (int i = 0; i < files.length; i++) { |
||
94 | if (files[i].isDirectory()) {
|
||
95 | if (!deleteDir(files[i])) {
|
||
96 | return false; |
||
97 | } |
||
98 | } |
||
99 | if (!files[i].delete()) {
|
||
100 | return false; |
||
101 | } |
||
102 | } |
||
103 | return dir.delete();
|
||
104 | } |
||
105 | |||
106 | public void testAddRemove() throws Exception { |
||
107 | File tmpDir = new File("target/_FilesystemExplorer.tmp"); |
||
108 | |||
109 | if (tmpDir.exists()) {
|
||
110 | if (!deleteDir(tmpDir)) {
|
||
111 | fail("Clean tmp dir:" + tmpDir.getAbsolutePath());
|
||
112 | } |
||
113 | } |
||
114 | |||
115 | tmpDir.mkdir(); |
||
116 | |||
117 | FilesystemServerExplorerParameters exParam = (FilesystemServerExplorerParameters) dataManager |
||
118 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
119 | |||
120 | exParam.setRoot(tmpDir.getAbsolutePath()); |
||
121 | |||
122 | 43020 | jjdelcerro | DataServerExplorer ex = dataManager.openServerExplorer(exParam.getExplorerName(),exParam); |
123 | 40435 | jjdelcerro | |
124 | assertTrue(ex.canAdd()); |
||
125 | |||
126 | assertTrue(ex.canAdd(DBFStoreProvider.NAME)); |
||
127 | |||
128 | assertEquals(0, ex.list().size());
|
||
129 | |||
130 | NewDataStoreParameters newParams = ex |
||
131 | .getAddParameters(DBFStoreProvider.NAME); |
||
132 | |||
133 | ((FilesystemStoreParameters) newParams).setFile(new File(tmpDir, |
||
134 | "tmp1.dbf"));
|
||
135 | EditableFeatureType fType; |
||
136 | if (((NewFeatureStoreParameters) newParams).getDefaultFeatureType() instanceof EditableFeatureType) { |
||
137 | fType = (EditableFeatureType) ((NewFeatureStoreParameters) newParams) |
||
138 | .getDefaultFeatureType(); |
||
139 | } else {
|
||
140 | fType = ((NewFeatureStoreParameters) newParams) |
||
141 | .getDefaultFeatureType().getEditable(); |
||
142 | } |
||
143 | fType.add("campo1", DataTypes.STRING).setSize(10); |
||
144 | ((NewFeatureStoreParameters) newParams).setDefaultFeatureType(fType); |
||
145 | ex.add(DBFStoreProvider.NAME, newParams, false);
|
||
146 | |||
147 | List list = ex.list();
|
||
148 | assertEquals(1, list.size());
|
||
149 | |||
150 | Iterator iter = list.iterator();
|
||
151 | TestDBF testDBF = new TestDBF();
|
||
152 | while (iter.hasNext()) {
|
||
153 | testDBF.testSimpleIteration((DBFStoreParameters) iter.next()); |
||
154 | } |
||
155 | |||
156 | ex.remove((DataStoreParameters) list.get(0));
|
||
157 | |||
158 | assertEquals(0, ex.list().size());
|
||
159 | |||
160 | |||
161 | } |
||
162 | } |