Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

First baby steps enabling cucumber (cuke4duke) for Wicket apps

  • Loading branch information...
commit c070ccb16755c30df35b2bc99c3f34f291a9675a 0 parents
authored January 03, 2010
5  .gitignore
... ...
@@ -0,0 +1,5 @@
  1
+target
  2
+.classpath
  3
+.project
  4
+.settings
  5
+
17  features/counting.feature
... ...
@@ -0,0 +1,17 @@
  1
+Feature: Counting
  2
+  In order to count the number of clicks on a link
  3
+  As a user
  4
+  I want to see a number increase with each click on a link.
  5
+
  6
+	Scenario: number is zero without any clicks
  7
+	  Given I am viewing the home page
  8
+	  Then I should see "Number of clicks 0"
  9
+	  And I should see a link with text "Click me"
  10
+
  11
+	Scenario: number is one after a click
  12
+	  Given I am viewing the home page
  13
+	  When I click the link with text "Click me"
  14
+	  Then I should see "Number of clicks 1"
  15
+
  16
+	
  17
+	
12  features/helloworld.feature
... ...
@@ -0,0 +1,12 @@
  1
+Feature: Helloworld
  2
+  In order to greet the world
  3
+  As a user
  4
+  I want to see the text Hello World in a browser window.
  5
+
  6
+	Scenario: Hello World
  7
+	  Given I am viewing the home page
  8
+	  Then I should see "Hello World"
  9
+
  10
+	
  11
+	
  12
+	
211  pom.xml
... ...
@@ -0,0 +1,211 @@
  1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3
+	<modelVersion>4.0.0</modelVersion>
  4
+	<groupId>com.wicketinaction</groupId>
  5
+	<artifactId>cucumber-wicket</artifactId>
  6
+	<packaging>war</packaging>
  7
+	<version>1.0-SNAPSHOT</version>
  8
+	<!-- TODO project name  -->
  9
+	<name>quickstart</name>
  10
+	<description></description>
  11
+	<properties>
  12
+		<wicket.version>1.4.5</wicket.version>
  13
+		<slf4j.version>1.5.6</slf4j.version>
  14
+		<jetty.version>6.1.21</jetty.version>
  15
+	</properties>
  16
+	<!--
  17
+		TODO <organization> <name>company name</name> <url>company url</url>
  18
+		</organization>
  19
+	-->
  20
+	<licenses>
  21
+		<license>
  22
+			<name>The Apache Software License, Version 2.0</name>
  23
+			<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  24
+			<distribution>repo</distribution>
  25
+		</license>
  26
+	</licenses>
  27
+
  28
+	<repositories>
  29
+		<repository>
  30
+			<id>codehaus</id>
  31
+			<url>http://repository.codehaus.org</url>
  32
+		</repository>
  33
+		<repository>
  34
+			<id>cukes</id>
  35
+			<url>http://cukes.info/maven</url>
  36
+		</repository>
  37
+	</repositories>
  38
+
  39
+	<pluginRepositories>
  40
+		<pluginRepository>
  41
+			<id>cukes</id>
  42
+			<url>http://cukes.info/maven</url>
  43
+		</pluginRepository>
  44
+	</pluginRepositories>
  45
+
  46
+	<dependencies>
  47
+		<!--  WICKET DEPENDENCIES -->
  48
+		<dependency>
  49
+			<groupId>org.apache.wicket</groupId>
  50
+			<artifactId>wicket</artifactId>
  51
+			<version>${wicket.version}</version>
  52
+		</dependency>
  53
+		<!--
  54
+			OPTIONAL <dependency> <groupId>org.apache.wicket</groupId>
  55
+			<artifactId>wicket-extensions</artifactId>
  56
+			<version>${wicket.version}</version> </dependency>
  57
+		-->
  58
+
  59
+		<!-- LOGGING DEPENDENCIES - LOG4J -->
  60
+		<dependency>
  61
+			<groupId>org.slf4j</groupId>
  62
+			<artifactId>slf4j-log4j12</artifactId>
  63
+			<version>${slf4j.version}</version>
  64
+		</dependency>
  65
+		<dependency>
  66
+			<groupId>log4j</groupId>
  67
+			<artifactId>log4j</artifactId>
  68
+			<version>1.2.14</version>
  69
+		</dependency>
  70
+
  71
