gvsig-tools / org.gvsig.tools / library / tags / org.gvsig.tools-3.0.13 / org.gvsig.tools.lib / src / test / java / org / gvsig / tools / persistence / case1 / MoreComplexTest.java
History | View | Annotate | Download (5.45 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.tools.persistence.case1; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.FileInputStream; |
28 |
import java.io.FileOutputStream; |
29 |
import java.io.InputStream; |
30 |
import java.io.OutputStream; |
31 |
|
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dynobject.DynStruct; |
34 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
36 |
import org.gvsig.tools.persistence.PersistentState; |
37 |
import org.gvsig.tools.persistence.case1.model.ModelManager; |
38 |
import org.gvsig.tools.persistence.case1.model.Project; |
39 |
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered; |
40 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
41 |
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException; |
42 |
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions; |
43 |
|
44 |
public class MoreComplexTest extends AbstractLibraryAutoInitTestCase { |
45 |
|
46 |
PersistenceManager manager; |
47 |
ModelManager modelmgr; |
48 |
|
49 |
protected void doSetUp() throws Exception { |
50 |
this.manager = ToolsLocator.getPersistenceManager();
|
51 |
manager.setAutoValidation(PersistenceManager.MANDATORY); |
52 |
modelmgr = ModelManager.getManager(); |
53 |
modelmgr.registerPersistence(); |
54 |
} |
55 |
|
56 |
protected void tearDown() throws Exception { |
57 |
super.tearDown();
|
58 |
modelmgr.unregisterPersistence(); |
59 |
} |
60 |
|
61 |
private void compareProject(Project obj1, Project obj2) { |
62 |
// TODO Auto-generated method stub
|
63 |
|
64 |
} |
65 |
|
66 |
public void testRegister() { |
67 |
DynStruct definition = manager.getDefinition(Project.class); |
68 |
assertNotNull("Can't register class", definition);
|
69 |
assertEquals( |
70 |
"Registration don't work, name incorrect",
|
71 |
"Project",
|
72 |
definition.getName() |
73 |
); |
74 |
} |
75 |
|
76 |
public void testGetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
77 |
Project obj = new Project();
|
78 |
PersistentState state = manager.getState(obj); |
79 |
assertNotNull("Can't retrieve state", state);
|
80 |
} |
81 |
|
82 |
public void testSetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
83 |
Project obj1 = new Project();
|
84 |
PersistentState state = manager.getState(obj1); |
85 |
assertNotNull("Can't retrieve state", state);
|
86 |
|
87 |
Project obj2 = (Project) manager.create(state); |
88 |
this.compareProject(obj1, obj2);
|
89 |
} |
90 |
|
91 |
public void testSaveState() throws Exception { |
92 |
Project obj1 = new Project();
|
93 |
PersistentState state = manager.getState(obj1); |
94 |
|
95 |
File f = File.createTempFile("gvsig-test-pers-project", "A.zip"); |
96 |
OutputStream out = new FileOutputStream(f); |
97 |
manager.saveState(state, out); |
98 |
out.close(); |
99 |
|
100 |
} |
101 |
|
102 |
public void testLoadState() throws Exception { |
103 |
Project obj1 = new Project();
|
104 |
PersistentState state1 = manager.getState(obj1); |
105 |
|
106 |
File f = File.createTempFile("gvsig-test-pers-project", "B.zip"); |
107 |
OutputStream out = new FileOutputStream(f); |
108 |
manager.saveState(state1, out); |
109 |
out.close(); |
110 |
|
111 |
InputStream in = new FileInputStream(f); |
112 |
PersistentState state2 = manager.loadState(in); |
113 |
Project obj2 = (Project) manager.create(state2); |
114 |
|
115 |
this.compareProject(obj1, obj2);
|
116 |
|
117 |
} |
118 |
|
119 |
public void testSaveStateWithOneProjectExtent() throws Exception { |
120 |
Project obj1 = new Project();
|
121 |
obj1.addExtent(); |
122 |
PersistentState state = manager.getState(obj1); |
123 |
|
124 |
File f = File.createTempFile("gvsig-test-pers-project", "A.zip"); |
125 |
OutputStream out = new FileOutputStream(f); |
126 |
manager.saveState(state, out); |
127 |
out.close(); |
128 |
|
129 |
} |
130 |
|
131 |
public void testSaveStateWithTwoProjectExtent() throws Exception { |
132 |
Project obj1 = new Project();
|
133 |
obj1.addExtent(); |
134 |
obj1.addExtent(); |
135 |
PersistentState state = manager.getState(obj1); |
136 |
|
137 |
File f = File.createTempFile("gvsig-test-pers-project", "A.zip"); |
138 |
OutputStream out = new FileOutputStream(f); |
139 |
manager.saveState(state, out); |
140 |
out.close(); |
141 |
|
142 |
} |
143 |
|
144 |
public void testSaveStateWithOneDocument() throws Exception { |
145 |
Project obj1 = new Project();
|
146 |
obj1.addExtent(); |
147 |
obj1.addExtent(); |
148 |
obj1.addDocument(); |
149 |
PersistentState state = manager.getState(obj1); |
150 |
|
151 |
File f = File.createTempFile("gvsig-test-pers-project", "A.zip"); |
152 |
OutputStream out = new FileOutputStream(f); |
153 |
manager.saveState(state, out); |
154 |
out.close(); |
155 |
|
156 |
} |
157 |
public void testSaveStateWithTwoDocument() throws Exception { |
158 |
Project obj1 = new Project();
|
159 |
obj1.addExtent(); |
160 |
obj1.addExtent(); |
161 |
obj1.addDocument(); |
162 |
obj1.addDocument(); |
163 |
PersistentState state = manager.getState(obj1); |
164 |
|
165 |
File f = File.createTempFile("gvsig-test-pers-project", "A.zip"); |
166 |
OutputStream out = new FileOutputStream(f); |
167 |
manager.saveState(state, out); |
168 |
out.close(); |
169 |
|
170 |
} |
171 |
|
172 |
} |