Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / test / java / org / gvsig / tools / packageutils / PackageManagerTest_peta.java @ 716

History | View | Annotate | Download (3.23 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.tools.packageutils;
29

    
30
import java.io.ByteArrayInputStream;
31
import java.io.ByteArrayOutputStream;
32
import java.io.IOException;
33
import java.io.InputStream;
34

    
35
import junit.framework.TestCase;
36

    
37
import org.gvsig.tools.packageutils.impl.DefaultPackageInfo;
38
import org.gvsig.tools.packageutils.impl.DefaultPackageManager;
39

    
40
/**
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
42
 */
43
public class PackageManagerTest_peta extends TestCase {
44

    
45
        PackageManager manager = null;
46

    
47
        private PackageManager getManager() {
48
                if (this.manager == null) {
49
                        this.manager = new DefaultPackageManager();
50
                }
51
                return this.manager;
52
        }
53

    
54
        protected void doSetUp() throws Exception {
55
                // Do nothing
56

    
57
        }
58

    
59
        public void testReadPackage() throws IOException {
60
                InputStream fis = getClass().getResourceAsStream("package1.info");
61

    
62
                PackageInfo packageInfo = new DefaultPackageInfo();
63

    
64
                getManager().readPacakgeInfo(packageInfo, fis);
65
//                System.out.println(packageInfo.toString());
66

    
67
                assertEquals(packageInfo.getCode(), "org.gvsig.myplugin");
68
                assertEquals(packageInfo.getName(), "myplugin");
69
                assertEquals(packageInfo.getDescription(), "Test");
70
                assertEquals(packageInfo.getVersion().toString(), "1.0.0-0");
71
                assertEquals(packageInfo.getState(), "RC1");
72
                assertEquals(packageInfo.isOfficial(), true);
73
        }
74

    
75
        public void testWritePackage() throws IOException {
76
                PackageInfo packageInfo1 = new DefaultPackageInfo();
77
                PackageInfo packageInfo2 = new DefaultPackageInfo();
78

    
79
                packageInfo1.setCode("org.gvsig.myplugin");
80
                packageInfo1.setName("My name");
81
                packageInfo1.setDescription("My description");
82
                packageInfo1.getVersion().parse("1.0.0");
83
                packageInfo1.setState("final");
84
                packageInfo1.setOfficial(false);
85
                packageInfo1.setType("plugin");
86

    
87
                ByteArrayOutputStream out = new ByteArrayOutputStream();
88

    
89
                getManager().writePacakgeInfo(packageInfo1, out);
90
                getManager().readPacakgeInfo(packageInfo2, new ByteArrayInputStream(out.toByteArray()));
91

    
92
                assertEquals("org.gvsig.myplugin", packageInfo2.getCode());
93
                assertEquals("My name", packageInfo2.getName());
94
                assertEquals("My description", packageInfo2.getDescription());
95
                assertEquals("1.0.0-0", packageInfo2.getVersion().toString());
96
                assertEquals("final", packageInfo2.getState());
97
                assertEquals(false, packageInfo2.isOfficial());
98
        }
99

    
100
}