package test; import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.apache.wicket.Component; import org.apache.wicket.MarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import wicketbench.junit.WicketBenchTestCase; import wicketbench.web.IComponentFactory; import wicketbench.web.WicketBench; /** * @author Joni Freeman */ public class DictionaryPanelTest extends WicketBenchTestCase { static { WicketBench.setApplicationClassName(TestApplication.class.getName()); } @Override public IComponentFactory createFactory() { return new IComponentFactory() { public DictionaryPanel createComponent(String panelId) { return new DictionaryPanel(panelId); } }; } public void testSearchPanelOnSelenium() { openSelenium(createFactory()); getSelenium().type("query", "ca"); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); String text = getSelenium().getBodyText(); assertTrue(text.contains("auto")); assertTrue(text.contains("kissa")); } public void testSearchPanelOnSelenium2() { openSelenium(createFactory()); getSelenium().type("query", "d"); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); String text = getSelenium().getBodyText(); assertTrue(text.contains("koira")); } public void testSearchPanelWithEmptyQuery() { openSelenium(createFactory()); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); String text = getSelenium().getBodyText(); assertTrue(text.contains("required")); } public void testShouldSupportEasyAccessToModel() { openSelenium(createFactory()); getSelenium().type("query", "ca"); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); List results = ((ListView) getComponent(pathToListing())).getList(); assertEquals(Arrays.asList("auto", "kissa"), results); } @SuppressWarnings("unchecked") public void testShouldSupportEasyCheckToCheckThatListItemsArePresent() { openSelenium(createFactory()); getSelenium().type("query", "ca"); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); ListView listView = (ListView) getComponent(pathToListing()); int count = 0; for (Iterator i = listView.iterator(); i.hasNext(); ) { assertTrue(getSelenium().isElementPresent(i.next().getMarkupId())); count++; } assertEquals(2, count); } public void testShouldSupportEasyAccessToListItems() { openSelenium(createFactory()); getSelenium().type("query", "ca"); getSelenium().click("submit"); getSelenium().waitForPageToLoad("5000"); ListView listView = (ListView) getComponent(pathToListing()); ListItem second = getComponent(listView, 1); assertTrue(getSelenium().isElementPresent(second.getMarkupId())); Label result = (Label) getComponent(listView, 1, "result"); assertEquals("kissa", result.getModel().getObject()); } protected String pathToListing() { return "results:listing"; } }