diff options
author | Artur <artur@vaadin.com> | 2017-06-15 10:21:50 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-06-15 10:21:50 +0300 |
commit | 7a0149592fff8a9d82e8e25bbc8837ed2b4382b5 (patch) | |
tree | 437056ea30eece99c18ca5cdf0d8d88cfeaf4422 /server/src/test/java | |
parent | 51947ca4dc73267fa5b583054bf5ca1b714002ae (diff) | |
download | vaadin-framework-7a0149592fff8a9d82e8e25bbc8837ed2b4382b5.tar.gz vaadin-framework-7a0149592fff8a9d82e8e25bbc8837ed2b4382b5.zip |
Make view parameter map available in ViewChangeEvent (#9529)
Diffstat (limited to 'server/src/test/java')
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java index 022b388840..fbc55d57cc 100644 --- a/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/src/test/java/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicReference; import org.easymock.EasyMock; import org.easymock.IArgumentMatcher; @@ -1060,4 +1061,57 @@ public class NavigatorTest { manager.setState(state); return navigator; } + + @Test + public void parameterMapFromViewChangeEvent() { + // create navigator to test + Navigator navigator = createNavigatorWithState("foo"); + View view1 = EasyMock.createMock(View.class); + View view2 = EasyMock.createMock(View.class); + ViewProvider provider = new ViewProvider() { + + @Override + public String getViewName(String viewAndParameters) { + if (viewAndParameters.contains("/")) { + return viewAndParameters.substring(0, + viewAndParameters.indexOf('/')); + } else { + return viewAndParameters; + } + } + + @Override + public View getView(String viewName) { + if (viewName.equals("view1")) { + return view1; + } else if (viewName.equals("view2")) { + return view2; + } else { + return null; + } + } + }; + navigator.addProvider(provider); + + AtomicReference<Map<String, String>> mapRef = new AtomicReference<>(); + AtomicReference<Map<String, String>> mapRefB = new AtomicReference<>(); + navigator.addViewChangeListener(new ViewChangeListener() { + @Override + public boolean beforeViewChange(ViewChangeEvent event) { + mapRef.set(event.getParameterMap()); + mapRefB.set(event.getParameterMap("b")); + return true; + } + }); + + navigator.navigateTo("view1"); + + Assert.assertTrue(mapRef.get().isEmpty()); + Assert.assertTrue(mapRefB.get().isEmpty()); + navigator.navigateTo("view1/a&b=c&d"); + + assertMap(mapRef.get(), entry("a", ""), entry("b", "c"), + entry("d", "")); + assertMap(mapRefB.get(), entry("a&", ""), entry("", "c&d")); + } } |