- wicket-arquilian / wicket-cdi-1.1 : Enable Junit Vintage Engine to run old Testrunners - BaseWicketTester.java: remove dependency on AssertionFailedException - global: use AssertionError instead of AssertionFailedError - updated Templates to use Junit 5 imports and classes - remove opentest4j as a dependency of wicket-util again - update cdi-unit to version 4.1.0 from 4.0.2 - Excluded Tests tagged with SLOW from surefire plugin
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0b48f270 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0b48f270 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0b48f270 Branch: refs/heads/WICKET-6563 Commit: 0b48f2703b0856e539045a486fd362077fe947a1 Parents: 872657b Author: renoth <[email protected]> Authored: Sat Sep 1 12:15:17 2018 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Wed Sep 26 15:40:32 2018 +0300 ---------------------------------------------------------------------- .../src/test/java/TestHomePage.java | 6 +- pom.xml | 5 +- testing/wicket-arquillian/pom.xml | 6 + .../testing/ApacheLicenceHeaderTest.java | 12 +- .../testing/TestWicketJavaEEApplication.java | 17 +- .../deployment/AbstractDeploymentTest.java | 155 ++++--- .../testing/pages/InsertContactTest.java | 56 ++- .../ArquillianContainerProvidedTest.java | 85 ++-- .../wicket/osgi/OsgiClashingPackagesTest.java | 85 ++-- .../org/apache/wicket/threadtest/App1Test.java | 2 +- .../org/apache/wicket/threadtest/App2Test.java | 2 +- .../authentication/panel/SignInPanelTest.java | 7 +- .../util/markup/xhtml/WellFormedXmlTest.java | 2 +- wicket-cdi/pom.xml | 6 + .../apache/wicket/cdi/CdiConfigurationTest.java | 11 +- .../org/apache/wicket/cdi/CdiWicketTester.java | 22 +- .../wicket/cdi/ConversationPropagatorTest.java | 5 +- .../apache/wicket/cdi/WicketCdiTestCase.java | 8 +- .../wicket/util/tester/BaseWicketTester.java | 433 ++++++++++--------- .../apache/wicket/util/tester/WicketTester.java | 28 +- .../test/java/org/apache/wicket/TesterTest.java | 4 +- .../handler/render/WebPageRendererTest.java | 4 +- .../inspector/SessionSizeModelTest.java | 7 +- .../stateless/StatelessCheckerTest.java | 16 +- .../util/markup/xhtml/WellFormedXmlTest.java | 2 +- .../wicket/examples/JettyTestCaseDecorator.java | 14 +- .../wicket/examples/WicketWebTestCase.java | 9 +- .../examples/ajax/prototype/AjaxTest.java | 4 +- .../wicket/examples/compref/ComprefTest.java | 10 +- .../wicket/examples/encodings/EncodingTest.java | 10 +- .../examples/forminput/FormInputTest.java | 2 +- .../examples/guestbook/GuestbookTest.java | 12 +- .../wicket/examples/hangman/HangManTest.java | 20 +- .../examples/hangman/WordGeneratorTest.java | 28 +- .../examples/helloworld/HelloWorldTest.java | 10 +- .../wicket/examples/images/ImagesTest.java | 13 +- .../wicket/examples/library/LibraryTest.java | 13 +- .../examples/linkomatic/LinkomaticTest.java | 2 +- .../wicket/examples/niceurl/NiceUrlTest.java | 13 +- .../wicket/examples/repeater/RepeaterTest.java | 2 +- .../wicket/examples/signin2/Signin2Test.java | 8 +- .../wicket/examples/template/TemplateTest.java | 5 +- .../wicket/filtertest/WithCPWithFPTest.java | 5 +- .../wicket/filtertest/WithCPWithoutFPTest.java | 4 +- .../wicket/filtertest/WithoutCPWithFPTest.java | 11 +- .../filtertest/WithoutCPWithoutFPTest.java | 11 +- .../util/markup/xhtml/WellFormedXmlTest.java | 2 +- .../ajax/markup/html/AjaxEditableTest.java | 13 +- .../ajax/markup/html/AjaxLazyLoadPanelTest.java | 2 +- .../html/autocomplete/AutoCompleteTest.java | 4 +- .../html/AjaxLazyLoadPanelTesterTest.java | 4 +- .../html/basic/DefaultLinkParserTest.java | 19 +- .../html/captcha/CaptchaImageResourceTest.java | 20 +- .../markup/html/form/DateTextFieldTest.java | 31 +- .../html/form/datetime/DateTimeFieldTest.java | 9 +- .../form/datetime/LocalDateTextFieldTest.java | 5 +- .../html/form/datetime/TimeFieldTest.java | 6 +- .../datetime/ZonedToLocalDateTimeModelTest.java | 4 +- .../markup/html/form/palette/PaletteTest.java | 5 +- .../markup/html/form/select/SelectTest.java | 13 +- .../resource/ThumbnailImageResourceTest.java | 5 +- .../html/repeater/data/table/DataTableTest.java | 34 +- .../data/table/export/CSVDataExporterTest.java | 8 +- .../data/table/filter/FilterFormTest.java | 2 +- .../repeater/tree/table/NodeBorderTest.java | 2 +- .../html/repeater/tree/table/NodeModelTest.java | 22 +- .../tree/table/TreeDataProviderTest.java | 8 +- .../html/repeater/util/ProviderSubsetTest.java | 10 +- .../repeater/util/TreeModelProviderTest.java | 9 +- .../markup/html/tabs/TabbedPanelTest.java | 50 +-- .../html/tabs/TabbedPanelVisibilityTest.java | 4 +- .../upload/UploadFormWithProgressBarTest.java | 4 +- .../RfcCompliantEmailValidatorTest.java | 12 +- .../extensions/wizard/WizardModelTest.java | 11 +- .../wizard/dynamic/DynamicWizardModelTest.java | 7 +- .../util/markup/xhtml/WellFormedXmlTest.java | 2 +- .../wicket/guice/AbstractInjectorTest.java | 40 +- .../guice/GuiceFieldValueFactoryTest.java | 4 +- .../guice/GuiceWebApplicationFactoryTest.java | 5 +- .../guice/JavaxInjectGuiceInjectorTest.java | 23 +- .../wicket/guice/JavaxInjectTestBehavior.java | 8 +- .../org/apache/wicket/guice/TestBehavior.java | 11 +- wicket-util/pom.xml | 6 - .../license/AbstractLicenseHeaderHandler.java | 17 +- .../license/ApacheLicenseHeaderTestCase.java | 3 +- .../util/license/CssLicenseHeaderHandler.java | 4 +- .../util/license/JavaLicenseHeaderHandler.java | 9 +- .../license/PropertiesLicenseHeaderHandler.java | 9 +- .../license/VelocityLicenseHeaderHandler.java | 9 +- .../util/license/XmlLicenseHeaderHandler.java | 13 +- .../util/license/XmlPrologHeaderHandler.java | 4 +- 91 files changed, 910 insertions(+), 774 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/archetypes/quickstart/src/main/resources/archetype-resources/src/test/java/TestHomePage.java ---------------------------------------------------------------------- diff --git a/archetypes/quickstart/src/main/resources/archetype-resources/src/test/java/TestHomePage.java b/archetypes/quickstart/src/main/resources/archetype-resources/src/test/java/TestHomePage.java index 2088135..b48d999 100644 --- a/archetypes/quickstart/src/main/resources/archetype-resources/src/test/java/TestHomePage.java +++ b/archetypes/quickstart/src/main/resources/archetype-resources/src/test/java/TestHomePage.java @@ -1,8 +1,8 @@ package ${package}; import org.apache.wicket.util.tester.WicketTester; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Simple test using the WicketTester @@ -11,7 +11,7 @@ public class TestHomePage { private WicketTester tester; - @Before + @BeforeEach public void setUp() { tester = new WicketTester(new WicketApplication()); http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 73ff1e1..39b9e56 100644 --- a/pom.xml +++ b/pom.xml @@ -989,7 +989,10 @@ <includes> <include>**/*Test.java</include> </includes> - + <properties> + <excludeTags>SLOW</excludeTags> + </properties> + <argLine>--add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-modules=ALL-SYSTEM</argLine> </configuration> </plugin> <plugin> http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/pom.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/pom.xml b/testing/wicket-arquillian/pom.xml index 3c47b5e..13023a6 100644 --- a/testing/wicket-arquillian/pom.xml +++ b/testing/wicket-arquillian/pom.xml @@ -138,6 +138,12 @@ <artifactId>arquillian-junit-container</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> <!-- Wicket CDI integration. --> <dependency> <groupId>org.apache.wicket</groupId> http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/ApacheLicenceHeaderTest.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/ApacheLicenceHeaderTest.java b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/ApacheLicenceHeaderTest.java index ac5aa02..8331475 100644 --- a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/ApacheLicenceHeaderTest.java +++ b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/ApacheLicenceHeaderTest.java @@ -16,14 +16,11 @@ */ package org.apache.wicket.arquillian.testing; -import java.util.Arrays; - import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase; /** - * Test that the license headers are in place in this project. The tests are run - * from {@link ApacheLicenseHeaderTestCase}, but you can add project specific - * tests here if needed. + * Test that the license headers are in place in this project. The tests are run from + * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests here if needed. * * @author Frank Bille Jensen (frankbille) */ @@ -34,9 +31,6 @@ public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase */ public ApacheLicenceHeaderTest() { -// xmlIgnore.add(".settings"); -// xmlIgnore.add("src/main/resources/META-INF/beans.xml"); -// xmlIgnore.add("src/test/java/simplelogger.properties"); -// xmlPrologIgnore = Arrays.asList("src"); + } } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/TestWicketJavaEEApplication.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/TestWicketJavaEEApplication.java b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/TestWicketJavaEEApplication.java index 9f2d146..8d4d57b 100644 --- a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/TestWicketJavaEEApplication.java +++ b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/TestWicketJavaEEApplication.java @@ -24,12 +24,15 @@ import org.apache.wicket.arquillian.testing.util.ResourceWebApplicationPath; * @author felipecalmeida * @since 06/20/2015 */ -public class TestWicketJavaEEApplication extends WicketJavaEEApplication { - +public class TestWicketJavaEEApplication extends WicketJavaEEApplication +{ + // Has some security ignores during the test (example: accept all roles). - - @Override - protected void initResourceFinder() { - getResourceSettings().getResourceFinders().add(new ResourceWebApplicationPath(TestWicketJavaEEApplication.class.getPackage().getName(), getServletContext())); - } + + @Override + protected void initResourceFinder() + { + getResourceSettings().getResourceFinders().add(new ResourceWebApplicationPath( + TestWicketJavaEEApplication.class.getPackage().getName(), getServletContext())); + } } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/deployment/AbstractDeploymentTest.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/deployment/AbstractDeploymentTest.java b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/deployment/AbstractDeploymentTest.java index 1615def..52b9014 100644 --- a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/deployment/AbstractDeploymentTest.java +++ b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/deployment/AbstractDeploymentTest.java @@ -16,6 +16,14 @@ */ package org.apache.wicket.arquillian.testing.deployment; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.io.File; +import java.util.Locale; + +import javax.servlet.ServletContext; + import org.apache.wicket.arquillian.testing.TestWicketJavaEEApplication; import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.WicketTestTag; @@ -32,119 +40,142 @@ import org.junit.jupiter.api.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.ServletContext; -import java.io.File; -import java.util.Locale; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - /** - * <b>WARNING: If this error occurs - org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already running! Managed containers do not support connecting to running server instances due to the possible harmful effect of connecting to the wrong server. Please stop server before running or change to another type of container. - * To disable this check and allow Arquillian to connect to a running server, set allowConnectingToRunningServer to true in the container configuration.</b> - * - * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> - * - * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. </b> - * + * <b>WARNING: If this error occurs - + * org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already + * running! Managed containers do not support connecting to running server instances due to the + * possible harmful effect of connecting to the wrong server. Please stop server before running or + * change to another type of container. To disable this check and allow Arquillian to connect to a + * running server, set allowConnectingToRunningServer to true in the container configuration.</b> + * + * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> + * + * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. + * </b> + * * @author felipecalmeida * @since 06/23/2015 * */ @Tag(WicketTestTag.SLOW) -public abstract class AbstractDeploymentTest { - +public abstract class AbstractDeploymentTest +{ + private static final Logger log = LoggerFactory.getLogger(AbstractDeploymentTest.class); - + private static final String WEBAPP_SRC = "src/main/webapp"; private static final String WEBAPP_TEST_SRC = "src/test/webapp"; + protected WicketTester wicketTester; @Deployment - public static WebArchive deployment() { + public static WebArchive deployment() + { // Create webapp files from src/main/webapp. (WEB AS NORMAL) - GenericArchive webapp = ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class).importDirectory(WEBAPP_SRC).as(GenericArchive.class); - + GenericArchive webapp = ShrinkWrap.create(GenericArchive.class) + .as(ExplodedImporter.class) + .importDirectory(WEBAPP_SRC) + .as(GenericArchive.class); + // Create webapptest files from src/test/webapp. (TEST) - GenericArchive webappTest = ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class).importDirectory(WEBAPP_TEST_SRC).as(GenericArchive.class); - + GenericArchive webappTest = ShrinkWrap.create(GenericArchive.class) + .as(ExplodedImporter.class) + .importDirectory(WEBAPP_TEST_SRC) + .as(GenericArchive.class); + // Some configurations to create a manifest.mf. ByteArrayAsset resource = new ByteArrayAsset("Dependencies: org.jboss.msc".getBytes()); - + // Create libs from POM.XML. File[] asFile = Maven.configureResolver() - .withMavenCentralRepo(true) - // Load everything from pom, that is compile and runtime, as a file and transitivity to don't loose anything and cause exceptions. - .loadPomFromFile("./pom.xml").importCompileAndRuntimeDependencies() - .resolve().withTransitivity().asFile(); - + .withMavenCentralRepo(true) + // Load everything from pom, that is compile and runtime, as a file and transitivity to + // don't loose anything and cause exceptions. + .loadPomFromFile("./pom.xml") + .importCompileAndRuntimeDependencies() + .resolve() + .withTransitivity() + .asFile(); + // Create the WAR. return ShrinkWrap.create(WebArchive.class, "wicket-servletContext8.war") - // Add packages and/or classes. - .addPackages(true, TestWicketJavaEEApplication.class.getPackage()) - // Add the persistence.xml - .addAsResource("META-INF/persistence.xml") - // Add a manifest. - .addAsManifestResource(resource, "MANIFEST.MF") - // Add WEBAPP files. - .merge(webapp,"/",Filters.exclude(".*\\web.xml")) - // Add WEBAPP TEST files. - .merge(webappTest,"/",Filters.includeAll()) - // Add LIBS from POM.XML. - .addAsLibraries(asFile); + // Add packages and/or classes. + .addPackages(true, TestWicketJavaEEApplication.class.getPackage()) + // Add the persistence.xml + .addAsResource("META-INF/persistence.xml") + // Add a manifest. + .addAsManifestResource(resource, "MANIFEST.MF") + // Add WEBAPP files. + .merge(webapp, "/", Filters.exclude(".*\\web.xml")) + // Add WEBAPP TEST files. + .merge(webappTest, "/", Filters.includeAll()) + // Add LIBS from POM.XML. + .addAsLibraries(asFile); } - - protected WicketTester wicketTester; - + /** * Set a new instance of wicketTester. * * @param wicketTester */ - public void setWicketTester(WicketTester wicketTester) { + public void setWicketTester(WicketTester wicketTester) + { this.wicketTester = wicketTester; } - + /** * Get an instance of wicketTester. The first time verify and create a new one. * * @return */ - public WicketTester getWicketTester() { - if(wicketTester == null) { - wicketTester = new WicketTester(useServletContextContainer(),false) { + public WicketTester getWicketTester() + { + if (wicketTester == null) + { + wicketTester = new WicketTester(useServletContextContainer(), false) + { @Override - protected Locale servletRequestLocale() { + protected Locale servletRequestLocale() + { return Locale.US; } }; } return wicketTester; } - + /** * Loading the TestWicketJavaEEApplication from src/test/webapp/WEB-INF/web.xml. - * + * * @return */ - protected WebApplication useServletContextContainer() { + protected WebApplication useServletContextContainer() + { WebApplication webApplication = null; - try { + try + { webApplication = TestWicketJavaEEApplication.get(); - } catch (Exception e) { - log.error("If not using arquillian, maybe org.apache.wicket.Application has a message for you " + e.getMessage()); - // I didn't test it, just supposing that i'm not using arquillian, so should show this message. - assertEquals("There is no application attached to current thread " + Thread.currentThread().getName(), e.getMessage()); } - + catch (Exception e) + { + log.error( + "If not using arquillian, maybe org.apache.wicket.Application has a message for you " + + e.getMessage()); + // I didn't test it, just supposing that i'm not using arquillian, so should show this + // message. + assertEquals("There is no application attached to current thread " + + Thread.currentThread().getName(), e.getMessage()); + } + assertNotNull(webApplication); - + log.info("WebApplication Name: " + webApplication.getName()); - + ServletContext servletContext = webApplication.getServletContext(); assertNotNull(servletContext); log.info("ServletContext Name: " + servletContext.getServletContextName()); - assertEquals("Wicket Arquillian WildFly Quickstart: Wicket TEST WAR",servletContext.getServletContextName()); - + assertEquals("Wicket Arquillian WildFly Quickstart: Wicket TEST WAR", + servletContext.getServletContextName()); + log.info("Server info: " + servletContext.getServerInfo()); return webApplication; } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/pages/InsertContactTest.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/pages/InsertContactTest.java b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/pages/InsertContactTest.java index 38df500..181235f 100644 --- a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/pages/InsertContactTest.java +++ b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/pages/InsertContactTest.java @@ -16,7 +16,8 @@ */ package org.apache.wicket.arquillian.testing.pages; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.util.List; import java.util.Locale; @@ -35,12 +36,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * <b>WARNING: If this error occurs - org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already running! Managed containers do not support connecting to running server instances due to the possible harmful effect of connecting to the wrong server. Please stop server before running or change to another type of container. - * To disable this check and allow Arquillian to connect to a running server, set allowConnectingToRunningServer to true in the container configuration.</b> - * - * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> + * <b>WARNING: If this error occurs - + * org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already + * running! Managed containers do not support connecting to running server instances due to the + * possible harmful effect of connecting to the wrong server. Please stop server before running or + * change to another type of container. To disable this check and allow Arquillian to connect to a + * running server, set allowConnectingToRunningServer to true in the container configuration.</b> * - * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. </b> + * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> + * + * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. + * </b> * * Just a class test to show that everything is working. * @@ -49,8 +55,9 @@ import org.slf4j.LoggerFactory; * */ @RunWith(Arquillian.class) -public class InsertContactTest extends AbstractDeploymentTest { - +public class InsertContactTest extends AbstractDeploymentTest +{ + private static final String EMAIL_IS_REQUIRED = "'email' is required."; private static final String NAME_IS_REQUIRED = "'name' is required."; @@ -68,8 +75,8 @@ public class InsertContactTest extends AbstractDeploymentTest { private static final Logger log = LoggerFactory.getLogger(InsertContactTest.class); @Inject - private ContactDao contactDao; - + private ContactDao contactDao; + @Before public void before() { @@ -77,45 +84,48 @@ public class InsertContactTest extends AbstractDeploymentTest { } @Test - public void testErrorMessagesInsertContact() { + public void testErrorMessagesInsertContact() + { Class<InsertContact> pageClass = InsertContact.class; getWicketTester().startPage(pageClass); getWicketTester().assertRenderedPage(pageClass); - + FormTester formTester = getWicketTester().newFormTester(INSERT_FORM); formTester.submit(); getWicketTester().assertErrorMessages(NAME_IS_REQUIRED, EMAIL_IS_REQUIRED); log.info("Required Messages: " + NAME_IS_REQUIRED + " and " + EMAIL_IS_REQUIRED); - + getWicketTester().assertRenderedPage(pageClass); } - + @Test - public void testInsertContact() { + public void testInsertContact() + { Class<InsertContact> pageClass = InsertContact.class; getWicketTester().startPage(pageClass); getWicketTester().assertRenderedPage(pageClass); - + FormTester formTester = getWicketTester().newFormTester(INSERT_FORM); formTester.setValue(NAME, WICKET_ARQUILLIAN_TEST); formTester.setValue(EMAIL, WICKET_ARQUILLIAN_TEST_APACHE_ORG); formTester.submit(); - + getWicketTester().assertNoErrorMessage(); getWicketTester().assertRenderedPage(ListContacts.class); - + log.info("Retrieving contacts to assert:"); List<Contact> contacts = contactDao.getContacts(); int contactsSize = contacts.size(); assertEquals(1, contactsSize); - + Contact contact = contacts.get(0); assertNotNull(contact.getId()); - assertEquals(WICKET_ARQUILLIAN_TEST,contact.getName()); - assertEquals(WICKET_ARQUILLIAN_TEST_APACHE_ORG,contact.getEmail()); - + assertEquals(WICKET_ARQUILLIAN_TEST, contact.getName()); + assertEquals(WICKET_ARQUILLIAN_TEST_APACHE_ORG, contact.getEmail()); + log.info("Contacts size: " + contactsSize); - for (Contact infoContact : contacts) { + for (Contact infoContact : contacts) + { log.info("Contacts info: " + infoContact); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/servletcontext/ArquillianContainerProvidedTest.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/servletcontext/ArquillianContainerProvidedTest.java b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/servletcontext/ArquillianContainerProvidedTest.java index a3ec33c..f045a3c 100644 --- a/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/servletcontext/ArquillianContainerProvidedTest.java +++ b/testing/wicket-arquillian/src/test/java/org/apache/wicket/arquillian/testing/servletcontext/ArquillianContainerProvidedTest.java @@ -36,37 +36,48 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * <b>WARNING: If this error occurs - org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already running! Managed containers do not support connecting to running server instances due to the possible harmful effect of connecting to the wrong server. Please stop server before running or change to another type of container. - * To disable this check and allow Arquillian to connect to a running server, set allowConnectingToRunningServer to true in the container configuration.</b> - * - * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> + * <b>WARNING: If this error occurs - + * org.jboss.arquillian.container.spi.client.container.LifecycleException: The server is already + * running! Managed containers do not support connecting to running server instances due to the + * possible harmful effect of connecting to the wrong server. Please stop server before running or + * change to another type of container. To disable this check and allow Arquillian to connect to a + * running server, set allowConnectingToRunningServer to true in the container configuration.</b> * - * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. </b> + * <b>SOLUTION: Search and kill wildfly or jboss proccess instance that are using port 8080.</b> + * + * <b> If you can't run inside eclipse, add as source the folder src/test/resources and try again. + * </b> * * @author felipecalmeida * @since 06/23/2015 * */ -@RunWith(Arquillian.class) -public class ArquillianContainerProvidedTest extends AbstractDeploymentTest { +@RunWith(Arquillian.class) // TODO upgrade to junit 5 ExtendWith when Arquillian project has Junit 5 + // support +public class ArquillianContainerProvidedTest extends AbstractDeploymentTest +{ - private static final Logger log = LoggerFactory.getLogger(ArquillianContainerProvidedTest.class); + private static final Logger log = LoggerFactory + .getLogger(ArquillianContainerProvidedTest.class); private static final String RESOURCE_PAGES_INSERT_CONTACT_HTML_NOT_FOUND = "Resource /pages/InsertContact.html not found."; /** - * Using container's servlet context and/or filter provided configured in web.xml and using Arquillian. + * Using container's servlet context and/or filter provided configured in web.xml and using + * Arquillian. */ @Test public void testFindResourcesServletContextFromContainer() throws MalformedURLException { - WebApplication webApplication = useServletContextContainer(); - setWicketTester(new WicketTester(webApplication, webApplication.getServletContext(), false)); + WebApplication webApplication = useServletContextContainer(); + setWicketTester( + new WicketTester(webApplication, webApplication.getServletContext(), false)); findResourcesServletContext(); } - + /** - * Using container's servlet context and/or filter provided configured in web.xml and using Arquillian. + * Using container's servlet context and/or filter provided configured in web.xml and using + * Arquillian. */ @Test public void testFindResourcesWebApplicationFromContainer() throws MalformedURLException @@ -75,38 +86,48 @@ public class ArquillianContainerProvidedTest extends AbstractDeploymentTest { setWicketTester(new WicketTester(webApplication, false)); findResourcesServletContext(); } - + /** * Creating another application and trying to reuse the ServletContext/Filter. */ @Test - public void testNewApplicationTryReuseServletContextFilter() { - try { + public void testNewApplicationTryReuseServletContextFilter() + { + try + { log.info("Trying to reuse container's ServletContext/Filter."); setWicketTester(new WicketTester(new TestWicketJavaEEApplication(), false)); fail("Should not be able to reuse the servlet context"); - } catch (IllegalStateException e) { - assertEquals("servletContext is not set yet. Any code in your Application object that uses the wicket filter instance should be put in the init() method instead of your constructor", e.getMessage()); + } + catch (IllegalStateException e) + { + assertEquals( + "servletContext is not set yet. Any code in your Application object that uses the wicket filter instance should be put in the init() method instead of your constructor", + e.getMessage()); } assertNull(wicketTester); } - + /** * Null application to test error. */ @Test - public void testNullApplication() { - try { + public void testNullApplication() + { + try + { log.info("Trying to use a null application."); setWicketTester(new WicketTester(null, false)); fail("WebApplication cannot be null"); - } catch (IllegalArgumentException iax) { + } + catch (IllegalArgumentException iax) + { assertEquals("Argument 'application' may not be null.", iax.getMessage()); } assertNull(wicketTester); } - + /** * Test with new application. */ @@ -116,16 +137,20 @@ public class ArquillianContainerProvidedTest extends AbstractDeploymentTest { setWicketTester(new WicketTester(new TestWicketJavaEEApplication())); assertNotNull(getWicketTester().getApplication()); log.info("Using mock servletcontext."); - log.info("WebApplication MOCK after wicketTester Name: " + getWicketTester().getApplication().getName()); - log.info("ServletContext MOCK after wicketTester Name: " + getWicketTester().getServletContext().getServletContextName()); + log.info("WebApplication MOCK after wicketTester Name: " + + getWicketTester().getApplication().getName()); + log.info("ServletContext MOCK after wicketTester Name: " + + getWicketTester().getServletContext().getServletContextName()); log.info("Server info: " + getWicketTester().getServletContext().getServerInfo()); - assertEquals("Wicket Mock Test Environment v1.0", getWicketTester().getServletContext().getServerInfo()); + assertEquals("Wicket Mock Test Environment v1.0", + getWicketTester().getServletContext().getServerInfo()); // USING MOCK. try { findResourcesServletContext(); - fail("Should not be able to find '/pages/InsertContact.html' in the mocked servlet context"); + fail( + "Should not be able to find '/pages/InsertContact.html' in the mocked servlet context"); } catch (IllegalStateException isx) { @@ -139,8 +164,10 @@ public class ArquillianContainerProvidedTest extends AbstractDeploymentTest { private void findResourcesServletContext() throws MalformedURLException { // Doing the same thing that ResourceWebApplicationPath does. - URL resource = getWicketTester().getServletContext().getResource("/pages/InsertContact.html"); - if (resource == null) { + URL resource = getWicketTester().getServletContext() + .getResource("/pages/InsertContact.html"); + if (resource == null) + { throw new IllegalStateException(RESOURCE_PAGES_INSERT_CONTACT_HTML_NOT_FOUND); } log.info("Resource found " + resource.getFile()); http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-common-tests/src/test/java/org/apache/wicket/osgi/OsgiClashingPackagesTest.java ---------------------------------------------------------------------- diff --git a/testing/wicket-common-tests/src/test/java/org/apache/wicket/osgi/OsgiClashingPackagesTest.java b/testing/wicket-common-tests/src/test/java/org/apache/wicket/osgi/OsgiClashingPackagesTest.java index 6672cc6..bd6701a 100644 --- a/testing/wicket-common-tests/src/test/java/org/apache/wicket/osgi/OsgiClashingPackagesTest.java +++ b/testing/wicket-common-tests/src/test/java/org/apache/wicket/osgi/OsgiClashingPackagesTest.java @@ -14,16 +14,16 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.apache.wicket.util.string.Strings; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** - * A test that verifies that there are no non-empty packages with the same name in - * two or more wicket modules. + * A test that verifies that there are no non-empty packages with the same name in two or more + * wicket modules. * * Based on https://gist.github.com/1977817, contributed by Andreas Pieber */ -public class OsgiClashingPackagesTest extends Assert +public class OsgiClashingPackagesTest { @Test @@ -47,26 +47,33 @@ public class OsgiClashingPackagesTest extends Assert String projectName = Strings.afterLast(dependency, '/'); Project project = new Project(projectName, jarFile); project.addTo(projectBuckets); - } finally { + } + finally + { jarFile.close(); } } } Set<Entry<String, List<Project>>> entrySet = projectBuckets.entrySet(); - for (Entry<String, List<Project>> entry : entrySet) { + for (Entry<String, List<Project>> entry : entrySet) + { List<Project> projects = entry.getValue(); - if (projects.size() > 1) { + if (projects.size() > 1) + { fail(entry); } } } - private void fail(Entry<String, List<Project>> entry) { + private void fail(Entry<String, List<Project>> entry) + { StringBuilder builder = new StringBuilder(); String packageName = entry.getKey(); - builder.append("Package '").append(packageName).append("' has files in two or more modules: "); - for (Project conflict : entry.getValue()) { + builder.append("Package '").append(packageName).append( + "' has files in two or more modules: "); + for (Project conflict : entry.getValue()) + { builder.append(conflict.getName()).append(", "); } try @@ -78,33 +85,41 @@ public class OsgiClashingPackagesTest extends Assert URL resource = resources.nextElement(); builder.append("\n\t").append(resource.toExternalForm()); } - } catch (IOException e) + } + catch (IOException e) { e.printStackTrace(); } - fail(builder.toString()); + Assertions.fail(builder.toString()); } - private static class Project { + private static class Project + { // a set with all package names in a dependency private final Set<String> packagesWithContent = new TreeSet<>(); // the name of the dependency private final String name; - public Project(String name, JarFile jarFile) { + public Project(String name, JarFile jarFile) + { this.name = name; collectPackageNames(jarFile); } /** - * Adds this project to as a value in the global map that contains 'packageName -> List[Project]' + * Adds this project to as a value in the global map that contains 'packageName -> + * List[Project]' + * * @param projectBuckets - * the global map + * the global map */ - public void addTo(Map<String, List<Project>> projectBuckets) { - for (String packageWithContent : packagesWithContent) { - if (!projectBuckets.containsKey(packageWithContent)) { + public void addTo(Map<String, List<Project>> projectBuckets) + { + for (String packageWithContent : packagesWithContent) + { + if (!projectBuckets.containsKey(packageWithContent)) + { projectBuckets.put(packageWithContent, new ArrayList<Project>()); } projectBuckets.get(packageWithContent).add(this); @@ -113,8 +128,9 @@ public class OsgiClashingPackagesTest extends Assert /** * Collects the names of all packages in this JarFile + * * @param jarFile - * the jar file to analyze + * the jar file to analyze */ private void collectPackageNames(final JarFile jarFile) { @@ -131,36 +147,27 @@ public class OsgiClashingPackagesTest extends Assert } } - public String getName() { + public String getName() + { return name; } @Override public String toString() { - return "Project{" + - "name='" + name + '\'' + - '}'; + return "Project{" + "name='" + name + '\'' + '}'; } private boolean shouldCollect(final String entryName) { - if ( - // ignore folder names. count just files/resources - entryName.endsWith("/") || + return !entryName.endsWith("/") && - // all modules have META-INF {MANIFEST.MF, Maven stuff, ..} - entryName.startsWith("META-INF/") || + // all modules have META-INF {MANIFEST.MF, Maven stuff, ..} + !entryName.startsWith("META-INF/") && - // ignore Wicket's IInitializer conf files - (entryName.startsWith("META-INF/wicket") && entryName.endsWith(".properties")) - ) - { - return false; - } - - return true; - } + // ignore Wicket's IInitializer conf files + (!entryName.startsWith("META-INF/wicket") || !entryName.endsWith(".properties")); + } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App1Test.java ---------------------------------------------------------------------- diff --git a/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App1Test.java b/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App1Test.java index 88e4874..27e299d 100644 --- a/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App1Test.java +++ b/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App1Test.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.wicket.threadtest.apps.app1.ResourceTestPage; import org.apache.wicket.threadtest.tester.SimpleGetCommand; import org.apache.wicket.threadtest.tester.Tester; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author eelcohillenius http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App2Test.java ---------------------------------------------------------------------- diff --git a/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App2Test.java b/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App2Test.java index f23d1d4..7a8153b 100644 --- a/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App2Test.java +++ b/testing/wicket-threadtest/src/test/java/org/apache/wicket/threadtest/App2Test.java @@ -21,7 +21,7 @@ import java.util.List; import org.apache.wicket.threadtest.tester.SimpleGetCommand; import org.apache.wicket.threadtest.tester.Tester; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author eelcohillenius http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-auth-roles/src/test/java/org/apache/wicket/authroles/authentication/panel/SignInPanelTest.java ---------------------------------------------------------------------- diff --git a/wicket-auth-roles/src/test/java/org/apache/wicket/authroles/authentication/panel/SignInPanelTest.java b/wicket-auth-roles/src/test/java/org/apache/wicket/authroles/authentication/panel/SignInPanelTest.java index 73735f5..e4208c5 100644 --- a/wicket-auth-roles/src/test/java/org/apache/wicket/authroles/authentication/panel/SignInPanelTest.java +++ b/wicket-auth-roles/src/test/java/org/apache/wicket/authroles/authentication/panel/SignInPanelTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.authroles.authentication.panel; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.concurrent.atomic.AtomicInteger; import org.apache.wicket.MarkupContainer; @@ -29,13 +31,12 @@ import org.apache.wicket.request.Request; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.WicketTester; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link SignInPanel} */ -public class SignInPanelTest extends Assert +public class SignInPanelTest { /** http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-auth-roles/src/test/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTest.java ---------------------------------------------------------------------- diff --git a/wicket-auth-roles/src/test/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTest.java b/wicket-auth-roles/src/test/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTest.java index a8e7628..88d9025 100644 --- a/wicket-auth-roles/src/test/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTest.java +++ b/wicket-auth-roles/src/test/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTest.java @@ -16,7 +16,7 @@ */ package org.apache.wicket.util.markup.xhtml; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Checks that the html markup files are well formed xml-s. http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-cdi/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-cdi/pom.xml b/wicket-cdi/pom.xml index fb40f46..ac6c3c2 100644 --- a/wicket-cdi/pom.xml +++ b/wicket-cdi/pom.xml @@ -64,6 +64,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.jglue.cdi-unit</groupId> <artifactId>cdi-unit</artifactId> <exclusions> http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java index 723db16..0b51437 100644 --- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java @@ -16,6 +16,9 @@ */ package org.apache.wicket.cdi; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.apache.wicket.cdi.testapp.TestConversationPage; import org.apache.wicket.cdi.testapp.TestPage; import org.apache.wicket.util.tester.WicketTester; @@ -46,11 +49,15 @@ public class CdiConfigurationTest extends WicketCdiTestCase } } - @Test(expected = Exception.class) + @Test public void testConfigureTwice() { configure(new CdiConfiguration()); - new CdiConfiguration().configure(tester.getApplication()); + + assertThrows(Exception.class, () -> { + new CdiConfiguration().configure(tester.getApplication()); + }); + } @Test http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java index 275a9bc..c887cd5 100644 --- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java @@ -16,8 +16,8 @@ */ package org.apache.wicket.cdi; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -53,10 +53,9 @@ public class CdiWicketTester extends WicketTester } /** - * Process the request by first activating the contexts on initial call. - * This call is called recursively in the super class so keep track of the - * topmost call and only activate and deactivate the contexts during that - * time. + * Process the request by first activating the contexts on initial call. This call is called + * recursively in the super class so keep track of the topmost call and only activate and + * deactivate the contexts during that time. * * @param forcedRequest * @param forcedRequestHandler @@ -65,7 +64,7 @@ public class CdiWicketTester extends WicketTester */ @Override protected boolean processRequest(final MockHttpServletRequest forcedRequest, - final IRequestHandler forcedRequestHandler, final boolean redirect) + final IRequestHandler forcedRequestHandler, final boolean redirect) { if (getLastRequest() != null) { @@ -111,17 +110,16 @@ public class CdiWicketTester extends WicketTester } /** - * Asserts that the response contains the right count. This can only be done - * by parsing the markup because models only contain valid values during a - * request, not after. + * Asserts that the response contains the right count. This can only be done by parsing the + * markup because models only contain valid values during a request, not after. * * @param count * TODO */ public void assertCount(int count) { - assertTrue("Response does not contain a count", - getLastResponseAsString().contains("COUNT=x")); + assertTrue(getLastResponseAsString().contains("COUNT=x"), + "Response does not contain a count"); Matcher matcher = COUNT_PATTERN.matcher(getLastResponseAsString()); assertTrue(matcher.find()); assertEquals(Integer.toString(count), matcher.group(1)); http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java index 945c9cf..0cd536f 100644 --- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.cdi; +import static org.junit.jupiter.api.Assertions.assertEquals; + import javax.enterprise.context.Conversation; import javax.inject.Inject; @@ -23,7 +25,6 @@ import org.apache.wicket.cdi.testapp.TestConversationPage; import org.apache.wicket.cdi.testapp.TestConversationalPage; import org.apache.wicket.core.request.mapper.MountedMapper; import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.hamcrest.CoreMatchers; import org.junit.Test; /** @@ -134,7 +135,7 @@ public class ConversationPropagatorTest extends WicketCdiTestCase tester.executeUrl("segment/hybrid?"+pageId+"&cid="+cid); - assertThat(tester.getLastRenderedPage().getId(), CoreMatchers.is(pageId)); + assertEquals(pageId, tester.getLastRenderedPage().getId()); } @Test http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java index 3f82075..3e64077 100644 --- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java @@ -32,20 +32,19 @@ import org.apache.wicket.util.tester.WicketTester; import org.jglue.cdiunit.AdditionalClasses; import org.jglue.cdiunit.CdiRunner; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.runner.RunWith; /** * @author jsarman */ -@RunWith(CdiRunner.class) +@RunWith(CdiRunner.class) // TODO upgrade to junit 5 ExtendWith when Cdi project has Junit 5 support @AdditionalClasses({ CdiWicketTester.class, BehaviorInjector.class, CdiConfiguration.class, CdiShutdownCleaner.class, ComponentInjector.class, ConversationExpiryChecker.class, ConversationPropagator.class, DetachEventEmitter.class, SessionInjector.class, TestAppScope.class, TestConversationBean.class, TestCdiApplication.class, AutoConversation.class }) -public abstract class WicketCdiTestCase extends Assert +public abstract class WicketCdiTestCase { @Inject private ContextManager contextManager; @@ -72,9 +71,6 @@ public abstract class WicketCdiTestCase extends Assert } } - /** - * @see junit.framework.TestCase#setUp() - */ @Before public void commonBefore() { http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java index 532cd10..313cb2d 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.regex.Pattern; + import javax.servlet.FilterConfig; import javax.servlet.ServletContext; import javax.servlet.http.Cookie; @@ -128,13 +129,11 @@ import org.apache.wicket.settings.RequestCycleSettings.RenderStrategy; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.lang.Classes; import org.apache.wicket.util.lang.Generics; -import org.apache.wicket.util.resource.ResourceStreamNotFoundException; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.string.Strings; import org.apache.wicket.util.time.Duration; import org.apache.wicket.util.visit.IVisit; import org.apache.wicket.util.visit.IVisitor; -import org.opentest4j.AssertionFailedError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,19 +158,14 @@ public class BaseWicketTester private static final Logger log = LoggerFactory.getLogger(BaseWicketTester.class); private final ServletContext servletContext; - private MockHttpSession httpSession; - private final WebApplication application; - + private final List<MockHttpServletRequest> previousRequests = Generics.newArrayList(); + private final List<MockHttpServletResponse> previousResponses = Generics.newArrayList(); + private MockHttpSession httpSession; private boolean followRedirects = true; private int redirectCount; - private MockHttpServletRequest lastRequest; private MockHttpServletResponse lastResponse; - - private final List<MockHttpServletRequest> previousRequests = Generics.newArrayList(); - private final List<MockHttpServletResponse> previousResponses = Generics.newArrayList(); - /** current request and response */ private MockHttpServletRequest request; private MockHttpServletResponse response; @@ -287,7 +281,8 @@ public class BaseWicketTester * @param init * force the application to be initialized (default = true) */ - public BaseWicketTester(final WebApplication application, final ServletContext servletCtx, boolean init) + public BaseWicketTester(final WebApplication application, final ServletContext servletCtx, + boolean init) { if (!init) { @@ -297,10 +292,10 @@ public class BaseWicketTester servletContext = servletCtx != null ? servletCtx // If it's provided from the container it's not necessary to mock. : !init && application.getServletContext() != null ? application.getServletContext() - : new MockServletContext(application, null); + : new MockServletContext(application, null); // If using Arquillian and it's configured in a web.xml it'll be provided. If not, mock it. - if(application.getWicketFilter() == null) + if (application.getWicketFilter() == null) { final FilterConfig filterConfig = new TestFilterConfig(); WicketFilter filter = new WicketFilter() @@ -339,16 +334,16 @@ public class BaseWicketTester application.getResourceSettings().setResourcePollFrequency(getResourcePollFrequency()); // reconfigure application for the test environment - application.setPageRendererProvider(new LastPageRecordingPageRendererProvider( - application.getPageRendererProvider())); - application.setRequestCycleProvider(new TestRequestCycleProvider( - application.getRequestCycleProvider())); + application.setPageRendererProvider( + new LastPageRecordingPageRendererProvider(application.getPageRendererProvider())); + application.setRequestCycleProvider( + new TestRequestCycleProvider(application.getRequestCycleProvider())); // set a feedback message filter that will not remove any messages originalFeedbackMessageCleanupFilter = application.getApplicationSettings() .getFeedbackMessageCleanupFilter(); - application.getApplicationSettings().setFeedbackMessageCleanupFilter( - IFeedbackMessageFilter.NONE); + application.getApplicationSettings() + .setFeedbackMessageCleanupFilter(IFeedbackMessageFilter.NONE); IPageManagerProvider pageManagerProvider = newTestPageManagerProvider(); if (pageManagerProvider != null) { @@ -391,7 +386,8 @@ public class BaseWicketTester private void setupNextRequestCycle() { - request = new MockHttpServletRequest(application, httpSession, servletContext, servletRequestLocale()); + request = new MockHttpServletRequest(application, httpSession, servletContext, + servletRequestLocale()); request.setURL(request.getContextPath() + request.getServletPath() + "/"); // assign protocol://host:port to next request unless the last request was ajax @@ -412,7 +408,8 @@ public class BaseWicketTester // Preserve response cookies in redirects // XXX: is this really needed ? Browsers wont do that, but some // Wicket tests assert that a cookie is in the response, - // even after redirects (see org.apache.wicket.util.cookies.SetCookieAndRedirectTest.statefulPage()) + // even after redirects (see + // org.apache.wicket.util.cookies.SetCookieAndRedirectTest.statefulPage()) // They should assert that the cookie is in the next *request* if (lastResponse != null) { @@ -469,7 +466,8 @@ public class BaseWicketTester } } - protected Locale servletRequestLocale() { + protected Locale servletRequestLocale() + { return Locale.getDefault(); } @@ -725,7 +723,7 @@ public class BaseWicketTester { if (redirectCount++ >= 100) { - throw new AssertionFailedError("Possible infinite redirect detected. Bailing out."); + throw new AssertionError("Possible infinite redirect detected. Bailing out."); } Url newUrl = Url.parse(lastResponse.getRedirectLocation(), @@ -995,11 +993,10 @@ public class BaseWicketTester * * @return Wicket-Ajax-BaseURL set on last response by {@link AbstractDefaultAjaxBehavior} * @throws IOException - * @throws ResourceStreamNotFoundException * @throws ParseException */ - public String getWicketAjaxBaseUrlEncodedInLastResponse() throws IOException, - ResourceStreamNotFoundException, ParseException + public String getWicketAjaxBaseUrlEncodedInLastResponse() + throws IOException, ParseException { XmlPullParser parser = new XmlPullParser(); parser.parse(getLastResponseAsString()); @@ -1080,10 +1077,10 @@ public class BaseWicketTester } /** - * Simulates processing URL that invokes an {@link IRequestListener} on a component. + * Simulates processing URL that invokes an {@link IRequestListener} on a component. * - * After the listener is invoked the page containing the component will be rendered - * (with an optional redirect - depending on {@link RenderStrategy}). + * After the listener is invoked the page containing the component will be rendered (with an + * optional redirect - depending on {@link RenderStrategy}). * * @param component */ @@ -1118,8 +1115,8 @@ public class BaseWicketTester * Simulates invoking an {@link IRequestListener} on a component. As opposed to the * {@link #executeListener(Component)} method, current request/response objects will be used * - * After the listener is invoked the page containing the component will be rendered - * (with an optional redirect - depending on {@link RenderStrategy}). + * After the listener is invoked the page containing the component will be rendered (with an + * optional redirect - depending on {@link RenderStrategy}). * * @param component */ @@ -1129,8 +1126,8 @@ public class BaseWicketTester // there are two ways to do this. RequestCycle could be forced to call the handler // directly but constructing and parsing the URL increases the chance of triggering bugs - IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider( - component.getPage(), component)); + IRequestHandler handler = new ListenerRequestHandler( + new PageAndComponentProvider(component.getPage(), component)); processRequest(handler); } @@ -1139,8 +1136,8 @@ public class BaseWicketTester * Simulates invoking an {@link IRequestListener} on a component. As opposed to the * {@link #executeListener(Component)} method, current request/response objects will be used * - * After the listener is invoked the page containing the component will be rendered - * (with an optional redirect - depending on {@link RenderStrategy}). + * After the listener is invoked the page containing the component will be rendered (with an + * optional redirect - depending on {@link RenderStrategy}). * * @param component * @param behavior @@ -1152,8 +1149,9 @@ public class BaseWicketTester // there are two ways to do this. RequestCycle could be forced to call the handler // directly but constructing and parsing the URL increases the chance of triggering bugs - IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider( - component.getPage(), component), component.getBehaviorId(behavior)); + IRequestHandler handler = new ListenerRequestHandler( + new PageAndComponentProvider(component.getPage(), component), + component.getBehaviorId(behavior)); processRequest(handler); } @@ -1184,8 +1182,8 @@ public class BaseWicketTester serializeFormToRequest(form); // mark behavior's component as the form submitter, - String name = Form.getRootFormRelativeId(new PropertyModel<Component>(behavior, - "component").getObject()); + String name = Form.getRootFormRelativeId( + new PropertyModel<Component>(behavior, "component").getObject()); if (!request.getPostParameters().getParameterNames().contains(name)) { request.getPostParameters().setParameterValue(name, "marked"); @@ -1200,9 +1198,10 @@ public class BaseWicketTester * * @return Origin header */ - protected String createOriginHeader(){ + protected String createOriginHeader() + { Url url = RequestCycle.get().getRequest().getUrl(); - return url.getProtocol() + "://" +url.getHost() + ":" + url.getPort(); + return url.getProtocol() + "://" + url.getHost() + ":" + url.getPort(); } /** @@ -1453,7 +1452,8 @@ public class BaseWicketTester } catch (Exception e) { - String errorMessage = "Error while parsing the markup for the autogenerated page: " + e.getMessage(); + String errorMessage = "Error while parsing the markup for the autogenerated page: " + + e.getMessage(); log.error(errorMessage, e); fail(errorMessage); } @@ -1516,57 +1516,6 @@ public class BaseWicketTester } /** - * A page that is used as the automatically created page for - * {@link BaseWicketTester#startComponentInPage(Class)} and the other variations. - * <p> - * This page caches the generated markup so that it is available even after - * {@link Component#detach()} where the {@link Component#markup component's markup cache} is - * cleared. - */ - public static class StartComponentInPage extends WebPage - { - private transient IMarkupFragment pageMarkup = null; - - /** - * Construct. - */ - public StartComponentInPage() - { - setStatelessHint(false); - } - - @Override - public IMarkupFragment getMarkup() - { - IMarkupFragment calculatedMarkup = null; - if (pageMarkup == null) - { - IMarkupFragment markup = super.getMarkup(); - if (markup != null && markup != Markup.NO_MARKUP) - { - calculatedMarkup = markup; - pageMarkup = markup; - } - } - else - { - calculatedMarkup = pageMarkup; - } - - return calculatedMarkup; - } - - /** - * @param markup - */ - public void setPageMarkup(IMarkupFragment markup) - { - setMarkup(markup); - pageMarkup = markup; - } - } - - /** * Gets the component with the given path from last rendered page. This method fails in case the * component couldn't be found. * @@ -1651,8 +1600,9 @@ public class BaseWicketTester { Component component = assertExists(path); - return isTrue("component '" + Classes.name(component.getClass()) + "' is not of type: " + - Classes.name(expectedComponentClass), + return isTrue( + "component '" + Classes.name(component.getClass()) + "' is not of type: " + + Classes.name(expectedComponentClass), expectedComponentClass.isAssignableFrom(component.getClass())); } @@ -1736,24 +1686,26 @@ public class BaseWicketTester return isFalse("component '" + path + "' is enabled", component.isEnabledInHierarchy()); } - protected Component assertExists(final String path) { + protected Component assertExists(final String path) + { Component component = getComponentFromLastRenderedPage(path); if (component == null) { fail("path: '" + path + "' does no exist for page: " + - Classes.simpleName(getLastRenderedPage().getClass())); + Classes.simpleName(getLastRenderedPage().getClass())); } return component; } - private FormComponent assertFormComponent(final String path) { + private FormComponent assertFormComponent(final String path) + { Component component = assertExists(path); if (component instanceof FormComponent == false) { fail("path: '" + path + "' is not a form component"); } - return (FormComponent) component; + return (FormComponent)component; } /** @@ -1908,8 +1860,8 @@ public class BaseWicketTester "not be invoked when AJAX (javascript) is disabled."); } - List<AjaxEventBehavior> behaviors = WicketTesterHelper.findAjaxEventBehaviors( - linkComponent, "click"); + List<AjaxEventBehavior> behaviors = WicketTesterHelper + .findAjaxEventBehaviors(linkComponent, "click"); for (AjaxEventBehavior behavior : behaviors) { executeBehavior(behavior); @@ -1935,10 +1887,11 @@ public class BaseWicketTester (AjaxFormSubmitBehavior)WicketTesterHelper.findAjaxEventBehavior(link, "click")); } // if the link is an IAjaxLink, use it (do check if AJAX is expected) - else if (isAjax && (linkComponent instanceof IAjaxLink || linkComponent instanceof AjaxFallbackLink)) + else if (isAjax && + (linkComponent instanceof IAjaxLink || linkComponent instanceof AjaxFallbackLink)) { - List<AjaxEventBehavior> behaviors = WicketTesterHelper.findAjaxEventBehaviors( - linkComponent, "click"); + List<AjaxEventBehavior> behaviors = WicketTesterHelper + .findAjaxEventBehaviors(linkComponent, "click"); for (AjaxEventBehavior behavior : behaviors) { executeBehavior(behavior); @@ -1959,7 +1912,7 @@ public class BaseWicketTester } else if (linkComponent instanceof ExternalLink) { - ExternalLink externalLink = (ExternalLink) linkComponent; + ExternalLink externalLink = (ExternalLink)linkComponent; String href = externalLink.getDefaultModelObjectAsString(); try { @@ -1969,7 +1922,8 @@ public class BaseWicketTester } catch (IOException iox) { - throw new WicketRuntimeException("An error occurred while redirecting to: " + href, iox); + throw new WicketRuntimeException("An error occurred while redirecting to: " + href, + iox); } } // if the link is a normal link (or ResourceLink) @@ -1986,34 +1940,34 @@ public class BaseWicketTester BookmarkablePageLink<?> bookmarkablePageLink = (BookmarkablePageLink<?>)link; try { - Method getParametersMethod = BookmarkablePageLink.class.getDeclaredMethod( - "getPageParameters", (Class<?>[])null); + Method getParametersMethod = BookmarkablePageLink.class + .getDeclaredMethod("getPageParameters", (Class<?>[])null); getParametersMethod.setAccessible(true); - PageParameters parameters = (PageParameters)getParametersMethod.invoke( - bookmarkablePageLink, (Object[])null); + PageParameters parameters = (PageParameters)getParametersMethod + .invoke(bookmarkablePageLink, (Object[])null); startPage(bookmarkablePageLink.getPageClass(), parameters); } catch (Exception e) { - throw new WicketRuntimeException("Internal error in WicketTester. " - + "Please report this in Wicket's Issue Tracker.", e); + throw new WicketRuntimeException("Internal error in WicketTester. " + + "Please report this in Wicket's Issue Tracker.", e); } } else if (link instanceof ResourceLink) { try { - Method getURL = ResourceLink.class.getDeclaredMethod("getURL", new Class[0]); + Method getURL = ResourceLink.class.getDeclaredMethod("getURL"); getURL.setAccessible(true); CharSequence url = (CharSequence)getURL.invoke(link); executeUrl(url.toString()); } catch (Exception x) { - throw new RuntimeException( - "An error occurred while clicking on a ResourceLink", x); + throw new RuntimeException("An error occurred while clicking on a ResourceLink", + x); } } else @@ -2057,10 +2011,8 @@ public class BaseWicketTester public void submitForm(String path) { Form<?> form = (Form<?>)getComponentFromLastRenderedPage(path); - Url url = Url.parse( - form.getRootForm() - .urlForListener(new PageParameters()) - .toString(), Charset.forName(request.getCharacterEncoding())); + Url url = Url.parse(form.getRootForm().urlForListener(new PageParameters()).toString(), + Charset.forName(request.getCharacterEncoding())); // make url absolute transform(url); @@ -2138,10 +2090,8 @@ public class BaseWicketTester * @param expectedDocument * expected output * @return a <code>Result</code> - * @throws Exception - */ - public Result isResultPage(final String expectedDocument) throws Exception - { + */ + public Result isResultPage(final String expectedDocument) { // Validate the document String document = getLastResponseAsString(); return isTrue("expected rendered page equals", document.equals(expectedDocument)); @@ -2173,16 +2123,15 @@ public class BaseWicketTester * Asserts there are no feedback messages with the given level. * * @param level - * the level of the feedback message + * the level of the feedback message * @return a <code>Result</code> */ public Result hasNoFeedbackMessage(int level) { List<Serializable> messages = getMessages(level); - return isTrue( - String.format("expected no %s message, but contains\n%s", - new FeedbackMessage(null, "", level).getLevelAsString().toLowerCase(Locale.ENGLISH), WicketTesterHelper.asLined(messages)), - messages.isEmpty()); + return isTrue(String.format("expected no %s message, but contains\n%s", + new FeedbackMessage(null, "", level).getLevelAsString().toLowerCase(Locale.ENGLISH), + WicketTesterHelper.asLined(messages)), messages.isEmpty()); } /** @@ -2196,7 +2145,8 @@ public class BaseWicketTester */ public List<Serializable> getMessages(final int level) { - List<FeedbackMessage> messages = getFeedbackMessages(new ExactLevelFeedbackMessageFilter(level)); + List<FeedbackMessage> messages = getFeedbackMessages( + new ExactLevelFeedbackMessageFilter(level)); List<Serializable> actualMessages = Generics.newArrayList(); for (FeedbackMessage message : messages) @@ -2245,11 +2195,13 @@ public class BaseWicketTester public void debugComponentTrees(String filter) { log.info("debugging ----------------------------------------------"); - for (WicketTesterHelper.ComponentData obj : WicketTesterHelper.getComponentData(getLastRenderedPage())) + for (WicketTesterHelper.ComponentData obj : WicketTesterHelper + .getComponentData(getLastRenderedPage())) { if (obj.path.matches(".*" + filter + ".*")) { - log.info("[{}{}] path\t" + obj.path + " \t" + obj.type + " \t[" + obj.value + "]", obj.isEnabled?"E":"-", obj.isVisible?"V":"-"); + log.info("[{}{}] path\t" + obj.path + " \t" + obj.type + " \t[" + obj.value + "]", + obj.isEnabled ? "E" : "-", obj.isVisible ? "V" : "-"); } } } @@ -2279,9 +2231,9 @@ public class BaseWicketTester String componentInfo = component.toString(); if (!component.isVisible()) { - failMessage = "A component which is invisible and doesn't render a placeholder tag" - + " will not be rendered at all and thus won't be accessible for subsequent AJAX interaction. " + - componentInfo; + failMessage = "A component which is invisible and doesn't render a placeholder tag" + + " will not be rendered at all and thus won't be accessible for subsequent AJAX interaction. " + + componentInfo; result = isTrue(failMessage, component.getOutputMarkupPlaceholderTag()); if (result.wasFailed()) { @@ -2293,11 +2245,11 @@ public class BaseWicketTester String ajaxResponse = getLastResponseAsString(); // Test that the previous response was actually a AJAX response - failMessage = "The previous response was not an AJAX response. "+ - "You need to execute an AJAX event, using #clickLink() or " + - "#executeAjaxEvent(), before using this assertion method"; - boolean isAjaxResponse = Pattern.compile( - "^<\\?xml version=\"1.0\" encoding=\".*?\"\\?><ajax-response>") + failMessage = "The previous response was not an AJAX response. " + + "You need to execute an AJAX event, using #clickLink() or " + + "#executeAjaxEvent(), before using this assertion method"; + boolean isAjaxResponse = Pattern + .compile("^<\\?xml version=\"1.0\" encoding=\".*?\"\\?><ajax-response>") .matcher(ajaxResponse) .find(); result = isTrue(failMessage, isAjaxResponse); @@ -2310,8 +2262,7 @@ public class BaseWicketTester String markupId = component.getMarkupId(); failMessage = "The component doesn't have a markup id, " + - "which means that it can't have been added to the AJAX response. " + - componentInfo; + "which means that it can't have been added to the AJAX response. " + componentInfo; result = isTrue(failMessage, !Strings.isEmpty(markupId)); if (result.wasFailed()) { @@ -2319,23 +2270,27 @@ public class BaseWicketTester } // Look for that the component is on the response, using the markup id - boolean isComponentInAjaxResponse = ajaxResponse.matches("(?s).*<component id=\"" + - markupId + "\"[^>]*?>.*"); + boolean isComponentInAjaxResponse = ajaxResponse + .matches("(?s).*<component id=\"" + markupId + "\"[^>]*?>.*"); failMessage = "Component wasn't found in the AJAX response. " + componentInfo; result = isTrue(failMessage, isComponentInAjaxResponse); - if (!result.wasFailed()) { + if (!result.wasFailed()) + { return result; } // Check if the component has been included as part of an enclosure render - Enclosure enclosure = getLastRenderedPage().visitChildren(Enclosure.class, (Enclosure enc, IVisit<Enclosure> visit) -> { - if (AjaxEnclosureListener.isControllerOfEnclosure(component, enc)){ - visit.stop(enc); - } - }); + Enclosure enclosure = getLastRenderedPage().visitChildren(Enclosure.class, + (Enclosure enc, IVisit<Enclosure> visit) -> { + if (AjaxEnclosureListener.isControllerOfEnclosure(component, enc)) + { + visit.stop(enc); + } + }); - if (enclosure == null) { + if (enclosure == null) + { return result; } @@ -2387,7 +2342,8 @@ public class BaseWicketTester private void internalExecuteAllTimerBehaviors(final Component component) { - List<AbstractAjaxTimerBehavior> behaviors = component.getBehaviors(AbstractAjaxTimerBehavior.class); + List<AbstractAjaxTimerBehavior> behaviors = component + .getBehaviors(AbstractAjaxTimerBehavior.class); for (AbstractAjaxTimerBehavior timer : behaviors) { checkUsability(component, true); @@ -2447,8 +2403,8 @@ public class BaseWicketTester checkUsability(component, true); - List<AjaxEventBehavior> ajaxEventBehaviors = WicketTesterHelper.findAjaxEventBehaviors( - component, event); + List<AjaxEventBehavior> ajaxEventBehaviors = WicketTesterHelper + .findAjaxEventBehaviors(component, event); for (AjaxEventBehavior ajaxEventBehavior : ajaxEventBehaviors) { executeBehavior(ajaxEventBehavior); @@ -2696,19 +2652,21 @@ public class BaseWicketTester if (component.isVisibleInHierarchy() == false) { - res = Result.fail("The component is currently not visible in the hierarchy and thus you can not be used." + - " Component: " + component); + res = Result.fail( + "The component is currently not visible in the hierarchy and thus you can not be used." + + " Component: " + component); } if (component.isEnabledInHierarchy() == false) { - res = Result.fail("The component is currently not enabled in the hierarchy and thus you can not be used." + - " Component: " + component); + res = Result.fail( + "The component is currently not enabled in the hierarchy and thus you can not be used." + + " Component: " + component); } if (throwException && res.wasFailed()) { - throw new AssertionFailedError(res.getMessage()); + throw new AssertionError(res.getMessage()); } return res; } @@ -2784,6 +2742,109 @@ public class BaseWicketTester processRequest(); } + /** + * A page that is used as the automatically created page for + * {@link BaseWicketTester#startComponentInPage(Class)} and the other variations. + * <p> + * This page caches the generated markup so that it is available even after + * {@link Component#detach()} where the {@link Component#markup component's markup cache} is + * cleared. + */ + public static class StartComponentInPage extends WebPage + { + private transient IMarkupFragment pageMarkup = null; + + /** + * Construct. + */ + public StartComponentInPage() + { + setStatelessHint(false); + } + + @Override + public IMarkupFragment getMarkup() + { + IMarkupFragment calculatedMarkup = null; + if (pageMarkup == null) + { + IMarkupFragment markup = super.getMarkup(); + if (markup != null && markup != Markup.NO_MARKUP) + { + calculatedMarkup = markup; + pageMarkup = markup; + } + } + else + { + calculatedMarkup = pageMarkup; + } + + return calculatedMarkup; + } + + /** + * @param markup + */ + public void setPageMarkup(IMarkupFragment markup) + { + setMarkup(markup); + pageMarkup = markup; + } + } + + private static class TestPageManagerProvider implements IPageManagerProvider + { + @Override + public IPageManager apply(IPageManagerContext pageManagerContext) + { + return new MockPageManager(); + } + } + + private static class WicketTesterServletWebResponse extends ServletWebResponse + implements + IMetaDataBufferingWebResponse + { + private List<Cookie> cookies = new ArrayList<Cookie>(); + + private WicketTesterServletWebResponse(ServletWebRequest request, + MockHttpServletResponse response) + { + super(request, response); + } + + @Override + public void addCookie(Cookie cookie) + { + super.addCookie(cookie); + cookies.add(cookie); + } + + @Override + public void writeMetaData(WebResponse webResponse) + { + for (Cookie cookie : cookies) + { + webResponse.addCookie(cookie); + } + } + + @Override + public void sendRedirect(String url) + { + super.sendRedirect(url); + try + { + getContainerResponse().sendRedirect(url); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + } + private class LastPageRecordingPageRendererProvider implements IPageRendererProvider { private final IPageRendererProvider delegate; @@ -2809,8 +2870,8 @@ public class BaseWicketTester if (handler.getPageProvider().hasPageInstance()) { Page renderedPage = (Page)handler.getPageProvider().getPageInstance(); - if (componentInPage != null && lastPage != null && renderedPage != null - && lastPage.getPageClass() != renderedPage.getPageClass()) + if (componentInPage != null && lastPage != null && renderedPage != null && + lastPage.getPageClass() != renderedPage.getPageClass()) { // WICKET-3913: reset startComponent if a new page // type is rendered @@ -2919,15 +2980,6 @@ public class BaseWicketTester } } - private static class TestPageManagerProvider implements IPageManagerProvider - { - @Override - public IPageManager apply(IPageManagerContext pageManagerContext) - { - return new MockPageManager(); - } - } - public class TestFilterConfig implements FilterConfig { private final Map<String, String> initParameters = new HashMap<String, String>(); @@ -2961,47 +3013,4 @@ public class BaseWicketTester throw new UnsupportedOperationException("Not implemented"); } } - - private static class WicketTesterServletWebResponse extends ServletWebResponse - implements - IMetaDataBufferingWebResponse - { - private List<Cookie> cookies = new ArrayList<Cookie>(); - - private WicketTesterServletWebResponse(ServletWebRequest request, - MockHttpServletResponse response) - { - super(request, response); - } - - @Override - public void addCookie(Cookie cookie) - { - super.addCookie(cookie); - cookies.add(cookie); - } - - @Override - public void writeMetaData(WebResponse webResponse) - { - for (Cookie cookie : cookies) - { - webResponse.addCookie(cookie); - } - } - - @Override - public void sendRedirect(String url) - { - super.sendRedirect(url); - try - { - getContainerResponse().sendRedirect(url); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - } - } } http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java index 7420526..dc352b6 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java @@ -18,14 +18,15 @@ package org.apache.wicket.util.tester; 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.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; + import javax.servlet.ServletContext; import org.apache.commons.collections4.CollectionUtils; @@ -50,7 +51,6 @@ import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.lang.Objects; -import org.opentest4j.AssertionFailedError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -283,21 +283,19 @@ public class WicketTester extends BaseWicketTester { if (null != getLastResponse().getHeader("Location")) { - throw new AssertionFailedError( - "Location header should *not* be present when using Ajax"); + fail("Location header should *not* be present when using Ajax"); } String ajaxLocation = getLastResponse().getHeader("Ajax-Location"); if (null == ajaxLocation) { - throw new AssertionFailedError( - "Ajax-Location header should be present when using Ajax"); + fail("Ajax-Location header should be present when using Ajax"); } int statusCode = getLastResponse().getStatus(); if (statusCode != 200) { - throw new AssertionFailedError("Expected HTTP status code to be 200 (OK)"); + fail("Expected HTTP status code to be 200 (OK)"); } } @@ -479,7 +477,7 @@ public class WicketTester extends BaseWicketTester if (markup == null) { - throw new AssertionFailedError(String.format("Cannot find the markup of component: %s", + fail(String.format("Cannot find the markup of component: %s", component.getPageRelativePath())); } @@ -599,12 +597,12 @@ public class WicketTester extends BaseWicketTester final List<FeedbackMessage> renderedMessages = model.getObject(); if (renderedMessages == null) { - throw new AssertionFailedError( + fail( String.format("feedback panel at path [%s] returned null messages", path)); } if (messages.length != renderedMessages.size()) { - throw new AssertionFailedError(String.format( + fail(String.format( "you expected '%d' messages for the feedback panel [%s], but there were actually '%d'", messages.length, path, renderedMessages.size())); } @@ -748,10 +746,8 @@ public class WicketTester extends BaseWicketTester * * @param expectedDocument * expected output <code>String</code> - * @throws Exception */ - public void assertResultPage(final String expectedDocument) throws Exception - { + public void assertResultPage(final String expectedDocument) { // Validate the document String document = getLastResponseAsString(); assertEquals(expectedDocument, document); @@ -821,7 +817,7 @@ public class WicketTester extends BaseWicketTester { if (result.wasFailed()) { - throw new AssertionFailedError(result.getMessage()); + fail(result.getMessage()); } } @@ -962,7 +958,7 @@ public class WicketTester extends BaseWicketTester public void executeListener(final Class<?> testClass, final Component component, final String filename) throws Exception { - assertNotNull(component); + assert(component != null); log.info("=== " + testClass.getName() + " : " + component.getPageRelativePath() + " ==="); @@ -980,7 +976,7 @@ public class WicketTester extends BaseWicketTester public void executeBehavior(final Class<?> testClass, final AbstractAjaxBehavior behavior, final String filename) throws Exception { - assertNotNull(behavior); + assert(behavior != null); log.info("=== " + testClass.getName() + " : " + behavior.toString() + " ==="); http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-core/src/test/java/org/apache/wicket/TesterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/TesterTest.java b/wicket-core/src/test/java/org/apache/wicket/TesterTest.java index 3258c33..692324d 100644 --- a/wicket-core/src/test/java/org/apache/wicket/TesterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/TesterTest.java @@ -22,7 +22,7 @@ import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.util.tester.WicketTestCase; import org.junit.jupiter.api.Test; -import org.opentest4j.AssertionFailedError; + /** * @author jcompagner @@ -42,7 +42,7 @@ class TesterTest extends WicketTestCase tester.assertVisible("label"); fail("Should fail, because label is invisible"); } - catch (AssertionFailedError e) + catch (AssertionError e) { } catch (NullPointerException e) http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java index 882c39d..5956c33 100644 --- a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java @@ -42,7 +42,7 @@ import org.apache.wicket.request.http.WebRequest; import org.apache.wicket.request.http.WebResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.opentest4j.AssertionFailedError; + /** * Tests for the calculation whether or not to redirect or directly render a page @@ -397,7 +397,7 @@ class WebPageRendererTest renderer.redirectToRender = true; when(provider.getPageInstance()).thenThrow( - new AssertionFailedError("no page instance should be created")); + new AssertionError("no page instance should be created")); when(urlRenderer.getBaseUrl()).thenReturn(Url.parse("a")); http://git-wip-us.apache.org/repos/asf/wicket/blob/0b48f270/wicket-devutils/src/test/java/org/apache/wicket/devutils/inspector/SessionSizeModelTest.java ---------------------------------------------------------------------- diff --git a/wicket-devutils/src/test/java/org/apache/wicket/devutils/inspector/SessionSizeModelTest.java b/wicket-devutils/src/test/java/org/apache/wicket/devutils/inspector/SessionSizeModelTest.java index af5b583..6510171 100644 --- a/wicket-devutils/src/test/java/org/apache/wicket/devutils/inspector/SessionSizeModelTest.java +++ b/wicket-devutils/src/test/java/org/apache/wicket/devutils/inspector/SessionSizeModelTest.java @@ -16,19 +16,20 @@ */ package org.apache.wicket.devutils.inspector; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.wicket.Session; import org.apache.wicket.mock.MockApplication; import org.apache.wicket.protocol.http.WebSession; import org.apache.wicket.request.Request; import org.apache.wicket.request.Response; import org.apache.wicket.util.tester.WicketTester; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Pedro Santos */ -public class SessionSizeModelTest extends Assert +public class SessionSizeModelTest { /**
