class CukeParser::ParseEngine::JsonParser

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

get_build(file_path,cuke_data) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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)
                                timestamp = @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(timestamp['date'],timestamp['time'],timestamp['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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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