Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added selenium test

  • Loading branch information...
commit bc99cfd3e4b19160d7df1dc1379d1cd6baaf3fb8 1 parent c0c719a
Christian Meier authored October 31, 2010
27  demo/Gemfile
... ...
@@ -1,3 +1,4 @@
  1
+# -*- mode: ruby -*-
1 2
 source 'http://rubygems.org'
2 3
 
3 4
 gem 'rails', '3.0.0'
@@ -32,3 +33,29 @@ gem "jdbc-sqlite3", :require => false if defined?(JRUBY_VERSION)
32 33
 # end
33 34
 
34 35
 gem 'enforce-ssl'
  36
+
  37
+if defined? MAVEN
  38
+  properties({ "jruby.plugins.version" => '0.23.0-SNAPSHOT' })
  39
+
  40
+  #TODO allow :scope => :test, :classifier => "test", :exclusions => ['ant.ant']
  41
+  #group :dev do
  42
+    jar 'junit.junit', '3.8.2'
  43
+    jar 'org.seleniumhq.selenium.client-drivers.selenium-java-client-driver', '1.0.1'
  44
+  #end
  45
+
  46
+  plugin('org.mortbay.jetty.jetty-maven-plugin', '${jetty.version}') do |jetty|
  47
+    jetty.with(:stopKey => 'foo', :stopPort => 9999)
  48
+    jetty.in_phase('pre-integration-test').execute('run').with(:daemon => true)
  49
+    jetty.in_phase('post-integration-test').execute('stop')
  50
+  end
  51
+
  52
+  plugin('org.codehaus.mojo.selenium-maven-plugin', '1.1') do |selenium|
  53
+    selenium.in_phase('pre-integration-test').execute("start-server").with({
  54
+         :background => true, :firefoxProfileTemplate => "src/test/resources/selenium" })
  55
+  end
  56
+
  57
+  plugin('surefire', '2.6') do |surefire|
  58
+    surefire.with :skip => true
  59
+    surefire.in_phase('integration-test').execute('test').with :skip => false 
  60
+  end
  61
+end
57  demo/README.textile
Source Rendered
... ...
@@ -0,0 +1,57 @@
  1
+h1. Start the demo application
  2
+
  3
+h2. with maven3 (jetty)
  4
+
  5
+bc. mvn rails3:rake -Dargs="db:setup"
  6
+mvn jetty:run -f Gemfile.pom
  7
+
  8
+p. note: there is no need to have jruby, rubygems, rails installed !!!
  9
+
  10
+h2. with ruby-maven gem (jetty)
  11
+
  12
+bc. jruby -S gem install ruby-maven --pre
  13
+rmvn rake db:setup
  14
+rmvn jetty-run
  15
+
  16
+p. note: you need to have jruby installed but no rails or bundler !!!
  17
+
  18
+h2. with jruby (webrick)
  19
+
  20
+bc. jruby -S bundle install
  21
+jruby -S rake db:setup
  22
+jruby script/rails server
  23
+
  24
+p. note: you to have jruby and bundler installed !!!
  25
+
  26
+h2. with ruby (webrick)
  27
+
  28
+bc. bundle install
  29
+rake db:setup
  30
+script/rails server
  31
+
  32
+p. note: you to have bundler installed !!!
  33
+
  34
+h1. Run the integration test (selenium)
  35
+
  36
+h2. with maven3 (jetty)
  37
+
  38
+bc. mvn rails3:rake -Dargs="db:setup"
  39
+mvn integration-test -f Gemfile.pom
  40
+
  41
+p. note: there is no need to have jruby, rubygems, rails installed !!!
  42
+
  43
+h2. with ruby-maven gem (jetty)
  44
+
  45
+bc. jruby -S gem install ruby-maven --pre
  46
+rmvn rake db:setup
  47
+rmvn integration-test
  48
+
  49
+p. note: you need to have jruby installed but no rails or bundler !!!
  50
+
  51
+h1.  Navigate through the application
  52
+
  53
+p. I use the jetty port 8080 for the sample urls. starting point is
  54
+
  55
+p. "http://localhost:8080/users":http://localhost:8080/users
  56
+
  57
+p. any further link enforces SSL will switch over to port 8443 and https.
13  demo/app/controllers/application_controller.rb
... ...
@@ -1,3 +1,16 @@
1 1
 class ApplicationController < ActionController::Base
2 2
   protect_from_forgery
  3
+
  4
+  before_filter do
  5
+
  6
+    # work around a bug somewhere in the
  7
+    # tcp stack from rails, rack, jruby-rack, jetty
  8
+    # when request HEAD and then following a GET on
  9
+    # the same connection does not send the body of the
  10
+    # GET. on a fresh connection both HEAD and HEAD work
  11
+    # as expected
  12
+    # only appeared on selenium tests
  13
+    response.header["Connection"] = "close"
  14
+
  15
+  end
3 16
 end
38  demo/src/test/java/enforce_ssl/DevelopmentTestCase.java
... ...
@@ -0,0 +1,38 @@
  1
+package enforce_ssl;
  2
+
  3
+import junit.framework.TestCase;
  4
+
  5
+import com.thoughtworks.selenium.DefaultSelenium;
  6
+import com.thoughtworks.selenium.SeleniumException;
  7
+
  8
+public class DevelopmentTestCase
  9
+    extends TestCase
  10
+{
  11
+    protected DefaultSelenium createSeleniumClient(String url) throws Exception {
  12
+        return new DefaultSelenium("localhost", 4444, "*firefox", url);
  13
+    }
  14
+    
  15
+    public void testRedirectToSsl() throws Exception {
  16
+        DefaultSelenium selenium = createSeleniumClient("http://localhost:8080");
  17
+        selenium.start();
  18
+
  19
+	selenium.open("/users");
  20
+	selenium.click("link=New User");
  21
+	    selenium.waitForPageToLoad("10000");
  22
+	assertEquals("https://localhost:8443/users/new", selenium.getLocation());
  23
+
  24
+        selenium.stop();
  25
+    } 
  26
+
  27
+    public void testStayOnSsl() throws Exception {
  28
+        DefaultSelenium selenium = createSeleniumClient("https://localhost:8443");
  29
+        selenium.start();
  30
+
  31
+	selenium.open("/users");
  32
+	selenium.click("link=New User");
  33
+	selenium.waitForPageToLoad("10000");
  34
+	assertEquals("https://localhost:8443/users/new", selenium.getLocation());
  35
+
  36
+        selenium.stop();
  37
+    }
  38
+}
0  demo/src/test/resources/selenium/.parentlock
No changes.
BIN  demo/src/test/resources/selenium/cert8.db
Binary file not shown
3  demo/src/test/resources/selenium/cert_override.txt
... ...
@@ -0,0 +1,3 @@
  1
+# PSM Certificate Override Settings file
  2
+# This is a generated file!  Do not edit.
  3
+localhost:8443	OID.2.16.840.1.101.3.4.2.1	92:DE:D7:63:60:A6:4C:A8:97:B9:E6:26:46:94:BC:C9:31:73:69:00:95:3B:14:E4:B7:3C:C7:26:59:CD:F4:55	U	AAAAAAAAAAAAAAAEAAAAcEzJ5aIwbjEQMA4GA1UEBhMHVW5rbm93bjEQMA4GA1UE  CBMHVW5rbm93bjEQMA4GA1UEBxMHVW5rbm93bjEQMA4GA1UEChMHVW5rbm93bjEQ  MA4GA1UECxMHVW5rbm93bjESMBAGA1UEAxMJbG9jYWxob3N0

0 notes on commit bc99cfd

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