+		<!--  JUNIT DEPENDENCY FOR TESTING -->
  72
+		<dependency>
  73
+			<groupId>junit</groupId>
  74
+			<artifactId>junit</artifactId>
  75
+			<version>4.7</version>
  76
+			<scope>test</scope>
  77
+		</dependency>
  78
+		<!-- Cucumber dependencies -->
  79
+		<dependency>
  80
+			<groupId>cuke4duke</groupId>
  81
+			<artifactId>cuke4duke</artifactId>
  82
+			<version>0.2.1</version>
  83
+			<scope>test</scope>
  84
+		</dependency>
  85
+		<dependency>
  86
+			<groupId>org.picocontainer</groupId>
  87
+			<artifactId>picocontainer</artifactId>
  88
+			<version>2.8.3</version>
  89
+			<scope>test</scope>
  90
+		</dependency>
  91
+
  92
+		<!--  JETTY DEPENDENCIES FOR TESTING  -->
  93
+		<dependency>
  94
+			<groupId>org.mortbay.jetty</groupId>
  95
+			<artifactId>jetty</artifactId>
  96
+			<version>${jetty.version}</version>
  97
+			<scope>provided</scope>
  98
+		</dependency>
  99
+		<dependency>
  100
+			<groupId>org.mortbay.jetty</groupId>
  101
+			<artifactId>jetty-util</artifactId>
  102
+			<version>${jetty.version}</version>
  103
+			<scope>provided</scope>
  104
+		</dependency>
  105
+		<dependency>
  106
+			<groupId>org.mortbay.jetty</groupId>
  107
+			<artifactId>jetty-management</artifactId>
  108
+			<version>${jetty.version}</version>
  109
+			<scope>provided</scope>
  110
+		</dependency>
  111
+	</dependencies>
  112
+	<build>
  113
+		<resources>
  114
+			<resource>
  115
+				<filtering>false</filtering>
  116
+				<directory>src/main/resources</directory>
  117
+			</resource>
  118
+			<resource>
  119
+				<filtering>false</filtering>
  120
+				<directory>src/main/java</directory>
  121
+				<includes>
  122
+					<include>**</include>
  123
+				</includes>
  124
+				<excludes>
  125
+					<exclude>**/*.java</exclude>
  126
+				</excludes>
  127
+			</resource>
  128
+		</resources>
  129
+		<testResources>
  130
+			<testResource>
  131
+				<filtering>false</filtering>
  132
+				<directory>src/test/resources</directory>
  133
+			</testResource>
  134
+			<testResource>
  135
+				<filtering>false</filtering>
  136
+				<directory>src/test/java</directory>
  137
+				<includes>
  138
+					<include>**</include>
  139
+				</includes>
  140
+				<excludes>
  141
+					<exclude>**/*.java</exclude>
  142
+				</excludes>
  143
+			</testResource>
  144
+		</testResources>
  145
+		<plugins>
  146
+			<plugin>
  147
+				<inherited>true</inherited>
  148
+				<groupId>org.apache.maven.plugins</groupId>
  149
+				<artifactId>maven-compiler-plugin</artifactId>
  150
+				<configuration>
  151
+					<source>1.6</source>
  152
+					<target>1.6</target>
  153
+					<optimize>true</optimize>
  154
+					<debug>true</debug>
  155
+				</configuration>
  156
+			</plugin>
  157
+			<plugin>
  158
+				<groupId>org.mortbay.jetty</groupId>
  159
+				<artifactId>maven-jetty-plugin</artifactId>
  160
+			</plugin>
  161
+			<plugin>
  162
+				<groupId>org.apache.maven.plugins</groupId>
  163
+				<artifactId>maven-eclipse-plugin</artifactId>
  164
+				<version>2.7</version>
  165
+				<configuration>
  166
+					<downloadSources>true</downloadSources>
  167
+				</configuration>
  168
+			</plugin>
  169
+			<plugin>
  170
+				<groupId>cuke4duke</groupId>
  171
+				<artifactId>cuke4duke-maven-plugin</artifactId>
  172
+				<version>0.2.1</version>
  173
+				<configuration>
  174
+					<jvmArgs>
  175
+						<jvmArg>-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory</jvmArg>
  176
+					</jvmArgs>
  177
+					<cucumberArgs>
  178
+						<cucumberArg>--backtrace</cucumberArg>
  179
