Class: CukeParser::ParseEngine::JsonParser
- Inherits:
-
Object
- Object
- CukeParser::ParseEngine::JsonParser
- Defined in:
- lib/parse_engine/json_parser.rb
Instance Method Summary collapse
- #get_build(file_path, cuke_data) ⇒ Object
- #get_complete_build(file_path, cuke_data, env_data) ⇒ Object
- #get_jenkins_build_list(file_path, build_stamp) ⇒ Object
-
#initialize ⇒ JsonParser
constructor
A new instance of JsonParser.
- #parse_build(file_path) ⇒ Object
- #parse_features(features) ⇒ Object
- #parse_scenarios(scenarios) ⇒ Object
- #parse_steps(steps) ⇒ Object
Constructor Details
#initialize ⇒ JsonParser
Returns a new instance of JsonParser.
7 8 9 10 11 |
# File 'lib/parse_engine/json_parser.rb', line 7 def initialize @utils = ParserUtils.new @system_data_path = "/archive/systemData.json" @cuke_data = "/archive/cucumber.json" end |
Instance Method Details
#get_build(file_path, cuke_data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/parse_engine/json_parser.rb', line 13 def get_build(file_path,cuke_data) file_path = file_path + "/" + cuke_data + ".json" if File.exists?(file_path) today = Time.now date = today.to_s.split(" ")[0] time = today.to_s.split(" ")[1] time.gsub!(":","-") @cur_build = CukeModel::CukeSuite.new(date,time,today,nil,nil,nil,nil,nil) return parse_build(file_path) else #nothing was found return false end end |
#get_complete_build(file_path, cuke_data, env_data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/parse_engine/json_parser.rb', line 28 def get_complete_build(file_path,cuke_data,env_data) cuke_file_path = file_path + "/" + cuke_data + ".json" system_data_file_path = file_path + "/" + env_data + ".json" if File.exists?(cuke_file_path) and File.exists?(system_data_file_path) today = Time.now date = today.to_s.split(" ")[0] time = today.to_s.split(" ")[1] time.gsub!(":","-") system_data = JSON.parse(File.read(system_data_file_path)) @cur_build = CukeModel::CukeSuite.new(date,time,today,system_data['mobilizer_build_tag'],system_data['mobilizer'],system_data['os'],system_data['url'],system_data['browser']) return parse_build(cuke_file_path) else #nothing was found return false end end |
#get_jenkins_build_list(file_path, build_stamp) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/parse_engine/json_parser.rb', line 117 def get_jenkins_build_list(file_path,build_stamp) build_list = [] dir_path = file_path + "/builds" dir = @utils.dir_purge(dir_path,build_stamp) if dir.kind_of?(Array) dir.each do |build_folder| cur_path = dir_path + "/" + build_folder system_data_file_path = cur_path + @system_data_path cuke_file_path = cur_path + @cuke_data if Dir.exists?(cur_path) and File.exists?(system_data_file_path) and File.exists?(cuke_file_path) and (File.size(cuke_file_path) > 1024) = @utils.parse_time(build_folder.split("_")) system_data_file = File.read(system_data_file_path) system_data = JSON.parse(system_data_file) #mobilizer_build_tag, mobilizer, os, url, browser @cur_build = CukeModel::CukeSuite.new(['date'],['time'],['runstamp'],system_data['mobilizer_build_tag'],system_data['mobilizer'],system_data['os'],system_data['url'],system_data['browser']) #now we have the cucumber.json file location, lets process it build_list.push(parse_build(cuke_file_path)) end end return build_list else return false end end |
#parse_build(file_path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/parse_engine/json_parser.rb', line 45 def parse_build(file_path) document = JSON.parse(File.read(file_path)) features = parse_features(document) if @cur_build.status.empty? #all the steps passed @cur_build.status = "passed" end @cur_build.duration = features['duration'] @cur_build.converted_duration = @utils.format_time(features['duration']) @cur_build.features = features['list'] return @cur_build end |
#parse_features(features) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/parse_engine/json_parser.rb', line 58 def parse_features(features) feature_data = Hash['duration', 0, 'list', Array.new] features.each do |feature| @cur_feature = CukeModel::CukeFeature.new(feature['keyword'],feature['name']) scenarios = parse_scenarios(feature['elements']) if @cur_feature.status.empty? #all the steps passed @cur_feature.status = "passed" end @cur_feature.duration = scenarios['duration'] @cur_feature.converted_duration = @utils.format_time(scenarios['duration']) @cur_feature.scenarios = scenarios['list'] feature_data['list'].push(@cur_feature) feature_data['duration'] = feature_data['duration'] + @cur_feature.duration end return feature_data end |
#parse_scenarios(scenarios) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/parse_engine/json_parser.rb', line 76 def parse_scenarios(scenarios) scenario_data = Hash['duration', 0, 'list', Array.new] scenarios.each do |scenario| @cur_scenario = CukeModel::CukeScenario.new(scenario['keyword'],scenario['name']) steps = parse_steps(scenario['steps']) if @cur_scenario.status.empty? #all the steps passed @cur_scenario.status = "passed" end @cur_scenario.duration = steps['duration'] @cur_scenario.converted_duration = @utils.format_time(steps['duration']) @cur_scenario.steps = steps['list'] scenario_data['list'].push(@cur_scenario) scenario_data['duration'] = scenario_data['duration'] + @cur_scenario.duration end return scenario_data end |
#parse_steps(steps) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/parse_engine/json_parser.rb', line 94 def parse_steps(steps) step_data = Hash['duration', 0, 'list', Array.new] steps.each do |step| stepErrorMessage = '' stepFailureImage = '' step_data['duration'] = step_data['duration'] + step['result']['duration'] dur = step['result']['duration'] convDur = @utils.format_time(dur) if step['result']['status'] == "failed" @cur_scenario.status = "failed" @cur_feature.status = "failed" @cur_build.status = "failed" stepErrorMessage = step['result']['error_message'] #failed steps should have an image available: unless step['embeddings'].nil? stepFailureImage = step['embeddings'][0]['data'] end end step_data['list'].push(CukeModel::CukeStep.new(step['keyword'],step['name'],dur,convDur,step['result']['status'],stepErrorMessage,stepFailureImage)) end return step_data end |