Statistics
| Revision:

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 @ 32420

History | View | Annotate | Download (8.7 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.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
import java.io.IOException;
35

    
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
import org.gvsig.installer.lib.impl.InstallerServiceTest;
45
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
46
import org.gvsig.tools.library.LibrariesInitializer;
47
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
48
import org.gvsig.tools.locator.LocatorException;
49

    
50

    
51
/**
52
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
53
 */
54
public class InstallerCreationServiceTest extends InstallerServiceTest{
55
        
56
        @Override
57
        protected void doSetUp() throws Exception {
58
                
59
        }        
60

    
61
        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
                int pluginsNumber = 0;
71
                for (int i=0 ; i<3 ; i++){
72
                        InstallerInfo installerInfo = installerCreationService.getPluginInfoAt(i);
73
                        if (installerInfo.getCode().equals("org.gvsig.wms")){
74
                                assertNotNull(installerInfo.getState());
75
                                pluginsNumber++;
76
                        }else if (installerInfo.getCode().equals("org.gvsig.wfs")){
77
                                assertEquals("RC2", installerInfo.getState());
78
                                pluginsNumber++;
79
                        }else if (installerInfo.getCode().equals("org.gvsig.wcs")){
80
                                assertEquals("RC1", installerInfo.getState());
81
                                pluginsNumber++;
82
                        }
83
                }
84
                
85
                Assert.assertEquals(3, pluginsNumber);
86
        }
87
        
88
        public void testCreateInstallerWithOutSelectAPluginException() throws IOException, LocatorException, InstallerCreationServiceException{
89
                File applicationDirectory = super.getApplicationDirectory();                
90
                
91
                InstallerCreationService installerCreationService = 
92
                        InstallerLocator.getInstallerManager().getInstallerCreationService();
93
                installerCreationService.setApplicationDirectory(applicationDirectory);
94
                
95
                Exception exc = null;
96
                
97
                try{
98
                        ByteArrayOutputStream os = new ByteArrayOutputStream();                
99
                        installerCreationService.createInstaller(os);
100
                }catch (Exception e) {
101
                        exc = e;
102
                }
103
                assertNotNull(exc);                
104
        }
105
        
106
        public void testSelectPlugin() throws IOException, LocatorException, InstallerCreationServiceException {
107
                File applicationDirectory = super.getApplicationDirectory();                
108
                
109
                InstallerCreationService installerCreationService = 
110
                        InstallerLocator.getInstallerManager().getInstallerCreationService();
111
                installerCreationService.setApplicationDirectory(applicationDirectory);
112
                
113
                installerCreationService.setSelectedPlugin("org.gvsig.wfs");
114
                InstallerInfo installerInfo = installerCreationService.getSelectedPlugin();
115
                assertNotNull(installerInfo);
116
                assertEquals("org.gvsig.wfs", installerInfo.getCode());
117
        }
118

    
119
        public void testCreateInstaller() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{
120
                File applicationDirectory = super.getApplicationDirectory();                
121
                
122
                InstallerCreationService installerCreationService = 
123
                        InstallerLocator.getInstallerManager().getInstallerCreationService();
124
                installerCreationService.setApplicationDirectory(applicationDirectory);
125
                installerCreationService.setSelectedPlugin("org.gvsig.wfs");
126
                InstallerInfo installerInfo = installerCreationService.getSelectedPlugin();
127
                
128
                assertEquals("1.0.0", installerInfo.getVersion());
129
                
130
                //Change the version to check that the installation process works fine
131
                installerInfo.setVersion("1.0.1");
132

    
133
                //Compress the plugin and create the installer compressed file
134
                ByteArrayOutputStream os = new ByteArrayOutputStream();                
135
                installerCreationService.createInstaller(os);
136
                
137
                //decompress the plugin and read the plugin information
138
                ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
139
                InstallerExecutionService installerExecutionService = 
140
                        InstallerLocator.getInstallerManager().getInstallerExecutionService();
141
                installerExecutionService.addInstaller(is);
142
                assertEquals(1, installerExecutionService.getPluginsSize());
143
                installerCreationService.setSelectedPlugin(0);
144
                InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
145
                assertEquals("1.0.1", newInstallerInfo.getVersion());
146
        }        
147
        
148
        public void testCreateInstallerWithAntFile() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{
149
                File applicationDirectory = super.getApplicationDirectory();                
150
                
151
                InstallerCreationService installerCreationService = 
152
                        InstallerLocator.getInstallerManager().getInstallerCreationService();
153
                installerCreationService.setApplicationDirectory(applicationDirectory);
154
                installerCreationService.setSelectedPlugin("org.gvsig.wfs");
155
                
156
                InstallerInfo installerInfo = installerCreationService.getSelectedPlugin();
157
                installerInfo.setAnScript(installerCreationService.getDefaultAntScript());        
158
                
159
                //Compress the plugin and create the installer compressed file
160
                ByteArrayOutputStream os = new ByteArrayOutputStream();                
161
                installerCreationService.createInstaller(os);
162
                
163
                //decompress the plugin and read the plugin information
164
                ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
165
                InstallerExecutionService installerExecutionService = 
166
                        InstallerLocator.getInstallerManager().getInstallerExecutionService();
167
                installerExecutionService.addInstaller(is);
168
                assertEquals(1, installerExecutionService.getPluginsSize());
169
                installerCreationService.setSelectedPlugin(0);
170
                InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
171
                assertTrue(newInstallerInfo.getAntScript().startsWith("<project"));                
172
        }        
173
        
174
        public void testCreateInstallerWithFiles() throws IOException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{
175
                File resource = new File (File.separator + "gvSIG" + File.separator + "extensiones" + File.separator + "org.gvsig.wms" + File.separator + "resources.txt");
176
                File applicationDirectory = super.getApplicationDirectory();                
177
                
178
                InstallerCreationService installerCreationService = 
179
                        InstallerLocator.getInstallerManager().getInstallerCreationService();
180
                installerCreationService.setApplicationDirectory(applicationDirectory);
181
                installerCreationService.setSelectedPlugin("org.gvsig.wfs");
182
                
183
                InstallerInfo installerInfo = installerCreationService.getSelectedPlugin();
184
                installerInfo.addFileToCopy(resource);
185
                
186
                //Compress the plugin and create the installer compressed file
187
                ByteArrayOutputStream os = new ByteArrayOutputStream();                
188
                installerCreationService.createInstaller(os);
189
                
190
                //decompress the plugin and read the plugin information
191
                ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
192
                InstallerExecutionService installerExecutionService = 
193
                        InstallerLocator.getInstallerManager().getInstallerExecutionService();
194
                installerExecutionService.addInstaller(is);
195
                assertEquals(1, installerExecutionService.getPluginsSize());
196
                installerCreationService.setSelectedPlugin(0);
197
                InstallerInfo newInstallerInfo = installerCreationService.getPluginInfoAt(0);
198
                assertEquals(1, newInstallerInfo.getFileToCopySize());
199
                assertEquals(resource.getAbsolutePath(), newInstallerInfo.getFileToCopyAt(0).getAbsolutePath());
200
        }                
201
}
202