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 2012/03/12 13:55:50 UTC
svn commit: r1299656 - in
/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite:
./ org/ org/apache/ org/apache/myfaces/ org/apache/myfaces/extensions/
org/apache/myfaces/extensions/scripting/ org/apache/myfaces/e...
Author: werpu
Date: Mon Mar 12 12:55:50 2012
New Revision: 1299656
URL: http://svn.apache.org/viewvc?rev=1299656&view=rev
Log:
EXTSCRIPT-154: adding testcases
Added:
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/InitialFullScanTest.java
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/EngineFactoryTest.java
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/GroovyCompilerTest.java
myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/JavaCompilerTest.java
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/InitialFullScanTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/InitialFullScanTest.java?rev=1299656&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/InitialFullScanTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/context/InitialFullScanTest.java Mon Mar 12 12:55:50 2012
@@ -0,0 +1,87 @@
+/*
+ * 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 rewrite.org.apache.myfaces.extensions.scripting.scanningcore.context;
+
+import org.junit.Before;
+import org.junit.Test;
+import rewrite.org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.FactoryEngines;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class InitialFullScanTest
+{
+ FactoryEngines factory = null;
+
+
+ @Before
+ public void init() throws Exception {
+ factory = FactoryEngines.getInstance();
+ factory.init();
+ }
+
+ @Test
+ public void testInitialFullScan() {
+ try
+ {
+ ScriptingEngine javaEngine = factory.getEngine(ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ ScriptingEngine groovyEngine = factory.getEngine(ScriptingConst.ENGINE_TYPE_JSF_GROOVY);
+ ClassLoader loader = this.getClass().getClassLoader();
+ String canonicalPackageName = this.getClass().getPackage().getName().replaceAll("\\.", File.separator);
+
+ Enumeration<URL> enumeration = loader.getResources(canonicalPackageName);
+ javaEngine.getSourcePaths().clear();
+ groovyEngine.getSourcePaths().clear();
+ //TODO source not binary dirs
+ while(enumeration.hasMoreElements()) {
+ URL currentDir = enumeration.nextElement();
+ String currentDirStr = currentDir.getFile();
+ currentDirStr = currentDirStr.replaceAll("target\\"+File.separatorChar+"test\\-classes",
+ "src/main/java");
+ currentDirStr = currentDirStr.replaceAll("target\\"+File.separatorChar+"classes",
+ "src/main/java");
+ javaEngine.getSourcePaths().add(currentDirStr);
+ groovyEngine.getSourcePaths().add(currentDirStr);
+ }
+ //we now scan for the files
+ WeavingContext.getInstance().initialFullScan();
+
+ }
+ catch (IOException e)
+ {
+ fail(e.getMessage());
+ }
+
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/EngineFactoryTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/EngineFactoryTest.java?rev=1299656&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/EngineFactoryTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/EngineFactoryTest.java Mon Mar 12 12:55:50 2012
@@ -0,0 +1,53 @@
+/*
+ * 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 rewrite.org.apache.myfaces.extensions.scripting.scanningcore.engine;
+
+import org.junit.Before;
+import org.junit.Test;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.FactoryEngines;
+import rewrite.org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ * Testcase for the engine factory to test for a correct
+ */
+
+public class EngineFactoryTest
+{
+ FactoryEngines factory = null;
+
+
+ @Before
+ public void init() throws Exception {
+ factory = FactoryEngines.getInstance();
+ factory.init();
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue("Java Engine found",factory.getEngine(ScriptingConst.ENGINE_TYPE_JSF_JAVA) != null);
+ assertTrue("Groovy Engine found",factory.getEngine(ScriptingConst.ENGINE_TYPE_JSF_GROOVY) != null);
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/GroovyCompilerTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/GroovyCompilerTest.java?rev=1299656&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/GroovyCompilerTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/GroovyCompilerTest.java Mon Mar 12 12:55:50 2012
@@ -0,0 +1,140 @@
+/*
+ * 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 rewrite.org.apache.myfaces.extensions.scripting.scanningcore.engine.compiler;
+
+import org.apache.commons.io.FilenameUtils;
+import org.junit.Test;
+import rewrite.org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.Configuration;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.FactoryEngines;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.compiler.GroovyCompiler;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class GroovyCompilerTest
+{
+ private static final String PROBE1 = "../../src/test/resources/compiler/TestProbe1Groovy.groovy";
+ private static final String PROBE2 = "../../src/test/resources/compiler/TestProbe2Groovy.groovy";
+ private static final String RESOURCES = "../../src/test/resources/";
+
+ File probe1;
+ File probe2;
+ File root;
+
+ GroovyCompiler compiler = new GroovyCompiler();
+ private static final String RESULT_HAS_NO_ERRORS = "result has no errors";
+ private static final String TARGET_DIR_EXISTS = "targetDir exists files are compiled into the targetDir";
+ private static final String CLASSFILE1_IS_COMPILED = "Classfile1 is compiled into the targetDir";
+ private static final String CLASSFILE1_IS_COMPILED1 = "Classfile1 is compiled into the target";
+ private static final String CLASSFILE2_IS_COMPILED = "Classfile2 is compiled into the target";
+
+ public GroovyCompilerTest()
+ {
+ try
+ {
+ FactoryEngines.getInstance().init();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ //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
+ 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.getInstance().setConfiguration(new Configuration());
+ WeavingContext.getInstance().getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_GROOVY, root.getAbsolutePath());
+ }
+
+ @Test
+ public void testFullCompileWhitelist()
+ {
+ File targetDir = null;
+
+ File target = WeavingContext.getInstance().getConfiguration().getCompileTarget();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ target.mkdirs();
+ target.deleteOnExit();
+
+ WeavingContext.getInstance().getConfiguration().addWhitelistPackage("compiler.myPackage");
+
+ CompilationResult result = compiler.compile(root, target, loader);
+
+ assertTrue(RESULT_HAS_NO_ERRORS, !result.hasErrors());
+
+ assertTrue("target exists files are compiled into the target", target != null);
+ File classFile1 = new File(target.getAbsolutePath() + "/compiler/TestProbe1Groovy.class");
+ File classFile2 = new File(target.getAbsolutePath() + "/compiler/TestProbe2Groovy.class");
+ File classFile3 = new File(target.getAbsolutePath() + "/compiler/myPackage/WhiteListedProbeGroovy.class");
+
+ assertTrue(CLASSFILE1_IS_COMPILED1, !classFile1.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, !classFile2.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, classFile3.exists());
+
+ }
+
+ @Test
+ public void testFullCompile()
+ {
+ File targetDir = null;
+
+ File target = WeavingContext.getInstance().getConfiguration().getCompileTarget();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ target.mkdirs();
+ target.deleteOnExit();
+
+ CompilationResult result = compiler.compile(root, target, loader);
+
+ assertTrue(RESULT_HAS_NO_ERRORS, !result.hasErrors());
+
+ assertTrue(TARGET_DIR_EXISTS, target != null);
+ File classFile1 = new File(target.getAbsolutePath() + "/compiler/TestProbe1Groovy.class");
+ File classFile2 = new File(target.getAbsolutePath() + "/compiler/TestProbe2Groovy.class");
+
+ assertTrue(CLASSFILE1_IS_COMPILED1, classFile1.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, classFile2.exists());
+
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/JavaCompilerTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/JavaCompilerTest.java?rev=1299656&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/JavaCompilerTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/engine/compiler/JavaCompilerTest.java Mon Mar 12 12:55:50 2012
@@ -0,0 +1,160 @@
+/*
+ * 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 rewrite.org.apache.myfaces.extensions.scripting.scanningcore.engine.compiler;
+
+import org.apache.commons.io.FilenameUtils;
+import org.junit.Test;
+import rewrite.org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.FileUtils;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.Configuration;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.FactoryEngines;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.api.CompilationException;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+import rewrite.org.apache.myfaces.extensions.scripting.core.engine.compiler.JSR199Compiler;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class JavaCompilerTest
+{
+ private static final String PROBE1 = "../../src/test/resources/compiler/TestProbe1.java";
+ private static final String PROBE2 = "../../src/test/resources/compiler/TestProbe2.java";
+ private static final String RESOURCES = "../../src/test/resources/";
+
+ File probe1;
+ File probe2;
+ File root;
+
+ JSR199Compiler compiler = new JSR199Compiler();
+ private static final String RESULT_HAS_NO_ERRORS = "result has no errors";
+ private static final String TARGET_DIR_EXISTS = "targetDir exists files are compiled into the targetDir";
+ private static final String CLASSFILE1_IS_COMPILED = "Classfile1 is compiled into the targetDir";
+ private static final String CLASSFILE1_IS_COMPILED1 = "Classfile1 is compiled into the target";
+ private static final String CLASSFILE2_IS_COMPILED = "Classfile2 is compiled into the target";
+
+ public JavaCompilerTest()
+ {
+ try
+ {
+ FactoryEngines.getInstance().init();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ //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
+ 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.getInstance().setConfiguration(new Configuration());
+ WeavingContext.getInstance().getConfiguration().addSourceDir(ScriptingConst.ENGINE_TYPE_JSF_JAVA,
+ root.getAbsolutePath());
+ }
+
+ @Test
+ public void testFullCompileWhitelist()
+ {
+ File targetDir = null;
+
+ File target = WeavingContext.getInstance().getConfiguration().getCompileTarget();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ target.mkdirs();
+ target.deleteOnExit();
+
+ WeavingContext.getInstance().getConfiguration().addWhitelistPackage("compiler.myPackage");
+
+ CompilationResult result = null;
+ try
+ {
+ result = compiler.compile(root, target, loader);
+ }
+ catch (CompilationException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ assertTrue(RESULT_HAS_NO_ERRORS, !result.hasErrors());
+
+ assertTrue("target exists files are compiled into the target", target != null);
+ File classFile1 = new File(target.getAbsolutePath() + "/compiler/TestProbe1.class");
+ File classFile2 = new File(target.getAbsolutePath() + "/compiler/TestProbe2.class");
+ File classFile3 = new File(target.getAbsolutePath() + "/compiler/myPackage/WhiteListedProbe.class");
+
+ assertTrue(CLASSFILE1_IS_COMPILED1, !classFile1.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, !classFile2.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, classFile3.exists());
+
+ }
+
+ @Test
+ public void testFullCompile()
+ {
+ File targetDir = null;
+
+ File target = FileUtils.getTempDir();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ target.mkdirs();
+ target.deleteOnExit();
+
+ CompilationResult result = null;
+ try
+ {
+ result = compiler.compile(root, target, loader);
+ }
+ catch (CompilationException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ assertTrue(RESULT_HAS_NO_ERRORS, !result.hasErrors());
+
+ assertTrue(TARGET_DIR_EXISTS, target != null);
+ File classFile1 = new File(target.getAbsolutePath() + "/compiler/TestProbe1.class");
+ File classFile2 = new File(target.getAbsolutePath() + "/compiler/TestProbe2.class");
+
+ assertTrue(CLASSFILE1_IS_COMPILED1, classFile1.exists());
+ assertTrue(CLASSFILE2_IS_COMPILED, classFile2.exists());
+
+ }
+
+}
+