+						<cucumberArg>--color</cucumberArg>
  180
+						<cucumberArg>--format</cucumberArg>
  181
+						<cucumberArg>pretty</cucumberArg>
  182
+						<cucumberArg>--format</cucumberArg>
  183
+						<cucumberArg>junit</cucumberArg>
  184
+						<cucumberArg>--out</cucumberArg>
  185
+						<cucumberArg>target/surefire-reports</cucumberArg>
  186
+						<cucumberArg>--format</cucumberArg>
  187
+						<cucumberArg>usage</cucumberArg>
  188
+						<cucumberArg>--out</cucumberArg>
  189
+						<cucumberArg>target/usage.txt</cucumberArg>
  190
+						<cucumberArg>--require</cucumberArg>
  191
+						<cucumberArg>${basedir}/target/test-classes</cucumberArg>
  192
+						<cucumberArg>--require</cucumberArg>
  193
+						<cucumberArg>${basedir}/target/classes</cucumberArg>
  194
+					</cucumberArgs>
  195
+					<gems>
  196
+						<gem>install cuke4duke --version 0.2.1</gem>
  197
+					</gems>
  198
+				</configuration>
  199
+				<executions>
  200
+					<execution>
  201
+						<id>run-features</id>
  202
+						<phase>integration-test</phase>
  203
+						<goals>
  204
+							<goal>cucumber</goal>
  205
+						</goals>
  206
+					</execution>
  207
+				</executions>
  208
+			</plugin>
  209
+		</plugins>
  210
+	</build>
  211
+</project>
31  src/main/java/com/wicketinaction/counting/CountingApplication.java
... ...
@@ -0,0 +1,31 @@
  1
+package com.wicketinaction.counting;
  2
+
  3
+import org.apache.wicket.Application;
  4
+import org.apache.wicket.protocol.http.WebApplication;
  5
+
  6
+/**
  7
+ * Application object for your web application. If you want to run this
  8
+ * application without deploying, run the Start class.
  9
+ * 
  10
+ * @see com.wicketinaction.Start#main(String[])
  11
+ */
  12
+public class CountingApplication extends WebApplication {
  13
+	/**
  14
+	 * Constructor
  15
+	 */
  16
+	public CountingApplication() {
  17
+	}
  18
+
  19
+	@Override
  20
+	public String getConfigurationType() {
  21
+		return Application.DEPLOYMENT;
  22
+	}
  23
+
  24
+	/**
  25
+	 * @see org.apache.wicket.Application#getHomePage()
  26
+	 */
  27
+	public Class<HomePage> getHomePage() {
  28
+		return HomePage.class;
  29
+	}
  30
+
  31
+}
11  src/main/java/com/wicketinaction/counting/HomePage.html
... ...
@@ -0,0 +1,11 @@
  1
+<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
  2
+    <head>  
  3
+        <title>Click counter</title>
  4
+    </head>
  5
+    <body>
  6
+    	<h1>Click counter</h1>
  7
+    	<p>Counts the number of clicks.</p>
  8
+    	<a href="#" wicket:id="link">Click me</a>
  9
+    	<p>Number of clicks <wicket:container wicket:id="clicks"></wicket:container></p>
  10
+    </body>
  11
+</html>
25  src/main/java/com/wicketinaction/counting/HomePage.java
... ...
@@ -0,0 +1,25 @@
  1
+package com.wicketinaction.counting;
  2
+
  3
+import org.apache.wicket.PageParameters;
  4
+import org.apache.wicket.markup.html.WebPage;
  5
+import org.apache.wicket.markup.html.basic.Label;
  6
+import org.apache.wicket.markup.html.link.Link;
  7
+import org.apache.wicket.model.PropertyModel;
  8
+
  9
+public class HomePage extends WebPage {
  10
+	private static final long serialVersionUID = 1L;
  11
+
  12
+	private int clicks = 0;
  13
+
  14
+	public HomePage(final PageParameters parameters) {
  15
+		add(new Label("clicks", new PropertyModel<Integer>(this, "clicks")));
  16
+		add(new Link<Void>("link") {
  17
+			private static final long serialVersionUID = 1L;
  18
+
  19
+			@Override
  20
+			public void onClick() {
  21
+				clicks++;
  22
+			}
  23
+		});
  24
+	}
  25
+}
31  src/main/java/com/wicketinaction/helloworld/HelloWorldApplication.java
... ...
@@ -0,0 +1,31 @@
  1
