<commit_before>require "spec_helper"

module MiqAeDiscoverySpec
  include MiqAeEngine
  describe "MiqAeDiscovery" do
    before(:each) do
      # admin user is needed to process Events
      @admin = FactoryGirl.create(:user_with_group, :userid => "admin", :name => "Administrator")
      @tenant = Tenant.root_tenant
      @group  = FactoryGirl.create(:miq_group, :tenant => @tenant)
      @ems    = FactoryGirl.create(:ext_management_system, :tenant => @tenant)
      @vm     = FactoryGirl.create(:vm_vmware, :miq_group => @group)
      @event  = FactoryGirl.create(:ems_event, :event_type => "CreateVM_Task_Complete",
                                  :source => "VC", :ems_id => @ems.id, :vm_or_template_id => @vm.id)
      @domain = "SPEC_DOMAIN"
      @model_data_dir = File.join(File.dirname(__FILE__), "data")
      EvmSpecHelper.import_yaml_model(File.join(@model_data_dir, "discovery"), @domain)
    end

    it "properly processes MiqAeEvent.raise_ems_event" do
      MiqAeEngine.should_receive(:deliver_queue)
      MiqAeEvent.raise_ems_event(@event)
    end

    context "automate deliver" do
      let(:workspace) { instance_double("MiqAeEngine::MiqAeWorkspace", :root => options) }
      let(:options) { {'test' => true} }

      it "check automate parameters" do
        attrs = {:event_id                  => @event.id,
                 :event_type                => @event.event_type,
                 "ExtManagementSystem::ems" => @ems.id,
                 :ems_id                    => @ems.id,
                 "VmOrTemplate::vm"         => @vm.id,
                 :vm_id                     => @vm.id,
        }

        args = {:object_type      => "EmsEvent",
                :object_id        => @event.id,
                :attrs            => attrs,
                :instance_name    => "Event",
                :user_id          => @admin.id,
                :miq_group_id     => @group.id,
                :tenant_id        => @tenant.id,
                :automate_message => nil}

        MiqAeEngine.should_receive(:deliver).with(args).and_return(workspace)
        ws = MiqAeEvent.raise_ems_event(@event)
        expect(ws.root['test']).to be_true
      end
    end

    it "properly processes Vm Scan Request" do
      ws = MiqAeEngine.instantiate("/EVM/VMSCAN/foo?target_vm_id=#{@vm.id}", @admin)
      ws.should_not be_nil
    end
  end
end
<commit_msg>Changes to test cases due to admin user is required to raise an event to automate.<commit_after>require "spec_helper"

module MiqAeDiscoverySpec
  include MiqAeEngine
  describe "MiqAeDiscovery" do
    before(:each) do
      # admin user is needed to process Events
      @admin = FactoryGirl.create(:user_with_group, :userid => "admin", :name => "Administrator")
      @tenant = Tenant.root_tenant
      @group  = FactoryGirl.create(:miq_group, :tenant => @tenant)
      @ems    = FactoryGirl.create(:ext_management_system, :tenant => @tenant)
      @vm     = FactoryGirl.create(:vm_vmware, :miq_group => @group)
      @event  = FactoryGirl.create(:ems_event, :event_type => "CreateVM_Task_Complete",
                                  :source => "VC", :ems_id => @ems.id, :vm_or_template_id => @vm.id)
      @domain = "SPEC_DOMAIN"
      @model_data_dir = File.join(File.dirname(__FILE__), "data")
      EvmSpecHelper.import_yaml_model(File.join(@model_data_dir, "discovery"), @domain)
    end

    it "properly processes MiqAeEvent.raise_ems_event" do
      MiqAeEngine.should_receive(:deliver_queue)
      MiqAeEvent.raise_ems_event(@event)
    end

    context "automate deliver" do
      it "check automate parameters" do
        attrs = {:event_id                  => @event.id,
                 :event_type                => @event.event_type,
                 "ExtManagementSystem::ems" => @ems.id,
                 :ems_id                    => @ems.id,
                 "VmOrTemplate::vm"         => @vm.id,
                 :vm_id                     => @vm.id,
        }

        args = {:object_type      => "EmsEvent",
                :object_id        => @event.id,
                :attrs            => attrs,
                :instance_name    => "Event",
                :user_id          => @admin.id,
                :miq_group_id     => @group.id,
                :tenant_id        => @tenant.id,
                :automate_message => nil}

        MiqAeEngine.should_receive(:deliver).with(args).and_return(workspace)
        ws = MiqAeEvent.raise_ems_event(@event)
        expect(ws.root['test']).to be_true
      end
    end

    it "properly processes Vm Scan Request" do
      ws = MiqAeEngine.instantiate("/EVM/VMSCAN/foo?target_vm_id=#{@vm.id}", @admin)
      ws.should_not be_nil
    end
  end
end

{'fraction_non_alphanumeric': 0.12117996604414262, 'fraction_numerical': 0.0, 'mean_word_length': 2.0426081342801807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4713303', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1475, 'n_words': 274}