1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.plugin;
17
18 import org.apache.commons.io.FileUtils;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.config.property.Config;
21 import org.kuali.rice.core.api.util.ClasspathOrFileResourceLoader;
22 import org.kuali.rice.kew.test.KEWTestCase;
23 import org.kuali.rice.kew.test.TestUtilities;
24
25 import java.io.File;
26 import java.util.List;
27
28 import static org.junit.Assert.*;
29
30
31
32
33
34
35
36
37
38
39
40 public class ExtraClassPathTest extends KEWTestCase {
41
42 private PluginRegistry registry;
43
44 @Override
45 public void setUp() throws Exception {
46
47
48 super.setUp();
49 TestUtilities.initializePluginDirectories();
50 String pluginZipFileLocation = new ClasspathOrFileResourceLoader().getResource("classpath:org/kuali/rice/kew/plugin/extraclasspathtest.zip").getURL().getPath();
51 File pluginZipFile = new File(pluginZipFileLocation);
52 assertTrue("File " + pluginZipFileLocation + " should exist", pluginZipFile.exists());
53 assertTrue("File " + pluginZipFileLocation + " should be a file", pluginZipFile.isFile());
54 FileUtils.copyFileToDirectory(pluginZipFile, TestUtilities.getPluginsDirectory());
55 pluginZipFile = new File(TestUtilities.getPluginsDirectory(), pluginZipFile.getName());
56 FileUtils.forceDeleteOnExit(pluginZipFile);
57 registry = new PluginRegistryFactory().createPluginRegistry();
58 registry.start();
59 }
60
61 @Override
62 public void tearDown() throws Exception {
63 super.tearDown();
64 if (registry != null) {
65 registry.stop();
66 }
67 TestUtilities.cleanupPluginDirectories();
68 }
69
70 @Test public void testExtraClassPath() throws Exception {
71
72 List<PluginEnvironment> environments = registry.getPluginEnvironments();
73 assertEquals("There should be 1 plugin environment.", 1, environments.size());
74
75 PluginEnvironment environment = environments.get(0);
76 assertEquals("Should be the extraclasspathtest plugin.", "extraclasspathtest", environment.getPlugin().getName().getLocalPart());
77
78
79 String extraClassesDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_CLASSES_DIR);
80 String extraLibDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_LIB_DIR);
81
82 File extraClassesDir = new ClasspathOrFileResourceLoader().getResource(extraClassesDirName).getFile();
83 assertTrue("extra classes dir (" + extraClassesDirName + ") should exist.", extraClassesDir.exists());
84 assertTrue("extra classes dir (" + extraClassesDirName + ") should be a directory.", extraClassesDir.isDirectory());
85 File extraLibDir = new File(extraLibDirName);
86 assertTrue("extra lib dir (" + extraLibDirName + ") should exist.", extraLibDir.exists());
87 assertTrue("extra lib dir (" + extraLibDirName + ") should be a directory.", extraLibDir.isDirectory());
88
89
90 ClassLoader classLoader = environment.getPlugin().getClassLoader();
91 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-classes.txt"));
92 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-lib.txt"));
93 }
94
95 }