root / 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 / execution / InstallerExecutionServiceTest.java @ 32450
History | View | Annotate | Download (7.06 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.execution; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileInputStream; |
32 |
import java.io.FileNotFoundException; |
33 |
import java.io.IOException; |
34 |
|
35 |
import junit.framework.Assert; |
36 |
|
37 |
import org.gvsig.installer.lib.api.InstallerInfo; |
38 |
import org.gvsig.installer.lib.api.InstallerLocator; |
39 |
import org.gvsig.installer.lib.api.creation.InstallerCreationService; |
40 |
import org.gvsig.installer.lib.api.creation.InstallerCreationServiceException; |
41 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionService; |
42 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException; |
43 |
import org.gvsig.installer.lib.impl.InstallerServiceTest; |
44 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
45 |
import org.gvsig.tools.locator.LocatorException; |
46 |
|
47 |
/**
|
48 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
49 |
*/
|
50 |
public class InstallerExecutionServiceTest extends InstallerServiceTest{ |
51 |
|
52 |
@Override
|
53 |
protected void doSetUp() throws Exception { |
54 |
// TODO Auto-generated method stub
|
55 |
|
56 |
} |
57 |
|
58 |
public void testReadPlugins() throws LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException, IOException{ |
59 |
File applicationDirectory = super.getApplicationDirectory(); |
60 |
|
61 |
InstallerExecutionService installerExecutionService = |
62 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
63 |
installerExecutionService.setApplicationDirectory(applicationDirectory); |
64 |
installerExecutionService.addInstallersFromInstallDirectory(); |
65 |
|
66 |
Assert.assertEquals(3, installerExecutionService.getPluginsSize());
|
67 |
|
68 |
for (int i=0 ; i<3 ; i++){ |
69 |
InstallerInfo installerInfo = installerExecutionService.getPluginInfoAt(i); |
70 |
if (installerInfo.getCode().equals("org.gvsig.plugin1")){ |
71 |
assertNotNull(installerInfo.getState()); |
72 |
}else if (installerInfo.getCode().equals("org.gvsig.plugin2")){ |
73 |
assertEquals("RC1", installerInfo.getState());
|
74 |
}else if (installerInfo.getCode().equals("org.gvsig.plugin3")){ |
75 |
assertEquals("RC1", installerInfo.getState());
|
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
public void testInstallPluginFromApplication() throws InstallerExecutionServiceException, IOException, LocatorException, InstallerCreationServiceException{ |
81 |
File applicationDirectory = super.getApplicationDirectory(); |
82 |
|
83 |
InstallerExecutionService installerExecutionService = |
84 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
85 |
installerExecutionService.setApplicationDirectory(applicationDirectory); |
86 |
installerExecutionService.addInstallersFromInstallDirectory(); |
87 |
installerExecutionService.setPluginToInstall("org.gvsig.plugin1");
|
88 |
installerExecutionService.executeInstaller(); |
89 |
|
90 |
Assert.assertEquals(3, installerExecutionService.getPluginsSize());
|
91 |
|
92 |
//Reading the excution and check that the file is installed
|
93 |
InstallerCreationService installerCreationService = |
94 |
InstallerLocator.getInstallerManager().getInstallerCreationService(); |
95 |
installerCreationService.setApplicationDirectory(applicationDirectory); |
96 |
Assert.assertEquals(4, installerCreationService.getPluginsSize());
|
97 |
} |
98 |
|
99 |
public void testInstallPluginFromExternalWithOutStreamException() throws InstallerExecutionServiceException, IOException, LocatorException, InstallerCreationServiceException{ |
100 |
File applicationDirectory = super.getApplicationDirectory(); |
101 |
|
102 |
InstallerExecutionService installerExecutionService = |
103 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
104 |
installerExecutionService.setApplicationDirectory(applicationDirectory); |
105 |
installerExecutionService.setPluginToInstall("org.gvsig.plugin1");
|
106 |
|
107 |
Exception exc = null; |
108 |
try{
|
109 |
installerExecutionService.executeInstaller(); |
110 |
}catch(InstallerExecutionServiceException e){
|
111 |
exc = e; |
112 |
} |
113 |
assertNotNull(exc); |
114 |
|
115 |
} |
116 |
|
117 |
public void testInstallPluginFromExternal() throws InstallerExecutionServiceException, IOException, LocatorException, InstallerCreationServiceException{ |
118 |
File applicationDirectory = super.getApplicationDirectory(); |
119 |
File externalInstallationFile = new File(applicationDirectory.getAbsoluteFile() + File.separator + "install" + File.separator + "installer1.zip"); |
120 |
|
121 |
InstallerExecutionService installerExecutionService = |
122 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
123 |
installerExecutionService.setApplicationDirectory(applicationDirectory); |
124 |
installerExecutionService.addInstaller(new FileInputStream(externalInstallationFile)); |
125 |
installerExecutionService.setPluginToInstall("org.gvsig.plugin1");
|
126 |
|
127 |
Assert.assertEquals(3, installerExecutionService.getPluginsSize());
|
128 |
|
129 |
installerExecutionService.executeInstaller(new FileInputStream(externalInstallationFile)); |
130 |
|
131 |
//Reading the excution and check that the file is installed
|
132 |
InstallerCreationService installerCreationService = |
133 |
InstallerLocator.getInstallerManager().getInstallerCreationService(); |
134 |
installerCreationService.setApplicationDirectory(applicationDirectory); |
135 |
Assert.assertEquals(4, installerCreationService.getPluginsSize());
|
136 |
} |
137 |
|
138 |
// public void testInstallPluginWithAntScript() throws InstallerExecutionServiceException, IOException, LocatorException, InstallerCreationServiceException{
|
139 |
// File applicationDirectory = super.getApplicationDirectory();
|
140 |
// File externalInstallationFile = new File(applicationDirectory.getAbsoluteFile() + File.separator + "install" + File.separator + "installer1.zip");
|
141 |
//
|
142 |
// InstallerExecutionService installerExecutionService =
|
143 |
// InstallerLocator.getInstallerManager().getInstallerExecutionService();
|
144 |
// installerExecutionService.setApplicationDirectory(applicationDirectory);
|
145 |
// installerExecutionService.addInstaller(new FileInputStream(externalInstallationFile));
|
146 |
// installerExecutionService.setPluginToInstall("org.gvsig.plugin2");
|
147 |
//
|
148 |
//
|
149 |
// installerExecutionService.executeInstaller(new FileInputStream(externalInstallationFile));
|
150 |
//
|
151 |
// //Reading the excution and check that the file is installed
|
152 |
// InstallerCreationService installerCreationService =
|
153 |
// InstallerLocator.getInstallerManager().getInstallerCreationService();
|
154 |
// installerCreationService.setApplicationDirectory(applicationDirectory);
|
155 |
// Assert.assertEquals(5, installerCreationService.getPluginsSize());
|
156 |
// }
|
157 |
|
158 |
} |
159 |
|