Skip to content

Commit

Permalink
restore disappeared test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Mar 23, 2024
1 parent d44774e commit 25044a8
Show file tree
Hide file tree
Showing 28 changed files with 1,703 additions and 11 deletions.
8 changes: 4 additions & 4 deletions impl/src/test/java/com/sun/faces/el/ELUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
import com.sun.faces.context.ExternalContextImpl;
import com.sun.faces.context.FacesContextImpl;
import com.sun.faces.lifecycle.LifecycleImpl;
import com.sun.faces.mock.MockCDIProvider;
import com.sun.faces.mock.MockBeanManager;
import com.sun.faces.mock.MockHttpServletRequest;
import com.sun.faces.mock.MockHttpServletResponse;
import com.sun.faces.mock.MockServletContext;

import jakarta.el.ELResolver;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.faces.FactoryFinder;
import jakarta.faces.context.FacesContext;

public class ELUtilsTest {

private ApplicationAssociate applicationAssociate;

@BeforeEach
public void setUp() {
CDI.setCDIProvider(new MockCDIProvider());

MockServletContext mockServletContext = new MockServletContext() {
@Override
public URL getResource(String path) {
Expand All @@ -52,6 +50,8 @@ public URL getResource(String path) {

applicationAssociate = (ApplicationAssociate) externalContext.getApplicationMap()
.get(RIConstants.FACES_PREFIX + "ApplicationAssociate");

FacesContext.getCurrentInstance().getAttributes().put(RIConstants.CDI_BEAN_MANAGER, new MockBeanManager());
}

@Test
Expand Down
17 changes: 10 additions & 7 deletions impl/src/test/java/com/sun/faces/mock/MockBeanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -73,12 +76,12 @@ public <T> CreationalContext<T> createCreationalContext(Contextual<T> contextual

@Override
public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers) {
return null;
return emptySet();
}

@Override
public Set<Bean<?>> getBeans(String name) {
return null;
return emptySet();
}

@Override
Expand Down
105 changes: 105 additions & 0 deletions impl/src/test/java/jakarta/faces/component/ActionListenerTestImpl.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* Test {@link ActionListener} implementation.
* </p>
*/
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) {
}
}
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* Test implementation of {@link ActionListener}.
* </p>
*/
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();
}
}
33 changes: 33 additions & 0 deletions impl/src/test/java/jakarta/faces/component/CommandTestImpl.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* Test {@link UICommand} subclass.
* </p>
*/
public class CommandTestImpl extends UICommand {

public CommandTestImpl() {
super();
}

public CommandTestImpl(String id) {
setId(id);
}
}
122 changes: 122 additions & 0 deletions impl/src/test/java/jakarta/faces/component/ComponentTestImpl.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* Test <code>UIComponent</code> for unit tests.
* </p>
*/
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();
}
}
Loading

0 comments on commit 25044a8

Please sign in to comment.