001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.plugin;
017
018 import static org.junit.Assert.assertEquals;
019 import static org.junit.Assert.assertNotNull;
020 import static org.junit.Assert.assertTrue;
021
022 import java.io.File;
023 import java.util.List;
024
025 import org.apache.commons.io.FileUtils;
026 import org.junit.Test;
027 import org.kuali.rice.core.api.config.property.Config;
028 import org.kuali.rice.kew.test.KEWTestCase;
029 import org.kuali.rice.kew.test.TestUtilities;
030
031
032 /**
033 * Tests that the extra classpath features of the plugin work as advertised.
034 *
035 * <p>Adds the test/src/org/kuali/rice/kew/plugin/classes directory to the extra classes on
036 * the classpath. Adds the test/src/org/kuali/rice/kew/plugin/lib directory to the extra
037 * libs on the classpath. Within the lib directory is a jar called extraclasspath.jar.
038 * Inside this jar is a single resource called extraclasspath-lib.txt.
039 *
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 */
042 public class ExtraClassPathTest extends KEWTestCase {
043
044 private PluginRegistry registry;
045
046 @Override
047 public void setUp() throws Exception {
048 // we want to copy the ziptest plugin into the plugin directories before the
049 // test harness starts up. That way the plugin will be loaded at startup time.
050 super.setUp();
051 TestUtilities.initializePluginDirectories();
052 String pluginZipFileLocation = getBaseDir() + "/src/test/resources/org/kuali/rice/kew/plugin/extraclasspathtest.zip";
053 File pluginZipFile = new File(pluginZipFileLocation);
054 assertTrue("File " + pluginZipFileLocation + " should exist", pluginZipFile.exists());
055 assertTrue("File " + pluginZipFileLocation + " should be a file", pluginZipFile.isFile());
056 FileUtils.copyFileToDirectory(pluginZipFile, TestUtilities.getPluginsDirectory());
057 pluginZipFile = new File(TestUtilities.getPluginsDirectory(), pluginZipFile.getName());
058 FileUtils.forceDeleteOnExit(pluginZipFile);
059 registry = new PluginRegistryFactory().createPluginRegistry();
060 registry.start();
061 }
062
063 @Override
064 public void tearDown() throws Exception {
065 super.tearDown();
066 if (registry != null) {
067 registry.stop();
068 }
069 TestUtilities.cleanupPluginDirectories();
070 }
071
072 @Test public void testExtraClassPath() throws Exception {
073 // first of all, let's check that the plugin was loaded when the test harness started up
074 List<PluginEnvironment> environments = registry.getPluginEnvironments();
075 assertEquals("There should be 1 plugin environment.", 1, environments.size());
076
077 PluginEnvironment environment = environments.get(0);
078 assertEquals("Should be the extraclasspathtest plugin.", "extraclasspathtest", environment.getPlugin().getName().getLocalPart());
079
080 // check that the properties were configured correctly
081 String extraClassesDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_CLASSES_DIR);
082 String extraLibDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_LIB_DIR);
083
084 File extraClassesDir = new File(extraClassesDirName);
085 assertTrue("extra classes dir (" + extraClassesDirName + ") should exist.", extraClassesDir.exists());
086 assertTrue("extra classes dir (" + extraClassesDirName + ") should be a directory.", extraClassesDir.isDirectory());
087 File extraLibDir = new File(extraLibDirName);
088 assertTrue("extra lib dir (" + extraLibDirName + ") should exist.", extraLibDir.exists());
089 assertTrue("extra lib dir (" + extraLibDirName + ") should be a directory.", extraLibDir.isDirectory());
090
091 // now verify that the resources from the extra classes and extra lib dirs got loaded
092 ClassLoader classLoader = environment.getPlugin().getClassLoader();
093 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-classes.txt"));
094 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-lib.txt"));
095 }
096
097 }