Upgrade Web Flow tests from JUnit 3 to 4

Remove `extends TestCase` from all test classes and add `@Before`,
`@After`, and `@Test` method annotations.

Note that class `JsfUtilsTests` still indirectly inherits from
`TestCase` via `org.apache.myfaces.test.base.AbstractJsfTestCase`.

Issue: SWF-1739
This commit is contained in:
Etienne Dysli Metref
2019-08-22 17:33:00 +02:00
committed by Rossen Stoyanchev
parent a638b396bb
commit ceb44a6634
171 changed files with 2346 additions and 523 deletions

View File

@@ -1,7 +1,12 @@
package org.springframework.faces.config;
import junit.framework.TestCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.binding.convert.ConversionException;
import org.springframework.binding.convert.ConversionExecutionException;
import org.springframework.binding.convert.ConversionExecutor;
@@ -23,7 +28,7 @@ import org.springframework.webflow.execution.ViewFactory;
import org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser;
import org.springframework.webflow.validation.ValidationHintResolver;
public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends TestCase {
public abstract class AbstractFacesFlowBuilderServicesConfigurationTests {
protected ApplicationContext context;
@@ -31,7 +36,7 @@ public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends
protected final JSFMockHelper jsf = new JSFMockHelper();
@Before
public void setUp() throws Exception {
this.jsf.setUp();
this.context = initApplicationContext();
@@ -39,10 +44,12 @@ public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends
protected abstract ApplicationContext initApplicationContext();
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
this.jsf.tearDown();
}
@Test
public void testConfigureDefaults() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesDefault");
assertNotNull(this.builderServices);
@@ -52,6 +59,7 @@ public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends
assertFalse(this.builderServices.getDevelopment());
}
@Test
public void testEnableManagedBeans() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesLegacy");
assertNotNull(this.builderServices);
@@ -61,6 +69,7 @@ public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends
assertFalse(this.builderServices.getDevelopment());
}
@Test
public void testFlowBuilderServicesAllCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesAllCustom");
assertNotNull(this.builderServices);
@@ -72,6 +81,7 @@ public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends
assertTrue(this.builderServices.getDevelopment());
}
@Test
public void testFlowBuilderServicesConversionServiceCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesConversionServiceCustom");
assertNotNull(this.builderServices);

View File

