Author: alexsmirnov
Date: 2010-05-25 18:05:22 -0400 (Tue, 25 May 2010)
New Revision: 17239
Added:
root/cdk/trunk/plugins/generator/.checkstyle
Removed:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/DependenciesGraph.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AnnotationProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ConverterProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ValidatorProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/BehaviorClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/TagHandlerClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/NameTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/XhtmlAttributesParsingTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/util/ComparatorUtilsTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbUnmarshalTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Child.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Root.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/package-info.java
Log:
Fix CheckStyle violations in tests
Added: root/cdk/trunk/plugins/generator/.checkstyle
===================================================================
--- root/cdk/trunk/plugins/generator/.checkstyle (rev 0)
+++ root/cdk/trunk/plugins/generator/.checkstyle 2010-05-25 22:05:22 UTC (rev 17239)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fileset-config file-format-version="1.2.0"
simple-config="false">
+ <fileset name="JavaSource" enabled="true"
check-config-name="RichFaces" local="false">
+ <file-match-pattern match-pattern="src/main/java"
include-pattern="true"/>
+ </fileset>
+ <fileset name="test sources" enabled="true"
check-config-name="RichFaces" local="false">
+ <file-match-pattern match-pattern="src/test/java"
include-pattern="true"/>
+ </fileset>
+ <filter name="NonSrcDirs" enabled="true"/>
+</fileset-config>
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -46,8 +46,9 @@
super();
this.log = log;
- // TODO set proper template loader.
+ // load templates from this project.
setClassForTemplateLoading(this.getClass(), TEMPLATES);
+ setTemplateUpdateDelay(10000);// Forever...
setObjectWrapper(wrapper);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,13 +23,6 @@
package org.richfaces.cdk;
-import com.google.common.collect.ImmutableList;
-import com.google.inject.Binder;
-import com.google.inject.Module;
-import org.junit.After;
-import org.junit.Before;
-import org.richfaces.cdk.annotations.JsfComponent;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -41,6 +34,14 @@
import java.util.Locale;
import java.util.logging.LogManager;
+import org.junit.After;
+import org.junit.Before;
+import org.richfaces.cdk.annotations.JsfComponent;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+
/**
* <p class="changed_added_4_0">
* </p>
@@ -50,9 +51,15 @@
*/
public abstract class CdkTestBase implements Module {
+ protected File tempDir;
+
protected Iterable<File> testSourceDirectory;
- protected File tempDir;
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Locale.class).toInstance(Locale.getDefault());
+ binder.bind(Charset.class).toInstance(Charset.defaultCharset());
+ }
@Before
public void setUpSourceDirectory() throws Exception {
@@ -84,10 +91,13 @@
testSourceDirectory = null;
}
- @Override
- public void configure(Binder binder) {
- binder.bind(Locale.class).toInstance(Locale.getDefault());
- binder.bind(Charset.class).toInstance(Charset.defaultCharset());
+ protected CdkClassLoader createClassLoader() {
+ try {
+ return new
CdkClassLoader(ImmutableList.of(getLibraryFile("test.source.properties"),
+ getLibraryFile(JsfComponent.class)), null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
protected File getJavaFile(String name) throws URISyntaxException {
@@ -99,6 +109,10 @@
return classFile;
}
+ protected File getLibraryFile(Class<?> clazz) throws Exception {
+ return getLibraryFile(clazz.getName().replaceAll("\\.", "/")
+ ".class");
+ }
+
protected File getLibraryFile(String resource) throws Exception {
URL url = this.getClass().getClassLoader().getResource(resource);
if (null != url) {
@@ -120,17 +134,4 @@
throw new Exception("Resource does not exists " + resource);
}
}
-
- protected File getLibraryFile(Class<?> clazz) throws Exception {
- return getLibraryFile(clazz.getName().replaceAll("\\.", "/")
+ ".class");
- }
-
- protected CdkClassLoader createClassLoader() {
- try {
- return new
CdkClassLoader(ImmutableList.of(getLibraryFile("test.source.properties"),
- getLibraryFile(JsfComponent.class)), null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
}
Deleted:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/DependenciesGraph.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/DependenciesGraph.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/DependenciesGraph.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -1,46 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk;
-
-/**
- * <p class="changed_added_4_0">
- * This application should create GraphVis .dot file with Cdk dependencies
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class DependenciesGraph {
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param args
- */
- public static void main(String[] args) {
-
- }
-
-}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -1,40 +1,57 @@
-
/**
*
*/
package org.richfaces.cdk;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.apache.maven.model.FileSet;
-import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
+import org.junit.Ignore;
import org.junit.Test;
-import org.junit.Ignore;
-import org.richfaces.cdk.apt.AptBuilder;
-import java.io.File;
-import java.util.*;
-import java.net.MalformedURLException;
-
/**
* @author asmirnov
- *
+ *
*/
public class LibraryBuilderTest extends CdkTestBase {
- private static final String PROJECT_BASE =
"E:\\_richfaces\\svn\\richfaces_root\\ui\\components\\core\\";
- private static final String[] JAVA_INCLUDES = new String[]{"**/*.java"};
+ private static final String[] JAVA_INCLUDES = new String[] { "**/*.java"
};
private static final String MAIN_CONFIG = "src/main/config";
private static final String MAIN_TEMPLATES = "src/main/templates";
+ private static final String PROJECT_BASE =
"E:\\_richfaces\\svn\\richfaces_root\\ui\\components\\core\\";
private static final String[] STRINGS_ARRAY = new String[0];
private static final String XML_INCLUDES = "**/*.xml";
protected File outputJavaDirectory = new File(PROJECT_BASE +
"target/generated-sources/main/java");
protected File outputResourcesDirectory = new File(PROJECT_BASE +
"target/generated-sources/main/resources");
protected File outputTestDirectory = new File(PROJECT_BASE +
"target/generated-sources/test/java");
+
protected File outputTestResourcesDirectory = new File(PROJECT_BASE +
"target/generated-sources/test/resources");
+ /**
+ * <p class="changed_added_4_0">
+ * This utility method sets output directory for particular type. I such directory
does not exist, it is created.
+ * </p>
+ *
+ * @param generator
+ * @param directory
+ * @param type
+ */
+ private static void setOutput(Generator generator, File directory, Outputs type) {
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+
+ generator.addOutputFolder(type, directory);
+ }
+
@Test
@Ignore
public void createInstance() throws Exception {
@@ -53,13 +70,11 @@
}
}
-
generator.addSources(Sources.JAVA_SOURCES, findJavaFiles(), folders);
// TODO - detect templates and configs directories.
generator.addSources(Sources.RENDERER_TEMPLATES, findTemplateFiles(), null);
generator.addSources(Sources.FACES_CONFIGS, findFacesConfigFiles(), null);
-
// Setup output folders.
setOutput(generator, outputJavaDirectory, Outputs.JAVA_CLASSES);
setOutput(generator, outputResourcesDirectory, Outputs.RESOURCES);
@@ -67,7 +82,7 @@
setOutput(generator, outputTestResourcesDirectory, Outputs.TEST_RESOURCES);
// configure CDK workers.
-// setupPlugins(generator);
+ // setupPlugins(generator);
try {
@@ -80,62 +95,84 @@
}
}
+ /**
+ * <p class="changed_added_4_0">
+ * This method checks library configuration and sets default values if necessary.
+ * </p>
+ */
+ protected void checkLibraryConfig() {
+
+ // TODO Auto-generated method stub
+ }
+
+ @Override
protected CdkClassLoader createClassLoader() {
return new CdkClassLoader(this.getClass().getClassLoader());
}
/**
- * <p class="changed_added_4_0">This utility method sets output
directory for particular type.
- * I such directory does not exist, it is created.</p>
- *
- * @param generator
- * @param directory
- * @param type
+ * Skan Array of filesets for selected resources.
+ *
+ * @param filesets
+ * @return
+ * @throws MojoExecutionException
*/
- private static void setOutput(Generator generator, File directory, Outputs type) {
- if (!directory.exists()) {
- directory.mkdirs();
+ @SuppressWarnings("unchecked")
+ protected Collection<File> doScan(FileSet[] filesets) throws
MojoExecutionException {
+ List<File> files = new ArrayList<File>();
+
+ if (null != filesets) {
+ for (FileSet fileSet : filesets) {
+ String[] includes = (String[])
fileSet.getIncludes().toArray(STRINGS_ARRAY);
+ String[] excludes = (String[])
fileSet.getExcludes().toArray(STRINGS_ARRAY);
+ File fileSetDirectory = resolveRelativePath(new
File(fileSet.getDirectory()));
+ String[] scan = doScan(includes, excludes, fileSetDirectory);
+
+ for (String filename : scan) {
+ files.add(resolveRelativePath(new File(fileSetDirectory,
filename)));
+ }
+ }
}
- generator.addOutputFolder(type, directory);
+ return files;
}
- /**
- * <p class="changed_added_4_0">This method checks library
configuration and sets default values if necessary.</p>
- */
- protected void checkLibraryConfig() {
+ protected String[] doScan(String[] includes, String[] excludes, File rootFolder)
throws MojoExecutionException {
+ try {
+ DirectoryScanner directoryScanner = new DirectoryScanner();
- // TODO Auto-generated method stub
- }
+ directoryScanner.setFollowSymlinks(true);
+ directoryScanner.setBasedir(rootFolder);
+ directoryScanner.setExcludes(excludes);
+ directoryScanner.setIncludes(includes);
+ directoryScanner.addDefaultExcludes();
+ directoryScanner.scan();
- private File resolveRelativePath(File file) {
- File result = file;
- if (!result.isAbsolute()) {
- result = new File(PROJECT_BASE, result.getPath());
+ return directoryScanner.getIncludedFiles();
+ } catch (IllegalStateException e) {
+ throw new MojoExecutionException("Error scanning source root:
\'" + rootFolder + "\'", e);
}
-
- return result;
}
- private Iterable<File> findTemplateFiles() throws MojoExecutionException {
- FileSet[] templates = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_TEMPLATES));
+ private Iterable<File> findFacesConfigFiles() throws MojoExecutionException {
+ FileSet[] facesConfigs = null;
+ File defaultDirectory = resolveRelativePath(new File(MAIN_CONFIG));
if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
FileSet fileSet = new FileSet();
- fileSet.setDirectory(MAIN_TEMPLATES);
+ fileSet.setDirectory(MAIN_CONFIG);
fileSet.addInclude(XML_INCLUDES);
- templates = new FileSet[]{fileSet};
+ facesConfigs = new FileSet[] { fileSet };
}
- return doScan(templates);
+ return doScan(facesConfigs);
}
private Iterable<File> findJavaFiles() throws MojoExecutionException {
Set<File> javaSources = new HashSet<File>();
String[] includes = JAVA_INCLUDES;
- String compileSourceRoots[] = new String[]{PROJECT_BASE +
"\\src\\main\\java"};
+ String[] compileSourceRoots = new String[] { PROJECT_BASE +
"\\src\\main\\java" };
for (String compileRoot : compileSourceRoots) {
File rootFolder = new File(compileRoot);
String[] sources = doScan(includes, null, rootFolder);
@@ -148,62 +185,27 @@
return javaSources;
}
- private Iterable<File> findFacesConfigFiles() throws MojoExecutionException {
- FileSet[] facesConfigs = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_CONFIG));
+ private Iterable<File> findTemplateFiles() throws MojoExecutionException {
+ FileSet[] templates = null;
+ File defaultDirectory = resolveRelativePath(new File(MAIN_TEMPLATES));
if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
FileSet fileSet = new FileSet();
- fileSet.setDirectory(MAIN_CONFIG);
+ fileSet.setDirectory(MAIN_TEMPLATES);
fileSet.addInclude(XML_INCLUDES);
- facesConfigs = new FileSet[]{fileSet};
+ templates = new FileSet[] { fileSet };
}
- return doScan(facesConfigs);
+ return doScan(templates);
}
- protected String[] doScan(String[] includes, String[] excludes, File rootFolder)
throws MojoExecutionException {
- try {
- DirectoryScanner directoryScanner = new DirectoryScanner();
-
- directoryScanner.setFollowSymlinks(true);
- directoryScanner.setBasedir(rootFolder);
- directoryScanner.setExcludes(excludes);
- directoryScanner.setIncludes(includes);
- directoryScanner.addDefaultExcludes();
- directoryScanner.scan();
-
- return directoryScanner.getIncludedFiles();
- } catch (IllegalStateException e) {
- throw new MojoExecutionException("Error scanning source root:
\'" + rootFolder + "\'", e);
+ private File resolveRelativePath(File file) {
+ File result = file;
+ if (!result.isAbsolute()) {
+ result = new File(PROJECT_BASE, result.getPath());
}
- }
- /**
- * Skan Array of filesets for selected resources.
- *
- * @param filesets
- * @return
- * @throws MojoExecutionException
- */
- @SuppressWarnings("unchecked")
- protected Collection<File> doScan(FileSet[] filesets) throws
MojoExecutionException {
- List<File> files = new ArrayList<File>();
-
- if (null != filesets) {
- for (FileSet fileSet : filesets) {
- String[] includes = (String[])
fileSet.getIncludes().toArray(STRINGS_ARRAY);
- String[] excludes = (String[])
fileSet.getExcludes().toArray(STRINGS_ARRAY);
- File fileSetDirectory = resolveRelativePath(new
File(fileSet.getDirectory()));
- String[] scan = doScan(includes, excludes, fileSetDirectory);
-
- for (String filename : scan) {
- files.add(resolveRelativePath(new File(fileSetDirectory,
filename)));
- }
- }
- }
-
- return files;
+ return result;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -29,7 +29,6 @@
import org.junit.Before;
import org.junit.Test;
import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.FacesId;
/**
@@ -40,8 +39,8 @@
*
*/
public class NamingConventionsTest {
- private static final FacesId COMPONENT_TYPE =
FacesId.parseId("foo.bar.Test");
private static final String BASE = "foo.bar";
+ private static final FacesId COMPONENT_TYPE =
FacesId.parseId("foo.bar.Test");
private RichFacesConventions conventions;
@Before
@@ -54,19 +53,7 @@
conventions = null;
}
- /**
- * Test method for
- * {@link org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
- *
- * @throws Exception
- */
@Test
- public void testInferComponentTypeFromUIClass() throws Exception {
- assertEquals(COMPONENT_TYPE, conventions.inferComponentType(new
ClassName("foo.bar.component.UITest")));
- }
-
-
- @Test
public void testInferComponentTypeFromAbstractClass() throws Exception {
assertEquals(COMPONENT_TYPE, conventions.inferComponentType(new
ClassName("foo.bar.component.AbstractTest")));
}
@@ -78,12 +65,23 @@
@Test
public void testInferComponentTypeFromMarkupClass() throws Exception {
- assertEquals(FacesId.parseId("foo.bar.HtmlTest"),
conventions.inferComponentType(new
ClassName("foo.bar.component.html.HtmlTest")));
+ assertEquals(FacesId.parseId("foo.bar.HtmlTest"),
conventions.inferComponentType(new ClassName(
+ "foo.bar.component.html.HtmlTest")));
}
+ /**
+ * Test method for
+ * {@link org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ *
+ * @throws Exception
+ */
@Test
+ public void testInferComponentTypeFromUIClass() throws Exception {
+ assertEquals(COMPONENT_TYPE, conventions.inferComponentType(new
ClassName("foo.bar.component.UITest")));
+ }
+
+ @Test
public void testInferUIComponentClassFromType() throws Exception {
- assertEquals(new ClassName("foo.bar.component.UITest"),
- conventions.inferUIComponentClass(COMPONENT_TYPE));
+ assertEquals(new ClassName("foo.bar.component.UITest"),
conventions.inferUIComponentClass(COMPONENT_TYPE));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -69,37 +69,37 @@
private static final String CLASS_JAVA =
"org/richfaces/cdk/apt/TestClass.java";
private static final String COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/AbstractTestComponent.java";
private static final String INTERFACE_JAVA =
"org/richfaces/cdk/apt/TestInterface.java";
- private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
private static final ImmutableSet<String> PROCESS_ANNOTATIONS =
ImmutableSet.of(TestAnnotation.class.getName());
+ private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
@Inject
- private CdkProcessor processor;
+ ComponentLibrary library;
- @Stub
- @Output(Outputs.JAVA_CLASSES)
- private FileManager output;
+ @Mock
+ private LibraryBuilder builder;
@Inject
- ComponentLibrary library;
-
- @Inject
private CdkAnnotationProcessor cdkProcessor;
@Mock
- private RoundEnvironment roundEnv;
+ private TypeElement element;
@Mock
- private TypeElement element;
+ private Logger log;
+ @Stub
+ @Output(Outputs.JAVA_CLASSES)
+ private FileManager output;
+
+ @Inject
+ private CdkProcessor processor;
+
@Mock
- private LibraryBuilder builder;
+ private RoundEnvironment roundEnv;
@Mock
private ModelValidator validator;
- @Mock
- private Logger log;
-
@Override
public void configure(Binder binder) {
super.configure(binder);
@@ -113,17 +113,11 @@
}).toInstance(Collections.<ModelBuilder> emptySet());
}
- @Override
- protected Iterable<String> sources() {
- return ImmutableList.of(CLASS_JAVA, INTERFACE_JAVA, SUB_CLASS_JAVA);
- }
-
@Test
public void testProcess() throws Exception {
expect(roundEnv.processingOver()).andReturn(false);
expect((Class<TestAnnotation2>)
cdkProcessor.getProcessedAnnotation()).andStubReturn(TestAnnotation2.class);
- expect((Set<TypeElement>) roundEnv.getRootElements()).andReturn(
- Collections.singleton(element));
+ expect((Set<TypeElement>)
roundEnv.getRootElements()).andReturn(Collections.singleton(element));
expect(element.getKind()).andReturn(ElementKind.CLASS);
TestAnnotation2 testAnnotation2 = createNiceMock(TestAnnotation2.class);
expect(element.getAnnotation(TestAnnotation2.class)).andReturn(testAnnotation2);
@@ -138,10 +132,25 @@
}
@Test
+ public void testProcess3() throws Exception {
+ expect(roundEnv.processingOver()).andReturn(false);
+ expect((Class<TestAnnotation>)
cdkProcessor.getProcessedAnnotation()).andStubReturn(TestAnnotation.class);
+ expect((Set<TypeElement>)
roundEnv.getRootElements()).andReturn(Collections.singleton(element));
+ expect(element.getKind()).andReturn(ElementKind.CLASS);
+ expect(element.getAnnotation(TestAnnotation.class)).andReturn(null);
+ validator.verify(library);
+ expectLastCall();
+ replay(element, roundEnv, builder, validator, cdkProcessor);
+ processor.process(Collections.singleton(element), roundEnv);
+ verify(element, roundEnv, builder, validator, cdkProcessor);
+ }
+
+ @Test
public void testProcessOver() throws Exception {
expect(roundEnv.processingOver()).andReturn(true);
expect(log.getErrorCount()).andReturn(0);
- log.debug((CharSequence) anyObject());expectLastCall().asStub();
+ log.debug((CharSequence) anyObject());
+ expectLastCall().asStub();
builder.generate();
expectLastCall();
replay(log, element, roundEnv, builder, validator, cdkProcessor);
@@ -160,19 +169,9 @@
verify(log, element, roundEnv, builder, validator, cdkProcessor);
}
- @Test
- public void testProcess3() throws Exception {
- expect(roundEnv.processingOver()).andReturn(false);
- expect((Class<TestAnnotation>)
cdkProcessor.getProcessedAnnotation()).andStubReturn(TestAnnotation.class);
- expect((Set<TypeElement>) roundEnv.getRootElements()).andReturn(
- Collections.singleton(element));
- expect(element.getKind()).andReturn(ElementKind.CLASS);
- expect(element.getAnnotation(TestAnnotation.class)).andReturn(null);
- validator.verify(library);
- expectLastCall();
- replay(element, roundEnv, builder, validator, cdkProcessor);
- processor.process(Collections.singleton(element), roundEnv);
- verify(element, roundEnv, builder, validator, cdkProcessor);
+ @Override
+ protected Iterable<String> sources() {
+ return ImmutableList.of(CLASS_JAVA, INTERFACE_JAVA, SUB_CLASS_JAVA);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,21 +23,22 @@
package org.richfaces.cdk.apt;
-import com.google.common.collect.ImmutableList;
-import com.google.inject.Inject;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.JavaCompiler.CompilationTask;
+
import org.easymock.Capture;
import org.easymock.CaptureType;
import org.easymock.EasyMock;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -48,14 +49,8 @@
import org.richfaces.cdk.Stub;
import org.richfaces.cdk.apt.processors.AnnotationProcessorTest;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.annotation.processing.Processor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.TypeElement;
-import javax.tools.JavaCompiler.CompilationTask;
-import java.util.Collections;
-import java.util.Set;
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -68,15 +63,15 @@
public class TaskFactoryTest extends AnnotationProcessorTest {
private static final String CLASS_JAVA =
"org/richfaces/cdk/apt/TestClass.java";
- private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
private static final String INTERFACE_JAVA =
"org/richfaces/cdk/apt/TestInterface.java";
+ private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
- @Inject
- private TaskFactoryImpl factory;
-
@Mock
Processor processor;
+ @Inject
+ private TaskFactoryImpl factory;
+
@Stub
@Output(Outputs.JAVA_CLASSES)
private FileManager output;
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AnnotationProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AnnotationProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AnnotationProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -35,7 +35,6 @@
import org.richfaces.cdk.Generator;
import org.richfaces.cdk.LibraryBuilder;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.Mock;
import org.richfaces.cdk.Source;
import org.richfaces.cdk.SourceFileManager;
import org.richfaces.cdk.SourceImpl;
@@ -55,33 +54,34 @@
public abstract class AnnotationProcessorTest extends CdkTestBase {
protected static final class TestName implements Name {
-
+
private final String name;
-
+
public TestName(String name) {
this.name = name;
}
+
@Override
+ public char charAt(int index) {
+ return name.charAt(index);
+ }
+
+ @Override
public boolean contentEquals(CharSequence cs) {
// TODO Auto-generated method stub
return name.equals(cs);
}
-
+
@Override
- public char charAt(int index) {
- return name.charAt(index);
- }
-
- @Override
public int length() {
return name.length();
}
-
+
@Override
public CharSequence subSequence(int start, int end) {
return name.substring(start, end);
}
-
+
@Override
public String toString() {
return name;
@@ -91,27 +91,15 @@
protected static final String FOO_BAR = "foo.Bar";
@Inject
+ protected Logger log;
+
+ @Inject
@Source(Sources.JAVA_SOURCES)
protected FileManager sources;
@Inject
- protected Logger log;
-
- @Inject
private Injector injector;
- protected void process(String javaFilePath) throws Exception {
- Generator generator = new Generator();
- generator.setLoader(createClassLoader());
- generator.addSources(Sources.JAVA_SOURCES,
ImmutableList.of(getJavaFile(javaFilePath)), null);
-
- generator.init();
- injector.injectMembers(new ComponentProcessor());
-
- LibraryBuilder builder = injector.getInstance(LibraryBuilder.class);
- builder.build();
- }
-
@Override
public void configure(Binder binder) {
super.configure(binder);
@@ -130,16 +118,29 @@
}
- protected abstract Iterable<String> sources();
-
@Override
protected CdkClassLoader createClassLoader() {
try {
return new
CdkClassLoader(ImmutableList.of(getLibraryFile("test.source.properties"),
- getLibraryFile(ComponentModel.class), getLibraryFile(ELContext.class),
getLibraryFile(JsfComponent.class),
- getLibraryFile(UIComponent.class)), this.getClass().getClassLoader());
+ getLibraryFile(ComponentModel.class), getLibraryFile(ELContext.class),
+ getLibraryFile(JsfComponent.class), getLibraryFile(UIComponent.class)),
this.getClass()
+ .getClassLoader());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+
+ protected void process(String javaFilePath) throws Exception {
+ Generator generator = new Generator();
+ generator.setLoader(createClassLoader());
+ generator.addSources(Sources.JAVA_SOURCES,
ImmutableList.of(getJavaFile(javaFilePath)), null);
+
+ generator.init();
+ injector.injectMembers(new ComponentProcessor());
+
+ LibraryBuilder builder = injector.getInstance(LibraryBuilder.class);
+ builder.build();
+ }
+
+ protected abstract Iterable<String> sources();
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -37,7 +37,6 @@
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.Mock;
import org.richfaces.cdk.MockController;
-import org.richfaces.cdk.Logger;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
@@ -52,9 +51,11 @@
import com.google.inject.Inject;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
@RunWith(CdkTestRunner.class)
public class AttributesProcessorTest extends AnnotationProcessorTest {
@@ -63,23 +64,25 @@
private static final String FOO_XML = "foo.xml";
+ @Mock
+ private DescriptionProcessor descriptionProcessor;
+
@Inject
private MockController mockController;
-
+
@Inject
private AttributesProcessorImpl processor;
@Mock
- private DescriptionProcessor descriptionProcessor;
+ private SourceUtils utils;
@Mock
private JAXB xmlProcessor;
- @Mock
- private SourceUtils utils;
-
/**
- * Test method for {@link
org.richfaces.cdk.apt.processors.AttributesProcessorImpl#processType(org.richfaces.cdk.model.BeanModelBase,
javax.lang.model.element.TypeElement)}.
+ * Test method for
+ * {@link
org.richfaces.cdk.apt.processors.AttributesProcessorImpl#processType(org.richfaces.cdk.model.BeanModelBase,
javax.lang.model.element.TypeElement)}
+ * .
*/
@Test
public void testProcessType() {
@@ -88,13 +91,16 @@
utils.visitSupertypes(same(element), EasyMock.isA(SuperTypeVisitor.class));
expectLastCall();
BeanProperty beanProperty = createNiceMock(BeanProperty.class);
- expect(utils.getBeanPropertiesAnnotatedWith(eq(Attribute.class),
same(element))).andReturn(Collections.singleton(beanProperty));
+ expect(utils.getBeanPropertiesAnnotatedWith(eq(Attribute.class),
same(element))).andReturn(
+ Collections.singleton(beanProperty));
expect(utils.getAbstractBeanProperties(same(element))).andReturn(new
HashSet<BeanProperty>(0));
expect(beanProperty.getName()).andReturn(FOO);
expect(beanProperty.getType()).andReturn(ClassName.parseName(String.class.getName()));
- mockController.replay();replay(element,beanProperty);
+ mockController.replay();
+ replay(element, beanProperty);
processor.processType(bean, element);
- mockController.verify();verify(element,beanProperty);
+ mockController.verify();
+ verify(element, beanProperty);
assertEquals(1, bean.getAttributes().size());
}
@@ -104,8 +110,10 @@
Fragment fragment = new Fragment();
PropertyModel propertyModel = new PropertyModel();
propertyModel.setName(FOO);
- fragment.getProperties().add(propertyModel );
- expect(xmlProcessor.unmarshal(eq(CdkEntityResolver.URN_ATTRIBUTES+FOO_XML),
(String)anyObject(), eq(Fragment.class))).andReturn(fragment);
+ fragment.getProperties().add(propertyModel);
+ expect(
+ xmlProcessor.unmarshal(eq(CdkEntityResolver.URN_ATTRIBUTES + FOO_XML),
(String) anyObject(),
+ eq(Fragment.class))).andReturn(fragment);
mockController.replay();
processor.processXmlFragment(bean, FOO_XML);
mockController.verify();
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -59,30 +59,18 @@
*/
@RunWith(CdkTestRunner.class)
public class BehaviorProcessorTest extends AnnotationProcessorTest {
- private static final String MY_BEHAVIOR = "my_behavior";
-
private static final String BEHAVIOR_CLASS_JAVA =
"org/richfaces/cdk/test/component/MyBehavior.java";
- @Inject
- private BehaviorProcessor processor;
+ private static final String MY_BEHAVIOR = "my_behavior";
- @Inject
- private ComponentLibrary library;
-
@Mock
- private SourceUtils utils;
+ private JsfBehavior behaviorAnnotation;
@Mock
private TypeElement componentElement;
- @Stub
- private Name name;
-
- @Stub
- private Tag tag;
-
@Mock
- private JsfBehavior behaviorAnnotation;
+ private NamingConventions conventions;
@Mock
private Description description;
@@ -90,8 +78,20 @@
@Mock
private JAXB jaxb;
+ @Inject
+ private ComponentLibrary library;
+
+ @Stub
+ private Name name;
+
+ @Inject
+ private BehaviorProcessor processor;
+
+ @Stub
+ private Tag tag;
+
@Mock
- private NamingConventions conventions;
+ private SourceUtils utils;
@Test
@Ignore
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,18 +23,14 @@
package org.richfaces.cdk.apt.processors;
-import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.same;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -54,9 +50,8 @@
import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.xmlconfig.JAXB;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.TypeElement;
-import java.util.Collections;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -67,65 +62,122 @@
*/
@RunWith(CdkTestRunner.class)
public class ComponentProcessorTest extends AnnotationProcessorTest {
- public static final String SMALL_JPG = "/icons/Small.jpg";
public static final String LARGE_GIF = "/icons/Large.gif";
- private static final String FOO_HTML_BAR = "foo.HtmlBar";
+ public static final String SMALL_JPG = "/icons/Small.jpg";
private static final String COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/AbstractTestComponent.java";
private static final String FACES_COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/UITestCommand.java";
+ private static final String FOO_HTML_BAR = "foo.HtmlBar";
- @Inject
- private ComponentProcessor processor;
+ @Mock
+ private JsfComponent annotation;
@Mock
private AttributesProcessor attributesProcessor;
- @Inject
- private ComponentLibrary library;
+ @Mock
+ private TypeElement componentElement;
- @Inject
- private ComponentModel model;
-
@Mock
- private SourceUtils utils;
+ private NamingConventions conventions;
@Mock
- private TypeElement componentElement;
-
- @Mock
- private JsfComponent annotation;
-
- @Mock
private Description description;
+ @Stub
+ private DescriptionProcessor descriptionProcessor;
+
@Mock
private JAXB jaxb;
-
+
+ @Inject
+ private ComponentLibrary library;
+
+ @Inject
+ private ComponentModel model;
+
+ @Inject
+ private ComponentProcessor processor;
+
@Mock
private BeanProperty property;
- @Mock
- private NamingConventions conventions;
-
@Stub
@Source(Sources.RENDERER_TEMPLATES)
private FileManager sources;
-
- @Stub
- private DescriptionProcessor descriptionProcessor;
+ @Mock
+ private SourceUtils utils;
+
+ @Test
+ public void testProcessFacetsFromAnnotation() throws Exception {
+ Facet facet = createMock(Facet.class);
+ expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),
same(componentElement))).andReturn(
+ Collections.<BeanProperty> emptySet());
+ expect(annotation.facets()).andReturn(new Facet[] { facet });
+ expect(facet.name()).andReturn("foo");
+ expect(facet.description()).andReturn(this.description);
+ expect(facet.generate()).andReturn(true);
+ // expect(this.description.smallIcon()).andReturn("");
+ // expect(this.description.largeIcon()).andReturn("");
+ //
expect(this.description.displayName()).andReturn("fooFacet").times(2);
+ // expect(this.description.value()).andReturn("");
+ replay(utils, componentElement, jaxb, annotation, property, facet, description);
+
+ processor.processFacets(componentElement, model, annotation);
+
+ verify(utils, componentElement, jaxb, annotation, property, facet, description);
+ assertEquals(1, model.getFacets().size());
+ FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
+ assertTrue(facetModel.isGenerate());
+ assertEquals("foo", facetModel.getName());
+ // assertEquals("my comment", facetModel.getDescription());
+ // assertEquals("fooFacet", facetModel.getDisplayname());
+ // assertNull(facetModel.getIcon());
+ }
+
+ @Test
+ public void testProcessFacetsFromProperty() throws Exception {
+ Facet facet = createMock(Facet.class);
+ expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),
same(componentElement))).andReturn(
+ Collections.singleton(property));
+ expect(annotation.facets()).andReturn(new Facet[0]);
+ expect(property.getAnnotation(Facet.class)).andReturn(facet);
+ expect(property.getName()).andReturn("foo");
+ expect(property.getDocComment()).andReturn("my comment").times(2);
+ expect(property.isExists()).andReturn(true);
+ expect(facet.description()).andReturn(description);
+ expect(facet.generate()).andReturn(true);
+ // expect(this.description.smallIcon()).andReturn("");
+ // expect(this.description.largeIcon()).andReturn("");
+ //
expect(this.description.displayName()).andReturn("fooFacet").times(2);
+ // expect(this.description.value()).andReturn("");
+ replay(utils, componentElement, jaxb, annotation, property, facet, description);
+
+ processor.processFacets(componentElement, model, annotation);
+
+ verify(utils, componentElement, jaxb, annotation, property, facet, description);
+ assertEquals(1, model.getFacets().size());
+ FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
+ assertTrue(facetModel.isGenerate());
+ assertEquals("foo", facetModel.getName());
+ // assertEquals("my comment", facetModel.getDescription());
+ // assertEquals("fooFacet", facetModel.getDisplayname());
+ // assertNull(facetModel.getIcon());
+ }
+
/**
* Test method for
* {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)} .
*
* @throws Exception
*/
- @Test
+ @Test
public void testSetClassNames() throws Exception {
-
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>emptySet());
+ expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
emptySet());
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model,"");
- verify(utils, componentElement, jaxb,annotation );
+ processor.setClassNames(componentElement, model, "");
+ verify(utils, componentElement, jaxb, annotation);
assertFalse(model.isGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
assertNull(model.getTargetClass());
@@ -137,57 +189,59 @@
*
* @throws Exception
*/
- @Test
+ @Test
public void testSetClassNames1() throws Exception {
-
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>singleton(Modifier.ABSTRACT));
+ expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
singleton(Modifier.ABSTRACT));
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model,"");
+ processor.setClassNames(componentElement, model, "");
- verify(utils, componentElement, jaxb,annotation );
+ verify(utils, componentElement, jaxb, annotation);
assertTrue(model.isGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
assertNull(model.getTargetClass());
}
+
/**
* Test method for
* {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)} .
*
* @throws Exception
*/
- @Test
+ @Test
public void testSetClassNames2() throws Exception {
-
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>emptySet());
+ expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
emptySet());
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model,FOO_HTML_BAR);
+ processor.setClassNames(componentElement, model, FOO_HTML_BAR);
- verify(utils, componentElement, jaxb,annotation );
+ verify(utils, componentElement, jaxb, annotation);
assertTrue(model.isGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
- assertEquals(FOO_HTML_BAR,model.getTargetClass().toString());
+ assertEquals(FOO_HTML_BAR, model.getTargetClass().toString());
}
@Test
public void testSetFamily() throws Exception {
replay(utils, componentElement, jaxb, annotation);
- processor.setComponeneFamily(componentElement, model,FOO_HTML_BAR);
+ processor.setComponeneFamily(componentElement, model, FOO_HTML_BAR);
- verify(utils, componentElement, jaxb,annotation );
+ verify(utils, componentElement, jaxb, annotation);
assertEquals(FOO_HTML_BAR, model.getFamily());
}
-
+
@Test
public void testSetFamily1() throws Exception {
- expect(utils.getConstant(same(componentElement),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(FOO_HTML_BAR);
+ expect(utils.getConstant(same(componentElement),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(
+ FOO_HTML_BAR);
replay(utils, componentElement, jaxb, annotation);
- processor.setComponeneFamily(componentElement, model,"");
+ processor.setComponeneFamily(componentElement, model, "");
- verify(utils, componentElement, jaxb,annotation );
+ verify(utils, componentElement, jaxb, annotation);
assertEquals(FOO_HTML_BAR, model.getFamily());
}
@@ -196,69 +250,12 @@
expect(utils.getConstant(same(componentElement),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(null);
replay(utils, componentElement, jaxb, annotation);
- processor.setComponeneFamily(componentElement, model,"");
+ processor.setComponeneFamily(componentElement, model, "");
- verify(utils, componentElement, jaxb,annotation );
- assertNull( model.getFamily());
+ verify(utils, componentElement, jaxb, annotation);
+ assertNull(model.getFamily());
}
-
-
- @Test
- public void testProcessFacetsFromProperty() throws Exception {
- Facet facet = createMock(Facet.class);
-
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),same(componentElement))).andReturn(Collections.singleton(property));
- expect(annotation.facets()).andReturn(new Facet[0]);
- expect(property.getAnnotation(Facet.class)).andReturn(facet);
- expect(property.getName()).andReturn("foo");
- expect(property.getDocComment()).andReturn("my comment").times(2);
- expect(property.isExists()).andReturn(true);
- expect(facet.description()).andReturn(description);
- expect(facet.generate()).andReturn(true);
-// expect(this.description.smallIcon()).andReturn("");
-// expect(this.description.largeIcon()).andReturn("");
-//
expect(this.description.displayName()).andReturn("fooFacet").times(2);
-// expect(this.description.value()).andReturn("");
- replay(utils, componentElement, jaxb, annotation,property,facet,description);
-
- processor.processFacets(componentElement, model, annotation);
-
- verify(utils, componentElement, jaxb,annotation,property,facet,description);
- assertEquals(1, model.getFacets().size());
- FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
- assertTrue(facetModel.isGenerate());
- assertEquals("foo", facetModel.getName());
-// assertEquals("my comment", facetModel.getDescription());
-// assertEquals("fooFacet", facetModel.getDisplayname());
-// assertNull(facetModel.getIcon());
- }
- @Test
- public void testProcessFacetsFromAnnotation() throws Exception {
- Facet facet = createMock(Facet.class);
-
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),same(componentElement))).andReturn(Collections.<BeanProperty>emptySet());
- expect(annotation.facets()).andReturn(new Facet[]{facet});
- expect(facet.name()).andReturn("foo");
- expect(facet.description()).andReturn(this.description);
- expect(facet.generate()).andReturn(true);
-// expect(this.description.smallIcon()).andReturn("");
-// expect(this.description.largeIcon()).andReturn("");
-//
expect(this.description.displayName()).andReturn("fooFacet").times(2);
-// expect(this.description.value()).andReturn("");
- replay(utils, componentElement, jaxb, annotation,property,facet,description);
-
- processor.processFacets(componentElement, model, annotation);
-
- verify(utils, componentElement, jaxb,annotation,property,facet,description);
- assertEquals(1, model.getFacets().size());
- FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
- assertTrue(facetModel.isGenerate());
- assertEquals("foo", facetModel.getName());
-// assertEquals("my comment", facetModel.getDescription());
-// assertEquals("fooFacet", facetModel.getDisplayname());
-// assertNull(facetModel.getIcon());
- }
-
-
@Override
protected Iterable<String> sources() {
return Collections.singleton(COMPONENT_CLASS_JAVA);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ConverterProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ConverterProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ConverterProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -21,20 +21,21 @@
package org.richfaces.cdk.apt.processors;
-import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.Collections;
+
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
-import org.richfaces.cdk.apt.processors.AnnotationProcessorTest;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
-import java.util.Collection;
-import java.util.Collections;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
/**
* @author akolonitsky
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -24,7 +24,6 @@
package org.richfaces.cdk.apt.processors;
import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
import java.util.Collections;
@@ -39,41 +38,48 @@
import com.google.inject.Inject;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
@RunWith(CdkTestRunner.class)
public class DescriptionProcessorTest extends AnnotationProcessorTest {
+ private static final String FOO_BAR_ELEMENT = "Foo bar element";
+
private static final String FOO_FACET = "fooFacet";
- private static final String FOO_BAR_ELEMENT = "Foo bar element";
+ @Mock
+ private DescriptionGroup bean;
+ @Mock
+ private Description description;
+
@Inject
+ private DescriptionProcessorImpl descriptionProcessor;
+
+ @Inject
private MockController mockController;
- @Inject
- private DescriptionProcessorImpl descriptionProcessor;
-
- @Mock
- private Description description;
-
- @Mock
- private DescriptionGroup bean;
/**
- * Test method for {@link
org.richfaces.cdk.apt.processors.DescriptionProcessorImpl#processDescription(org.richfaces.cdk.model.DescriptionGroup,
org.richfaces.cdk.annotations.Description, java.lang.String)}.
+ * Test method for
+ * {@link
org.richfaces.cdk.apt.processors.DescriptionProcessorImpl#processDescription(org.richfaces.cdk.model.DescriptionGroup,
org.richfaces.cdk.annotations.Description, java.lang.String)}
+ * .
*/
@Test
public void testProcessDescription() {
- bean.setDescription(FOO_BAR_ELEMENT);expectLastCall();
- bean.setDisplayname(FOO_FACET);expectLastCall();
- expect(this.description.smallIcon()).andReturn("");
- expect(this.description.largeIcon()).andReturn("");
- expect(this.description.displayName()).andReturn(FOO_FACET).times(2);
- expect(this.description.value()).andReturn("");
+ bean.setDescription(FOO_BAR_ELEMENT);
+ expectLastCall();
+ bean.setDisplayname(FOO_FACET);
+ expectLastCall();
+ expect(this.description.smallIcon()).andReturn("");
+ expect(this.description.largeIcon()).andReturn("");
+ expect(this.description.displayName()).andReturn(FOO_FACET).times(2);
+ expect(this.description.value()).andReturn("");
mockController.replay();
- descriptionProcessor.processDescription(bean, description,FOO_BAR_ELEMENT);
+ descriptionProcessor.processDescription(bean, description, FOO_BAR_ELEMENT);
mockController.verify();
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ValidatorProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ValidatorProcessorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ValidatorProcessorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -21,28 +21,29 @@
package org.richfaces.cdk.apt.processors;
-import com.google.inject.Inject;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+
import org.easymock.EasyMock;
import org.junit.Assert;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
-import org.richfaces.cdk.apt.processors.AnnotationProcessorTest;
import org.richfaces.cdk.annotations.JsfValidator;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.ValidatorModel;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* @author akolonitsky
@@ -50,15 +51,43 @@
*/
@RunWith(CdkTestRunner.class)
public class ValidatorProcessorTest extends AnnotationProcessorTest {
+ private static class MyName implements Name {
+ private final String toString;
+
+ MyName(String toString) {
+ this.toString = toString;
+ }
+
+ @Override
+ public char charAt(int index) {
+ return 0;
+ }
+
+ @Override
+ public boolean contentEquals(CharSequence cs) {
+ return false;
+ }
+
+ @Override
+ public int length() {
+ return 0;
+ }
+
+ @Override
+ public CharSequence subSequence(int start, int end) {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+ }
private static final String VALIDATOR_CLASS_JAVA =
"org/richfaces/cdk/test/component/MyValidator.java";
+
@Inject
private ComponentLibrary library;
- @Override
- protected Iterable<String> sources() {
- return Collections.singleton(VALIDATOR_CLASS_JAVA);
- }
-
@Test
@Ignore
public void testProcess() throws Exception {
@@ -68,7 +97,7 @@
for (ValidatorModel model : validators) {
FacesId id = model.getId();
- if (id != null ) {
+ if (id != null) {
assertEquals("my_validator", id.toString());
}
}
@@ -76,7 +105,6 @@
// TODO create Test for ProcessorBase
@Test
-
public void testSetNames() {
ValidatorModel model;
@@ -98,37 +126,41 @@
// /////////////////////////////// ABSTRACT
///////////////////////////////////////
// @JsfValidator public abstract class BaseClass { ...
-// checkAbstractWithException(null);
+ // checkAbstractWithException(null);
// @JsfValidator(validatorClass = "") public abstract class BaseClass {
...
-// checkAbstractWithException("");
+ // checkAbstractWithException("");
// @JsfValidator(validatorClass = BaseClass) public abstract class BaseClass {
...
-// checkAbstractWithException("BaseClass");
+ // checkAbstractWithException("BaseClass");
// @JsfValidator(validatorClass = GeneratedClass) public abstract class BaseClass
{ ...
model = getValidatorModelForSetNames(true, "GeneratedClass",
"BaseClass", true);
check("GeneratedClass", "BaseClass", true, model);
}
- private void checkAbstractWithException(String validatorClass) {
- try {
- getValidatorModelForSetNames(true, validatorClass, "BaseClass",
true);
- Assert.fail("Abstract class can't be a validator.");
- } catch (IllegalStateException e) {
- // Do nothing.
- }
+ @Override
+ protected Iterable<String> sources() {
+ return Collections.singleton(VALIDATOR_CLASS_JAVA);
}
private void check(String validatorClass, String baseClass, boolean generate,
ValidatorModel model) {
if (baseClass != null) {
-// assertEquals(model.getBaseClass().toString(), baseClass);
+ // assertEquals(model.getBaseClass().toString(), baseClass);
} else {
assertNull(model.getBaseClass());
}
+ // assertEquals(generate, model.isGenerate());
+ }
-// assertEquals(generate, model.isGenerate());
+ private void checkAbstractWithException(String validatorClass) {
+ try {
+ getValidatorModelForSetNames(true, validatorClass, "BaseClass",
true);
+ Assert.fail("Abstract class can't be a validator.");
+ } catch (IllegalStateException e) {
+ // Do nothing.
+ }
}
private ValidatorModel getValidatorModelForSetNames(boolean isAnnotationDefined,
String validatorClass,
@@ -154,40 +186,7 @@
}
EasyMock.verify();
-// ValidatorProcessor.setClassNames(element, validatorModel, validator);
+ // ValidatorProcessor.setClassNames(element, validatorModel, validator);
return validatorModel;
}
-
- private static class MyName implements Name {
- private final String toString;
-
- MyName(String toString) {
- this.toString = toString;
- }
-
- @Override
- public int length() {
- return 0;
- }
-
- @Override
- public char charAt(int index) {
- return 0;
- }
-
- @Override
- public CharSequence subSequence(int start, int end) {
- return null;
- }
-
- @Override
- public String toString() {
- return toString;
- }
-
- @Override
- public boolean contentEquals(CharSequence cs) {
- return false;
- }
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -58,44 +58,31 @@
public abstract class AbstractClassGeneratorTest extends CdkTestBase {
@Inject
- protected ComponentLibrary library;
-
- @Inject
@As(CdkConfiguration.class)
protected Configuration configuration;
@Inject
- @As(LibraryModelWrapper.class)
- protected ObjectWrapper wrapper;
+ protected ComponentLibrary library;
+ @Inject
+ protected Logger log;
+
@Mock
@Output(Outputs.RESOURCES)
protected FileManager output;
@Inject
- protected Logger log;
+ @As(LibraryModelWrapper.class)
+ protected ObjectWrapper wrapper;
- protected static PropertyBase addAttribute(ModelElementBase model, String
attributeName, Class<?> type, boolean generate) {
+ protected static PropertyBase addAttribute(ModelElementBase model, String
attributeName, Class<?> type,
+ boolean generate) {
PropertyBase attribute = model.getOrCreateAttribute(attributeName);
attribute.setType(new ClassName(type));
attribute.setGenerate(generate);
return attribute;
}
- protected static EventName getEvent(String name, boolean defaultEvent) {
- EventName event = new EventName();
- event.setName(name);
- event.setDefaultEvent(defaultEvent);
- return event;
- }
-
- protected void compare(StringWriter writer, String fileName) throws IOException {
- InputStream expectedFacesConfigFile =
this.getClass().getResourceAsStream(fileName);
- Assert.assertNotNull("File (" + fileName + ") with expected result
wasn't found.", expectedFacesConfigFile);
-
- compareTextFiles(new StringReader(writer.toString()), new
InputStreamReader(expectedFacesConfigFile));
- }
-
protected static void compareTextFiles(Reader reference, Reader output) throws
IOException {
LineNumberReader ref = new LineNumberReader(reference);
LineNumberReader out = new LineNumberReader(output);
@@ -118,4 +105,18 @@
}
}
}
+
+ protected static EventName getEvent(String name, boolean defaultEvent) {
+ EventName event = new EventName();
+ event.setName(name);
+ event.setDefaultEvent(defaultEvent);
+ return event;
+ }
+
+ protected void compare(StringWriter writer, String fileName) throws IOException {
+ InputStream expectedFacesConfigFile =
this.getClass().getResourceAsStream(fileName);
+ Assert.assertNotNull("File (" + fileName + ") with expected result
wasn't found.", expectedFacesConfigFile);
+
+ compareTextFiles(new StringReader(writer.toString()), new
InputStreamReader(expectedFacesConfigFile));
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/BehaviorClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/BehaviorClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/BehaviorClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,12 +22,11 @@
package org.richfaces.cdk.generate.java;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
+
+import java.io.StringWriter;
+import java.util.Set;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -38,8 +37,7 @@
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.PropertyBase;
-import java.io.StringWriter;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* @author akolonitsky
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -28,8 +28,6 @@
import japa.parser.JavaParser;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.body.MethodDeclaration;
-import japa.parser.ast.visitor.GenericVisitorAdapter;
-import japa.parser.ast.visitor.VoidVisitor;
import japa.parser.ast.visitor.VoidVisitorAdapter;
import java.io.ByteArrayInputStream;
@@ -67,9 +65,10 @@
private final class VoidVisitorAdapterExtension extends
VoidVisitorAdapter<String> {
private boolean found = false;
+ @Override
public void visit(MethodDeclaration n, String arg) {
- if(arg.equals(n.getName())){
- this.found =true;
+ if (arg.equals(n.getName())) {
+ this.found = true;
}
}
}
@@ -77,39 +76,6 @@
@Inject
private ComponentClassGenerator generator;
- @Test
- public void testGetOutputFileComponent() throws Exception {
- final StringWriter outputWriter = new StringWriter();
- expect(output.createOutput((String) anyObject(),
anyInt())).andReturn(outputWriter);
- replay(output);
-
- ComponentModel component = createComponent();
-
- library.getComponents().add(component);
-
- generator.generate(component);
- log.debug(outputWriter.toString());
-
- verify(output);
-
-// TODO - any change in the template breaks test, make comperison more intellectual
?
- ByteArrayInputStream inputStream = new
ByteArrayInputStream(outputWriter.toString().getBytes());
- CompilationUnit compilationUnit = JavaParser.parse(inputStream);
- assertNotNull(compilationUnit);
- VoidVisitorAdapterExtension visitorAdapter = new VoidVisitorAdapterExtension();
- compilationUnit.accept(visitorAdapter , "isTestFlag");
- assertTrue(visitorAdapter.found);
-// compare(outputWriter, "GeneratedComponent.java");
- }
-
- public ComponentClassGenerator getGenerator() {
- return generator;
- }
-
- public void setGenerator(ComponentClassGenerator generator) {
- this.generator = generator;
- }
-
public static ComponentModel createComponent() {
ComponentModel component = new
ComponentModel(FacesId.parseId("foo.bar"));
component.setGenerate(true);
@@ -157,7 +123,40 @@
Set<EventName> eventNames = attribute.getEventNames();
eventNames.add(getEvent("id", false));
eventNames.add(getEvent("action", true));
-
+
return component;
}
+
+ public ComponentClassGenerator getGenerator() {
+ return generator;
+ }
+
+ public void setGenerator(ComponentClassGenerator generator) {
+ this.generator = generator;
+ }
+
+ @Test
+ public void testGetOutputFileComponent() throws Exception {
+ final StringWriter outputWriter = new StringWriter();
+ expect(output.createOutput((String) anyObject(),
anyInt())).andReturn(outputWriter);
+ replay(output);
+
+ ComponentModel component = createComponent();
+
+ library.getComponents().add(component);
+
+ generator.generate(component);
+ log.debug(outputWriter.toString());
+
+ verify(output);
+
+ // TODO - any change in the template breaks test, make comperison more
intellectual ?
+ ByteArrayInputStream inputStream = new
ByteArrayInputStream(outputWriter.toString().getBytes());
+ CompilationUnit compilationUnit = JavaParser.parse(inputStream);
+ assertNotNull(compilationUnit);
+ VoidVisitorAdapterExtension visitorAdapter = new VoidVisitorAdapterExtension();
+ compilationUnit.accept(visitorAdapter, "isTestFlag");
+ assertTrue(visitorAdapter.found);
+ // compare(outputWriter, "GeneratedComponent.java");
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,12 +22,11 @@
package org.richfaces.cdk.generate.java;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
+
+import java.io.StringWriter;
+import java.util.Set;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -38,8 +37,7 @@
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.FacesId;
-import java.io.StringWriter;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* @author akolonitsky
@@ -80,8 +78,7 @@
log.debug(outputWriter.toString());
verify(output);
// TODO - use source code parser to analyze generated class
-// compare(outputWriter, "GeneratedConverter.java");
+ // compare(outputWriter, "GeneratedConverter.java");
}
-
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/TagHandlerClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/TagHandlerClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/TagHandlerClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,12 +22,12 @@
package org.richfaces.cdk.generate.java;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
+
+import java.io.StringWriter;
+
+import javax.faces.view.facelets.ComponentHandler;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -37,8 +37,7 @@
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.TagModel;
-import javax.faces.view.facelets.ComponentHandler;
-import java.io.StringWriter;
+import com.google.inject.Inject;
/**
* @author akolonitsky
@@ -48,11 +47,19 @@
public class TagHandlerClassGeneratorTest extends AbstractClassGeneratorTest {
@Inject
- private Logger log;
-
- @Inject
private TagHandlerClassGenerator generator;
+ @Inject
+ private Logger log;
+
+ public TagHandlerClassGenerator getGenerator() {
+ return generator;
+ }
+
+ public void setGenerator(TagHandlerClassGenerator generator) {
+ this.generator = generator;
+ }
+
@Test
public void testGetOutputFileBehavior() throws Exception {
final StringWriter outputWriter = new StringWriter();
@@ -62,25 +69,16 @@
ComponentModel model = ComponentClassGeneratorTest.createComponent();
library.getComponents().add(model);
-
TagModel tagModel = new TagModel();
tagModel.setName("mytag");
tagModel.setTargetClass(ClassName.parseName("org.richfaces.cdk.generate.java.GeneratedTagHandler"));
tagModel.setBaseClass(ClassName.parseName(ComponentHandler.class.getName()));
-
- generator.process(model,tagModel);
+ generator.process(model, tagModel);
+
log.debug(outputWriter.toString());
verify(output);
compare(outputWriter, "GeneratedTagHandler.java");
}
-
- public TagHandlerClassGenerator getGenerator() {
- return generator;
- }
-
- public void setGenerator(TagHandlerClassGenerator generator) {
- this.generator = generator;
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,12 +22,11 @@
package org.richfaces.cdk.generate.java;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
+
+import java.io.StringWriter;
+import java.util.Set;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
@@ -38,8 +37,7 @@
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.ValidatorModel;
-import java.io.StringWriter;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* @author akolonitsky
@@ -80,7 +78,7 @@
verify(output);
// TODO - use source code parser to analyze generated class
-// compare(outputWriter, "GeneratedValidator.java");
+ // compare(outputWriter, "GeneratedValidator.java");
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,15 +23,16 @@
package org.richfaces.cdk.model;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.Collection;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
-import java.util.Arrays;
-import java.util.Collection;
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -46,6 +47,7 @@
private final String expectedCanonicalName;
private final String expectedTypeParameter;
private final String packageName;
+
private final String simpleName;
public ClassDescriptionTest(String className, String expectedCanonicalName, String
expectedBoxedName,
@@ -58,6 +60,13 @@
this.simpleName = simpleName;
}
+ @Parameters
+ public static Collection<String[]> values() {
+ return Arrays.asList(new String[] { int.class.getName(), "int",
"java.lang.Integer", null, null, "int" },
+ new String[] { "java.util.List<String>",
"java.util.List", "java.util.List<String>",
"<String>","java.util", "List" },
+ new String[] { double.class.getName(), "double",
"java.lang.Double", null, null,"double" });
+ }
+
/**
* Test method for {@link ClassName#ClassName(java.lang.String)}.
*/
@@ -72,12 +81,4 @@
assertEquals(packageName, description.getPackage());
assertEquals(simpleName, description.getSimpleName());
}
-
- @Parameters
- public static Collection<String[]> values() {
- return Arrays.asList(new String[] { int.class.getName(), "int",
"java.lang.Integer", null, null, "int" },
- new String[] { "java.util.List<String>",
"java.util.List", "java.util.List<String>",
"<String>",
- "java.util", "List" }, new String[] {
double.class.getName(), "double", "java.lang.Double", null, null,
- "double" });
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -32,19 +32,27 @@
*/
public class ModelBean implements ModelElement<ModelBean> {
+ public static final class Type extends FacesId {
+ private static final long serialVersionUID = 6227413669285563473L;
+
+ public Type(String type) {
+ super(type);
+ }
+ }
/**
* <p class="changed_added_4_0">
* </p>
*/
private static final long serialVersionUID = -4853397197172488116L;
String readOnly;
+
String writeOnly;
-
- private boolean vizited = false;
private String doNotReplace;
private Object result;
private Type type;
+ private boolean vizited = false;
+
public ModelBean() {
}
@@ -52,136 +60,128 @@
this.type = new Type(name);
}
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ vizited = true;
+
+ return visitor.visit(this, data);
+ }
+
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the type
+ * @return the doNotReplace
*/
- public Type getType() {
- return this.type;
+ @Merge(false)
+ public String getDoNotReplace() {
+ return doNotReplace;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param type
- * the type to set
+ * @return the readOnly
*/
- public void setType(Type type) {
- this.type = type;
+ @Merge
+ public String getReadOnly() {
+ return readOnly;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the vizited
+ * @return the result
*/
@Merge
- public boolean isVizited() {
- return vizited;
+ public Object getResult() {
+ return result;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param vizited
- * the vizited to set
+ * @return the type
*/
- public void setVizited(boolean vizited) {
- this.vizited = vizited;
+ public Type getType() {
+ return this.type;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the result
+ * @return the vizited
*/
@Merge
- public Object getResult() {
- return result;
+ public boolean isVizited() {
+ return vizited;
}
+ @Override
+ public void merge(ModelBean other) {
+ ComponentLibrary.merge(this, other);
+ }
+
+ @Override
+ public boolean same(ModelBean other) {
+ return null != getType() && getType().equals(other.getType());
+ }
+
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param result
- * the result to set
+ * @param doNotReplace
+ * the doNotReplace to set
*/
- public void setResult(Object result) {
- this.result = result;
+ public void setDoNotReplace(String doNotReplace) {
+ this.doNotReplace = doNotReplace;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the readOnly
+ * @param result
+ * the result to set
*/
- @Merge
- public String getReadOnly() {
- return readOnly;
+ public void setResult(Object result) {
+ this.result = result;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param writeOnly
- * the writeOnly to set
+ * @param type
+ * the type to set
*/
- public void setWriteOnly(String writeOnly) {
- this.writeOnly = writeOnly;
+ public void setType(Type type) {
+ this.type = type;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the doNotReplace
+ * @param vizited
+ * the vizited to set
*/
- @Merge(false)
- public String getDoNotReplace() {
- return doNotReplace;
+ public void setVizited(boolean vizited) {
+ this.vizited = vizited;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param doNotReplace
- * the doNotReplace to set
+ * @param writeOnly
+ * the writeOnly to set
*/
- public void setDoNotReplace(String doNotReplace) {
- this.doNotReplace = doNotReplace;
+ public void setWriteOnly(String writeOnly) {
+ this.writeOnly = writeOnly;
}
-
- @Override
- public void merge(ModelBean other) {
- ComponentLibrary.merge(this, other);
- }
-
- public <R,D> R accept(Visitor<R,D> visitor, D data) {
- vizited = true;
-
- return visitor.visit(this,data);
- }
-
- @Override
- public boolean same(ModelBean other) {
- return null != getType() && getType().equals(other.getType());
- }
-
- public static final class Type extends FacesId {
- private static final long serialVersionUID = 6227413669285563473L;
-
- public Type(String type) {
- super(type);
- }
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/NameTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/NameTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/NameTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,9 +23,9 @@
package org.richfaces.cdk.model;
+import static org.junit.Assert.*;
+
import org.junit.After;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
@@ -164,21 +164,21 @@
}
/**
- * Test method for {@link org.richfaces.cdk.model.Name#create(java.lang.String,
java.lang.String)}.
+ * Test method for
+ * {@link org.richfaces.cdk.model.Name#create(java.lang.String,
org.richfaces.cdk.model.Name.Classifier, java.lang.String)}
+ * .
*/
@Test
- public void testCreateStringString() {
+ public void testCreateStringClassifierString() {
// fail("Not yet implemented");
}
/**
- * Test method for
- * {@link org.richfaces.cdk.model.Name#create(java.lang.String,
org.richfaces.cdk.model.Name.Classifier, java.lang.String)}
- * .
+ * Test method for {@link org.richfaces.cdk.model.Name#create(java.lang.String,
java.lang.String)}.
*/
@Test
- public void testCreateStringClassifierString() {
+ public void testCreateStringString() {
// fail("Not yet implemented");
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -18,17 +18,13 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+ */
package org.richfaces.cdk.model.validator;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestBase;
@@ -42,38 +38,43 @@
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.FacesId;
+import com.google.inject.Inject;
+
/**
* @author asmirnov
* @version $Id$
- *
+ *
*/
@RunWith(CdkTestRunner.class)
public class ModelValidatorTest extends CdkTestBase {
@Mock
- private NamingConventions namiingConventions;
-
+ protected Logger log;
+
@Mock
SourceUtils utils;
-
- @Mock
- protected Logger log;
@Inject
+ ValidatorImpl validator;
+
+ @Inject
private ComponentLibrary library;
- @Inject
- ValidatorImpl validator;
+ @Mock
+ private NamingConventions namiingConventions;
+
/**
- * Test method for {@link
org.richfaces.cdk.model.validator.ValidatorImpl#verifyComponent(org.richfaces.cdk.model.ComponentModel)}.
+ * Test method for
+ * {@link
org.richfaces.cdk.model.validator.ValidatorImpl#verifyComponent(org.richfaces.cdk.model.ComponentModel)}.
*/
@Test
public void testVerifyEmptyComponent() {
ComponentModel component = new ComponentModel();
- log.error((CharSequence) anyObject());expectLastCall();
- replay(log,utils,namiingConventions);
+ log.error((CharSequence) anyObject());
+ expectLastCall();
+ replay(log, utils, namiingConventions);
validator.verifyComponentType(component);
- verify(log,utils,namiingConventions);
+ verify(log, utils, namiingConventions);
}
@Test
@@ -84,10 +85,10 @@
component.setTargetClass(className);
expect(namiingConventions.inferComponentType(className)).andReturn(type);
expect(namiingConventions.inferUIComponentFamily(type)).andReturn("foo.baz");
- replay(log,utils,namiingConventions);
+ replay(log, utils, namiingConventions);
// Validator should set component type from base class.
validator.verifyComponentType(component);
- verify(log,utils,namiingConventions);
+ verify(log, utils, namiingConventions);
assertEquals(type, component.getType());
assertEquals("foo.baz", component.getFamily());
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -68,14 +68,14 @@
public class RendererTemplateParserTest extends CdkTestBase {
@Inject
- private RendererTemplateParser parser;
+ @As(JAXBBinding.class)
+ private JAXB binding;
@Inject
private ComponentLibrary library;
@Inject
- @As(JAXBBinding.class)
- private JAXB binding;
+ private RendererTemplateParser parser;
@Mock
private EntityResolver2 resolver;
@@ -84,24 +84,14 @@
@Source(Sources.RENDERER_TEMPLATES)
private FileManager templatesSource;
- private RenderKitModel getRenderkitFromModel(String renderkitId) {
- RenderKitModel renderKit = library.getRenderKit(new FacesId(renderkitId));
- assertNotNull(renderKit);
-
- return renderKit;
+ private void assertNoDefaultValue(PropertyBase property) {
+ assertNull(property.getDefaultValue());
}
- private RendererModel getFirstRendererFromRenderkit(RenderKitModel renderKit) {
- Collection<RendererModel> renderers = renderKit.getRenderers();
- assertNotNull(renderers);
-
- Iterator<RendererModel> renderersIterator = renderers.iterator();
- assertTrue(renderersIterator.hasNext());
-
- RendererModel renderer = renderersIterator.next();
- assertNotNull(renderer);
-
- return renderer;
+ private void assertNoEventNames(PropertyBase property) {
+ Set<EventName> eventNames = property.getEventNames();
+ assertNotNull(eventNames);
+ assertTrue(eventNames.isEmpty());
}
private void assertNoSignature(PropertyBase property) {
@@ -110,21 +100,89 @@
assertTrue(signature.isEmpty());
}
- private void assertNoEventNames(PropertyBase property) {
- Set<EventName> eventNames = property.getEventNames();
- assertNotNull(eventNames);
- assertTrue(eventNames.isEmpty());
+ private void assertNotRequired(PropertyBase property) {
+ assertFalse(property.isRequired());
}
- private void assertNoDefaultValue(PropertyBase property) {
- assertNull(property.getDefaultValue());
+ @Test
+ public void basicComponentTest() throws Exception {
+ Template template =
parser.parseTemplate(getJavaFile("org/richfaces/cdk/templatecompiler/basic.template.xml"));
+ assertNotNull(template);
+
+ parser.mergeTemplateIntoModel(template, null);
+
+ RenderKitModel renderKit =
getRenderkitFromModel(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ RendererModel renderer = getFirstRendererFromRenderkit(renderKit);
+
+ assertEquals(new
ClassName("org.richfaces.renderkit.html.BasicRendererImpl"),
renderer.getRendererClass());
+ assertFalse(renderer.isRendersChildren());
}
- private void assertNotRequired(PropertyBase property) {
- assertFalse(property.isRequired());
+ /**
+ * Checks that method signature satisfies the following declaration:
<code>java.lang.String action()</code>
+ *
+ * @param actionProperty
+ */
+ private void checkDummyComponentAction(PropertyBase actionProperty) {
+ assertNotNull(actionProperty);
+ assertNoEventNames(actionProperty);
+
+ assertEquals(Lists.newArrayList(), actionProperty.getSignature());
}
/**
+ * Checks that method signature satisfies the following declaration:
+ * <code>void actionListener(javax.faces.event.ActionEvent)</code>
+ *
+ * @param actionListenerProperty
+ */
+ private void checkDummyComponentActionListener(PropertyBase actionListenerProperty)
{
+ assertNotNull(actionListenerProperty);
+ assertNoEventNames(actionListenerProperty);
+
+ assertEquals(Lists.newArrayList(new ClassName(ActionEvent.class)),
actionListenerProperty.getSignature());
+ }
+
+ /**
+ * Checks that method signature satisfies the following declaration:
+ * <code>float coolMethod(int, java.lang.String,
javax.faces.validator.Validator)</code>
+ *
+ * @param coolMethodProperty
+ */
+ private void checkDummyComponentCoolMethod(PropertyBase coolMethodProperty) {
+ assertNotNull(coolMethodProperty);
+ assertNoEventNames(coolMethodProperty);
+
+ ArrayList<ClassName> expectedSignature =
+ Lists.newArrayList(new ClassName(int.class), new ClassName(String.class), new
ClassName(Validator.class));
+
+ assertEquals(expectedSignature, coolMethodProperty.getSignature());
+ }
+
+ private void checkDummyComponentImportedAttribute(PropertyBase importedAttribute,
Class<?> type) {
+ assertNotNull(importedAttribute);
+ assertNoEventNames(importedAttribute);
+ assertNoSignature(importedAttribute);
+ assertNoDefaultValue(importedAttribute);
+ assertFalse(importedAttribute.isRequired());
+
+ assertEquals(type.getName(), importedAttribute.getType().getName());
+ }
+
+ /**
+ * @param integerAttribute
+ */
+ private void checkDummyComponentIntegerAttribute(PropertyBase integerAttribute) {
+ assertNotNull(integerAttribute);
+ assertNoEventNames(integerAttribute);
+ assertNoSignature(integerAttribute);
+ assertNotRequired(integerAttribute);
+
+ assertEquals(new ClassName(Integer.class), integerAttribute.getType());
+ assertEquals("-1", integerAttribute.getDefaultValue());
+ }
+
+ /**
* Checks the following conditions for attribute:<br />
* - signature is empty<br />
* - There's a single "change" event name that is not a default
event<br />
@@ -183,61 +241,6 @@
}
/**
- * Checks that method signature satisfies the following declaration:
<code>java.lang.String action()</code>
- *
- * @param actionProperty
- */
- private void checkDummyComponentAction(PropertyBase actionProperty) {
- assertNotNull(actionProperty);
- assertNoEventNames(actionProperty);
-
- assertEquals(Lists.newArrayList(), actionProperty.getSignature());
- }
-
- /**
- * Checks that method signature satisfies the following declaration:
- * <code>void actionListener(javax.faces.event.ActionEvent)</code>
- *
- * @param actionListenerProperty
- */
- private void checkDummyComponentActionListener(PropertyBase actionListenerProperty)
{
- assertNotNull(actionListenerProperty);
- assertNoEventNames(actionListenerProperty);
-
- assertEquals(Lists.newArrayList(new ClassName(ActionEvent.class)),
actionListenerProperty.getSignature());
- }
-
- /**
- * Checks that method signature satisfies the following declaration:
- * <code>float coolMethod(int, java.lang.String,
javax.faces.validator.Validator)</code>
- *
- * @param coolMethodProperty
- */
- private void checkDummyComponentCoolMethod(PropertyBase coolMethodProperty) {
- assertNotNull(coolMethodProperty);
- assertNoEventNames(coolMethodProperty);
-
- ArrayList<ClassName> expectedSignature =
- Lists.newArrayList(new ClassName(int.class), new ClassName(String.class),
- new ClassName(Validator.class));
-
- assertEquals(expectedSignature, coolMethodProperty.getSignature());
- }
-
- /**
- * @param integerAttribute
- */
- private void checkDummyComponentIntegerAttribute(PropertyBase integerAttribute) {
- assertNotNull(integerAttribute);
- assertNoEventNames(integerAttribute);
- assertNoSignature(integerAttribute);
- assertNotRequired(integerAttribute);
-
- assertEquals(new ClassName(Integer.class), integerAttribute.getType());
- assertEquals("-1", integerAttribute.getDefaultValue());
- }
-
- /**
* @param requiredAttribute
*/
private void checkDummyComponentRequiredAttribute(PropertyBase requiredAttribute) {
@@ -251,40 +254,19 @@
assertEquals("Required Attribute",
requiredAttribute.getDisplayname());
}
- private void checkDummyComponentImportedAttribute(PropertyBase importedAttribute,
Class<?> type) {
- assertNotNull(importedAttribute);
- assertNoEventNames(importedAttribute);
- assertNoSignature(importedAttribute);
- assertNoDefaultValue(importedAttribute);
- assertFalse(importedAttribute.isRequired());
-
- assertEquals(type.getName(), importedAttribute.getType().getName());
- }
-
@Test
- public void basicComponentTest() throws Exception {
- Template template =
parser.parseTemplate(getJavaFile("org/richfaces/cdk/templatecompiler/basic.template.xml"));
- assertNotNull(template);
-
- parser.mergeTemplateIntoModel(template, null);
-
- RenderKitModel renderKit =
getRenderkitFromModel(RenderKitFactory.HTML_BASIC_RENDER_KIT);
- RendererModel renderer = getFirstRendererFromRenderkit(renderKit);
-
- assertEquals(new
ClassName("org.richfaces.renderkit.html.BasicRendererImpl"), renderer
- .getRendererClass());
- assertFalse(renderer.isRendersChildren());
- }
-
- @Test
-
// TODO - fix import-attributes.
public void dummyComponentTest() throws Exception {
- expect(resolver.getExternalSubset(EasyMock.<String>
eq("cdk:root"), (String)anyObject())).andReturn(null);
- expect(resolver.resolveEntity((String)isNull(),
(String)eq("urn:resource:org/richfaces/cdk/templatecompiler/dummy-attributes.xml"))).andReturn(new
InputSource(this.getClass().getResourceAsStream("/org/richfaces/cdk/templatecompiler/dummy-attributes.xml")));
- expect(resolver.getExternalSubset(EasyMock.<String>
eq("cdk:properties"), (String)isNull())).andReturn(null);
- expect(resolver.resolveEntity((String)isNull(),
(String)eq("urn:attributes:dummy-template-props.xml"))).andReturn(new
InputSource(this.getClass().getResourceAsStream("/META-INF/cdk/attributes/dummy-template-props.xml")));
-
expect(resolver.getExternalSubset(EasyMock.<String>eq("cdk:properties"),
(String)isNull())).andReturn(null);
+ expect(resolver.getExternalSubset(EasyMock.<String>
eq("cdk:root"), (String) anyObject())).andReturn(null);
+ expect(
+ resolver.resolveEntity((String) isNull(),
+
eq("urn:resource:org/richfaces/cdk/templatecompiler/dummy-attributes.xml"))).andReturn(
+ new InputSource(this.getClass().getResourceAsStream(
+
"/org/richfaces/cdk/templatecompiler/dummy-attributes.xml")));
+ expect(resolver.getExternalSubset(EasyMock.<String>
eq("cdk:properties"), (String) isNull())).andReturn(null);
+ expect(resolver.resolveEntity((String) isNull(),
eq("urn:attributes:dummy-template-props.xml"))).andReturn(
+ new
InputSource(this.getClass().getResourceAsStream("/META-INF/cdk/attributes/dummy-template-props.xml")));
+ expect(resolver.getExternalSubset(EasyMock.<String>
eq("cdk:properties"), (String) isNull())).andReturn(null);
replay(resolver, templatesSource);
Template template =
parser.parseTemplate(getJavaFile("org/richfaces/cdk/templatecompiler/dummy.template.xml"));
@@ -296,8 +278,7 @@
RenderKitModel renderKit =
getRenderkitFromModel("org.richfaces.CUSTOM_RENDERKIT");
RendererModel renderer = getFirstRendererFromRenderkit(renderKit);
- assertEquals(new
ClassName("org.richfaces.renderkit.html.DummyRendererImpl"), renderer
- .getRendererClass());
+ assertEquals(new
ClassName("org.richfaces.renderkit.html.DummyRendererImpl"),
renderer.getRendererClass());
assertTrue(renderer.isRendersChildren());
assertEquals("org.richfaces.Dummy", renderer.getFamily());
@@ -306,29 +287,49 @@
Collection<PropertyBase> attributes = renderer.getAttributes();
assertNotNull(attributes);
- checkDummyComponentOnclick(getAttribute(attributes,"onclick"));
- checkDummyComponentOnchange(getAttribute(attributes,"onchange"));
- checkDummyComponentAction(getAttribute(attributes,"action"));
-
checkDummyComponentActionListener(getAttribute(attributes,"actionListener"));
- checkDummyComponentCoolMethod(getAttribute(attributes,"coolMethod"));
-
checkDummyComponentIntegerAttribute(getAttribute(attributes,"integerAttribute"));
-
checkDummyComponentRequiredAttribute(getAttribute(attributes,"requiredAttribute"));
+ checkDummyComponentOnclick(getAttribute(attributes, "onclick"));
+ checkDummyComponentOnchange(getAttribute(attributes, "onchange"));
+ checkDummyComponentAction(getAttribute(attributes, "action"));
+ checkDummyComponentActionListener(getAttribute(attributes,
"actionListener"));
+ checkDummyComponentCoolMethod(getAttribute(attributes, "coolMethod"));
+ checkDummyComponentIntegerAttribute(getAttribute(attributes,
"integerAttribute"));
+ checkDummyComponentRequiredAttribute(getAttribute(attributes,
"requiredAttribute"));
-
checkDummyComponentImportedAttribute(getAttribute(attributes,"anotherImportedStringProperty"),
String.class);
-
checkDummyComponentImportedAttribute(getAttribute(attributes,"anotherImportedProperty"),
Object.class);
-
checkDummyComponentImportedAttribute(getAttribute(attributes,"importedBooleanProperty"),
boolean.class);
-
checkDummyComponentImportedAttribute(getAttribute(attributes,"importedIntegerProperty"),
Integer.class);
+ checkDummyComponentImportedAttribute(getAttribute(attributes,
"anotherImportedStringProperty"), String.class);
+ checkDummyComponentImportedAttribute(getAttribute(attributes,
"anotherImportedProperty"), Object.class);
+ checkDummyComponentImportedAttribute(getAttribute(attributes,
"importedBooleanProperty"), boolean.class);
+ checkDummyComponentImportedAttribute(getAttribute(attributes,
"importedIntegerProperty"), Integer.class);
assertEquals(11, attributes.size());
}
private PropertyBase getAttribute(Collection<PropertyBase> attributes, String
string) {
for (PropertyBase property : attributes) {
- if(string.equals(property.getName())){
+ if (string.equals(property.getName())) {
return property;
}
}
return null;
}
+ private RendererModel getFirstRendererFromRenderkit(RenderKitModel renderKit) {
+ Collection<RendererModel> renderers = renderKit.getRenderers();
+ assertNotNull(renderers);
+
+ Iterator<RendererModel> renderersIterator = renderers.iterator();
+ assertTrue(renderersIterator.hasNext());
+
+ RendererModel renderer = renderersIterator.next();
+ assertNotNull(renderer);
+
+ return renderer;
+ }
+
+ private RenderKitModel getRenderkitFromModel(String renderkitId) {
+ RenderKitModel renderKit = library.getRenderKit(new FacesId(renderkitId));
+ assertNotNull(renderKit);
+
+ return renderKit;
+ }
+
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/XhtmlAttributesParsingTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/XhtmlAttributesParsingTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/XhtmlAttributesParsingTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -51,14 +51,46 @@
*/
public class XhtmlAttributesParsingTest {
- private Schema xhtmlSchema;
+ private static final class AttributeKindPredicate implements
Predicate<Attribute> {
- private void verifyAttributesByPredicate(Collection<Attribute> attributes,
Predicate<Attribute> predicate) {
- for (Attribute attribute : attributes) {
- Assert.assertTrue(attribute.getName(), predicate.apply(attribute));
+ private Kind kind;
+
+ public AttributeKindPredicate(Kind kind) {
+ super();
+ this.kind = kind;
}
+
+ @Override
+ public boolean apply(Attribute attribute) {
+ return kind.equals(attribute.getKind());
+ }
}
+ private static final class AttributeNamePredicate implements
Predicate<Attribute> {
+
+ private String name;
+
+ public AttributeNamePredicate(String name) {
+ super();
+ this.name = name;
+ }
+
+ @Override
+ public boolean apply(Attribute attribute) {
+ return name.equals(attribute.getName());
+ }
+ }
+
+ private static final class AttributeNullDataPredicate implements
Predicate<Attribute> {
+
+ @Override
+ public boolean apply(Attribute attribute) {
+ return attribute.getName() == null || attribute.getKind() == null;
+ }
+ }
+
+ private Schema xhtmlSchema;
+
private Collection<Attribute>
findAttributesByPredicate(Predicate<Attribute> predicate) {
List<Attribute> result = new ArrayList<Attribute>();
@@ -86,44 +118,6 @@
return result;
}
- private static final class AttributeNullDataPredicate implements
Predicate<Attribute> {
-
- @Override
- public boolean apply(Attribute attribute) {
- return attribute.getName() == null || attribute.getKind() == null;
- }
- }
-
- private static final class AttributeNamePredicate implements
Predicate<Attribute> {
-
- public AttributeNamePredicate(String name) {
- super();
- this.name = name;
- }
-
- private String name;
-
- @Override
- public boolean apply(Attribute attribute) {
- return name.equals(attribute.getName());
- }
- }
-
- private static final class AttributeKindPredicate implements
Predicate<Attribute> {
-
- private Kind kind;
-
- public AttributeKindPredicate(Kind kind) {
- super();
- this.kind = kind;
- }
-
- @Override
- public boolean apply(Attribute attribute) {
- return kind.equals(attribute.getKind());
- }
- }
-
@Before
public void setUp() throws Exception {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
@@ -199,4 +193,10 @@
Collection<String> requiredAttributeNames =
getNamesCollection(requiredAttributes);
System.out.println("XhtmlAttributesParsingTest.testRequiredAttributes():
" + requiredAttributeNames);
}
+
+ private void verifyAttributesByPredicate(Collection<Attribute> attributes,
Predicate<Attribute> predicate) {
+ for (Attribute attribute : attributes) {
+ Assert.assertTrue(attribute.getName(), predicate.apply(attribute));
+ }
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -39,139 +39,13 @@
*/
public class TemplateTest extends JaxbTestBase {
- private static final String TEMPLATE_EPILOG =
"</cc:implementation></cdk:root>";
- private static final String TEMPLATE_MIDDLE =
"</cc:interface><cc:implementation>";
public static final String TEMPLATE_PROLOG =
"<cdk:root
xmlns=\"http://www.w3.org/1999/xhtml\"
xmlns:cdk=\"http://richfaces.org/cdk/core\"
xmlns:c=\"http://richfaces.org/cdk/jstl/core\"
xmlns:cc=\"http://richfaces.org/cdk/jsf/composite\"><cc:i...;
private static final Object DEFAULT_ATTRIBUTE_TYPE = Object.class.getName();
+ private static final String TEMPLATE_EPILOG =
"</cc:implementation></cdk:root>";
+ private static final String TEMPLATE_MIDDLE =
"</cc:interface><cc:implementation>";
@Test
- public void testTemplate() throws Exception {
- Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
TEMPLATE_EPILOG);
- assertNotNull(template.getInterface());
- assertNotNull(template.getImplementation());
- }
-
- @Test
- public void testImpl() throws Exception {
- Template template =
- unmarshal(
- Template.class,
- TEMPLATE_PROLOG
- + TEMPLATE_MIDDLE
- + "<cdk:call
expression=\"#{cc.clientId}\"/><table
width=\"200\"><tbody><cdk:call
expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div
class='bar'>foo</div>"
- + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(4, children.size());
- assertEquals(CdkCallElement.class, children.get(0).getClass());
- assertEquals(AnyElement.class, children.get(1).getClass());
- assertEquals(String.class, children.get(2).getClass());
- }
-
- @Test
- public void testJstlCoreElements() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
"start"
- + "<c:if test=\"#{someTest}\">if
content</c:if>" + "<c:choose>"
- + "<c:when test=\"#{anotherTest}\">when
content</c:when>" + "<c:when test=\"#{coolTest}\">"
- + "<c:if test=\"#{nestedIfTest}\">nested if
content</c:if>" + "</c:when>"
- + "<c:otherwise>otherwise content</c:otherwise>" +
"</c:choose>"
- + "<c:forEach items=\"#{someCollection}\"
var=\"iterationVar\">" + "forEach content" +
"</c:forEach>"
- + "finish" + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
-
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(5, children.size());
- assertEquals("start", children.get(0));
- assertEquals(CdkIfElement.class, children.get(1).getClass());
- CdkIfElement ifElement = (CdkIfElement) children.get(1);
- assertEquals("#{someTest}", ifElement.getTest());
- List<Object> ifChildren = ifElement.getChildren();
- assertNotNull(ifChildren);
- assertEquals(1, ifChildren.size());
- assertEquals("if content", ifChildren.get(0));
-
- assertEquals(CdkChooseElement.class, children.get(2).getClass());
- CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
- List<Object> chooseChildren = chooseElement.getChildren();
- assertNotNull(chooseChildren);
- assertEquals(3, chooseChildren.size());
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
- CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
- assertEquals("#{anotherTest}", firstWhen.getTest());
- List<Object> childrenOfFirstWhen = firstWhen.getChildren();
- assertNotNull(childrenOfFirstWhen);
- assertEquals(1, childrenOfFirstWhen.size());
- assertEquals("when content", childrenOfFirstWhen.get(0));
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
- CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
- assertEquals("#{coolTest}", secondWhen.getTest());
-
- List<Object> childrenOfSecondWhen = secondWhen.getChildren();
- assertNotNull(childrenOfSecondWhen);
- assertEquals(1, childrenOfSecondWhen.size());
-
- assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
- CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
- assertEquals("#{nestedIfTest}", nestedIf.getTest());
- List<Object> childrenOfNestedIf = nestedIf.getChildren();
- assertNotNull(childrenOfNestedIf);
- assertEquals(1, childrenOfNestedIf.size());
- assertEquals("nested if content", childrenOfNestedIf.get(0));
-
- assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
- CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement)
chooseChildren.get(2);
- List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
- assertNotNull(childrenOfOtherwiseElement);
- assertEquals(1, childrenOfOtherwiseElement.size());
- assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
-
- assertEquals(CdkForEachElement.class, children.get(3).getClass());
- CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
- assertEquals("#{someCollection}", forEachElement.getItems());
- assertEquals("iterationVar", forEachElement.getVar());
-
- List<Object> forEachChildren = forEachElement.getChildren();
- assertNotNull(forEachChildren);
- assertEquals(1, forEachChildren.size());
- assertEquals("forEach content", forEachChildren.get(0));
-
- assertEquals("finish", children.get(4));
- }
-
- @Test
- public void testInterface() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG
- +
"<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
- +
"<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
- +
"<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
- +
"<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
- + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
- +
"<cdk:renders-children>false</cdk:renders-children>" +
TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- assertEquals("org.richfaces.renderkit.html.TreeRenderer",
interfaceSection.getJavaClass());
- assertEquals("org.richfaces.renderkit.TreeRendererBase",
interfaceSection.getBaseClass());
- assertEquals("org.richfaces.TreeFamily",
interfaceSection.getComponentFamily());
- assertEquals("org.richfaces.TreeRenderer",
interfaceSection.getRendererType());
- assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
- assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
-
- }
-
- @Test
public void testAttributes() throws Exception {
Template template =
unmarshal(
@@ -326,44 +200,122 @@
}
@Test
- public void testResourceDependencies() throws Exception {
+ public void testImpl() throws Exception {
Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG +
"<cdk:resource-dependencies>"
- + "<cdk:resource-dependency name=\"jquery.js\"
/>"
- + "<cdk:resource-dependency name=\"richfaces.css\"
library=\"org.richfaces\" />"
- + "<cdk:resource-dependency name=\"richfaces.js\"
library=\"org.richfaces\" target=\"body\" /> "
- + "</cdk:resource-dependencies> " +
+ unmarshal(
+ Template.class,
+ TEMPLATE_PROLOG
+ + TEMPLATE_MIDDLE
+ + "<cdk:call
expression=\"#{cc.clientId}\"/><table
width=\"200\"><tbody><cdk:call
expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div
class='bar'>foo</div>"
+ + TEMPLATE_EPILOG);
- TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(4, children.size());
+ assertEquals(CdkCallElement.class, children.get(0).getClass());
+ assertEquals(AnyElement.class, children.get(1).getClass());
+ assertEquals(String.class, children.get(2).getClass());
+ }
+ @Test
+ public void testInterface() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG
+ +
"<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
+ +
"<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
+ +
"<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
+ +
"<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
+ + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
+ +
"<cdk:renders-children>false</cdk:renders-children>" +
TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
CompositeInterface interfaceSection = template.getInterface();
assertNotNull(interfaceSection);
- assertNull(interfaceSection.getRendersChildren());
+ assertEquals("org.richfaces.renderkit.html.TreeRenderer",
interfaceSection.getJavaClass());
+ assertEquals("org.richfaces.renderkit.TreeRendererBase",
interfaceSection.getBaseClass());
+ assertEquals("org.richfaces.TreeFamily",
interfaceSection.getComponentFamily());
+ assertEquals("org.richfaces.TreeRenderer",
interfaceSection.getRendererType());
+ assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
+ assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
- List<ResourceDependency> resourceDependencies =
interfaceSection.getResourceDependencies();
- assertNotNull(resourceDependencies);
- assertEquals(3, resourceDependencies.size());
+ }
- ResourceDependency resourceDependency;
+ @Test
+ public void testJstlCoreElements() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
"start"
+ + "<c:if test=\"#{someTest}\">if
content</c:if>" + "<c:choose>"
+ + "<c:when test=\"#{anotherTest}\">when
content</c:when>" + "<c:when test=\"#{coolTest}\">"
+ + "<c:if test=\"#{nestedIfTest}\">nested if
content</c:if>" + "</c:when>"
+ + "<c:otherwise>otherwise content</c:otherwise>" +
"</c:choose>"
+ + "<c:forEach items=\"#{someCollection}\"
var=\"iterationVar\">" + "forEach content" +
"</c:forEach>"
+ + "finish" + TEMPLATE_EPILOG);
- resourceDependency = resourceDependencies.get(0);
- assertNotNull(resourceDependency);
- assertEquals("jquery.js", resourceDependency.getName());
- assertNull(resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
- resourceDependency = resourceDependencies.get(1);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.css", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(5, children.size());
+ assertEquals("start", children.get(0));
+ assertEquals(CdkIfElement.class, children.get(1).getClass());
+ CdkIfElement ifElement = (CdkIfElement) children.get(1);
+ assertEquals("#{someTest}", ifElement.getTest());
+ List<Object> ifChildren = ifElement.getChildren();
+ assertNotNull(ifChildren);
+ assertEquals(1, ifChildren.size());
+ assertEquals("if content", ifChildren.get(0));
- resourceDependency = resourceDependencies.get(2);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.js", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("body", resourceDependency.getTarget());
+ assertEquals(CdkChooseElement.class, children.get(2).getClass());
+ CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
+ List<Object> chooseChildren = chooseElement.getChildren();
+ assertNotNull(chooseChildren);
+ assertEquals(3, chooseChildren.size());
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
+ CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
+ assertEquals("#{anotherTest}", firstWhen.getTest());
+ List<Object> childrenOfFirstWhen = firstWhen.getChildren();
+ assertNotNull(childrenOfFirstWhen);
+ assertEquals(1, childrenOfFirstWhen.size());
+ assertEquals("when content", childrenOfFirstWhen.get(0));
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
+ CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
+ assertEquals("#{coolTest}", secondWhen.getTest());
+
+ List<Object> childrenOfSecondWhen = secondWhen.getChildren();
+ assertNotNull(childrenOfSecondWhen);
+ assertEquals(1, childrenOfSecondWhen.size());
+
+ assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
+ CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
+ assertEquals("#{nestedIfTest}", nestedIf.getTest());
+ List<Object> childrenOfNestedIf = nestedIf.getChildren();
+ assertNotNull(childrenOfNestedIf);
+ assertEquals(1, childrenOfNestedIf.size());
+ assertEquals("nested if content", childrenOfNestedIf.get(0));
+
+ assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
+ CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement)
chooseChildren.get(2);
+ List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
+ assertNotNull(childrenOfOtherwiseElement);
+ assertEquals(1, childrenOfOtherwiseElement.size());
+ assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
+
+ assertEquals(CdkForEachElement.class, children.get(3).getClass());
+ CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
+ assertEquals("#{someCollection}", forEachElement.getItems());
+ assertEquals("iterationVar", forEachElement.getVar());
+
+ List<Object> forEachChildren = forEachElement.getChildren();
+ assertNotNull(forEachChildren);
+ assertEquals(1, forEachChildren.size());
+ assertEquals("forEach content", forEachChildren.get(0));
+
+ assertEquals("finish", children.get(4));
}
@Test
@@ -397,4 +349,52 @@
assertEquals("java.lang.String", secondObject.getType());
assertEquals("\"test expression\" +\n\"second
line\"", secondObject.getBodyValue());
}
+
+ @Test
+ public void testResourceDependencies() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG +
"<cdk:resource-dependencies>"
+ + "<cdk:resource-dependency name=\"jquery.js\"
/>"
+ + "<cdk:resource-dependency name=\"richfaces.css\"
library=\"org.richfaces\" />"
+ + "<cdk:resource-dependency name=\"richfaces.js\"
library=\"org.richfaces\" target=\"body\" /> "
+ + "</cdk:resource-dependencies> " +
+
+ TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ assertNull(interfaceSection.getRendersChildren());
+
+ List<ResourceDependency> resourceDependencies =
interfaceSection.getResourceDependencies();
+ assertNotNull(resourceDependencies);
+ assertEquals(3, resourceDependencies.size());
+
+ ResourceDependency resourceDependency;
+
+ resourceDependency = resourceDependencies.get(0);
+ assertNotNull(resourceDependency);
+ assertEquals("jquery.js", resourceDependency.getName());
+ assertNull(resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(1);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.css", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(2);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.js", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("body", resourceDependency.getTarget());
+ }
+
+ @Test
+ public void testTemplate() throws Exception {
+ Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
TEMPLATE_EPILOG);
+ assertNotNull(template.getInterface());
+ assertNotNull(template.getImplementation());
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -45,33 +45,18 @@
components.add(value);
}
- public Bean2 getTestBean2() {
- return testBean2;
+ public Integer count(Integer i) {
+ return null;
}
- public void setTestBean2(Bean2 testBean2) {
- this.testBean2 = testBean2;
- }
-
- public void test(UIComponent comp, boolean test) {
- }
-
public UIComponent[] getArray() {
return array;
}
- public void setArray(UIComponent[] array) {
- this.array = array;
- }
-
public List<UIComponent> getComponents() {
return components;
}
- public void setComponents(List<UIComponent> components) {
- this.components = components;
- }
-
public UIComponent getFacet(String name) {
return facets.get(name);
}
@@ -80,27 +65,42 @@
return facets;
}
- public void setFacets(Map<String, UIComponent> facets) {
- this.facets = facets;
- }
-
public Map getRawMap() {
return rawMap;
}
- public void setRawMap(Map rawMap) {
- this.rawMap = rawMap;
+ public Bean2 getTestBean2() {
+ return testBean2;
}
public boolean isReadOnly() {
return readOnly;
}
+ public void setArray(UIComponent[] array) {
+ this.array = array;
+ }
+
+ public void setComponents(List<UIComponent> components) {
+ this.components = components;
+ }
+
+ public void setFacets(Map<String, UIComponent> facets) {
+ this.facets = facets;
+ }
+
+ public void setRawMap(Map rawMap) {
+ this.rawMap = rawMap;
+ }
+
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
- public Integer count(Integer i) {
- return null;
+ public void setTestBean2(Bean2 testBean2) {
+ this.testBean2 = testBean2;
}
+
+ public void test(UIComponent comp, boolean test) {
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -21,30 +21,43 @@
package org.richfaces.cdk.templatecompiler.parser.el.test;
+import static org.junit.Assert.*;
+import static org.richfaces.cdk.templatecompiler.el.HelperMethod.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.junit.After;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.EMPTINESS_CHECK;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.EQUALS_CHECK;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.TO_BOOLEAN_CONVERSION;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.TO_STRING_CONVERSION;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.Type;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
public class ELParserTest {
private ELVisitor visitor;
+ private void parseExpression(String expression) throws ParsingException {
+ parseExpression(expression, Object.class);
+ }
+
+ private void parseExpression(String expression, Class<?> returnType) throws
ParsingException {
+ Map<String, Type> contextMap = new HashMap<String, Type>();
+
+ contextMap.put("action",
TypesFactory.getType(org.richfaces.cdk.templatecompiler.parser.el.test.Bean.class));
+ contextMap.put("clientId", TypesFactory.getType(String.class));
+ contextMap.put("test", TypesFactory.getType(boolean.class));
+ contextMap.put("otherTest", TypesFactory.getType(boolean.class));
+ contextMap.put("this", TypesFactory.getType(Object.class));
+ contextMap.put("super", TypesFactory.getType(Object.class));
+ contextMap.put("objectVar", TypesFactory.getType(Object.class));
+
+ visitor.parse(expression, contextMap, TypesFactory.getType(returnType));
+ }
+
@Before
public void setUp() {
visitor = new ELVisitor();
@@ -56,126 +69,58 @@
}
@Test
- public void testNull() throws Exception {
- parseExpression("#{null}");
- assertEquals("null", visitor.getParsedExpression());
- assertTrue(visitor.getExpressionType().isNullType());
- }
+ public void testAnd() throws Exception {
+ parseExpression("#{test and otherTest}");
+ assertEquals("(test && otherTest)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- @Test
- public void testTrue() throws Exception {
- parseExpression("#{true}");
- assertEquals("true", visitor.getParsedExpression());
+ parseExpression("#{otherTest && test}");
+ assertEquals("(otherTest && test)",
visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- }
- @Test
- public void testFalse() throws Exception {
- parseExpression("#{false}");
- assertEquals("false", visitor.getParsedExpression());
+ parseExpression("#{action and otherTest}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(convertToBoolean(action) && otherTest)",
visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- }
- @Test
- public void testFloat() throws Exception {
- parseExpression("#{5.0}");
- assertEquals("Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{5.012e+34}");
- assertEquals("Double.valueOf(5.012e+34)",
visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{test && action}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(test && convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testNegative() throws Exception {
- parseExpression("#{-5}");
- assertEquals("-5", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- }
+ public void testBooleanReturnType() throws Exception {
+ parseExpression("#{clientId}", Boolean.TYPE);
- @Test
- public void testNegativeFloat() throws Exception {
- parseExpression("#{-5.0}");
- assertEquals("-Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
- }
-
- @Test
- public void testNotEqual() throws Exception {
- parseExpression("#{1 ne 3}");
- assertEquals("(1 != 3)", visitor.getParsedExpression());
+ assertEquals("convertToBoolean(clientId)",
visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- parseExpression("#{2 != 3}");
- assertEquals("(2 != 3)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{test}", Boolean.TYPE);
- parseExpression("#{action != 2}");
- assertEquals("!isEqual(action,2)", visitor.getParsedExpression());
+ assertEquals("test", visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
- parseExpression("#{2 ne action}");
- assertEquals("!isEqual(2,action)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
- parseExpression("#{action != clientId}");
- assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
- parseExpression("#{action ne clientId}");
- assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
- parseExpression("#{action ne null}");
- assertEquals("(action != null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
- parseExpression("#{2 != null}");
- assertEquals("!isEqual(2,null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ assertFalse(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
- public void testNot() throws Exception {
- parseExpression("#{not test}");
- assertEquals("(!test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ public void testChoice() throws Exception {
+ parseExpression("#{test ? 2 : 3}");
+ assertEquals("(test ? 2 : 3)", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- parseExpression("#{!otherTest}");
- assertEquals("(!otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{test ? null : 'string'}");
+ assertEquals("(test ? null : \"string\")",
visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
- parseExpression("#{!action}");
- assertEquals("(!convertToBoolean(action))",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{action ? null : 'string'}");
+ assertEquals("(convertToBoolean(action) ? null :
\"string\")", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
- public void testPlus() throws Exception {
- // TODO: tests involving double values
- parseExpression("#{1+2}");
- assertEquals("(1 + 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- }
-
- @Test
- public void testMinus() throws Exception {
- parseExpression("#{1-2}");
- assertEquals("(1 - 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- }
-
- @Test
public void testDiv() throws Exception {
parseExpression("#{1/2}");
assertEquals("(1 / 2)", visitor.getParsedExpression());
@@ -183,59 +128,18 @@
}
@Test
- public void testMult() throws Exception {
- parseExpression("#{1*2}");
- assertEquals("(1 * 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- }
-
- @Test
- public void testMod() throws Exception {
- parseExpression("#{1%2}");
- assertEquals("(1 % 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
- }
-
- @Test
- public void testAnd() throws Exception {
- parseExpression("#{test and otherTest}");
- assertEquals("(test && otherTest)",
visitor.getParsedExpression());
+ public void testEmpty() throws Exception {
+ parseExpression("#{empty action.array}");
+ assertEquals("isEmpty(action.getArray())",
visitor.getParsedExpression());
+ assertTrue(visitor.getUsedHelperMethods().contains(EMPTINESS_CHECK));
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{otherTest && test}");
- assertEquals("(otherTest && test)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{action and otherTest}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(convertToBoolean(action) && otherTest)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{test && action}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(test && convertToBoolean(action))",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testOr() throws Exception {
- parseExpression("#{test or otherTest}");
- assertEquals("(test || otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{otherTest || test}");
- assertEquals("(otherTest || test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{action or otherTest}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(convertToBoolean(action) || otherTest)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{test || action}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(test || convertToBoolean(action))",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ public void testEmptyString() throws Exception {
+ parseExpression("");
+ assertEquals("\"\"", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
@@ -254,7 +158,7 @@
assertEquals("isEqual(action,2)", visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
-
+
parseExpression("#{2 eq action}");
assertEquals("isEqual(2,action)", visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
@@ -282,6 +186,31 @@
}
@Test
+ public void testFalse() throws Exception {
+ parseExpression("#{false}");
+ assertEquals("false", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testFloat() throws Exception {
+ parseExpression("#{5.0}");
+ assertEquals("Double.valueOf(5.0)", visitor.getParsedExpression());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{5.012e+34}");
+ assertEquals("Double.valueOf(5.012e+34)",
visitor.getParsedExpression());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testFunction() throws Exception {
+ parseExpression("#{super:getType()}");
+ assertEquals("super.getType()", visitor.getParsedExpression());
+ Type variableType = visitor.getExpressionType();
+ }
+
+ @Test
public void testGreatThen() throws Exception {
parseExpression("#{1 gt 2}");
assertEquals("(1 > 2)", visitor.getParsedExpression());
@@ -293,6 +222,31 @@
}
@Test
+ public void testGreatThenEquals() throws Exception {
+ parseExpression("#{1 ge 2}");
+ assertEquals("(1 >= 2)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{3 >= 2}");
+ assertEquals("(3 >= 2)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testIdentifier() throws Exception {
+ parseExpression("#{clientId}");
+ assertEquals("clientId", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testInteger() throws Exception {
+ parseExpression("#{152}");
+ assertEquals("152", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
public void testLessThen() throws Exception {
parseExpression("#{1 lt 2}");
assertEquals("(1 < 2)", visitor.getParsedExpression());
@@ -315,80 +269,79 @@
}
@Test
- public void testGreatThenEquals() throws Exception {
- parseExpression("#{1 ge 2}");
- assertEquals("(1 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
-
- parseExpression("#{3 >= 2}");
- assertEquals("(3 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ public void testLiteral() throws Exception {
+ parseExpression("clientId");
+ assertEquals("\"clientId\"", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
- public void testChoice() throws Exception {
- parseExpression("#{test ? 2 : 3}");
- assertEquals("(test ? 2 : 3)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ public void testLiteralWithDeferred() throws Exception {
+ parseExpression("#{1}#{2}");
+ assertEquals("convertToString(1) + convertToString(2)",
visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
- parseExpression("#{test ? null : 'string'}");
- assertEquals("(test ? null : \"string\")",
visitor.getParsedExpression());
+ parseExpression("abs #{getType()}");
+ assertEquals("\"abs \" + convertToString(this.getType())",
visitor.getParsedExpression());
assertEquals(String.class, visitor.getExpressionType().getRawType());
+ }
- parseExpression("#{action ? null : 'string'}");
- assertEquals("(convertToBoolean(action) ? null :
\"string\")", visitor.getParsedExpression());
+ @Test
+ public void testLiteralWithDeferred2() throws Exception {
+ parseExpression("#{getType()} abs ");
+ assertEquals("convertToString(this.getType()) + \" abs \"",
visitor.getParsedExpression());
assertEquals(String.class, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
- public void testInteger() throws Exception {
- parseExpression("#{152}");
- assertEquals("152", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ public void testMethod() throws Exception {
+ parseExpression("#{action.readOnly}");
+ assertEquals("action.isReadOnly()", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testString() throws Exception {
- parseExpression("#{\"nabc\"}");
- assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ public void testMethodReturnArray() throws Exception {
+ parseExpression("#{action.array}");
+ assertEquals("action.getArray()", visitor.getParsedExpression());
+ assertEquals(UIComponent[].class, visitor.getExpressionType().getRawType());
+ }
- parseExpression("#{'nabc'}");
- assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testMethodReturnArrayElement() throws Exception {
+ parseExpression("#{action.array[0]}");
+ assertEquals("action.getArray()[0]", visitor.getParsedExpression());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ }
- parseExpression("#{'\tabc'}");
- assertEquals("\"\\tabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
-
- parseExpression("#{'/nabc'}");
- assertEquals("\"/nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
-
- parseExpression("#{'na\"bc'}");
- assertEquals("\"na\\\"bc\"",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
-
- parseExpression("#{'na\\\\bc'}");
- assertEquals("\"na\\\\bc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testMethodReturnList() throws Exception {
+ parseExpression("#{action.components}");
+ assertEquals("action.getComponents()", visitor.getParsedExpression());
+ Type variableType = visitor.getExpressionType();
+ assertEquals(List.class, variableType.getRawType());
+ assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
}
@Test
- public void testIdentifier() throws Exception {
- parseExpression("#{clientId}");
- assertEquals("clientId", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ public void testMethodReturnListElement() throws Exception {
+ parseExpression("#{action.components[0]}");
+ assertEquals("action.getComponents().get(0)",
visitor.getParsedExpression());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
}
@Test
- public void testLiteral() throws Exception {
- parseExpression("clientId");
- assertEquals("\"clientId\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ public void testMethodReturnListElement2() throws Exception {
+ parseExpression("#{action.components[0].rendered}");
+ assertEquals("action.getComponents().get(0).isRendered()",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
+ // @Test
+ // public void testMethodReturnMapElement1() throws Exception {
+ // assertEquals("action.getFacets().get(\"header\")",
resolveExpression("#{action.facets.header}"));
+ // }
+
@Test
public void testMethodReturnMap() throws Exception {
parseExpression("#{action.facets}");
@@ -416,11 +369,6 @@
assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
- // @Test
- // public void testMethodReturnMapElement1() throws Exception {
- // assertEquals("action.getFacets().get(\"header\")",
resolveExpression("#{action.facets.header}"));
- // }
-
@Test
public void testMethodReturnMapElement2() throws Exception {
parseExpression("#{action.facets.toString()}");
@@ -438,104 +386,206 @@
}
@Test
- public void testMethod() throws Exception {
- parseExpression("#{action.readOnly}");
- assertEquals("action.isReadOnly()", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ public void testMethodWithParam() throws Exception {
+ parseExpression("#{getType(action.array[0].rendered, action.readOnly,
true)}");
+
assertEquals("this.getType(action.getArray()[0].isRendered(),action.isReadOnly(),true)",
visitor
+ .getParsedExpression());
+
+ Type variableType = visitor.getExpressionType();
+
+ parseExpression("#{action.count(123)}");
+ assertEquals("action.count(123)", visitor.getParsedExpression());
+ assertEquals(Integer.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action.count(clientId)}");
+ assertEquals("action.count(clientId)", visitor.getParsedExpression());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
@Test
- public void testNestedMethod() throws Exception {
- parseExpression("#{action.testBean2.string}");
- assertEquals("action.getTestBean2().getString()",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ public void testMinus() throws Exception {
+ parseExpression("#{1-2}");
+ assertEquals("(1 - 2)", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodReturnList() throws Exception {
- parseExpression("#{action.components}");
- assertEquals("action.getComponents()", visitor.getParsedExpression());
- Type variableType = visitor.getExpressionType();
- assertEquals(List.class, variableType.getRawType());
- assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ public void testMod() throws Exception {
+ parseExpression("#{1%2}");
+ assertEquals("(1 % 2)", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodReturnListElement() throws Exception {
- parseExpression("#{action.components[0]}");
- assertEquals("action.getComponents().get(0)",
visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ public void testMult() throws Exception {
+ parseExpression("#{1*2}");
+ assertEquals("(1 * 2)", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodReturnListElement2() throws Exception {
- parseExpression("#{action.components[0].rendered}");
- assertEquals("action.getComponents().get(0).isRendered()",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ public void testNegative() throws Exception {
+ parseExpression("#{-5}");
+ assertEquals("-5", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodReturnArray() throws Exception {
- parseExpression("#{action.array}");
- assertEquals("action.getArray()", visitor.getParsedExpression());
- assertEquals(UIComponent[].class, visitor.getExpressionType().getRawType());
+ public void testNegativeFloat() throws Exception {
+ parseExpression("#{-5.0}");
+ assertEquals("-Double.valueOf(5.0)", visitor.getParsedExpression());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodReturnArrayElement() throws Exception {
- parseExpression("#{action.array[0]}");
- assertEquals("action.getArray()[0]", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ public void testNestedMethod() throws Exception {
+ parseExpression("#{action.testBean2.string}");
+ assertEquals("action.getTestBean2().getString()",
visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
- public void testMethodWithParam() throws Exception {
- parseExpression("#{getType(action.array[0].rendered, action.readOnly,
true)}");
-
assertEquals("this.getType(action.getArray()[0].isRendered(),action.isReadOnly(),true)",
visitor
- .getParsedExpression());
+ public void testNonExistingMethod() throws Exception {
+ parseExpression("#{action.doSomething(clientId, 123)}");
+ assertEquals("action.doSomething(clientId,123)",
visitor.getParsedExpression());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ }
- Type variableType = visitor.getExpressionType();
+ @Test
+ public void testNot() throws Exception {
+ parseExpression("#{not test}");
+ assertEquals("(!test)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- parseExpression("#{action.count(123)}");
- assertEquals("action.count(123)", visitor.getParsedExpression());
- assertEquals(Integer.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{!otherTest}");
+ assertEquals("(!otherTest)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- parseExpression("#{action.count(clientId)}");
- assertEquals("action.count(clientId)", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{!action}");
+ assertEquals("(!convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
- public void testEmpty() throws Exception {
- parseExpression("#{empty action.array}");
- assertEquals("isEmpty(action.getArray())",
visitor.getParsedExpression());
- assertTrue(visitor.getUsedHelperMethods().contains(EMPTINESS_CHECK));
+ public void testNotEqual() throws Exception {
+ parseExpression("#{1 ne 3}");
+ assertEquals("(1 != 3)", visitor.getParsedExpression());
assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{2 != 3}");
+ assertEquals("(2 != 3)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{action != 2}");
+ assertEquals("!isEqual(action,2)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{2 ne action}");
+ assertEquals("!isEqual(2,action)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{action != clientId}");
+ assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{action ne clientId}");
+ assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{action ne null}");
+ assertEquals("(action != null)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+
+ parseExpression("#{2 != null}");
+ assertEquals("!isEqual(2,null)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
}
@Test
- public void testFunction() throws Exception {
- parseExpression("#{super:getType()}");
- assertEquals("super.getType()", visitor.getParsedExpression());
- Type variableType = visitor.getExpressionType();
+ public void testNull() throws Exception {
+ parseExpression("#{null}");
+ assertEquals("null", visitor.getParsedExpression());
+ assertTrue(visitor.getExpressionType().isNullType());
}
@Test
- public void testLiteralWithDeferred() throws Exception {
- parseExpression("#{1}#{2}");
- assertEquals("convertToString(1) + convertToString(2)",
visitor.getParsedExpression());
+ public void testOr() throws Exception {
+ parseExpression("#{test or otherTest}");
+ assertEquals("(test || otherTest)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{otherTest || test}");
+ assertEquals("(otherTest || test)", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action or otherTest}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(convertToBoolean(action) || otherTest)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{test || action}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(test || convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testPlus() throws Exception {
+ // TODO: tests involving double values
+ parseExpression("#{1+2}");
+ assertEquals("(1 + 2)", visitor.getParsedExpression());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
+ public void testString() throws Exception {
+ parseExpression("#{\"nabc\"}");
+ assertEquals("\"nabc\"", visitor.getParsedExpression());
assertEquals(String.class, visitor.getExpressionType().getRawType());
- parseExpression("abs #{getType()}");
- assertEquals("\"abs \" + convertToString(this.getType())",
visitor.getParsedExpression());
+ parseExpression("#{'nabc'}");
+ assertEquals("\"nabc\"", visitor.getParsedExpression());
assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{'\tabc'}");
+ assertEquals("\"\\tabc\"", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{'/nabc'}");
+ assertEquals("\"/nabc\"", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{'na\"bc'}");
+ assertEquals("\"na\\\"bc\"",
visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{'na\\\\bc'}");
+ assertEquals("\"na\\\\bc\"", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
- public void testLiteralWithDeferred2() throws Exception {
- parseExpression("#{getType()} abs ");
- assertEquals("convertToString(this.getType()) + \" abs \"",
visitor.getParsedExpression());
+ public void testStringReturnType() throws Exception {
+ parseExpression("#{clientId}", String.class);
+
+ assertEquals("clientId", visitor.getParsedExpression());
assertEquals(String.class, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
+
+ parseExpression("#{test}", String.class);
+
+ assertEquals("convertToString(test)", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
}
@Test
@@ -549,6 +599,13 @@
}
@Test
+ public void testTrue() throws Exception {
+ parseExpression("#{true}");
+ assertEquals("true", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ }
+
+ @Test
public void testVariableFunction() throws Exception {
parseExpression("#{objectVar.getType()}");
assertEquals("objectVar.getType()", visitor.getParsedExpression());
@@ -556,13 +613,6 @@
}
@Test
- public void testNonExistingMethod() throws Exception {
- parseExpression("#{action.doSomething(clientId, 123)}");
- assertEquals("action.doSomething(clientId,123)",
visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
- }
-
- @Test
public void testWrongExpression() throws Exception {
try {
parseExpression("#{bean.property}");
@@ -579,59 +629,4 @@
assertEquals("action.getProperty()", visitor.getParsedExpression());
assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
-
- @Test
- public void testEmptyString() throws Exception {
- parseExpression("");
- assertEquals("\"\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
- }
-
- @Test
- public void testBooleanReturnType() throws Exception {
- parseExpression("#{clientId}", Boolean.TYPE);
-
- assertEquals("convertToBoolean(clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
-
- parseExpression("#{test}", Boolean.TYPE);
-
- assertEquals("test", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- }
-
- @Test
- public void testStringReturnType() throws Exception {
- parseExpression("#{clientId}", String.class);
-
- assertEquals("clientId", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
-
- parseExpression("#{test}", String.class);
-
- assertEquals("convertToString(test)", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
- }
-
- private void parseExpression(String expression) throws ParsingException {
- parseExpression(expression, Object.class);
- }
-
- private void parseExpression(String expression, Class<?> returnType) throws
ParsingException {
- Map<String, Type> contextMap = new HashMap<String, Type>();
-
- contextMap.put("action",
TypesFactory.getType(org.richfaces.cdk.templatecompiler.parser.el.test.Bean.class));
- contextMap.put("clientId", TypesFactory.getType(String.class));
- contextMap.put("test", TypesFactory.getType(boolean.class));
- contextMap.put("otherTest", TypesFactory.getType(boolean.class));
- contextMap.put("this", TypesFactory.getType(Object.class));
- contextMap.put("super", TypesFactory.getType(Object.class));
- contextMap.put("objectVar", TypesFactory.getType(Object.class));
-
- visitor.parse(expression, contextMap, TypesFactory.getType(returnType));
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -40,40 +40,58 @@
private static final class ParameterizedTypesHolder {
@SuppressWarnings("unused")
- public Map<String, Object> getMap() {
+ public List<String>[] getArray() {
return null;
}
@SuppressWarnings("unused")
- public List<String>[] getArray() {
+ public Map<String, Object> getMap() {
return null;
}
@SuppressWarnings("unused")
- public List<? extends String> getWildcardList() {
+ public <Abc> Abc getTypeVariableList() {
return null;
}
@SuppressWarnings("unused")
- public <Abc> Abc getTypeVariableList() {
+ public List<? extends String> getWildcardList() {
return null;
}
}
+ private java.lang.reflect.Type getParameterizedArrayType() throws Exception {
+ return
ParameterizedTypesHolder.class.getMethod("getArray").getGenericReturnType();
+ }
+
private java.lang.reflect.Type getParameterizedMapType() throws Exception {
return
ParameterizedTypesHolder.class.getMethod("getMap").getGenericReturnType();
}
- private java.lang.reflect.Type getParameterizedArrayType() throws Exception {
- return
ParameterizedTypesHolder.class.getMethod("getArray").getGenericReturnType();
+ private java.lang.reflect.Type getTypeVariableType() throws Exception {
+ return
ParameterizedTypesHolder.class.getMethod("getTypeVariableList").getGenericReturnType();
}
private java.lang.reflect.Type getWildcardType() throws Exception {
return
ParameterizedTypesHolder.class.getMethod("getWildcardList").getGenericReturnType();
}
- private java.lang.reflect.Type getTypeVariableType() throws Exception {
- return
ParameterizedTypesHolder.class.getMethod("getTypeVariableList").getGenericReturnType();
+ @Test
+ public void testCaching() throws Exception {
+ Type objectType = TypesFactory.getType(Object.class);
+ Type objectType2 = TypesFactory.getType(Object.class);
+
+ assertNotNull(objectType);
+ assertNotNull(objectType2);
+
+ assertSame(objectType, objectType2);
+
+ TypesFactory.clearCaches();
+
+ Type objectType3 = TypesFactory.getType(Object.class);
+ assertNotNull(objectType3);
+
+ assertNotSame(objectType, objectType3);
}
@Test
@@ -204,24 +222,6 @@
}
@Test
- public void testCaching() throws Exception {
- Type objectType = TypesFactory.getType(Object.class);
- Type objectType2 = TypesFactory.getType(Object.class);
-
- assertNotNull(objectType);
- assertNotNull(objectType2);
-
- assertSame(objectType, objectType2);
-
- TypesFactory.clearCaches();
-
- Type objectType3 = TypesFactory.getType(Object.class);
- assertNotNull(objectType3);
-
- assertNotSame(objectType, objectType3);
- }
-
- @Test
public void testReferencedType() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
String className = "some.not.available.Class";
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/util/ComparatorUtilsTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/util/ComparatorUtilsTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/util/ComparatorUtilsTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -26,7 +26,6 @@
import org.junit.Test;
-
/**
* @author Nick Belaevski
*
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -1,27 +1,68 @@
package org.richfaces.cdk.xmlconfig;
-import com.google.common.collect.ImmutableList;
-import com.google.inject.Binder;
-import com.google.inject.Inject;
import static org.easymock.EasyMock.*;
-import static org.junit.Assert.assertNotNull;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.richfaces.cdk.*;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.xml.sax.InputSource;
+import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
-import java.net.MalformedURLException;
+import java.net.URLConnection;
import java.net.URLStreamHandler;
-import java.net.URLConnection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkClassLoader;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.Source;
+import org.richfaces.cdk.Sources;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.xml.sax.InputSource;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+
@RunWith(CdkTestRunner.class)
public class CdkResolverTest extends CdkTestBase {
+ private class MyURLConnection extends URLConnection {
+
+ private InputStream inputStream;
+
+ MyURLConnection(URL u, InputStream inputStream) {
+ super(u);
+ this.inputStream = inputStream;
+ }
+
+ @Override
+ public void connect() throws IOException {
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return this.inputStream;
+ }
+ }
+
+ private class MyURLStreamHandler extends URLStreamHandler {
+
+ private InputStream inputStream;
+
+ MyURLStreamHandler(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
+
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new MyURLConnection(u, inputStream);
+ }
+ }
+
private static final String TEST_HTML = "org/richfaces/cdk/apt/test.html";
@Inject
@@ -43,14 +84,6 @@
new
CdkClassLoader(ImmutableList.of(getLibraryFile("test.source.properties"),
getLibraryFile(JsfComponent.class)), null) {
@Override
- public InputStream getResourceAsStream(String name) {
- if ("foo/bar.xml".equals(name)) {
- return getBarXmlStream();
- } else {
- return super.getResourceAsStream(name);
- }
- }
-
public URL getResource(String name) {
if ("foo/bar.xml".equals(name)) {
try {
@@ -65,6 +98,15 @@
}
}
+ @Override
+ public InputStream getResourceAsStream(String name) {
+ if ("foo/bar.xml".equals(name)) {
+ return getBarXmlStream();
+ } else {
+ return super.getResourceAsStream(name);
+ }
+ }
+
};
binder.bind(CdkClassLoader.class).toInstance(classLoader);
} catch (Exception e) {
@@ -72,16 +114,20 @@
}
}
- private ByteArrayInputStream getBarXmlStream() {
- return new ByteArrayInputStream("baz".getBytes());
+ @Test
+ public void testGetProjectInputSource() throws Exception {
+ expect(facesConfigSource.getFile(TEST_HTML)).andReturn(getJavaFile(TEST_HTML));
+ replay(facesConfigSource, templatesSource);
+ InputSource input = entityResolver.getProjectInputSource(facesConfigSource,
TEST_HTML);
+ verify(facesConfigSource, templatesSource);
+ assertNotNull(input);
}
@Test
- public void testResolveSystemIdSystem() throws Exception {
+ public void testResolveSystemIdAttributes() throws Exception {
replay(facesConfigSource, templatesSource);
-
- InputSource input =
entityResolver.resolveSystemId("http://java.sun.com/xml/ns/javaee/we...;
+ InputSource input =
entityResolver.resolveSystemId("urn:attributes:test-props.xml");
verify(facesConfigSource, templatesSource);
assertNotNull(input);
}
@@ -95,54 +141,16 @@
}
@Test
- public void testResolveSystemIdAttributes() throws Exception {
+ public void testResolveSystemIdSystem() throws Exception {
replay(facesConfigSource, templatesSource);
- InputSource input =
entityResolver.resolveSystemId("urn:attributes:test-props.xml");
- verify(facesConfigSource, templatesSource);
- assertNotNull(input);
- }
- @Test
- public void testGetProjectInputSource() throws Exception {
- expect(facesConfigSource.getFile(TEST_HTML)).andReturn(getJavaFile(TEST_HTML));
- replay(facesConfigSource, templatesSource);
- InputSource input = entityResolver.getProjectInputSource(facesConfigSource,
TEST_HTML);
+ InputSource input =
entityResolver.resolveSystemId("http://java.sun.com/xml/ns/javaee/we...;
verify(facesConfigSource, templatesSource);
assertNotNull(input);
}
-
- private class MyURLConnection extends URLConnection {
-
- private InputStream inputStream;
-
- @Override
- public void connect() throws IOException {
- }
-
- MyURLConnection(URL u, InputStream inputStream) {
- super(u);
- this.inputStream = inputStream;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- return this.inputStream;
- }
+ private ByteArrayInputStream getBarXmlStream() {
+ return new ByteArrayInputStream("baz".getBytes());
}
-
- private class MyURLStreamHandler extends URLStreamHandler {
-
- private InputStream inputStream;
-
- MyURLStreamHandler(InputStream inputStream) {
- this.inputStream = inputStream;
- }
-
- @Override
- protected URLConnection openConnection(URL u) throws IOException {
- return new MyURLConnection(u, inputStream);
- }
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -1,8 +1,9 @@
package org.richfaces.cdk.xmlconfig;
-import com.google.common.collect.Iterables;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+
import org.junit.Test;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentModel;
@@ -12,7 +13,7 @@
import org.richfaces.cdk.xmlconfig.model.ComponentBean;
import org.richfaces.cdk.xmlconfig.model.ComponentBean.ComponentExtension;
-import java.util.Collection;
+import com.google.common.collect.Iterables;
public class ComponentAdapterTest {
private static final String BAZ = "baz";
@@ -22,7 +23,6 @@
private static final String FOO_UI_BAR = "foo.UIBar";
@Test
-
public void testComponentAdapter() throws Exception {
ComponentModel component = new ComponentModel(FacesId.parseId(FOO_BAR));
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,11 +23,11 @@
package org.richfaces.cdk.xmlconfig;
-import com.google.common.collect.Iterables;
-import com.google.inject.Binder;
-import com.google.inject.Inject;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.List;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.As;
@@ -45,11 +45,11 @@
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.xmlconfig.model.FacesConfigBean;
-import org.richfaces.cdk.xmlconfig.model.RenderKitBean;
import org.xml.sax.ext.EntityResolver2;
-import java.util.Collection;
-import java.util.List;
+import com.google.common.collect.Iterables;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -62,24 +62,24 @@
public class FacesConfigTest extends CdkTestBase {
@Inject
+ @As(JAXBBinding.class)
+ JAXB jaxbBinding;
+
+ @Inject
FragmentParser parser;
@Inject
@As(CdkEntityResolver.class)
EntityResolver2 resolver;
- @Inject
- @As(JAXBBinding.class)
- JAXB jaxbBinding;
+ @Mock
+ @Source(Sources.FACES_CONFIGS)
+ private FileManager configSource;
@Mock
@Source(Sources.RENDERER_TEMPLATES)
private FileManager templatesSource;
- @Mock
- @Source(Sources.FACES_CONFIGS)
- private FileManager configSource;
-
@Override
public void configure(Binder binder) {
super.configure(binder);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -23,11 +23,11 @@
package org.richfaces.cdk.xmlconfig;
-import com.google.common.collect.Iterables;
-import com.google.inject.Binder;
-import com.google.inject.Inject;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.List;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.As;
@@ -42,9 +42,9 @@
import org.richfaces.cdk.model.PropertyBase;
import org.xml.sax.ext.EntityResolver2;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
+import com.google.common.collect.Iterables;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -57,24 +57,24 @@
public class FragmentParserTest extends CdkTestBase {
@Inject
+ @As(JAXBBinding.class)
+ JAXB binder;
+
+ @Inject
FragmentParser parser;
@Inject
@As(CdkEntityResolver.class)
EntityResolver2 resolver;
- @Inject
- @As(JAXBBinding.class)
- JAXB binder;
+ @Mock
+ @Source(Sources.FACES_CONFIGS)
+ private FileManager configSource;
@Mock
@Source(Sources.RENDERER_TEMPLATES)
private FileManager templatesSource;
- @Mock
- @Source(Sources.FACES_CONFIGS)
- private FileManager configSource;
-
@Override
public void configure(Binder binder) {
super.configure(binder);
@@ -82,30 +82,21 @@
}
@Test
- public void parserTest() throws Exception {
+ public void nestedXincludeTest() throws Exception {
Collection<PropertyBase> properties =
-
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/fragment.xml");
+
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent2.xml");
- assertEquals(3, properties.size());
- }
-
- @Test
- public void xincludeTest() throws Exception {
-
- Collection<PropertyBase> properties =
-
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent.xml");
-
assertEquals(2, properties.size());
}
@Test
- public void nestedXincludeTest() throws Exception {
+ public void parserTest() throws Exception {
Collection<PropertyBase> properties =
-
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent2.xml");
+
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/fragment.xml");
- assertEquals(2, properties.size());
+ assertEquals(3, properties.size());
}
@Test
@@ -117,7 +108,7 @@
assertEquals(1, properties.size());
PropertyBase property = Iterables.getOnlyElement(properties);
- assertEquals("ontest2",property.getName());
+ assertEquals("ontest2", property.getName());
assertEquals("int", property.getType().getName());
assertEquals("test2 property", property.getDescription());
@@ -137,8 +128,17 @@
assertEquals(2, signature.size());
- String alias = property.getAliasFor();
+ String alias = property.getAliasFor();
assertEquals("bar", alias);
}
+
+ @Test
+ public void xincludeTest() throws Exception {
+
+ Collection<PropertyBase> properties =
+
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent.xml");
+
+ assertEquals(2, properties.size());
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -10,6 +10,14 @@
public abstract class JaxbTestBase extends CdkTestBase {
protected static final String XML_PROLOG = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n";
+ protected <T> String marshal(T root) {
+ ByteArrayOutputStream xml = new ByteArrayOutputStream();
+
+ JAXB.marshal(root, xml);
+
+ return new String(xml.toByteArray());
+ }
+
protected <T> T unmarshal(Class<T> type, String src) {
StringBuilder xml = new StringBuilder(XML_PROLOG);
@@ -20,12 +28,4 @@
return result;
}
-
- protected <T> String marshal(T root) {
- ByteArrayOutputStream xml = new ByteArrayOutputStream();
-
- JAXB.marshal(root, xml);
-
- return new String(xml.toByteArray());
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbUnmarshalTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbUnmarshalTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbUnmarshalTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -40,26 +40,27 @@
*/
public class JaxbUnmarshalTest extends JaxbTestBase {
@Test
- public void testRootElement() throws Exception {
+ public void testExtensions() throws Exception {
Root root =
unmarshal(
Root.class,
- "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value></children></root-config>");
+ "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value><extension><e:myExtension
xmlns:e=\"http://foo.bar/extensions\">eee</e:myExtension><s:foo
xmlns:s=\"urn:foo\">foo</s:foo></extension></children></root-config>");
+ Set<Child> children = root.getChildren();
- assertEquals("foo", root.getName());
+ assertEquals(1, children.size());
- Set<Child> children = root.getChildren();
+ Child child = children.iterator().next();
- assertEquals(1, children.size());
- assertEquals("xxx", children.iterator().next().getId());
+ assertEquals(1, child.getExtension().getExtensions().size());
+ assertEquals("eee", child.getWrapped());
}
@Test
- public void testUniqueElement() throws Exception {
+ public void testRootElement() throws Exception {
Root root =
unmarshal(
Root.class,
- "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value></children><children><id>xxx</id><value>baz</value></children></root-config>");
+ "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value></children></root-config>");
assertEquals("foo", root.getName());
@@ -70,18 +71,17 @@
}
@Test
- public void testExtensions() throws Exception {
+ public void testUniqueElement() throws Exception {
Root root =
unmarshal(
Root.class,
- "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value><extension><e:myExtension
xmlns:e=\"http://foo.bar/extensions\">eee</e:myExtension><s:foo
xmlns:s=\"urn:foo\">foo</s:foo></extension></children></root-config>");
+ "<root-config xmlns='http://foo.bar/schema'
><name>foo</name><children><id>xxx</id><value>bar</value></children><children><id>xxx</id><value>baz</value></children></root-config>");
+
+ assertEquals("foo", root.getName());
+
Set<Child> children = root.getChildren();
assertEquals(1, children.size());
-
- Child child = children.iterator().next();
-
- assertEquals(1, child.getExtension().getExtensions().size());
- assertEquals("eee", child.getWrapped());
+ assertEquals("xxx", children.iterator().next().getId());
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,6 +22,8 @@
package org.richfaces.cdk.xmlconfig;
+import java.util.Set;
+
import org.junit.Test;
import org.richfaces.cdk.generate.taglib.TaglibGeneratorVisitor;
import org.richfaces.cdk.model.ClassName;
@@ -32,8 +34,6 @@
import org.richfaces.cdk.model.Taglib;
import org.richfaces.cdk.model.ValidatorModel;
-import java.util.Set;
-
/**
* @author akolonitsky
* @since Feb 3, 2010
@@ -61,23 +61,23 @@
taglib.setUri("http://foo.bar/a4j");
library.setTaglib(taglib);
TaglibGeneratorVisitor visitor = new TaglibGeneratorVisitor();
- library.accept(visitor,library);
-// visitor.generate();
+ library.accept(visitor, library);
+ // visitor.generate();
// TODO validate result
}
+ private PropertyBase addAttribute(ValidatorModel validator, String attributeName,
Class<?> type, boolean generate) {
+ PropertyBase attribute = validator.getOrCreateAttribute(attributeName);
+ attribute.setType(new ClassName(type));
+ attribute.setGenerate(generate);
+ return attribute;
+ }
+
private EventName getEvent(String name, boolean defaultEvent) {
EventName event = new EventName();
event.setName(name);
event.setDefaultEvent(defaultEvent);
return event;
}
-
- private PropertyBase addAttribute(ValidatorModel validator, String attributeName,
Class<?> type, boolean generate) {
- PropertyBase attribute = validator.getOrCreateAttribute(attributeName);
- attribute.setType(new ClassName(type));
- attribute.setGenerate(generate);
- return attribute;
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/XmlTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -21,21 +21,26 @@
package org.richfaces.cdk.xmlconfig;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.transform.stream.StreamResult;
+
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Validator;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Assert;
import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.xmlconfig.model.FacesConfigAdapter;
-import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.CdkTestRunner;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import javax.xml.transform.stream.StreamResult;
-import java.io.*;
-
import com.google.inject.Inject;
/**
@@ -45,32 +50,13 @@
@RunWith(CdkTestRunner.class)
public abstract class XmlTest extends JaxbTestBase {
- static {
- XMLUnit.setControlEntityResolver(new CdkEntityResolver());
- }
-
@Inject
protected Logger log;
- protected void validateXml(StringWriter facesConfig, String schemaLocation) throws
SAXException, IOException {
- InputSource is = new InputSource(new StringReader(facesConfig.toString()));
- Validator validator = new Validator(is);
- validator.useXMLSchema(true);
- InputSource source = new CdkEntityResolver()
- .resolveEntity(null, schemaLocation);
- validator.setJAXP12SchemaSource(source);
-
- validator.assertIsValid();
+ static {
+ XMLUnit.setControlEntityResolver(new CdkEntityResolver());
}
- protected void validateXml(StringWriter facesConfig) throws SAXException, IOException
{
- validateXml(facesConfig, ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION);
- }
-
- protected void validateTaglib(StringWriter facesConfig) throws SAXException,
IOException {
- validateXml(facesConfig, ComponentLibrary.TAGLIB_SCHEMA_LOCATION);
- }
-
protected void checkXmlStructure(StringWriter writer) throws SAXException,
IOException {
Class<?> testClass = this.getClass();
InputStream expectedFacesConfigFile =
testClass.getResourceAsStream(testClass.getSimpleName() + ".xml");
@@ -78,9 +64,7 @@
return;
}
XMLUnit.setNormalizeWhitespace(true);
- Diff xmlDiff = new Diff(
- new StringReader(writer.toString()),
- new InputStreamReader(expectedFacesConfigFile));
+ Diff xmlDiff = new Diff(new StringReader(writer.toString()), new
InputStreamReader(expectedFacesConfigFile));
Assert.assertTrue("XML was not similar:" + xmlDiff.toString(),
xmlDiff.similar());
}
@@ -90,8 +74,26 @@
StreamResult result = new StreamResult(writer);
JAXBBinding jaxbBinding = new JAXBBinding();
- jaxbBinding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION,
- new FacesConfigAdapter().marshal(library));
+ jaxbBinding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION, new
FacesConfigAdapter()
+ .marshal(library));
return writer;
}
+
+ protected void validateTaglib(StringWriter facesConfig) throws SAXException,
IOException {
+ validateXml(facesConfig, ComponentLibrary.TAGLIB_SCHEMA_LOCATION);
+ }
+
+ protected void validateXml(StringWriter facesConfig) throws SAXException, IOException
{
+ validateXml(facesConfig, ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION);
+ }
+
+ protected void validateXml(StringWriter facesConfig, String schemaLocation) throws
SAXException, IOException {
+ InputSource is = new InputSource(new StringReader(facesConfig.toString()));
+ Validator validator = new Validator(is);
+ validator.useXMLSchema(true);
+ InputSource source = new CdkEntityResolver().resolveEntity(null,
schemaLocation);
+ validator.setJAXP12SchemaSource(source);
+
+ validator.assertIsValid();
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -22,17 +22,17 @@
package org.richfaces.cdk.xmlconfig.testmodel;
+import java.io.StringWriter;
+
import org.junit.Test;
+import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
-import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.xmlconfig.XmlTest;
-import java.io.StringWriter;
-
/**
* @author akolonitsky
* @since Jan 21, 2010
@@ -58,7 +58,7 @@
// Jaxb marshaling
StringWriter facesConfig = generateFacesConfig(library);
log.debug(facesConfig.toString());
-
+
// Checks
checkXmlStructure(facesConfig);
validateXml(facesConfig);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Child.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Child.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Child.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -42,53 +42,108 @@
*/
@XmlType(name = "ChildType", namespace = Root.HTTP_FOO_BAR_SCHEMA)
public class Child implements Id {
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+ public static class Extension {
+ private List<Element> extensions = new ArrayList<Element>();
+ private Child parent;
+
+ // This method is called after all the properties (except IDREF) are unmarshalled
for this object,
+ // but before this object is set to the parent object.
+ void afterUnmarshal(Unmarshaller u, Object parent) {
+ }
+
+ // This method is called immediately after the object is created and before the
unmarshalling of this
+ // object begins. The callback provides an opportunity to initialize JavaBean
properties prior to unmarshalling.
+ void beforeUnmarshal(Unmarshaller u, Object parent) {
+ this.parent = (Child) parent;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the extensions
+ */
+ @XmlAnyElement
+ public List<Element> getExtensions() {
+ return extensions;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the myExtension
+ */
+ @XmlElement(namespace = Root.EXTENSIONS_NAMESPACE)
+ public String getMyExtension() {
+ return parent.getWrapped();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param extensions
+ * the extensions to set
+ */
+ public void setExtensions(List<Element> extensions) {
+ this.extensions = extensions;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param myExtension
+ * the myExtension to set
+ */
+ public void setMyExtension(String myExtension) {
+ parent.setWrapped(myExtension);
+ }
+ }
private Extension extension;
private String id;
private String value;
+
private String wrapped;
/*
* (non-Javadoc)
*
- * @see org.richfaces.cdk.xmlconfig.testmodel.Id#getId()
+ * @see java.lang.Object#equals(java.lang.Object)
*/
@Override
- @XmlElement(namespace = Root.HTTP_FOO_BAR_SCHEMA)
- public String getId() {
- return id;
- }
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param id
- * the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
+ if (obj == null) {
+ return false;
+ }
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the value
- */
- @XmlElement(namespace = Root.HTTP_FOO_BAR_SCHEMA)
- public String getValue() {
- return value;
- }
+ if (!(obj instanceof Child)) {
+ return false;
+ }
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param value
- * the value to set
- */
- public void setValue(String value) {
- this.value = value;
+ Child other = (Child) obj;
+
+ if (id == null) {
+ if (other.id != null) {
+ return false;
+ }
+ } else if (!id.equals(other.id)) {
+ return false;
+ }
+
+ return true;
}
@XmlElement(namespace = Root.HTTP_FOO_BAR_SCHEMA)
@@ -100,29 +155,36 @@
return extension;
}
- public void setExtension(Extension extension) {
- this.extension = extension;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.xmlconfig.testmodel.Id#getId()
+ */
+ @Override
+ @XmlElement(namespace = Root.HTTP_FOO_BAR_SCHEMA)
+ public String getId() {
+ return id;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the wrapped
+ * @return the value
*/
- public String getWrapped() {
- return wrapped;
+ @XmlElement(namespace = Root.HTTP_FOO_BAR_SCHEMA)
+ public String getValue() {
+ return value;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param wrapped
- * the wrapped to set
+ * @return the wrapped
*/
- public void setWrapped(String wrapped) {
- this.wrapped = wrapped;
+ public String getWrapped() {
+ return wrapped;
}
/*
@@ -140,102 +202,40 @@
return result;
}
- /*
- * (non-Javadoc)
+ public void setExtension(Extension extension) {
+ this.extension = extension;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
*
- * @see java.lang.Object#equals(java.lang.Object)
+ * @param id
+ * the id to set
*/
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- if (obj == null) {
- return false;
- }
-
- if (!(obj instanceof Child)) {
- return false;
- }
-
- Child other = (Child) obj;
-
- if (id == null) {
- if (other.id != null) {
- return false;
- }
- } else if (!id.equals(other.id)) {
- return false;
- }
-
- return true;
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param value
+ * the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @author asmirnov(a)exadel.com
- *
+ * @param wrapped
+ * the wrapped to set
*/
- public static class Extension {
- private List<Element> extensions = new ArrayList<Element>();
- private Child parent;
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the myExtension
- */
- @XmlElement(namespace = Root.EXTENSIONS_NAMESPACE)
- public String getMyExtension() {
- return parent.getWrapped();
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param myExtension
- * the myExtension to set
- */
- public void setMyExtension(String myExtension) {
- parent.setWrapped(myExtension);
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the extensions
- */
- @XmlAnyElement
- public List<Element> getExtensions() {
- return extensions;
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param extensions
- * the extensions to set
- */
- public void setExtensions(List<Element> extensions) {
- this.extensions = extensions;
- }
-
- // This method is called immediately after the object is created and before the
unmarshalling of this
- // object begins. The callback provides an opportunity to initialize JavaBean
properties prior to unmarshalling.
- void beforeUnmarshal(Unmarshaller u, Object parent) {
- this.parent = (Child) parent;
- }
-
- // This method is called after all the properties (except IDREF) are unmarshalled
for this object,
- // but before this object is set to the parent object.
- void afterUnmarshal(Unmarshaller u, Object parent) {
- }
+ public void setWrapped(String wrapped) {
+ this.wrapped = wrapped;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -21,6 +21,8 @@
package org.richfaces.cdk.xmlconfig.testmodel;
+import java.io.StringWriter;
+
import org.junit.Test;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
@@ -28,8 +30,6 @@
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.xmlconfig.XmlTest;
-import java.io.StringWriter;
-
/**
* @author akolonitsky
* @since Jan 10, 2010
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -66,6 +66,10 @@
@As(JAXBBinding.class)
JAXB binding;
+ @Mock
+ @Source(Sources.FACES_CONFIGS)
+ FileManager configSource;
+
@Inject
@As(CdkEntityResolver.class)
EntityResolver2 resolver;
@@ -74,26 +78,6 @@
@Source(Sources.RENDERER_TEMPLATES)
FileManager templatesSource;
- @Mock
- @Source(Sources.FACES_CONFIGS)
- FileManager configSource;
-
- @Override
- public void configure(Binder binder) {
- super.configure(binder);
- binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
- }
-
- protected void validateXml(StringWriter facesConfig) throws SAXException,
IOException, URISyntaxException {
- InputSource is = new InputSource(new StringReader(facesConfig.toString()));
- Validator validator = new Validator(is);
- validator.useXMLSchema(true);
- InputSource source = new
InputSource(getJavaFile("META-INF/schema/web-facesconfig_2_0.xsd").toURI().toString());
- validator.setJAXP12SchemaSource(source);
-
- validator.assertIsValid();
- }
-
protected void checkXmlStructure(StringWriter writer) throws SAXException,
IOException {
Class<?> testClass = this.getClass();
InputStream expectedFacesConfigFile =
testClass.getResourceAsStream(testClass.getSimpleName() + ".xml");
@@ -106,6 +90,12 @@
Assert.assertTrue("XML was not similar", xmlDiff.similar());
}
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
+ }
+
protected StringWriter generateFacesConfig(ComponentLibrary library) throws Exception
{
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
@@ -113,4 +103,14 @@
binding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION, new
FacesConfigAdapter().marshal(library));
return writer;
}
+
+ protected void validateXml(StringWriter facesConfig) throws SAXException,
IOException, URISyntaxException {
+ InputSource is = new InputSource(new StringReader(facesConfig.toString()));
+ Validator validator = new Validator(is);
+ validator.useXMLSchema(true);
+ InputSource source = new
InputSource(getJavaFile("META-INF/schema/web-facesconfig_2_0.xsd").toURI().toString());
+ validator.setJAXP12SchemaSource(source);
+
+ validator.assertIsValid();
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Root.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Root.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/Root.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -48,43 +48,43 @@
* <p class="changed_added_4_0">
* </p>
*
- * @return the name
+ * @return the children
*/
@XmlElement(namespace = HTTP_FOO_BAR_SCHEMA)
- public String getName() {
- return name;
+ public Set<Child> getChildren() {
+ return children;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param name
- * the name to set
+ * @return the name
*/
- public void setName(String name) {
- this.name = name;
+ @XmlElement(namespace = HTTP_FOO_BAR_SCHEMA)
+ public String getName() {
+ return name;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @return the children
+ * @param children
+ * the children to set
*/
- @XmlElement(namespace = HTTP_FOO_BAR_SCHEMA)
- public Set<Child> getChildren() {
- return children;
+ public void setChildren(Set<Child> children) {
+ this.children = children;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param children
- * the children to set
+ * @param name
+ * the name to set
*/
- public void setChildren(Set<Child> children) {
- this.children = children;
+ public void setName(String name) {
+ this.name = name;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -49,6 +49,6 @@
// Checks
checkXmlStructure(facesConfig);
- validateXml(facesConfig);
+ validateXml(facesConfig);
}
}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/package-info.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/package-info.java 2010-05-25
18:17:01 UTC (rev 17238)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/package-info.java 2010-05-25
22:05:22 UTC (rev 17239)
@@ -14,8 +14,8 @@
*/
@XmlAccessorType(XmlAccessType.NONE)
@javax.xml.bind.annotation.XmlSchema(namespace = Root.HTTP_FOO_BAR_SCHEMA, xmlns = {
- @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI =
Root.HTTP_FOO_BAR_SCHEMA),
- @javax.xml.bind.annotation.XmlNs(prefix = "ext", namespaceURI =
Root.EXTENSIONS_NAMESPACE) })
+ @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI =
Root.HTTP_FOO_BAR_SCHEMA),
+ @javax.xml.bind.annotation.XmlNs(prefix = "ext", namespaceURI =
Root.EXTENSIONS_NAMESPACE) })
package org.richfaces.cdk.xmlconfig.testmodel;
import javax.xml.bind.annotation.XmlAccessType;