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