diff --git a/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java b/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java index ddedc7468a..24d58b0299 100644 --- a/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java +++ b/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java @@ -20,6 +20,12 @@ import java.util.HashMap; import java.util.Map; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.faces.FactoryFinder; +import jakarta.faces.application.ApplicationFactory; +import jakarta.faces.context.FacesContextFactory; +import jakarta.faces.lifecycle.LifecycleFactory; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -34,12 +40,6 @@ import com.sun.faces.mock.MockServletConfig; import com.sun.faces.mock.MockServletContext; -import jakarta.enterprise.inject.spi.CDI; -import jakarta.faces.FactoryFinder; -import jakarta.faces.application.ApplicationFactory; -import jakarta.faces.context.FacesContextFactory; -import jakarta.faces.lifecycle.LifecycleFactory; - public class JUnitFacesTestCaseBase { protected MockApplication application = null; @@ -78,6 +78,8 @@ public void setUp() throws Exception { new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle()); + FactoryFinder.setFactory(FactoryFinder.FACES_SERVLET_FACTORY, + "com.sun.faces.mock.MockFacesServletFactory"); FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory"); FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, diff --git a/impl/src/test/java/com/sun/faces/mock/MockBeanManager.java b/impl/src/test/java/com/sun/faces/mock/MockBeanManager.java index 998e88e1e0..7fbc3e1ad1 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockBeanManager.java +++ b/impl/src/test/java/com/sun/faces/mock/MockBeanManager.java @@ -17,6 +17,14 @@ package com.sun.faces.mock; +import static java.util.Collections.emptySet; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.List; +import java.util.Set; + import jakarta.el.ELResolver; import jakarta.el.ExpressionFactory; import jakarta.enterprise.context.spi.Context; @@ -42,11 +50,6 @@ import jakarta.enterprise.inject.spi.ObserverMethod; import jakarta.enterprise.inject.spi.ProducerFactory; import jakarta.enterprise.inject.spi.el.ELAwareBeanManager; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.List; -import java.util.Set; public class MockBeanManager implements BeanManager, ELAwareBeanManager { @@ -73,12 +76,12 @@ public CreationalContext createCreationalContext(Contextual contextual @Override public Set> getBeans(Type beanType, Annotation... qualifiers) { - return null; + return emptySet(); } @Override public Set> getBeans(String name) { - return null; + return emptySet(); } @Override diff --git a/impl/src/test/java/com/sun/faces/mock/MockFacesServletFactory.java b/impl/src/test/java/com/sun/faces/mock/MockFacesServletFactory.java new file mode 100644 index 0000000000..7824d4fe90 --- /dev/null +++ b/impl/src/test/java/com/sun/faces/mock/MockFacesServletFactory.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.mock; + +import jakarta.faces.FactoryFinder; +import jakarta.faces.webapp.FacesServletFactory; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; + +import com.sun.faces.webapp.FacesServletImpl; + +public class MockFacesServletFactory extends FacesServletFactory { + public MockFacesServletFactory() { + System.setProperty(FactoryFinder.FACES_SERVLET_FACTORY, this.getClass().getName()); + } + + @Override + public Servlet getFacesServlet(ServletConfig config) { + Servlet facesServlet = new FacesServletImpl(); + try { + facesServlet.init(config); + } catch (ServletException e) { + throw new IllegalStateException(e); + } + return facesServlet; + } + + @Override + public FacesServletFactory getWrapped() { + return null; + } +} diff --git a/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java b/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java deleted file mode 100644 index f8c6c76daa..0000000000 --- a/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package jakarta.faces; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.File; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - *

- * A unit test to make sure all classes implementing {@link FacesWrapper} are - * actually wrapping all public and protected methods of the wrapped class. This - * should help to keep the wrapper classes in synch with the wrapped classes. - *

- */ -public class FacesWrapperTestCase { - - private static List> wrapperClasses; - private static List> noWrapperClasses; - private static List methodsToIgnore; - private static final String JAVAX_FACES_PKG = "jakarta.faces."; - - /** - * Perform class-level initialization for test - lookup for classes - * implementing FacesWrapper. - * @throws java.lang.Exception - */ - @BeforeEach - public void setUp() throws Exception { - if (wrapperClasses == null) { - loadWrapperClasses(); - methodsToIgnore = new ArrayList(); - methodsToIgnore.add(Object.class.getMethod("toString", new Class[0])); - } - } - - /** - * Unit test to assert wrapperClasses list was loaded (see {@link #setUp()}. - */ - @Test - public void testWrapperClassesLoaded() { - assertNotNull(wrapperClasses); - assertTrue(!wrapperClasses.isEmpty()); - } - - /** - * Unit test to assert there are no *Wrapper classes not implementing - * FacesWrapper. - */ - @Test - public void testWrapperClassesImplementFacesWrapper() { - assertNotNull(noWrapperClasses); - if (noWrapperClasses.size() > 0) { - System.out.println("Wrapper classes not implementing jakarta.faces.FacesWrapper:"); - System.out.println(noWrapperClasses.toString()); - } - assertTrue(noWrapperClasses - .isEmpty()); - } - - /** - * The main goal of this TestSuite: unit test to assert all classes - * implementing FacesWrapper do wrap all public and protected methods of the - * wrapped class. - */ - @Test - public void testWrapperClassWrapsPublicAndProtectedMethods() { - for (Class wrapper : wrapperClasses) { - if (wrapper.isInterface()) { - continue; - } - List wrapperMethods = getPublicAndProtectedMethods(wrapper); - List methodsToWrap = getPublicAndProtectedMethods(wrapper.getSuperclass()); - - System.out.println("verify " + wrapper.getName() + " is wrapping " - + wrapper.getSuperclass().getName() + " well"); - String msg = wrapper.getCanonicalName() + " does not wrap method: "; - for (Method m : methodsToWrap) { - if (isMethodContained(m, methodsToIgnore)) { - continue; - } - assertTrue(isMethodContained(m, wrapperMethods), msg + m.toString()); - } - } - } - - // private methods - /** - * Returns true it the passed method is contained in the also passed list of - * methods by also comparing matching parameters. - * - * @param m the method (from the wrapped class) to compare against. - * @param wrapperMethods the list of methods of the wrapper class. - */ - private boolean isMethodContained(Method m, List wrapperMethods) { - String name = m.getName(); - Class[] paramTypes = m.getParameterTypes(); - Class returnType = m.getReturnType(); - for (Method wm : wrapperMethods) { - if (name.equals(wm.getName()) && Arrays.equals(paramTypes, wm.getParameterTypes()) - && returnType == wm.getReturnType()) { - return true; - } - } - - return false; - } - - /** - * Collect public and protected methods of a class. - * - * @param wrapper the class to find its methods. - * @return list of found methods. - */ - private List getPublicAndProtectedMethods(Class wrapper) { - List mList = new ArrayList(); - if (Object.class == wrapper) { - return mList; - } - - Method[] methods = wrapper.getDeclaredMethods(); - for (Method m : methods) { - int mod = m.getModifiers(); - if (!Modifier.isStatic(mod) && (Modifier.isPublic(mod) || Modifier.isProtected(mod))) { - mList.add(m); - } - } - return mList; - } - - /** - * Collect the wrapper classes. - */ - private void loadWrapperClasses() { - wrapperClasses = new ArrayList<>(); - noWrapperClasses = new ArrayList<>(); - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - try { - collectWrapperClasses( - classLoader, - JAVAX_FACES_PKG, - new File(classLoader.getResource("jakarta/faces/Messages.properties").getFile()) - .getParentFile()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Walk package tree for collecting wrapper classes. - * - * @param classLoader the ClassLoader. - * @param pkg package name. - * @param jakartaFacesFolder current File (directory or file) - * @throws Exception might throw ClassNotFoundException from class loading. - */ - private void collectWrapperClasses(ClassLoader classLoader, String pkg, File jakartaFacesFolder) throws Exception { - for (File file : jakartaFacesFolder.listFiles()) { - if (file.isDirectory()) { - collectWrapperClasses(classLoader, pkg + file.getName() + ".", file); - } else { - addWrapperClassToWrapperClassesList(classLoader, pkg, file); - } - } - } - - /** - * Add classes that are assignable to FacesWrapper class to the - * wrapperClasses list - and also add classes with a name ending on - * "Wrapper" but being not assignable to FacesWrapper to the - * noWrapperClasses list. - * - * @param cl the ClasslOader used to load the class. - * @param pkg the name of the package working in. - * @param f the File to analyse. - * @throws Exception ClassLoader exceptions. - */ - private void addWrapperClassToWrapperClassesList(ClassLoader cl, String pkg, File f) - throws Exception { - String name = f.getName(); - if (!name.endsWith(".class")) { - return; - } - String className = pkg + name.substring(0, name.length() - 6); - Class c = cl.loadClass(className); - Class wrappedClass = c.getSuperclass(); - if (wrappedClass != null) { - // we are not interested in interfaces extending FacesWrapper interface. - // also skip classes implementing FacesWrapper but extend from Object (e.g. factories). - if (FacesWrapper.class.isAssignableFrom(wrappedClass) || wrappedClass == Object.class) { - return; - } - } - if (FacesWrapper.class.isAssignableFrom(c)) { - wrapperClasses.add(c); - } else if (c != FacesWrapper.class && c.getName().endsWith("Wrapper")) { - noWrapperClasses.add(c); - } - } -} diff --git a/impl/src/test/java/jakarta/faces/component/ActionListenerTestImpl.java b/impl/src/test/java/jakarta/faces/component/ActionListenerTestImpl.java new file mode 100644 index 0000000000..0ddcf20643 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/ActionListenerTestImpl.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.context.FacesContext; +import jakarta.faces.event.ActionEvent; +import jakarta.faces.event.ActionListener; + +/** + *

+ * Test {@link ActionListener} implementation. + *

+ */ +public class ActionListenerTestImpl implements ActionListener, StateHolder { + + public ActionListenerTestImpl() { + } + + public ActionListenerTestImpl(String id) { + this.id = id; + } + + private String id = null; + + // ----------------------------------------------------------- Pubic Methods + public String getId() { + return this.id; + } + + @Override + public void processAction(ActionEvent event) { + trace(getId() + "@" + event.getPhaseId().toString()); + } + + @Override + public boolean equals(Object otherObj) { + if (!(otherObj instanceof ActionListenerTestImpl)) { + return false; + } + ActionListenerTestImpl other = (ActionListenerTestImpl) otherObj; + if (null != id && null == other.id || null == id && null != other.id) { + return false; + } + boolean idsAreEqual = true; + if (null != id) { + idsAreEqual = id.equals(other.id); + } + return idsAreEqual; + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static final StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } + + // + // methods from StateHolder + // + @Override + public Object saveState(FacesContext context) { + return id; + } + + @Override + public void restoreState(FacesContext context, Object state) { + id = (String) state; + } + + @Override + public boolean isTransient() { + return false; + } + + @Override + public void setTransient(boolean newT) { + } +} diff --git a/impl/src/test/java/jakarta/faces/component/CommandActionListenerTestImpl.java b/impl/src/test/java/jakarta/faces/component/CommandActionListenerTestImpl.java new file mode 100644 index 0000000000..7215ded620 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/CommandActionListenerTestImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.event.ActionEvent; +import jakarta.faces.event.ActionListener; + +/** + *

+ * Test implementation of {@link ActionListener}. + *

+ */ +public class CommandActionListenerTestImpl implements ActionListener { + + protected String actionListenerId = null; + + public CommandActionListenerTestImpl(String actionListenerId) { + this.actionListenerId = actionListenerId; + } + + @Override + public void processAction(ActionEvent event) { + trace(actionListenerId); + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/CommandTestImpl.java b/impl/src/test/java/jakarta/faces/component/CommandTestImpl.java new file mode 100644 index 0000000000..37d816b576 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/CommandTestImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +/** + *

+ * Test {@link UICommand} subclass. + *

+ */ +public class CommandTestImpl extends UICommand { + + public CommandTestImpl() { + super(); + } + + public CommandTestImpl(String id) { + setId(id); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/ComponentTestImpl.java b/impl/src/test/java/jakarta/faces/component/ComponentTestImpl.java new file mode 100644 index 0000000000..31e576dadf --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/ComponentTestImpl.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import java.io.IOException; + +import jakarta.faces.context.FacesContext; + +/** + *

+ * Test UIComponent for unit tests. + *

+ */ +public class ComponentTestImpl extends UIComponentBase { + + public ComponentTestImpl() { + this("test"); + } + + public ComponentTestImpl(String componentId) { + super(); + setId(componentId); + } + + public String getComponentType() { + return "TestComponent"; + } + + @Override + public String getFamily() { + return "Test"; + } + + // -------------------------------------------------- Trace-Enabled Methods + @Override + public void decode(FacesContext context) { + trace("d-" + getId()); + super.decode(context); + } + + @Override + public void encodeBegin(FacesContext context) throws IOException { + trace("eB-" + getId()); + super.encodeBegin(context); + } + + @Override + public void encodeChildren(FacesContext context) throws IOException { + trace("eC-" + getId()); + super.encodeChildren(context); + } + + @Override + public void encodeEnd(FacesContext context) throws IOException { + trace("eE-" + getId()); + super.encodeEnd(context); + } + + public void updateModel(FacesContext context) { + trace("u-" + getId()); + // super.updateModel(context); + } + + @Override + public void processDecodes(FacesContext context) { + trace("pD-" + getId()); + super.processDecodes(context); + } + + @Override + public void processValidators(FacesContext context) { + trace("pV-" + getId()); + super.processValidators(context); + } + + @Override + public void processUpdates(FacesContext context) { + trace("pU-" + getId()); + super.processUpdates(context); + } + + public void callPushComponent(FacesContext context) { + pushComponentToEL(context, null); + } + + public void callPopComponent(FacesContext context) { + popComponentFromEL(context); + } + + // --------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/DataBeanTestImpl.java b/impl/src/test/java/jakarta/faces/component/DataBeanTestImpl.java new file mode 100644 index 0000000000..6556e9d50a --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/DataBeanTestImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import java.io.Serializable; + +// Test JavaBean for DataModel Tests +public class DataBeanTestImpl implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + private String command; + + public String getCommand() { + return this.command; + } + + public void setCommand(String command) { + this.command = command; + } + + private String input; + + public String getInput() { + return this.input; + } + + public void setInput(String input) { + this.input = input; + } + + private String output; + + public String getOutput() { + return this.output; + } + + public void setOutput(String output) { + this.output = output; + } +} diff --git a/impl/src/test/java/jakarta/faces/component/EventTestImpl.java b/impl/src/test/java/jakarta/faces/component/EventTestImpl.java new file mode 100644 index 0000000000..657251ce7b --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/EventTestImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.event.FacesEvent; +import jakarta.faces.event.FacesListener; + +public class EventTestImpl extends FacesEvent { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public EventTestImpl(UIComponent component) { + this(component, null); + } + + public EventTestImpl(UIComponent component, String id) { + super(component); + this.id = id; + } + + private String id; + + public String getId() { + return this.id; + } + + @Override + public boolean isAppropriateListener(FacesListener listener) { + return listener instanceof ListenerTestImpl; + } + + @Override + public void processListener(FacesListener listener) { + ((ListenerTestImpl) listener).processTest(this); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/InputTestImpl.java b/impl/src/test/java/jakarta/faces/component/InputTestImpl.java new file mode 100644 index 0000000000..4a6759b276 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/InputTestImpl.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +/** + *

+ * Test {@link UIInput} subclass. + *

+ */ +public class InputTestImpl extends UIInput { + + public InputTestImpl() { + super(); + } + + public InputTestImpl(String id) { + setId(id); + } + + @Override + public boolean compareValues(Object previous, Object value) { + return super.compareValues(previous, value); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/InputValidatorTestImpl.java b/impl/src/test/java/jakarta/faces/component/InputValidatorTestImpl.java new file mode 100644 index 0000000000..da8e96fc00 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/InputValidatorTestImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.context.FacesContext; +import jakarta.faces.validator.Validator; + +/** + *

+ * Test implementation of {@link Validator}. + *

+ */ +public class InputValidatorTestImpl implements Validator { + + protected String validatorId = null; + + public InputValidatorTestImpl(String validatorId) { + this.validatorId = validatorId; + } + + @Override + public void validate(FacesContext context, UIComponent component, Object value) { + trace(validatorId); + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/InputValueChangeListenerTestImpl.java b/impl/src/test/java/jakarta/faces/component/InputValueChangeListenerTestImpl.java new file mode 100644 index 0000000000..6d13789681 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/InputValueChangeListenerTestImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.event.ValueChangeEvent; +import jakarta.faces.event.ValueChangeListener; + +/** + *

+ * Test implementation of {@link ValueChangeListener}. + *

+ */ +public class InputValueChangeListenerTestImpl implements ValueChangeListener { + + protected String valueChangeListenerId = null; + + public InputValueChangeListenerTestImpl(String valueChangeListenerId) { + this.valueChangeListenerId = valueChangeListenerId; + } + + @Override + public void processValueChange(ValueChangeEvent event) { + trace(valueChangeListenerId); + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/ListenerTestImpl.java b/impl/src/test/java/jakarta/faces/component/ListenerTestImpl.java new file mode 100644 index 0000000000..96afb96363 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/ListenerTestImpl.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.event.AbortProcessingException; +import jakarta.faces.event.FacesListener; + +public class ListenerTestImpl implements FacesListener { + + public ListenerTestImpl(String id, String fromId, String toId) { + this.id = id; + this.fromId = fromId; // When an event with this id is received ... + this.toId = toId; // queue an additional event with this id + } + + public ListenerTestImpl(String id) { + this.id = id; + } + + public ListenerTestImpl(String id, boolean abort) { + this.id = id; + this.abort = abort; + } + + private boolean abort = false; + private String fromId = null; + private String id = null; + private String toId = null; + + public String getId() { + return this.id; + } + + public void processTest(EventTestImpl event) { + if (getId() != null) { + trace(getId()); + } + if (event.getId() != null) { + trace(event.getId()); + if (event.getId().equals(fromId)) { + event.getComponent().queueEvent(new EventTestImpl(event.getComponent(), toId)); + } + } + if (abort) { + throw new AbortProcessingException(); + } + } + + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/NamingContainerTestImpl.java b/impl/src/test/java/jakarta/faces/component/NamingContainerTestImpl.java new file mode 100644 index 0000000000..abc8b9f2c3 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/NamingContainerTestImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +/** + *

+ * Test {@link NamingContainer} implementation with tracing. + *

+ */ +public class NamingContainerTestImpl extends UINamingContainer { + + // ------------------------------------------------------------ Constructors + public NamingContainerTestImpl() { + } + + // ---------------------------------------------------------- Public Methods + @Override + public UIComponent findComponent(String expr) { + + trace(getId()); + trace(expr); + return super.findComponent(expr); + + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/SelectManyTestImpl.java b/impl/src/test/java/jakarta/faces/component/SelectManyTestImpl.java new file mode 100644 index 0000000000..8ceafe31fb --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/SelectManyTestImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +/** + *

+ * Test {@link UISelectMany} subclass. + *

+ */ +public class SelectManyTestImpl extends UISelectMany { + + @Override + public boolean compareValues(Object previous, Object value) { + return super.compareValues(previous, value); + } +} diff --git a/impl/src/test/java/jakarta/faces/component/ValueChangeListenerTestImpl.java b/impl/src/test/java/jakarta/faces/component/ValueChangeListenerTestImpl.java new file mode 100644 index 0000000000..1ab7fb8ae5 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/component/ValueChangeListenerTestImpl.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.component; + +import jakarta.faces.context.FacesContext; +import jakarta.faces.event.ValueChangeEvent; +import jakarta.faces.event.ValueChangeListener; + +/** + *

+ * Test {@link ValueChangeListener} implementation. + *

+ */ +public class ValueChangeListenerTestImpl implements ValueChangeListener, StateHolder { + + // ------------------------------------------------------------ Constructors + /** + * + * Called from state system. + */ + public ValueChangeListenerTestImpl() { + } + + public ValueChangeListenerTestImpl(String id) { + this.id = id; + } + + private String id = null; + + // ----------------------------------------------------------- Pubic Methods + public String getId() { + return this.id; + } + + @Override + public void processValueChange(ValueChangeEvent event) { + trace(getId()); + } + + // ---------------------------------------------------- Static Trace Methods + // Accumulated trace log + private static StringBuffer trace = new StringBuffer(); + + // Append to the current trace log (or clear if null) + public static void trace(String text) { + if (text == null) { + trace.setLength(0); + } else { + trace.append('/'); + trace.append(text); + } + } + + // Retrieve the current trace log + public static String trace() { + return trace.toString(); + } + + // this needs to be named differently because other test methods + // rely on the standard equal method. + public boolean isEqual(Object otherObj) { + if (!(otherObj instanceof ValueChangeListenerTestImpl)) { + return false; + } + ValueChangeListenerTestImpl other = (ValueChangeListenerTestImpl) otherObj; + if (null != id && null == other.id || null == id && null != other.id) { + return false; + } + boolean idsAreEqual = true; + if (null != id) { + idsAreEqual = id.equals(other.id); + } + return idsAreEqual; + } + + // + // methods from StateHolder + // + @Override + public Object saveState(FacesContext context) { + return id; + } + + @Override + public void restoreState(FacesContext context, Object state) { + id = (String) state; + } + + @Override + public boolean isTransient() { + return false; + } + + @Override + public void setTransient(boolean newT) { + } +} diff --git a/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender.java b/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender.java new file mode 100644 index 0000000000..c35c3feb46 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.mock; + +import com.sun.faces.mock.MockFacesContextFactory; + +import jakarta.faces.FactoryFinder; +import jakarta.faces.context.FacesContextFactory; + +public class MockFacesContextFactoryExtender extends MockFacesContextFactory { + + public MockFacesContextFactoryExtender() { + } + + public MockFacesContextFactoryExtender(FacesContextFactory oldImpl) { + System.setProperty(FactoryFinder.FACES_CONTEXT_FACTORY, + this.getClass().getName()); + System.setProperty("oldImpl", oldImpl.getClass().getName()); + } +} diff --git a/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender2.java b/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender2.java new file mode 100644 index 0000000000..62e54d1495 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/mock/MockFacesContextFactoryExtender2.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.mock; + +import com.sun.faces.mock.MockFacesContextFactory; + +import jakarta.faces.FactoryFinder; +import jakarta.faces.context.FacesContextFactory; + +public class MockFacesContextFactoryExtender2 extends MockFacesContextFactory { + + public MockFacesContextFactoryExtender2() { + } + + public MockFacesContextFactoryExtender2(FacesContextFactory oldImpl) { + System.setProperty(FactoryFinder.FACES_CONTEXT_FACTORY, + this.getClass().getName()); + System.setProperty("oldImpl", oldImpl.getClass().getName()); + } +} diff --git a/impl/src/test/java/jakarta/faces/model/BeanTestImpl.java b/impl/src/test/java/jakarta/faces/model/BeanTestImpl.java new file mode 100644 index 0000000000..063aa320c6 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/model/BeanTestImpl.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.model; + +/** + *

+ * JavaBean for data model tests.

+ */ +public class BeanTestImpl extends com.sun.faces.mock.model.BeanTestImpl { + +} diff --git a/impl/src/test/java/jakarta/faces/model/ListenerTestImpl.java b/impl/src/test/java/jakarta/faces/model/ListenerTestImpl.java new file mode 100644 index 0000000000..3d6ec16261 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/model/ListenerTestImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.model; + +/** + *

+ * Test implementation of DataModelListener.

+ */ +public class ListenerTestImpl implements DataModelListener { + + // ----------------------------------------------- DataModelListener Methods + @Override + public void rowSelected(DataModelEvent event) { + Object rowData = event.getRowData(); + int rowIndex = event.getRowIndex(); + trace(String.valueOf(rowIndex)); + if ((rowIndex >= 0) && (rowData == null)) { + throw new IllegalArgumentException("rowIndex=" + rowIndex + + " but rowData is null"); + } else if ((rowIndex == -1) && (rowData != null)) { + throw new IllegalArgumentException("rowIndex=" + rowIndex + + " but rowData is not null"); + } else if (rowIndex < -1) { + throw new IllegalArgumentException("rowIndex=" + rowIndex); + } + + } + + // ---------------------------------------------------------- Static Methods + private static StringBuffer trace = new StringBuffer(); + + public static String trace() { + return (trace.toString()); + } + + public static void trace(String value) { + if (value == null) { + trace = new StringBuffer(); + } else { + trace.append('/'); + trace.append(value); + } + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigAttribute.java b/impl/src/test/java/jakarta/faces/webapp/ConfigAttribute.java new file mode 100644 index 0000000000..15d2032b93 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigAttribute.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +/** + *

+ * Config Bean for an Attribute.

+ */ +public class ConfigAttribute extends ConfigFeature { + + private String attributeClass; + + public String getAttributeClass() { + return (this.attributeClass); + } + + public void setAttributeClass(String attributeClass) { + this.attributeClass = attributeClass; + } + + private String attributeName; + + public String getAttributeName() { + return (this.attributeName); + } + + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigBase.java b/impl/src/test/java/jakarta/faces/webapp/ConfigBase.java new file mode 100644 index 0000000000..02d703ba4d --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigBase.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + *

+ * Base bean for parsing configuration information. + *

+ */ +public class ConfigBase { + + // ---------------------------------------------------------- + private String actionListener = null; + + public String getActionListener() { + return (this.actionListener); + } + + public void setActionListener(String actionListener) { + this.actionListener = actionListener; + } + + private String navigationHandler = null; + + public String getNavigationHandler() { + return (this.navigationHandler); + } + + public void setNavigationHandler(String navigationHandler) { + this.navigationHandler = navigationHandler; + } + + + // ------------------------------------------------------------ + private Map components = null; + + public void addComponent(ConfigComponent component) { + if (components == null) { + components = new HashMap(); + } + components.put(component.getComponentType(), component); + } + + public Map getComponents() { + if (components == null) { + return (Collections.EMPTY_MAP); + } else { + return (this.components); + } + } + + // ------------------------------------------------------------ + private Map converters = null; + + public void addConverter(ConfigConverter converter) { + if (converters == null) { + converters = new HashMap(); + } + converters.put(converter.getConverterId(), converter); + } + + public Map getConverters() { + if (converters == null) { + return (Collections.EMPTY_MAP); + } else { + return (this.converters); + } + } + + // ------------------------------------------------------------ + private Map validators = null; + + public void addValidator(ConfigValidator validator) { + if (validators == null) { + validators = new HashMap(); + } + validators.put(validator.getValidatorId(), validator); + } + + public Map getValidators() { + if (validators == null) { + return (Collections.EMPTY_MAP); + } else { + return (this.validators); + } + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigComponent.java b/impl/src/test/java/jakarta/faces/webapp/ConfigComponent.java new file mode 100644 index 0000000000..3b6803fd60 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigComponent.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +/** + *

+ * Config Bean for an Component.

+ */ +public class ConfigComponent extends ConfigFeature { + + private String componentClass; + + public String getComponentClass() { + return (this.componentClass); + } + + public void setComponentClass(String componentClass) { + this.componentClass = componentClass; + } + + private String componentType; + + public String getComponentType() { + return (this.componentType); + } + + public void setComponentType(String componentType) { + this.componentType = componentType; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigConverter.java b/impl/src/test/java/jakarta/faces/webapp/ConfigConverter.java new file mode 100644 index 0000000000..668a9729d8 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigConverter.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +/** + *

+ * Config Bean for a Converter.

+ */ +public class ConfigConverter extends ConfigFeature { + + private String converterId; + + public String getConverterId() { + return (this.converterId); + } + + public void setConverterId(String converterId) { + this.converterId = converterId; + } + + private String converterClass; + + public String getConverterClass() { + return (this.converterClass); + } + + public void setConverterClass(String converterClass) { + this.converterClass = converterClass; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigFeature.java b/impl/src/test/java/jakarta/faces/webapp/ConfigFeature.java new file mode 100644 index 0000000000..4e22293698 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigFeature.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + *

+ * Base bean for configuration beans that have common feature elements.

+ */ +public abstract class ConfigFeature { + + private Map attributes = null; + + public void addAttribute(ConfigAttribute attribute) { + if (attributes == null) { + attributes = new HashMap(); + } + attributes.put(attribute.getAttributeName(), attribute); + } + + public Map getAttributes() { + if (attributes == null) { + return (Collections.EMPTY_MAP); + } else { + return (attributes); + } + } + + private String description; + + public String getDescription() { + return (this.description); + } + + public void setDescription(String description) { + this.description = description; + } + + private String displayName; + + public String getDisplayName() { + return (this.displayName); + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + private String largeIcon; + + public String getLargeIcon() { + return (this.largeIcon); + } + + public void setLargeIcon(String largeIcon) { + this.largeIcon = largeIcon; + } + + private Map properties = null; + + public void addProperty(ConfigProperty property) { + if (properties == null) { + properties = new HashMap(); + } + properties.put(property.getPropertyName(), property); + } + + public Map getProperties() { + if (properties == null) { + return (Collections.EMPTY_MAP); + } else { + return (properties); + } + } + + private String smallIcon; + + public String getSmallIcon() { + return (this.smallIcon); + } + + public void setSmallIcon(String smallIcon) { + this.smallIcon = smallIcon; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigProperty.java b/impl/src/test/java/jakarta/faces/webapp/ConfigProperty.java new file mode 100644 index 0000000000..35cdd80808 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigProperty.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +/** + *

+ * Config Bean for an Property.

+ */ +public class ConfigProperty extends ConfigFeature { + + private String propertyClass; + + public String getPropertyClass() { + return (this.propertyClass); + } + + public void setPropertyClass(String propertyClass) { + this.propertyClass = propertyClass; + } + + private String propertyName; + + public String getPropertyName() { + return (this.propertyName); + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigValidator.java b/impl/src/test/java/jakarta/faces/webapp/ConfigValidator.java new file mode 100644 index 0000000000..44cbb9cecb --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigValidator.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package jakarta.faces.webapp; + +/** + *

+ * Config Bean for a Validator.

+ */ +public class ConfigValidator extends ConfigFeature { + + private String validatorId; + + public String getValidatorId() { + return (this.validatorId); + } + + public void setValidatorId(String validatorId) { + this.validatorId = validatorId; + } + + private String validatorClass; + + public String getValidatorClass() { + return (this.validatorClass); + } + + public void setValidatorClass(String validatorClass) { + this.validatorClass = validatorClass; + } +} diff --git a/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java b/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java index 7e9fa7ea6d..727ee4b52c 100644 --- a/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java +++ b/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java @@ -18,18 +18,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.sun.faces.junit.JUnitFacesTestCaseBase; -import com.sun.faces.mock.MockRenderKit; - import jakarta.faces.FactoryFinder; import jakarta.faces.component.UIViewRoot; import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; import jakarta.servlet.http.HttpServletResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.sun.faces.junit.JUnitFacesTestCaseBase; +import com.sun.faces.mock.MockRenderKit; + public class FacesServletTestCase extends JUnitFacesTestCaseBase { // this is private in FacesServlet to not break backwards compatibility diff --git a/impl/src/test/java/jakarta/faces/webapp/config-file-0.xml b/impl/src/test/java/jakarta/faces/webapp/config-file-0.xml new file mode 100644 index 0000000000..5c0bef22a4 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/config-file-0.xml @@ -0,0 +1,25 @@ + + + + + + diff --git a/impl/src/test/java/jakarta/faces/webapp/config-file-1.xml b/impl/src/test/java/jakarta/faces/webapp/config-file-1.xml new file mode 100644 index 0000000000..1be236c741 --- /dev/null +++ b/impl/src/test/java/jakarta/faces/webapp/config-file-1.xml @@ -0,0 +1,225 @@ + + + + + + + + com.mycompany.MyActionListener + com.mycompany.OldVariableResolver + + + + + + Second Validator Description + Second Validator Display Name + + secondValidator.jpg + secondValidator.gif + + Second + com.mycompany.MySecondValidator + + Second Validator Property 1 Description + Second Validator Property 1 Display Name + prop1 + java.lang.String + + + + + + + First Validator Description + First Validator Display Name + + firstValidator.jpg + firstValidator.gif + + First + com.mycompany.MyFirstValidator + + First Validator Attribute 1 Description + First Validator Attribute 1 Display Name + attr1 + java.lang.String + + + + + + + User Interface Command Component + User Interface Command + Command + jakarta.faces.component.UICommand + + + + + + First Converter Description + First Converter Display Name + + firstConverter.jpg + firstConverter.gif + + First + com.mycompany.MyFirstConverter + + First Converter Attribute 1 Description + First Converter Attribute 1 Display Name + attr1 + java.lang.String + + + + + + + com.mycompany.MyNavigationHandler + com.mycompany.MyPropertyResolver + com.mycompany.MyVariableResolver + + + + + + Second Converter Description + Second Converter Display Name + + secondConverter.jpg + secondConverter.gif + + Second + com.mycompany.MySecondConverter + + Second Converter Property 1 Description + Second Converter Property 1 Display Name + prop1 + java.lang.String + + + + + + Third Converter Description + Third Converter Display Name + + thirdConverter.jpg + thirdConverter.gif + + java.util.Date + com.mycompany.MyThirdConverter + + Third Converter Property 1 Description + Third Converter Property 1 Display Name + prop1 + java.lang.String + + + + + + + + This is the set of rules that provides default navigation + independent of the request view. + + Default Navigation Rules + + * + + + #{UserBean.Logout} + /logout.jsp + + + + loginRequired + /must-login-first.jsp + + + + + + + + /login.jsp + + + #{UserBean.login} + success + /home.jsp + + + + #{UserBean.register} + success + /get-user-info.jsp + + + + #{UserBean.register} + duplicate + /try-another-name.jsp + + + + + + + + + + #{SearchForm.go} + /search-results.jsp + + + + + + + + /movies/* + + + #{SearchForm.go} + /movies/movie-search-results.jsp + + + + + + + + This element represents a JDBC DataSource that will be + initialized through some external means, and made available + in some scope (most likely application). + + Database Connection Pool + connectionPool + javax.sql.DataSource + + +