Merge pull request #99 from edysli/internal-tests-junit5
This commit is contained in:
@@ -73,6 +73,7 @@ configure(subprojects.findAll {
|
||||
hibernate5Version = "5.2.17.Final"
|
||||
tiles3Version = "3.0.8"
|
||||
log4jVersion = "2.11.1"
|
||||
junit5Version = "5.5.1"
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
@@ -95,9 +96,7 @@ configure(subprojects.findAll {
|
||||
compile("org.springframework:spring-core:$springVersion")
|
||||
compile("org.springframework:spring-expression:$springVersion")
|
||||
compileOnly("javax.el:javax.el-api:3.0.1-b04")
|
||||
testCompile("junit:junit:4.12") {
|
||||
exclude group:'org.hamcrest', module:'hamcrest-core'
|
||||
}
|
||||
testCompile("org.junit.jupiter:junit-jupiter:${junit5Version}")
|
||||
testCompile("org.hamcrest:hamcrest-all:1.3")
|
||||
testCompile("org.easymock:easymock:3.5.1")
|
||||
testCompile("org.apache.tomcat:tomcat-jasper-el:8.5.27")
|
||||
@@ -157,7 +156,7 @@ project("spring-webflow") {
|
||||
optional("org.apache.tiles:tiles-extras:$tiles3Version") {
|
||||
exclude group: "org.springframework", module: "spring-web"
|
||||
}
|
||||
provided("junit:junit:3.8.2")
|
||||
provided("junit:junit:4.12")
|
||||
testCompile("org.springframework:spring-aop:$springVersion")
|
||||
testCompile("org.springframework:spring-jdbc:$springVersion")
|
||||
testCompile("org.springframework:spring-test:$springVersion")
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package org.springframework.binding.collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MapAccessorTests extends TestCase {
|
||||
public class MapAccessorTests {
|
||||
private MapAccessor<String, Object> accessor;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("string", "hello");
|
||||
map.put("integer", 9);
|
||||
@@ -16,6 +20,7 @@ public class MapAccessorTests extends TestCase {
|
||||
this.accessor = new MapAccessor<>(map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessNullAttribute() {
|
||||
assertEquals(null, accessor.get("null"));
|
||||
assertEquals(null, accessor.get("null", "something else"));
|
||||
@@ -28,16 +33,19 @@ public class MapAccessorTests extends TestCase {
|
||||
assertEquals(null, accessor.getRequiredCollection("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetString() {
|
||||
assertEquals("hello", accessor.getString("string"));
|
||||
assertEquals("hello", accessor.getRequiredString("string"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInteger() {
|
||||
assertEquals(new Integer(9), accessor.getInteger("integer"));
|
||||
assertEquals(new Integer(9), accessor.getRequiredInteger("integer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredMissingKey() {
|
||||
try {
|
||||
accessor.getRequired("bogus");
|
||||
|
||||
@@ -15,21 +15,28 @@
|
||||
*/
|
||||
package org.springframework.binding.collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.binding.collection.SharedMapDecorator}.
|
||||
*/
|
||||
public class SharedMapDecoratorTests extends TestCase {
|
||||
public class SharedMapDecoratorTests {
|
||||
|
||||
private SharedMapDecorator<String, String> map = new SharedMapDecorator<>(
|
||||
new HashMap<>());
|
||||
|
||||
@Test
|
||||
public void testGetPutRemove() {
|
||||
assertTrue(map.size() == 0);
|
||||
assertTrue(map.isEmpty());
|
||||
@@ -47,6 +54,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
assertNull(map.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
Map<String, String> all = new HashMap<>();
|
||||
all.put("foo", "bar");
|
||||
@@ -55,6 +63,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
assertTrue(map.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntrySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
@@ -62,6 +71,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
assertTrue(entrySet.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
@@ -69,6 +79,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
assertTrue(keySet.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValues() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
|
||||
@@ -15,18 +15,24 @@
|
||||
*/
|
||||
package org.springframework.binding.collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.binding.collection.StringKeyedMapAdapter}.
|
||||
*/
|
||||
public class StringKeyedMapAdapterTests extends TestCase {
|
||||
public class StringKeyedMapAdapterTests {
|
||||
|
||||
private Map<String, String> contents = new HashMap<>();
|
||||
|
||||
@@ -49,6 +55,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testGetPutRemove() {
|
||||
assertTrue(map.size() == 0);
|
||||
assertTrue(map.isEmpty());
|
||||
@@ -66,6 +73,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
assertNull(map.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
Map<String, String> all = new HashMap<>();
|
||||
all.put("foo", "bar");
|
||||
@@ -74,6 +82,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
assertTrue(map.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntrySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
@@ -81,6 +90,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
assertTrue(entrySet.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
@@ -88,6 +98,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
assertTrue(keySet.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValues() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
package org.springframework.binding.convert.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,8 +32,7 @@ import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
@@ -45,14 +49,16 @@ import org.springframework.binding.format.DefaultNumberFormatFactory;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class DefaultConversionServiceTests extends TestCase {
|
||||
public class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
public void testConvertCompatibleTypes() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
List<Object> lst = new ArrayList<>();
|
||||
assertSame(lst, service.getConversionExecutor(ArrayList.class, List.class).execute(lst));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideConverter() {
|
||||
Converter customConverter = new StringToBoolean("ja", "nee");
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -69,6 +75,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertTrue(((Boolean) executor.execute("ja")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetClassNotSupported() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
try {
|
||||
@@ -78,6 +85,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, Integer.class);
|
||||
@@ -89,6 +97,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", threeString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterConverter() {
|
||||
GenericConversionService service = new GenericConversionService();
|
||||
FormattedStringToNumber converter = new FormattedStringToNumber();
|
||||
@@ -104,6 +113,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3,000", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverter() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
FormattedStringToNumber converter = new FormattedStringToNumber();
|
||||
@@ -119,6 +129,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3,000", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterForSameType() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("trimmer", new Trimmer());
|
||||
@@ -126,6 +137,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("a string", executor.execute("a string "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterForSameTypeNotCompatibleSource() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("trimmer", new Trimmer());
|
||||
@@ -136,6 +148,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterForSameTypeNotCompatibleTarget() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("trimmer", new Trimmer());
|
||||
@@ -146,6 +159,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterReverseComparsion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -157,6 +171,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterReverseNotCompatibleSource() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -167,6 +182,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterArrayToArray() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -176,6 +192,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", p[1].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterArrayToArrayReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -195,6 +212,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", p[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterArrayToArrayBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -205,6 +223,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterArrayToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -215,6 +234,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", (list.get(1)).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterArrayToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -227,6 +247,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", p.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterArrayToListBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -238,6 +259,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterListToArray() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -250,6 +272,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", p[1].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterListToArrayReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -264,6 +287,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", p[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterListToArrayBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -275,6 +299,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterObjectToArray() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -283,6 +308,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy1", p[0].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterObjectToArrayReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -292,6 +318,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy1", p[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterObjectToArrayBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -303,6 +330,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterObjectToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -312,6 +340,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy1", list.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterCsvStringToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -322,6 +351,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", list.get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterObjectToListBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -334,6 +364,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterObjectToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -344,6 +375,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy1", list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterListToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -357,6 +389,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", list.get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterListToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -372,6 +405,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("princy2", list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomConverterListToListBogus() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -386,6 +420,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversionPrimitive() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, int.class);
|
||||
@@ -393,6 +428,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals(new Integer(3), three);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayToArrayConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String[].class, Integer[].class);
|
||||
@@ -402,6 +438,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals(new Integer(3), result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayToArrayPrimitiveConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String[].class, int[].class);
|
||||
@@ -411,6 +448,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals(3, result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testArrayToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -421,6 +459,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListToArrayConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Collection.class, String[].class);
|
||||
@@ -434,6 +473,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSetToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -448,6 +488,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListToArrayConversionWithComponentConversion() {
|
||||
try {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -470,6 +511,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testArrayToLinkedListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -480,6 +522,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayAbstractListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
try {
|
||||
@@ -489,6 +532,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringToArrayConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, String[].class);
|
||||
@@ -499,6 +543,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStringToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
@@ -510,6 +555,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringToArrayConversionWithElementConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, Integer[].class);
|
||||
|
||||
@@ -15,26 +15,34 @@
|
||||
*/
|
||||
package org.springframework.binding.convert.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.converters.StringToDate;
|
||||
|
||||
public class StaticConversionExecutorImplTests extends TestCase {
|
||||
public class StaticConversionExecutorImplTests {
|
||||
|
||||
private StaticConversionExecutor conversionExecutor;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
StringToDate stringToDate = new StringToDate();
|
||||
conversionExecutor = new StaticConversionExecutor(String.class, Date.class, stringToDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeConversion() {
|
||||
assertTrue(conversionExecutor.execute("2008-10-10").getClass().equals(Date.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignmentCompatibleTypeConversion() {
|
||||
java.sql.Date date = new java.sql.Date(123L);
|
||||
try {
|
||||
@@ -45,10 +53,12 @@ public class StaticConversionExecutorImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNull() {
|
||||
assertNull(conversionExecutor.execute(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalType() {
|
||||
try {
|
||||
conversionExecutor.execute(new StringBuilder());
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
*/
|
||||
package org.springframework.binding.expression.beanwrapper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.binding.convert.converters.StringToDate;
|
||||
import org.springframework.binding.convert.service.GenericConversionService;
|
||||
@@ -25,12 +30,13 @@ import org.springframework.binding.expression.ParserException;
|
||||
import org.springframework.binding.expression.ValueCoercionException;
|
||||
import org.springframework.binding.expression.support.FluentParserContext;
|
||||
|
||||
public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
public class BeanWrapperExpressionParserTests {
|
||||
|
||||
private BeanWrapperExpressionParser parser = new BeanWrapperExpressionParser();
|
||||
|
||||
private TestBean bean = new TestBean();
|
||||
|
||||
@Test
|
||||
public void testParseSimple() {
|
||||
String exp = "flag";
|
||||
Expression e = parser.parseExpression(exp, null);
|
||||
@@ -39,6 +45,7 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
assertFalse(b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleAllowDelimited() {
|
||||
parser.setAllowDelimitedEvalExpressions(true);
|
||||
String exp = "${flag}";
|
||||
@@ -48,6 +55,7 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
assertFalse(b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleDelimitedNotAllowed() {
|
||||
String exp = "${flag}";
|
||||
try {
|
||||
@@ -57,6 +65,7 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateSimpleLiteral() {
|
||||
String exp = "flag";
|
||||
Expression e = parser.parseExpression(exp, new FluentParserContext().template());
|
||||
@@ -64,12 +73,14 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
assertEquals("flag", e.getValue(bean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateEmpty() {
|
||||
Expression e = parser.parseExpression("", new FluentParserContext().template());
|
||||
assertNotNull(e);
|
||||
assertEquals("", e.getValue(bean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateComposite() {
|
||||
String exp = "hello ${flag} ${flag} ${flag}";
|
||||
Expression e = parser.parseExpression(exp, new FluentParserContext().template());
|
||||
@@ -78,6 +89,7 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
assertEquals("hello false false false", str);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateEnclosedCompositeNotSupported() {
|
||||
String exp = "${hello ${flag} ${flag} ${flag}}";
|
||||
try {
|
||||
@@ -87,18 +99,21 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueType() {
|
||||
String exp = "flag";
|
||||
Expression e = parser.parseExpression(exp, null);
|
||||
assertEquals(boolean.class, e.getValueType(bean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueTypeNullCollectionValue() {
|
||||
String exp = "list[0]";
|
||||
Expression e = parser.parseExpression(exp, null);
|
||||
assertEquals(null, e.getValueType(bean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValueWithCoersion() {
|
||||
GenericConversionService cs = (GenericConversionService) parser.getConversionService();
|
||||
StringToDate converter = new StringToDate();
|
||||
@@ -108,6 +123,7 @@ public class BeanWrapperExpressionParserTests extends TestCase {
|
||||
e.setValue(bean, "2008-9-15");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetBogusValueWithCoersion() {
|
||||
Expression e = parser.parseExpression("date", null);
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -8,9 +11,9 @@ import javax.el.ELResolver;
|
||||
import javax.el.FunctionMapper;
|
||||
import javax.el.VariableMapper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.EvaluationException;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionVariable;
|
||||
@@ -18,20 +21,23 @@ import org.springframework.binding.expression.ParserException;
|
||||
import org.springframework.binding.expression.ValueCoercionException;
|
||||
import org.springframework.binding.expression.support.FluentParserContext;
|
||||
|
||||
public class ELExpressionParserTests extends TestCase {
|
||||
public class ELExpressionParserTests {
|
||||
|
||||
private ELExpressionParser parser = new ELExpressionParser(new ExpressionFactoryImpl());
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
parser.putContextFactory(TestBean.class, new TestELContextFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleEvalExpressionNoParserContext() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals(7L, exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNullExpressionString() {
|
||||
String expressionString = null;
|
||||
try {
|
||||
@@ -42,11 +48,13 @@ public class ELExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNull() {
|
||||
Expression exp = parser.parseExpression("null", null);
|
||||
assertEquals(null, exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyExpressionString() {
|
||||
String expressionString = "";
|
||||
try {
|
||||
@@ -57,6 +65,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleEvalExpressionNoEvalContextWithTypeCoersion() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser
|
||||
@@ -64,24 +73,28 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals(7, exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBeanEvalExpressionNoParserContext() {
|
||||
String expressionString = "value";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("foo", exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEvalExpressionWithContextTypeCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class));
|
||||
assertEquals(2L, exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEvalExpressionWithContextCustomELVariableResolver() {
|
||||
String expressionString = "specialProperty";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().evaluate(TestBean.class));
|
||||
assertEquals("Custom resolver resolved this special property!", exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBeanEvalExpressionInvalidELVariable() {
|
||||
try {
|
||||
String expressionString = "bogus";
|
||||
@@ -94,12 +107,14 @@ public class ELExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLiteralExpression() {
|
||||
String expressionString = "'value'";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("value", exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateExpression() {
|
||||
String expressionString = "text text text #{value} text text text#{value}";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template());
|
||||
@@ -107,6 +122,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals("text text text foo text text textfoo", exp.getValue(target));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateExpressionWithVariables() {
|
||||
String expressionString = "#{value}#{max}";
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
@@ -115,6 +131,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals("foo2", exp.getValue(target));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariablesWithCoersion() {
|
||||
Expression exp = parser.parseExpression("max", new FluentParserContext().variable(new ExpressionVariable("max",
|
||||
"maximum", new FluentParserContext().expectResult(Long.class))));
|
||||
@@ -122,6 +139,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals(2L, exp.getValue(target));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateNestedVariables() {
|
||||
String expressionString = "#{value}#{max}";
|
||||
Expression exp = parser.parseExpression(
|
||||
@@ -140,12 +158,14 @@ public class ELExpressionParserTests extends TestCase {
|
||||
// assertEquals(null, e.getValueType(target));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testGetExpressionString() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("maximum", exp.getExpressionString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpressionType() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -153,6 +173,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals(int.class, exp.getValueType(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueWithCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(String.class));
|
||||
@@ -160,6 +181,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals("2", exp.getValue(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueCoersionError() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
@@ -172,6 +194,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -180,6 +203,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals(5, context.getMaximum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValueWithTypeCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -188,6 +212,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
assertEquals(5, context.getMaximum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValueCoersionError() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
|
||||
@@ -1,46 +1,55 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.el.ELContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.collection.MapAdaptable;
|
||||
|
||||
public class MapAdaptableELResolverTests extends TestCase {
|
||||
public class MapAdaptableELResolverTests {
|
||||
|
||||
private ELContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
context = new DefaultELContext(new MapAdaptableELResolver(), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
Class<?> type = context.getELResolver().getType(context, new TestMapAdaptable(), "bar");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals(String.class, type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType_UnknownProperty() {
|
||||
Class<?> type = context.getELResolver().getType(context, new TestMapAdaptable(), "foo");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals(null, type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
Object value = context.getELResolver().getValue(context, new TestMapAdaptable(), "bar");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals("bar", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue_UnknownProperty() {
|
||||
Object value = context.getELResolver().getValue(context, new TestMapAdaptable(), "foo");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals(null, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
MapAdaptable<String, String> testMap = new TestMapAdaptable();
|
||||
context.getELResolver().setValue(context, testMap, "foo", "foo");
|
||||
@@ -48,6 +57,7 @@ public class MapAdaptableELResolverTests extends TestCase {
|
||||
assertEquals("foo", testMap.asMap().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValue_OverWrite() {
|
||||
MapAdaptable<String, String> testMap = new TestMapAdaptable();
|
||||
context.getELResolver().setValue(context, testMap, "bar", "foo");
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
package org.springframework.binding.expression.spel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.EvaluationException;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionVariable;
|
||||
@@ -40,20 +44,23 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
public class ELExpressionParserCompatibilityTests {
|
||||
|
||||
private SpringELExpressionParser parser = new SpringELExpressionParser(new SpelExpressionParser());
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
parser.addPropertyAccessor(new SpecialPropertyAccessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleEvalExpressionNoParserContext() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals(7, exp.getValue(null)); // Unified EL returns Long
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNullExpressionString() {
|
||||
String expressionString = null;
|
||||
try {
|
||||
@@ -64,11 +71,13 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNull() {
|
||||
Expression exp = parser.parseExpression("null", null);
|
||||
assertEquals(null, exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyExpressionString() {
|
||||
String expressionString = "";
|
||||
try {
|
||||
@@ -79,18 +88,21 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleEvalExpressionNoEvalContextWithTypeCoersion() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class));
|
||||
assertEquals(7L, exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBeanEvalExpressionNoParserContext() {
|
||||
String expressionString = "value";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("foo", exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEvalExpressionWithContextTypeCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser
|
||||
@@ -98,12 +110,14 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals(2, exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEvalExpressionWithContextCustomELVariableResolver() {
|
||||
String expressionString = "specialProperty";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().evaluate(TestBean.class));
|
||||
assertEquals("Custom resolver resolved this special property!", exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBeanEvalExpressionInvalidELVariable() {
|
||||
try {
|
||||
String expressionString = "bogus";
|
||||
@@ -116,12 +130,14 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLiteralExpression() {
|
||||
String expressionString = "'value'";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("value", exp.getValue(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateExpression() {
|
||||
String expressionString = "text text text #{value} text text text#{value}";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template());
|
||||
@@ -129,6 +145,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals("text text text foo text text textfoo", exp.getValue(target));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTemplateExpressionWithVariables() {
|
||||
String expressionString = "#{value}#{#max}";
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
@@ -137,12 +154,14 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals("foo2", exp.getValue(target)); // TODO:
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpressionString() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals("maximum", exp.getExpressionString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpressionType() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -151,6 +170,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertTrue(int.class.equals(clazz) || Integer.class.equals(clazz));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueWithCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(String.class));
|
||||
@@ -158,6 +178,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals("2", exp.getValue(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueCoersionError() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
@@ -170,6 +191,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -178,6 +200,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals(5, context.getMaximum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValueWithTypeCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
@@ -186,6 +209,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
assertEquals(5, context.getMaximum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValueCoersionError() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
package org.springframework.binding.mapping;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.spel.SpringELExpressionParser;
|
||||
import org.springframework.binding.mapping.impl.DefaultMapper;
|
||||
import org.springframework.binding.mapping.impl.DefaultMapping;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
public class DefaultMapperTests extends TestCase {
|
||||
public class DefaultMapperTests {
|
||||
private DefaultMapper mapper = new DefaultMapper();
|
||||
private ExpressionParser parser = new SpringELExpressionParser(new SpelExpressionParser());
|
||||
|
||||
@Test
|
||||
public void testMapping() {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("foo", null), parser.parseExpression("bar",
|
||||
null));
|
||||
@@ -43,6 +47,7 @@ public class DefaultMapperTests extends TestCase {
|
||||
}).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappingConversion() {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("beep", null), parser.parseExpression(
|
||||
"beep", null));
|
||||
@@ -55,6 +60,7 @@ public class DefaultMapperTests extends TestCase {
|
||||
assertEquals(Locale.ENGLISH, bean2.beep);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappingConversionError() {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("boop", null), parser.parseExpression(
|
||||
"boop", null));
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package org.springframework.binding.message;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
public class DefaultMessageContextTests extends TestCase {
|
||||
public class DefaultMessageContextTests {
|
||||
private DefaultMessageContext context;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage("message", Locale.getDefault(), "Hello world resolved!");
|
||||
messageSource.addMessage("argmessage", Locale.getDefault(), "Hello world {0}!");
|
||||
context = new DefaultMessageContext(messageSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMessageContext() {
|
||||
context.addMessage(new MessageBuilder().defaultText("Hello world!").build());
|
||||
Message[] messages = context.getAllMessages();
|
||||
@@ -26,6 +30,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(null, messages[0].getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveMessage() {
|
||||
context.addMessage(new MessageBuilder().warning().source(this).code("message").build());
|
||||
Message[] messages = context.getMessagesBySource(this);
|
||||
@@ -35,6 +40,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(this, messages[0].getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveMessageDefaultText() {
|
||||
context.addMessage(new MessageBuilder().error().code("bogus").defaultText("Hello world fallback!").build());
|
||||
Message[] messages = context.getAllMessages();
|
||||
@@ -44,6 +50,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(null, messages[0].getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveMessageWithArgs() {
|
||||
context.addMessage(new MessageBuilder().error().source(this).code("argmessage").arg("Keith")
|
||||
.defaultText("Hello world fallback!").build());
|
||||
@@ -54,6 +61,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(this, messages[0].getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveMessageWithMultipleCodes() {
|
||||
context.addMessage(new MessageBuilder().error().source(this).code("bogus").code("argmessage").arg("Keith")
|
||||
.defaultText("Hello world fallback!").build());
|
||||
@@ -64,6 +72,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(this, messages[0].getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRestoreMessages() {
|
||||
context.addMessage(new MessageBuilder().defaultText("Info").build());
|
||||
context.addMessage(new MessageBuilder().error().defaultText("Error").build());
|
||||
@@ -80,6 +89,7 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
assertEquals(1, context.getMessagesBySource(this).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSequencing() {
|
||||
context.addMessage(new MessageBuilder().defaultText("Info").build());
|
||||
context.addMessage(new MessageBuilder().warning().source(this).code("message").build());
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
package org.springframework.binding.message;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
public class MessageBuilderTests extends TestCase {
|
||||
public class MessageBuilderTests {
|
||||
private StaticMessageSource messageSource = new StaticMessageSource();
|
||||
private Locale locale = Locale.getDefault();
|
||||
private MessageBuilder builder = new MessageBuilder();
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
messageSource.addMessage("foo", locale, "bar");
|
||||
messageSource.addMessage("bar", locale, "{0}");
|
||||
messageSource.addMessage("baz", locale, "boop");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDefaultText() {
|
||||
MessageResolver resolver = builder.defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -26,6 +32,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFatal() {
|
||||
MessageResolver resolver = builder.fatal().defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -34,6 +41,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildError() {
|
||||
MessageResolver resolver = builder.error().defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -42,6 +50,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWarning() {
|
||||
MessageResolver resolver = builder.warning().defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -50,6 +59,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildNothing() {
|
||||
MessageResolver resolver = builder.build();
|
||||
try {
|
||||
@@ -60,6 +70,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCode() {
|
||||
MessageResolver resolver = builder.error().code("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -68,6 +79,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCodes() {
|
||||
MessageResolver resolver = builder.error().codes("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -76,6 +88,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildArg() {
|
||||
MessageResolver resolver = builder.error().code("bar").arg("baz").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -84,6 +97,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildArgs() {
|
||||
MessageResolver resolver = builder.error().codes("bar").args("baz").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -92,6 +106,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCodesNull() {
|
||||
MessageResolver resolver = builder.codes().build();
|
||||
try {
|
||||
@@ -102,6 +117,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildArgsNull() {
|
||||
MessageResolver resolver = builder.args().build();
|
||||
try {
|
||||
@@ -112,6 +128,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildArgsWithNullCodes() {
|
||||
MessageResolver resolver = builder.error().args("baz").build();
|
||||
try {
|
||||
@@ -121,12 +138,14 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildArgsWithNullCodesDefaultText() {
|
||||
MessageResolver resolver = builder.error().args("baz").defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
assertEquals("foo", message.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithSource() {
|
||||
MessageResolver resolver = builder.source("foo").defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -135,6 +154,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertEquals(Severity.INFO, message.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildResolvableArg() {
|
||||
MessageResolver resolver = builder.error().code("bar").resolvableArg("baz").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
@@ -143,6 +163,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
assertNull(message.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildResolvableArgs() {
|
||||
MessageResolver resolver = builder.error().codes("bar").resolvableArgs("baz")
|
||||
.build();
|
||||
|
||||
@@ -2,13 +2,13 @@ package org.springframework.binding.message;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.validation.MessageCodesResolver;
|
||||
|
||||
public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
public class MessageContextErrorsMessageCodesTests {
|
||||
|
||||
private DefaultMessageContext context;
|
||||
|
||||
@@ -18,8 +18,8 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
|
||||
private MessageCodesResolver resolver;
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage(errorCode, Locale.getDefault(), "doesntmatter");
|
||||
context = new DefaultMessageContext(messageSource);
|
||||
@@ -27,6 +27,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
resolver = EasyMock.createMock(MessageCodesResolver.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectUsesObjectName() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
@@ -38,6 +39,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
EasyMock.verify(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectValueUsesObjectName() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName, "field", null)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
@@ -48,6 +50,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
EasyMock.verify(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectValueEmptyField() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
package org.springframework.binding.message;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.spel.SpringELExpressionParser;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.validation.DefaultMessageCodesResolver;
|
||||
import org.springframework.validation.MapBindingResult;
|
||||
|
||||
public class MessageContextErrorsTests extends TestCase {
|
||||
public class MessageContextErrorsTests {
|
||||
|
||||
private DefaultMessageContext context;
|
||||
private MessageContextErrors errors;
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage("foo", Locale.getDefault(), "bar");
|
||||
messageSource.addMessage("bar", Locale.getDefault(), "{0}");
|
||||
@@ -29,6 +31,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
errors = new MessageContextErrors(context, "object", new Object(), parser, resolver, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReject() {
|
||||
errors.reject("foo");
|
||||
errors.reject("bogus", "baz");
|
||||
@@ -50,6 +53,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
assertEquals(Severity.ERROR, msg.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectValue() {
|
||||
errors.rejectValue("class", "foo");
|
||||
errors.rejectValue("class", "bogus", "baz");
|
||||
@@ -71,6 +75,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
assertEquals(Severity.ERROR, msg.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalError() {
|
||||
errors.rejectValue(null, "bar", new Object[] { "boop" }, null);
|
||||
Message msg = context.getAllMessages()[0];
|
||||
@@ -79,6 +84,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
assertEquals(Severity.ERROR, msg.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllErrors() {
|
||||
MapBindingResult result = new MapBindingResult(new HashMap<>(), "object");
|
||||
result.reject("bar", new Object[] { "boop" }, null);
|
||||
@@ -96,14 +102,17 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
assertEquals(Severity.ERROR, msg.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGlobalErrors() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFieldErrors() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFieldValue() {
|
||||
|
||||
}
|
||||
|
||||
@@ -15,18 +15,21 @@
|
||||
*/
|
||||
package org.springframework.binding.method;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test case for {@link MethodInvocationException}.
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class MethodInvocationExceptionTests extends TestCase {
|
||||
public class MethodInvocationExceptionTests {
|
||||
|
||||
@Test
|
||||
public void testGetTargetException() {
|
||||
// runtime exception
|
||||
IllegalArgumentException iae = new IllegalArgumentException("test");
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
*/
|
||||
package org.springframework.binding.method;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
|
||||
/**
|
||||
@@ -25,14 +30,16 @@ import org.springframework.binding.expression.support.StaticExpression;
|
||||
* @author Erwin Vervaet
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class MethodInvokerTests extends TestCase {
|
||||
public class MethodInvokerTests {
|
||||
|
||||
private MethodInvoker methodInvoker;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.methodInvoker = new MethodInvoker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvocationTargetException() {
|
||||
try {
|
||||
methodInvoker.invoke(new MethodSignature("test"), new TestObject(), null);
|
||||
@@ -43,6 +50,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidMethod() {
|
||||
try {
|
||||
methodInvoker.invoke(new MethodSignature("bogus"), new TestObject(), null);
|
||||
@@ -52,6 +60,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanArg() {
|
||||
Parameters parameters = new Parameters();
|
||||
Bean bean = new Bean();
|
||||
@@ -60,6 +69,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertSame(bean, methodInvoker.invoke(method, new TestObject(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveArg() {
|
||||
Parameters parameters = new Parameters();
|
||||
parameters.add(new Parameter(Boolean.class, new StaticExpression(true)));
|
||||
|
||||
@@ -15,46 +15,53 @@
|
||||
*/
|
||||
package org.springframework.binding.method;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @since 1.0
|
||||
*/
|
||||
public class MethodKeyTests extends TestCase {
|
||||
public class MethodKeyTests {
|
||||
|
||||
private static final Method LIST_NO_ARGS = safeGetMethod(File.class, "list", null);
|
||||
|
||||
private static final Method LIST_FILENAME_FILTER = safeGetMethod(File.class, "list",
|
||||
new Class[] { FilenameFilter.class });
|
||||
|
||||
@Test
|
||||
public void testGetMethodWithNoArgs() {
|
||||
MethodKey key = new MethodKey(File.class, "list");
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_NO_ARGS, m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMoreGenericMethod() {
|
||||
MethodKey key = new MethodKey(Object.class, "equals", Long.class);
|
||||
assertEquals(safeGetMethod(Object.class, "equals", new Class[] { Object.class }), key.getMethod());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMethodWithSingleArg() {
|
||||
MethodKey key = new MethodKey(File.class, "list", FilenameFilter.class);
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_FILENAME_FILTER, m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMethodWithSingleNullArgAndValidMatch() {
|
||||
MethodKey key = new MethodKey(File.class, "list", new Class[] { null });
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_FILENAME_FILTER, m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMethodWithSingleNullAndUnclearMatch() {
|
||||
new MethodKey(File.class, "listFiles", new Class[] { null });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
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 {
|
||||
@AfterEach
|
||||
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);
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.context = initApplicationContext();
|
||||
}
|
||||
|
||||
protected abstract ApplicationContext initApplicationContext();
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureDefaults() {
|
||||
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
|
||||
assertEquals(1, map.values().size());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.jsfMockHelper.setUp();
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
this.jsfMockHelper.tearDown();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.springframework.faces.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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);
|
||||
|
||||
@BeforeEach
|
||||
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 {
|
||||
@AfterEach
|
||||
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();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.springframework.faces.model.converter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.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;
|
||||
|
||||
|
||||
@@ -5,17 +5,19 @@ import java.util.List;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
|
||||
public class FacesConversionServiceTests extends TestCase {
|
||||
public class FacesConversionServiceTests {
|
||||
private FacesConversionService service;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
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<>();
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package org.springframework.faces.mvc;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
|
||||
@BeforeEach
|
||||
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());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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());
|
||||
|
||||
@@ -15,50 +15,59 @@
|
||||
*/
|
||||
package org.springframework.faces.security;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.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");
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testProcessAction() {
|
||||
|
||||
String outcome = "foo";
|
||||
@@ -50,12 +57,13 @@ public class FlowActionListenerTests extends TestCase {
|
||||
|
||||
this.listener.processAction(event);
|
||||
|
||||
assertTrue("The event was not signaled",
|
||||
this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
assertEquals("The event should be " + outcome, outcome,
|
||||
this.jsfMock.externalContext().getRequestMap().get(JsfView.EVENT_KEY));
|
||||
assertTrue(this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY),
|
||||
"The event was not signaled");
|
||||
assertEquals(outcome, this.jsfMock.externalContext().getRequestMap().get(JsfView.EVENT_KEY),
|
||||
"The event should be " + outcome);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testProcessAction_NullOutcome() {
|
||||
|
||||
String outcome = null;
|
||||
@@ -66,8 +74,8 @@ public class FlowActionListenerTests extends TestCase {
|
||||
|
||||
this.listener.processAction(event);
|
||||
|
||||
assertFalse("An unexpected event was signaled",
|
||||
this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
assertFalse(this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY),
|
||||
"An unexpected event was signaled");
|
||||
}
|
||||
|
||||
private class MethodExpressionStub extends MethodExpression {
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.el.ELContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.myfaces.test.el.MockELContext;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
@AfterEach
|
||||
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");
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
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);
|
||||
@@ -58,11 +67,12 @@ public class FlowFacesContextTests extends TestCase {
|
||||
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
|
||||
assertEquals("Message count is incorrect", 1, this.messageContext.getAllMessages().length);
|
||||
assertEquals(1, this.messageContext.getAllMessages().length, "Message count is incorrect");
|
||||
Message message = this.messageContext.getMessagesBySource(new FacesMessageSource("foo"))[0];
|
||||
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);
|
||||
@@ -107,12 +119,13 @@ public class FlowFacesContextTests extends TestCase {
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "zoo", "zar"));
|
||||
|
||||
assertEquals("Message count is incorrect", 2, this.messageContext.getAllMessages().length);
|
||||
assertEquals(2, this.messageContext.getAllMessages().length, "Message count is incorrect");
|
||||
Message[] messages = this.messageContext.getMessagesBySource(new FacesMessageSource(null));
|
||||
assertEquals("foo : bar", messages[0].getText());
|
||||
assertEquals("zoo : zar", messages[1].getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testGetMessages() {
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
@@ -124,9 +137,10 @@ public class FlowFacesContextTests extends TestCase {
|
||||
assertNotNull(i.next());
|
||||
iterationCount++;
|
||||
}
|
||||
assertEquals("There should be 6 messages to iterate", 6, iterationCount);
|
||||
assertEquals(6, iterationCount, "There should be 6 messages to iterate");
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -202,12 +220,13 @@ public class FlowFacesContextTests extends TestCase {
|
||||
Iterator<String> i = this.facesContext.getClientIdsWithMessages();
|
||||
while (i.hasNext()) {
|
||||
String clientId = i.next();
|
||||
assertEquals("Client id not expected", expectedOrderedIds.get(iterationCount), clientId);
|
||||
assertEquals(expectedOrderedIds.get(iterationCount), clientId, "Client id not expected");
|
||||
iterationCount++;
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
@AfterEach
|
||||
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" };
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
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();
|
||||
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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 {
|
||||
@AfterEach
|
||||
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>"));
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
configureJsf();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
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();
|
||||
@@ -110,7 +116,7 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
assertFalse(this.executed, "Lifecycle executed more than once");
|
||||
super.execute(context);
|
||||
this.executed = true;
|
||||
}
|
||||
@@ -123,15 +129,15 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
String phaseCallback = "AFTER_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
assertFalse(this.phaseCallbacks.contains(phaseCallback),
|
||||
"Phase callback " + phaseCallback + " already executed.");
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
String phaseCallback = "BEFORE_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
assertFalse(this.phaseCallbacks.contains(phaseCallback),
|
||||
"Phase callback " + phaseCallback + " already executed.");
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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,23 +21,25 @@ public class JsfManagedBeanAwareELExpressionParserTests extends TestCase {
|
||||
|
||||
ExpressionParser parser;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
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));
|
||||
Object result = expr.getValue(this.requestContext);
|
||||
assertNotNull("The JSF Bean should not be null.", result);
|
||||
assertNotNull(result, "The JSF Bean should not be null.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,19 @@
|
||||
*/
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.jsfMock.setUp();
|
||||
this.requestContext = new MockRequestContext();
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
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,13 +83,14 @@ public class JsfManagedBeanPropertyAccessorTests extends TestCase {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrite() {
|
||||
Object jsfBean1 = new Object();
|
||||
Object jsfBean2 = new Object();
|
||||
|
||||
MutableAttributeMap<Object> map = this.requestContext.getExternalContext().getRequestMap();
|
||||
this.accessor.write(null, null, "myJsfBean", jsfBean1);
|
||||
assertNull("Write occurs only if bean is present in the map", map.get("myJsfBean"));
|
||||
assertNull(map.get("myJsfBean"), "Write occurs only if bean is present in the map");
|
||||
|
||||
map.put("myJsfBean", jsfBean1);
|
||||
this.accessor.write(null, null, "myJsfBean", jsfBean2);
|
||||
|
||||
@@ -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.jupiter.api.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);
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
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());
|
||||
@@ -117,15 +127,16 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
View newView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not created", newView);
|
||||
assertTrue("A JsfView was expected", newView instanceof JsfView);
|
||||
assertEquals("View name did not match", VIEW_ID, ((JsfView) newView).getViewRoot().getViewId());
|
||||
assertFalse("An unexpected event was signaled,", newView.hasFlowEvent());
|
||||
assertNotNull(newView, "A View was not created");
|
||||
assertTrue(newView instanceof JsfView, "A JsfView was expected");
|
||||
assertEquals(VIEW_ID, ((JsfView) newView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertFalse(newView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
@@ -148,17 +159,18 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId());
|
||||
assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent());
|
||||
assertTrue("The input component's valid flag was not reset", input.isValid());
|
||||
assertTrue("The PostRestoreViewEvent was not seen", existingRoot.isPostRestoreStateEventSeen());
|
||||
assertNotNull(restoredView, "A View was not restored");
|
||||
assertTrue(restoredView instanceof JsfView, "A JsfView was expected");
|
||||
assertEquals(VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(input.isValid(), "The input component's valid flag was not reset");
|
||||
assertTrue(existingRoot.isPostRestoreStateEventSeen(), "The PostRestoreViewEvent was not seen");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
@@ -195,19 +207,20 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId());
|
||||
assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent());
|
||||
assertSame("The UIInput binding was not restored properly", input, testBean.getInput());
|
||||
assertSame("The faceted UIOutput binding was not restored properly", output, testBean.getOutput());
|
||||
assertTrue("The PostRestoreViewEvent was not seen", existingRoot.isPostRestoreStateEventSeen());
|
||||
assertNotNull(restoredView, "A View was not restored");
|
||||
assertTrue(restoredView instanceof JsfView, "A JsfView was expected");
|
||||
assertEquals(VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertSame(input, testBean.getInput(), "The UIInput binding was not restored properly");
|
||||
assertSame(output, testBean.getOutput(), "The faceted UIOutput binding was not restored properly");
|
||||
assertTrue(existingRoot.isPostRestoreStateEventSeen(), "The PostRestoreViewEvent was not seen");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
@@ -230,17 +243,18 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
assertTrue("An ViewRoot was not set", ((JsfView) restoredView).getViewRoot() != null);
|
||||
assertEquals("View name did not match", VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId());
|
||||
assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent());
|
||||
assertTrue("The PostRestoreViewEvent was not seen", existingRoot.isPostRestoreStateEventSeen());
|
||||
assertNotNull(restoredView, "A View was not restored");
|
||||
assertTrue(restoredView instanceof JsfView, "A JsfView was expected");
|
||||
assertTrue(((JsfView) restoredView).getViewRoot() != null, "An ViewRoot was not set");
|
||||
assertEquals(VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(existingRoot.isPostRestoreStateEventSeen(), "The PostRestoreViewEvent was not seen");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
@@ -256,14 +270,15 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
View newView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not created", newView);
|
||||
assertTrue("A JsfView was expected", newView instanceof JsfView);
|
||||
assertEquals("View name did not match", VIEW_ID, ((JsfView) newView).getViewRoot().getViewId());
|
||||
assertSame("View root was not the third party instance", newRoot, ((JsfView) newView).getViewRoot());
|
||||
assertFalse("An unexpected event was signaled,", newView.hasFlowEvent());
|
||||
assertTrue("The PostRestoreViewEvent was not seen", newRoot.isPostRestoreStateEventSeen());
|
||||
assertNotNull(newView, "A View was not created");
|
||||
assertTrue(newView instanceof JsfView, "A JsfView was expected");
|
||||
assertEquals(VIEW_ID, ((JsfView) newView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertSame(newRoot, ((JsfView) newView).getViewRoot(), "View root was not the third party instance");
|
||||
assertFalse(newView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(newRoot.isPostRestoreStateEventSeen(), "The PostRestoreViewEvent was not seen");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetView_ExceptionsOnPostRestoreStateEvent() {
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
@@ -282,9 +297,9 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
this.factory.getView(this.context);
|
||||
ExceptionEventAwareMockApplication application = (ExceptionEventAwareMockApplication) FlowFacesContext
|
||||
.getCurrentInstance().getApplication();
|
||||
assertNotNull("Expected exception event", application.getExceptionQueuedEventContext());
|
||||
assertSame("Expected same exception", existingRoot.getAbortProcessingException(), application
|
||||
.getExceptionQueuedEventContext().getException());
|
||||
assertNotNull(application.getExceptionQueuedEventContext(), "Expected exception event");
|
||||
assertSame(existingRoot.getAbortProcessingException(),
|
||||
application.getExceptionQueuedEventContext().getException(), "Expected same exception");
|
||||
}
|
||||
|
||||
private class NoExecutionLifecycle extends FlowLifecycle {
|
||||
@@ -304,15 +319,15 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
String phaseCallback = "AFTER_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
assertFalse(this.phaseCallbacks.contains(phaseCallback),
|
||||
"Phase callback " + phaseCallback + " already executed.");
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
String phaseCallback = "BEFORE_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
assertFalse(this.phaseCallbacks.contains(phaseCallback),
|
||||
"Phase callback " + phaseCallback + " already executed.");
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
@@ -378,7 +393,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
|
||||
if (event instanceof PostRestoreStateEvent) {
|
||||
assertSame("Component did not match", this, event.getComponent());
|
||||
assertSame(this, event.getComponent(), "Component did not match");
|
||||
this.postRestoreStateEventSeen = true;
|
||||
if (this.throwOnPostRestoreStateEvent) {
|
||||
this.abortProcessingException = new AbortProcessingException();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
@BeforeEach
|
||||
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();
|
||||
@AfterEach
|
||||
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(
|
||||
@@ -146,13 +156,14 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
restoredView.processUserEvent();
|
||||
|
||||
assertFalse("An unexpected event was signaled,", restoredView.hasFlowEvent());
|
||||
assertTrue("The lifecycle should have been invoked", ((NoEventLifecycle) lifecycle).executed);
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(((NoEventLifecycle) lifecycle).executed, "The lifecycle should have been invoked");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
@@ -171,11 +182,12 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
restoredView.processUserEvent();
|
||||
|
||||
assertTrue("No event was signaled,", restoredView.hasFlowEvent());
|
||||
assertEquals("Event should be " + this.event, this.event, restoredView.getFlowEvent().getId());
|
||||
assertTrue("The lifecycle should have been invoked", ((EventSignalingLifecycle) lifecycle).executed);
|
||||
assertTrue(restoredView.hasFlowEvent(), "No event was signaled,");
|
||||
assertEquals(this.event, restoredView.getFlowEvent().getId(), "Event should be " + this.event);
|
||||
assertTrue(((EventSignalingLifecycle) lifecycle).executed, "The lifecycle should have been invoked");
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testUserEventQueued_GETRefresh() {
|
||||
|
||||
MockParameterMap requestParameterMap = new MockParameterMap();
|
||||
@@ -186,9 +198,10 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), this.jsfMock.lifecycle(), this.context);
|
||||
|
||||
assertFalse("No user event should be queued", createdView.userEventQueued());
|
||||
assertFalse(createdView.userEventQueued(), "No user event should be queued");
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testUserEventQueued_FormSubmitted() {
|
||||
|
||||
this.jsfMock.request().addParameter("execution", "e1s1");
|
||||
@@ -198,7 +211,7 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), this.jsfMock.lifecycle(), this.context);
|
||||
|
||||
assertTrue("User event should be queued", createdView.userEventQueued());
|
||||
assertTrue(createdView.userEventQueued(), "User event should be queued");
|
||||
}
|
||||
|
||||
private class ExceptionalViewHandler extends MockViewHandler {
|
||||
@@ -216,7 +229,7 @@ public class JsfViewTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
assertFalse(this.executed, "Lifecycle executed more than once");
|
||||
super.execute(context);
|
||||
this.executed = true;
|
||||
}
|
||||
@@ -231,7 +244,7 @@ public class JsfViewTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
assertFalse(this.executed, "Lifecycle executed more than once");
|
||||
super.execute(context);
|
||||
JsfViewTests.this.extContext.getRequestMap().put(JsfView.EVENT_KEY, JsfViewTests.this.event);
|
||||
this.executed = true;
|
||||
|
||||
@@ -15,21 +15,25 @@
|
||||
*/
|
||||
package org.springframework.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Keith likes to have these little cut & paste examples in the source repositories. If only he knew the power of code
|
||||
* templates in Eclipse...
|
||||
*/
|
||||
public class UnitTestTemplate extends TestCase {
|
||||
class UnitTestTemplate {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
public void testScenario1() {
|
||||
@Test
|
||||
void scenario1() {
|
||||
}
|
||||
|
||||
public void testScenario2() {
|
||||
@Test
|
||||
void scenario2() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -26,15 +31,17 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
/**
|
||||
* Unit tests for {@link AbstractAction}.
|
||||
*/
|
||||
public class AbstractActionTests extends TestCase {
|
||||
public class AbstractActionTests {
|
||||
|
||||
private TestAbstractAction action = new TestAbstractAction();
|
||||
|
||||
@Test
|
||||
public void testInitCallback() throws Exception {
|
||||
action.afterPropertiesSet();
|
||||
assertTrue(action.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitCallbackWithException() throws Exception {
|
||||
action = new TestAbstractAction() {
|
||||
protected void initAction() {
|
||||
@@ -49,6 +56,7 @@ public class AbstractActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalExecute() throws Exception {
|
||||
action = new TestAbstractAction() {
|
||||
protected Event doExecute(RequestContext context) {
|
||||
@@ -60,6 +68,7 @@ public class AbstractActionTests extends TestCase {
|
||||
assertTrue(result.getAttributes().size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionalExecute() throws Exception {
|
||||
try {
|
||||
action.execute(new MockRequestContext());
|
||||
@@ -69,6 +78,7 @@ public class AbstractActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreExecuteShortCircuit() throws Exception {
|
||||
action = new TestAbstractAction() {
|
||||
protected Event doPreExecute(RequestContext context) {
|
||||
@@ -79,6 +89,7 @@ public class AbstractActionTests extends TestCase {
|
||||
assertEquals("success", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostExecuteCalled() throws Exception {
|
||||
testNormalExecute();
|
||||
assertTrue(action.postExecuteCalled);
|
||||
@@ -102,11 +113,13 @@ public class AbstractActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
Event event = action.success();
|
||||
assertEquals(action.getEventFactorySupport().getSuccessEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessResult() {
|
||||
Object o = new Object();
|
||||
Event event = action.success(o);
|
||||
@@ -114,11 +127,13 @@ public class AbstractActionTests extends TestCase {
|
||||
assertSame(o, event.getAttributes().get(action.getEventFactorySupport().getResultAttributeName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() {
|
||||
Event event = action.error();
|
||||
assertEquals(action.getEventFactorySupport().getErrorEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorException() {
|
||||
IllegalArgumentException e = new IllegalArgumentException("woops");
|
||||
Event event = action.error(e);
|
||||
@@ -126,37 +141,44 @@ public class AbstractActionTests extends TestCase {
|
||||
assertSame(e, event.getAttributes().get(action.getEventFactorySupport().getExceptionAttributeName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYes() {
|
||||
Event event = action.yes();
|
||||
assertEquals(action.getEventFactorySupport().getYesEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNo() {
|
||||
Event event = action.no();
|
||||
assertEquals(action.getEventFactorySupport().getNoEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueResult() {
|
||||
Event event = action.result(true);
|
||||
assertEquals(action.getEventFactorySupport().getYesEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalseResult() {
|
||||
Event event = action.result(false);
|
||||
assertEquals(action.getEventFactorySupport().getNoEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomResult() {
|
||||
Event event = action.result("custom");
|
||||
assertEquals("custom", event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomResultObject() {
|
||||
Event event = action.result("custom", "result", "value");
|
||||
assertEquals("custom", event.getId());
|
||||
assertEquals("value", event.getAttributes().getString("result"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomResultCollection() {
|
||||
LocalAttributeMap<Object> collection = new LocalAttributeMap<>();
|
||||
collection.put("result", "value");
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.execution.Action;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -29,19 +31,20 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class CompositeActionTests extends TestCase {
|
||||
public class CompositeActionTests {
|
||||
|
||||
private CompositeAction tested;
|
||||
|
||||
private Action actionMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
actionMock = EasyMock.createMock(Action.class);
|
||||
Action[] actions = new Action[] { actionMock };
|
||||
tested = new CompositeAction(actions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoExecute() throws Exception {
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
LocalAttributeMap<Object> attributes = new LocalAttributeMap<>();
|
||||
@@ -54,6 +57,7 @@ public class CompositeActionTests extends TestCase {
|
||||
assertEquals(1, result.getAttributes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoExecuteWithError() throws Exception {
|
||||
tested.setStopOnError(true);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
@@ -64,6 +68,7 @@ public class CompositeActionTests extends TestCase {
|
||||
assertEquals("error", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoExecuteWithNullResult() throws Exception {
|
||||
tested.setStopOnError(true);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
@@ -71,9 +76,10 @@ public class CompositeActionTests extends TestCase {
|
||||
EasyMock.replay(actionMock);
|
||||
Event result = tested.doExecute(mockRequestContext);
|
||||
EasyMock.verify(actionMock);
|
||||
assertEquals("Expecting success since no check is performed if null result,", "success", result.getId());
|
||||
assertEquals("success", result.getId(), "Expecting success since no check is performed if null result,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleActions() throws Exception {
|
||||
CompositeAction ca = new CompositeAction(
|
||||
new Action() {
|
||||
@@ -86,7 +92,7 @@ public class CompositeActionTests extends TestCase {
|
||||
return new Event(this, "bar");
|
||||
}
|
||||
});
|
||||
assertEquals("Result of last executed action should be returned", "bar", ca.execute(new MockRequestContext())
|
||||
.getId());
|
||||
assertEquals("bar", ca.execute(new MockRequestContext()).getId(),
|
||||
"Result of last executed action should be returned");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,34 +15,43 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class DispatchMethodInvokerTests extends TestCase {
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DispatchMethodInvokerTests {
|
||||
|
||||
private MockClass mockClass;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
mockClass = new MockClass();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithExplicitParameters() throws Exception {
|
||||
DispatchMethodInvoker invoker = new DispatchMethodInvoker(mockClass, Object.class);
|
||||
invoker.invoke("argumentMethod", "testValue");
|
||||
assertTrue("Method should have been called successfully", mockClass.getMethodCalled());
|
||||
assertTrue(mockClass.getMethodCalled(), "Method should have been called successfully");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithAssignableParameters() throws Exception {
|
||||
DispatchMethodInvoker invoker = new DispatchMethodInvoker(mockClass, String.class);
|
||||
invoker.invoke("argumentMethod", "testValue");
|
||||
assertTrue("Method should have been called successfully", mockClass.getMethodCalled());
|
||||
assertTrue(mockClass.getMethodCalled(), "Method should have been called successfully");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithNoParameters() throws Exception {
|
||||
DispatchMethodInvoker invoker = new DispatchMethodInvoker(mockClass);
|
||||
invoker.invoke("noArgumentMethod");
|
||||
assertTrue("Method should have been called successfully", mockClass.getMethodCalled());
|
||||
assertTrue(mockClass.getMethodCalled(), "Method should have been called successfully");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithException() {
|
||||
DispatchMethodInvoker invoker = new DispatchMethodInvoker(mockClass, Object.class);
|
||||
try {
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
@@ -25,8 +26,9 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
* Unit tests for {@link EvaluateAction}.
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class EvaluateActionTests extends TestCase {
|
||||
public class EvaluateActionTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateExpressionNoResultExposer() throws Exception {
|
||||
EvaluateAction action = new EvaluateAction(new StaticExpression("bar"), null);
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
@@ -34,6 +36,7 @@ public class EvaluateActionTests extends TestCase {
|
||||
assertEquals("bar", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateExpressionEmptyStringResult() throws Exception {
|
||||
EvaluateAction action = new EvaluateAction(new StaticExpression(""), null);
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
@@ -41,6 +44,7 @@ public class EvaluateActionTests extends TestCase {
|
||||
assertEquals("null", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateExpressionNullResult() throws Exception {
|
||||
EvaluateAction action = new EvaluateAction(new StaticExpression(null), null);
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
@@ -48,6 +52,7 @@ public class EvaluateActionTests extends TestCase {
|
||||
assertEquals("success", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateExpressionResultExposer() throws Exception {
|
||||
StaticExpression resultExpression = new StaticExpression("");
|
||||
EvaluateAction action = new EvaluateAction(new StaticExpression("bar"), resultExpression);
|
||||
|
||||
@@ -15,28 +15,34 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EventFactorySupport}.
|
||||
*/
|
||||
public class EventFactorySupportTests extends TestCase {
|
||||
public class EventFactorySupportTests {
|
||||
|
||||
private EventFactorySupport support = new EventFactorySupport();
|
||||
|
||||
private Object source = new Object();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
Event e = support.success(source);
|
||||
assertEquals("success", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessWithResult() {
|
||||
Object result = new Object();
|
||||
Event e = support.success(source, result);
|
||||
@@ -45,12 +51,14 @@ public class EventFactorySupportTests extends TestCase {
|
||||
assertSame(result, e.getAttributes().get("result"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() {
|
||||
Event e = support.error(source);
|
||||
assertEquals("error", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorWithException() {
|
||||
Exception ex = new Exception();
|
||||
Event e = support.error(source, ex);
|
||||
@@ -59,36 +67,42 @@ public class EventFactorySupportTests extends TestCase {
|
||||
assertSame(ex, e.getAttributes().get("exception"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYes() {
|
||||
Event e = support.yes(source);
|
||||
assertEquals("yes", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNo() {
|
||||
Event e = support.no(source);
|
||||
assertEquals("no", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanTrueEvent() {
|
||||
Event e = support.event(source, true);
|
||||
assertEquals("yes", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanFalseEvent() {
|
||||
Event e = support.event(source, false);
|
||||
assertEquals("no", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvent() {
|
||||
Event e = support.event(source, "no");
|
||||
assertEquals("no", e.getId());
|
||||
assertSame(source, e.getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventWithAttrs() {
|
||||
Event e = support.event(source, "no", "foo", "bar");
|
||||
assertEquals("no", e.getId());
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class ExternalRedirectActionTests extends TestCase {
|
||||
public class ExternalRedirectActionTests {
|
||||
private ExternalRedirectAction action;
|
||||
|
||||
@Test
|
||||
public void testExecute() throws Exception {
|
||||
action = new ExternalRedirectAction(new StaticExpression("/wherever"));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
@@ -15,6 +18,7 @@ public class ExternalRedirectActionTests extends TestCase {
|
||||
assertEquals("/wherever", context.getMockExternalContext().getExternalRedirectUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithNullResourceUri() {
|
||||
try {
|
||||
action = new ExternalRedirectAction(null);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class FlowDefinitionRedirectActionTests extends TestCase {
|
||||
public class FlowDefinitionRedirectActionTests {
|
||||
private FlowDefinitionRedirectAction action;
|
||||
|
||||
@Test
|
||||
public void testExecute() throws Exception {
|
||||
Expression flowId = new StaticExpression("user?foo=bar");
|
||||
action = new FlowDefinitionRedirectAction(flowId);
|
||||
@@ -18,6 +21,7 @@ public class FlowDefinitionRedirectActionTests extends TestCase {
|
||||
assertEquals("bar", context.getMockExternalContext().getFlowRedirectFlowInput().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithNullRequestFields() throws Exception {
|
||||
Expression flowId = new StaticExpression("user");
|
||||
action = new FlowDefinitionRedirectAction(flowId);
|
||||
@@ -26,6 +30,7 @@ public class FlowDefinitionRedirectActionTests extends TestCase {
|
||||
assertEquals("user", context.getMockExternalContext().getFlowRedirectFlowId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithNullFlowId() throws Exception {
|
||||
try {
|
||||
action = new FlowDefinitionRedirectAction(null);
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -32,7 +35,7 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class FormActionBindingTests extends TestCase {
|
||||
public class FormActionBindingTests {
|
||||
|
||||
public static class TestBean {
|
||||
|
||||
@@ -48,6 +51,7 @@ public class FormActionBindingTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageCodesOnBindFailure() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setPathInfo("/fooFlow");
|
||||
@@ -72,6 +76,7 @@ public class FormActionBindingTests extends TestCase {
|
||||
assertEquals(1, formActionErrors.getFieldErrorCount("prop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldBinding() throws Exception {
|
||||
FormAction formAction = new FormAction() {
|
||||
protected Object createFormObject(RequestContext context) {
|
||||
|
||||
@@ -15,8 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
@@ -35,7 +43,7 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class FormActionTests extends TestCase {
|
||||
public class FormActionTests {
|
||||
|
||||
private static class TestBean {
|
||||
|
||||
@@ -80,10 +88,12 @@ public class FormActionTests extends TestCase {
|
||||
|
||||
private FormAction action;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
action = createFormAction("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupForm() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
|
||||
@@ -111,6 +121,7 @@ public class FormActionTests extends TestCase {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupFormWithExistingFormObject() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -135,6 +146,7 @@ public class FormActionTests extends TestCase {
|
||||
assertEquals("bla", getFormObject(context).getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndValidate() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -150,6 +162,7 @@ public class FormActionTests extends TestCase {
|
||||
assertEquals("value", getFormObject(context).getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndValidateFailure() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
|
||||
@@ -165,6 +178,7 @@ public class FormActionTests extends TestCase {
|
||||
assertNull(getFormObject(context).getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndValidateWithExistingFormObject() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -189,6 +203,7 @@ public class FormActionTests extends TestCase {
|
||||
}
|
||||
|
||||
// this is what happens in a 'form state'
|
||||
@Test
|
||||
public void testBindAndValidateFailureThenSetupForm() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(blankParameters());
|
||||
|
||||
@@ -221,6 +236,7 @@ public class FormActionTests extends TestCase {
|
||||
assertEquals("", getFormObject(context).getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleFormObjectsInOneFlow() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -263,6 +279,7 @@ public class FormActionTests extends TestCase {
|
||||
assertEquals("", getFormObject(context, "otherTest").getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFormObject() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
FormAction action = createFormAction("test");
|
||||
@@ -276,6 +293,7 @@ public class FormActionTests extends TestCase {
|
||||
assertSame(formObject, testBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFormErrors() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
FormAction action = createFormAction("test");
|
||||
@@ -290,6 +308,7 @@ public class FormActionTests extends TestCase {
|
||||
assertSame(errors, testErrors);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormObjectAccessUsingAlias() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(blankParameters());
|
||||
|
||||
@@ -319,6 +338,7 @@ public class FormActionTests extends TestCase {
|
||||
}
|
||||
|
||||
// as reported in SWF-4
|
||||
@Test
|
||||
public void testInconsistentFormObjectAndErrors() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -348,11 +368,12 @@ public class FormActionTests extends TestCase {
|
||||
|
||||
assertTrue(formObject instanceof OtherTestBean);
|
||||
assertSame(freshBean, formObject);
|
||||
assertTrue("Expected OtherTestBean, but was " + errors.getTarget().getClass(),
|
||||
errors.getTarget() instanceof OtherTestBean);
|
||||
assertTrue(errors.getTarget() instanceof OtherTestBean,
|
||||
"Expected OtherTestBean, but was " + errors.getTarget().getClass());
|
||||
assertSame(formObject, errors.getTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleFormObjects() throws Exception {
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
|
||||
@@ -387,6 +408,7 @@ public class FormActionTests extends TestCase {
|
||||
assertSame(test2, new FormObjectAccessor(context).getCurrentFormObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormObjectAndNoErrors() throws Exception {
|
||||
// this typically happens with mapping from parent flow to subflow
|
||||
MockRequestContext context = new MockRequestContext(parameters());
|
||||
@@ -408,6 +430,7 @@ public class FormActionTests extends TestCase {
|
||||
assertFalse(getErrors(context).hasErrors());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupFormThenBindAndValidate() throws Exception {
|
||||
FormAction action = createFormAction("testBean");
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
@@ -424,6 +447,7 @@ public class FormActionTests extends TestCase {
|
||||
assertEquals(true, ((TestBeanValidator) action.getValidator()).invoked);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormActionWithValidatorAndNoFormActionClass() throws Exception {
|
||||
FormAction action = new FormAction() {
|
||||
protected Object createFormObject(RequestContext context) throws Exception {
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.action.DispatchMethodInvoker.MethodLookupException;
|
||||
import org.springframework.webflow.action.MultiAction.MethodResolver;
|
||||
import org.springframework.webflow.engine.StubViewFactory;
|
||||
@@ -28,18 +30,20 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
/**
|
||||
* Unit tests for {@link MultiAction}.
|
||||
*/
|
||||
public class MultiActionTests extends TestCase {
|
||||
public class MultiActionTests {
|
||||
|
||||
private TestMultiAction action = new TestMultiAction();
|
||||
|
||||
private MockRequestContext context = new MockRequestContext();
|
||||
|
||||
@Test
|
||||
public void testDispatchWithMethodSignature() throws Exception {
|
||||
context.getAttributeMap().put(AnnotatedAction.METHOD_ATTRIBUTE, "increment");
|
||||
action.execute(context);
|
||||
assertEquals(1, action.counter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatchWithBogusMethodSignature() throws Exception {
|
||||
context.getAttributeMap().put(AnnotatedAction.METHOD_ATTRIBUTE, "bogus");
|
||||
try {
|
||||
@@ -50,6 +54,7 @@ public class MultiActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatchWithCurrentStateId() throws Exception {
|
||||
MockFlowSession session = context.getMockFlowExecutionContext().getMockActiveSession();
|
||||
session.setState(new ViewState(session.getDefinitionInternal(), "increment", new StubViewFactory()));
|
||||
@@ -57,6 +62,7 @@ public class MultiActionTests extends TestCase {
|
||||
assertEquals(1, action.counter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSuchMethodWithCurrentStateId() throws Exception {
|
||||
try {
|
||||
action.execute(context);
|
||||
@@ -66,6 +72,7 @@ public class MultiActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotResolveMethod() throws Exception {
|
||||
try {
|
||||
context.getMockFlowExecutionContext().getMockActiveSession().setState(null);
|
||||
@@ -76,6 +83,7 @@ public class MultiActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomMethodResolver() throws Exception {
|
||||
MethodResolver methodResolver = context -> "increment";
|
||||
action.setMethodResolver(methodResolver);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.View;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class RenderActionTests extends TestCase {
|
||||
public class RenderActionTests {
|
||||
@Test
|
||||
public void testRenderAction() throws Exception {
|
||||
StaticExpression name = new StaticExpression("frag1");
|
||||
StaticExpression name2 = new StaticExpression("frag2");
|
||||
@@ -21,6 +24,7 @@ public class RenderActionTests extends TestCase {
|
||||
assertEquals("frag2", fragments[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalNullArg() {
|
||||
try {
|
||||
new RenderAction((Expression[]) null);
|
||||
@@ -30,6 +34,7 @@ public class RenderActionTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalEmptyArg() {
|
||||
try {
|
||||
new RenderAction();
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
@@ -27,15 +30,17 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class ResultObjectBasedEventFactoryTests extends TestCase {
|
||||
public class ResultObjectBasedEventFactoryTests {
|
||||
|
||||
private ResultObjectBasedEventFactory factory = new ResultObjectBasedEventFactory();
|
||||
|
||||
@Test
|
||||
public void testNull() {
|
||||
Event event = factory.createResultEvent(this, null, new MockRequestContext());
|
||||
assertEquals(factory.getNullEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoolean() {
|
||||
Event event = factory.createResultEvent(this, true, new MockRequestContext());
|
||||
assertEquals(factory.getYesEventId(), event.getId());
|
||||
@@ -43,6 +48,7 @@ public class ResultObjectBasedEventFactoryTests extends TestCase {
|
||||
assertEquals(factory.getNoEventId(), event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLabeledEnum() {
|
||||
Event event = factory.createResultEvent(this, MyLabeledEnum.A, new MockRequestContext());
|
||||
assertEquals("A", event.getId());
|
||||
@@ -62,17 +68,20 @@ public class ResultObjectBasedEventFactoryTests extends TestCase {
|
||||
* public String toString() { return "MyEnum " + name(); } }
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testString() {
|
||||
Event event = factory.createResultEvent(this, "foobar", new MockRequestContext());
|
||||
assertEquals("foobar", event.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvent() {
|
||||
Event orig = new Event(this, "test");
|
||||
Event event = factory.createResultEvent(this, orig, new MockRequestContext());
|
||||
assertSame(orig, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupported() {
|
||||
try {
|
||||
factory.createResultEvent(this, new Date(), new MockRequestContext());
|
||||
|
||||
@@ -15,26 +15,32 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResultObjectBasedEventFactory}.
|
||||
*/
|
||||
public class ResultObjectEventFactoryTests extends TestCase {
|
||||
public class ResultObjectEventFactoryTests {
|
||||
|
||||
private MockRequestContext context = new MockRequestContext();
|
||||
|
||||
private ResultObjectBasedEventFactory factory = new ResultObjectBasedEventFactory();
|
||||
|
||||
@Test
|
||||
public void testAlreadyAnEvent() {
|
||||
Event event = new Event(this, "event");
|
||||
Event result = factory.createResultEvent(this, event, context);
|
||||
assertSame(event, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappedTypes() {
|
||||
assertTrue(factory.isMappedValueType(MyEnum.class));
|
||||
assertTrue(factory.isMappedValueType(boolean.class));
|
||||
@@ -43,11 +49,13 @@ public class ResultObjectEventFactoryTests extends TestCase {
|
||||
assertFalse(factory.isMappedValueType(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullResult() {
|
||||
Event result = factory.createResultEvent(this, null, context);
|
||||
assertEquals("null", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanResult() {
|
||||
Event result = factory.createResultEvent(this, true, context);
|
||||
assertEquals("yes", result.getId());
|
||||
@@ -55,11 +63,13 @@ public class ResultObjectEventFactoryTests extends TestCase {
|
||||
assertEquals("no", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLabeledEnumResult() {
|
||||
Event result = factory.createResultEvent(this, MyEnum.FOO, context);
|
||||
assertEquals("FOO", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOtherResult() {
|
||||
Event result = factory.createResultEvent(this, "hello", context);
|
||||
assertEquals("hello", result.getId());
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class SetActionTests extends TestCase {
|
||||
public class SetActionTests {
|
||||
|
||||
@Test
|
||||
public void testSetAction() throws Exception {
|
||||
StaticExpression name = new StaticExpression("");
|
||||
SetAction action = new SetAction(name, new StaticExpression("bar"));
|
||||
|
||||
@@ -15,20 +15,22 @@
|
||||
*/
|
||||
package org.springframework.webflow.action;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SuccessEventFactory}.
|
||||
*/
|
||||
public class SuccessEventFactoryTests extends TestCase {
|
||||
public class SuccessEventFactoryTests {
|
||||
|
||||
private MockRequestContext context = new MockRequestContext();
|
||||
|
||||
private SuccessEventFactory factory = new SuccessEventFactory();
|
||||
|
||||
@Test
|
||||
public void testDefaultAdaptionRules() {
|
||||
Event result = factory.createResultEvent(this, "result", context);
|
||||
assertEquals("success", result.getId());
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
@@ -22,18 +27,20 @@ import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.mvc.builder.MvcViewFactoryCreator;
|
||||
import org.springframework.webflow.validation.ValidationHintResolver;
|
||||
|
||||
public abstract class AbstractFlowBuilderServicesConfigurationTests extends TestCase {
|
||||
public abstract class AbstractFlowBuilderServicesConfigurationTests {
|
||||
|
||||
protected ApplicationContext context;
|
||||
|
||||
protected FlowBuilderServices builderServices;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
context = initApplicationContext();
|
||||
}
|
||||
|
||||
protected abstract ApplicationContext initApplicationContext();
|
||||
|
||||
@Test
|
||||
public void testFlowBuilderServicesDefaultConfig() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesDefault");
|
||||
assertNotNull(builderServices);
|
||||
@@ -44,6 +51,7 @@ public abstract class AbstractFlowBuilderServicesConfigurationTests extends Test
|
||||
assertFalse(builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowBuilderServicesAllCustomized() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesAllCustom");
|
||||
assertNotNull(builderServices);
|
||||
@@ -55,6 +63,7 @@ public abstract class AbstractFlowBuilderServicesConfigurationTests extends Test
|
||||
assertTrue(builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowBuilderServicesConversionServiceCustomized() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesConversionServiceCustom");
|
||||
assertNotNull(builderServices);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.webflow.conversation.Conversation;
|
||||
import org.springframework.webflow.conversation.ConversationException;
|
||||
@@ -16,10 +19,11 @@ import org.springframework.webflow.executor.FlowExecutor;
|
||||
import org.springframework.webflow.executor.FlowExecutorImpl;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
|
||||
public abstract class AbstractFlowExecutorConfigurationTests extends TestCase {
|
||||
public abstract class AbstractFlowExecutorConfigurationTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
context = initApplicationContext();
|
||||
}
|
||||
@@ -27,6 +31,7 @@ public abstract class AbstractFlowExecutorConfigurationTests extends TestCase {
|
||||
protected abstract ApplicationContext initApplicationContext();
|
||||
|
||||
|
||||
@Test
|
||||
public void testConfigOk() {
|
||||
FlowExecutor executor = context.getBean("flowExecutor", FlowExecutor.class);
|
||||
executor.launchExecution("flow", null, new MockExternalContext());
|
||||
@@ -34,6 +39,7 @@ public abstract class AbstractFlowExecutorConfigurationTests extends TestCase {
|
||||
executor2.launchExecution("flow", null, new MockExternalContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomConversationManager() {
|
||||
FlowExecutorImpl executor = context.getBean("flowExecutor", FlowExecutorImpl.class);
|
||||
try {
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionConstructionException;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
|
||||
import org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException;
|
||||
|
||||
public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
public abstract class AbstractFlowRegistryConfigurationTests {
|
||||
|
||||
protected ApplicationContext context;
|
||||
|
||||
protected FlowDefinitionRegistry registry;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.context = initApplicationContext();
|
||||
this.registry = (FlowDefinitionRegistry) context.getBean("flowRegistry");
|
||||
@@ -22,6 +27,7 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
protected abstract ApplicationContext initApplicationContext();
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegistryFlowLocationsPopulated() {
|
||||
FlowDefinition flow = registry.getFlowDefinition("flow");
|
||||
assertEquals("flow", flow.getId());
|
||||
@@ -29,6 +35,7 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
assertEquals(2, flow.getAttributes().get("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistryFlowLocationPatternsPopulated() {
|
||||
FlowDefinition flow1 = registry.getFlowDefinition("flow1");
|
||||
assertEquals("flow1", flow1.getId());
|
||||
@@ -36,16 +43,19 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
assertEquals("flow2", flow2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistryFlowBuildersPopulated() {
|
||||
FlowDefinition foo = registry.getFlowDefinition("foo");
|
||||
assertEquals("foo", foo.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistryFlowBuildersPopulatedWithId() {
|
||||
FlowDefinition foo = registry.getFlowDefinition("foo2");
|
||||
assertEquals("foo2", foo.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistryFlowBuildersPopulatedWithAttributes() {
|
||||
FlowDefinition foo3 = registry.getFlowDefinition("foo3");
|
||||
assertEquals("foo3", foo3.getId());
|
||||
@@ -53,6 +63,7 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
assertEquals(2, foo3.getAttributes().get("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSuchFlow() {
|
||||
try {
|
||||
registry.getFlowDefinition("not there");
|
||||
@@ -61,6 +72,7 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBogusPath() {
|
||||
try {
|
||||
registry.getFlowDefinition("bogus");
|
||||
@@ -69,6 +81,7 @@ public abstract class AbstractFlowRegistryConfigurationTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParent() {
|
||||
assertNotNull(registry.getParent());
|
||||
assertEquals("parentFlow", registry.getParent().getFlowDefinition("parentFlow").getId());
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -30,76 +32,88 @@ import org.springframework.web.context.support.ServletContextResourceLoader;
|
||||
/**
|
||||
* Unit tests for {@link FlowDefinitionResourceFactory}.
|
||||
*/
|
||||
public class FlowDefinitionResourceFactoryTests extends TestCase {
|
||||
public class FlowDefinitionResourceFactoryTests {
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private FlowDefinitionResourceFactory factory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
resourceLoader = new ServletContextResourceLoader(new MockServletContext());
|
||||
factory = new FlowDefinitionResourceFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdNoBasePath() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
assertEquals("booking-flow", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdFileSystemResourceBasePathMatch() {
|
||||
Resource resource = new FileSystemResource("/the/path/on/the/file/system/sample-flow.xml");
|
||||
factory.setBasePath("file:/the/path");
|
||||
assertEquals("on/the/file/system", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdCustomBasePath() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("WEB-INF");
|
||||
assertEquals("hotels/booking", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowCustomBasePathTrailingSlash() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("WEB-INF/");
|
||||
assertEquals("hotels/booking", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdCustomBasePathLeadingSlash() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("/WEB-INF");
|
||||
assertEquals("hotels/booking", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdCustomBasePathLeadingAndTrailingSlash() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("/WEB-INF/");
|
||||
assertEquals("hotels/booking", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdFlowPathIsBasePath() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("/WEB-INF/hotels/booking");
|
||||
assertEquals("booking-flow", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdBasePathMismatch() {
|
||||
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
|
||||
factory.setBasePath("/foo/bar");
|
||||
assertEquals("WEB-INF/hotels/booking", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdClassPathResource() {
|
||||
Resource resource = new ClassPathResource("org/springframework/webflow/sample/sample-flow.xml");
|
||||
factory.setBasePath("classpath:org/springframework/webflow/");
|
||||
assertEquals("sample", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdClassPathStarResource() {
|
||||
Resource resource = new ClassPathResource("org/springframework/webflow/sample/sample-flow.xml");
|
||||
factory.setBasePath("classpath*:org/springframework/webflow/");
|
||||
assertEquals("sample", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdFileSystemResource() {
|
||||
Resource resource = new FileSystemResource(
|
||||
"/the/path/on/the/file/system/org/springframework/webflow/sample/sample-flow.xml");
|
||||
@@ -107,12 +121,14 @@ public class FlowDefinitionResourceFactoryTests extends TestCase {
|
||||
assertEquals("sample", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdFileSystemResourceNoBasePathMatch() {
|
||||
Resource resource = new FileSystemResource("/the/path/on/the/file/system/sample-flow.xml");
|
||||
factory.setBasePath("classpath:org/springframework/webflow/");
|
||||
assertEquals("the/path/on/the/file/system", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdUrlResource() throws MalformedURLException {
|
||||
Resource resource = new UrlResource(
|
||||
"file:/the/path/on/the/file/system/org/springframework/webflow/sample/sample-flow.xml");
|
||||
@@ -120,6 +136,7 @@ public class FlowDefinitionResourceFactoryTests extends TestCase {
|
||||
assertEquals("sample", factory.getFlowId(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdUrlResourceNoBasePathMatch() throws MalformedURLException {
|
||||
Resource resource = new UrlResource("file:/the/path/on/the/file/system/sample-flow.xml");
|
||||
factory.setBasePath("classpath:org/springframework/webflow/");
|
||||
|
||||
@@ -3,12 +3,8 @@ package org.springframework.webflow.config;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionConstructionException;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionLocator;
|
||||
import org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.EndState;
|
||||
import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.engine.StubViewFactory;
|
||||
@@ -18,13 +14,15 @@ import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.execution.FlowExecutionListener;
|
||||
import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader;
|
||||
|
||||
public class FlowExecutorFactoryBeanTests extends TestCase {
|
||||
public class FlowExecutorFactoryBeanTests {
|
||||
private FlowExecutorFactoryBean factoryBean;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
factoryBean = new FlowExecutorFactoryBean();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowExecutorNoPropertiesSet() throws Exception {
|
||||
try {
|
||||
factoryBean.afterPropertiesSet();
|
||||
@@ -33,6 +31,7 @@ public class FlowExecutorFactoryBeanTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowExecutorBasicConfig() throws Exception {
|
||||
factoryBean.setFlowDefinitionLocator(id -> {
|
||||
Flow flow = new Flow(id);
|
||||
@@ -45,6 +44,7 @@ public class FlowExecutorFactoryBeanTests extends TestCase {
|
||||
factoryBean.getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowExecutorOptionsSpecified() throws Exception {
|
||||
factoryBean.setFlowDefinitionLocator(id -> {
|
||||
Flow flow = new Flow(id);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.service.DefaultConversionService;
|
||||
import org.springframework.binding.expression.spel.SpringELExpressionParser;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -15,6 +20,7 @@ public class FlowRegistryBeanDefinitionParserTests extends AbstractFlowRegistryC
|
||||
return new ClassPathXmlApplicationContext("org/springframework/webflow/config/flow-registry.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFlowBuilderServices() {
|
||||
Map<String, FlowBuilderServices> flowBuilderServicesBeans = context.getBeansOfType(FlowBuilderServices.class);
|
||||
assertTrue(flowBuilderServicesBeans.size() > 0);
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
|
||||
import org.springframework.webflow.test.TestFlowBuilderServicesFactory;
|
||||
|
||||
public class FlowRegistryFactoryBeanTests extends TestCase {
|
||||
public class FlowRegistryFactoryBeanTests {
|
||||
private FlowRegistryFactoryBean factoryBean;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
factoryBean = new FlowRegistryFactoryBean();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
factoryBean.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowRegistry() throws Exception {
|
||||
HashSet<FlowElementAttribute> attributes = new HashSet<>();
|
||||
attributes.add(new FlowElementAttribute("foo", "bar", null));
|
||||
@@ -40,6 +48,7 @@ public class FlowRegistryFactoryBeanTests extends TestCase {
|
||||
assertEquals("flow2", def.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowRegistryGeneratedFlowId() throws Exception {
|
||||
FlowLocation location1 = new FlowLocation(null, "org/springframework/webflow/config/flow.xml", null);
|
||||
FlowLocation[] flowLocations = new FlowLocation[] { location1 };
|
||||
@@ -53,6 +62,7 @@ public class FlowRegistryFactoryBeanTests extends TestCase {
|
||||
assertTrue(def.getAttributes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowRegistryCustomFlowServices() throws Exception {
|
||||
FlowLocation location1 = new FlowLocation(null, "org/springframework/webflow/config/flow.xml", null);
|
||||
FlowLocation[] flowLocations = new FlowLocation[] { location1 };
|
||||
|
||||
@@ -1,51 +1,60 @@
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
public class AbstractAjaxHandlerTests extends TestCase {
|
||||
public class AbstractAjaxHandlerTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAjaxRequest() {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, true);
|
||||
assertTrue(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotAjaxRequest() {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, false);
|
||||
assertFalse(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAjaxRequestViaDelegate() {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(new TestAjaxHandler(null, true), false);
|
||||
assertTrue(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAjaxRedirect() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, true);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
assertTrue(handler.wasAjaxRedirectInternalCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAjaxRedirectNotSent() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, false);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
assertFalse(handler.wasAjaxRedirectInternalCalled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAjaxRedirectViaDelegate() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(new TestAjaxHandler(null, true), false);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
|
||||
public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
public class DefaultFlowUrlHandlerTests {
|
||||
private DefaultFlowUrlHandler urlHandler = new DefaultFlowUrlHandler();
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Test
|
||||
public void testGetFlowId() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -21,6 +23,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("foo", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdNoPathInfo() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app/foo.htm");
|
||||
@@ -29,12 +32,14 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("app/foo", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdOnlyContextPath() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setRequestURI("/springtravel");
|
||||
assertEquals("springtravel", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowExecutionKey() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -44,6 +49,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("12345", urlHandler.getFlowExecutionKey(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrl() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -53,6 +59,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/bookHotel", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlNoPathInfo() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app/foo.htm");
|
||||
@@ -61,6 +68,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/foo.htm", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlContextPathOnly() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setRequestURI("/springtravel");
|
||||
@@ -68,6 +76,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlEmptyInput() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -77,6 +86,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/bookHotel", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithFlowInput() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -91,6 +101,7 @@ public class DefaultFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/bookHotel?foo=bar&bar=needs+encoding&baz=1&boop=", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowExecutionUrl() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
public class FilenameFlowUrlHandlerTests {
|
||||
|
||||
private DefaultFlowUrlHandler urlHandler = new FilenameFlowUrlHandler();
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Test
|
||||
public void testGetFlowId() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -32,6 +34,7 @@ public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("foo", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdNoPathInfo() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app/foo.htm");
|
||||
@@ -40,12 +43,14 @@ public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("foo", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIdOnlyContextPath() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setRequestURI("/springtravel");
|
||||
assertEquals("", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithPathInfo() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -55,6 +60,7 @@ public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/bar", flowDefUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithPathInfoNestedPath() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -64,6 +70,7 @@ public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/nestedPath/bar", flowDefUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithPathInfoNestedPathAndFileExtension() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/app");
|
||||
@@ -73,6 +80,7 @@ public class FilenameFlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/nestedPath/bar.flow", flowDefUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithServletPathAndFileExtension() {
|
||||
request.setContextPath("/springtravel");
|
||||
request.setServletPath("/nestedPath/foo.flow");
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
/**
|
||||
@@ -28,14 +33,14 @@ import org.springframework.mock.web.MockServletContext;
|
||||
* @author Ulrik Sandberg
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class HttpServletContextMapTests extends TestCase {
|
||||
public class HttpServletContextMapTests {
|
||||
|
||||
private HttpServletContextMap tested;
|
||||
|
||||
private MockServletContext context;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
context = new MockServletContext();
|
||||
// a fresh MockServletContext seems to already contain an element;
|
||||
// that's confusing, so we remove it
|
||||
@@ -44,53 +49,62 @@ public class HttpServletContextMapTests extends TestCase {
|
||||
tested.put("SomeKey", "SomeValue");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
context = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
tested.remove("SomeKey");
|
||||
assertEquals("size,", 0, tested.size());
|
||||
assertEquals("isEmpty,", true, tested.isEmpty());
|
||||
assertEquals(0, tested.size(), "size,");
|
||||
assertEquals(true, tested.isEmpty(), "isEmpty,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSizeAddOne() {
|
||||
assertEquals("size,", 1, tested.size());
|
||||
assertEquals(1, tested.size(), "size,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSizeAddTwo() {
|
||||
tested.put("SomeOtherKey", "SomeOtherValue");
|
||||
assertEquals("size,", 2, tested.size());
|
||||
assertEquals(2, tested.size(), "size,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsKey() {
|
||||
assertEquals("containsKey,", true, tested.containsKey("SomeKey"));
|
||||
assertEquals(true, tested.containsKey("SomeKey"), "containsKey,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsValue() {
|
||||
assertTrue(tested.containsValue("SomeValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() {
|
||||
assertEquals("get,", "SomeValue", tested.get("SomeKey"));
|
||||
assertEquals("SomeValue", tested.get("SomeKey"), "get,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPut() {
|
||||
Object old = tested.put("SomeKey", "SomeNewValue");
|
||||
|
||||
assertEquals("old value,", "SomeValue", old);
|
||||
assertEquals("new value,", "SomeNewValue", tested.get("SomeKey"));
|
||||
assertEquals("SomeValue", old, "old value,");
|
||||
assertEquals("SomeNewValue", tested.get("SomeKey"), "new value,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
Object old = tested.remove("SomeKey");
|
||||
|
||||
assertEquals("old value,", "SomeValue", old);
|
||||
assertNull("should be gone", tested.get("SomeKey"));
|
||||
assertEquals("SomeValue", old, "old value,");
|
||||
assertNull(tested.get("SomeKey"), "should be gone");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
Map<String, Object> otherMap = new HashMap<>();
|
||||
otherMap.put("SomeOtherKey", "SomeOtherValue");
|
||||
@@ -100,21 +114,25 @@ public class HttpServletContextMapTests extends TestCase {
|
||||
assertEquals("SomeUpdatedValue", tested.get("SomeKey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
tested.clear();
|
||||
assertTrue(tested.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeySet() {
|
||||
assertEquals(1, tested.keySet().size());
|
||||
assertTrue(tested.keySet().contains("SomeKey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValues() {
|
||||
assertEquals(1, tested.values().size());
|
||||
assertTrue(tested.values().contains("SomeValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntrySet() {
|
||||
assertEquals(1, tested.entrySet().size());
|
||||
assertEquals("SomeKey", tested.entrySet().iterator().next().getKey());
|
||||
|
||||
@@ -15,10 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
@@ -26,24 +32,25 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class HttpServletRequestMapTests extends TestCase {
|
||||
public class HttpServletRequestMapTests {
|
||||
|
||||
private HttpServletRequestMap tested;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
tested = new HttpServletRequestMap(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttribute() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
@@ -51,12 +58,14 @@ public class HttpServletRequestMapTests extends TestCase {
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
assertEquals("Some value", request.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAttribute() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
@@ -64,13 +73,14 @@ public class HttpServletRequestMapTests extends TestCase {
|
||||
assertNull(request.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttributeNames() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
request.removeAttribute("javax.servlet.context.tempdir");
|
||||
// perform test
|
||||
Iterator<String> names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
assertNotNull(names, "Null result unexpected");
|
||||
assertTrue(names.hasNext(), "More elements");
|
||||
String name = names.next();
|
||||
assertEquals("Some key", name);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
@@ -26,24 +32,25 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class HttpServletRequestParameterMapTests extends TestCase {
|
||||
public class HttpServletRequestParameterMapTests {
|
||||
|
||||
private HttpServletRequestParameterMap tested;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
tested = new HttpServletRequestParameterMap(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttribute() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
@@ -51,6 +58,7 @@ public class HttpServletRequestParameterMapTests extends TestCase {
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
try {
|
||||
@@ -61,6 +69,7 @@ public class HttpServletRequestParameterMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAttribute() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
@@ -72,12 +81,13 @@ public class HttpServletRequestParameterMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttributeNames() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
Iterator<String> names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
assertNotNull(names, "Null result unexpected");
|
||||
assertTrue(names.hasNext(), "More elements");
|
||||
String name = names.next();
|
||||
assertEquals("Some param", name);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,18 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
@@ -27,24 +35,25 @@ import org.springframework.web.util.WebUtils;
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class HttpSessionMapTests extends TestCase {
|
||||
public class HttpSessionMapTests {
|
||||
|
||||
private HttpSessionMap tested;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
tested = new HttpSessionMap(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttribute() {
|
||||
request.getSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
@@ -52,19 +61,22 @@ public class HttpSessionMapTests extends TestCase {
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttributeNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some key");
|
||||
assertNull("No value expected", result);
|
||||
assertNull(result, "No value expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
assertEquals("Some value", request.getSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAttribute() {
|
||||
request.getSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
@@ -72,6 +84,7 @@ public class HttpSessionMapTests extends TestCase {
|
||||
assertNull(request.getSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAttributeNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
@@ -79,29 +92,33 @@ public class HttpSessionMapTests extends TestCase {
|
||||
assertNull(request.getSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttributeNames() {
|
||||
request.getSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
Iterator<String> names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
assertNotNull(names, "Null result unexpected");
|
||||
assertTrue(names.hasNext(), "More elements");
|
||||
String name = names.next();
|
||||
assertEquals("Some key", name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttributeNamesNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
Iterator<String> names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertFalse("No elements expected", names.hasNext());
|
||||
assertNotNull(names, "Null result unexpected");
|
||||
assertFalse(names.hasNext(), "No elements expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSessionAsMutex() {
|
||||
Object mutex = tested.getMutex();
|
||||
assertSame(mutex, request.getSession());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSessionMutex() {
|
||||
Object object = new Object();
|
||||
request.getSession().setAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, object);
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -28,7 +34,7 @@ import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
/**
|
||||
* Unit tests for {@link ServletExternalContext}.
|
||||
*/
|
||||
public class ServletExternalContextTests extends TestCase {
|
||||
public class ServletExternalContextTests {
|
||||
|
||||
private MockServletContext servletContext;
|
||||
|
||||
@@ -38,7 +44,8 @@ public class ServletExternalContextTests extends TestCase {
|
||||
|
||||
private ServletExternalContext context;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
servletContext = new MockServletContext();
|
||||
servletContext.setAttribute("aFoo", "bar");
|
||||
request = new MockHttpServletRequest();
|
||||
@@ -48,52 +55,63 @@ public class ServletExternalContextTests extends TestCase {
|
||||
context = new ServletExternalContext(servletContext, request, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContextPath() {
|
||||
request.setContextPath("/foo");
|
||||
assertEquals("/foo", request.getContextPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestParameters() {
|
||||
assertTrue(context.getRequestParameterMap().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppAttribute() {
|
||||
assertEquals("bar", context.getApplicationMap().get("aFoo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSessionAttribute() {
|
||||
assertEquals("bar", context.getSessionMap().get("sFoo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequestAttribute() {
|
||||
assertEquals("bar", context.getRequestMap().get("rFoo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNativeObjects() {
|
||||
assertEquals(servletContext, context.getNativeContext());
|
||||
assertEquals(request, context.getNativeRequest());
|
||||
assertEquals(response, context.getNativeResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExecutionUrl() {
|
||||
request.setRequestURI("/foo");
|
||||
String url = context.getFlowExecutionUrl("foo", "e1s1");
|
||||
assertEquals("/foo?execution=e1s1", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotAnAjaxRequest() {
|
||||
assertFalse(context.isAjaxRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAjaxRequestAcceptHeader() {
|
||||
context.setAjaxRequest(true);
|
||||
assertTrue(context.isAjaxRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotResponseCommitted() {
|
||||
assertFalse(context.isResponseComplete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitExecutionRedirect() {
|
||||
context.requestFlowExecutionRedirect();
|
||||
assertTrue(context.getFlowExecutionRedirectRequested());
|
||||
@@ -101,6 +119,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertTrue(context.isResponseCompleteFlowExecutionRedirect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitFlowRedirect() {
|
||||
context.requestFlowDefinitionRedirect("foo", null);
|
||||
assertTrue(context.getFlowDefinitionRedirectRequested());
|
||||
@@ -110,6 +129,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertNotNull(context.getFlowRedirectFlowInput());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitFlowRedirectWithInput() {
|
||||
LocalAttributeMap<Object> input = new LocalAttributeMap<>();
|
||||
context.requestFlowDefinitionRedirect("foo", input);
|
||||
@@ -120,6 +140,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertEquals(input, context.getFlowRedirectFlowInput());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitExternalRedirect() {
|
||||
context.requestExternalRedirect("foo");
|
||||
assertTrue(context.getExternalRedirectRequested());
|
||||
@@ -129,6 +150,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertFalse(context.isResponseCompleteFlowExecutionRedirect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitExecutionRedirectPopup() {
|
||||
context.requestFlowExecutionRedirect();
|
||||
context.requestRedirectInPopup();
|
||||
@@ -139,6 +161,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertTrue(context.isResponseCompleteFlowExecutionRedirect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitFlowRedirectPopup() {
|
||||
context.requestFlowDefinitionRedirect("foo", null);
|
||||
context.requestRedirectInPopup();
|
||||
@@ -149,6 +172,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertFalse(context.isResponseAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitExternalRedirectPopup() {
|
||||
context.requestExternalRedirect("foo");
|
||||
context.requestRedirectInPopup();
|
||||
@@ -158,6 +182,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertFalse(context.isResponseAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordResponseComplete() {
|
||||
context.recordResponseComplete();
|
||||
assertTrue(context.isResponseComplete());
|
||||
@@ -165,6 +190,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertFalse(context.isResponseCompleteFlowExecutionRedirect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleCommitResponse() {
|
||||
context.recordResponseComplete();
|
||||
try {
|
||||
@@ -184,6 +210,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleCommitResponseExecutionRedirectFirst() {
|
||||
context.requestFlowExecutionRedirect();
|
||||
try {
|
||||
@@ -193,6 +220,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleCommitResponseDefinitionRedirectFirst() {
|
||||
context.requestFlowDefinitionRedirect("foo", null);
|
||||
try {
|
||||
@@ -202,6 +230,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleCommitResponseExternalRedirectFirst() {
|
||||
context.requestExternalRedirect("foo");
|
||||
try {
|
||||
@@ -211,6 +240,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedirectInPopup() {
|
||||
context.requestFlowExecutionRedirect();
|
||||
assertTrue(context.isResponseComplete());
|
||||
@@ -220,6 +250,7 @@ public class ServletExternalContextTests extends TestCase {
|
||||
assertTrue(context.getRedirectInPopup());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedirectInPopupNoRedirectRequested() {
|
||||
try {
|
||||
context.requestRedirectInPopup();
|
||||
@@ -229,12 +260,14 @@ public class ServletExternalContextTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResponseWriter() throws IOException {
|
||||
Writer writer = context.getResponseWriter();
|
||||
writer.append('t');
|
||||
assertEquals("t", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResponseWriterResponseComplete() throws IOException {
|
||||
context.recordResponseComplete();
|
||||
try {
|
||||
|
||||
@@ -1,39 +1,45 @@
|
||||
package org.springframework.webflow.context.servlet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
|
||||
public class WebFlow1FlowUrlHandlerTests extends TestCase {
|
||||
public class WebFlow1FlowUrlHandlerTests {
|
||||
private WebFlow1FlowUrlHandler urlHandler = new WebFlow1FlowUrlHandler();
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Test
|
||||
public void testGetFlowId() {
|
||||
request.addParameter("_flowId", "foo");
|
||||
assertEquals("foo", urlHandler.getFlowId(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowExecutionKey() {
|
||||
request.addParameter("_flowExecutionKey", "12345");
|
||||
assertEquals("12345", urlHandler.getFlowExecutionKey(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrl() {
|
||||
request.setRequestURI("/springtravel/app/flows");
|
||||
String url = urlHandler.createFlowDefinitionUrl("bookHotel", null, request);
|
||||
assertEquals("/springtravel/app/flows?_flowId=bookHotel", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlEmptyInput() {
|
||||
request.setRequestURI("/springtravel/app/flows");
|
||||
String url = urlHandler.createFlowDefinitionUrl("bookHotel", CollectionUtils.EMPTY_ATTRIBUTE_MAP, request);
|
||||
assertEquals("/springtravel/app/flows?_flowId=bookHotel", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowDefinitionUrlWithFlowInput() {
|
||||
request.setRequestURI("/springtravel/app/flows");
|
||||
LocalAttributeMap<Object> input = new LocalAttributeMap<>(new LinkedHashMap<>());
|
||||
@@ -45,6 +51,7 @@ public class WebFlow1FlowUrlHandlerTests extends TestCase {
|
||||
assertEquals("/springtravel/app/flows?_flowId=bookHotel&foo=bar&bar=needs+encoding&baz=1&boop=", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFlowExecutionUrl() {
|
||||
request.setRequestURI("/springtravel/app/flows");
|
||||
String url = urlHandler.createFlowExecutionUrl("bookHotel", "12345", request);
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.context.web;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.webflow.context.servlet.HttpSessionMap;
|
||||
import org.springframework.webflow.core.collection.AttributeMapBindingEvent;
|
||||
@@ -30,18 +35,20 @@ import org.springframework.webflow.core.collection.AttributeMapBindingListener;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class HttpSessionMapBindingListenerTests extends TestCase {
|
||||
public class HttpSessionMapBindingListenerTests {
|
||||
|
||||
private HttpServletRequest request;
|
||||
private HttpSession session;
|
||||
private TestAttributeMapBindingListener value;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
session = request.getSession(true);
|
||||
value = new TestAttributeMapBindingListener();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueBoundUnBound() {
|
||||
value.valueBoundEvent = null;
|
||||
value.valueUnboundEvent = null;
|
||||
|
||||
@@ -15,13 +15,20 @@
|
||||
*/
|
||||
package org.springframework.webflow.conversation.impl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.context.ExternalContextHolder;
|
||||
import org.springframework.webflow.conversation.Conversation;
|
||||
import org.springframework.webflow.conversation.ConversationException;
|
||||
@@ -33,18 +40,21 @@ import org.springframework.webflow.test.MockExternalContext;
|
||||
/**
|
||||
* Unit tests for {@link SessionBindingConversationManager}.
|
||||
*/
|
||||
public class SessionBindingConversationManagerTests extends TestCase {
|
||||
public class SessionBindingConversationManagerTests {
|
||||
|
||||
private SessionBindingConversationManager conversationManager;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
conversationManager = new SessionBindingConversationManager();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
ExternalContextHolder.setExternalContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversationLifeCycle() {
|
||||
ExternalContextHolder.setExternalContext(new MockExternalContext());
|
||||
Conversation conversation = conversationManager.beginConversation(new ConversationParameters("test", "test",
|
||||
@@ -61,6 +71,7 @@ public class SessionBindingConversationManagerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPassivation() {
|
||||
ExternalContextHolder.setExternalContext(new MockExternalContext());
|
||||
Conversation conversation = conversationManager.beginConversation(new ConversationParameters("test", "test",
|
||||
@@ -78,6 +89,7 @@ public class SessionBindingConversationManagerTests extends TestCase {
|
||||
conversation2.unlock();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPassivation() throws Exception {
|
||||
MockExternalContext externalContext = new MockExternalContext();
|
||||
ExternalContextHolder.setExternalContext(externalContext);
|
||||
@@ -105,6 +117,7 @@ public class SessionBindingConversationManagerTests extends TestCase {
|
||||
conversation.unlock();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxConversations() {
|
||||
conversationManager.setMaxConversations(2);
|
||||
ExternalContextHolder.setExternalContext(new MockExternalContext());
|
||||
@@ -129,6 +142,7 @@ public class SessionBindingConversationManagerTests extends TestCase {
|
||||
assertNotNull(conversationManager.getConversation(conversation3.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomSessionKey() {
|
||||
conversationManager.setSessionKey("foo");
|
||||
MockExternalContext context = new MockExternalContext();
|
||||
|
||||
@@ -15,13 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.core.collection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CollectionUtils}.
|
||||
*/
|
||||
public class CollectionUtilsTests extends TestCase {
|
||||
public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testSingleEntryMap() {
|
||||
AttributeMap<Object> map1 = CollectionUtils.singleEntryMap("foo", "bar");
|
||||
AttributeMap<Object> map2 = CollectionUtils.singleEntryMap("foo", "bar");
|
||||
|
||||
@@ -15,20 +15,31 @@
|
||||
*/
|
||||
package org.springframework.webflow.core.collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LocalAttributeMap}.
|
||||
*/
|
||||
public class LocalAttributeMapTests extends TestCase {
|
||||
public class LocalAttributeMapTests {
|
||||
|
||||
private LocalAttributeMap<Object> attributeMap = new LocalAttributeMap<>();
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
attributeMap.put("string", "A string");
|
||||
attributeMap.put("integer", 12345);
|
||||
@@ -42,21 +53,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
attributeMap.put("collection", new LinkedList<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() {
|
||||
TestBean bean = (TestBean) attributeMap.get("bean");
|
||||
assertNotNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNull() {
|
||||
TestBean bean = (TestBean) attributeMap.get("bogus");
|
||||
assertNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredType() {
|
||||
TestBean bean = attributeMap.get("bean", TestBean.class);
|
||||
assertNotNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWrongType() {
|
||||
try {
|
||||
attributeMap.get("bean", String.class);
|
||||
@@ -66,6 +81,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithDefaultOption() {
|
||||
TestBean d = new TestBean();
|
||||
TestBean bean = (TestBean) attributeMap.get("bean", d);
|
||||
@@ -73,17 +89,20 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
assertNotSame(bean, d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithDefault() {
|
||||
TestBean d = new TestBean();
|
||||
TestBean bean = (TestBean) attributeMap.get("bogus", d);
|
||||
assertSame(bean, d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequired() {
|
||||
TestBean bean = (TestBean) attributeMap.getRequired("bean");
|
||||
assertNotNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequired("bogus");
|
||||
@@ -93,11 +112,13 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredOfType() {
|
||||
TestBean bean = attributeMap.getRequired("bean", TestBean.class);
|
||||
assertNotNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredWrongType() {
|
||||
try {
|
||||
attributeMap.getRequired("bean", String.class);
|
||||
@@ -107,11 +128,13 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumber() {
|
||||
BigDecimal bd = attributeMap.getNumber("bigDecimal", BigDecimal.class);
|
||||
assertEquals(new BigDecimal("12345.67"), bd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberWrongType() {
|
||||
try {
|
||||
attributeMap.getNumber("bigDecimal", Integer.class);
|
||||
@@ -121,6 +144,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberWithDefaultOption() {
|
||||
BigDecimal d = new BigDecimal("1");
|
||||
BigDecimal bd = attributeMap.getNumber("bigDecimal", BigDecimal.class, d);
|
||||
@@ -128,6 +152,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
assertNotSame(d, bd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberWithDefault() {
|
||||
BigDecimal d = new BigDecimal("1");
|
||||
BigDecimal bd = attributeMap.getNumber("bogus", BigDecimal.class, d);
|
||||
@@ -135,11 +160,13 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
assertSame(d, bd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberRequired() {
|
||||
BigDecimal bd = attributeMap.getRequiredNumber("bigDecimal", BigDecimal.class);
|
||||
assertEquals(new BigDecimal("12345.67"), bd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredNumber("bogus", BigDecimal.class);
|
||||
@@ -149,21 +176,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInteger() {
|
||||
Integer i = attributeMap.getInteger("integer");
|
||||
assertEquals(new Integer(12345), i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIntegerNull() {
|
||||
Integer i = attributeMap.getInteger("bogus");
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIntegerRequired() {
|
||||
Integer i = attributeMap.getRequiredInteger("integer");
|
||||
assertEquals(new Integer(12345), i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIntegerRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredInteger("bogus");
|
||||
@@ -173,21 +204,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLong() {
|
||||
Long i = attributeMap.getLong("long");
|
||||
assertEquals(new Long(12345), i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLongNull() {
|
||||
Long i = attributeMap.getLong("bogus");
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLongRequired() {
|
||||
Long i = attributeMap.getRequiredLong("long");
|
||||
assertEquals(new Long(12345), i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLongRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredLong("bogus");
|
||||
@@ -197,21 +232,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetString() {
|
||||
String i = attributeMap.getString("string");
|
||||
assertEquals("A string", i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringNull() {
|
||||
String i = attributeMap.getString("bogus");
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringRequired() {
|
||||
String i = attributeMap.getRequiredString("string");
|
||||
assertEquals("A string", i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredString("bogus");
|
||||
@@ -221,21 +260,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBoolean() {
|
||||
Boolean i = attributeMap.getBoolean("boolean");
|
||||
assertEquals(Boolean.TRUE, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBooleanNull() {
|
||||
Boolean i = attributeMap.getBoolean("bogus");
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBooleanRequired() {
|
||||
Boolean i = attributeMap.getRequiredBoolean("boolean");
|
||||
assertEquals(Boolean.TRUE, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBooleanRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredBoolean("bogus");
|
||||
@@ -245,21 +288,25 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArray() {
|
||||
String[] i = attributeMap.getArray("stringArray", String[].class);
|
||||
assertEquals(3, i.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayNull() {
|
||||
String[] i = attributeMap.getArray("A bogus array", String[].class);
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayRequired() {
|
||||
String[] i = attributeMap.getRequiredArray("stringArray", String[].class);
|
||||
assertEquals(3, i.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredArray("A bogus array", String[].class);
|
||||
@@ -270,6 +317,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetCollection() {
|
||||
List<Object> i = attributeMap.getCollection("collection", List.class);
|
||||
assertTrue(i instanceof LinkedList);
|
||||
@@ -277,17 +325,20 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetCollectionNull() {
|
||||
List<Object> i = attributeMap.getCollection("bogus", List.class);
|
||||
assertNull(i);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetCollectionRequired() {
|
||||
List<Object> i = attributeMap.getRequiredCollection("collection", List.class);
|
||||
assertEquals(0, i.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCollectionRequiredNotPresent() {
|
||||
try {
|
||||
attributeMap.getRequiredCollection("A bogus collection");
|
||||
@@ -297,11 +348,13 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMap() {
|
||||
Map<String, Object> map = attributeMap.asMap();
|
||||
assertEquals(10, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnion() {
|
||||
LocalAttributeMap<Object> one = new LocalAttributeMap<>();
|
||||
one.put("foo", "bar");
|
||||
@@ -318,6 +371,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
assertEquals("boo", three.get("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
LocalAttributeMap<String> map = new LocalAttributeMap<>();
|
||||
map.put("foo", "bar");
|
||||
@@ -328,6 +382,7 @@ public class LocalAttributeMapTests extends TestCase {
|
||||
assertEquals(map, map2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtract() {
|
||||
assertEquals("A string", attributeMap.extract("string"));
|
||||
assertFalse(attributeMap.contains("string"));
|
||||
|
||||
@@ -15,21 +15,28 @@
|
||||
*/
|
||||
package org.springframework.webflow.core.collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LocalParameterMap}.
|
||||
*/
|
||||
public class LocalParameterMapTests extends TestCase {
|
||||
public class LocalParameterMapTests {
|
||||
|
||||
private LocalParameterMap parameterMap;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("string", "A string");
|
||||
@@ -41,31 +48,37 @@ public class LocalParameterMapTests extends TestCase {
|
||||
parameterMap = new LocalParameterMap(map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
assertTrue(!parameterMap.isEmpty());
|
||||
assertEquals(6, parameterMap.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() {
|
||||
String value = parameterMap.get("string");
|
||||
assertEquals("A string", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNull() {
|
||||
String value = parameterMap.get("bogus");
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequired() {
|
||||
String value = parameterMap.getRequired("string");
|
||||
assertEquals("A string", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredWithConversion() {
|
||||
Integer value = parameterMap.getRequired("integer", Integer.class);
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredNotPresent() {
|
||||
try {
|
||||
parameterMap.getRequired("bogus");
|
||||
@@ -74,22 +87,26 @@ public class LocalParameterMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithDefaultOption() {
|
||||
String value = parameterMap.get("string", "default");
|
||||
assertEquals("A string", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithDefault() {
|
||||
String value = parameterMap.get("bogus", "default");
|
||||
assertEquals("default", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithDefaultAndConversion() {
|
||||
Object value = parameterMap.get("bogus", Integer.class, 1);
|
||||
assertEquals(1, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testGetWithDefaultAndConversionNotAssignable() {
|
||||
try {
|
||||
parameterMap.get("bogus", (Class) Integer.class, "1");
|
||||
@@ -99,21 +116,25 @@ public class LocalParameterMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArray() {
|
||||
String[] value = parameterMap.getArray("stringArray");
|
||||
assertEquals(3, value.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEmptyArray() {
|
||||
String[] array = parameterMap.getArray("emptyArray");
|
||||
assertEquals(0, array.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayNull() {
|
||||
String[] value = parameterMap.getArray("bogus");
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayRequired() {
|
||||
String[] value = parameterMap.getRequiredArray("stringArray");
|
||||
assertEquals(3, value.length);
|
||||
@@ -126,6 +147,7 @@ public class LocalParameterMapTests extends TestCase {
|
||||
assertEquals(new Integer(3), values[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredArrayNotPresent() {
|
||||
try {
|
||||
parameterMap.getRequiredArray("bogus");
|
||||
@@ -134,27 +156,32 @@ public class LocalParameterMapTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSingleValueAsArray() {
|
||||
String[] value = parameterMap.getArray("string");
|
||||
assertEquals(1, value.length);
|
||||
assertEquals("A string", value[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayAsSingleVaue() {
|
||||
String value = parameterMap.get("stringArray");
|
||||
assertEquals("1", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEmptyArrayAsSingleVaue() {
|
||||
String value = parameterMap.get("emptyArray");
|
||||
assertEquals(null, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConversion() {
|
||||
Integer i = parameterMap.getInteger("integer");
|
||||
assertEquals(new Integer(12345), i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArrayConversion() {
|
||||
Integer[] i = parameterMap.getArray("stringArray", Integer.class);
|
||||
assertEquals(i.length, 3);
|
||||
@@ -170,81 +197,97 @@ public class LocalParameterMapTests extends TestCase {
|
||||
assertEquals(new Integer(3), values[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumber() {
|
||||
Integer value = parameterMap.getNumber("integer", Integer.class);
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredNumber() {
|
||||
Integer value = parameterMap.getRequiredNumber("integer", Integer.class);
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberWithDefault() {
|
||||
Integer value = parameterMap.getNumber("bogus", Integer.class, 12345);
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInteger() {
|
||||
Integer value = parameterMap.getInteger("integer");
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredInteger() {
|
||||
Integer value = parameterMap.getRequiredInteger("integer");
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIntegerWithDefault() {
|
||||
Integer value = parameterMap.getInteger("bogus", 12345);
|
||||
assertEquals(new Integer(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLong() {
|
||||
Long value = parameterMap.getLong("integer");
|
||||
assertEquals(new Long(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredLong() {
|
||||
Long value = parameterMap.getRequiredLong("integer");
|
||||
assertEquals(new Long(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLongWithDefault() {
|
||||
Long value = parameterMap.getLong("bogus", 12345L);
|
||||
assertEquals(new Long(12345), value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBoolean() {
|
||||
Boolean value = parameterMap.getBoolean("boolean");
|
||||
assertEquals(Boolean.TRUE, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredBoolean() {
|
||||
Boolean value = parameterMap.getRequiredBoolean("boolean");
|
||||
assertEquals(Boolean.TRUE, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBooleanWithDefault() {
|
||||
Boolean value = parameterMap.getBoolean("bogus", true);
|
||||
assertEquals(Boolean.TRUE, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMultipart() {
|
||||
MultipartFile file = parameterMap.getMultipartFile("multipartFile");
|
||||
assertNotNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequiredMultipart() {
|
||||
MultipartFile file = parameterMap.getRequiredMultipartFile("multipartFile");
|
||||
assertNotNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
LocalParameterMap map1 = new LocalParameterMap(new HashMap<>(parameterMap.asMap()));
|
||||
assertEquals(parameterMap, map1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsAttributeMap() {
|
||||
AttributeMap<Object> map = parameterMap.asAttributeMap();
|
||||
assertEquals(map.asMap(), parameterMap.asMap());
|
||||
|
||||
@@ -15,8 +15,14 @@
|
||||
*/
|
||||
package org.springframework.webflow.definition.registry;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
@@ -25,7 +31,7 @@ import org.springframework.webflow.definition.StateDefinition;
|
||||
/**
|
||||
* Unit tests for {@link FlowDefinitionRegistryImpl}.
|
||||
*/
|
||||
public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
public class FlowDefinitionRegistryImplTests {
|
||||
|
||||
private FlowDefinitionRegistryImpl registry = new FlowDefinitionRegistryImpl();
|
||||
|
||||
@@ -33,11 +39,13 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
|
||||
private BarFlow barFlow;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
fooFlow = new FooFlow();
|
||||
barFlow = new BarFlow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSuchFlowDefinition() {
|
||||
try {
|
||||
registry.getFlowDefinition("bogus");
|
||||
@@ -47,6 +55,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlowDefinitionId() {
|
||||
try {
|
||||
registry.getFlowDefinition(null);
|
||||
@@ -56,6 +65,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlankFlowDefinitionId() {
|
||||
try {
|
||||
registry.getFlowDefinition("");
|
||||
@@ -65,12 +75,14 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterFlow() {
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
|
||||
assertTrue(registry.containsFlowDefinition("foo"));
|
||||
assertEquals(fooFlow, registry.getFlowDefinition("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowIds() {
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow));
|
||||
@@ -78,6 +90,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
assertEquals("foo", registry.getFlowDefinitionIds()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterFlowSameIds() {
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
|
||||
FooFlow newFlow = new FooFlow();
|
||||
@@ -85,6 +98,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
assertSame(newFlow, registry.getFlowDefinition("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterMultipleFlows() {
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow));
|
||||
@@ -94,6 +108,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
assertEquals(barFlow, registry.getFlowDefinition("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentHierarchy() {
|
||||
testRegisterMultipleFlows();
|
||||
FlowDefinitionRegistryImpl child = new FlowDefinitionRegistryImpl();
|
||||
@@ -106,6 +121,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
|
||||
assertEquals(barFlow, child.getFlowDefinition("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroy() {
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
|
||||
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow));
|
||||
|
||||
@@ -15,8 +15,14 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.ActionExecutionException;
|
||||
import org.springframework.webflow.execution.ActionExecutor;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -24,18 +30,20 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.TestAction;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class ActionExecutorTests extends TestCase {
|
||||
public class ActionExecutorTests {
|
||||
|
||||
private MockRequestContext context;
|
||||
private State state;
|
||||
private Flow flow;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
flow = new Flow("myFlow");
|
||||
state = new EndState(flow, "end");
|
||||
context = new MockRequestContext(flow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteAction() {
|
||||
TestAction action = new TestAction();
|
||||
Event result = ActionExecutor.execute(action, context);
|
||||
@@ -43,6 +51,7 @@ public class ActionExecutorTests extends TestCase {
|
||||
assertEquals("success", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteActionInState() {
|
||||
context.getMockFlowExecutionContext().getMockActiveSession().setState(state);
|
||||
TestAction action = new TestAction();
|
||||
@@ -51,6 +60,7 @@ public class ActionExecutorTests extends TestCase {
|
||||
assertEquals("success", result.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteActionWithException() {
|
||||
TestAction action = new TestAction() {
|
||||
protected Event doExecute(RequestContext context) throws Exception {
|
||||
@@ -68,6 +78,7 @@ public class ActionExecutorTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteActionInStateWithException() {
|
||||
context.getMockFlowExecutionContext().getMockActiveSession().setState(state);
|
||||
TestAction action = new TestAction() {
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.engine.support.MockTransitionCriteria;
|
||||
import org.springframework.webflow.execution.Action;
|
||||
@@ -27,12 +30,13 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
* Tests ActionState behavior
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class ActionStateTests extends TestCase {
|
||||
public class ActionStateTests {
|
||||
|
||||
private Flow flow;
|
||||
private ActionState state;
|
||||
private MockRequestControlContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
flow = new Flow("myFlow");
|
||||
state = new ActionState(flow, "actionState");
|
||||
@@ -40,6 +44,7 @@ public class ActionStateTests extends TestCase {
|
||||
context = new MockRequestControlContext(flow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSingleAction() {
|
||||
state.getActionList().add(new TestAction());
|
||||
state.getTransitionSet().add(new Transition(on("success"), to("finish")));
|
||||
@@ -47,6 +52,7 @@ public class ActionStateTests extends TestCase {
|
||||
assertEquals(1, ((TestAction) state.getActionList().get(0)).getExecutionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteNothing() {
|
||||
try {
|
||||
state.enter(context);
|
||||
@@ -56,6 +62,7 @@ public class ActionStateTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteActionCannotHandleResultEvent() {
|
||||
state.getActionList().add(new TestAction());
|
||||
try {
|
||||
@@ -66,6 +73,7 @@ public class ActionStateTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteActionChain() {
|
||||
state.getActionList().add(new TestAction("not mapped result"));
|
||||
state.getActionList().add(new TestAction(null));
|
||||
|
||||
@@ -15,24 +15,28 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.core.AnnotatedObject;
|
||||
|
||||
public class AnnotatedObjectTests extends TestCase {
|
||||
public class AnnotatedObjectTests {
|
||||
|
||||
private AnnotatedObject object = new Flow("foo");
|
||||
|
||||
@Test
|
||||
public void testSetCaption() {
|
||||
object.setCaption("caption");
|
||||
assertEquals("caption", object.getCaption());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDescription() {
|
||||
object.setDescription("description");
|
||||
assertEquals("description", object.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutCustomAttributes() {
|
||||
object.getAttributes().put("foo", "bar");
|
||||
assertEquals("bar", object.getAttributes().get("foo"));
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.action.AbstractAction;
|
||||
import org.springframework.webflow.execution.AnnotatedAction;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -24,21 +26,24 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.TestAction;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class AnnotedActionTests extends TestCase {
|
||||
public class AnnotedActionTests {
|
||||
|
||||
private AnnotatedAction action = new AnnotatedAction(new TestAction());
|
||||
|
||||
private MockRequestContext context;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
Flow flow = new Flow("myFlow");
|
||||
context = new MockRequestContext(flow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicExecute() throws Exception {
|
||||
assertEquals("success", action.execute(context).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithCustomAttribute() throws Exception {
|
||||
action.getAttributes().put("attr", "value");
|
||||
action.setTargetAction(new AbstractAction() {
|
||||
@@ -51,6 +56,7 @@ public class AnnotedActionTests extends TestCase {
|
||||
assertEquals(0, context.getAttributes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithChainOfCustomAttributes() throws Exception {
|
||||
AnnotatedAction action2 = new AnnotatedAction(action);
|
||||
action2.getAttributes().put("attr2", "value");
|
||||
@@ -66,6 +72,7 @@ public class AnnotedActionTests extends TestCase {
|
||||
assertEquals(0, context.getAttributes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithName() throws Exception {
|
||||
action.getAttributes().put("name", "foo");
|
||||
action.setTargetAction(new AbstractAction() {
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.engine.support.MockTransitionCriteria;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -27,8 +29,9 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class DecisionStateTests extends TestCase {
|
||||
public class DecisionStateTests {
|
||||
|
||||
@Test
|
||||
public void testIfDecision() {
|
||||
Flow flow = new Flow("flow");
|
||||
DecisionState state = new DecisionState(flow, "decisionState");
|
||||
@@ -40,6 +43,7 @@ public class DecisionStateTests extends TestCase {
|
||||
assertFalse(context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testElseDecision() {
|
||||
Flow flow = new Flow("flow");
|
||||
DecisionState state = new DecisionState(flow, "decisionState");
|
||||
@@ -52,6 +56,7 @@ public class DecisionStateTests extends TestCase {
|
||||
assertFalse(context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotDecide() {
|
||||
Flow flow = new Flow("flow");
|
||||
DecisionState state = new DecisionState(flow, "decisionState");
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.EvaluationException;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
@@ -41,16 +44,18 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
* Tests EndState behavior.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class EndStateTests extends TestCase {
|
||||
public class EndStateTests {
|
||||
|
||||
@Test
|
||||
public void testEnterEndStateTerminateFlowExecution() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
EndState state = new EndState(flow, "end");
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
state.enter(context);
|
||||
assertFalse("Active", context.getFlowExecutionContext().isActive());
|
||||
assertFalse(context.getFlowExecutionContext().isActive(), "Active");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterEndStateWithFinalResponseRenderer() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
EndState state = new EndState(flow, "end");
|
||||
@@ -61,6 +66,7 @@ public class EndStateTests extends TestCase {
|
||||
assertTrue(action.executeCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterEndStateWithFinalResponseRendererResponseAlreadyComplete() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
EndState state = new EndState(flow, "end");
|
||||
@@ -72,6 +78,7 @@ public class EndStateTests extends TestCase {
|
||||
assertFalse(action.executeCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterEndStateWithOutputMapper() {
|
||||
Flow flow = new Flow("myFlow") {
|
||||
@SuppressWarnings("unused")
|
||||
@@ -92,6 +99,7 @@ public class EndStateTests extends TestCase {
|
||||
state.enter(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterEndStateTerminateFlowSession() {
|
||||
final Flow subflow = new Flow("mySubflow");
|
||||
EndState state = new EndState(subflow, "end");
|
||||
@@ -113,7 +121,7 @@ public class EndStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(new MockFlowExecutionContext(session));
|
||||
state.enter(context);
|
||||
|
||||
assertFalse("Active", context.getFlowExecutionContext().isActive());
|
||||
assertFalse(context.getFlowExecutionContext().isActive(), "Active");
|
||||
}
|
||||
|
||||
protected static TransitionCriteria on(String event) {
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
|
||||
@@ -25,8 +28,9 @@ import org.springframework.webflow.execution.Event;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class EventTests extends TestCase {
|
||||
public class EventTests {
|
||||
|
||||
@Test
|
||||
public void testNewEvent() {
|
||||
Event event = new Event(this, "id");
|
||||
assertEquals("id", event.getId());
|
||||
@@ -34,6 +38,7 @@ public class EventTests extends TestCase {
|
||||
assertTrue(event.getAttributes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventNullSource() {
|
||||
try {
|
||||
new Event(null, "id");
|
||||
@@ -43,6 +48,7 @@ public class EventTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventNullId() {
|
||||
try {
|
||||
new Event(this, null);
|
||||
@@ -52,6 +58,7 @@ public class EventTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewEventWithAttributes() {
|
||||
LocalAttributeMap<Object> attrs = new LocalAttributeMap<>();
|
||||
attrs.put("name", "value");
|
||||
@@ -60,6 +67,7 @@ public class EventTests extends TestCase {
|
||||
assertEquals(1, event.getAttributes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewEventNullAttributes() {
|
||||
Event event = new Event(this, "id", null);
|
||||
assertTrue(event.getAttributes().isEmpty());
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.FlowExecutionException;
|
||||
import org.springframework.webflow.test.MockRequestControlContext;
|
||||
|
||||
@@ -25,12 +28,13 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class FlowExecutionHandlerSetTests extends TestCase {
|
||||
public class FlowExecutionHandlerSetTests {
|
||||
|
||||
Flow flow = new Flow("myFlow");
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
boolean handled;
|
||||
|
||||
@Test
|
||||
public void testHandleException() {
|
||||
FlowExecutionExceptionHandlerSet handlerSet = new FlowExecutionExceptionHandlerSet();
|
||||
handlerSet.add(new TestStateExceptionHandler(NullPointerException.class, "null"));
|
||||
|
||||
@@ -15,10 +15,16 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.support.FluentParserContext;
|
||||
@@ -46,7 +52,7 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class FlowTests extends TestCase {
|
||||
public class FlowTests {
|
||||
|
||||
private Flow flow = createSimpleFlow();
|
||||
|
||||
@@ -59,20 +65,22 @@ public class FlowTests extends TestCase {
|
||||
return flow;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddStates() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
new EndState(flow, "myState1");
|
||||
new EndState(flow, "myState2");
|
||||
assertEquals("Wrong start state:", "myState1", flow.getStartState().getId());
|
||||
assertEquals("State count wrong:", 2, flow.getStateCount());
|
||||
assertEquals("myState1", flow.getStartState().getId(), "Wrong start state:");
|
||||
assertEquals(2, flow.getStateCount(), "State count wrong:");
|
||||
assertTrue(flow.containsState("myState1"));
|
||||
assertTrue(flow.containsState("myState2"));
|
||||
State state = flow.getStateInstance("myState1");
|
||||
assertEquals("Wrong flow:", flow.getId(), state.getFlow().getId());
|
||||
assertEquals("Wrong state:", "myState1", flow.getState("myState1").getId());
|
||||
assertEquals("Wrong state:", "myState2", flow.getState("myState2").getId());
|
||||
assertEquals(flow.getId(), state.getFlow().getId(), "Wrong flow:");
|
||||
assertEquals("myState1", flow.getState("myState1").getId(), "Wrong state:");
|
||||
assertEquals("myState2", flow.getState("myState2").getId(), "Wrong state:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDuplicateState() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
new EndState(flow, "myState1");
|
||||
@@ -84,6 +92,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSameStateTwice() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
EndState state = new EndState(flow, "myState1");
|
||||
@@ -93,9 +102,10 @@ public class FlowTests extends TestCase {
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
assertEquals("State count wrong:", 1, flow.getStateCount());
|
||||
assertEquals(1, flow.getStateCount(), "State count wrong:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddStateAlreadyInOtherFlow() {
|
||||
Flow otherFlow = new Flow("myOtherFlow");
|
||||
State state = new EndState(otherFlow, "myState1");
|
||||
@@ -108,6 +118,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStateNoStartState() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
try {
|
||||
@@ -118,6 +129,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStateNoSuchState() {
|
||||
try {
|
||||
flow.getState("myState3");
|
||||
@@ -127,11 +139,13 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTransitionableState() {
|
||||
assertEquals("Wrong state:", "myState1", flow.getTransitionableState("myState1").getId());
|
||||
assertEquals("Wrong state:", "myState1", flow.getState("myState1").getId());
|
||||
assertEquals("myState1", flow.getTransitionableState("myState1").getId(), "Wrong state:");
|
||||
assertEquals("myState1", flow.getState("myState1").getId(), "Wrong state:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStateNoSuchTransitionableState() {
|
||||
try {
|
||||
flow.getTransitionableState("myState2");
|
||||
@@ -146,6 +160,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPossibleOutcomes() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
new EndState(flow, "myState1");
|
||||
@@ -154,6 +169,7 @@ public class FlowTests extends TestCase {
|
||||
assertEquals("myState2", flow.getPossibleOutcomes()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddActions() {
|
||||
flow.getStartActionList().add(new TestMultiAction());
|
||||
flow.getStartActionList().add(new TestMultiAction());
|
||||
@@ -162,18 +178,21 @@ public class FlowTests extends TestCase {
|
||||
assertEquals(1, flow.getEndActionList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGlobalTransition() {
|
||||
Transition t = new Transition(to("myState2"));
|
||||
flow.getGlobalTransitionSet().add(t);
|
||||
assertSame(t, flow.getGlobalTransitionSet().toArray()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStart() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
flow.start(context, new LocalAttributeMap<>());
|
||||
assertEquals("Wrong start state", "myState1", context.getCurrentState().getId());
|
||||
assertEquals("myState1", context.getCurrentState().getId(), "Wrong start state");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithoutStartState() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
try {
|
||||
@@ -185,15 +204,17 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithAction() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
TestAction action = new TestAction();
|
||||
flow.getStartActionList().add(action);
|
||||
flow.start(context, new LocalAttributeMap<>());
|
||||
assertEquals("Wrong start state", "myState1", context.getCurrentState().getId());
|
||||
assertEquals("myState1", context.getCurrentState().getId(), "Wrong start state");
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithVariables() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
flow.addVariable(new FlowVariable("var1", new VariableValueFactory() {
|
||||
@@ -208,6 +229,7 @@ public class FlowTests extends TestCase {
|
||||
context.getFlowScope().getRequired("var1", ArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithMapper() {
|
||||
DefaultMapper attributeMapper = new DefaultMapper();
|
||||
ExpressionParser parser = new WebFlowSpringELExpressionParser(new SpelExpressionParser());
|
||||
@@ -223,6 +245,7 @@ public class FlowTests extends TestCase {
|
||||
assertEquals("foo", context.getFlowScope().get("attr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithMapperButNoInput() {
|
||||
DefaultMapper attributeMapper = new DefaultMapper();
|
||||
ExpressionParser parser = new WebFlowSpringELExpressionParser(new SpelExpressionParser());
|
||||
@@ -238,6 +261,7 @@ public class FlowTests extends TestCase {
|
||||
assertNull(context.getFlowScope().get("attr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEventNullCurrentState() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
Event event = new Event(this, "foo");
|
||||
@@ -249,6 +273,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEventInvalidCurrentState() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(flow.getStateInstance("myState2"));
|
||||
@@ -262,6 +287,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(flow.getStateInstance("myState1"));
|
||||
@@ -273,6 +299,7 @@ public class FlowTests extends TestCase {
|
||||
assertTrue(!context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEventGlobalTransition() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(flow.getStateInstance("myState1"));
|
||||
@@ -284,6 +311,7 @@ public class FlowTests extends TestCase {
|
||||
assertTrue(!context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEventNoTransition() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(flow.getStateInstance("myState1"));
|
||||
@@ -297,6 +325,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResume() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(flow.getStateInstance("myState1"));
|
||||
@@ -304,6 +333,7 @@ public class FlowTests extends TestCase {
|
||||
assertTrue(context.getFlowScope().getBoolean("renderCalled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnd() {
|
||||
TestAction action = new TestAction();
|
||||
flow.getEndActionList().add(action);
|
||||
@@ -313,6 +343,7 @@ public class FlowTests extends TestCase {
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndWithOutputMapper() {
|
||||
DefaultMapper attributeMapper = new DefaultMapper();
|
||||
ExpressionParser parser = new WebFlowSpringELExpressionParser(new SpelExpressionParser());
|
||||
@@ -328,6 +359,7 @@ public class FlowTests extends TestCase {
|
||||
assertEquals("foo", sessionOutput.get("attr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleException() {
|
||||
flow.getExceptionHandlerSet().add(
|
||||
new TransitionExecutingFlowExecutionExceptionHandler().add(TestException.class, "myState2"));
|
||||
@@ -339,6 +371,7 @@ public class FlowTests extends TestCase {
|
||||
assertFalse(context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleExceptionNoMatch() {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!",
|
||||
@@ -350,6 +383,7 @@ public class FlowTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroy() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.refresh();
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class FlowVariableTests extends TestCase {
|
||||
public class FlowVariableTests {
|
||||
|
||||
private boolean restoreCalled;
|
||||
|
||||
@Test
|
||||
public void testCreateVariable() {
|
||||
FlowVariable var = new FlowVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
@@ -23,6 +27,7 @@ public class FlowVariableTests extends TestCase {
|
||||
assertEquals("bar", context.getFlowScope().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyVariable() {
|
||||
FlowVariable var = new FlowVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
@@ -39,6 +44,7 @@ public class FlowVariableTests extends TestCase {
|
||||
assertFalse(context.getFlowScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreVariable() {
|
||||
FlowVariable var = new FlowVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.FlowExecutionException;
|
||||
import org.springframework.webflow.execution.TestAction;
|
||||
import org.springframework.webflow.test.MockRequestControlContext;
|
||||
@@ -26,7 +30,7 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class StateTests extends TestCase {
|
||||
public class StateTests {
|
||||
|
||||
private Flow flow;
|
||||
|
||||
@@ -36,6 +40,7 @@ public class StateTests extends TestCase {
|
||||
|
||||
private boolean handled;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
flow = new Flow("flow");
|
||||
state = new State(flow, "myState") {
|
||||
@@ -45,6 +50,7 @@ public class StateTests extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateEnter() {
|
||||
assertEquals("myState", state.getId());
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
@@ -53,6 +59,7 @@ public class StateTests extends TestCase {
|
||||
assertTrue(entered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateEnterWithEntryAction() {
|
||||
TestAction action = new TestAction();
|
||||
state.getEntryActionList().add(action);
|
||||
@@ -64,6 +71,7 @@ public class StateTests extends TestCase {
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandledException() {
|
||||
state.getExceptionHandlerSet().add(new FlowExecutionExceptionHandler() {
|
||||
public boolean canHandle(FlowExecutionException exception) {
|
||||
@@ -81,6 +89,7 @@ public class StateTests extends TestCase {
|
||||
assertTrue(handled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCouldNotHandleException() {
|
||||
FlowExecutionException e = new FlowExecutionException(flow.getId(), state.getId(), "Whatev");
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.EvaluationException;
|
||||
import org.springframework.binding.expression.support.AbstractGetValueExpression;
|
||||
import org.springframework.binding.mapping.Mapper;
|
||||
import org.springframework.binding.mapping.MappingResult;
|
||||
import org.springframework.binding.mapping.MappingResults;
|
||||
import org.springframework.binding.mapping.impl.DefaultMappingResults;
|
||||
import org.springframework.webflow.core.collection.AttributeMap;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
@@ -39,13 +38,14 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class SubflowStateTests extends TestCase {
|
||||
public class SubflowStateTests {
|
||||
|
||||
private Flow parentFlow;
|
||||
private SubflowState subflowState;
|
||||
private Flow subflow;
|
||||
private MockRequestControlContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
parentFlow = new Flow("parent");
|
||||
subflow = new Flow("child");
|
||||
@@ -58,6 +58,7 @@ public class SubflowStateTests extends TestCase {
|
||||
context.setCurrentState(subflowState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnter() {
|
||||
new State(subflow, "whatev") {
|
||||
protected void doEnter(RequestControlContext context) throws FlowExecutionException {
|
||||
@@ -68,6 +69,7 @@ public class SubflowStateTests extends TestCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testEnterWithInput() {
|
||||
subflowState.setAttributeMapper(new SubflowAttributeMapper() {
|
||||
public MutableAttributeMap<Object> createSubflowInput(RequestContext context) {
|
||||
@@ -91,6 +93,7 @@ public class SubflowStateTests extends TestCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testReturnWithOutput() {
|
||||
subflowState.setAttributeMapper(new SubflowAttributeMapper() {
|
||||
public MutableAttributeMap<Object> createSubflowInput(RequestContext context) {
|
||||
|
||||
@@ -15,17 +15,21 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.execution.FlowExecutionException;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.test.MockRequestControlContext;
|
||||
|
||||
public class TransitionTests extends TestCase {
|
||||
public class TransitionTests {
|
||||
|
||||
private boolean exitCalled;
|
||||
|
||||
@Test
|
||||
public void testExecuteTransitionFromState() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
@@ -53,6 +57,7 @@ public class TransitionTests extends TestCase {
|
||||
assertSame(target, context.getCurrentState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteTransitionWithNullSourceState() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState target = new TransitionableState(flow, "state 2") {
|
||||
@@ -70,6 +75,7 @@ public class TransitionTests extends TestCase {
|
||||
assertSame(target, context.getCurrentState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteTransitionNullTargetState() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
@@ -90,6 +96,7 @@ public class TransitionTests extends TestCase {
|
||||
assertSame(source, context.getCurrentState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteTransitionNullTargetStateResolver() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
@@ -109,6 +116,7 @@ public class TransitionTests extends TestCase {
|
||||
assertSame(source, context.getCurrentState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionExecutionRefused() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.TestBean;
|
||||
import org.springframework.webflow.engine.support.ActionTransitionCriteria;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
@@ -31,8 +35,9 @@ import org.springframework.webflow.test.MockRequestControlContext;
|
||||
* Tests that ViewState logic is correct.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class ViewStateTests extends TestCase {
|
||||
public class ViewStateTests {
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateRenderResponse() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -40,12 +45,13 @@ public class ViewStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateRenderNotAllowed() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -54,12 +60,13 @@ public class ViewStateTests extends TestCase {
|
||||
context.getMockExternalContext().setResponseAllowed(false);
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateResponseAlreadyComplete() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -68,11 +75,12 @@ public class ViewStateTests extends TestCase {
|
||||
context.getExternalContext().recordResponseComplete();
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateRedirectResponseAlreadyComplete() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -81,11 +89,12 @@ public class ViewStateTests extends TestCase {
|
||||
context.getExternalContext().requestFlowExecutionRedirect();
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateWithVariables() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -101,11 +110,12 @@ public class ViewStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
state.enter(context);
|
||||
assertEquals("bar", context.getViewScope().getString("foo"));
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateWithLocalRedirect() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -114,11 +124,12 @@ public class ViewStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateWithNoLocalRedirect() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -127,11 +138,12 @@ public class ViewStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertTrue("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateRedirectInPopup() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -141,12 +153,13 @@ public class ViewStateTests extends TestCase {
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getMockExternalContext().getRedirectInPopup());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterViewStateWithAlwaysRedirectOnPause() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -155,11 +168,12 @@ public class ViewStateTests extends TestCase {
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
context.setAlwaysRedirectOnPause(true);
|
||||
state.enter(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForRefresh() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -169,12 +183,13 @@ public class ViewStateTests extends TestCase {
|
||||
context = new MockRequestControlContext(context.getFlowExecutionContext());
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
state.resume(context);
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForRefreshResponseCompleteRecorded() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -188,11 +203,12 @@ public class ViewStateTests extends TestCase {
|
||||
context.getFlashScope().put("foo", "bar");
|
||||
context.getExternalContext().recordResponseComplete();
|
||||
state.resume(context);
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateRestoreVariables() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -210,11 +226,12 @@ public class ViewStateTests extends TestCase {
|
||||
state.enter(context);
|
||||
context = new MockRequestControlContext(context.getFlowExecutionContext());
|
||||
state.resume(context);
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertEquals("Restored", ((TestBean) context.getViewScope().get("foo")).datum1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventWithTransitionFlowEnded() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -233,6 +250,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(testAction.isExecuted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventWithTransitionStateExited() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -251,6 +269,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getFlowScope().contains("saveStateCalled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventWithTransitionStateExitedNoRedirect() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -269,6 +288,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertFalse(context.getFlowScope().contains("saveStateCalled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNotExitedNonAjax() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -287,12 +307,13 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNotExitedNonAjaxResponseNotAllowed() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -309,12 +330,13 @@ public class ViewStateTests extends TestCase {
|
||||
state.resume(context);
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertEquals(StubViewFactory.USER_EVENT_STATE, context.getFlashScope().get(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNotExitedNonAjaxRedirectEnabled() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -333,12 +355,13 @@ public class ViewStateTests extends TestCase {
|
||||
state.resume(context);
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertEquals(StubViewFactory.USER_EVENT_STATE, context.getFlashScope().get(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNotExitedAjax() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -358,12 +381,13 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNoExitActionRecordedResponseComplete() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -380,7 +404,7 @@ public class ViewStateTests extends TestCase {
|
||||
state.getTransitionSet().add(t);
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
state.enter(context);
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
context.getFlowScope().remove("renderCalled");
|
||||
context = new MockRequestControlContext(context.getFlowExecutionContext());
|
||||
context.putRequestParameter("_eventId", "submit");
|
||||
@@ -389,12 +413,13 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertFalse(context.getFlashScope().contains("foo"));
|
||||
assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventStateNoExitActionRecordedExecutionRedirect() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -411,7 +436,7 @@ public class ViewStateTests extends TestCase {
|
||||
state.getTransitionSet().add(t);
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
state.enter(context);
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
assertTrue(context.getFlowScope().contains("renderCalled"), "Render not called");
|
||||
context.getFlowScope().remove("renderCalled");
|
||||
context = new MockRequestControlContext(context.getFlowExecutionContext());
|
||||
context.putRequestParameter("_eventId", "submit");
|
||||
@@ -420,12 +445,13 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertTrue(context.getExternalContext().isResponseComplete());
|
||||
assertFalse("Render called", context.getFlowScope().contains("renderCalled"));
|
||||
assertFalse(context.getFlowScope().contains("renderCalled"), "Render called");
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
assertTrue(context.getFlashScope().contains("foo"));
|
||||
assertEquals(StubViewFactory.USER_EVENT_STATE, context.getFlashScope().get(View.USER_EVENT_STATE_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedirectInSameStateOverridesAlwaysRedirectOnPause() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -443,6 +469,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedModeOverridesRedirectInSameState() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -458,6 +485,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStateRedirectOverridesEmbeddedMode() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
@@ -474,6 +502,7 @@ public class ViewStateTests extends TestCase {
|
||||
assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeViewStateForEventDestroyVariables() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package org.springframework.webflow.engine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.test.MockRequestControlContext;
|
||||
|
||||
public class ViewVariableTests extends TestCase {
|
||||
public class ViewVariableTests {
|
||||
|
||||
private boolean restoreCalled;
|
||||
|
||||
@Test
|
||||
public void testCreateVariable() {
|
||||
ViewVariable var = new ViewVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
@@ -26,6 +30,7 @@ public class ViewVariableTests extends TestCase {
|
||||
assertEquals("bar", context.getViewScope().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyVariable() {
|
||||
ViewVariable var = new ViewVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
@@ -45,6 +50,7 @@ public class ViewVariableTests extends TestCase {
|
||||
assertFalse(context.getViewScope().contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreVariable() {
|
||||
ViewVariable var = new ViewVariable("foo", new VariableValueFactory() {
|
||||
public Object createInitialValue(RequestContext context) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.springframework.webflow.engine.builder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -11,23 +13,26 @@ import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.engine.builder.support.AbstractFlowBuilder;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
|
||||
public class DefaultFlowHolderTests extends TestCase {
|
||||
public class DefaultFlowHolderTests {
|
||||
private DefaultFlowHolder holder;
|
||||
private FlowAssembler assembler;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockFlowBuilderContext context = new MockFlowBuilderContext("flowId");
|
||||
context.getFlowBuilderServices().setApplicationContext(new StaticApplicationContext());
|
||||
FlowAssembler assembler = new FlowAssembler(new SimpleFlowBuilder(), context);
|
||||
holder = new DefaultFlowHolder(assembler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowDefinition() {
|
||||
FlowDefinition flow = holder.getFlowDefinition();
|
||||
assertEquals("flowId", flow.getId());
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlowDefinitionWithChangesRefreshed() {
|
||||
assembler = new FlowAssembler(new ChangeDetectableFlowBuilder(), new MockFlowBuilderContext("flowId"));
|
||||
holder = new DefaultFlowHolder(assembler);
|
||||
@@ -36,10 +41,12 @@ public class DefaultFlowHolderTests extends TestCase {
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyNotInitialized() {
|
||||
holder.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroy() {
|
||||
holder.getFlowDefinition();
|
||||
holder.destroy();
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package org.springframework.webflow.engine.builder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
|
||||
public class FlowAssemblerTests extends TestCase {
|
||||
public class FlowAssemblerTests {
|
||||
private FlowBuilder builder;
|
||||
private FlowAssembler assembler;
|
||||
private FlowBuilderContext builderContext;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = EasyMock.createMock(FlowBuilder.class);
|
||||
builderContext = new MockFlowBuilderContext("search");
|
||||
assembler = new FlowAssembler(builder, builderContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssembleFlow() {
|
||||
builder.init(builderContext);
|
||||
builder.dispose();
|
||||
@@ -35,6 +40,7 @@ public class FlowAssemblerTests extends TestCase {
|
||||
EasyMock.verify(builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisposeCalledOnException() {
|
||||
builder.init(builderContext);
|
||||
EasyMock.expectLastCall().andThrow(new IllegalArgumentException());
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package org.springframework.webflow.engine.builder.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -48,15 +54,17 @@ import org.springframework.webflow.test.MockExternalContext;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class FlowModelFlowBuilderTests extends TestCase {
|
||||
public class FlowModelFlowBuilderTests {
|
||||
private FlowModel model;
|
||||
|
||||
protected void setUp() {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
|
||||
beanFactory.addBean("bean", new Object());
|
||||
model = new FlowModel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildIncompleteFlow() {
|
||||
try {
|
||||
getFlow(model);
|
||||
@@ -70,6 +78,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
return new LinkedList<>(Arrays.asList(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFlowWithEndState() {
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
Flow flow = getFlow(model);
|
||||
@@ -77,6 +86,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFlowWithDefaultStartState() {
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
Flow flow = getFlow(model);
|
||||
@@ -84,6 +94,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFlowWithStartStateAttribute() {
|
||||
model.setStartStateId("end");
|
||||
model.setStates(asList(new EndStateModel("foo"), new EndStateModel("end")));
|
||||
@@ -92,6 +103,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomFlowAttribute() {
|
||||
AttributeModel attribute1 = new AttributeModel("foo", "bar");
|
||||
AttributeModel attribute2 = new AttributeModel("number", "1");
|
||||
@@ -104,6 +116,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals(1, flow.getAttributes().get("number"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistenceContextFlow() {
|
||||
model.setPersistenceContext(new PersistenceContextModel());
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
@@ -112,6 +125,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue((Boolean) flow.getAttributes().get("persistenceContext"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowInputOutputMapping() {
|
||||
InputModel input1 = new InputModel("foo", "flowScope.foo");
|
||||
InputModel input2 = new InputModel("foo", "flowScope.bar");
|
||||
@@ -157,6 +171,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertNull(outcome.getOutput().get("notReached"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowSecured() {
|
||||
model.setSecured(new SecuredModel("ROLE_USER"));
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
@@ -168,6 +183,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(rule.getAttributes().contains("ROLE_USER"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowSecuredState() {
|
||||
EndStateModel end = new EndStateModel("end");
|
||||
end.setSecured(new SecuredModel("ROLE_USER"));
|
||||
@@ -181,6 +197,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(rule.getAttributes().contains("ROLE_USER"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowSecuredTransition() {
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
TransitionModel transition = new TransitionModel();
|
||||
@@ -196,6 +213,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(rule.getAttributes().contains("ROLE_USER"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowVariable() {
|
||||
model.setVars(asList(new VarModel("flow-foo", "org.springframework.webflow.TestBean")));
|
||||
model.setStates(asList(new EndStateModel("end")));
|
||||
@@ -203,6 +221,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("flow-foo", flow.getVariable("flow-foo").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStateVariable() {
|
||||
ViewStateModel view = new ViewStateModel("view");
|
||||
view.setVars(asList(new VarModel("foo", "org.springframework.webflow.TestBean")));
|
||||
@@ -211,6 +230,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertNotNull(((ViewState) flow.getStateInstance("view")).getVariable("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStateRedirect() {
|
||||
ViewStateModel view = new ViewStateModel("view");
|
||||
view.setRedirect("true");
|
||||
@@ -219,6 +239,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(((ViewState) flow.getStateInstance("view")).getRedirect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStatePopup() {
|
||||
ViewStateModel view = new ViewStateModel("view");
|
||||
view.setPopup("true");
|
||||
@@ -227,6 +248,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(((ViewState) flow.getStateInstance("view")).getPopup());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStateFlowRedirect() {
|
||||
ViewStateModel state = new ViewStateModel("view");
|
||||
state.setView("flowRedirect:myFlow?input=#{flowScope.foo}");
|
||||
@@ -238,6 +260,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(avf.getAction() instanceof FlowDefinitionRedirectAction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewStateExternalRedirect() {
|
||||
ViewStateModel state = new ViewStateModel("view");
|
||||
state.setView("externalRedirect:https://www.paypal.com?_callbackUrl=#{flowExecutionUri}");
|
||||
@@ -249,6 +272,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertTrue(avf.getAction() instanceof ExternalRedirectAction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceBackedFlowBuilder() {
|
||||
ClassPathResource resource = new ClassPathResource("flow-endstate.xml", XmlFlowModelBuilderTests.class);
|
||||
Flow flow = getFlow(resource);
|
||||
@@ -256,6 +280,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("end", flow.getStartState().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceBackedFlowBuilderWithMessages() {
|
||||
ClassPathResource resource = new ClassPathResource("resources/flow.xml", FlowModelFlowBuilderTests.class);
|
||||
Flow flow = getFlow(resource);
|
||||
@@ -263,6 +288,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("bar", flow.getApplicationContext().getMessage("foo", null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbstractFlow() {
|
||||
model.setAbstract("true");
|
||||
try {
|
||||
@@ -273,6 +299,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionHandlers() {
|
||||
FlowModel model = new FlowModel();
|
||||
model.setStates(asList(new EndStateModel("state")));
|
||||
@@ -293,6 +320,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals(1, flow.getExceptionHandlerSet().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActionWithResultType() throws Exception {
|
||||
SetModel setModel = new SetModel("flowScope.stringArray", "intArray");
|
||||
setModel.setType("java.lang.String[]");
|
||||
@@ -308,6 +336,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("2", expected[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActionWithImplicitTypeConversion() throws Exception {
|
||||
SetModel setModel = new SetModel("testBean.stringArray", "intArray");
|
||||
model.setOnStartActions(asList(setModel));
|
||||
@@ -324,6 +353,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("2", expected.stringArray[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateActionWithResultType() throws Exception {
|
||||
EvaluateModel evaluateModel = new EvaluateModel("testBean.getIntegers()");
|
||||
evaluateModel.setResult("flowScope.stringArray");
|
||||
@@ -340,6 +370,7 @@ public class FlowModelFlowBuilderTests extends TestCase {
|
||||
assertEquals("2", expected[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateActionWithELExpression() throws Exception {
|
||||
EvaluateModel evaluateModel = new EvaluateModel("testBean.getIntegers()");
|
||||
evaluateModel.setResult("flowScope.stringArray");
|
||||
|
||||
@@ -15,21 +15,21 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.builder.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.engine.TargetStateResolver;
|
||||
import org.springframework.webflow.engine.Transition;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class TextToTargetStateResolverTests extends TestCase {
|
||||
public class TextToTargetStateResolverTests {
|
||||
|
||||
private MockFlowBuilderContext serviceLocator = new MockFlowBuilderContext("flowId");
|
||||
private TextToTargetStateResolver converter = new TextToTargetStateResolver(serviceLocator);
|
||||
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatic() throws Exception {
|
||||
String expression = "mockState";
|
||||
TargetStateResolver resolver = (TargetStateResolver) converter.convertSourceToTargetClass(expression,
|
||||
@@ -39,6 +39,7 @@ public class TextToTargetStateResolverTests extends TestCase {
|
||||
assertEquals("mockState", resolver.resolveTargetState(transition, null, context).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDynamic() throws Exception {
|
||||
String expression = "#{flowScope.lastState}";
|
||||
TargetStateResolver resolver = (TargetStateResolver) converter.convertSourceToTargetClass(expression,
|
||||
@@ -49,6 +50,7 @@ public class TextToTargetStateResolverTests extends TestCase {
|
||||
assertEquals("mockState", resolver.resolveTargetState(transition, null, context).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNull() throws Exception {
|
||||
String expression = null;
|
||||
TargetStateResolver resolver = (TargetStateResolver) converter.convertSourceToTargetClass(expression,
|
||||
@@ -56,6 +58,7 @@ public class TextToTargetStateResolverTests extends TestCase {
|
||||
assertNull(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmpty() throws Exception {
|
||||
String expression = "";
|
||||
TargetStateResolver resolver = (TargetStateResolver) converter.convertSourceToTargetClass(expression,
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.builder.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.ParserContext;
|
||||
import org.springframework.binding.expression.ParserException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.expression.support.StaticExpression;
|
||||
import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.engine.TransitionCriteria;
|
||||
@@ -31,22 +31,23 @@ import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class TextToTransitionCriteriaTests extends TestCase {
|
||||
public class TextToTransitionCriteriaTests {
|
||||
|
||||
private MockFlowBuilderContext serviceLocator = new MockFlowBuilderContext("flowId");
|
||||
private TextToTransitionCriteria converter = new TextToTransitionCriteria(serviceLocator);
|
||||
|
||||
@Override
|
||||
protected void tearDown() {
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAny() throws Exception {
|
||||
String expression = "*";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
assertTrue(criterion.test(ctx), "Criterion should evaluate to true");
|
||||
assertSame(WildcardTransitionCriteria.INSTANCE,
|
||||
converter.convertSourceToTargetClass("*", TransitionCriteria.class));
|
||||
assertSame(WildcardTransitionCriteria.INSTANCE,
|
||||
@@ -55,55 +56,61 @@ public class TextToTransitionCriteriaTests extends TestCase {
|
||||
converter.convertSourceToTargetClass(null, TransitionCriteria.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticEventId() throws Exception {
|
||||
String expression = "sample";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
assertTrue(criterion.test(ctx), "Criterion should evaluate to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueEvaluation() throws Exception {
|
||||
String expression = "#{flowScope.foo == 'bar'}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
assertTrue(criterion.test(ctx), "Criterion should evaluate to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalseEvaluation() throws Exception {
|
||||
String expression = "#{flowScope.foo != 'bar'}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertFalse("Criterion should evaluate to false", criterion.test(ctx));
|
||||
assertFalse(criterion.test(ctx), "Criterion should evaluate to false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStringEvaluation() throws Exception {
|
||||
String expression = "#{3 + 4}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
MockRequestContext ctx = getRequestContext();
|
||||
ctx.setCurrentEvent(new Event(this, "7"));
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
assertTrue(criterion.test(ctx), "Criterion should evaluate to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrenEventEval() throws Exception {
|
||||
String expression = "#{currentEvent.id == 'submit'}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass(expression,
|
||||
TransitionCriteria.class);
|
||||
MockRequestContext ctx = getRequestContext();
|
||||
ctx.setCurrentEvent(new Event(this, "submit"));
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
assertTrue(criterion.test(ctx), "Criterion should evaluate to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullExpressionEvaluation() throws Exception {
|
||||
serviceLocator.getFlowBuilderServices()
|
||||
.setExpressionParser((expressionString, context) -> new StaticExpression(null));
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass("doesnt matter",
|
||||
TransitionCriteria.class);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertFalse("Criterion should evaluate to false", criterion.test(ctx));
|
||||
assertFalse(criterion.test(ctx), "Criterion should evaluate to false");
|
||||
}
|
||||
|
||||
private MockRequestContext getRequestContext() {
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.impl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
@@ -41,7 +48,7 @@ import org.springframework.webflow.test.MockFlowExecutionKey;
|
||||
/**
|
||||
* Test case for {@link FlowExecutionImplFactory}.
|
||||
*/
|
||||
public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
public class FlowExecutionImplFactoryTests {
|
||||
|
||||
private FlowExecutionImplFactory factory = new FlowExecutionImplFactory();
|
||||
|
||||
@@ -57,11 +64,13 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
|
||||
private boolean removeAllSnapshotsCalled;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
flowDefinition = new Flow("flow");
|
||||
new EndState(flowDefinition, "end");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
FlowExecution execution = factory.createFlowExecution(flowDefinition);
|
||||
assertSame(flowDefinition, execution.getDefinition());
|
||||
@@ -69,6 +78,7 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
assertFalse(execution.isActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNullArgument() {
|
||||
try {
|
||||
factory.createFlowExecution(null);
|
||||
@@ -78,15 +88,17 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithExecutionAttributes() {
|
||||
MutableAttributeMap<Object> attributes = new LocalAttributeMap<>();
|
||||
attributes.put("foo", "bar");
|
||||
factory.setExecutionAttributes(attributes);
|
||||
FlowExecution execution = factory.createFlowExecution(flowDefinition);
|
||||
assertEquals(attributes, execution.getAttributes());
|
||||
assertSame("Flow execution attributes are global", attributes.asMap(), execution.getAttributes().asMap());
|
||||
assertSame(attributes.asMap(), execution.getAttributes().asMap(), "Flow execution attributes are global");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithExecutionListener() {
|
||||
FlowExecutionListener listener1 = new FlowExecutionListener() {
|
||||
public void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap<?> input) {
|
||||
@@ -100,6 +112,7 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
assertTrue(starting);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithExecutionKeyFactory() {
|
||||
State state = new State(flowDefinition, "state") {
|
||||
protected void doEnter(RequestControlContext context) throws FlowExecutionException {
|
||||
@@ -120,6 +133,7 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
assertNull(execution.getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreExecutionState() {
|
||||
FlowExecutionImpl flowExecution = (FlowExecutionImpl) factory.createFlowExecution(flowDefinition);
|
||||
LocalAttributeMap<Object> executionAttributes = new LocalAttributeMap<>();
|
||||
@@ -141,8 +155,8 @@ public class FlowExecutionImplFactoryTests extends TestCase {
|
||||
flowExecution.getFlowSessions().add(session1);
|
||||
flowExecution.getFlowSessions().add(session2);
|
||||
factory.restoreFlowExecution(flowExecution, flowDefinition, flowExecutionKey, conversationScope, locator);
|
||||
assertSame("Flow execution attributes are global", flowExecution.getAttributes().asMap(),
|
||||
executionAttributes.asMap());
|
||||
assertSame(flowExecution.getAttributes().asMap(), executionAttributes.asMap(),
|
||||
"Flow execution attributes are global");
|
||||
assertEquals(1, flowExecution.getListeners().length);
|
||||
assertSame(listener, flowExecution.getListeners()[0]);
|
||||
assertSame(flowExecutionKey, flowExecution.getKey());
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.impl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.message.MessageBuilder;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.definition.FlowDefinition;
|
||||
@@ -46,9 +53,10 @@ import org.springframework.webflow.test.MockFlowExecutionKeyFactory;
|
||||
* @author Ben Hale
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class FlowExecutionImplTests extends TestCase {
|
||||
public class FlowExecutionImplTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testStartAndEnd() {
|
||||
Flow flow = new Flow("flow");
|
||||
new EndState(flow, "end");
|
||||
@@ -85,6 +93,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(0, mockListener.getFlowNestingLevel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartAndEndSavedMessages() {
|
||||
Flow flow = new Flow("flow");
|
||||
new EndState(flow, "end");
|
||||
@@ -106,6 +115,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertNotNull(execution.getFlashScope().get("messagesMemento"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartAndPause() {
|
||||
Flow flow = new Flow("flow");
|
||||
new State(flow, "state") {
|
||||
@@ -123,6 +133,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(1, mockListener.getPausedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartWithNullInputMap() {
|
||||
Flow flow = new Flow("flow");
|
||||
new State(flow, "state") {
|
||||
@@ -145,6 +156,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(1, mockListener.getPausedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartExceptionThrownBeforeFirstSessionCreated() {
|
||||
Flow flow = new Flow("flow");
|
||||
flow.getExceptionHandlerSet().add(new FlowExecutionExceptionHandler() {
|
||||
@@ -181,6 +193,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartExceptionThrownByState() {
|
||||
Flow flow = new Flow("flow");
|
||||
State state = new State(flow, "state") {
|
||||
@@ -200,6 +213,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartFlowExecutionExceptionThrownByState() {
|
||||
Flow flow = new Flow("flow");
|
||||
final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops");
|
||||
@@ -219,6 +233,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartExceptionThrownByStateHandledByFlowExceptionHandler() {
|
||||
Flow flow = new Flow("flow");
|
||||
StubFlowExecutionExceptionHandler exceptionHandler = new StubFlowExecutionExceptionHandler();
|
||||
@@ -236,6 +251,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertTrue(exceptionHandler.getHandled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartExceptionThrownByStateHandledByStateExceptionHandler() {
|
||||
Flow flow = new Flow("flow");
|
||||
flow.getExceptionHandlerSet().add(new StubFlowExecutionExceptionHandler());
|
||||
@@ -254,6 +270,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertTrue(exceptionHandler.getHandled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionHandledByNestedExceptionHandler() {
|
||||
Flow flow = new Flow("flow");
|
||||
ExceptionThrowingExceptionHandler exceptionHandler = new ExceptionThrowingExceptionHandler(true);
|
||||
@@ -270,6 +287,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(2, exceptionHandler.getHandleCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartCannotCallTwice() {
|
||||
Flow flow = new Flow("flow");
|
||||
new EndState(flow, "end");
|
||||
@@ -284,6 +302,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResume() {
|
||||
Flow flow = new Flow("flow");
|
||||
new ViewState(flow, "view", new StubViewFactory());
|
||||
@@ -300,6 +319,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(2, mockListener.getPausedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeNotAViewState() {
|
||||
Flow flow = new Flow("flow");
|
||||
new State(flow, "state") {
|
||||
@@ -323,6 +343,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeAfterEnding() {
|
||||
Flow flow = new Flow("flow");
|
||||
new EndState(flow, "end");
|
||||
@@ -337,6 +358,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeException() {
|
||||
Flow flow = new Flow("flow");
|
||||
ViewState state = new ViewState(flow, "view", new StubViewFactory()) {
|
||||
@@ -362,6 +384,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResumeFlowExecutionException() {
|
||||
Flow flow = new Flow("flow");
|
||||
ViewState state = new ViewState(flow, "view", new StubViewFactory()) {
|
||||
@@ -387,6 +410,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteTransition() {
|
||||
Flow flow = new Flow("flow");
|
||||
ViewState state = new ViewState(flow, "view", new StubViewFactory()) {
|
||||
@@ -409,6 +433,7 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
assertEquals(1, mockListener.getTransitionExecutingCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestContextManagedOnStartAndResume() {
|
||||
Flow flow = new Flow("flow");
|
||||
new ViewState(flow, "view", new StubViewFactory()) {
|
||||
@@ -421,11 +446,11 @@ public class FlowExecutionImplTests extends TestCase {
|
||||
|
||||
MockExternalContext context = new MockExternalContext();
|
||||
execution.start(null, context);
|
||||
assertNull("RequestContext was not released", RequestContextHolder.getRequestContext());
|
||||
assertNull(RequestContextHolder.getRequestContext(), "RequestContext was not released");
|
||||
|
||||
context = new MockExternalContext();
|
||||
execution.resume(context);
|
||||
assertNull("RequestContext was not released", RequestContextHolder.getRequestContext());
|
||||
assertNull(RequestContextHolder.getRequestContext(), "RequestContext was not released");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,20 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractModel}.
|
||||
*/
|
||||
public class AbstractModelTests extends TestCase {
|
||||
public class AbstractModelTests {
|
||||
|
||||
@Test
|
||||
public void testStringMerge() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
String child = "child";
|
||||
@@ -31,6 +36,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("child", obj.merge(child, parent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringMergeNullParent() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
String child = "child";
|
||||
@@ -38,6 +44,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("child", obj.merge(child, parent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringMergeNullChild() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
String child = null;
|
||||
@@ -45,6 +52,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("parent", obj.merge(child, parent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringMergeNulls() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
String child = null;
|
||||
@@ -52,6 +60,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals(null, obj.merge(child, parent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeModel() {
|
||||
AttributeModel parent = new AttributeModel("foo", "bar");
|
||||
AttributeModel child = new AttributeModel("foo", null);
|
||||
@@ -60,6 +69,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("bar", child.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeParentCreateCopy() {
|
||||
AttributeModel parent = new AttributeModel("foo", "bar");
|
||||
AttributeModel child = null;
|
||||
@@ -69,6 +79,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertNotSame(parent, child);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMergeAddAtEndFalse() {
|
||||
LinkedList<SecuredModel> child = new LinkedList<>();
|
||||
child.add(new SecuredModel("1"));
|
||||
@@ -88,6 +99,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("foo", result.get(2).getMatch());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMergeAddAtEndTrue() {
|
||||
LinkedList<SecuredModel> child = new LinkedList<>();
|
||||
child.add(new SecuredModel("1"));
|
||||
@@ -107,6 +119,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("foo", result.get(1).getMatch());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMergeNullParent() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
LinkedList<SecuredModel> child = new LinkedList<>();
|
||||
@@ -117,6 +130,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("1", result.get(0).getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMergeNullChild() {
|
||||
LinkedList<SecuredModel> child = null;
|
||||
LinkedList<SecuredModel> parent = new LinkedList<>();
|
||||
@@ -128,6 +142,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertNotSame(parent.get(0), result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMergeNulls() {
|
||||
AbstractModel obj = new PersistenceContextModel();
|
||||
LinkedList<Model> child = null;
|
||||
@@ -136,6 +151,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyModel() {
|
||||
AttributeModel model = new AttributeModel("foo", "bar");
|
||||
FlowModel m = new FlowModel();
|
||||
@@ -144,6 +160,7 @@ public class AbstractModelTests extends TestCase {
|
||||
assertEquals("bar", copy.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyModelNull() {
|
||||
FlowModel m = new FlowModel();
|
||||
AttributeModel copy = (AttributeModel) m.copy(null);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user