Revision 32420 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
InstallerExecutionServiceTest.java | ||
---|---|---|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.io.FileInputStream; |
32 | 32 |
import java.io.FileNotFoundException; |
33 |
import java.io.IOException; |
|
33 | 34 |
|
34 | 35 |
import junit.framework.Assert; |
35 | 36 |
|
37 |
import org.gvsig.installer.lib.api.InstallerInfo; |
|
36 | 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; |
|
37 | 41 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionService; |
38 | 42 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException; |
43 |
import org.gvsig.installer.lib.impl.InstallerServiceTest; |
|
39 | 44 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
45 |
import org.gvsig.tools.locator.LocatorException; |
|
40 | 46 |
|
41 | 47 |
/** |
42 | 48 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
43 | 49 |
*/ |
44 |
public class InstallerExecutionServiceTest extends AbstractLibraryAutoInitTestCase{
|
|
50 |
public class InstallerExecutionServiceTest extends InstallerServiceTest{
|
|
45 | 51 |
|
46 | 52 |
@Override |
47 | 53 |
protected void doSetUp() throws Exception { |
... | ... | |
49 | 55 |
|
50 | 56 |
} |
51 | 57 |
|
52 |
public void testReadFiles() throws InstallerExecutionServiceException, FileNotFoundException{ |
|
53 |
File file = new File(getClass().getClassLoader().getResource("installation.zip").getFile()); |
|
54 |
File installationFile = new File(getClass().getClassLoader().getResource("application").getFile()); |
|
55 |
|
|
58 |
public void testReadPlugins() throws LocatorException, InstallerCreationServiceException, InstallerExecutionServiceException, IOException{ |
|
59 |
File applicationDirectory = super.getApplicationDirectory(); |
|
60 |
|
|
56 | 61 |
InstallerExecutionService installerExecutionService = |
57 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
|
58 |
installerExecutionService.addInstaller(new FileInputStream(file)); |
|
59 |
installerExecutionService.setApplicationDirectory(installationFile); |
|
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 |
} |
|
60 | 79 |
|
80 |
public void testInstallPluginFromApplication() throws InstallerExecutionServiceException, IOException, LocatorException, InstallerCreationServiceException{ |
|
81 |
File applicationDirectory = super.getApplicationDirectory(); |
|
61 | 82 |
|
83 |
InstallerExecutionService installerExecutionService = |
|
84 |
InstallerLocator.getInstallerManager().getInstallerExecutionService(); |
|
85 |
installerExecutionService.setApplicationDirectory(applicationDirectory); |
|
86 |
installerExecutionService.addInstallersFromInstallDirectory(); |
|
87 |
installerExecutionService.setPluginToInstall("org.gvsig.plugin1"); |
|
88 |
installerExecutionService.executeInstaller(); |
|
62 | 89 |
|
90 |
Assert.assertEquals(3, installerExecutionService.getPluginsSize()); |
|
63 | 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()); |
|
64 | 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 |
} |
|
65 | 138 |
|
66 | 139 |
} |
67 | 140 |
|
Also available in: Unified diff