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

History | View | Annotate | Download (6.77 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 =
61
            InstallerLocator.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
73
                if (packageInfo.getCode().equals("org.gvsig.plugin2")) {
74
                    assertEquals("RC1", packageInfo.getState());
75
                    pluginsNumber++;
76
                } else
77
                    if (packageInfo.getCode().equals("org.gvsig.plugin3")) {
78
                        assertEquals("Testing", packageInfo.getState());
79
                        pluginsNumber++;
80
                    }
81
        }
82

    
83
        Assert.assertEquals(3, pluginsNumber);
84
    }
85

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

    
93
        InstallPackageService installerExecutionService =
94
            InstallerLocator.getInstallerManager().getInstallPackageService();
95
        installerExecutionService.addBundlesFromDirectory(installersDirectory);
96

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

    
102
        Assert.assertEquals(3, installerExecutionService.getPackageCount());
103

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

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

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

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

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

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

    
133
        // Reading the excution and check that the file is installed
134
        MakePluginPackageService installerCreationService =
135
            InstallerLocator.getInstallerManager().getMakePluginPackageService(
136
                pluginsDirectory);
137
        Assert
138
            .assertEquals(4, installerCreationService.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
}