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 / execution / InstallPackageServiceTest.java @ 37599

History | View | Annotate | Download (6.17 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.IOException;
32

    
33
import junit.framework.Assert;
34

    
35
import org.gvsig.installer.lib.api.InstallerLocator;
36
import org.gvsig.installer.lib.api.PackageInfo;
37
import org.gvsig.installer.lib.api.creation.MakePluginPackageService;
38
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
39
import org.gvsig.installer.lib.api.execution.InstallPackageService;
40
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
41
import org.gvsig.installer.lib.impl.InstallerServiceTest;
42
import org.gvsig.tools.locator.LocatorException;
43

    
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
46
 */
47
public class InstallPackageServiceTest extends InstallerServiceTest {
48

    
49
        @Override
50
        protected void doSetUp() throws Exception {
51
                // TODO Auto-generated method stub
52

    
53
        }
54

    
55
        public void testReadPlugins() throws LocatorException,
56
                        MakePluginPackageServiceException, InstallPackageServiceException,
57
                        IOException {
58
                File installersDirectory = super.getInstallersDirectory();
59

    
60
                InstallPackageService installPackageService = InstallerLocator
61
                                .getInstallerManager().getInstallPackageService();
62
                installPackageService.addBundlesFromDirectory(installersDirectory);
63

    
64
                Assert.assertEquals(3, installPackageService.getPackageCount());
65

    
66
                int pluginsNumber = 0;
67
                for (int i = 0; i < 3; i++) {
68
                        PackageInfo packageInfo = installPackageService.getPackageInfo(i);
69
                        if (packageInfo.getCode().equals("org.gvsig.plugin1")) {
70
                                assertNotNull(packageInfo.getState());
71
                                pluginsNumber++;
72
                        } else if (packageInfo.getCode().equals("org.gvsig.plugin2")) {
73
                                assertEquals("RC1", packageInfo.getState());
74
                                pluginsNumber++;
75
                        } else if (packageInfo.getCode().equals("org.gvsig.plugin3")) {
76
                                assertEquals("Testing", packageInfo.getState());
77
                                pluginsNumber++;
78
                        }
79
                }
80

    
81
                Assert.assertEquals(3, pluginsNumber);
82
        }
83

    
84
        public void testInstallPluginFromApplication()
85
                        throws InstallPackageServiceException, IOException,
86
                        LocatorException, MakePluginPackageServiceException {
87
                File installersDirectory = super.getInstallersDirectory();
88
                File pluginsDirectory = super.getPluginsDirectory();
89
                File applicationDirectory = super.getApplicationDirectory();
90

    
91
                InstallPackageService installerExecutionService = InstallerLocator
92
                                .getInstallerManager().getInstallPackageService();
93
                installerExecutionService.addBundlesFromDirectory(installersDirectory);
94

    
95
                PackageInfo packageInfo = installerExecutionService
96
                                .getPackageInfo("org.gvsig.plugin1");
97
                installerExecutionService.installPackage(applicationDirectory,
98
                                packageInfo);
99

    
100
                Assert.assertEquals(3, installerExecutionService.getPackageCount());
101

    
102
                // Reading the excution and check that the file is installed
103
                MakePluginPackageService installerCreationService = InstallerLocator
104
                                .getInstallerManager().getMakePluginPackageService(
105
                                                pluginsDirectory);
106
                Assert
107
                                .assertEquals(4, installerCreationService
108
                                                .getPluginPackageCount());
109
        }
110

    
111
        public void testInstallPluginFromExternal()
112
                        throws InstallPackageServiceException, IOException,
113
                        LocatorException, MakePluginPackageServiceException {
114
                File applicationDirectory = super.getApplicationDirectory();
115
                File externalInstallationFile = new File(applicationDirectory
116
                                .getAbsoluteFile()
117
                                + File.separator + "install" + File.separator + "bundle1.zip");
118
                File pluginsDirectory = super.getPluginsDirectory();
119

    
120
                InstallPackageService installerExecutionService = InstallerLocator
121
                                .getInstallerManager().getInstallPackageService();
122
                installerExecutionService.addBundle(externalInstallationFile);
123

    
124
                PackageInfo packageInfo = installerExecutionService
125
                                .getPackageInfo("org.gvsig.plugin1");
126

    
127
                Assert.assertEquals(3, installerExecutionService.getPackageCount());
128

    
129
                installerExecutionService.installPackage(applicationDirectory,
130
                                packageInfo);
131

    
132
                // Reading the excution and check that the file is installed
133
                MakePluginPackageService installerCreationService = InstallerLocator
134
                                .getInstallerManager().getMakePluginPackageService(
135
                                                pluginsDirectory);
136
                Assert
137
                                .assertEquals(4, installerCreationService
138
                                                .getPluginPackageCount());
139
        }
140

    
141
        // public void testInstallPluginWithAntScript() throws
142
        // InstallPackageServiceException, LocatorException,
143
        // MakePluginPackageServiceException, IOException{
144
        // File applicationDirectory = super.getApplicationDirectory();
145
        // File installersDirectory = super.getInstallersDirectory();
146
        // File pluginsDirectory = super.getPluginsDirectory();
147
        //
148
        // InstallPackageService installerExecutionService =
149
        // InstallerLocator.getInstallerManager().getInstallPackageService();
150
        // installerExecutionService.addBundlesFromDirectory(installersDirectory);
151
        //
152
        // PackageInfo packageInfo =
153
        // installerExecutionService.getPackageInfo("org.gvsig.plugin2");
154
        //
155
        // Assert.assertEquals(3, installerExecutionService.getPackageCount());
156
        //
157
        // installerExecutionService.installPackage(applicationDirectory,
158
        // packageInfo);
159
        //
160
        // //Reading the excution and check that the file is installed
161
        // MakePluginPackageService installerCreationService =
162
        // InstallerLocator.getInstallerManager().getMakePluginPackageService(pluginsDirectory);
163
        //
164
        // Assert.assertEquals(5, installerCreationService.getPluginPackageCount());
165
        // }
166

    
167
}