http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/TestWicketJavaEEApplication.java
----------------------------------------------------------------------
diff --git 
a/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/TestWicketJavaEEApplication.java
 
b/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/TestWicketJavaEEApplication.java
deleted file mode 100644
index da90dcf..0000000
--- 
a/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/TestWicketJavaEEApplication.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
- * contributors by the @authors tag. See the copyright.txt in the
- * distribution for a full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.as.quickstarts.wicketWar;
-
-import org.apache.wicket.util.file.IResourceFinder;
-import org.jboss.as.quickstarts.wicketWar.util.ResourceWebApplicationPath;
-
-/**
- * Just extends the Application to add some needs.
- * 
- * @author felipecalmeida
- * @since 06/20/2015
- */
-public class TestWicketJavaEEApplication extends WicketJavaEEApplication {
-  
-       // Has some security ignores during the test (example: accept all 
roles).
-       
-       @Override
-    protected IResourceFinder getResourceFinder() {
-       return new 
ResourceWebApplicationPath(TestWicketJavaEEApplication.class.getPackage().getName(),
 getServletContext());
-    }
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContactTest.java
----------------------------------------------------------------------
diff --git 
a/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContactTest.java
 
b/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContactTest.java
deleted file mode 100644
index c7a6631..0000000
--- 
a/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContactTest.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * 
- */
-package org.jboss.as.quickstarts.wicketWar.pages;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.servlet.ServletContext;
-
-import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.util.tester.WicketTester;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.as.quickstarts.wicketWar.TestWicketJavaEEApplication;
-import org.jboss.as.quickstarts.wicketWar.WicketJavaEEApplication;
-import org.jboss.shrinkwrap.api.Filters;
-import org.jboss.shrinkwrap.api.GenericArchive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
-import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-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>
- * 
- * @author felipecalmeida
- * @since 06/21/2015
- *
- */
-@RunWith(Arquillian.class)
-public class InsertContactTest {
-       
-       /** log. */
-       private static final Logger log = 
LoggerFactory.getLogger(InsertContactTest.class);
-       
-       private static final String WEBAPP_SRC = "src/main/webapp";
-       private static final String WEBAPP_TEST_SRC = "src/test/webapp";
-
-       @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);
-               
-               // Create webapptest files from src/test/webapp. (TEST)
-               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()
-                               // I'm not using internet directly, I have a 
Nexus Repository that handles the libs for me.
-                               .workOffline().withMavenCentralRepo(false)
-                               // 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-servletContext.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);
-       }
-       
-       private WicketTester wicketTester;
-
-       private ServletContext servletContext;
-       
-//     private String basePath = 
TestWicketJavaEEApplication.class.getPackage().getName().replaceAll("\\.", 
"\\/");
-       
-       @After
-       public void tearDown() throws Exception {
-               if(wicketTester != null && wicketTester.getApplication() != 
null) {
-                       wicketTester.getApplication().internalDestroy();
-               }
-       }
-
-       @Test
-       public void testFindResources(){
-               WebApplication webApplication = useServletContextContainer();
-               
-               // USING CONTAINER'S SERVLET.
-               testFindResourcesServletContext(servletContext);
-               
-               reuseServletContextFromContainerOrCreateMock(webApplication);
-               
-               // USING MOCK.
-               testFindResourcesServletContextMock(wicketTester);
-               
-       }
-
-       /**
-        * Loading the TestWicketJavaEEApplication from 
src/test/webapp/WEB-INF/web.xml.
-        * 
-        * @return
-        */
-       private WebApplication useServletContextContainer() {
-               WebApplication webApplication = null;
-               try {
-                       webApplication = TestWicketJavaEEApplication.get();
-               } catch (Exception e) {
-                       log.error("IF NOT USING ARQUILLIAN, 
org.apache.wicket.Application has a message for you " + e.getMessage());
-                       // DIDN'T TEST THIS, 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 = webApplication.getServletContext();
-               assertNotNull(servletContext);
-               log.info("ServletContext Name: " + 
servletContext.getServletContextName());
-               assertEquals("WildFly Quickstart: Wicket TEST 
WAR",servletContext.getServletContextName());
-               
-               log.info("Server info: " + servletContext.getServerInfo());
-               return webApplication;
-       }
-
-       /**
-        * Trying to use ServletContext from Container.
-        * 
-        * @param webApplication
-        */
-       private void 
reuseServletContextFromContainerOrCreateMock(WebApplication webApplication) {
-               try {
-                       log.info("TRYING TO REUSE CONTAINER'S 
SERVLETCONTEXT/FILTER.");
-                       wicketTester = new WicketTester(webApplication);
-                       assertNotNull(wicketTester.getApplication());
-                       log.info("USING CONTAINER'S SERVLETCONTEXT/FILTER.");
-                       log.info("WebApplication after wicketTester Name: " + 
wicketTester.getApplication().getName());
-                       log.info("ServletContext after wicketTester Name: " + 
wicketTester.getServletContext().getServletContextName());
-                       log.info("Server info: " + 
wicketTester.getServletContext().getServerInfo());
-               } catch (IllegalStateException e) {
-                       assertEquals("Application name can only be set 
once.",e.getMessage());
-                       log.error("CANNOT USE CONTAINER'S SERVLETCONTEXT.\n", 
e);
-               }
-               if(wicketTester == null){
-                       try {
-                               wicketTester = new WicketTester(new 
TestWicketJavaEEApplication());
-                               assertNotNull(wicketTester.getApplication());
-                               log.info("USING A MOCK SERVLETCONTEXT.");
-                               log.info("WebApplication MOCK after 
wicketTester Name: " + wicketTester.getApplication().getName());
-                               log.info("ServletContext MOCK after 
wicketTester Name: " + 
wicketTester.getServletContext().getServletContextName());
-                               log.info("Server info: " + 
wicketTester.getServletContext().getServerInfo());
-                               assertEquals("Wicket Mock Test Environment 
v1.0", wicketTester.getServletContext().getServerInfo());
-                       } catch (IllegalStateException e) {
-                               // I DON'T KNOW WHAT OR IF COULD CAUSE THIS.
-                               log.error("CANNOT USE A MOCK SERVLETCONTEXT.");
-//                             assertEquals("Application name can only be set 
once.",e.getMessage());
-                       }
-               }
-       }
-       
-       /**
-        * Using mock.
-        * 
-        * @param wicketTester
-        */
-       private void testFindResourcesServletContextMock(WicketTester 
wicketTester) {
-               
testFindResourcesServletContext(wicketTester.getServletContext());
-       }
-       
-       /**
-        * Look for resources (like html, js, css, img, etc).
-        * 
-        * @param servletContext
-        */
-       private void testFindResourcesServletContext(ServletContext 
servletContext) {
-               try {
-                       // Doing the same thing that ResourceWebApplicationPath 
does.
-                       URL resource = 
servletContext.getResource("/pages/InsertContact.html");
-                       if(resource == null) {
-                               throw new MalformedURLException("Resource 
/pages/InsertContact.html not found.");
-                       }
-                       log.info("RESOURCE FOUND " + resource.getFile());
-                       
assertTrue(resource.getFile().contains("/pages/InsertContact.html"));
-               } catch (Exception e) {
-                       assertEquals("Resource /pages/InsertContact.html not 
found.", e.getMessage());
-                       log.error("RESOURCE CANNOT BE FOUND.", e);
-               }
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/testing/wicket-arquillian/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/testing/wicket-arquillian/src/test/resources/arquillian.xml 
b/testing/wicket-arquillian/src/test/resources/arquillian.xml
index 6ae0d20..cca5a0c 100644
--- a/testing/wicket-arquillian/src/test/resources/arquillian.xml
+++ b/testing/wicket-arquillian/src/test/resources/arquillian.xml
@@ -11,9 +11,7 @@
     <container qualifier="wildfly" default="true">
        <configuration>
                <property name="jbossHome">target/wildfly-8.1.0.Final</property>
-            <!-- JDK before 8: -XX:MaxPermSize=128m -XX -->
-            <!-- JDK 8 and later: -XX:MaxMetaspaceSize=128m -->
-            <!-- DEBUG MODE MANAGED: 
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y -->
+            <!-- DEBUG MODE MANAGED: 
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n -->
                <property name="javaVmArguments">-Xmx128m -XX:MaxPermSize=128m 
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
             </property>
        </configuration>

http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml 
b/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml
index b52ea2a..4266a83 100644
--- a/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml
+++ b/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml
@@ -13,7 +13,7 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";>
 
-       <display-name>WildFly Quickstart: Wicket TEST WAR</display-name>
+       <display-name>Wicket Arquillian WildFly Quickstart: Wicket TEST 
WAR</display-name>
 
        <!-- Enable Wicket -->
        <filter>
@@ -22,7 +22,7 @@
                <init-param>
                        <!-- Specify the "entry point" for Wicket to configure 
itself from -->
                        <param-name>applicationClassName</param-name>
-                       
<param-value>org.jboss.as.quickstarts.wicketWar.TestWicketJavaEEApplication</param-value>
+                       
<param-value>org.apache.wicket.arquillian.testing.TestWicketJavaEEApplication</param-value>
                </init-param>
        </filter>
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/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 f94305c..74b5309 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
@@ -137,6 +137,7 @@ 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.junit.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -253,7 +254,7 @@ public class BaseWicketTester
        }
 
        /**
-        * Creates a <code>WicketTester</code>.
+        * Creates a <code>WicketTester</code>. Constructor to keep 
compatibility.
         * 
         * @param application
         *            a <code>WicketTester</code> <code>WebApplication</code> 
object
@@ -262,20 +263,59 @@ public class BaseWicketTester
         */
        public BaseWicketTester(final WebApplication application, final 
ServletContext servletCtx)
        {
+               this(application, servletCtx, true);
+       }
+       
+       /**
+        * Creates a <code>WicketTester</code>.
+        * 
+        * @param application
+        *            a <code>WicketTester</code> <code>WebApplication</code> 
object
+        * @param init
+        *            force the application to be initialized (default = true)
+        */
+       public BaseWicketTester(final WebApplication application, boolean init)
+       {
+               this(application, null, init);
+       }
+       
+       /**
+        * Creates a <code>WicketTester</code>.
+        * 
+        * @param application
+        *            a <code>WicketTester</code> <code>WebApplication</code> 
object
+        * @param servletCtx
+        *            the servlet context used as backend
+        * @param init
+        *            force the application to be initialized (default = true)
+        */
+       public BaseWicketTester(final WebApplication application, final 
ServletContext servletCtx, boolean init)
+       {
+               // Assert the application is not null.
+               if(!init)
+               {
+                       Assert.assertNotNull("WebApplication cannot be 
null",application);
+               }
+               
                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);
-
-               final FilterConfig filterConfig = new TestFilterConfig();
-               WicketFilter filter = new WicketFilter()
+               
+               // If using Arquillian and it's configured in a web.xml it'll 
be provided. If not, mock it.
+               if(application.getWicketFilter() == null)
                {
-                       @Override
-                       public FilterConfig getFilterConfig()
+                       final FilterConfig filterConfig = new 
TestFilterConfig();
+                       WicketFilter filter = new WicketFilter()
                        {
-                               return filterConfig;
-                       }
-               };
-
-               application.setWicketFilter(filter);
+                               @Override
+                               public FilterConfig getFilterConfig()
+                               {
+                                       return filterConfig;
+                               }
+                       };
+                       application.setWicketFilter(filter);
+               }
 
                httpSession = new MockHttpSession(servletContext);
 
@@ -283,15 +323,23 @@ public class BaseWicketTester
 
                this.application = application;
 
-               // FIXME some tests are leaking applications by not calling 
destroy on them or overriding
-               // teardown() without calling super, for now we work around by 
making each name unique
-               application.setName("WicketTesterApplication-" + 
UUID.randomUUID());
+               // If it's provided from the container it's not necessary to 
set again.
+               if(init)
+               {
+                       // FIXME some tests are leaking applications by not 
calling destroy on them or overriding
+                       // teardown() without calling super, for now we work 
around by making each name unique
+                       application.setName("WicketTesterApplication-" + 
UUID.randomUUID());
+               }
+               
                ThreadContext.setApplication(application);
 
-               application.setServletContext(servletContext);
-
-               // initialize the application
-               application.initApplication();
+               // If it's provided from the container it's not necessary to 
set again and init.
+               if(init)
+               {
+                       application.setServletContext(servletContext);
+                       // initialize the application
+                       application.initApplication();
+               }
 
                // We don't expect any changes during testing. In addition we 
avoid creating
                // ModificationWatcher threads tests.

http://git-wip-us.apache.org/repos/asf/wicket/blob/af093ab1/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 e860574..886a092 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
@@ -221,7 +221,7 @@ public class WicketTester extends BaseWicketTester
        }
 
        /**
-        * Creates a <code>WicketTester</code> to help unit testing.
+        * Creates a <code>WicketTester</code> to help unit testing. 
Constructor to keep compatibility.
         * 
         * @param application
         *            a <code>WicketTester</code> <code>WebApplication</code> 
object
@@ -232,6 +232,34 @@ public class WicketTester extends BaseWicketTester
        {
                super(application, servletCtx);
        }
+       
+       /**
+        * Creates a <code>WicketTester</code> to help unit testing.
+        * 
+        * @param application
+        *            a <code>WicketTester</code> <code>WebApplication</code> 
object
+        * @param init
+        *            force the application to be initialized (default = true)
+        */
+       public WicketTester(WebApplication application, boolean init)
+       {
+               super(application, init);
+       }
+       
+       /**
+        * Creates a <code>WicketTester</code> to help unit testing.
+        * 
+        * @param application
+        *            a <code>WicketTester</code> <code>WebApplication</code> 
object
+        * @param servletCtx
+        *            the servlet context used as backend
+        * @param init
+        *            force the application to be initialized (default = true)
+        */
+       public WicketTester(WebApplication application, ServletContext 
servletCtx, boolean init)
+       {
+               super(application, servletCtx, init);
+       }
 
        /**
         * Asserts that the Ajax location header is present.

Reply via email to