@@ -1,27 +1,36 @@
package org.springframework.faces.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.faces.webflow.JsfResourceRequestHandler;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
public abstract class AbstractResourcesConfigurationTests extends TestCase {
public abstract class AbstractResourcesConfigurationTests {
protected ApplicationContext context;
@Before
public void setUp() throws Exception {
this.context = initApplicationContext();
}
protected abstract ApplicationContext initApplicationContext();
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
}
@Test
public void testConfigureDefaults() {
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
assertEquals(1, map.values().size());

View File

@@ -1,5 +1,7 @@
package org.springframework.faces.config;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.faces.webflow.JSFMockHelper;
@@ -11,13 +13,16 @@ public class ResourcesBeanDefinitionParserTests extends AbstractResourcesConfigu
*/
private final JSFMockHelper jsfMockHelper = new JSFMockHelper();
@Override
@Before
public void setUp() throws Exception {
this.jsfMockHelper.setUp();
super.setUp();
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
super.tearDown();
this.jsfMockHelper.tearDown();
}

View File

@@ -1,5 +1,9 @@
package org.springframework.faces.model;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -13,15 +17,17 @@ import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import junit.framework.TestCase;
import org.apache.myfaces.test.mock.MockFacesContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.faces.webflow.JSFMockHelper;
import org.springframework.util.ReflectionUtils;
import com.sun.faces.facelets.component.UIRepeat;
public class SelectionTrackingActionListenerTests extends TestCase {
public class SelectionTrackingActionListenerTests {
/**
* JSF Mock Helper
@@ -48,6 +54,7 @@ public class SelectionTrackingActionListenerTests extends TestCase {
*/
private final ActionListener selectionTrackingListener = new SelectionTrackingActionListener(this.delegateListener);
@Before
public void setUp() throws Exception {
this.jsfMockHelper.setUp();
this.viewToTest = new UIViewRoot();
@@ -58,10 +65,12 @@ public class SelectionTrackingActionListenerTests extends TestCase {
this.dataModel = new OneSelectionTrackingListDataModel<>(rows);
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
this.jsfMockHelper.tearDown();
}
@Test
public void testProcessActionWithUIData() {
UIData dataTable = new UIData();
@@ -86,6 +95,7 @@ public class SelectionTrackingActionListenerTests extends TestCase {
assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
}
@Test
public void testProcessActionWithUIRepeat() {
UIRepeat uiRepeat = new UIRepeat();

View File

@@ -1,5 +1,10 @@
package org.springframework.faces.model.converter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -7,16 +12,16 @@ import java.util.List;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.binding.convert.converters.Converter;
import org.springframework.faces.model.SerializableListDataModel;
public class DataModelConverterTests extends TestCase {
public class DataModelConverterTests {
Converter converter = new DataModelConverter();
@SuppressWarnings("unchecked")
@Test
public void testConvertListToDataModel() throws Exception {
List<Object> sourceList = new ArrayList<>();
@@ -28,6 +33,7 @@ public class DataModelConverterTests extends TestCase {
}
@SuppressWarnings("unchecked")
@Test
public void testConvertListToListDataModel() throws Exception {
List<Object> sourceList = new ArrayList<>();
@@ -39,6 +45,7 @@ public class DataModelConverterTests extends TestCase {
}
@SuppressWarnings("unchecked")
@Test
public void testConvertListToSerializableListDataModel() throws Exception {
List<Object> sourceList = new ArrayList<>();
@@ -51,6 +58,7 @@ public class DataModelConverterTests extends TestCase {
}
@SuppressWarnings("unchecked")
@Test
public void testConvertListToSerializableListDataModelNullSource() throws Exception {
List<Object> sourceList = null;

View File

@@ -5,17 +5,19 @@ import java.util.List;
import javax.faces.model.DataModel;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.springframework.binding.convert.ConversionExecutor;
public class FacesConversionServiceTests extends TestCase {
public class FacesConversionServiceTests {
private FacesConversionService service;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.service = new FacesConversionService();
}
@Test
public void testGetAbstractType() {
ConversionExecutor executor = this.service.getConversionExecutor(List.class, DataModel.class);
ArrayList<Object> list = new ArrayList<>();

View File

@@ -1,13 +1,18 @@
package org.springframework.faces.mvc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Locale;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.faces.webflow.JSFMockHelper;
import org.springframework.faces.webflow.MockViewHandler;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -17,12 +22,13 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
public class JsfViewTests extends TestCase {
public class JsfViewTests {
UrlBasedViewResolver resolver;
private final JSFMockHelper jsfMock = new JSFMockHelper();
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
this.jsfMock.facesContext().getApplication().setViewHandler(new ResourceCheckingViewHandler());
@@ -34,15 +40,18 @@ public class JsfViewTests extends TestCase {
this.resolver.setApplicationContext(new StaticWebApplicationContext());
}
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
}
@Test
public void testViewResolution() throws Exception {
View view = this.resolver.resolveViewName("intro", new Locale("EN"));
assertTrue(view instanceof JsfView);
}
@Test
public void testViewRender() throws Exception {
JsfView view = (JsfView) this.resolver.resolveViewName("intro", new Locale("EN"));
view.setApplicationContext(new StaticWebApplicationContext());

View File

@@ -15,50 +15,59 @@
*/
package org.springframework.faces.security;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* Unit tests for {@link FaceletsAuthorizeTag}.
* @author Rossen Stoyanchev
*/
public class FaceletsAuthorizeTagTests extends TestCase {
public class FaceletsAuthorizeTagTests {
@Test
public void testIfAllGrantedWithOneRole() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfAllGranted("ROLE_A");
assertEquals("hasRole('ROLE_A')", tag.getAccess());
}
@Test
public void testIfAllGrantedWithMultipleRoles() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfAllGranted("ROLE_A, ROLE_B, ROLE_C");
assertEquals("hasRole('ROLE_A') and hasRole('ROLE_B') and hasRole('ROLE_C')", tag.getAccess());
}
@Test
public void testIfAnyGrantedWithOneRole() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfAnyGranted("ROLE_A");
assertEquals("hasAnyRole('ROLE_A')", tag.getAccess());
}
@Test
public void testIfAnyGrantedWithMultipleRole() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfAnyGranted("ROLE_A, ROLE_B, ROLE_C");
assertEquals("hasAnyRole('ROLE_A','ROLE_B','ROLE_C')", tag.getAccess());
}
@Test
public void testIfNoneGrantedWithOneRole() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfNotGranted("ROLE_A");
assertEquals("!hasAnyRole('ROLE_A')", tag.getAccess());
}
@Test
public void testIfNoneGrantedWithMultipleRole() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfNotGranted("ROLE_A, ROLE_B, ROLE_C");
assertEquals("!hasAnyRole('ROLE_A','ROLE_B','ROLE_C')", tag.getAccess());
}
@Test
public void testIfAllAnyNotGranted() {
FaceletsAuthorizeTag tag = new FaceletsAuthorizeTag();
tag.setIfAllGranted("ROLE_A");

View File

@@ -1,21 +1,26 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import javax.el.ELContext;
import javax.el.MethodExpression;
import javax.el.MethodInfo;
import javax.faces.component.UICommand;
import javax.faces.event.ActionEvent;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.webflow.core.collection.LocalAttributeMap;
import org.springframework.webflow.engine.Flow;
import org.springframework.webflow.engine.ViewState;
import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
public class FlowActionListenerTests extends TestCase {
public class FlowActionListenerTests {
FlowActionListener listener;
@@ -23,7 +28,8 @@ public class FlowActionListenerTests extends TestCase {
RequestContext context = EasyMock.createMock(RequestContext.class);
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
this.listener = new FlowActionListener(this.jsfMock.application().getActionListener());
@@ -34,12 +40,13 @@ public class FlowActionListenerTests extends TestCase {
EasyMock.replay(this.context);
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@Test
public final void testProcessAction() {
String outcome = "foo";
@@ -56,6 +63,7 @@ public class FlowActionListenerTests extends TestCase {
this.jsfMock.externalContext().getRequestMap().get(JsfView.EVENT_KEY));
}
@Test
public final void testProcessAction_NullOutcome() {
String outcome = null;

View File

@@ -1,10 +1,18 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import javax.el.ELContext;
import junit.framework.TestCase;
import org.apache.myfaces.test.el.MockELContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.webflow.core.collection.LocalAttributeMap;
@@ -18,7 +26,7 @@ import org.springframework.webflow.test.MockRequestContext;
*
* @author Phillip Webb
*/
public class FlowELResolverTests extends TestCase {
public class FlowELResolverTests {
private final FlowELResolver resolver = new FlowELResolver();
@@ -26,14 +34,17 @@ public class FlowELResolverTests extends TestCase {
private final ELContext elContext = new MockELContext();
protected void setUp() {
@Before
public void setUp() {
RequestContextHolder.setRequestContext(this.requestContext);
}
protected void tearDown() {
@After
public void tearDown() {
RequestContextHolder.setRequestContext(null);
}
@Test
public void testRequestContextResolve() {
Object actual = this.resolver.getValue(this.elContext, null, "flowRequestContext");
assertTrue(this.elContext.isPropertyResolved());
@@ -41,6 +52,7 @@ public class FlowELResolverTests extends TestCase {
assertSame(this.requestContext, actual);
}
@Test
public void testImplicitFlowResolve() {
Object actual = this.resolver.getValue(this.elContext, null, "flowScope");
assertTrue(this.elContext.isPropertyResolved());
@@ -48,6 +60,7 @@ public class FlowELResolverTests extends TestCase {
assertSame(this.requestContext.getFlowScope(), actual);
}
@Test
public void testFlowResourceResolve() {
ApplicationContext applicationContext = new StaticWebApplicationContext();
((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
@@ -57,6 +70,7 @@ public class FlowELResolverTests extends TestCase {
assertSame(applicationContext, actual);
}
@Test
public void testScopeResolve() {
this.requestContext.getFlowScope().put("test", "test");
Object actual = this.resolver.getValue(this.elContext, null, "test");
@@ -64,6 +78,7 @@ public class FlowELResolverTests extends TestCase {
assertEquals("test", actual);
}
@Test
public void testMapAdaptableResolve() {
LocalAttributeMap<String> base = new LocalAttributeMap<>();
base.put("test", "test");
@@ -72,6 +87,7 @@ public class FlowELResolverTests extends TestCase {
assertEquals("test", actual);
}
@Test
public void testBeanResolveWithRequestContext() {
StaticWebApplicationContext applicationContext = new StaticWebApplicationContext();
((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
@@ -82,6 +98,7 @@ public class FlowELResolverTests extends TestCase {
assertTrue(actual instanceof Bean);
}
@Test
public void testBeanResolveWithoutRequestContext() {
RequestContextHolder.setRequestContext(null);
Object actual = this.resolver.getValue(this.elContext, null, "test");

View File

@@ -1,5 +1,10 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
@@ -12,9 +17,10 @@ import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.binding.message.DefaultMessageContext;
import org.springframework.binding.message.Message;
import org.springframework.binding.message.MessageBuilder;
@@ -22,7 +28,7 @@ import org.springframework.binding.message.MessageContext;
import org.springframework.faces.webflow.FlowFacesContext.FacesMessageSource;
import org.springframework.webflow.execution.RequestContext;
public class FlowFacesContextTests extends TestCase {
public class FlowFacesContextTests {
JSFMockHelper jsf = new JSFMockHelper();
@@ -35,22 +41,25 @@ public class FlowFacesContextTests extends TestCase {
MessageContext prepopulatedMessageContext;
@SuppressWarnings("cast")
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsf.setUp();
this.requestContext = (RequestContext) EasyMock.createMock(RequestContext.class);
this.facesContext = new FlowFacesContext(this.requestContext, this.jsf.facesContext());
setupMessageContext();
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsf.tearDown();
}
@Test
public final void testCurrentInstance() {
assertSame(FacesContext.getCurrentInstance(), this.facesContext);
}
@Test
public final void testAddMessage() {
this.messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -63,6 +72,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals("foo : bar", message.getText());
}
@Test
public final void testGetGlobalMessagesOnly() {
this.messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -81,6 +91,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(1, iterationCount);
}
@Test
public final void testGetAllMessages() {
this.messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -99,6 +110,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(2, iterationCount);
}
@Test
public final void testAddMessages_MultipleNullIds() {
this.messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -113,6 +125,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals("zoo : zar", messages[1].getText());
}
@Test
public final void testGetMessages() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -127,6 +140,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals("There should be 6 messages to iterate", 6, iterationCount);
}
@Test
public final void testMutableGetMessages() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -145,6 +159,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals("summary2", gotMessage.getSummary());
}
@Test
public final void testGetMessagesByClientId_ForComponent() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -162,6 +177,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(2, iterationCount);
}
@Test
public final void testGetMessagesByClientId_ForUserMessage() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -179,6 +195,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(1, iterationCount);
}
@Test
public final void testgetMessagesByClientId_InvalidId() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -188,6 +205,7 @@ public class FlowFacesContextTests extends TestCase {
assertFalse(i.hasNext());
}
@Test
public final void testGetClientIdsWithMessages() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -208,6 +226,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(3, iterationCount);
}
@Test
public final void testMessagesAreSerializable() throws Exception {
DefaultMessageContext messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(messageContext);
@@ -243,6 +262,7 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(FacesMessage.SEVERITY_FATAL, gotMessage.getSeverity());
}
@Test
public final void testGetMaximumSeverity() {
this.messageContext = this.prepopulatedMessageContext;
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
@@ -251,12 +271,14 @@ public class FlowFacesContextTests extends TestCase {
assertEquals(FacesMessage.SEVERITY_FATAL, this.facesContext.getMaximumSeverity());
}
@Test
public final void testGetELContext() {
assertNotNull(this.facesContext.getELContext());
assertSame(this.facesContext, this.facesContext.getELContext().getContext(FacesContext.class));
}
@Test
public final void testValidationFailed() {
this.messageContext = new DefaultMessageContext();
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);

View File

@@ -1,5 +1,7 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -7,20 +9,21 @@ import java.util.List;
import javax.faces.context.PartialViewContext;
import javax.faces.context.PartialViewContextWrapper;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Test;
import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.execution.View;
import org.springframework.webflow.test.MockRequestContext;
public class FlowPartialViewContextTests extends TestCase {
public class FlowPartialViewContextTests {
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
RequestContextHolder.setRequestContext(null);
}
@Test
public void testReturnFragmentIds() {
String[] fragmentIds = new String[] { "foo", "bar" };
@@ -31,6 +34,7 @@ public class FlowPartialViewContextTests extends TestCase {
assertEquals(Arrays.asList(fragmentIds), new FlowPartialViewContext(null).getRenderIds());
}
@Test
public void testNoFragmentIds() {
final List<String> renderIds = Arrays.asList("foo", "bar");
FlowPartialViewContext context = new FlowPartialViewContext(new PartialViewContextWrapper() {
@@ -51,6 +55,7 @@ public class FlowPartialViewContextTests extends TestCase {
assertEquals(renderIds, context.getRenderIds());
}
@Test
public void testReturnFragmentIdsMutable() {
String[] fragmentIds = new String[] { "foo", "bar" };

View File

@@ -1,10 +1,14 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import java.io.IOException;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.webflow.core.collection.LocalAttributeMap;
import org.springframework.webflow.execution.FlowExecutionContext;
@@ -12,7 +16,7 @@ import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.test.MockFlowExecutionKey;
public class FlowResponseStateManagerTests extends TestCase {
public class FlowResponseStateManagerTests {
private final JSFMockHelper jsfMock = new JSFMockHelper();
@@ -24,7 +28,8 @@ public class FlowResponseStateManagerTests extends TestCase {
private FlowExecutionContext flowExecutionContext;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
this.webappContext = new StaticWebApplicationContext();
this.webappContext.setServletContext(this.jsfMock.servletContext());
@@ -36,17 +41,14 @@ public class FlowResponseStateManagerTests extends TestCase {
this.responseStateManager = new FlowResponseStateManager(null);
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.webappContext.close();
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
public void testname() {
}
@Test
public void testWriteFlowSerializedView() throws IOException {
EasyMock.expect(this.flowExecutionContext.getKey()).andReturn(new MockFlowExecutionKey("e1s1"));
LocalAttributeMap<Object> viewMap = new LocalAttributeMap<>();
@@ -64,6 +66,7 @@ public class FlowResponseStateManagerTests extends TestCase {
EasyMock.verify(this.flowExecutionContext, this.requestContext);
}
@Test
public void testGetState() {
Object state = new Object();

View File

@@ -1,15 +1,20 @@
package org.springframework.faces.webflow;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.web.context.support.StaticWebApplicationContext;
public class JsfAjaxHandlerTests extends TestCase {
public class JsfAjaxHandlerTests {
private final JSFMockHelper jsfMock = new JSFMockHelper();
private JsfAjaxHandler ajaxHandler;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
StaticWebApplicationContext webappContext = new StaticWebApplicationContext();
webappContext.setServletContext(this.jsfMock.servletContext());
@@ -17,10 +22,12 @@ public class JsfAjaxHandlerTests extends TestCase {
this.ajaxHandler.setApplicationContext(webappContext);
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
}
@Test
public void testSendAjaxRedirect() throws Exception {
this.ajaxHandler.sendAjaxRedirectInternal("/target", this.jsfMock.request(), this.jsfMock.response(), false);
assertTrue(this.jsfMock.contentAsString().matches("<\\?xml version='1.0' encoding='utf-8'\\?>\n<partial-response.*><redirect url=\"/target\"/></partial-response>"));

View File

@@ -1,5 +1,8 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -14,9 +17,10 @@ import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.el.ExpressionFactoryImpl;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.FluentParserContext;
@@ -31,7 +35,7 @@ import org.springframework.webflow.execution.View;
import org.springframework.webflow.expression.el.WebFlowELExpressionParser;
import org.springframework.webflow.test.MockExternalContext;
public class JsfFinalResponseActionTests extends TestCase {
public class JsfFinalResponseActionTests {
private static final String VIEW_ID = "/testView.xhtml";
@@ -49,12 +53,13 @@ public class JsfFinalResponseActionTests extends TestCase {
ExpressionParser parser = new WebFlowELExpressionParser(new ExpressionFactoryImpl());
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
configureJsf();
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@@ -82,6 +87,7 @@ public class JsfFinalResponseActionTests extends TestCase {
new LocalParameterMap(new HashMap<>()));
}
@Test
public void testRender() throws Exception {
UIViewRoot newRoot = new UIViewRoot();

View File

@@ -1,9 +1,13 @@
package org.springframework.faces.webflow;
import junit.framework.TestCase;
import org.springframework.webflow.context.servlet.AjaxHandler;
import org.springframework.webflow.context.servlet.DefaultAjaxHandler;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.webflow.context.ExternalContext;
@@ -12,11 +16,12 @@ import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.executor.FlowExecutionResult;
import org.springframework.webflow.executor.FlowExecutor;
public class JsfFlowHandlerAdapterTests extends TestCase {
public class JsfFlowHandlerAdapterTests {
private JsfFlowHandlerAdapter handlerAdapter;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.setServletContext(new MockServletContext());
this.handlerAdapter = new JsfFlowHandlerAdapter();
@@ -24,12 +29,14 @@ public class JsfFlowHandlerAdapterTests extends TestCase {
this.handlerAdapter.setFlowExecutor(new StubFlowExecutor());
}
@Test
public void testAjaxHandlerNotProvided() throws Exception {
this.handlerAdapter.afterPropertiesSet();
assertNotNull(this.handlerAdapter.getAjaxHandler());
assertTrue(this.handlerAdapter.getAjaxHandler() instanceof JsfAjaxHandler);
}
@Test
public void testAjaxHandlerProvided() throws Exception {
AjaxHandler myAjaxHandler = new DefaultAjaxHandler();
this.handlerAdapter.setAjaxHandler(myAjaxHandler);

View File

@@ -1,8 +1,11 @@
package org.springframework.faces.webflow;
import junit.framework.TestCase;
import static org.junit.Assert.assertNotNull;
import org.apache.el.ExpressionFactoryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.binding.expression.Expression;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.FluentParserContext;
@@ -10,7 +13,7 @@ import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.test.MockRequestContext;
public class JsfManagedBeanAwareELExpressionParserTests extends TestCase {
public class JsfManagedBeanAwareELExpressionParserTests {
JSFMockHelper jsfMock = new JSFMockHelper();
@@ -18,19 +21,21 @@ public class JsfManagedBeanAwareELExpressionParserTests extends TestCase {
ExpressionParser parser;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
RequestContextHolder.setRequestContext(this.requestContext);
this.parser = new JsfManagedBeanAwareELExpressionParser(new ExpressionFactoryImpl());
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@SuppressWarnings("unchecked")
@Test
public void testGetJSFBean() {
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
Expression expr = this.parser.parseExpression("myJsfBean", new FluentParserContext().evaluate(RequestContext.class));

View File

@@ -15,13 +15,19 @@
*/
package org.springframework.faces.webflow;
import junit.framework.TestCase;
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 org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.test.MockRequestContext;
public class JsfManagedBeanPropertyAccessorTests extends TestCase {
public class JsfManagedBeanPropertyAccessorTests {
JSFMockHelper jsfMock = new JSFMockHelper();
@@ -29,31 +35,35 @@ public class JsfManagedBeanPropertyAccessorTests extends TestCase {
private MockRequestContext requestContext;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
this.requestContext = new MockRequestContext();
RequestContextHolder.setRequestContext(this.requestContext);
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@SuppressWarnings("unchecked")
@Test
public void testCanRead() {
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
assertTrue(this.accessor.canRead(null, null, "myJsfBean"));
}
@SuppressWarnings("unchecked")
@Test
public void testRead() {
Object jsfBean = new Object();
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", jsfBean);
assertEquals(jsfBean, this.accessor.read(null, null, "myJsfBean").getValue());
}
@Test
public void testCanWrite() {
assertFalse(this.accessor.canWrite(null, null, "myJsfBean"));
@@ -73,6 +83,7 @@ public class JsfManagedBeanPropertyAccessorTests extends TestCase {
map.clear();
}
@Test
public void testWrite() {
Object jsfBean1 = new Object();
Object jsfBean2 = new Object();

View File

@@ -19,6 +19,7 @@ import org.apache.myfaces.test.mock.MockFacesContextFactory;
import org.apache.myfaces.test.mock.MockRenderKitFactory;
import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
import org.junit.Test;
public class JsfUtilsTests extends AbstractJsfTestCase {
@@ -26,6 +27,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
super(name);
}
@Test
public void testBeforeListenersCalledInForwardOrder() {
List<OrderVerifyingPhaseListener> list = new ArrayList<>();
MockLifecycle lifecycle = new MockLifecycle();
@@ -41,6 +43,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
assertEquals(listener3, list.get(2));
}
@Test
public void testAfterListenersCalledInReverseOrder() {
List<OrderVerifyingPhaseListener> list = new ArrayList<>();
MockLifecycle lifecycle = new MockLifecycle();
@@ -56,6 +59,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
assertEquals(listener1, list.get(2));
}
@Test
public void testGetFactory() {
// Not testing all but at least test the mocked factories
assertTrue(JsfUtils.findFactory(ApplicationFactory.class) instanceof MockApplicationFactory);
@@ -64,6 +68,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
assertTrue(JsfUtils.findFactory(RenderKitFactory.class) instanceof MockRenderKitFactory);
}
@Test
public void testGetUnknowFactory() {
try {
JsfUtils.findFactory(InputStream.class);

View File

@@ -1,5 +1,12 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -21,11 +28,12 @@ import javax.faces.event.PostRestoreStateEvent;
import javax.faces.event.SystemEvent;
import javax.faces.lifecycle.Lifecycle;
import junit.framework.TestCase;
import org.apache.el.ExpressionFactoryImpl;
import org.apache.myfaces.test.mock.MockApplication20;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.FluentParserContext;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -43,7 +51,7 @@ import org.springframework.webflow.execution.ViewFactory;
import org.springframework.webflow.expression.el.WebFlowELExpressionParser;
import org.springframework.webflow.test.MockExternalContext;
public class JsfViewFactoryTests extends TestCase {
public class JsfViewFactoryTests {
private static final String VIEW_ID = "/testView.xhtml";
@@ -69,7 +77,8 @@ public class JsfViewFactoryTests extends TestCase {
private final MockHttpServletResponse response = new MockHttpServletResponse();
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
configureJsf();
this.extContext.setNativeContext(this.servletContext);
this.extContext.setNativeRequest(this.request);
@@ -81,8 +90,8 @@ public class JsfViewFactoryTests extends TestCase {
new LocalParameterMap(new HashMap<>()));
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@@ -100,6 +109,7 @@ public class JsfViewFactoryTests extends TestCase {
/**
* View has not yet been created
*/
@Test
public final void testGetView_Create() {
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
@@ -126,6 +136,7 @@ public class JsfViewFactoryTests extends TestCase {
/**
* View already exists in view/flash scope and must be restored and the lifecycle executed, no flow event signaled
*/
@Test
public final void testGetView_Restore() {
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
@@ -159,6 +170,7 @@ public class JsfViewFactoryTests extends TestCase {
/**
* View already exists in view/flash scope and must be restored and the lifecycle executed, no flow event signaled
*/
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
public final void testGetView_RestoreWithBindings() {
@@ -208,6 +220,7 @@ public class JsfViewFactoryTests extends TestCase {
* Ajax Request - View already exists in view/flash scope and must be restored and the lifecycle executed, no flow
* event signaled
*/
@Test
public final void testGetView_Restore_Ajax() {
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
@@ -241,6 +254,7 @@ public class JsfViewFactoryTests extends TestCase {
/**
* Third party sets the view root before RESTORE_VIEW
*/
@Test
public final void testGetView_ExternalViewRoot() {
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
@@ -264,6 +278,7 @@ public class JsfViewFactoryTests extends TestCase {
assertTrue("The PostRestoreViewEvent was not seen", newRoot.isPostRestoreStateEventSeen());
}
@Test
public void testGetView_ExceptionsOnPostRestoreStateEvent() {
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,

View File

@@ -1,5 +1,9 @@
package org.springframework.faces.webflow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.StringWriter;
import javax.faces.FacesException;
@@ -11,10 +15,11 @@ import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.lifecycle.Lifecycle;
import junit.framework.TestCase;
import org.apache.myfaces.test.mock.MockResponseWriter;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.execution.FlowExecutionContext;
import org.springframework.webflow.execution.FlowExecutionKey;
@@ -23,7 +28,7 @@ import org.springframework.webflow.execution.RequestContextHolder;
import org.springframework.webflow.test.MockExternalContext;
import org.springframework.webflow.test.MockParameterMap;
public class JsfViewTests extends TestCase {
public class JsfViewTests {
private static final String VIEW_ID = "testView.xhtml";
@@ -59,7 +64,8 @@ public class JsfViewTests extends TestCase {
}
};
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.jsfMock.setUp();
this.jsfMock.facesContext().getApplication().setViewHandler(new MockViewHandler());
@@ -89,17 +95,19 @@ public class JsfViewTests extends TestCase {
this.view = new JsfView(viewToRender, this.jsfMock.lifecycle(), this.context);
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
this.jsfMock.tearDown();
RequestContextHolder.setRequestContext(null);
}
@Test
public final void testSaveState() {
EasyMock.replay(this.context, this.flowExecutionContext, this.flowMap, this.flashScope);
this.view.saveState();
}
@Test
public final void testRender() throws IOException {
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
@@ -110,6 +118,7 @@ public class JsfViewTests extends TestCase {
this.view.render();
}
@Test
public final void testRenderException() {
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
@@ -128,6 +137,7 @@ public class JsfViewTests extends TestCase {
/**
* View already exists in view scope and must be restored and the lifecycle executed, no event signaled
*/
@Test
public final void testProcessUserEvent_Restored_NoEvent() {
EasyMock.expect(this.flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
@@ -153,6 +163,7 @@ public class JsfViewTests extends TestCase {
/**
* View already exists in view scope and must be restored and the lifecycle executed, an event is signaled
*/
@Test
public final void testProcessUserEvent_Restored_EventSignaled() {
EasyMock.expect(this.flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
@@ -176,6 +187,7 @@ public class JsfViewTests extends TestCase {
assertTrue("The lifecycle should have been invoked", ((EventSignalingLifecycle) lifecycle).executed);
}
@Test
public final void testUserEventQueued_GETRefresh() {
MockParameterMap requestParameterMap = new MockParameterMap();
@@ -189,6 +201,7 @@ public class JsfViewTests extends TestCase {
assertFalse("No user event should be queued", createdView.userEventQueued());
}
@Test
public final void testUserEventQueued_FormSubmitted() {
this.jsfMock.request().addParameter("execution", "e1s1");