+package com.wicketinaction.helloworld;
  2
+
  3
+import org.apache.wicket.Application;
  4
+import org.apache.wicket.protocol.http.WebApplication;
  5
+
  6
+/**
  7
+ * Application object for your web application. If you want to run this
  8
+ * application without deploying, run the Start class.
  9
+ * 
  10
+ * @see com.wicketinaction.Start#main(String[])
  11
+ */
  12
+public class HelloWorldApplication extends WebApplication {
  13
+	/**
  14
+	 * Constructor
  15
+	 */
  16
+	public HelloWorldApplication() {
  17
+	}
  18
+
  19
+	@Override
  20
+	public String getConfigurationType() {
  21
+		return Application.DEPLOYMENT;
  22
+	}
  23
+
  24
+	/**
  25
+	 * @see org.apache.wicket.Application#getHomePage()
  26
+	 */
  27
+	public Class<HomePage> getHomePage() {
  28
+		return HomePage.class;
  29
+	}
  30
+
  31
+}
8  src/main/java/com/wicketinaction/helloworld/HomePage.html
... ...
@@ -0,0 +1,8 @@
  1
+<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
  2
+    <head>  
  3
+        <title>Hello World</title>
  4
+    </head>
  5
+    <body>
  6
+        <h1 wicket:id="message">message will be here</h1>
  7
+    </body>
  8
+</html>
22  src/main/java/com/wicketinaction/helloworld/HomePage.java
... ...
@@ -0,0 +1,22 @@
  1
+package com.wicketinaction.helloworld;
  2
+
  3
+import org.apache.wicket.PageParameters;
  4
+import org.apache.wicket.markup.html.basic.Label;
  5
+import org.apache.wicket.markup.html.WebPage;
  6
+
  7
+/**
  8
+ * Homepage
  9
+ */
  10
+public class HomePage extends WebPage {
  11
+	private static final long serialVersionUID = 1L;
  12
+
  13
+	/**
  14
+	 * Constructor that is invoked when page is invoked without a session.
  15
+	 * 
  16
+	 * @param parameters
  17
+	 *            Page parameters
  18
+	 */
  19
+	public HomePage(final PageParameters parameters) {
  20
+		add(new Label("message", "Hello World"));
  21
+	}
  22
+}
12  src/main/resources/log4j.properties
... ...
@@ -0,0 +1,12 @@
  1
+log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
  2
+log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
  3
+log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
  4
+
  5
+log4j.rootLogger=FATAL,Stdout
  6
+
  7
+#log4j.logger.org.apache.wicket=INFO
  8
+#log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
  9
+#log4j.logger.org.apache.wicket.version=INFO
  10
+#log4j.logger.org.apache.wicket.RequestCycle=INFO
  11
+
  12
+
35  src/main/webapp/WEB-INF/web.xml
... ...
@@ -0,0 +1,35 @@
  1
+<?xml version="1.0" encoding="ISO-8859-1"?>
  2
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3
+	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  4
+	version="2.4">
  5
+
  6
+	<display-name>cucumber-wicket</display-name>
  7
+
  8
+	<filter>
  9
+		<filter-name>helloworld</filter-name>
  10
+		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
  11
+		<init-param>
  12
+			<param-name>applicationClassName</param-name>
  13
+			<param-value>com.wicketinaction.helloworld.HelloWorldApplication</param-value>
  14
+		</init-param>
  15
+	</filter>
  16
+
  17
+	<filter>
  18
+		<filter-name>counting</filter-name>
  19
+		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
  20
+		<init-param>
  21
+			<param-name>applicationClassName</param-name>
  22
+			<param-value>com.wicketinaction.counting.CountingApplication</param-value>
  23
+		</init-param>
  24
+	</filter>
  25
+
  26
+	<filter-mapping>
  27
+		<filter-name>helloworld</filter-name>
  28
