001 /* 002 * Copyright 2006-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 017 package org.kuali.rice.kew.plugin; 018 019 import static org.junit.Assert.assertEquals; 020 import static org.junit.Assert.assertNotNull; 021 import static org.junit.Assert.assertTrue; 022 023 import java.io.File; 024 import java.util.List; 025 026 import org.apache.commons.io.FileUtils; 027 import org.junit.Test; 028 import org.kuali.rice.core.api.config.property.Config; 029 import org.kuali.rice.kew.test.KEWTestCase; 030 import org.kuali.rice.kew.test.TestUtilities; 031 032 033 /** 034 * Tests that the extra classpath features of the plugin work as advertised. 035 * 036 * <p>Adds the test/src/org/kuali/rice/kew/plugin/classes directory to the extra classes on 037 * the classpath. Adds the test/src/org/kuali/rice/kew/plugin/lib directory to the extra 038 * libs on the classpath. Within the lib directory is a jar called extraclasspath.jar. 039 * Inside this jar is a single resource called extraclasspath-lib.txt. 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043 public class ExtraClassPathTest extends KEWTestCase { 044 045 private PluginRegistry registry; 046 047 @Override 048 public void setUp() throws Exception { 049 // we want to copy the ziptest plugin into the plugin directories before the 050 // test harness starts up. That way the plugin will be loaded at startup time. 051 super.setUp(); 052 TestUtilities.initializePluginDirectories(); 053 String pluginZipFileLocation = getBaseDir() + "/src/test/resources/org/kuali/rice/kew/plugin/extraclasspathtest.zip"; 054 File pluginZipFile = new File(pluginZipFileLocation); 055 assertTrue("File " + pluginZipFileLocation + " should exist", pluginZipFile.exists()); 056 assertTrue("File " + pluginZipFileLocation + " should be a file", pluginZipFile.isFile()); 057 FileUtils.copyFileToDirectory(pluginZipFile, TestUtilities.getPluginsDirectory()); 058 pluginZipFile = new File(TestUtilities.getPluginsDirectory(), pluginZipFile.getName()); 059 FileUtils.forceDeleteOnExit(pluginZipFile); 060 registry = new PluginRegistryFactory().createPluginRegistry(); 061 registry.start(); 062 } 063 064 @Override 065 public void tearDown() throws Exception { 066 super.tearDown(); 067 if (registry != null) { 068 registry.stop(); 069 } 070 TestUtilities.cleanupPluginDirectories(); 071 } 072 073 @Test public void testExtraClassPath() throws Exception { 074 // first of all, let's check that the plugin was loaded when the test harness started up 075 List<PluginEnvironment> environments = registry.getPluginEnvironments(); 076 assertEquals("There should be 1 plugin environment.", 1, environments.size()); 077 078 PluginEnvironment environment = environments.get(0); 079 assertEquals("Should be the extraclasspathtest plugin.", "extraclasspathtest", environment.getPlugin().getName().getLocalPart()); 080 081 // check that the properties were configured correctly 082 String extraClassesDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_CLASSES_DIR); 083 String extraLibDirName = environment.getPlugin().getConfig().getProperty(Config.EXTRA_LIB_DIR); 084 085 File extraClassesDir = new File(extraClassesDirName); 086 assertTrue("extra classes dir (" + extraClassesDirName + ") should exist.", extraClassesDir.exists()); 087 assertTrue("extra classes dir (" + extraClassesDirName + ") should be a directory.", extraClassesDir.isDirectory()); 088 File extraLibDir = new File(extraLibDirName); 089 assertTrue("extra lib dir (" + extraLibDirName + ") should exist.", extraLibDir.exists()); 090 assertTrue("extra lib dir (" + extraLibDirName + ") should be a directory.", extraLibDir.isDirectory()); 091 092 // now verify that the resources from the extra classes and extra lib dirs got loaded 093 ClassLoader classLoader = environment.getPlugin().getClassLoader(); 094 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-classes.txt")); 095 assertNotNull("Resource should exist.", classLoader.getResource("extraclasspath-lib.txt")); 096 } 097 098 }