Revision 32415 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
InstallerCreationServiceTest.java | ||
---|---|---|
31 | 31 |
import java.io.ByteArrayOutputStream; |
32 | 32 |
import java.io.File; |
33 | 33 |
import java.io.FileNotFoundException; |
34 |
import java.io.IOException; |
|
34 | 35 |
|
35 | 36 |
import junit.framework.Assert; |
36 | 37 |
|
... | ... | |
40 | 41 |
import org.gvsig.installer.lib.api.creation.InstallerCreationServiceException; |
41 | 42 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionService; |
42 | 43 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException; |
44 |
import org.gvsig.installer.lib.impl.InstallerServiceTest; |
|
43 | 45 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
44 | 46 |
import org.gvsig.tools.library.LibrariesInitializer; |
45 | 47 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
... | ... | |
49 | 51 |
/** |
50 | 52 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
51 | 53 |
*/ |
52 |
public class InstallerCreationServiceTest extends AbstractLibraryAutoInitTestCase{
|
|
54 |
public class InstallerCreationServiceTest extends InstallerServiceTest{
|
|
53 | 55 |
|
54 | 56 |
@Override |
55 | 57 |
protected void doSetUp() throws Exception { |
56 | 58 |
|
57 | 59 |
} |
58 | 60 |
|
59 |
public void testCreateService() throws FileNotFoundException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{ |
|
60 |
String tempDirectoryPath = System.getProperty("java.io.tmpdir") + File.separator + "tmp_gvsig_installer"; |
|
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 |
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 |
} |
|
61 | 81 |
|
62 |
//Compress the plugin |
|
63 |
File file = new File(getClass().getClassLoader().getResource("org.gvsig.plugin1").getFile()); |
|
64 |
File installationFile = new File(getClass().getClassLoader().getResource("application").getFile()); |
|
82 |
public void testCreateInstallerWithOutSelectAPluginException() throws IOException, LocatorException, InstallerCreationServiceException{ |
|
83 |
File applicationDirectory = super.getApplicationDirectory(); |
|
65 | 84 |
|
66 | 85 |
InstallerCreationService installerCreationService = |
67 | 86 |
InstallerLocator.getInstallerManager().getInstallerCreationService(); |
68 |
installerCreationService.setPluginDirectory(file);
|
|
87 |
installerCreationService.setApplicationDirectory(applicationDirectory);
|
|
69 | 88 |
|
89 |
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 |
|
70 | 128 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
71 | 129 |
installerCreationService.createInstaller(os); |
72 |
|
|
73 |
//decompress the plugin |
|
130 |
|
|
131 |
//decompress the plugin and read the plugin information
|
|
74 | 132 |
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
75 | 133 |
InstallerExecutionService installerExecutionService = |
76 | 134 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
77 | 135 |
installerExecutionService.addInstaller(is); |
78 |
installerExecutionService.setApplicationDirectory(installationFile); |
|
136 |
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(); |
|
79 | 144 |
|
80 |
Assert.assertEquals(1, installerExecutionService.getPluginsSize());
|
|
81 |
|
|
82 |
//Read the information
|
|
83 |
InstallerInfo installerInfo = installerExecutionService.getPluginInfoAt(0);
|
|
145 |
InstallerCreationService installerCreationService =
|
|
146 |
InstallerLocator.getInstallerManager().getInstallerCreationService(); |
|
147 |
installerCreationService.setApplicationDirectory(applicationDirectory);
|
|
148 |
installerCreationService.setSelectedPlugin("org.gvsig.wfs");
|
|
84 | 149 |
|
85 |
assertEquals(installerInfo.getCode(), "org.gvsig.myplugin"); |
|
86 |
assertEquals(installerInfo.getName(), "myplugin"); |
|
87 |
assertEquals(installerInfo.getDescription(), "Test"); |
|
88 |
assertEquals(installerInfo.getVersion(), "1.0.0"); |
|
89 |
assertEquals(installerInfo.getBuild(), 1); |
|
90 |
assertEquals(installerInfo.getState(), "RC1"); |
|
91 |
assertEquals(installerInfo.isOfficial(), true); |
|
92 |
} |
|
150 |
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 |
} |
|
93 | 167 |
|
94 |
public void testLoadPluginInfo() throws FileNotFoundException, LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException{ |
|
95 |
String tempDirectoryPath = System.getProperty("java.io.tmpdir") + File.separator + "tmp_gvsig_installer"; |
|
96 |
|
|
97 |
//Compress the plugin |
|
98 |
File file = new File(getClass().getClassLoader().getResource("org.gvsig.plugin3").getFile()); |
|
168 |
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(); |
|
99 | 171 |
|
100 | 172 |
InstallerCreationService installerCreationService = |
101 | 173 |
InstallerLocator.getInstallerManager().getInstallerCreationService(); |
102 |
installerCreationService.setPluginDirectory(file); |
|
103 |
installerCreationService.loadInstallInfoFromDirectory(); |
|
104 |
|
|
105 |
//Read the information |
|
106 |
InstallerInfo installerInfo = installerCreationService.getInstallerInfo(); |
|
174 |
installerCreationService.setApplicationDirectory(applicationDirectory); |
|
175 |
installerCreationService.setSelectedPlugin("org.gvsig.wfs"); |
|
107 | 176 |
|
108 |
assertEquals(installerInfo.getCode(), "org.gvsig.plugin3"); |
|
109 |
assertEquals(1, installerInfo.getFileToCopySize()); |
|
110 |
String resource = installerInfo.getFileToCopyAt(0).getAbsolutePath(); |
|
111 |
assertTrue(resource.endsWith("org.gvsig.plugin2" + File.separator + "resource.txt")); |
|
177 |
InstallerInfo installerInfo = installerCreationService.getSelectedPlugin(); |
|
178 |
installerInfo.addFileToCopy(resource); |
|
112 | 179 |
|
113 |
} |
|
114 |
|
|
180 |
//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 |
} |
|
115 | 195 |
} |
116 | 196 |
|
Also available in: Unified diff