Statistics
| Revision:

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 / SimpleTest.java

History | View | Annotate | Download (3.43 KB)

1 802 cordinyana
/**
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 73 jjdelcerro
package org.gvsig.tools.persistence.case1;
25
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dynobject.DynStruct;
28
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
29
import org.gvsig.tools.persistence.PersistenceManager;
30
import org.gvsig.tools.persistence.PersistentState;
31
import org.gvsig.tools.persistence.case1.model.ModelManager;
32
import org.gvsig.tools.persistence.case1.model.ProjectExtent;
33
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
35
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException;
36
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
37
38
public class SimpleTest extends AbstractLibraryAutoInitTestCase {
39
40
        PersistenceManager manager;
41
        ModelManager modelmgr;
42
43
        protected void doSetUp() throws Exception {
44
                this.manager = ToolsLocator.getPersistenceManager();
45
                manager.setAutoValidation(PersistenceManager.MANDATORY);
46
                modelmgr = new ModelManager();
47
                modelmgr.registerPersistence();
48
        }
49
50
        protected void tearDown() throws Exception {
51
                super.tearDown();
52
                modelmgr.unregisterPersistence();
53
        }
54
55
        public void testRegister() {
56
57
                DynStruct definition = manager.getDefinition(ProjectExtent.class);
58
                assertNotNull("Can't register class", definition);
59
                assertEquals(
60
                                "Registration don't work, name incorrect",
61
                                "ProjectExtent",
62
                                definition.getName()
63
                );
64
        }
65
66
        public void testGetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions {
67
                ProjectExtent obj = new ProjectExtent();
68
                PersistentState state = manager.getState(obj);
69
                assertNotNull("Can't retrieve state", state);
70
                DynStruct definition = state.getDefinition();
71
                assertNotNull("Can't register class", definition);
72
                assertEquals(
73
                                "Registration don't work, name incorrect",
74
                                "ProjectExtent",
75
                                definition.getName()
76
                );
77
        }
78
79
        public void testSetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions {
80
                ProjectExtent obj1 = new ProjectExtent();
81
                PersistentState state = manager.getState(obj1);
82
                assertNotNull("Can't retrieve state", state);
83
84
                ProjectExtent obj2 = (ProjectExtent) manager.create(state);
85
                assertEquals("Restore of object state failed, code mismatch", obj1.getCode(), obj2.getCode());
86
                assertEquals("Restore of object state failed, description mismatch", obj1.description, obj2.description);
87
        }
88
89
90
}