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 / SingleFactoryTest.java
History | View | Annotate | Download (3.18 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 org.gvsig.tools.ToolsLocator; |
27 |
import org.gvsig.tools.dynobject.DynStruct; |
28 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
29 |
import org.gvsig.tools.persistence.PersistenceFactory; |
30 |
import org.gvsig.tools.persistence.PersistenceManager; |
31 |
import org.gvsig.tools.persistence.PersistentState; |
32 |
import org.gvsig.tools.persistence.case1.model.Projection; |
33 |
import org.gvsig.tools.persistence.case1.model.ProjectionFactory; |
34 |
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered; |
35 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
36 |
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException; |
37 |
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions; |
38 |
|
39 |
public class SingleFactoryTest extends AbstractLibraryAutoInitTestCase { |
40 |
|
41 |
PersistenceManager manager; |
42 |
PersistenceFactory factory; |
43 |
|
44 |
protected void doSetUp() throws Exception { |
45 |
this.manager = ToolsLocator.getPersistenceManager();
|
46 |
manager.setAutoValidation(PersistenceManager.MANDATORY); |
47 |
factory = new ProjectionFactory();
|
48 |
manager.registerFactory(factory); |
49 |
|
50 |
} |
51 |
|
52 |
protected void tearDown() throws Exception { |
53 |
super.tearDown();
|
54 |
manager.unregisterFactory(factory); |
55 |
} |
56 |
|
57 |
public void testRegister() { |
58 |
DynStruct definition = manager.getDefinition(Projection.class); |
59 |
assertNotNull("Can't register class", definition);
|
60 |
assertEquals( |
61 |
"Registration don't work, name incorrect",
|
62 |
"Projection",
|
63 |
definition.getName() |
64 |
); |
65 |
} |
66 |
|
67 |
public void testGetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
68 |
Projection obj = new Projection();
|
69 |
PersistentState state = manager.getState(obj); |
70 |
assertNotNull("Can't retrieve state", state);
|
71 |
} |
72 |
|
73 |
public void testSetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions { |
74 |
Projection obj1 = new Projection();
|
75 |
PersistentState state = manager.getState(obj1); |
76 |
assertNotNull("Can't retrieve state", state);
|
77 |
|
78 |
Projection obj2 = (Projection) manager.create(state); |
79 |
assertEquals("Restore of object state failed, fullcode mismatch", obj1.getFullCode(), obj2.getFullCode());
|
80 |
} |
81 |
|
82 |
|
83 |
} |