KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > plugin > PluginInstallerTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.plugin;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.LinkedHashSet JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.SortedSet JavaDoc;
27 import java.util.TreeSet JavaDoc;
28 import junit.framework.TestCase;
29 import org.apache.geronimo.gbean.AbstractName;
30 import org.apache.geronimo.kernel.config.Configuration;
31 import org.apache.geronimo.kernel.config.ConfigurationData;
32 import org.apache.geronimo.kernel.config.ConfigurationManager;
33 import org.apache.geronimo.kernel.config.ConfigurationStore;
34 import org.apache.geronimo.kernel.config.NoSuchConfigException;
35 import org.apache.geronimo.kernel.config.NoSuchStoreException;
36 import org.apache.geronimo.kernel.config.NullConfigurationStore;
37 import org.apache.geronimo.kernel.config.LifecycleResults;
38 import org.apache.geronimo.kernel.config.LifecycleException;
39 import org.apache.geronimo.kernel.config.LifecycleMonitor;
40 import org.apache.geronimo.kernel.repository.Artifact;
41 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
42 import org.apache.geronimo.kernel.repository.WritableListableRepository;
43 import org.apache.geronimo.kernel.repository.ArtifactResolver;
44 import org.apache.geronimo.kernel.repository.Version;
45 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
46 import org.apache.geronimo.system.threads.ThreadPool;
47
48 /**
49  * Tests the plugin installer GBean
50  *
51  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
52  */

53 public class PluginInstallerTest extends TestCase {
54     private URL JavaDoc fakeRepo;
55     private URL JavaDoc testRepo;
56     private PluginInstaller installer;
57
58     protected void setUp() throws Exception JavaDoc {
59         super.setUp();
60         fakeRepo = new URL JavaDoc("http://nowhere.com/");
61         String JavaDoc url = getClass().getResource("/geronimo-plugins.xml").toString();
62         int pos = url.lastIndexOf("/");
63         testRepo = new URL JavaDoc(url.substring(0, pos));
64         installer = new PluginInstallerGBean(new MockConfigManager(), new MockRepository(), new MockConfigStore(),
65                 new BasicServerInfo("."), new ThreadPool() {
66             public int getPoolSize() {
67                 return 0;
68             }
69
70             public void execute(String JavaDoc consumerName, Runnable JavaDoc runnable) {
71                 new Thread JavaDoc(runnable).start();
72             }
73         }, null);
74     }
75
76     public void testParsing() throws Exception JavaDoc {
77         PluginList list = installer.listPlugins(testRepo, null, null);
78         assertNotNull(list);
79         
80         assertEquals(1, list.getRepositories().length);
81         assertEquals(fakeRepo, list.getRepositories()[0]);
82         assertTrue(list.getPlugins().length > 0);
83         int prereqCount = 0;
84         for (int i = 0; i < list.getPlugins().length; i++) {
85             PluginMetadata metadata = list.getPlugins()[i];
86             prereqCount += metadata.getPrerequisites().length;
87             for (int j = 0; j < metadata.getPrerequisites().length; j++) {
88                 PluginMetadata.Prerequisite prerequisite = metadata.getPrerequisites()[j];
89                 assertFalse(prerequisite.isPresent());
90             }
91         }
92         assertTrue(prereqCount > 0);
93     }
94
95     private static class MockConfigStore extends NullConfigurationStore {
96
97     }
98
99     private static class MockRepository implements WritableListableRepository {
100         public void copyToRepository(File JavaDoc source, Artifact destination, FileWriteMonitor monitor) throws IOException JavaDoc {
101         }
102
103         public void copyToRepository(InputStream JavaDoc source, int size, Artifact destination, FileWriteMonitor monitor) throws IOException JavaDoc {
104         }
105
106         public boolean contains(Artifact artifact) {
107             return false;
108         }
109
110         public File JavaDoc getLocation(Artifact artifact) {
111             return null;
112         }
113
114         public LinkedHashSet JavaDoc getDependencies(Artifact artifact) {
115             return new LinkedHashSet JavaDoc();
116         }
117
118         public SortedSet JavaDoc list() {
119             return new TreeSet JavaDoc();
120         }
121
122         public SortedSet JavaDoc list(Artifact query) {
123             return new TreeSet JavaDoc();
124         }
125     }
126
127     private static class MockConfigManager implements ConfigurationManager {
128
129         public boolean isInstalled(Artifact configurationId) {
130             return false;
131         }
132
133         public Artifact[] getInstalled(Artifact query) {
134             return new Artifact[0];
135         }
136
137         public Artifact[] getLoaded(Artifact query) {
138             return new Artifact[0];
139         }
140
141         public Artifact[] getRunning(Artifact query) {
142             return new Artifact[0];
143         }
144
145         public boolean isLoaded(Artifact configID) {
146             return false;
147         }
148
149         public List JavaDoc listStores() {
150             return Collections.EMPTY_LIST;
151         }
152
153         public ConfigurationStore[] getStores() {
154             return new ConfigurationStore[0];
155         }
156
157         public ConfigurationStore getStoreForConfiguration(Artifact configuration) {
158             return null;
159         }
160
161         public List JavaDoc listConfigurations(AbstractName store) throws NoSuchStoreException {
162             return Collections.EMPTY_LIST;
163         }
164
165         public boolean isRunning(Artifact configurationId) {
166             return false;
167         }
168
169         public List JavaDoc listConfigurations() {
170             return null;
171         }
172
173         public boolean isConfiguration(Artifact artifact) {
174             return false;
175         }
176
177         public Configuration getConfiguration(Artifact configurationId) {
178             return null;
179         }
180
181         public LifecycleResults loadConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException {
182             return null;
183         }
184
185         public LifecycleResults loadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, LifecycleException {
186             return null;
187         }
188
189         public LifecycleResults loadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
190             return null;
191         }
192
193         public LifecycleResults loadConfiguration(ConfigurationData configurationData, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
194             return null;
195         }
196
197         public LifecycleResults unloadConfiguration(Artifact configurationId) throws NoSuchConfigException {
198             return null;
199         }
200
201         public LifecycleResults unloadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException {
202             return null;
203         }
204
205         public LifecycleResults startConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException {
206             return null;
207         }
208
209         public LifecycleResults startConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
210             return null;
211         }
212
213         public LifecycleResults stopConfiguration(Artifact configurationId) throws NoSuchConfigException {
214             return null;
215         }
216
217         public LifecycleResults stopConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException {
218             return null;
219         }
220
221         public LifecycleResults restartConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException {
222             return null;
223         }
224
225         public LifecycleResults restartConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
226             return null;
227         }
228
229         public LifecycleResults reloadConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException {
230             return null;
231         }
232
233         public LifecycleResults reloadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
234             return null;
235         }
236
237         public LifecycleResults reloadConfiguration(Artifact configurationId, Version version) throws NoSuchConfigException, LifecycleException {
238             return null;
239         }
240
241         public LifecycleResults reloadConfiguration(Artifact configurationId, Version version, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
242             return null;
243         }
244
245         public LifecycleResults reloadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, LifecycleException {
246             return null;
247         }
248
249         public LifecycleResults reloadConfiguration(ConfigurationData configurationData, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
250             return null;
251         }
252
253         public void uninstallConfiguration(Artifact configurationId) throws IOException JavaDoc, NoSuchConfigException {
254
255         }
256
257         public ArtifactResolver getArtifactResolver() {
258             return null;
259         }
260
261         public boolean isOnline() {
262             return true;
263         }
264
265         public void setOnline(boolean online) {
266         }
267     }
268 }
269
Popular Tags