+		<url-pattern>/helloworld/*</url-pattern>
  29
+	</filter-mapping>
  30
+
  31
+	<filter-mapping>
  32
+		<filter-name>counting</filter-name>
  33
+		<url-pattern>/counting/*</url-pattern>
  34
+	</filter-mapping>
  35
+</web-app>
48  src/test/java/com/wicketinaction/Start.java
... ...
@@ -0,0 +1,48 @@
  1
+package com.wicketinaction;
  2
+
  3
+import org.mortbay.jetty.Connector;
  4
+import org.mortbay.jetty.Server;
  5
+import org.mortbay.jetty.bio.SocketConnector;
  6
+import org.mortbay.jetty.webapp.WebAppContext;
  7
+
  8
+public class Start {
  9
+
  10
+	public static void main(String[] args) throws Exception {
  11
+		Server server = new Server();
  12
+		SocketConnector connector = new SocketConnector();
  13
+		
  14
+		// Set some timeout options to make debugging easier.
  15
+		connector.setMaxIdleTime(1000 * 60 * 60);
  16
+		connector.setSoLingerTime(-1);
  17
+		connector.setPort(8080);
  18
+		server.setConnectors(new Connector[] { connector });
  19
+
  20
+		WebAppContext bb = new WebAppContext();
  21
+		bb.setServer(server);
  22
+		bb.setContextPath("/");
  23
+		bb.setWar("src/main/webapp");
  24
+		
  25
+		// START JMX SERVER
  26
+		// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
  27
+		// MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
  28
+		// server.getContainer().addEventListener(mBeanContainer);
  29
+		// mBeanContainer.start();
  30
+		
  31
+		server.addHandler(bb);
  32
+
  33
+		try {
  34
+			System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
  35
+			server.start();
  36
+			System.in.read();
  37
+			System.out.println(">>> STOPPING EMBEDDED JETTY SERVER"); 
  38
+            // while (System.in.available() == 0) {
  39
+			//   Thread.sleep(5000);
  40
+			// }
  41
+			server.stop();
  42
+			server.join();
  43
+		} catch (Exception e) {
  44
+			e.printStackTrace();
  45
+			System.exit(100);
  46
+		}
  47
+	}
  48
+}
27  src/test/java/com/wicketinaction/WicketSteps.java
... ...
@@ -0,0 +1,27 @@
  1
+package com.wicketinaction;
  2
+
  3
+import org.apache.wicket.protocol.http.WebApplication;
  4
+import org.apache.wicket.util.tester.WicketTester;
  5
+
  6
+import cuke4duke.Given;
  7
+import cuke4duke.Then;
  8
+
  9
+public abstract class WicketSteps {
  10
+	private WicketTester tester;
  11
+
  12
+	protected WicketSteps(WebApplication application) {
  13
+		tester = new WicketTester(application);
  14
+	}
  15
+
  16
+	@Given("^I am viewing the (.*)$")
  17
+	public void iAmViewing(String arg1) {
  18
+		if ("home page".equalsIgnoreCase(arg1)) {
  19
+			tester.startPage(tester.getApplication().getHomePage());
  20
+		}
  21
+	}
  22
+
  23
+	@Then("^I should see \"([^\"]*)\"$")
  24
+	public void iShouldSee(String arg1) {
  25
+		tester.assertContains(arg1);
  26
+	}
  27
+}
9  src/test/java/com/wicketinaction/counting/CountingSteps.java
... ...
@@ -0,0 +1,9 @@
  1
+package com.wicketinaction.counting;
  2
+
  3
+import com.wicketinaction.WicketSteps;
  4
+
  5
+public class CountingSteps extends WicketSteps {
  6
+	public CountingSteps() {
  7
+		super(new CountingApplication());
  8
+	}
  9
+}
9  src/test/java/com/wicketinaction/helloworld/HelloWorldSteps.java
... ...
@@ -0,0 +1,9 @@
  1
+package com.wicketinaction.helloworld;
  2
+
  3
+import com.wicketinaction.WicketSteps;
  4
+
  5
+public class HelloWorldSteps extends WicketSteps {
  6
+	public HelloWorldSteps() {
  7
+		super(new HelloWorldApplication());
  8
+	}
  9
+}
9  src/test/resources/log4j.properties
... ...
@@ -0,0 +1,9 @@
  1
+log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
  2
+log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
  3
+log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
  4
+
  5
+log4j.rootLogger=INFO,Stdout
  6
+
  7
+log4j.logger.org.apache.wicket=ERROR
  8
+
  9
+

0 notes on commit c070ccb

Please sign in to comment.
Something went wrong with that request. Please try again.