Skip to content
Browse files

Isolate HtmlUnit classes in HtmlUnit namespace

  • Loading branch information...
1 parent bbeb728 commit 43af5866c7a138431b075a2321e6e09f6a47972a @bernerdschaefer bernerdschaefer committed
Showing with 58 additions and 50 deletions.
  1. +3 −6 lib/akephalos/client.rb
  2. +6 −8 lib/akephalos/client/filter.rb
  3. +23 −12 lib/akephalos/htmlunit.rb
  4. +26 −24 lib/akephalos/htmlunit/ext/http_method.rb
View
9 lib/akephalos/client.rb
@@ -19,18 +19,15 @@ module Akephalos
# point for all interaction with the browser, exposing its current page and
# allowing navigation.
class Client
- java_import 'com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController'
- java_import 'com.gargoylesoftware.htmlunit.SilentCssErrorHandler'
-
attr_reader :page
def initialize
@_client = java.util.concurrent.FutureTask.new do
- client = WebClient.new
+ client = HtmlUnit::WebClient.new
Filter.new(client)
- client.setAjaxController(NicelyResynchronizingAjaxController.new)
- client.setCssErrorHandler(SilentCssErrorHandler.new)
+ client.setAjaxController(HtmlUnit::NicelyResynchronizingAjaxController.new)
+ client.setCssErrorHandler(HtmlUnit::SilentCssErrorHandler.new)
client
end
View
14 lib/akephalos/client/filter.rb
@@ -9,11 +9,7 @@ class Client
# found. If no filters are defined, or no filters match the request, then
# the response will bubble up to HtmlUnit for the normal request/response
# cycle.
- class Filter < WebConnectionWrapper
- java_import 'com.gargoylesoftware.htmlunit.util.NameValuePair'
- java_import 'com.gargoylesoftware.htmlunit.WebResponseData'
- java_import 'com.gargoylesoftware.htmlunit.WebResponseImpl'
-
+ class Filter < HtmlUnit::Util::WebConnectionWrapper
# Filters an outgoing request, and if a match is found, returns the mock
# response.
#
@@ -23,14 +19,16 @@ class Filter < WebConnectionWrapper
def filter(request)
if filter = find_filter(request)
start_time = Time.now
- headers = filter[:headers].map { |name, value| NameValuePair.new(name.to_s, value.to_s) }
- response = WebResponseData.new(
+ headers = filter[:headers].map do |name, value|
+ HtmlUnit::Util::NameValuePair.new(name.to_s, value.to_s)
+ end
+ response = HtmlUnit::WebResponseData.new(
filter[:body].to_s.to_java_bytes,
filter[:status],
HTTP_STATUS_CODES.fetch(filter[:status], "Unknown"),
headers
)
- WebResponseImpl.new(response, request, Time.now - start_time)
+ HtmlUnit::WebResponseImpl.new(response, request, Time.now - start_time)
end
end
View
35 lib/akephalos/htmlunit.rb
@@ -13,15 +13,26 @@
java.lang.System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "fatal")
java.lang.System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true")
-java_import "com.gargoylesoftware.htmlunit.WebClient"
-java_import "com.gargoylesoftware.htmlunit.util.WebConnectionWrapper"
-java_import 'com.gargoylesoftware.htmlunit.HttpMethod'
-
-
-# Disable history tracking
-com.gargoylesoftware.htmlunit.History.field_reader :ignoreNewPages_
-
-# Run in Firefox compatibility mode
-com.gargoylesoftware.htmlunit.BrowserVersion.setDefault(
- com.gargoylesoftware.htmlunit.BrowserVersion::FIREFOX_3
-)
+# Container module for com.gargoylesoftware.htmlunit namespace.
+module HtmlUnit
+ java_import "com.gargoylesoftware.htmlunit.BrowserVersion"
+ java_import "com.gargoylesoftware.htmlunit.History"
+ java_import "com.gargoylesoftware.htmlunit.HttpMethod"
+ java_import "com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController"
+ java_import "com.gargoylesoftware.htmlunit.SilentCssErrorHandler"
+ java_import "com.gargoylesoftware.htmlunit.WebClient"
+ java_import "com.gargoylesoftware.htmlunit.WebResponseData"
+ java_import "com.gargoylesoftware.htmlunit.WebResponseImpl"
+
+ # Container module for com.gargoylesoftware.htmlunit.util namespace.
+ module Util
+ java_import "com.gargoylesoftware.htmlunit.util.NameValuePair"
+ java_import "com.gargoylesoftware.htmlunit.util.WebConnectionWrapper"
+ end
+
+ # Disable history tracking
+ History.field_reader :ignoreNewPages_
+
+ # Run in Firefox compatibility mode
+ BrowserVersion.setDefault(BrowserVersion::FIREFOX_3)
+end
View
50 lib/akephalos/htmlunit/ext/http_method.rb
@@ -1,28 +1,30 @@
-# Reopen com.gargoylesoftware.htmlunit.HttpMethod to add convenience methods.
-class HttpMethod
+module HtmlUnit
+ # Reopen HtmlUnit's HttpMethod class to add convenience methods.
+ class HttpMethod
- # Loosely compare HttpMethod with another object, accepting either an
- # HttpMethod instance or a symbol describing the method. Note that :any is a
- # special symbol which will always return true.
- #
- # @param [HttpMethod] other an HtmlUnit HttpMethod object
- # @param [Symbol] other a symbolized representation of an http method
- # @return [true/false]
- def ===(other)
- case other
- when HttpMethod
- super
- when :any
- true
- when :get
- self == self.class::GET
- when :post
- self == self.class::POST
- when :put
- self == self.class::PUT
- when :delete
- self == self.class::DELETE
+ # Loosely compare HttpMethod with another object, accepting either an
+ # HttpMethod instance or a symbol describing the method. Note that :any is a
+ # special symbol which will always return true.
+ #
+ # @param [HttpMethod] other an HtmlUnit HttpMethod object
+ # @param [Symbol] other a symbolized representation of an http method
+ # @return [true/false]
+ def ===(other)
+ case other
+ when HttpMethod
+ super
+ when :any
+ true
+ when :get
+ self == self.class::GET
+ when :post
+ self == self.class::POST
+ when :put
+ self == self.class::PUT
+ when :delete
+ self == self.class::DELETE
+ end
end
- end
+ end
end

0 comments on commit 43af586

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