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