Revision 259 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/case1/ComplexTest.java
ComplexTest.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import org.gvsig.tools.ToolsLocator; |
10 | 10 |
import org.gvsig.tools.dynobject.DynStruct; |
11 |
import org.gvsig.tools.exception.BaseException; |
|
11 | 12 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
12 | 13 |
import org.gvsig.tools.persistence.PersistenceManager; |
13 | 14 |
import org.gvsig.tools.persistence.PersistentState; |
... | ... | |
18 | 19 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
19 | 20 |
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException; |
20 | 21 |
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions; |
22 |
import org.slf4j.Logger; |
|
23 |
import org.slf4j.LoggerFactory; |
|
21 | 24 |
|
22 | 25 |
public class ComplexTest extends AbstractLibraryAutoInitTestCase { |
23 | 26 |
|
27 |
private static Logger LOG = LoggerFactory.getLogger(ComplexTest.class); |
|
28 |
|
|
24 | 29 |
PersistenceManager manager; |
25 | 30 |
ModelManager modelmgr; |
26 |
|
|
31 |
|
|
27 | 32 |
protected void doSetUp() throws Exception { |
28 | 33 |
this.manager = ToolsLocator.getPersistenceManager(); |
29 | 34 |
manager.setAutoValidation(PersistenceManager.MANDATORY); |
... | ... | |
35 | 40 |
super.tearDown(); |
36 | 41 |
modelmgr.unregisterPersistence(); |
37 | 42 |
} |
38 |
|
|
43 |
|
|
39 | 44 |
public void compareMapContext(MapContext obj1, MapContext obj2) { |
40 |
assertEquals("MapContext aren't equals, code mismatch", obj1.getCode(), obj2.getCode()); |
|
41 |
assertEquals("MapContext aren't equals, projection mismatch", obj1.getProjection().getFullCode(), obj2.getProjection().getFullCode()); |
|
42 |
assertEquals("MapContext aren't equals, viewport mismatch", obj1.getViewPort().getCode(), obj2.getViewPort().getCode()); |
|
45 |
assertEquals("MapContext aren't equals, code mismatch", obj1.getCode(), |
|
46 |
obj2.getCode()); |
|
47 |
assertEquals("MapContext aren't equals, projection mismatch", obj1 |
|
48 |
.getProjection().getFullCode(), obj2.getProjection() |
|
49 |
.getFullCode()); |
|
50 |
assertEquals("MapContext aren't equals, viewport mismatch", obj1 |
|
51 |
.getViewPort().getCode(), obj2.getViewPort().getCode()); |
|
43 | 52 |
} |
44 |
|
|
53 |
|
|
45 | 54 |
public void testRegister() { |
46 | 55 |
DynStruct definition = manager.getDefinition(MapContext.class); |
47 | 56 |
assertNotNull("Can't register class", definition); |
48 |
assertEquals( |
|
49 |
"Registration don't work, name incorrect", |
|
50 |
"MapContext", |
|
51 |
definition.getName() |
|
52 |
); |
|
57 |
assertEquals("Registration don't work, name incorrect", "MapContext", |
|
58 |
definition.getName()); |
|
53 | 59 |
} |
54 |
|
|
55 |
public void testGetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
|
56 |
MapContext obj = new MapContext( new Projection() ); |
|
57 |
PersistentState state = manager.getState(obj); |
|
58 |
assertNotNull("Can't retrieve state", state); |
|
59 |
assertNotNull("Can't retrieve layers", state.get("layers")); |
|
60 |
assertNotNull("Can't retrieve viewPort", state.get("viewPort")); |
|
60 |
|
|
61 |
public void testGetState() throws PersistenceTypeNotSupportedException, |
|
62 |
PersistenceClassNotRegistered, PersistenceException, |
|
63 |
PersistenceValidateExceptions { |
|
64 |
try { |
|
65 |
MapContext obj = new MapContext(new Projection()); |
|
66 |
PersistentState state = manager.getState(obj); |
|
67 |
assertNotNull("Can't retrieve state", state); |
|
68 |
assertNotNull("Can't retrieve layers", state.get("layers")); |
|
69 |
assertNotNull("Can't retrieve viewPort", state.get("viewPort")); |
|
70 |
} catch (BaseException ex) { |
|
71 |
LOG.error(ex.getMessageStack()); |
|
72 |
} catch (Exception ex) { |
|
73 |
LOG.error(ex.getMessage()); |
|
74 |
} |
|
75 |
|
|
61 | 76 |
} |
62 | 77 |
|
63 |
public void testSetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
|
64 |
MapContext obj1 = new MapContext( new Projection() ); |
|
78 |
public void testSetState() throws PersistenceTypeNotSupportedException, |
|
79 |
PersistenceClassNotRegistered, PersistenceException, |
|
80 |
PersistenceValidateExceptions { |
|
81 |
MapContext obj1 = new MapContext(new Projection()); |
|
65 | 82 |
PersistentState state = manager.getState(obj1); |
66 | 83 |
assertNotNull("Can't retrieve state", state); |
67 |
|
|
84 |
|
|
68 | 85 |
MapContext obj2 = (MapContext) manager.create(state); |
69 | 86 |
this.compareMapContext(obj1, obj2); |
70 | 87 |
} |
71 | 88 |
|
72 | 89 |
public void testSaveState() throws Exception { |
73 |
MapContext obj = new MapContext( new Projection() );
|
|
90 |
MapContext obj = new MapContext(new Projection());
|
|
74 | 91 |
PersistentState state = manager.getState(obj); |
75 | 92 |
|
76 | 93 |
File f = File.createTempFile("gvsig-test-pers-complex", "A.zip"); |
... | ... | |
81 | 98 |
} |
82 | 99 |
|
83 | 100 |
public void testLoadState() throws Exception { |
84 |
MapContext obj1 = new MapContext( new Projection() );
|
|
101 |
MapContext obj1 = new MapContext(new Projection());
|
|
85 | 102 |
PersistentState state1 = manager.getState(obj1); |
86 | 103 |
|
87 | 104 |
File f = File.createTempFile("gvsig-test-pers-complex", "B.zip"); |
88 | 105 |
OutputStream out = new FileOutputStream(f); |
89 | 106 |
manager.saveState(state1, out); |
90 | 107 |
out.close(); |
91 |
|
|
108 |
|
|
92 | 109 |
InputStream in = new FileInputStream(f); |
93 | 110 |
PersistentState state2 = manager.loadState(in); |
94 | 111 |
MapContext obj2 = (MapContext) manager.create(state2); |
95 |
|
|
96 |
this.compareMapContext(obj1, obj2); |
|
97 | 112 |
|
113 |
this.compareMapContext(obj1, obj2); |
|
114 |
|
|
98 | 115 |
} |
99 | 116 |
|
100 |
|
|
101 | 117 |
} |
Also available in: Unified diff