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

History | View | Annotate | Download (2.96 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;
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.junit.AbstractLibraryAutoInitTestCase;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36
37
public abstract class AbstractBasicTest         extends AbstractLibraryAutoInitTestCase {
38
                protected static final Logger logger = LoggerFactory.getLogger(AbstractBasicTest.class);
39
40
                protected PersistenceManager manager;
41
42
                abstract protected String getTestId();
43
44
                protected void saveState(Object obj) throws Exception {
45
                        PersistentState state = manager.getState(obj);
46
47
                        File f = File.createTempFile("gvsig-test-pers-"+getTestId(), "S.zip");
48
                        OutputStream out = new FileOutputStream(f);
49
                        manager.saveState(state, out);
50
                        out.close();
51
                }
52 639 jjdelcerro
53 73 jjdelcerro
                protected PersistentState saveAndRestoreState(Object obj) throws Exception {
54
                        PersistentState state1 = manager.getState(obj);
55
56
                        File f = File.createTempFile("gvsig-test-pers-"+getTestId(), "SR.zip");
57
                        OutputStream out = new FileOutputStream(f);
58
                        manager.saveState(state1, out);
59
                        out.close();
60
61
                        InputStream in = new FileInputStream(f);
62
                        PersistentState state2 = manager.loadState(in);
63
                        return state2;
64
                }
65
66 639 jjdelcerro
                protected void saveObject(Object obj) throws Exception {
67
                        File f = File.createTempFile("gvsig-test-pers-"+getTestId(), "OS.zip");
68
                        OutputStream out = new FileOutputStream(f);
69
                        manager.putObject(out,obj);
70
                        out.close();
71
                }
72
73
                protected Object saveAndRestoreObject(Object obj) throws Exception {
74
                        File f = File.createTempFile("gvsig-test-pers-"+getTestId(), "OSR.zip");
75
                        OutputStream out = new FileOutputStream(f);
76
                        manager.putObject(out,obj);
77
                        out.close();
78
79
                        InputStream in = new FileInputStream(f);
80
                        Object obj2 = manager.getObject(in);
81
                        in.close();
82
                        return obj2;
83
                }
84
85 73 jjdelcerro
                public void doSetUp() throws Exception {
86
                        this.manager = ToolsLocator.getPersistenceManager();
87
                        manager.setAutoValidation(PersistenceManager.MANDATORY);
88
                }
89
90
}