taas 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "test-unit"
5
+ gem "mocha"
6
+ gem "shoulda"
7
+ gem "rack-test"
8
+ gem "jeweler"
9
+ gem "pry"
10
+ gem "pry-nav"
11
+ end
12
+
13
+ gem "rake"
14
+ gem "sinatra"
15
+ gem "json"
16
+
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.8)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ coderay (1.0.7)
8
+ git (1.2.5)
9
+ i18n (0.6.1)
10
+ jeweler (1.8.4)
11
+ bundler (~> 1.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ rdoc
15
+ json (1.7.5)
16
+ metaclass (0.0.1)
17
+ method_source (0.7.1)
18
+ mocha (0.11.4)
19
+ metaclass (~> 0.0.1)
20
+ multi_json (1.3.6)
21
+ pry (0.9.9.6)
22
+ coderay (~> 1.0.5)
23
+ method_source (~> 0.7.1)
24
+ slop (>= 2.4.4, < 3)
25
+ pry-nav (0.2.1)
26
+ pry (~> 0.9.9)
27
+ rack (1.4.1)
28
+ rack-protection (1.2.0)
29
+ rack
30
+ rack-test (0.6.2)
31
+ rack (>= 1.0)
32
+ rake (0.9.2.2)
33
+ rdoc (3.12)
34
+ json (~> 1.4)
35
+ shoulda (3.3.1)
36
+ shoulda-context (~> 1.0)
37
+ shoulda-matchers (~> 1.4.1)
38
+ shoulda-context (1.0.1)
39
+ shoulda-matchers (1.4.1)
40
+ activesupport (>= 3.0.0)
41
+ sinatra (1.3.3)
42
+ rack (~> 1.3, >= 1.3.6)
43
+ rack-protection (~> 1.2)
44
+ tilt (~> 1.3, >= 1.3.3)
45
+ slop (2.4.4)
46
+ test-unit (2.4.9)
47
+ tilt (1.3.3)
48
+
49
+ PLATFORMS
50
+ ruby
51
+ x86-mingw32
52
+
53
+ DEPENDENCIES
54
+ jeweler
55
+ json
56
+ mocha
57
+ pry
58
+ pry-nav
59
+ rack-test
60
+ rake
61
+ shoulda
62
+ sinatra
63
+ test-unit
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2012 Anand Bagmar (abagmar@gmail.com).
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = TaaS
2
+
3
+ Typically in organizations, there are multiple projects / products. Organizations like to have a common Test Automation
4
+ solution across these products in an effort to standardize the framework.
5
+
6
+ However, this is not a good idea!
7
+
8
+ Each product should be tested using the tools and technologies that are <b>"right"</b> for it.
9
+
10
+ Yet - these different products talk to each other and you need a way to test the integration between them in an automated fashion.
11
+
12
+ <b>"TaaS"</b> is a product that allows you to validate the integration across a variety of products via Test Automation - the <b>"correct"</b> way.
13
+
14
+ = Documentation
15
+
16
+ Check the doc[https://github.com/anandbagmar/taas/tree/master/doc] folder for information about TaaS and how to use it.
17
+
18
+ == Copyright
19
+
20
+ /**
21
+ * Created by: Anand Bagmar
22
+ * Email: abagmar@gmail.com
23
+ *
24
+ * Copyright 2010 Anand Bagmar. Distributed under the Apache 2.0 License
25
+ *
26
+ * See LICENSE.txt for further details.
27
+ **/
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ $PROJECT_ROOT=File.expand_path(File.dirname(__FILE__))
2
+
3
+ namespace :test do
4
+ desc "run all unit test"
5
+ task :unit do
6
+ Dir['test/**/*_test.rb'].each { |testCase|
7
+ tName = File.join($PROJECT_ROOT, testCase)
8
+ puts "running test: #{tName}"
9
+ load tName
10
+ }
11
+ end
12
+ end
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "taas"
18
+ gem.homepage = "http://github.com/anandbagmar/taas"
19
+ gem.license = "Apache 2.0"
20
+ gem.summary = %q{TaaS}
21
+ gem.description = %q{"TaaS" allows you to validate the integration across a variety of products via Test Automation - the "correct" way. TaaS uses a web service interface to run your end-2-end integration tests between two independent but related system. See the blog for more details: http://goo.gl/nVShb}
22
+ gem.authors = ["Anand Bagmar, Akash Mishra"]
23
+ gem.email = ["abagmar@gmail.com, akash.mishra20@gmail.com"]
24
+ gem.files.exclude "doc/**/*"
25
+ gem.rubyforge_project = "taas"
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,9 @@
1
+ module TaaS
2
+ class CommandExecuter
3
+ def self.execute_command(dir, command)
4
+ return nil if command.nil? || dir.nil? || command.empty? || dir.empty?
5
+ Dir.chdir(dir)
6
+ `#{command}`
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module TaaS
2
+ class Contract
3
+
4
+ def initialize(hash)
5
+ @hash = hash
6
+ end
7
+
8
+ def value_of(key)
9
+ @hash[key]
10
+ end
11
+
12
+ def has_property?(key)
13
+ @hash.has_key?(key)
14
+ end
15
+
16
+ def command(params)
17
+ command = @hash["command"]
18
+ parameter_string = ParameterFactory.generate_parameter_string(@hash["input_param_format"],params)
19
+ command.scan(/<taas_params>/).empty? ? command+parameter_string : command.gsub("<taas_params>",parameter_string)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'pry'
2
+ module TaaS
3
+ class Contracts
4
+
5
+ @@contract_hash = {}
6
+
7
+ def self.load(absolute_path)
8
+ raise "File path cant be nil or empty" if (absolute_path.nil? || absolute_path.empty?)
9
+ @@contract_hash = YAML.load_file(absolute_path)["contracts"] rescue {}
10
+ end
11
+
12
+ def self.is_empty?
13
+ @@contract_hash.eql?({}) || @@contract_hash.nil?
14
+ end
15
+
16
+ def self.contains?(contract_name)
17
+ @@contract_hash.keys.include?(contract_name)
18
+ end
19
+
20
+ def self.get_contract(contract_name)
21
+ return nil unless contains?(contract_name)
22
+ contract = Contract.new @@contract_hash[contract_name]
23
+ contract
24
+ end
25
+
26
+ def self.get_execution_attribute(attribute, contract_name)
27
+ return nil if @@contract_hash.nil? || @@contract_hash.eql?({})
28
+ @@contract_hash["contracts"][contract_name.to_s][attribute]
29
+ end
30
+
31
+ def self.get_all_contracts
32
+ return @@contract_hash
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require "json"
2
+ module TaaS
3
+ class OutputParser
4
+ def self.parse_taas_output(output)
5
+ output.scan(/<TaaS Response Start>(.*)<TaaS Response Complete>/m).first.first rescue nil
6
+ end
7
+
8
+ def self.parse_server_output(response_body)
9
+ return nil unless valid_server_response?(response_body)
10
+ body = response_body.scan(/<Taas-Output>(.*)<\/TaaS-Output>/m).first.first
11
+ response_json = response_body.scan(/<TaaS-Json>(.*)<\/TaaS-Json>/m).first.first
12
+ response_hash = JSON.parse(response_json) rescue nil
13
+ return nil if response_hash.nil?
14
+ return response_hash,body
15
+ end
16
+
17
+ def self.valid_server_response?(response)
18
+ !(response.scan(/<Taas-Output>(.*)<\/TaaS-Output>/m).empty? || response.scan(/<TaaS-Json>(.*)<\/TaaS-Json>/m).empty?)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module TaaS
2
+ class ParameterFactory
3
+ def self.generate_parameter_string(template,params_hash)
4
+ parameter_string = ""
5
+ template = "key=value" if template.nil?
6
+ params_hash.each do |key,value|
7
+ parameter_string += " #{template.gsub("key",key.to_s).gsub("value",value.to_s)}"
8
+ end
9
+ parameter_string
10
+ end
11
+ end
12
+ end
data/lib/server.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "sinatra"
2
+
3
+
4
+ Dir.glob(File.join("#{$PROJECT_ROOT}", "lib","helper", "**", "*.rb")).each do |test_file|
5
+ puts "requiring #{test_file}"
6
+ require "#{test_file}"
7
+ end
8
+
9
+ include TaaS
10
+
11
+ Contracts.load(ARGV[0])
12
+
13
+ post "/contract" do
14
+ response_json = '{"pass":"false","data":{}}'
15
+ output = "Contract Name is either nil or not valid."
16
+ if !params["contract_name"].nil? && !Contracts.is_empty? && Contracts.contains?(params["contract_name"])
17
+ command = Contracts.get_contract(params["contract_name"]).command(params)
18
+ dir = Contracts.get_contract(params["contract_name"]).value_of("dir")
19
+ output = CommandExecuter.execute_command(dir,command)
20
+ response_json = OutputParser.parse_taas_output(output)
21
+ end
22
+ "<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>"
23
+ end
24
+
25
+
26
+ get "/" do
27
+ table_header ="<table width=\"600\" border=\"1\"><tr><th>Contract Name</th><th>Contract parameters</th></tr>"
28
+ table_footer="</table>"
29
+ table_body =""
30
+ Contracts.get_all_contracts.each_pair do |key,value|
31
+ inner_table_body=""
32
+ inner_table_header ="<table width=\"400\" border=\"1\"><tr><th>KEY</th><th>VALUE</th></tr>"
33
+ inner_table_footer="</table>"
34
+ value.each_pair do |key1,value1|
35
+ inner_table_body = inner_table_body + "<tr><td>#{key1}</td><td>#{value1}</td></tr>"
36
+ end
37
+ inner_table = inner_table_header+inner_table_body+inner_table_footer
38
+ table_body = table_body + "<tr><td>#{key}</td><td>#{inner_table}</td></tr>"
39
+ end
40
+ table_header+table_body+table_footer
41
+ end
data/lib/taas.rb ADDED
@@ -0,0 +1,13 @@
1
+
2
+ require "taas_client"
3
+ require File.join($PROJECT_ROOT,"lib","helper","command_executer")
4
+
5
+ module TaaS
6
+ def self.start_server(contract_file)
7
+ CommandExecuter.execute_command(File.dirname(__FILE__),"ruby server.rb #{contract_file}")
8
+ end
9
+
10
+ def self.client(url, timeout)
11
+ TaaSClient.new(url, timeout)
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module TaaS
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require "rubygems"
2
+ require 'uri'
3
+ require 'net/http'
4
+ require "json"
5
+ require File.join($PROJECT_ROOT,"lib","helper","output_parser")
6
+
7
+ module TaaS
8
+ class TaaSClient
9
+
10
+ attr_accessor :url, :timeout
11
+
12
+ def initialize(url, timeout_in_seconds=1000)
13
+ @url = url
14
+ @timeout = timeout_in_seconds * 10000
15
+ end
16
+
17
+ def execute_contract(params={})
18
+ response_body = request_taas_server(params)
19
+
20
+ raise "TaaS Request is false" unless OutputParser.valid_server_response?(response_body)
21
+
22
+ OutputParser.parse_server_output(response_body)
23
+ end
24
+
25
+
26
+
27
+ def request_taas_server(params)
28
+ uri = URI.parse(@url)
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+
31
+ request = Net::HTTP::Post.new(uri.request_uri)
32
+ request.set_form_data(params)
33
+ http.read_timeout = @timeout
34
+ http.request(request).body
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+
data/taas.gemspec ADDED
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "taas"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Anand Bagmar, Akash Mishra"]
12
+ s.date = "2013-04-03"
13
+ s.description = "\"TaaS\" allows you to validate the integration across a variety of products via Test Automation - the \"correct\" way. TaaS uses a web service interface to run your end-2-end integration tests between two independent but related system. See the blog for more details: http://goo.gl/nVShb"
14
+ s.email = ["abagmar@gmail.com, akash.mishra20@gmail.com"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/helper/command_executer.rb",
27
+ "lib/helper/contract.rb",
28
+ "lib/helper/contracts.rb",
29
+ "lib/helper/output_parser.rb",
30
+ "lib/helper/parameter_factory.rb",
31
+ "lib/server.rb",
32
+ "lib/taas.rb",
33
+ "lib/taas/version.rb",
34
+ "lib/taas_client.rb",
35
+ "taas.gemspec",
36
+ "test/helper/command_executer_test.rb",
37
+ "test/helper/contract_test.rb",
38
+ "test/helper/contracts_test.rb",
39
+ "test/helper/output_parser_test.rb",
40
+ "test/helper/parameter_factory_test.rb",
41
+ "test/server_test.rb",
42
+ "test/taas_client_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+ s.homepage = "http://github.com/anandbagmar/taas"
46
+ s.licenses = ["Apache 2.0"]
47
+ s.require_paths = ["lib"]
48
+ s.rubyforge_project = "taas"
49
+ s.rubygems_version = "1.8.24"
50
+ s.summary = "TaaS"
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
57
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
58
+ s.add_runtime_dependency(%q<json>, [">= 0"])
59
+ s.add_development_dependency(%q<test-unit>, [">= 0"])
60
+ s.add_development_dependency(%q<mocha>, [">= 0"])
61
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
63
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
64
+ s.add_development_dependency(%q<pry>, [">= 0"])
65
+ s.add_development_dependency(%q<pry-nav>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<rake>, [">= 0"])
68
+ s.add_dependency(%q<sinatra>, [">= 0"])
69
+ s.add_dependency(%q<json>, [">= 0"])
70
+ s.add_dependency(%q<test-unit>, [">= 0"])
71
+ s.add_dependency(%q<mocha>, [">= 0"])
72
+ s.add_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_dependency(%q<rack-test>, [">= 0"])
74
+ s.add_dependency(%q<jeweler>, [">= 0"])
75
+ s.add_dependency(%q<pry>, [">= 0"])
76
+ s.add_dependency(%q<pry-nav>, [">= 0"])
77
+ end
78
+ else
79
+ s.add_dependency(%q<rake>, [">= 0"])
80
+ s.add_dependency(%q<sinatra>, [">= 0"])
81
+ s.add_dependency(%q<json>, [">= 0"])
82
+ s.add_dependency(%q<test-unit>, [">= 0"])
83
+ s.add_dependency(%q<mocha>, [">= 0"])
84
+ s.add_dependency(%q<shoulda>, [">= 0"])
85
+ s.add_dependency(%q<rack-test>, [">= 0"])
86
+ s.add_dependency(%q<jeweler>, [">= 0"])
87
+ s.add_dependency(%q<pry>, [">= 0"])
88
+ s.add_dependency(%q<pry-nav>, [">= 0"])
89
+ end
90
+ end
91
+
@@ -0,0 +1,21 @@
1
+ require File.join($PROJECT_ROOT, 'lib', 'helper', 'command_executer')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+
5
+ class CommandExecuterTest < Test::Unit::TestCase
6
+ context "execute_contract" do
7
+ should "not execute the contract if dir is nil or empty" do
8
+ assert_nil CommandExecuter.execute_command(nil,"echo 'Hello'")
9
+ assert_nil CommandExecuter.execute_command("","echo 'Hello'")
10
+ end
11
+
12
+ should "not execute the contract if command is nil or empty" do
13
+ assert_nil CommandExecuter.execute_command(Dir.pwd,nil)
14
+ assert_nil CommandExecuter.execute_command(Dir.pwd,"")
15
+ end
16
+
17
+ should "return the executed command output for valid dir and command" do
18
+ assert_equal "Hello\n",CommandExecuter.execute_command(Dir.pwd,"echo 'Hello'").unpack("U*").map{|c|c.chr}.join
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ require File.join($PROJECT_ROOT, 'lib', 'helper', 'contract')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+ class ContractTest < Test::Unit::TestCase
5
+
6
+ context "value_of" do
7
+ should "return the value of the given property of the contract" do
8
+ key, value = ["command","ls"]
9
+ params_hash = {key => value, "dir" => "/home"}
10
+ contract = Contract.new(params_hash)
11
+ assert_equal value,contract.value_of(key)
12
+ end
13
+
14
+ should "return nil if the given property is not present in the contract" do
15
+ contract = Contract.new({})
16
+ assert_nil contract.value_of("key")
17
+ end
18
+ end
19
+
20
+ context "has_property?" do
21
+ should "return true if the property is present in the contract" do
22
+ key, value = ["command","ls"]
23
+ params_hash = {key => value}
24
+ contract = Contract.new(params_hash)
25
+ assert contract.has_property?(key)
26
+ end
27
+ should "return false if the property is not present in the contract" do
28
+ key, value = ["command","ls"]
29
+ params_hash = {key => value}
30
+ contract = Contract.new(params_hash)
31
+ assert_false contract.has_property?("key")
32
+ end
33
+ end
34
+
35
+ context "command" do
36
+ should "return the parameter string replaced in the place of <taas_params> template" do
37
+ command_template = "play <taas_params> test"
38
+ parameter_string = "-Dorder_id=1 -Dname=s"
39
+ contract_hash = {"dir" => "/home", "command" => command_template, "input_param_format" => "-Dkey=value", :input_params =>{:order_id => nil}, :output_params =>{}}
40
+ parameter = {:order_id => 1, :name => "s"}
41
+ contract = Contract.new(contract_hash)
42
+
43
+ ParameterFactory.stubs(:generate_parameter_string).with("-Dkey=value",parameter).returns(parameter_string)
44
+
45
+ assert_equal "play #{parameter_string} test",contract.command(parameter)
46
+ end
47
+
48
+ should "return the parameter string append to command if no <taas_params> template is specified" do
49
+ command_template = "play test"
50
+ parameter_string = "order_id=1 name=s"
51
+ parameter = {:order_id => 1, :name => "s"}
52
+ contract_hash = {"dir" => "/home", "command" => command_template, "input_param_format" => "key=value", :input_params =>{:order_id => nil}, :output_params =>{}}
53
+ contract = Contract.new(contract_hash)
54
+
55
+ ParameterFactory.stubs(:generate_parameter_string).with("key=value",parameter).returns(parameter_string)
56
+
57
+ assert_equal "#{command_template}#{parameter_string}",contract.command(parameter)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,97 @@
1
+ require File.join($PROJECT_ROOT, 'lib', 'helper', 'contracts')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+
5
+ class ContractsTest < Test::Unit::TestCase
6
+
7
+ CONTRACT_HASH = {"contracts"=>{
8
+ "create_live_sale"=>
9
+ {"command"=>"bundle exec cucumber",
10
+ "dir"=>"/home/tworker/work/livesale-automation",
11
+ "input_params"=>{"name"=>nil, "no_of_listing"=>nil},
12
+ "timeout_in_seconds"=>100,
13
+ "output_params"=>{"live_sale_id"=>nil}},
14
+ "end_live_sale"=>
15
+ {"command"=>"bundle exec cucumber",
16
+ "dir"=>"/home/tworker/work/livesale-automation",
17
+ "input_params"=>{"live_sale_id"=>nil},
18
+ "timeout_in_seconds"=>100,
19
+ "output_params"=>{"actual_end_time"=>nil}}}}
20
+
21
+ context "load" do
22
+ should "load the valid contract from contract file" do
23
+ contract_file_absolute_path = "a1/a5"
24
+ YAML.stubs(:load_file).with(contract_file_absolute_path).returns(CONTRACT_HASH)
25
+
26
+ Contracts.load(contract_file_absolute_path)
27
+
28
+ assert_equal false,Contracts.is_empty?
29
+ end
30
+
31
+ should "not load contract if contract file is not present" do
32
+ contract_file_absolute_path = "a1/a2"
33
+ YAML.stubs(:load_file).with(contract_file_absolute_path).returns({})
34
+
35
+ Contracts.load(contract_file_absolute_path)
36
+
37
+ assert_equal true,Contracts.is_empty?
38
+ end
39
+
40
+ should "raise execption if empty or nil contract file is passesd" do
41
+ assert_raise do
42
+ Contracts.load(nil)
43
+ end
44
+ assert_raise do
45
+ Contracts.load("")
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ context "get_contract" do
52
+ setup {
53
+ @contract_file_absolute_path = "a1/a2"
54
+ @contract_name = "create_live_sale"
55
+ }
56
+ should "should return the contract object of given contract" do
57
+ YAML.stubs(:load_file).with(@contract_file_absolute_path).returns(CONTRACT_HASH)
58
+ Contracts.load(@contract_file_absolute_path)
59
+
60
+ assert_equal CONTRACT_HASH["contracts"][@contract_name]["command"],Contracts.get_contract(@contract_name).value_of("command")
61
+ end
62
+
63
+ should "return nil if contract is not present" do
64
+ YAML.stubs(:load_file).with(@contract_file_absolute_path).returns(CONTRACT_HASH)
65
+ Contracts.load(@contract_file_absolute_path)
66
+
67
+ assert_nil Contracts.get_contract("dummy")
68
+ end
69
+ end
70
+
71
+ context "is_valid_contract?" do
72
+ setup {
73
+ @contract_file_absolute_path = "a1/a2"
74
+ @contract_name = :create_live_sale
75
+ YAML.stubs(:load_file).with(@contract_file_absolute_path).returns(CONTRACT_HASH)
76
+ Contracts.load(@contract_file_absolute_path)
77
+ }
78
+ should "return true if requested contract is present" do
79
+ assert Contracts.contains?("create_live_sale")
80
+ end
81
+ should "return false if requested contract is not present" do
82
+ assert_false Contracts.contains?("dummy_contract")
83
+ end
84
+ end
85
+
86
+ context "get_all_contracts" do
87
+ setup {
88
+ @contract_file_absolute_path = "a1/a2"
89
+ @contract_name = :create_live_sale
90
+ YAML.stubs(:load_file).with(@contract_file_absolute_path).returns(CONTRACT_HASH)
91
+ Contracts.load(@contract_file_absolute_path)
92
+ }
93
+ should "return all the contracts" do
94
+ assert_equal CONTRACT_HASH["contracts"],Contracts.get_all_contracts
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,75 @@
1
+ require File.join($PROJECT_ROOT,'lib', 'helper', 'output_parser')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+
5
+ class OutputParserTest < Test::Unit::TestCase
6
+ context "parse_taas_output" do
7
+ should "return TaaS specific parsed json TaaS from the output" do
8
+ response_json = '"paas":"true","data":{}'
9
+ output = "this is core output.<TaaS Response Start>#{response_json}<TaaS Response Complete>"
10
+
11
+ assert_equal OutputParser.parse_taas_output(output),response_json
12
+ end
13
+
14
+ should "return nil if the output format is not correct" do
15
+ response_json = '"paas":"true","data":{}'
16
+ output = "this is core output.#{response_json}<TaaS Response Complete>"
17
+
18
+ assert_nil OutputParser.parse_taas_output(output)
19
+ end
20
+ end
21
+
22
+ context "parse server output" do
23
+ should "return the parameter hash and command output from server dump" do
24
+ output="this is dummy output"
25
+ response_json = '{"paas":"true","data":{}}'
26
+ server_response="<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>"
27
+ response_hash = JSON.parse(response_json)
28
+
29
+ assert_equal [response_hash, output],OutputParser.parse_server_output(server_response)
30
+
31
+ end
32
+
33
+ should "return nil if server dump is not of taas output standard" do
34
+ output="this is dummy output"
35
+ response_json = '{"paas":"true","data":{}}'
36
+ server_response_1="<TaaS-Server-Response>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>"
37
+ server_response_2="<TaaS-Server-Response><Taas-Output>#{output}<TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>"
38
+ server_response_3="<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output>#{response_json}</TaaS-Json></TaaS-Server-Response>"
39
+ server_response_4="<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Server-Response>"
40
+ server_response_5="<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>yello</TaaS-Json></TaaS-Server-Response>"
41
+
42
+ assert_nil OutputParser.parse_server_output(server_response_1)
43
+ assert_nil OutputParser.parse_server_output(server_response_2)
44
+ assert_nil OutputParser.parse_server_output(server_response_3)
45
+ assert_nil OutputParser.parse_server_output(server_response_4)
46
+ assert_nil OutputParser.parse_server_output(server_response_5)
47
+ end
48
+ end
49
+
50
+ context "valid_server_response?" do
51
+
52
+ should "return false if the response is not same as TaaS server template" do
53
+ server_output = "<TaaS-Server-Response>Dummy output</TaaS-Output><TaaS-Json>dummy json</TaaS-Json></TaaS-Server-Response>"
54
+ assert_false OutputParser.valid_server_response?(server_output)
55
+
56
+ server_output = "<TaaS-Server-Response><Taas-Output>Dummy output<TaaS-Json>dummy json</TaaS-Json></TaaS-Server-Response>"
57
+ assert_false OutputParser.valid_server_response?(server_output)
58
+
59
+ server_output = "<TaaS-Server-Response><Taas-Output>Dummy output</TaaS-Output>dummy json</TaaS-Json></TaaS-Server-Response>"
60
+ assert_false OutputParser.valid_server_response?(server_output)
61
+
62
+ server_output = "<TaaS-Server-Response><Taas-Output>Dummy output</TaaS-Output><TaaS-Json>dummy json</TaaS-Server-Response>"
63
+ assert_false OutputParser.valid_server_response?(server_output)
64
+
65
+ end
66
+
67
+ should "return true if the response is not same as TaaS server template" do
68
+ server_output = "<TaaS-Server-Response><Taas-Output>Dummy output</TaaS-Output><TaaS-Json>dummy json</TaaS-Json></TaaS-Server-Response>"
69
+ assert OutputParser.valid_server_response?(server_output)
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+
@@ -0,0 +1,31 @@
1
+ require File.join($PROJECT_ROOT,'lib', 'helper', 'parameter_factory')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+ class ParameterFactoryTest < Test::Unit::TestCase
5
+
6
+ context "generate_parameter_string" do
7
+ should "create command line params string in given template" do
8
+ template ="-Dkey=value"
9
+ params_hash = {:order_id => 1, :name => "s"}
10
+ expected_string = " -Dorder_id=1 -Dname=s"
11
+
12
+ generated_string = ParameterFactory.generate_parameter_string(template,params_hash)
13
+
14
+ assert_true generated_string.include?("-Dorder_id=1")
15
+ assert_true generated_string.include?("-Dname=s")
16
+ puts generated_string.gsub("-Dname=s","").gsub("-Dorder_id=1","")
17
+
18
+ end
19
+
20
+ should "create command line in params in key=value template if no template is specified" do
21
+ params_hash = {:order_id => 1, :name => "s"}
22
+ expected_string = " order_id=1 name=s"
23
+
24
+ generated_string = ParameterFactory.generate_parameter_string(nil,params_hash)
25
+
26
+ assert_true generated_string.include?("order_id=1")
27
+ assert_true generated_string.include?("name=s")
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,109 @@
1
+ require File.join($PROJECT_ROOT, 'lib', 'server')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+ ENV['RACK_ENV']='test'
5
+
6
+ class ServerTest < Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+
9
+ def app
10
+ Sinatra::Application
11
+ end
12
+
13
+ context "post /contract" do
14
+ should "return the pass attribute as false if the contract is not loaded" do
15
+ contract_name = "Do Not Exists"
16
+ file_name = "file_name"
17
+ Contracts.stubs(:load).with(ARGV[0]).returns(file_name)
18
+ Contracts.stubs(:is_empty?).returns(true)
19
+ output = "Contract Name is either nil or not valid."
20
+ response_json = '{"pass":"false","data":{}}'
21
+
22
+ post "/contract", params = {:contract_name => "Do Not Exists"}
23
+
24
+ assert last_response.ok?
25
+ assert_true last_response.body.include?("<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>")
26
+
27
+ end
28
+ should "return the pass attribute as false if the contract is loaded but requested contract is not valid" do
29
+ contract_name = "Do Not Exists"
30
+ file_name = "file_name"
31
+ Contracts.stubs(:load).with(ARGV[0]).returns(file_name)
32
+ Contracts.stubs(:is_empty?).returns(false)
33
+ Contracts.stubs(:contains?).with(contract_name).returns(false)
34
+ output = "Contract Name is either nil or not valid."
35
+ response_json = '{"pass":"false","data":{}}'
36
+
37
+ post "/contract", params = {:contract_name => "Do Not Exists"}
38
+
39
+ assert last_response.ok?
40
+ assert last_response.body.include?("<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>")
41
+
42
+ end
43
+
44
+ should "not return pass attribute as false if the specificed contract do not exist but CONTACT_MANGER is initialized" do
45
+ contract_name = "Do Not Exists"
46
+ file_name = "file_name"
47
+ Contracts.stubs(:load).with(ARGV[0]).returns(file_name)
48
+ Contracts.stubs(:contains?).with(contract_name).returns(false)
49
+ output = "Contract Name is either nil or not valid."
50
+ response_json = '{"pass":"false","data":{}}'
51
+
52
+ post "/contract", params = {:contract_name => "Do Not Exists"}
53
+
54
+ assert last_response.ok?
55
+ assert last_response.body.include?("<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>")
56
+ end
57
+
58
+
59
+
60
+ should "return the raw output from the executed contract" do
61
+ command = "a"
62
+ dir = "/taas/executiondir"
63
+ response_json = '{"pass":"true","data":{"params1":"value1","params2":"value2"}'
64
+ output = "All files and dir<TaaS Response Start>#{response_json}<TaaS Response Complete>"
65
+ contract_name = "Contract Exists"
66
+ params = {"contract_name" => contract_name}
67
+ contract = Contract.new({})
68
+ file_name = "file_name"
69
+ Contracts.stubs(:load).with(ARGV[0]).returns(file_name)
70
+ Contracts.stubs(:is_empty?).returns(false)
71
+ Contracts.stubs(:contains?).with(contract_name).returns(true)
72
+ Contracts.stubs(:get_contract).with(contract_name).returns(contract)
73
+ Contract.any_instance.stubs(:command).with(params).returns(command)
74
+ Contract.any_instance.stubs(:value_of).with("dir").returns(dir)
75
+ CommandExecuter.stubs(:execute_command).with(dir,command).returns(output)
76
+ OutputParser.stubs(:parse_taas_output).with(output).returns(response_json)
77
+
78
+ post "/contract", params
79
+
80
+ assert last_response.ok?
81
+ assert last_response.body.include?("<TaaS-Server-Response><Taas-Output>#{output}</TaaS-Output><TaaS-Json>#{response_json}</TaaS-Json></TaaS-Server-Response>")
82
+ end
83
+ end
84
+
85
+
86
+ context "get /" do
87
+
88
+ should "display the table version of the loaded Contracts" do
89
+ contract_name = "Do Not Exists"
90
+ file_name = "file_name_get"
91
+ Contracts.stubs(:load).with(ARGV[0]).returns(file_name)
92
+ Contracts.stubs(:get_all_contracts).returns({"c1" => {"command" => "one","dir"=>"pwd"},"c2" => {"command" => "two","dir"=>"pwd1"} })
93
+
94
+ get "/"
95
+
96
+ assert last_response.ok?
97
+ assert_true last_response.body.include?("command")
98
+ assert_true last_response.body.include?("c1")
99
+ assert_true last_response.body.include?("one")
100
+ assert_true last_response.body.include?("pwd")
101
+ assert_true last_response.body.include?("pwd")
102
+ assert_true last_response.body.include?("c2")
103
+ assert_true last_response.body.include?("two")
104
+ assert_true last_response.body.include?("pwd1")
105
+
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,64 @@
1
+ require File.join($PROJECT_ROOT, 'lib', 'taas_client')
2
+ require File.join($PROJECT_ROOT, 'test',"test_helper")
3
+
4
+
5
+ class TaaSClientTest < Test::Unit::TestCase
6
+
7
+ context "execute_contract" do
8
+ setup do
9
+ @taas_client = TaaSClient.new("http://taas-url.com/")
10
+ @params = {:contract_name => "create_xyz", :params => {:params_one => "one", :params_n => "params n"}}
11
+ @response_json = '"pass":"true","data":{}'
12
+ @hash = {:pass => true, :data => {}}
13
+ @output="This is a Dummy Output"
14
+ @server_output = "<TaaS-Server-Response><Taas-Output>#{@output}</TaaS-Output><TaaS-Json>#{@response_json}</TaaS-Json></TaaS-Server-Response>"
15
+ end
16
+ should "return hash and command output of server if failed is false" do
17
+ @taas_client.stubs(:request_taas_server).with(@params).returns(@server_output)
18
+ OutputParser.stubs(:valid_server_response?).with(@server_output).returns(true)
19
+ values = lambda {return @output,@hash}
20
+ OutputParser.stubs(:parse_server_output).with(@server_output).returns(values.call)
21
+
22
+ command_output, response_hash = @taas_client.execute_contract(@params)
23
+
24
+ assert_equal command_output,@output
25
+ assert_equal response_hash, @hash
26
+ end
27
+
28
+
29
+ should "raise an error if validate_server returns false" do
30
+ @taas_client.stubs(:request_taas_server).with(@params).returns(@server_output)
31
+ OutputParser.stubs(:valid_server_response?).with(@server_output).returns(false)
32
+
33
+ assert_raise do
34
+ @taas_client.execute_contract(@params)
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+
41
+ context "request_taas_server" do
42
+ should "return the body of the taas server response" do
43
+ input_params = {:name => "taas"}
44
+ output_params = {"id"=>1, "json_response"=>{}}
45
+ taas_client = TaaSClient.new("http://localhost:4567/")
46
+
47
+ uri = URI.parse("http://localhost:4567/")
48
+ URI.stubs(:parse).with("http://localhost:4567/").returns(uri)
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ Net::HTTP.stubs(:new).with(uri.host,uri.port).returns(http)
51
+ stub_request = Net::HTTP::Post.new(uri.request_uri)
52
+ Net::HTTP::Post.stubs(:new).with(uri.request_uri).returns(stub_request)
53
+ stub_request.stubs(:set_form_data).with(input_params).returns(true)
54
+ stub_request.stubs(:read_timeout=).with(1000*10000).returns(true)
55
+
56
+ command_output = "This is command output"
57
+ response = "<Taas command output start>#{command_output}<Taas command output ends>{\"id\":1,\"json_response\":{}}"
58
+ http.stubs(:request).with(stub_request).returns(response)
59
+ response.stubs(:body).returns(response)
60
+
61
+ assert response,taas_client.request_taas_server(input_params)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "yaml"
4
+ require "mocha"
5
+ require "json"
6
+ require "rack/test"
7
+ require "shoulda"
8
+
9
+ include TaaS
10
+
11
+
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taas
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Anand Bagmar, Akash Mishra
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-04-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ requirement: *id001
31
+ prerelease: false
32
+ name: rake
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ requirement: *id002
45
+ prerelease: false
46
+ name: sinatra
47
+ type: :runtime
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirement: *id003
59
+ prerelease: false
60
+ name: json
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirement: *id004
73
+ prerelease: false
74
+ name: test-unit
75
+ type: :development
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirement: *id005
87
+ prerelease: false
88
+ name: mocha
89
+ type: :development
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirement: *id006
101
+ prerelease: false
102
+ name: shoulda
103
+ type: :development
104
+ - !ruby/object:Gem::Dependency
105
+ version_requirements: &id007 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirement: *id007
115
+ prerelease: false
116
+ name: rack-test
117
+ type: :development
118
+ - !ruby/object:Gem::Dependency
119
+ version_requirements: &id008 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ requirement: *id008
129
+ prerelease: false
130
+ name: jeweler
131
+ type: :development
132
+ - !ruby/object:Gem::Dependency
133
+ version_requirements: &id009 !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ requirement: *id009
143
+ prerelease: false
144
+ name: pry
145
+ type: :development
146
+ - !ruby/object:Gem::Dependency
147
+ version_requirements: &id010 !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirement: *id010
157
+ prerelease: false
158
+ name: pry-nav
159
+ type: :development
160
+ description: "\"TaaS\" allows you to validate the integration across a variety of products via Test Automation - the \"correct\" way. TaaS uses a web service interface to run your end-2-end integration tests between two independent but related system. See the blog for more details: http://goo.gl/nVShb"
161
+ email:
162
+ - abagmar@gmail.com, akash.mishra20@gmail.com
163
+ executables: []
164
+
165
+ extensions: []
166
+
167
+ extra_rdoc_files:
168
+ - LICENSE.txt
169
+ - README.rdoc
170
+ files:
171
+ - Gemfile
172
+ - Gemfile.lock
173
+ - LICENSE.txt
174
+ - README.rdoc
175
+ - Rakefile
176
+ - VERSION
177
+ - lib/helper/command_executer.rb
178
+ - lib/helper/contract.rb
179
+ - lib/helper/contracts.rb
180
+ - lib/helper/output_parser.rb
181
+ - lib/helper/parameter_factory.rb
182
+ - lib/server.rb
183
+ - lib/taas.rb
184
+ - lib/taas/version.rb
185
+ - lib/taas_client.rb
186
+ - taas.gemspec
187
+ - test/helper/command_executer_test.rb
188
+ - test/helper/contract_test.rb
189
+ - test/helper/contracts_test.rb
190
+ - test/helper/output_parser_test.rb
191
+ - test/helper/parameter_factory_test.rb
192
+ - test/server_test.rb
193
+ - test/taas_client_test.rb
194
+ - test/test_helper.rb
195
+ homepage: http://github.com/anandbagmar/taas
196
+ licenses:
197
+ - Apache 2.0
198
+ post_install_message:
199
+ rdoc_options: []
200
+
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ none: false
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ hash: 3
209
+ segments:
210
+ - 0
211
+ version: "0"
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ hash: 3
218
+ segments:
219
+ - 0
220
+ version: "0"
221
+ requirements: []
222
+
223
+ rubyforge_project: taas
224
+ rubygems_version: 1.8.24
225
+ signing_key:
226
+ specification_version: 3
227
+ summary: TaaS
228
+ test_files: []
229
+