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

History | View | Annotate | Download (6.02 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 applicationDirectory = super.getApplicationDirectory();
89

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

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

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

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

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

    
117
                InstallPackageService installerExecutionService = InstallerLocator
118
                                .getInstallerManager().getInstallPackageService();
119
                installerExecutionService.addBundle(externalInstallationFile);
120

    
121
                PackageInfo packageInfo = installerExecutionService
122
                                .getPackageInfo("org.gvsig.plugin1");
123

    
124
                Assert.assertEquals(3, installerExecutionService.getPackageCount());
125

    
126
                installerExecutionService.installPackage(applicationDirectory,
127
                                packageInfo);
128

    
129
                // Reading the excution and check that the file is installed
130
                MakePluginPackageService installerCreationService = InstallerLocator
131
                                .getInstallerManager().getMakePluginPackageService();
132
                Assert
133
                                .assertEquals(4, installerCreationService
134
                                                .getPluginPackageCount());
135
        }
136

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

    
163
}