View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests that the extra classpath features of the plugin work as advertised.
32   *
33   * <p>Adds the test/src/org/kuali/rice/kew/plugin/classes directory to the extra classes on
34   * the classpath.  Adds the test/src/org/kuali/rice/kew/plugin/lib directory to the extra
35   * libs on the classpath.  Within the lib directory is a jar called extraclasspath.jar.
36   * Inside this jar is a single resource called extraclasspath-lib.txt.
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  public class ExtraClassPathTest extends KEWTestCase {
41      
42      private PluginRegistry registry;
43  
44  	@Override
45  	public void setUp() throws Exception {
46  		// we want to copy the ziptest plugin into the plugin directories before the
47  		// test harness starts up.  That way the plugin will be loaded at startup time.
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  		// first of all, let's check that the plugin was loaded when the test harness started up
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  		// check that the properties were configured correctly
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  		// now verify that the resources from the extra classes and extra lib dirs got loaded
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  }