rtomcat 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,38 +9,30 @@ begin
9
9
  gem.email = "darrinholst@gmail.com"
10
10
  gem.homepage = "http://github.com/darrinholst/rtomcat"
11
11
  gem.authors = ["Darrin Holst"]
12
- gem.rubyforge_project = "rtomcat"
13
- gem.add_dependency("rest-client", ">= 1.0.3")
12
+ gem.add_dependency("rest-client", ">= 1.0.3")
14
13
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
14
  end
16
15
 
17
- Jeweler::RubyforgeTasks.new
16
+ Jeweler::GemcutterTasks.new
18
17
  rescue LoadError
19
18
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
19
  end
21
20
 
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:test) do |test|
24
- test.libs << 'lib' << 'test'
25
- test.pattern = 'test/**/*_test.rb'
26
- test.verbose = true
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
25
  end
28
26
 
29
- begin
30
- require 'rcov/rcovtask'
31
- Rcov::RcovTask.new do |test|
32
- test.libs << 'test'
33
- test.pattern = 'test/**/*_test.rb'
34
- test.verbose = true
35
- end
36
- rescue LoadError
37
- task :rcov do
38
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
- end
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
40
31
  end
41
32
 
33
+ task :spec => :check_dependencies
42
34
 
43
- task :default => :test
35
+ task :default => :spec
44
36
 
45
37
  require 'rake/rdoctask'
46
38
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,38 +1,41 @@
1
1
  require 'rest_client'
2
2
 
3
3
  class Tomcat::Manager
4
- def initialize(url, username, password)
4
+ def initialize(url, username, password, timeout = nil)
5
5
  @url = url
6
6
  @username = username
7
7
  @password = password
8
+ @timeout = timeout
8
9
  end
9
-
10
+
10
11
  def undeploy(appname)
11
12
  check_response(resource('undeploy', appname).get)
12
13
  end
13
-
14
+
14
15
  def deploy(appname, file)
15
16
  check_response(resource('deploy', appname).put(file))
16
17
  end
17
-
18
+
18
19
  def redeploy(appname, file)
19
20
  begin
20
21
  undeploy(appname)
21
22
  rescue
22
23
  end
23
-
24
+
24
25
  deploy(appname, file)
25
26
  end
26
-
27
+
27
28
  private
28
-
29
+
29
30
  def check_response(response)
30
- match = response.match(/(.*) - .*/)
31
+ match = response.match(/(.*) - .*/)
31
32
  raise("http status code: #{response.code}, message: #{response}") unless match && match[1].eql?("OK")
32
33
  response
33
34
  end
34
35
 
35
36
  def resource(function, appname)
36
- RestClient::Resource.new("#{@url}/#{function}?path=/#{appname}", :user => @username, :password => @password)
37
+ options = {:user => @username, :password => @password}
38
+ options[:timeout] = @timeout if @timeout
39
+ RestClient::Resource.new("#{@url}/#{function}?path=/#{appname}", options)
37
40
  end
38
41
  end
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{rtomcat}
5
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Darrin Holst"]
9
- s.date = %q{2009-07-16}
12
+ s.date = %q{2010-01-28}
10
13
  s.email = %q{darrinholst@gmail.com}
11
14
  s.extra_rdoc_files = [
12
15
  "LICENSE",
@@ -22,18 +25,18 @@ Gem::Specification.new do |s|
22
25
  "lib/manager.rb",
23
26
  "lib/rtomcat.rb",
24
27
  "rtomcat.gemspec",
25
- "test/manager_test.rb",
26
- "test/test_helper.rb"
28
+ "spec/manager_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
27
31
  ]
