View Javadoc

1   /**
2    * Copyright 2005-2011 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 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   * Tests that the extra classpath features of the plugin work as advertised.
34   *
35   * <p>Adds the test/src/org/kuali/rice/kew/plugin/classes directory to the extra classes on
36   * the classpath.  Adds the test/src/org/kuali/rice/kew/plugin/lib directory to the extra
37   * libs on the classpath.  Within the lib directory is a jar called extraclasspath.jar.
38   * Inside this jar is a single resource called extraclasspath-lib.txt.
39   *
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   */
42  public class ExtraClassPathTest extends KEWTestCase {
43      
44      private PluginRegistry registry;
45  
46  	@Override
47  	public void setUp() throws Exception {
48  		// we want to copy the ziptest plugin into the plugin directories before the
49  		// test harness starts up.  That way the plugin will be loaded at startup time.
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  		// first of all, let's check that the plugin was loaded when the test harness started up
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  		// check that the properties were configured correctly
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  		// now verify that the resources from the extra classes and extra lib dirs got loaded
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  }