You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/04/12 21:43:37 UTC
svn commit: r933379 [9/15] - in /myfaces/extensions/scripting/trunk:
extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/
extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/scripting/
e...
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/lifecycle/StartupTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/lifecycle/StartupTestCase.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/lifecycle/StartupTestCase.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/lifecycle/StartupTestCase.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.lifecycle;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.support.ContextUtils;
+import org.apache.myfaces.extensions.scripting.core.support.MockServletContext;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContextInitializer;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.servlet.ServletContext;
+
+import static org.junit.Assert.*;
+
+/**
+ * Unit tests which should secure the startup cycle
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class StartupTestCase {
+ ServletContext context;
+
+ @Before
+ public void init() {
+ context = ContextUtils.startupSystem();
+ }
+
+ @Test
+ public void testStartup() {
+ assertTrue("Scripting must be enabled", WeavingContext.isScriptingEnabled());
+ assertTrue("Configuration must be reachable", WeavingContext.getConfiguration() != null);
+ assertTrue("RefreshContext must be set", WeavingContext.getRefreshContext() != null);
+ assertTrue("Daemon must be running", WeavingContext.getRefreshContext().getDaemon().isRunning());
+ assertTrue("Daemon must be running", WeavingContext.getFileChangedDaemon().isRunning());
+ assertTrue("External context must be reachable", WeavingContext.getExternalContext() == context);
+ assertTrue("Weaver must be set", WeavingContext.getWeaver() != null);
+ }
+
+ @Test
+ public void testConfiguration() {
+ assertTrue("Compile target dir must be set", WeavingContext.getConfiguration().getCompileTarget() != null);
+ assertTrue("Initial compile flag must be set to allow the initial compile", WeavingContext.getConfiguration().isInitialCompile());
+
+ assertTrue("Source dirs per registered scripting engine must be one", WeavingContext.getConfiguration().getSourceDirs(ScriptingConst.ENGINE_TYPE_JSF_JAVA).size() == 1);
+ assertTrue("Source dirs per registered scripting engine must be one", WeavingContext.getConfiguration().getSourceDirs(ScriptingConst.ENGINE_TYPE_JSF_GROOVY).size() == 1);
+ }
+
+ @Test
+ public void testNotFullyStarted() {
+ assertTrue("Startup not done yet", context.getAttribute(ScriptingConst.CTX_ATTR_STARTUP) == null);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/MethodReloadingProbe.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/MethodReloadingProbe.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/MethodReloadingProbe.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/MethodReloadingProbe.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,21 @@
+package org.apache.myfaces.extensions.scripting.core.probes;
+
+/**
+ * Interface which will allow the proxying of our probe
+ * in reloading handlers
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface MethodReloadingProbe {
+
+ /**
+ * testmethod 1 goes through
+ */
+ public void testMethod1();
+
+ /**
+ * this one throws an exception
+ */
+ public void testMethod2();
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.scripting.core.probes;
+
+import org.junit.Ignore;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * testprobe for our reflectutils
+ */
+
+@Ignore
+public class Probe implements MethodReloadingProbe {
+
+ public Probe() {
+ }
+
+ public Probe(String hello, String world) {
+
+ }
+
+ public void testMethod1() {
+
+ }
+
+ public void testMethod2() {
+ throw new NullPointerException("for test");
+ }
+
+ public boolean testMethod3(String param1) {
+ return true;
+ }
+
+ public static boolean testMethod4(String param1, String param2) {
+ return true;
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe2.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe2.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/probes/Probe2.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.probes;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class Probe2 {
+
+ public Probe2(String[] test) {
+
+ }
+
+ public static Boolean myHello(String xxx) {
+ return Boolean.TRUE;
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/refreshContext/RefreshContextTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/refreshContext/RefreshContextTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/refreshContext/RefreshContextTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/refreshContext/RefreshContextTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.refreshContext;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.myfaces.extensions.scripting.api.Configuration;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.refresh.RefreshContext;
+import org.apache.myfaces.extensions.scripting.refresh.ReloadingMetadata;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Set;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Testcases for the refresh context
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RefreshContextTest {
+
+ private static String PROBE1 = "../../src/test/resources/compiler/TestProbe1.java";
+ private static String PROBE2 = "../../src/test/resources/compiler/TestProbe2.java";
+ private static String RESOURCES = "../../src/test/resources/";
+
+ private static final String TAINT_HISTORY_SIZE = "Taint history size";
+ private static final String TAINT_HISTORY_CONTAINS = "Taint history contains";
+ private static final String THREE_NEW_ENTRIES_IN_THE_LOG = "three new entries in the log";
+ private static final String ALL_ENTRIES_GCED = "All entries gced";
+
+ File probe1;
+ File probe2;
+ File root;
+
+ public RefreshContextTest() {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ String currentPath = loader.getResource("./").getPath();
+ String sourcePath1 = currentPath + PROBE1;
+ String sourcePath2 = currentPath + PROBE2;
+ String rootPath = currentPath + RESOURCES;
+
+ sourcePath1 = FilenameUtils.normalize(sourcePath1);
+ sourcePath2 = FilenameUtils.normalize(sourcePath2);
+ rootPath = FilenameUtils.normalize(rootPath);
+
+ probe1 = new File(sourcePath1);
+ probe2 = new File(sourcePath2);
+ root = new File(rootPath);
+
+ WeavingContext.setConfiguration(new Configuration());
+ WeavingContext.getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_JAVA, root.getAbsolutePath());
+ WeavingContext.setRefreshContext(new RefreshContext());
+ }
+
+ @Test
+ public void testTaingLog() {
+ RefreshContext ctx = WeavingContext.getRefreshContext();
+ ctx.setTaintLogTimeout(0);
+
+ ReloadingMetadata data = new ReloadingMetadata();
+ data.setAClass(this.getClass());
+ data.setTainted(true);
+ data.setTimestamp(System.currentTimeMillis());
+
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+
+ assertTrue(THREE_NEW_ENTRIES_IN_THE_LOG, ctx.getTaintHistory(0l).size() == 3);
+ try {
+ Thread.sleep(20);
+ } catch (InterruptedException e) {
+ fail(e.toString());
+ }
+ ctx.gcTaintLog();
+ assertTrue(ALL_ENTRIES_GCED, ctx.getTaintHistory(0l).size() == 0);
+
+ ctx.setTaintLogTimeout(300000000l);
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+ ctx.gcTaintLog();
+ assertTrue(THREE_NEW_ENTRIES_IN_THE_LOG, ctx.getTaintHistory(0l).size() == 3);
+
+ }
+
+ @Test
+ public void testTaintHistory() {
+ RefreshContext ctx = WeavingContext.getRefreshContext();
+ ctx.setTaintLogTimeout(3);
+
+ ReloadingMetadata data = new ReloadingMetadata();
+ data.setAClass(this.getClass());
+ data.setTainted(true);
+ data.setTimestamp(System.currentTimeMillis());
+
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+
+ Set<String> result = ctx.getTaintHistoryClasses(0l);
+ assertTrue(TAINT_HISTORY_CONTAINS, result.contains(this.getClass().getName()));
+ assertTrue(TAINT_HISTORY_SIZE, result.size() == 1);
+
+ }
+
+ @Test
+ public void testTaintHistoryLastNoOfEntroies() {
+ RefreshContext ctx = WeavingContext.getRefreshContext();
+ ctx.setTaintLogTimeout(3);
+
+ ReloadingMetadata data = new ReloadingMetadata();
+ data.setAClass(this.getClass());
+ data.setTainted(true);
+ data.setTimestamp(System.currentTimeMillis());
+
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+ ctx.addTaintLogEntry(data);
+
+ Collection<ReloadingMetadata> result = ctx.getLastTainted(100);
+ assertTrue(TAINT_HISTORY_SIZE, result.size() == 3);
+ result = ctx.getLastTainted(2);
+ assertTrue(TAINT_HISTORY_SIZE, result.size() == 2);
+ result = ctx.getLastTainted(0);
+ assertTrue(TAINT_HISTORY_SIZE, result.size() == 0);
+
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategyTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategyTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategyTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategyTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.reloading;
+
+import org.apache.myfaces.extensions.scripting.core.reloading.ManagedBeanReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.api.BaseWeaver;
+import org.apache.myfaces.extensions.scripting.api.DynamicCompiler;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.probes.Probe;
+import org.apache.myfaces.extensions.scripting.core.support.Consts;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * A simple test to ensure that the managed bean reloading strategy
+ * does not do anything
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ManagedBeanReloadingStrategyTest {
+
+ static final class DummyWeaver extends BaseWeaver {
+
+ @Override
+ public boolean isDynamic(Class clazz) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void scanForAddedClasses() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ protected DynamicCompiler instantiateCompiler() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ protected String getLoadingInfo(String file) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ }
+
+ @Test
+ public void testReload() throws Exception {
+ Probe probe = new Probe();
+ ManagedBeanReloadingStrategy strategy = new ManagedBeanReloadingStrategy();
+ for (int artifactType : Consts.ARTIFACT_TYPES) {
+ Object probe2 = strategy.reload(probe, artifactType);
+ assertTrue(probe2 == probe);
+ }
+ }
+
+ @Test
+ public void testSetGetWeaver() throws Exception {
+ ManagedBeanReloadingStrategy strategy = new ManagedBeanReloadingStrategy();
+ ScriptingWeaver dummyWeaver = new DummyWeaver();
+ strategy.setWeaver(dummyWeaver);
+ assertTrue(strategy.getWeaver() == dummyWeaver);
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.reloading;
+
+import org.apache.myfaces.extensions.scripting.core.reloading.SimpleReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.probes.Probe;
+import org.apache.myfaces.extensions.scripting.core.support.ContextUtils;
+import org.apache.myfaces.extensions.scripting.core.support.ObjectReloadingWeaver;
+import org.apache.myfaces.extensions.scripting.core.support.PathUtils;
+import org.apache.myfaces.extensions.scripting.core.support.TestingJavaScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.loaders.java.RecompiledClassLoader;
+import org.apache.myfaces.extensions.scripting.refresh.ReloadingMetadata;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Simple Reloading Strategy
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class SimpleReloadingStrategyTest {
+
+ private static final PathUtils _pathUtils = new PathUtils();
+ private static final String RESOURCES = _pathUtils.getResource(".");
+ Logger logger = Logger.getLogger(SimpleReloadingStrategyTest.class.getName());
+
+ ServletContext _context;
+ RecompiledClassLoader _loader;
+ File _root = new File(RESOURCES + File.separator + "compiler/");
+
+ SimpleReloadingStrategy _strategy;
+
+ static class MyProbe {
+ //weaver = new CoreWeaver(new JavaScriptingWeaver());
+ //TWeavingContext.setScriptingEnabled(true);
+ //TWeavingContext.setWeaverForTesting(weaver);
+ }
+
+ @Before
+ public void init() throws Exception {
+ _context = ContextUtils.startupSystem();
+ WeavingContext.getConfiguration().getSourceDirs(ScriptingConst.ENGINE_TYPE_JSF_JAVA).clear();
+ WeavingContext.getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_JAVA, _root.getAbsolutePath());
+
+ _loader = new RecompiledClassLoader(Thread.currentThread().getContextClassLoader(), ScriptingConst.ENGINE_TYPE_JSF_JAVA, ".java", false);
+ ContextUtils.doJavaRecompile(_root.getAbsolutePath());
+
+ /**
+ * we now work on our normal scripting weaver for java for this testcase
+ */
+ WeavingContext.setWeaver(new TestingJavaScriptingWeaver());
+ _strategy = new SimpleReloadingStrategy(WeavingContext.getWeaver());
+ }
+
+ @Test
+ public void testReload() throws Exception {
+
+ Object probe = _loader.loadClass("compiler.TestProbe1").newInstance();
+ ReloadingMetadata metaData = getMetadata(probe);
+ WeavingContext.getRefreshContext().getDaemon().getClassMap().put("compiler.TestProbe1", metaData);
+
+ ReflectUtil.executeMethod(probe, "setTestAttr", "hello");
+ Object probe2 = _strategy.reload(probe, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ Object attr = ReflectUtil.executeMethod(probe, "getTestAttr");
+ assertFalse(probe.hashCode() == probe2.hashCode());
+ assertTrue(attr instanceof String);
+ assertTrue(((String)attr).equals("hello"));
+
+ Object probe3 = _strategy.reload(probe2, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ assertTrue(probe2 == probe3);
+ }
+
+ private ReloadingMetadata getMetadata(Object probe) {
+ ReloadingMetadata metaData = new ReloadingMetadata();
+ metaData.setAClass(probe.getClass());
+ metaData.setAnnotated(false);
+ metaData.setSourcePath(RESOURCES);
+ metaData.setFileName("compiler/TestProbe1.java");
+ metaData.setScriptingEngine(ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ metaData.setTaintedOnce(true);
+ metaData.setTainted(true);
+ metaData.setTimestamp(System.currentTimeMillis());
+ return metaData;
+ }
+
+ @Test
+ public void testGetSetWeaver() throws Exception {
+ ScriptingWeaver weaver = new ObjectReloadingWeaver(Probe.class);
+ _strategy.setWeaver(weaver);
+ assertTrue(_strategy.getWeaver() == weaver);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import junit.framework.TestCase;
+import org.apache.myfaces.extensions.scripting.api.CompilationException;
+import org.apache.myfaces.extensions.scripting.api.CompilationResult;
+import org.apache.myfaces.extensions.scripting.sandbox.compiler.Compiler;
+import org.apache.myfaces.extensions.scripting.sandbox.compiler.CompilerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * <p>Base class for test cases that generate Java source files.</p>
+ */
+public abstract class AbstractGeneratorTestCase extends TestCase {
+
+ /**
+ * The temporary test directory where test cases store generated Java source files, etc.
+ */
+ private File testDirectory;
+
+ // ------------------------------------------ Test lifecycle methods
+
+ /**
+ * <p>Creates a temporary directory that can be used to store
+ * generated source files and compiled class files within it.</p>
+ */
+ @Override
+ public void setUp() throws Exception {
+ // Create the test directory within the directory that the class file of this test case is located in
+ testDirectory =
+ new File(getClass().getResource(".").toURI().getPath(), "test");
+ if (!testDirectory.mkdirs() && !testDirectory.exists()) {
+ throw new IllegalStateException(
+ "Couldn't setup the test case for the test case '" + getClass().getName()
+ + "'. It wasn't possible to create a temporary test folder.");
+ }
+ }
+
+ /**
+ * <p>Deletes the temporary directory including all subdirectories
+ * and files within it.</p>
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ deleteDirectory(testDirectory);
+
+ if (!testDirectory.delete()) {
+ System.err.println("Couldn't delete the temporary test directory '" + testDirectory.getAbsolutePath() + "'.");
+ }
+ }
+
+ // ------------------------------------------ Protected methods
+
+ /**
+ * <p>Writes the given file content to the specified file. Use this method in order to
+ * persist dynamically generated Java code. Note that this method assumes that the given
+ * file name is a relative path to the test directory.</p>
+ *
+ * @param fileName the Java source file that you want to save
+ * @param fileContent the content that you want to save, i.e. the Java code
+ * @throws java.io.IOException if an I/O-error occurs
+ */
+ protected void writeFile(String fileName, String[] fileContent) throws IOException {
+ writeFile(new File(testDirectory, fileName), fileContent);
+ }
+
+ /**
+ * <p>Writes the given file content to the specified file. Use this method in order to
+ * persist dynamically generated Java code.</p>
+ *
+ * @param file the Java source file that you want to save
+ * @param fileContent the content that you want to save, i.e. the Java code
+ * @throws IOException if an I/O-error occurs
+ */
+ protected void writeFile(File file, String[] fileContent) throws IOException {
+ if (!file.getParentFile().exists() && !file.getParentFile().mkdirs() && !!file.createNewFile()) {
+ throw new IllegalStateException("Couldn't create the file '" + file.getAbsolutePath() + "'.");
+ }
+
+ PrintWriter writer = new PrintWriter(new FileOutputStream(file));
+ for (String line : fileContent) {
+ writer.println(line);
+ }
+
+ writer.flush();
+ writer.close();
+
+ // Wait a little bit so that the system updates the timestamps
+ try {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ protected CompilationResult compileFile(String sourcePath, String targetPath, String fileName, String[] fileContent)
+ throws IOException, CompilationException {
+ return compileFile(CompilerFactory.createCompiler(),
+ new File(buildAbsolutePath(sourcePath)), new File(buildAbsolutePath(targetPath)), fileName, fileContent);
+ }
+
+ protected CompilationResult compileFile(String sourcePath, String targetPath, String fileName, String[] fileContent, ClassLoader classLoader)
+ throws IOException, CompilationException {
+ return compileFile(CompilerFactory.createCompiler(),
+ new File(buildAbsolutePath(sourcePath)), new File(buildAbsolutePath(targetPath)), fileName, fileContent, classLoader);
+ }
+
+ protected CompilationResult compileFile(Compiler compiler, String sourcePath, String targetPath, String fileName, String[] fileContent)
+ throws IOException, CompilationException {
+ return compileFile(compiler,
+ new File(buildAbsolutePath(sourcePath)), new File(buildAbsolutePath(targetPath)), fileName, fileContent);
+ }
+
+ protected CompilationResult compileFile(Compiler compiler, File sourcePath, File targetPath, String fileName, String[] fileContent)
+ throws IOException, CompilationException {
+ return compileFile(compiler, sourcePath, targetPath, fileName, fileContent, getClass().getClassLoader());
+ }
+
+ protected CompilationResult compileFile(Compiler compiler, File sourcePath, File targetPath, String fileName, String[] fileContent, ClassLoader classLoader)
+ throws IOException, CompilationException {
+ writeFile(new File(sourcePath, fileName), fileContent);
+
+ CompilationResult result = compiler.compile(sourcePath, targetPath, fileName, classLoader);
+ assertFalse("Compilation errors: " + result.getErrors().toString(), result.hasErrors());
+
+ return result;
+ }
+
+ /**
+ * <p>Concatenates the given relative path and the path of the test directory. In doing so
+ * an absolute path will be created that you can use to access the according file.</p>
+ *
+ * @param relativePath the relative path of the file that you want to access
+ * @return the absolute path of the file that you want to access
+ */
+ protected String buildAbsolutePath(String relativePath) {
+ return buildAbsoluteFile(relativePath).getAbsolutePath();
+ }
+
+ /**
+ * <p>Concatenates the given relative path and the path of the test directory. In doing so
+ * an absolute file will be created that you can use to access the according file.</p>
+ *
+ * @param relativePath the relative path of the file that you want to access
+ * @return the absolute File object of the file that you want to access
+ */
+ protected File buildAbsoluteFile(String relativePath) {
+ File file = new File(testDirectory, relativePath);
+ if (!file.exists() && !file.mkdirs()) {
+ throw new IllegalStateException("Couldn't create the directory '" + file.getAbsolutePath() + "'.");
+ }
+
+ return file;
+ }
+
+ // ------------------------------------------ Private utility methods
+
+ /**
+ * <p>Deletes all subdirectories and files within the given directory.</p>
+ *
+ * @param directory the directory you want to delete
+ */
+ public static void deleteDirectory(File directory) {
+ for (File file : directory.listFiles()) {
+ if (file.isDirectory()) {
+ deleteDirectory(file);
+ }
+
+ if (!file.delete()) {
+ System.err.println("Couldn't delete the file or directory '" + file.getAbsolutePath() + "'.");
+ }
+ }
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/Consts.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/Consts.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/Consts.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/Consts.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import static org.apache.myfaces.extensions.scripting.api.ScriptingConst.*;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class Consts {
+ public static final String PROBE2 = "org.apache.myfaces.extensions.scripting.core.classIdentifier.Probe2";
+ public static String JAVA_FILE_ENDING = ".java";
+ public static final int[] ARTIFACT_TYPES = {
+ ARTIFACT_TYPE_UNKNOWN,
+ ARTIFACT_TYPE_MANAGEDBEAN,
+ ARTIFACT_TYPE_MANAGEDPROPERTY,
+ ARTIFACT_TYPE_RENDERKIT,
+ ARTIFACT_TYPE_VIEWHANDLER,
+ ARTIFACT_TYPE_RENDERER,
+ ARTIFACT_TYPE_COMPONENT,
+ ARTIFACT_TYPE_VALIDATOR,
+ ARTIFACT_TYPE_BEHAVIOR,
+ ARTIFACT_TYPE_APPLICATION,
+ ARTIFACT_TYPE_ELCONTEXTLISTENER,
+ ARTIFACT_TYPE_ACTIONLISTENER,
+ ARTIFACT_TYPE_VALUECHANGELISTENER,
+ ARTIFACT_TYPE_CONVERTER,
+ ARTIFACT_TYPE_LIFECYCLE,
+ ARTIFACT_TYPE_PHASELISTENER,
+ ARTIFACT_TYPE_FACESCONTEXT,
+ ARTIFACT_TYPE_NAVIGATIONHANDLER,
+ ARTIFACT_TYPE_RESPONSEWRITER,
+ ARTIFACT_TYPE_RESPONSESTREAM,
+ ARTIFACT_TYPE_RESOURCEHANDLER,
+ ARTIFACT_TYPE_CLIENTBEHAVIORRENDERER,
+ ARTIFACT_TYPE_SYSTEMEVENTLISTENER,
+ };
+ public static final String JAVA_LANG = "java.lang";
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.myfaces.extensions.scripting.api.DynamicCompiler;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContextInitializer;
+import org.apache.myfaces.extensions.scripting.loaders.java.compiler.CompilerFacade;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+/**
+ * Context utils which store the reusable test code
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ContextUtils {
+ /**
+ * A startup routine shared by many tests
+ * to do the basic weaving initialization
+ *
+ * @return the mockup servlet context
+ */
+ public static MockServletContext startupSystem() {
+ MockServletContext context = new MockServletContext();
+ WeavingContextInitializer.initWeavingContext(context);
+ return context;
+ }
+
+ /**
+ * same as the other one but with a web.xml path being possible
+ * @param webXmlPath the path to the web.xml
+ * @return the servlet context
+ */
+ public static MockServletContext startupSystem(String webXmlPath) {
+ MockServletContext context = new MockServletContext(webXmlPath);
+ WeavingContextInitializer.initWeavingContext(context);
+ return context;
+ }
+
+
+ public static File doJavaRecompile(String sourceRoot) throws ClassNotFoundException {
+ DynamicCompiler compiler = new CompilerFacade(false);
+ try {
+ FileUtils.deleteDirectory(WeavingContext.getConfiguration().getCompileTarget());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ WeavingContext.getConfiguration().getCompileTarget().mkdirs();
+ return compiler.compileAllFiles(sourceRoot, "");
+
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/LoggingHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/LoggingHandler.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/LoggingHandler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/LoggingHandler.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * A logging handler which can capture our internal logging output
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class LoggingHandler extends Handler {
+ StringBuilder _output = new StringBuilder();
+
+ @Override
+ public void publish(LogRecord record) {
+ _output.append(record.getMessage());
+ }
+
+ public StringBuilder getOutput() {
+ return _output;
+ }
+
+ public void setOutput(StringBuilder output) {
+ _output = output;
+ }
+
+ @Override
+ public void flush() {
+
+ }
+
+ @Override
+ public void close() throws SecurityException {
+
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.servlet.StartupServletContextPluginChainLoader;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Basic unit testing servlet context mock
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class MockServletContext extends org.apache.myfaces.test.mock.MockServletContext {
+
+ Map<String, Object> _attributes = new HashMap<String, Object>();
+ Map<String, String> _initParameters = new HashMap<String, String>();
+ String _resourceRoot = "../../src/test/resources/webapp";
+
+ public MockServletContext() {
+ setResourceRoot(_resourceRoot);
+ addInitParameter(ScriptingConst.INIT_PARAM_MYFACES_PLUGIN, StartupServletContextPluginChainLoader.class.getName());
+ }
+
+ public MockServletContext(String resourceRoot) {
+ setResourceRoot(resourceRoot);
+ addInitParameter(ScriptingConst.INIT_PARAM_MYFACES_PLUGIN, StartupServletContextPluginChainLoader.class.getName());
+ }
+
+ public void setResourceRoot(String newRoot) {
+ _resourceRoot = newRoot;
+ super.setDocumentRoot(new File(Thread.currentThread().getContextClassLoader().getResource("./").getPath() + _resourceRoot));
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockupScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockupScriptingWeaver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockupScriptingWeaver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockupScriptingWeaver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+
+import java.util.Collection;
+
+/**
+ * A simple mockup which just
+ * remembers its last operation
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class MockupScriptingWeaver implements ScriptingWeaver {
+
+ String _lastOp = null;
+ int _scriptingEngine;
+
+ public MockupScriptingWeaver(int scriptingEngine) {
+ _scriptingEngine = scriptingEngine;
+ }
+
+ public String getLastOp() {
+ return _lastOp;
+ }
+
+ public void setLastOp(String lastOp) {
+ this._lastOp = lastOp;
+ }
+
+ public void appendCustomScriptPath(String scriptPath) {
+ _lastOp = "appendCustomScriptPath";
+ }
+
+ public Object reloadScriptingInstance(Object o, int artifactType) {
+ _lastOp = "reloadScriptingInstance";
+ return o;
+ }
+
+ public Class reloadScriptingClass(Class aclass) {
+ _lastOp = "reloadScriptingInstance";
+ return aclass;
+ }
+
+ public Class loadScriptingClassFromName(String className) {
+ _lastOp = "loadScriptingClassFromName";
+ return null;
+ }
+
+ public int getScriptingEngine() {
+ _lastOp = "getScriptingEngine";
+ return _scriptingEngine;
+ }
+
+ public boolean isDynamic(Class clazz) {
+ _lastOp = "isDynamic";
+ return true;
+ }
+
+ public ScriptingWeaver getWeaverInstance(Class weaverClass) {
+ _lastOp = "getWeaverInstance";
+ return this;
+ }
+
+ public void fullClassScan() {
+ _lastOp = "fullClassScan";
+ }
+
+ public void fullRecompile() {
+ _lastOp = "fullRecompile";
+ }
+
+ public void postStartupActions() {
+ _lastOp = "postStartupActions";
+ }
+
+ public void requestRefresh() {
+ _lastOp = "requestRefresh";
+ }
+
+ public Collection<String> loadPossibleDynamicClasses() {
+ _lastOp = "loadPossibleDynamicClasses";
+ return null;
+ }
+
+ public void scanForAddedClasses() {
+ _lastOp = "scanForAddedClasses";
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ObjectReloadingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ObjectReloadingWeaver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ObjectReloadingWeaver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ObjectReloadingWeaver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.myfaces.extensions.scripting.api.BaseWeaver;
+import org.apache.myfaces.extensions.scripting.api.DynamicCompiler;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+
+/**
+ * This weaver does nothing except instantiating
+ * the object anew at every reload instance request
+ * <p/>
+ * we need it to simulate the object level reloading
+ * at every method call *
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ObjectReloadingWeaver extends BaseWeaver {
+
+ Class _clazz;
+
+ public ObjectReloadingWeaver(Class clazz) {
+ super();
+ _clazz = clazz;
+ }
+
+ @Override
+ public boolean isDynamic(Class clazz) {
+ return true;
+ }
+
+ public void scanForAddedClasses() {
+ }
+
+ @Override
+ protected DynamicCompiler instantiateCompiler() {
+ return null;
+ }
+
+ @Override
+ protected String getLoadingInfo(String file) {
+ return null;
+ }
+
+ @Override
+ public Class reloadScriptingClass(Class aclass) {
+ return aclass;
+ }
+
+ @Override
+ public Object reloadScriptingInstance(Object scriptingInstance, int artifactType) {
+ return ReflectUtil.instantiate(_clazz);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import java.io.File;
+
+/**
+ * Supportive utils to access the source
+ * probes directly
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class PathUtils {
+
+ String _currentPath;
+ String _resourceRoot;
+
+ public PathUtils() {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ //we use a location relative to our current root one to reach the sources
+ //because the test also has to be performed outside of maven
+ //and the ide cannot cope with resource paths for now
+ _currentPath = loader.getResource("./").getPath();
+ _resourceRoot = _currentPath + "../../src/test/resources";
+ }
+
+ /**
+ * Resource root dir getter
+ *
+ * @return the resource root dir (from our source package)
+ */
+ public String getResourceRoot() {
+ return _resourceRoot;
+ }
+
+ public String getResource(String in) {
+ if (in.startsWith("//") || in.startsWith("\\")) {
+ in = in.substring(1);
+ }
+ return _resourceRoot + File.separator + in;
+ }
+
+ /**
+ * Simulates the Unix touch statement on a relative pathed source file
+ *
+ * @param relativeSourceFile the relative path to the resource file
+ */
+ public void touch(String relativeSourceFile) {
+ File resource = new File(getResource(relativeSourceFile));
+ touch(resource);
+ }
+
+ /**
+ * Unix touch on a file object
+ *
+ * @param resource the file object to be touched
+ */
+ public void touch(File resource) {
+ if (resource.exists()) {
+ resource.setLastModified(System.currentTimeMillis());
+ }
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TWeavingContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TWeavingContext.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TWeavingContext.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TWeavingContext.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.myfaces.extensions.scripting.refresh.FileChangedDaemon;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * A helper to bypass an app server startup which otherwise would be enforced
+ */
+
+public class TWeavingContext extends WeavingContext {
+ public static void setWeaverForTesting(Object weaver) {
+ _weaverHolder.set(weaver);
+ //if (FileChangedDaemon.getInstance().getWeavers() == null) {
+ // FileChangedDaemon.getInstance().setWeavers((ScriptingWeaver) weaver);
+ //}
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TestingJavaScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TestingJavaScriptingWeaver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TestingJavaScriptingWeaver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/TestingJavaScriptingWeaver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.support;
+
+import org.apache.myfaces.extensions.scripting.api.DynamicCompiler;
+import org.apache.myfaces.extensions.scripting.loaders.java.JavaScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.loaders.java.compiler.CompilerFacade;
+import org.junit.Ignore;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+@Ignore
+public class TestingJavaScriptingWeaver extends JavaScriptingWeaver {
+ @Override
+ protected DynamicCompiler instantiateCompiler() {
+ /*we enforce javac for testing purposes*/
+ return new CompilerFacade(false);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/FileUtilsTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/FileUtilsTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/FileUtilsTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.utilsTests;
+
+import org.apache.myfaces.extensions.scripting.core.support.PathUtils;
+import org.apache.myfaces.extensions.scripting.core.util.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static junit.framework.Assert.fail;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test cases for our FileUtils
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class FileUtilsTest {
+ PathUtils pathUtils = new PathUtils();
+
+ @Before
+ public void init() {
+
+ }
+
+ @Test
+ public void testForRegexp() {
+ String fileSep = FileUtils.getFileSeparatorForRegex();
+ assertTrue("must be double backslash instead of single one", (File.separator.equals("\\")) ? fileSep.equals("\\\\") : fileSep.equals(File.separator));
+ }
+
+ @Test
+ public void testGetFileSeparator() {
+ String fileSeparator = FileUtils.getFileSeparator();
+ assertTrue(fileSeparator.equals(File.separator));
+ }
+
+ @Test
+ public void testGetTempDir() {
+ File tempDir = FileUtils.getTempDir();
+ assertTrue(tempDir != null);
+ assertTrue(tempDir.exists());
+ }
+
+ @Test
+ public void testFileStrategy() {
+ List<File> sourceFiles = FileUtils.fetchSourceFiles(new File(pathUtils.getResource("compiler/")), ".java");
+ assertTrue("wildcarding is needed", sourceFiles.size() == 0);
+
+ sourceFiles = FileUtils.fetchSourceFiles(new File(pathUtils.getResource("compiler/")), "java");
+ assertTrue("wildcarding is needed", sourceFiles.size() == 0);
+
+
+ sourceFiles = FileUtils.fetchSourceFiles(new File(pathUtils.getResource("compiler/")), "*.java");
+ assertTrue("source files must have been found", sourceFiles.size() > 2);
+ //check also for subdirs
+ for(File sourceFile: sourceFiles) {
+ if(sourceFile.getAbsolutePath().contains("myPackage")) {
+ return;
+ }
+ }
+ fail("source file must also be in myPackage");
+ }
+
+ @Test
+ public void testDirStrategy() {
+ StringBuilder result = FileUtils.fetchSourcePaths(new File(pathUtils.getResource("compilerx/")), "");
+ assertTrue("invalid dir should result in empty results", result.toString().trim().length() == 0);
+
+ result = FileUtils.fetchSourcePaths(new File(pathUtils.getResource("compiler/")), "");
+ assertTrue("myPackage should be found", result.toString().trim().contains("myPackage"));
+
+
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/ReflectUtilTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/ReflectUtilTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/ReflectUtilTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/utilsTests/ReflectUtilTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.core.utilsTests;
+
+import org.apache.myfaces.extensions.scripting.core.util.Cast;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+import org.apache.myfaces.extensions.scripting.core.util.Null;
+import org.apache.myfaces.extensions.scripting.core.probes.Probe;
+import org.apache.myfaces.extensions.scripting.core.util.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import static org.junit.Assert.*;
+
+/**
+ * Testcase for our reflect utils
+ * which we rely heavily upon
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ReflectUtilTest {
+ private static final String HELLO_WORLD = "Hello World";
+ private static final String JAVA_LANG_STRING = "java.lang.String";
+ private static final String MSG_INSTANTIATED = "String must be instantiated";
+ private static final String MSG_PROBE_INSTANTIATED = "Probe must be instantiated";
+ private static final String MSG_INIT_FAIL = "init failed expected";
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testInstantiate() throws Exception {
+ String retVal = (String) ReflectUtil.instantiate(JAVA_LANG_STRING);
+ assertTrue(MSG_INSTANTIATED, retVal != null);
+
+ retVal = (String) ReflectUtil.instantiate(JAVA_LANG_STRING, HELLO_WORLD);
+ assertTrue(MSG_INSTANTIATED, retVal != null && retVal.equals(HELLO_WORLD));
+
+ Object myHello = HELLO_WORLD;
+ Object probe = ReflectUtil.instantiate(Probe.class, new Cast(String.class, myHello), HELLO_WORLD);
+ assertTrue(MSG_PROBE_INSTANTIATED, probe != null);
+
+ try {
+ ReflectUtil.instantiate(Probe.class, new Cast(Integer.class, myHello), HELLO_WORLD);
+ fail();
+ } catch (RuntimeException ex) {
+ assertTrue(MSG_INIT_FAIL, true);
+ }
+ probe = ReflectUtil.instantiate(Probe.class, new Null(String.class), new Null(String.class));
+ assertTrue(MSG_PROBE_INSTANTIATED, probe != null);
+
+ try {
+ ReflectUtil.instantiate(Probe.class, new Null(Integer.class), new Null(String.class));
+ fail();
+ } catch (RuntimeException ex) {
+ assertTrue(MSG_INIT_FAIL, true);
+ }
+
+ //TODO (1.1) test fails, but is not used so we can live with it
+ //probe = ReflectUtil.instantiate(Probe2.class,new Array(String.class, HELLO_WORLD, HELLO_WORLD));
+ //assertTrue("Probe must be instantiated", probe != null);
+ }
+
+ @Test
+ public void testNewObject() throws Exception {
+ String retVal = (String) ReflectUtil.newObject(String.class);
+ assertTrue(MSG_INSTANTIATED, retVal != null);
+ }
+
+ @Test
+ public void testExecuteStaticMethod() throws Exception {
+ Boolean retVal = (Boolean) ReflectUtil.executeStaticMethod(Boolean.class, "valueOf", "true");
+ assertTrue("retval must be true", retVal);
+
+ try {
+ ReflectUtil.executeStaticMethod(Boolean.class, "xx_valueOf", "true");
+ fail();
+ } catch (RuntimeException ex) {
+ assertTrue("Exception must be thrown", true);
+ }
+
+ }
+
+ @Test
+ public void testFastExecuteStaticMethod() throws Exception {
+ Boolean retVal = (Boolean) ReflectUtil.fastExecuteStaticMethod(Boolean.class, "valueOf", "true");
+ assertTrue("retval must be true", retVal);
+ }
+
+ @Test
+ public void testGetAllMethods() throws Exception {
+ Collection<Method> retVal = ReflectUtil.getAllMethods(Boolean.class, "valueOf", 1);
+ assertTrue(retVal.size() == 2);/*String and boolean*/
+ retVal = ReflectUtil.getAllMethods(Object.class, "toString", 0);
+ assertTrue(retVal.size() == 1);/*String and boolean*/
+ }
+
+ @Test
+ public void testExecuteMethod() throws Exception {
+
+ Boolean probe = true;
+ Boolean retVal = (Boolean) ReflectUtil.executeMethod(probe, "valueOf", "true");
+ assertTrue(retVal);
+ String sRetVal = (String) ReflectUtil.executeMethod(probe, "toString");
+ assertTrue(sRetVal.equals("true"));
+
+ Object hashVal = ReflectUtil.executeMethod(new Probe(), "hashCode");
+ assertTrue(hashVal != null);
+
+ try {
+ ReflectUtil.executeMethod(new Probe(), "xx_hashCode");
+ fail();
+ } catch (RuntimeException ex) {
+ assertTrue("calling must faile with an RE", true);
+ }
+ }
+
+ @Test
+ public void testFastExecuteMethod() throws Exception {
+
+ Boolean probe = true;
+ Boolean retVal = (Boolean) ReflectUtil.fastExecuteMethod(probe, "valueOf", "true");
+ assertTrue(retVal);
+ String sRetVal = (String) ReflectUtil.fastExecuteMethod(probe, "toString");
+ assertTrue(sRetVal.equals("true"));
+
+ Object hashVal = ReflectUtil.fastExecuteMethod(new Probe(), "hashCode");
+ assertTrue(hashVal != null);
+
+ }
+
+ @Test
+ public void testCast() {
+ assertTrue("Cast testing", ReflectUtil.cast(String.class, HELLO_WORLD) instanceof Cast);
+ assertTrue("Cast testing", ReflectUtil.nullCast(String.class) instanceof Null);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/jsf/RefreshPhaseListenerTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/jsf/RefreshPhaseListenerTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/jsf/RefreshPhaseListenerTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/jsf/RefreshPhaseListenerTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.jsf;
+
+import org.apache.myfaces.extensions.scripting.jsf.RefreshPhaseListener;
+import org.apache.myfaces.extensions.scripting.core.support.ContextUtils;
+import org.apache.myfaces.extensions.scripting.core.support.MockServletContext;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContextInitializer;
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RefreshPhaseListenerTest extends AbstractJsfTestCase {
+ MockServletContext context;
+
+ boolean executed = false;
+ Runnable runner;
+
+ RefreshPhaseListener probe;
+
+
+ public RefreshPhaseListenerTest() {
+ super(RefreshPhaseListenerTest.class.getName());
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ probe = new RefreshPhaseListener();
+ context = ContextUtils.startupSystem();
+
+ runner = new Runnable() {
+ public void run() {
+ executed = true;
+ }
+ };
+ }
+
+ public void testCalling1() throws Exception {
+ RefreshPhaseListener.applyAction(runner);
+
+ assertTrue(probe.getPhaseId() == PhaseId.ANY_PHASE);
+ probe.beforePhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, new MockLifecycle()));
+ assertTrue(executed);
+ executed = false;
+ probe.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, new MockLifecycle()));
+ assertFalse(executed);
+
+ }
+
+ public void testAfterPhase() {
+ probe.afterPhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, new MockLifecycle()));
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.loaders.java;
+
+import org.apache.myfaces.extensions.scripting.loaders.java.RecompiledClassLoader;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.support.ContextUtils;
+import org.apache.myfaces.extensions.scripting.core.support.PathUtils;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.security.AccessController;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RecompiledClassLoaderTest {
+
+ private static final PathUtils _pathUtils = new PathUtils();
+ private static final String RESOURCES = _pathUtils.getResource(".");
+ Logger logger = Logger.getLogger(RecompiledClassLoaderTest.class.getName());
+
+ ServletContext _context;
+ RecompiledClassLoader _loader;
+ File _root = new File(RESOURCES + File.separator + "compiler/");
+
+ @Before
+ public void init() throws Exception {
+ _context = ContextUtils.startupSystem();
+ WeavingContext.getConfiguration().getSourceDirs(ScriptingConst.ENGINE_TYPE_JSF_JAVA).clear();
+ WeavingContext.getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_JAVA, _root.getAbsolutePath());
+
+ _loader = new RecompiledClassLoader(Thread.currentThread().getContextClassLoader(), ScriptingConst.ENGINE_TYPE_JSF_JAVA, ".java", false);
+ ContextUtils.doJavaRecompile(_root.getAbsolutePath());
+
+ }
+
+ @Test
+ public void testInit2() {
+ new RecompiledClassLoader();
+ }
+
+ @Test
+ public void testLoadClass() throws Exception {
+
+ //the simple reloading case is handled by the reloading strategy testcase
+ //so this test is mostly just to test the rest of the class
+
+ Class clazz1 = _loader.loadClass("java.lang.String");
+ Class clazz2 = _loader.loadClass("java.lang.String");
+ assertTrue(clazz1.hashCode() == clazz2.hashCode());
+
+ }
+
+ @Test
+ public void testGetSetSourceRoot() throws Exception {
+ _loader.setSourceRoot("booga");
+ assertTrue(_loader.getSourceRoot().equals("booga"));
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.extensions.scripting.loaders.java;
+
+import org.apache.myfaces.extensions.scripting.loaders.java.ScannerClassloader;
+import org.apache.myfaces.extensions.scripting.loaders.java.RecompiledClassLoader;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.support.ContextUtils;
+import org.apache.myfaces.extensions.scripting.core.support.PathUtils;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ScannerClassloaderTest {
+ private static final PathUtils _pathUtils = new PathUtils();
+ private static final String RESOURCES = _pathUtils.getResource(".");
+
+ ServletContext _context;
+ ScannerClassloader _loader;
+ File _root = new File(RESOURCES + File.separator + "compiler/");
+
+ @Before
+ public void init() throws Exception {
+ _context = ContextUtils.startupSystem();
+ WeavingContext.getConfiguration().getSourceDirs(ScriptingConst.ENGINE_TYPE_JSF_JAVA).clear();
+ WeavingContext.getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_JAVA, _root.getAbsolutePath());
+
+ _loader = new ScannerClassloader(Thread.currentThread().getContextClassLoader(), ScriptingConst.ENGINE_TYPE_JSF_JAVA, ".java", WeavingContext.getConfiguration().getCompileTarget());
+ ContextUtils.doJavaRecompile(_root.getAbsolutePath());
+ }
+
+ @Test
+ public void testInit2() {
+ new RecompiledClassLoader();
+ }
+
+ @Test
+ public void testLoadClass() throws Exception {
+ Class clazz1 = _loader.loadClass("compiler.TestProbe1");
+ Class clazz2 = _loader.loadClass("compiler.TestProbe1");
+ assertTrue(clazz1 == clazz2);
+ }
+
+
+}