28
32
  s.homepage = %q{http://github.com/darrinholst/rtomcat}
29
33
  s.rdoc_options = ["--charset=UTF-8"]
30
34
  s.require_paths = ["lib"]
31
- s.rubyforge_project = %q{rtomcat}
32
- s.rubygems_version = %q{1.3.4}
35
+ s.rubygems_version = %q{1.3.5}
33
36
  s.summary = %q{ruby wrapper around the tomcat manager}
34
37
  s.test_files = [
35
- "test/manager_test.rb",
36
- "test/test_helper.rb"
38
+ "spec/manager_spec.rb",
39
+ "spec/spec_helper.rb"
37
40
  ]
38
41
 
39
42
  if s.respond_to? :specification_version then
@@ -49,3 +52,4 @@ Gem::Specification.new do |s|
49
52
  s.add_dependency(%q<rest-client>, [">= 1.0.3"])
50
53
  end
51
54
  end
55
+
@@ -0,0 +1,73 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ module Tomcat
4
+ APP = "appname"
5
+ OK = "OK - some message"
6
+ UNAUTHROIZED = "401 - Unauthorized"
7
+ NOT_FOUND = "404 - Not Found"
8
+
9
+ describe Manager do
10
+ before(:each) do
11
+ @file = mock
12
+ @resource = mock
13
+ @manager = Tomcat::Manager.new("http://localhost:8080", "user", "password")
14
+ end
15
+
16
+ it "should undeploy" do
17
+ expect_new_resource("undeploy").and_return(@resource)
18
+ @resource.should_receive(:get).and_return(OK)
19
+ @manager.undeploy(APP)
20
+ end
21
+
22
+ it "should raise if undeploy doesn't work" do
23
+ UNAUTHROIZED.should_receive(:code).and_return(401)
24
+ expect_new_resource("undeploy").and_return(@resource)
25
+ @resource.should_receive(:get).and_return(UNAUTHROIZED)
26
+ lambda{@manager.undeploy(APP)}.should raise_error("http status code: 401, message: 401 - Unauthorized")
27
+ end
28
+
29
+ it "should deploy" do
30
+ expect_new_resource("deploy").and_return(@resource)
31
+ @resource.should_receive(:put).with(@file).and_return(OK)
32
+ @manager.deploy(APP, @file)
33
+ end
34
+
35
+ it "should raise if deploy doesn't work" do
36
+ UNAUTHROIZED.should_receive(:code).and_return(401)
37
+ expect_new_resource("deploy").and_return(@resource)
38
+ @resource.should_receive(:put).with(@file).and_return(UNAUTHROIZED)
39
+ lambda{@manager.deploy(APP, @file)}.should raise_error("http status code: 401, message: 401 - Unauthorized")
40
+ end
41
+
42
+ it "should redeploy" do
43
+ undeploy_resource = mock
44
+ deploy_resource = mock
45
+ expect_new_resource("undeploy").and_return(undeploy_resource)
46
+ undeploy_resource.should_receive(:get).and_return(OK)
47
+ expect_new_resource("deploy").and_return(deploy_resource)
48
+ deploy_resource.should_receive(:put).with(@file).and_return(OK)
49
+ @manager.redeploy(APP, @file)
50
+ end
51
+
52
+ it "should ignore undeploy errors if redeploying" do
53
+ undeploy_resource = mock
54
+ deploy_resource = mock
55
+ expect_new_resource("undeploy").and_return(undeploy_resource)
56
+ undeploy_resource.should_receive(:get).and_return(NOT_FOUND)
57
+ expect_new_resource("deploy").and_return(deploy_resource)
58
+ deploy_resource.should_receive(:put).with(@file).and_return(OK)
59
+ @manager.redeploy(APP, @file)
60
+ end
61
+
62
+ it "should allow timeout to be specified" do
63
+ @manager = Tomcat::Manager.new("http://localhost:8080", "user", "password", 120)
64
+ expect_new_resource("undeploy", :timeout => 120).and_return(@resource)
65
+ @resource.should_receive(:get).and_return(OK)
66
+ @manager.undeploy(APP)
67
+ end
68
+
69
+ def expect_new_resource(resource, extra_parmas = {})
70
+ RestClient::Resource.should_receive(:new).with("http://localhost:8080/#{resource}?path=/#{APP}", {:user => "user", :password => "password"}.merge(extra_parmas))
71
+ end
72
+ end
73
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -1,12 +1,9 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'fakeweb'
4
-
5
- FakeWeb.allow_net_connect = false
6
-
7
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
3
  require 'rtomcat'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
10
8
 
11
- class Test::Unit::TestCase
12
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtomcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darrin Holst
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-16 00:00:00 -05:00
12
+ date: 2010-01-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,8 +41,9 @@ files:
41
41
  - lib/manager.rb
42
42
  - lib/rtomcat.rb
43
43
  - rtomcat.gemspec
44
- - test/manager_test.rb
45
- - test/test_helper.rb
44
+ - spec/manager_spec.rb
45
+ - spec/spec.opts
46
+ - spec/spec_helper.rb
46
47
  has_rdoc: true
47
48
  homepage: http://github.com/darrinholst/rtomcat
48
49
  licenses: []
@@ -66,11 +67,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  version:
67
68
  requirements: []
68
69
 
69
- rubyforge_project: rtomcat
70
- rubygems_version: 1.3.4
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
71
72
  signing_key:
72
73
  specification_version: 3
73
74
  summary: ruby wrapper around the tomcat manager
74
75
  test_files:
75
- - test/manager_test.rb
76
- - test/test_helper.rb
76
+ - spec/manager_spec.rb
77
+ - spec/spec_helper.rb
@@ -1,80 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ManagerTest < Test::Unit::TestCase
4
- def setup
5
- @manager = Tomcat::Manager.new("http://localhost:8080", "user", "password")
6
- end
7
-
8
- def test_undeploy
9
- FakeWeb.register_uri(:get, undeploy_url, :body => "OK - Undeployed application at context path /appname")
10
- assert_nothing_raised { undeploy }
11
- end
12
-
13
- def test_undeploy_when_not_a_200_status
14
- FakeWeb.register_uri(:get, undeploy_url, :status => ["401", "Unauthorized"])
15
- assert_raises_with("Unauthorized") { undeploy }
16
- end
17
-
18
- def test_undeploy_when_non_ok_response
19
- FakeWeb.register_uri(:get, undeploy_url, :body => "FAIL - some error")
20
- assert_raises_with("http status code: 200, message: FAIL - some error") { undeploy }
21
- end
22
-
23
- def test_deploy
24
- FakeWeb.register_uri(:put, deploy_url, :body => "OK - Deployed application at context path /appname")
25
- assert_nothing_raised { deploy }
26
- end
27
-
28
- def test_deploy_when_not_a_200_status
29
- FakeWeb.register_uri(:put, deploy_url, :status => ["401", "Unauthorized"])
30
- assert_raises_with("Unauthorized") { deploy }
31
- end
32
-
33
- def test_deploy_when_non_ok_response
34
- FakeWeb.register_uri(:put, deploy_url, :body => "FAIL - some error")
35
- assert_raises_with("http status code: 200, message: FAIL - some error") { deploy }
36
- end
37
-
38
- def test_redeploy
39
- FakeWeb.register_uri(:get, undeploy_url, :body => "OK - Undeployed application at context path /appname")
40
- FakeWeb.register_uri(:put, deploy_url, :body => "OK - Deployed application at context path /appname")
41
- assert_nothing_raised { redeploy }
42
- end
43
-
44
- def test_redeploy_ignores_undeploy_errors
45
- FakeWeb.register_uri(:get, undeploy_url, :body => "FAIL - some error")
46
- FakeWeb.register_uri(:put, deploy_url, :body => "OK - Deployed application at context path /appname")
47
- assert_nothing_raised { redeploy }
48
- end
49
-
50
- private
51
-
52
- def undeploy_url
53
- "http://user:password@localhost:8080/undeploy?path=/appname"
54
- end
55
-
56
- def undeploy
57
- @manager.undeploy('appname')
58
- end
59
-
60
- def deploy_url
61
- "http://user:password@localhost:8080/deploy?path=/appname"
62
- end
63
-
64
- def deploy
65
- @manager.deploy('appname', "FakeWeb doesn't allow for put body interrogation right now, so this parameter doesn't matter")
66
- end
67
-
68
- def redeploy
69
- @manager.redeploy('appname', "Some bogus file content")
70
- end
71
-
72
- def assert_raises_with(message)
73
- begin
74
- yield
75
- fail("should have raised")
76
- rescue Exception => e
77
- assert_equal(message, e.message)
78
- end
79
- end
80
- end