Repository: wicket Updated Branches: refs/heads/master 3e63e97c5 -> ea1dc12e4
Example to run Arquillian with Wicket. I'm using Wildfly example from https://github.com/wildfly/quickstart/tree/master/wicket-war Made some modifications and added an Arquillian Test configured and running, everything passing, and has some LOG to help to understand. To run for the first time just type: mvn install Then mvn test. Import to Eclipse (or any IDE), and run the example inside, to debug, has to run the test normally and connect as remote. Not necessary to download any Application Server, the maven plugin already do this for you (It's managed). Signed-off-by: Felipe C Almeida <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/11b458bc Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/11b458bc Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/11b458bc Branch: refs/heads/master Commit: 11b458bc303a75b071acbdd1593dca657da1ee8e Parents: 5b13f0a Author: Felipe C <[email protected]> Authored: Sun Jun 21 03:08:56 2015 -0300 Committer: Felipe C <[email protected]> Committed: Sun Jun 21 03:08:56 2015 -0300 ---------------------------------------------------------------------- testing/wicket-arquillian/README.md | 89 +++++ testing/wicket-arquillian/pom.xml | 345 +++++++++++++++++++ .../wicketWar/WicketJavaEEApplication.java | 70 ++++ .../quickstarts/wicketWar/dao/ContactDao.java | 61 ++++ .../wicketWar/dao/ContactDaoBean.java | 69 ++++ .../as/quickstarts/wicketWar/model/Contact.java | 104 ++++++ .../wicketWar/pages/InsertContact.java | 82 +++++ .../wicketWar/pages/ListContacts.java | 70 ++++ .../util/ResourceWebApplicationPath.java | 98 ++++++ .../src/main/resources/META-INF/MANIFEST.MF | 1 + .../src/main/resources/META-INF/persistence.xml | 35 ++ .../src/main/webapp/WEB-INF/beans.xml | 25 ++ .../src/main/webapp/WEB-INF/faces-config.xml | 9 + .../src/main/webapp/WEB-INF/web.xml | 49 +++ .../webapp/WEB-INF/wicket-quickstart-ds.xml | 37 ++ .../src/main/webapp/pages/InsertContact.html | 41 +++ .../src/main/webapp/pages/ListContacts.html | 43 +++ .../wicketWar/TestWicketJavaEEApplication.java | 36 ++ .../wicketWar/pages/InsertContactTest.java | 207 +++++++++++ .../src/test/resources/arquillian.xml | 22 ++ .../src/test/webapp/WEB-INF/web.xml | 42 +++ 21 files changed, 1535 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/README.md ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/README.md b/testing/wicket-arquillian/README.md new file mode 100644 index 0000000..6e17c0b --- /dev/null +++ b/testing/wicket-arquillian/README.md @@ -0,0 +1,89 @@ +wicket-war: Wicket Framework used in a WAR. +=========================================== +Author: Ondrej Zizka <[email protected]> +Level: Intermediate +Technologies: Apache Wicket, JPA +Summary: Demonstrates how to use the Wicket Framework 1.5 with the JBoss server using the Wicket-Stuff Java EE integration packaged as a WAR +Target Project: WildFly +Source: <https://github.com/wildfly/quickstart/> + +What is it? +----------- + +This is an example of how to use Wicket Framework 1.5 with WildFly, leveraging features of Java EE 7, using the Wicket-Stuff Java EE integration. + +Features used: + + * Injection of `@PersistenceContext` + * Injection of a value from `web.xml` using `@Resource` + * Injection of a stateless session bean using `@EJB` + +This is a WAR version. + + +System requirements +------------------- + +All you need to build this project is Java 7.0 (Java SDK 1.7) or better, Maven 3.1 or better. + +The application this project produces is designed to be run on JBoss WildFly. + + +Configure Maven +--------------- + +If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts. + + +Start JBoss WildFly with the Web Profile +------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line to start the server with the web profile: + + For Linux: JBOSS_HOME/bin/standalone.sh + For Windows: JBOSS_HOME\bin\standalone.bat + + + +Build and Deploy the Quickstart +------------------------- + +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._ + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive: + + mvn clean package wildfly:deploy + +4. This will deploy `target/wildfly-wicket-war.war` to the running instance of the server. + + + +Access the application +---------------------- + +Access the running application in a browser at the following URL: <http://localhost:8080/wildfly-wicket-war> + +You will see a page with a table listing user entities. Initially, this table is empty. By clicking a link, you can add more users. + + +Undeploy the Archive +-------------------- + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive: + + mvn wildfly:undeploy + + +Debug the Application +------------------------------------ + +If you want to debug the source code or look at the Javadocs of any library in the project, +run either of the following commands to pull them into your local repository. The IDE should then detect them. + + mvn dependency:sources + mvn dependency:resolve -Dclassifier=javadoc http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/pom.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/pom.xml b/testing/wicket-arquillian/pom.xml new file mode 100644 index 0000000..0c8d4fc --- /dev/null +++ b/testing/wicket-arquillian/pom.xml @@ -0,0 +1,345 @@ +<?xml version="1.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. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.wildfly.quickstarts</groupId> + <artifactId>wildfly-arquillian-wicket-war</artifactId> + <version>8.0.0-SNAPSHOT</version> + <packaging>war</packaging> + + <name>WildFly Quickstarts: Wicket: WAR</name> + <licenses> + <license> + <name>Apache License, Version 2.0</name> + <distribution>repo</distribution> + <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> + </license> + </licenses> + + <description> + A sample JAVA EE 6 project demonstrating how to use Wicket Framework with JBoss WildFly. + WAR version (everything in a single .war file). + </description> + + + <properties> + <!-- Explicitly declaring the source encoding eliminates the following + message: --> + <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered + resources, i.e. build is platform dependent! --> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + + <!-- JBoss dependency versions --> + + <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin> + + <version.jboss.spec.javaee.7.0>3.0.2.Final</version.jboss.spec.javaee.7.0> + + + <!-- Other dependency versions --> + <version.org.apache.wicket>1.5.5</version.org.apache.wicket> + <version.net.ftlines.wicket-cdi>1.2</version.net.ftlines.wicket-cdi> + + <!-- other plugin versions --> + <version.compiler.plugin>3.1</version.compiler.plugin> + <version.war.plugin>2.1.1</version.war.plugin> + + <!-- maven-compiler-plugin --> + <maven.compiler.target>1.7</maven.compiler.target> + <maven.compiler.source>1.7</maven.compiler.source> + + <version.shrinkwrap.resolvers>2.1.1</version.shrinkwrap.resolvers> + <version.arquillian_core>1.0.3.Final</version.arquillian_core> + <version.jbossas_7>8.1.0.Final</version.jbossas_7> + <version.junit>4.8.1</version.junit> + </properties> + + <dependencyManagement> + <dependencies> + <!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill + of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) + of artifacts. We use this here so that we always get the correct versions + of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can + read this as the JBoss stack of the Java EE 7 APIs, with some extras tools + for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate + stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras + from the Hibernate family of projects) --> + <dependency> + <groupId>org.jboss.spec</groupId> + <artifactId>jboss-javaee-6.0</artifactId> + <version>${version.jboss.spec.javaee.7.0}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + + <!-- Wicket --> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket-core</artifactId> + <version>${version.org.apache.wicket}</version> + </dependency> + + <!-- Wicket Java EE integration. --> + <dependency> + <groupId>net.ftlines.wicket-cdi</groupId> + <artifactId>wicket-cdi</artifactId> + <version>${version.net.ftlines.wicket-cdi}</version> + </dependency> + + <!-- Arquillian --> + <!-- Override dependency resolver with latest version. This must go *BEFORE* + the Arquillian BOM. --> + <dependency> + <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-bom</artifactId> + <version>${version.shrinkwrap.resolvers}</version> + <scope>import</scope> + <type>pom</type> + </dependency> + <dependency> + <groupId>org.jboss.arquillian</groupId> + <artifactId>arquillian-bom</artifactId> + <version>${version.arquillian_core}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-container-test-impl-base</artifactId> + <version>${version.arquillian_core}</version> + <classifier>tests</classifier> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.core</groupId> + <artifactId>arquillian-core-impl-base</artifactId> + <version>${version.arquillian_core}</version> + <classifier>tests</classifier> + </dependency> + </dependencies> + </dependencyManagement> + + <!-- Dependencies. --> + + <dependencies> + <!-- "provided" scope used for API's included in JBoss WildFly. --> + + <!-- Import the CDI API. --> + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the Common Annotations API (JSR-250). --> + <dependency> + <groupId>org.jboss.spec.javax.annotation</groupId> + <artifactId>jboss-annotations-api_1.1_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the EJB API. --> + <dependency> + <groupId>org.jboss.spec.javax.ejb</groupId> + <artifactId>jboss-ejb-api_3.1_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the JPA API. --> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Servlet --> + <dependency> + <groupId>org.jboss.spec.javax.servlet</groupId> + <artifactId>jboss-servlet-api_3.0_spec</artifactId> + </dependency> + + <!-- Wicket --> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket-core</artifactId> + </dependency> + + <!-- Wicket CDI integration. --> + <dependency> + <groupId>net.ftlines.wicket-cdi</groupId> + <artifactId>wicket-cdi</artifactId> + </dependency> + + <!-- Shrinkwrap --> + <dependency> + <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-depchain</artifactId> + <!-- <version>${version.shrinkwrap.resolvers}</version> --> + <scope>test</scope> + <type>pom</type> + </dependency> + <!-- <dependency> <groupId>org.jboss.shrinkwrap</groupId> <artifactId>shrinkwrap-api</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.shrinkwrap</groupId> + <artifactId>shrinkwrap-spi</artifactId> <scope>test</scope> </dependency> + <dependency> <groupId>org.jboss.shrinkwrap</groupId> <artifactId>shrinkwrap-impl-base</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-api</artifactId> <scope>test</scope> </dependency> + <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> <artifactId>shrinkwrap-resolver-api-maven</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-impl-maven</artifactId> <scope>test</scope> + </dependency> --> + + <!-- Arquillian Test Harness --> + <dependency> + <groupId>org.jboss.arquillian.core</groupId> + <artifactId>arquillian-core-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.core</groupId> + <artifactId>arquillian-core-spi</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.test</groupId> + <artifactId>arquillian-test-spi</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-container-spi</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-container-test-spi</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-container-test-impl-base</artifactId> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.core</groupId> + <artifactId>arquillian-core-impl-base</artifactId> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${version.junit}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.wildfly</groupId> + <artifactId>wildfly-arquillian-container-managed</artifactId> + <version>${version.jbossas_7}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <!-- Set the name of the war, used as the context root when the app is + deployed. --> + <finalName>${project.artifactId}</finalName> + + <!-- Allow packaging the html files alongside the java sources --> + <!-- <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> + </resource> <resource> <directory>src/main/java</directory> <filtering>true</filtering> + <includes> <include>**</include> </includes> <excludes> <exclude>**/*.java</exclude> + </excludes> </resource> </resources> --> + <!-- <testResources> <testResource> <directory>src/test/resources</directory> + <filtering>true</filtering> </testResource> <testResource> <directory>src/test/java</directory> + <filtering>true</filtering> <includes> <include>**</include> </includes> + <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> --> + + <plugins> + <!-- WildFly plugin to deploy the war --> + <plugin> + <groupId>org.wildfly.plugins</groupId> + <artifactId>wildfly-maven-plugin</artifactId> + <version>${version.wildfly.maven.plugin}</version> + <configuration> + <fileNames> + <fileName>target/${build.finalName}.war</fileName> + </fileNames> + </configuration> + </plugin> + <!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation + processors --> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>${version.compiler.plugin}</version> + <configuration> + <source>${maven.compiler.source}</source> + <target>${maven.compiler.target}</target> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.12.4</version> + <configuration> + <environmentVariables> + <JBOSS_HOME>${project.build.directory}/wildfly-${version.jbossas_7}</JBOSS_HOME> + </environmentVariables> + <systemProperties> + <jboss.version>${version.jbossas_7}</jboss.version> + </systemProperties> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack</id> + <phase>process-test-classes</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.wildfly</groupId> + <artifactId>wildfly-dist</artifactId> + <version>${version.jbossas_7}</version> + <type>zip</type> + <overWrite>true</overWrite> + <outputDirectory>${project.build.directory}</outputDirectory> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> + http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/WicketJavaEEApplication.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/WicketJavaEEApplication.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/WicketJavaEEApplication.java new file mode 100644 index 0000000..a91c104 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/WicketJavaEEApplication.java @@ -0,0 +1,70 @@ +/* + * 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 static net.ftlines.wicket.cdi.ConversationPropagation.NONE; + +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import net.ftlines.wicket.cdi.CdiConfiguration; + +import org.apache.wicket.Page; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.util.file.IResourceFinder; +import org.jboss.as.quickstarts.wicketWar.pages.InsertContact; +import org.jboss.as.quickstarts.wicketWar.pages.ListContacts; +import org.jboss.as.quickstarts.wicketWar.util.ResourceWebApplicationPath; + + +/** + * + * @author Ondrej Zizka + */ +public class WicketJavaEEApplication extends WebApplication { + + @Override + public Class<? extends Page> getHomePage() { + return ListContacts.class; + } + + @Override + protected void init() { + super.init(); + + // Enable CDI + BeanManager bm; + try { + bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); + } catch (NamingException e) { + throw new IllegalStateException("Unable to obtain CDI BeanManager", e); + } + + // Configure CDI, disabling Conversations as we aren't using them + new CdiConfiguration(bm).setPropagation(NONE).configure(this); + + // Mount the InsertContact page at /insert + mountPage("/insert", InsertContact.class); + } + + @Override + protected IResourceFinder getResourceFinder() { + return new ResourceWebApplicationPath(WicketJavaEEApplication.class.getPackage().getName(), getServletContext()); + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDao.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDao.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDao.java new file mode 100644 index 0000000..78d7003 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDao.java @@ -0,0 +1,61 @@ +/* + * 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.dao; + +import java.util.List; + +import javax.ejb.Local; + +import org.jboss.as.quickstarts.wicketWar.model.Contact; + +/** + * + * @author Filippo Diotalevi + */ +@Local +public interface ContactDao { + + /** + * Returns the currently available contacts. + * + * @return every contact in the database + */ + public List<Contact> getContacts(); + + /** + * Returns a specific Contact from DB. + * + * @param id The Id for the Contact + * @return The specified Contact object + */ + public Contact getContact(Long id); + + /** + * Persist a new Contact in the DB. + * + * @param name The name of the new Contact + * @param email The e-mail address of the new Contact + */ + public void addContact(String name, String email); + + /** + * Removes a specific item from the DB. + * + * @param modelObject The specific Contact object, which we wants to remove + */ + public void remove(Contact modelObject); +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDaoBean.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDaoBean.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDaoBean.java new file mode 100644 index 0000000..25fb2d1 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/dao/ContactDaoBean.java @@ -0,0 +1,69 @@ +/* + * 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.dao; + +import java.util.List; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.jboss.as.quickstarts.wicketWar.model.Contact; + +/** + * A bean which manages Contact entities. + */ +@Stateless +public class ContactDaoBean implements ContactDao { + + @PersistenceContext + private EntityManager em; + + + @Override + @SuppressWarnings("unchecked") + public List<Contact> getContacts() { + return em.createQuery("SELECT c FROM Contact c").getResultList(); + } + + /** + * Get Contact by ID. + */ + @Override + public Contact getContact(Long id) { + return em.find(Contact.class, id); + } + + /** + * Add a new Contact. + */ + @Override + public void addContact(String name, String email) { + em.merge(new Contact(null, name, email)); + } + + /** + * Remove a Contact. + */ + @Override + public void remove(Contact modelObject) { + Contact managed = em.merge(modelObject); + em.remove(managed); + em.flush(); + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/model/Contact.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/model/Contact.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/model/Contact.java new file mode 100644 index 0000000..152b777 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/model/Contact.java @@ -0,0 +1,104 @@ +/* + * 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.model; + +import static javax.persistence.GenerationType.IDENTITY; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + + +/** + * + * @author Filippo Diotalevi + */ +@SuppressWarnings("serial") +@Entity +public class Contact implements Serializable { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + private String name; + + @Column(unique=true) + private String email; + + public Contact() { + } + + public Contact(Long id, String name, String email) { + this.id = id; + this.name = name; + this.email = email; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Contact other = (Contact) obj; + if (email == null) { + if (other.email != null) + return false; + } else if (!email.equals(other.email)) + return false; + return true; + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContact.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContact.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContact.java new file mode 100644 index 0000000..ce7c692 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContact.java @@ -0,0 +1,82 @@ +/* + * 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.pages; + +import javax.inject.Inject; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.RequiredTextField; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.PropertyModel; +import org.jboss.as.quickstarts.wicketWar.dao.ContactDao; +import org.jboss.as.quickstarts.wicketWar.model.Contact; + +/** + * + * @author Filippo Diotalevi + */ +@SuppressWarnings("serial") +public class InsertContact extends WebPage { + + private Form<Contact> insertForm; + + private String name; + + private String email; + + @Inject + private ContactDao contactDao; + + + public InsertContact() { + add(new FeedbackPanel("feedback")); + + insertForm = new Form<Contact>("insertForm") { + + @Override + protected void onSubmit() { + contactDao.addContact(name, email); + setResponsePage(ListContacts.class); + } + }; + + insertForm.add(new RequiredTextField<String>("name", + new PropertyModel<String>(this, "name"))); + insertForm.add(new RequiredTextField<String>("email", new PropertyModel<String>(this, + "email"))); + add(insertForm); + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/ListContacts.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/ListContacts.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/ListContacts.java new file mode 100644 index 0000000..fe86ce1 --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/pages/ListContacts.java @@ -0,0 +1,70 @@ +/* + * 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.pages; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.jboss.as.quickstarts.wicketWar.dao.ContactDao; +import org.jboss.as.quickstarts.wicketWar.model.Contact; + +/** + * Dynamic behavior for the ListContact page + * + * @author Filippo Diotalevi + */ +@SuppressWarnings("serial") +public class ListContacts extends WebPage { + + // Inject the ContactDao using @Inject + @Inject + private ContactDao contactDao; + + @Resource(name = "welcomeMessage") + private String welcome; + + // Set up the dynamic behavior for the page, widgets bound by id + public ListContacts() { + + // Add the dynamic welcome message, specified in web.xml + add(new Label("welcomeMessage", welcome)); + add(new ListView<Contact>("contacts", contactDao.getContacts()) { + + // Populate the table of contacts + @Override + protected void populateItem(final ListItem<Contact> item) { + Contact contact = item.getModelObject(); + item.add(new Label("name", contact.getName())); + item.add(new Label("email", contact.getEmail())); + item.add(new Link<Contact>("delete", item.getModel()) { + + @Override + public void onClick() { + contactDao.remove(item.getModelObject()); + setResponsePage(ListContacts.class); + } + }); + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/util/ResourceWebApplicationPath.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/util/ResourceWebApplicationPath.java b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/util/ResourceWebApplicationPath.java new file mode 100644 index 0000000..6aea12e --- /dev/null +++ b/testing/wicket-arquillian/src/main/java/org/jboss/as/quickstarts/wicketWar/util/ResourceWebApplicationPath.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.util; + +import java.net.URL; + +import javax.servlet.ServletContext; + +import org.apache.wicket.util.file.IResourcePath; +import org.apache.wicket.util.resource.IResourceStream; +import org.apache.wicket.util.resource.UrlResourceStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Maintain a list of paths which might either be ordinary folders of the filesystem or relative + * paths to the web application's servlet context. + * + * @author Johan Compagner + */ +public final class ResourceWebApplicationPath implements IResourcePath +{ + private final static Logger log = LoggerFactory.getLogger(ResourceWebApplicationPath.class); + + private static final String WEB_INF = "WEB-INF/"; + + /** The web apps servlet context */ + private final ServletContext servletContext; + + private String basePath; + + /** + * Constructor + * + * @param servletContext + * The webapplication context where the resources must be loaded from + */ + public ResourceWebApplicationPath(String basePath,final ServletContext servletContext) + { + this.basePath = basePath.replaceAll("\\.", "\\/"); + this.servletContext = servletContext; + } + + /** + * + * @see org.apache.wicket.util.file.IResourceFinder#find(Class, String) + */ + public IResourceStream find(final Class<?> clazz, final String pathname) + { + + if (pathname.startsWith(WEB_INF) == false) + { + try + { + final URL url = servletContext.getResource(pathname.replaceFirst(basePath, "")); + if (url != null) + { + return new UrlResourceStream(url); + } + } + catch (Exception ex) + { + // ignore, file couldn't be found + } + } + + return null; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return "[webapppath: " + basePath + "]"; + } + + @Override + public void add(String folder) { + // DO NOTHING. + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/resources/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/resources/META-INF/MANIFEST.MF b/testing/wicket-arquillian/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..aff5ee3 --- /dev/null +++ b/testing/wicket-arquillian/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +Dependencies: org.jboss.msc http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/resources/META-INF/persistence.xml b/testing/wicket-arquillian/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..0c3470d --- /dev/null +++ b/testing/wicket-arquillian/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<persistence version="2.0" + xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/persistence + http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> + <persistence-unit name="primary"> + <!-- If you are running in a production environment, add a managed + data source, this example data source is just for development and testing! --> + <!-- The datasource is deployed as <EAR>/META-INF/wicket-quickstart-ds.xml, + you can find it in the source at ear/src/main/application/META-INF/wicket-quickstart-ds.xml --> + <jta-data-source>java:jboss/datasources/WicketQuickstartDS</jta-data-source> + <properties> + <!-- Properties for Hibernate --> + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> + <property name="hibernate.show_sql" value="false" /> + </properties> + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/WEB-INF/beans.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/WEB-INF/beans.xml b/testing/wicket-arquillian/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..e7488ad --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- This file can be an empty text file (0 bytes) --> +<!-- We're declaring the schema to save you time if you do have to configure + this in the future --> +<beans xmlns="http://java.sun.com/xml/ns/javaee" 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/beans_1_0.xsd"> +</beans> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/WEB-INF/faces-config.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/WEB-INF/faces-config.xml b/testing/wicket-arquillian/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..ddd61c7 --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<faces-config + xmlns="http://java.sun.com/xml/ns/javaee" + 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-facesconfig_1_2.xsd" + version="1.2"> + +</faces-config> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/WEB-INF/web.xml b/testing/wicket-arquillian/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..040099d --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" 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_2_5.xsd" + version="2.5"> + + <display-name>WildFly Quickstart: Wicket WAR</display-name> + + <!-- Enable Wicket --> + <filter> + <filter-name>Wicket</filter-name> + <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> + <init-param> + <!-- Specify the "entry point" for Wicket to configure itself + from --> + <param-name>applicationClassName</param-name> + <param-value>org.jboss.as.quickstarts.wicketWar.WicketJavaEEApplication</param-value> + </init-param> + </filter> + + <!-- Have wicket manage the context root --> + <filter-mapping> + <filter-name>Wicket</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <!-- A message displayed on the page, externalized into web.xml --> + <env-entry> + <env-entry-name>welcomeMessage</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>Welcome to the WildFly Quickstart showing the use of Wicket, packaged in an WAR</env-entry-value> + </env-entry> + +</web-app> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/WEB-INF/wicket-quickstart-ds.xml ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/WEB-INF/wicket-quickstart-ds.xml b/testing/wicket-arquillian/src/main/webapp/WEB-INF/wicket-quickstart-ds.xml new file mode 100644 index 0000000..92fa71a --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/WEB-INF/wicket-quickstart-ds.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- This is an unmanaged datasource. It should be used for proofs of concept + or testing only. It uses H2, an in memory database that ships with JBoss + AS. --> +<datasources xmlns="http://www.jboss.org/ironjacamar/schema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"> + <!-- The datasource is bound into JNDI at this location. We reference + this in META-INF/persistence.xml --> + <datasource jndi-name="java:jboss/datasources/WicketQuickstartDS" + pool-name="wicket-quickstart" enabled="true" + use-java-context="true"> + <connection-url>jdbc:h2:mem:wicket-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url> + <driver>h2</driver> + <security> + <user-name>sa</user-name> + <password>sa</password> + </security> + </datasource> +</datasources> + http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/pages/InsertContact.html ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/pages/InsertContact.html b/testing/wicket-arquillian/src/main/webapp/pages/InsertContact.html new file mode 100644 index 0000000..309531e --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/pages/InsertContact.html @@ -0,0 +1,41 @@ +<!-- + 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. +--> +<html xmlns:wicket="http://wicket.sourceforge.net/"> + <head> + <title>wicket-war</title> + </head> + + <body> + <span wicket:id="feedback"></span> + <form method="post" action="#" wicket:id="insertForm"> + <table border="0" cellpadding="5"> + <tr> + <td width="200">Name</td> + <td><input type="text" wicket:id="name" size="20"/></td> + </tr> + <tr> + <td width="200">Email</td> + <td><input type="text" wicket:id="email" size="20"/></td> + </tr> + <tr> + <td width="200"> </td> + <td><input type="submit" value="Insert"/></td> + </tr> + </table> + </form> + </body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/testing/wicket-arquillian/src/main/webapp/pages/ListContacts.html ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/webapp/pages/ListContacts.html b/testing/wicket-arquillian/src/main/webapp/pages/ListContacts.html new file mode 100644 index 0000000..d6613bd --- /dev/null +++ b/testing/wicket-arquillian/src/main/webapp/pages/ListContacts.html @@ -0,0 +1,43 @@ +<!-- + 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. +--> +<html xmlns:wicket="http://wicket.sourceforge.net/"> + <head> + <title>wicket-war</title> + </head> + + <body> + + <h1> + <span wicket:id="welcomeMessage"></span> + </h1> + + <table border="1" cellpadding="8"> + <tr> + <td width="200">Name</td> + <td width="200">Email</td> + <td width="200"> </td> + </tr> + <tr wicket:id="contacts"> + <td><span wicket:id="name">[name]</span></td> + <td><span wicket:id="email">[email]</span></td> + <td><a href="#" wicket:id="delete">[delete]</a></td> + </tr> + </table> + + <wicket:link><a href="InsertContact.html">Insert a new Contact</a></wicket:link> + </body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/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 new file mode 100644 index 0000000..da90dcf --- /dev/null +++ b/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/TestWicketJavaEEApplication.java @@ -0,0 +1,36 @@ +/* + * 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/11b458bc/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 new file mode 100644 index 0000000..c7a6631 --- /dev/null +++ b/testing/wicket-arquillian/src/test/java/org/jboss/as/quickstarts/wicketWar/pages/InsertContactTest.java @@ -0,0 +1,207 @@ +/** + * + */ +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/11b458bc/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 new file mode 100644 index 0000000..b709b61 --- /dev/null +++ b/testing/wicket-arquillian/src/test/resources/arquillian.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<arquillian xmlns="http://jboss.org/schema/arquillian" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + + <defaultProtocol type="Servlet 3.0" /> + <engine> + <property name="deploymentExportPath">target</property> + </engine> + + <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 --> + <property name="javaVmArguments">-Xmx128m -XX:MaxMetaspaceSize=128m -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n + </property> + </configuration> + </container> + +</arquillian> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/11b458bc/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 new file mode 100644 index 0000000..b52ea2a --- /dev/null +++ b/testing/wicket-arquillian/src/test/webapp/WEB-INF/web.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- 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. --> +<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" + 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> + + <!-- Enable Wicket --> + <filter> + <filter-name>WicketTesterFilter</filter-name> + <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> + <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> + </init-param> + </filter> + + <!-- Have wicket manage the context root --> + <filter-mapping> + <filter-name>WicketTesterFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <!-- A message displayed on the page, externalized into web.xml --> + <env-entry> + <env-entry-name>welcomeMessage</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>Welcome to the WildFly Quickstart showing the use of Wicket, packaged in an WAR</env-entry-value> + </env-entry> + +</web-app>
