svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / test / java / org / gvsig / installer / lib / impl / creation / InstallerCreationServiceTest.java @ 32415
History | View | Annotate | Download (8.57 KB)
1 | 32292 | jpiera | /* 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.installer.lib.impl.creation; |
||
29 | |||
30 | import java.io.ByteArrayInputStream; |
||
31 | import java.io.ByteArrayOutputStream; |
||
32 | import java.io.File; |
||
33 | import java.io.FileNotFoundException; |
||
34 | 32415 | jpiera | import java.io.IOException; |
35 | 32292 | jpiera | |
36 | import junit.framework.Assert; |
||
37 | |||
38 | import org.gvsig.installer.lib.api.InstallerInfo; |
||
39 | import org.gvsig.installer.lib.api.InstallerLocator; |
||
40 | import org.gvsig.installer.lib.api.creation.InstallerCreationService; |
||
41 | import org.gvsig.installer.lib.api.creation.InstallerCreationServiceException; |
||
42 | import org.gvsig.installer.lib.api.execution.InstallerExecutionService; |
||
43 | import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException; |
||
44 | 32415 | jpiera | import org.gvsig.installer.lib.impl.InstallerServiceTest; |
45 | 32292 | jpiera | import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
46 | 32400 | jpiera | import org.gvsig.tools.library.LibrariesInitializer; |
47 | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
||
48 | 32292 | jpiera | import org.gvsig.tools.locator.LocatorException; |
49 | |||
50 | |||
51 | /**
|
||
52 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
53 | */
|
||
54 | 32415 | jpiera | public class InstallerCreationServiceTest extends InstallerServiceTest{ |
55 | 32292 | jpiera | |
56 | @Override
|
||
57 | protected void doSetUp() throws Exception { |
||
58 | |||
59 | } |
||
60 | |||
61 | 32415 | jpiera | public void testReadPlugins() throws LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException, IOException{ |
62 | File applicationDirectory = super.getApplicationDirectory(); |
||
63 | |||
64 | InstallerCreationService installerCreationService = |
||
65 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
66 | installerCreationService.setApplicationDirectory(applicationDirectory); |
||
67 | |||
68 | Assert.assertEquals(3, installerCreationService.getPluginsSize());
|
||
69 | |||
70 | for (int i=0 ; i<3 ; i++){ |
||
71 | InstallerInfo installerInfo = installerCreationService.getPluginInfoAt(i); |
||
72 | if (installerInfo.getCode().equals("org.gvsig.wms")){ |
||
73 | assertNotNull(installerInfo.getState()); |
||
74 | }else if (installerInfo.getCode().equals("org.gvsig.wfs")){ |
||
75 | assertEquals("RC2", installerInfo.getState());
|
||
76 | }else if (installerInfo.getCode().equals("org.gvsig.wcs")){ |
||
77 | assertEquals("RC1", installerInfo.getState());
|
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | 32292 | jpiera | |
82 | 32415 | jpiera | public void testCreateInstallerWithOutSelectAPluginException() throws IOException, LocatorException, InstallerCreationServiceException{ |
83 | File applicationDirectory = super.getApplicationDirectory(); |
||
84 | 32292 | jpiera | |
85 | InstallerCreationService installerCreationService = |
||
86 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
87 | 32415 | jpiera | installerCreationService.setApplicationDirectory(applicationDirectory); |
88 | 32292 | jpiera | |
89 | 32415 | jpiera | Exception exc = null; |
90 | |||
91 | try{
|
||
92 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
93 | installerCreationService.createInstaller(os); |
||
94 | }catch (Exception e) { |
||
95 | exc = e; |
||
96 | } |
||
97 | assertNotNull(exc); |
||
98 | } |
||
99 | |||
100 | public void testSelectPlugin() throws IOException, LocatorException, InstallerCreationServiceException { |
||
101 | File applicationDirectory = super.getApplicationDirectory(); |
||
102 | |||
103 | InstallerCreationService installerCreationService = |
||
104 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
105 | installerCreationService.setApplicationDirectory(applicationDirectory); |
||
106 | |||
107 | installerCreationService.setSelectedPlugin("org.gvsig.wfs");
|
||
108 | InstallerInfo installerInfo = installerCreationService.getSelectedPlugin(); |
||
109 | assertNotNull(installerInfo); |
||
110 | assertEquals("org.gvsig.wfs", installerInfo.getCode());
|
||
111 | } |
||
112 | |||
113 | public void testCreateInstaller() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{ |
||
114 | File applicationDirectory = super.getApplicationDirectory(); |
||
115 | |||
116 | InstallerCreationService installerCreationService = |
||
117 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
118 | installerCreationService.setApplicationDirectory(applicationDirectory); |
||
119 | installerCreationService.setSelectedPlugin("org.gvsig.wfs");
|
||
120 | InstallerInfo installerInfo = installerCreationService.getSelectedPlugin(); |
||
121 | |||
122 | assertEquals("1.0.0", installerInfo.getVersion());
|
||
123 | |||
124 | //Change the version to check that the installation process works fine
|
||
125 | installerInfo.setVersion("1.0.1");
|
||
126 | |||
127 | //Compress the plugin and create the installer compressed file
|
||
128 | 32292 | jpiera | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
129 | installerCreationService.createInstaller(os); |
||
130 | 32415 | jpiera | |
131 | //decompress the plugin and read the plugin information
|
||
132 | 32292 | jpiera | ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
133 | InstallerExecutionService installerExecutionService = |
||
134 | InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
||
135 | 32400 | jpiera | installerExecutionService.addInstaller(is); |
136 | 32415 | jpiera | assertEquals(1, installerExecutionService.getPluginsSize());
|
137 | installerCreationService.setSelectedPlugin(0);
|
||
138 | InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
|
||
139 | assertEquals("1.0.1", newInstallerInfo.getVersion());
|
||
140 | } |
||
141 | |||
142 | public void testCreateInstallerWithAntFile() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{ |
||
143 | File applicationDirectory = super.getApplicationDirectory(); |
||
144 | 32292 | jpiera | |
145 | 32415 | jpiera | InstallerCreationService installerCreationService = |
146 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
147 | installerCreationService.setApplicationDirectory(applicationDirectory); |
||
148 | installerCreationService.setSelectedPlugin("org.gvsig.wfs");
|
||
149 | 32292 | jpiera | |
150 | 32415 | jpiera | InstallerInfo installerInfo = installerCreationService.getSelectedPlugin(); |
151 | installerInfo.setAnScript(installerCreationService.getDefaultAntScript()); |
||
152 | |||
153 | //Compress the plugin and create the installer compressed file
|
||
154 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
155 | installerCreationService.createInstaller(os); |
||
156 | |||
157 | //decompress the plugin and read the plugin information
|
||
158 | ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
||
159 | InstallerExecutionService installerExecutionService = |
||
160 | InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
||
161 | installerExecutionService.addInstaller(is); |
||
162 | assertEquals(1, installerExecutionService.getPluginsSize());
|
||
163 | installerCreationService.setSelectedPlugin(0);
|
||
164 | InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
|
||
165 | assertTrue(newInstallerInfo.getAntScript().startsWith("<project"));
|
||
166 | } |
||
167 | 32292 | jpiera | |
168 | 32415 | jpiera | public void testCreateInstallerWithFiles() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{ |
169 | File resource = new File (File.separator + "gvSIG" + File.separator + "extensiones" + File.separator + "org.gvsig.wms" + File.separator + "resources.txt"); |
||
170 | File applicationDirectory = super.getApplicationDirectory(); |
||
171 | 32292 | jpiera | |
172 | InstallerCreationService installerCreationService = |
||
173 | InstallerLocator.getInstallerManager().getInstallerCreationService(); |
||
174 | 32415 | jpiera | installerCreationService.setApplicationDirectory(applicationDirectory); |
175 | installerCreationService.setSelectedPlugin("org.gvsig.wfs");
|
||
176 | 32292 | jpiera | |
177 | 32415 | jpiera | InstallerInfo installerInfo = installerCreationService.getSelectedPlugin(); |
178 | installerInfo.addFileToCopy(resource); |
||
179 | 32292 | jpiera | |
180 | 32415 | jpiera | //Compress the plugin and create the installer compressed file
|
181 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
182 | installerCreationService.createInstaller(os); |
||
183 | |||
184 | //decompress the plugin and read the plugin information
|
||
185 | ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
||
186 | InstallerExecutionService installerExecutionService = |
||
187 | InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
||
188 | installerExecutionService.addInstaller(is); |
||
189 | assertEquals(1, installerExecutionService.getPluginsSize());
|
||
190 | installerCreationService.setSelectedPlugin(0);
|
||
191 | InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
|
||
192 | assertEquals(1, newInstallerInfo.getFileToCopySize());
|
||
193 | assertEquals(resource.getAbsolutePath(), newInstallerInfo.getFileToCopyAt(0).getAbsolutePath());
|
||
194 | } |
||
195 | 32292 | jpiera | } |