1 17 package org.apache.geronimo.system.plugin; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.util.Collections ; 24 import java.util.LinkedHashSet ; 25 import java.util.List ; 26 import java.util.SortedSet ; 27 import java.util.TreeSet ; 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 53 public class PluginInstallerTest extends TestCase { 54 private URL fakeRepo; 55 private URL testRepo; 56 private PluginInstaller installer; 57 58 protected void setUp() throws Exception { 59 super.setUp(); 60 fakeRepo = new URL ("http://nowhere.com/"); 61 String url = getClass().getResource("/geronimo-plugins.xml").toString(); 62 int pos = url.lastIndexOf("/"); 63 testRepo = new URL (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 consumerName, Runnable runnable) { 71 new Thread (runnable).start(); 72 } 73 }, null); 74 } 75 76 public void testParsing() throws Exception { 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 source, Artifact destination, FileWriteMonitor monitor) throws IOException { 101 } 102 103 public void copyToRepository(InputStream source, int size, Artifact destination, FileWriteMonitor monitor) throws IOException { 104 } 105 106 public boolean contains(Artifact artifact) { 107 return false; 108 } 109 110 public File getLocation(Artifact artifact) { 111 return null; 112 } 113 114 public LinkedHashSet getDependencies(Artifact artifact) { 115 return new LinkedHashSet (); 116 } 117 118 public SortedSet list() { 119 return new TreeSet (); 120 } 121 122 public SortedSet list(Artifact query) { 123 return new TreeSet (); 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 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 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 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 , 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 |