<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe IControl::LocalLB::ProfileHttpClass do

  before do
    @profile = IControl::LocalLB::ProfileHttpClass.find("test_profile1")
    @profile2 = IControl::LocalLB::ProfileHttpClass.find("test_profile2")
    @arguments = {"host" => "test.com","cookie" => "test_cookie","header" => "test_header", "path" => "/test/path"}
  end
  
  describe "find method" do

    it "should have a find class method called find" do 
      IControl::LocalLB::ProfileHttpClass.methods.should include(:find)
    end

    it "should return an array of IControl::LocalLB::ProfileHttpClass instances when find(:all) is called" do
      profiles = IControl::LocalLB::ProfileHttpClass.find(:all)
      profiles.class.should be(Array)
      profiles[0].class.should be(IControl::LocalLB::ProfileHttpClass)
    end

    it "should return the first element when called with :first argument" do
      @profile.class.should be(IControl::LocalLB::ProfileHttpClass)
    end

  end

  describe "path_match_pattern" do

    it "should allow retreive its associated path_match_patterns" do
      @profile.path_match_pattern.class.should be(Array)
    end


    it "should allow retreive its associated path_match_patterns" do
      @profile.host_match_pattern.class.should be(Array)
    end
  end


  describe "base_profile? method" do

    it "should return a boolean value" do 
      @profile.base_profile?.should be_equal(false)
    end

  end

  describe "default_profile method" do 

    it "should exist" do
      @profile.default_profile.should_not be_nil
    end

    it "should result another profile" do 
      @profile.default_profile.class.should be(IControl::LocalLB::ProfileHttpClass)
    end

    it "should return a base profile" do
      @profile.default_profile.base_profile?.should be_equal(true)
    end

  end

  ["host","cookie","header","path"].each do |type|
    
    describe "#{type}_match_pattern method" do 
      
      it "should exist" do
        @profile2.methods.should include("#{type}_match_pattern".to_sym)
      end
      
      it "should return an Array" do
        @profile2.send("#{type}_match_pattern").class.should be(Array)      
      end
      
      it "should not contents any nil value in the Array" do
        @profile2.send("#{type}_match_pattern").should_not include(nil)
      end
      
      it "should return valid values" do
        patterns = @profile2.send("#{type}_match_pattern")
        patterns.length.should be_>(1)
        patterns.first[:pattern].should_not be nil      
      end
    end
    
    describe "set_default_#{type}_match_pattern method" do 

      it "should exist" do
        @profile2.methods.should include("set_default_#{type}_match_pattern".to_sym)
      end
      
      it "should return an empty array" do 
        value = @profile2.send("set_default_#{type}_match_pattern")
        value.class.should be(Array)
      end

      it "should empty the contents of the array after called" do
        register_conversation ["IControl.LocalLB.ProfileHttpClass_before_deletion.get_#{type}_match_pattern",
                               "IControl.LocalLB.ProfileHttpClass_after_deletion.get_#{type}_match_pattern"]
        pattern = @profile.send"get_#{type}_match_pattern"
        pattern.length.should_not be 0
        pattern = @profile.send("set_default_#{type}_match_pattern")
        pattern.length.should be 0
      end
    end

    ["add","remove"].each do |op|
            
      describe "#{op}_#{type}_host_match_pattern method" do 
      
        it "should exist" do
          @profile2.methods.should include("#{op}_#{type}_match_pattern".to_sym)
        end
      
        it "sould return the recently created pattern if it correctly adds it" do
          pattern = "test_#{type}"
          result = @profile2.send("#{op}_#{type}_match_pattern",pattern,true)
          result["pattern"].should ==(pattern)
          result["is_glob"].should be(true)
        end
        
        it "sould allow the addition of string patterns as well" do
          pattern = "test_#{type}-regexp"
          result = @profile2.send("#{op}_#{type}_match_pattern",pattern)
          result["pattern"].should ==(pattern)
          result["is_glob"].should be(false)
        end    
        
        it "should #{op} a new #{type} pattern" do
          register_conversation ["IControl.LocalLB.ProfileHttpClass_before_#{op}.get_#{type}_match_pattern",
                                 "IControl.LocalLB.ProfileHttpClass_after_#{op}.get_#{type}_match_pattern"]
          match_pattern =  @profile.send("#{type}_match_pattern")
          case op
          when "add" then 
            match_pattern.length.should be 0 
          when "remove" then  
            match_pattern.length.should > 0
            match_pattern.first[:pattern].should ==@arguments[type]
          end
          lambda { @profile.send("#{op}_#{type}_match_pattern",@arguments[type])}.should_not raise_exception
          match_pattern =  @profile.send("#{type}_match_pattern")
          case op
          when "add" then 
            match_pattern.length.should_not be 0
            match_pattern.first[:pattern].should ==@arguments[type]
          when "remove" then 
            match_pattern.length.should be 0
          end
        end
      end
      
    end
  end
  
  describe "default_profile= method" do <commit_msg>Changed the tests according to the last not backward compatible changes<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe IControl::LocalLB::ProfileHttpClass do

  before do
    @profile = IControl::LocalLB::ProfileHttpClass.find("test_profile1")
    @profile2 = IControl::LocalLB::ProfileHttpClass.find("test_profile2")
    @arguments = {"host" => "test.com","cookie" => "test_cookie","header" => "test_header", "path" => "/test/path"}
  end
  
  describe "find method" do

    it "should have a find class method called find" do 
      IControl::LocalLB::ProfileHttpClass.methods.should include(:find)
    end

    it "should return an array of IControl::LocalLB::ProfileHttpClass instances when find(:all) is called" do
      profiles = IControl::LocalLB::ProfileHttpClass.find(:all)
      profiles.class.should be(Array)
      profiles[0].class.should be(IControl::LocalLB::ProfileHttpClass)
    end

    it "should return the first element when called with :first argument" do
      @profile.class.should be(IControl::LocalLB::ProfileHttpClass)
    end

  end

  describe "path_match_pattern" do

    it "should allow retreive its associated path_match_patterns" do
      @profile.path_match_pattern.class.should be(Array)
    end


    it "should allow retreive its associated path_match_patterns" do
      @profile.host_match_pattern.class.should be(Array)
    end
  end


  describe "base_profile? method" do

    it "should return a boolean value" do 
      @profile.base_profile?.should be_equal(false)
    end

  end

  describe "default_profile method" do 

    it "should exist" do
      @profile.default_profile.should_not be_nil
    end

    it "should result another profile" do 
      @profile.default_profile.class.should be(IControl::LocalLB::ProfileHttpClass)
    end

    it "should return a base profile" do
      @profile.default_profile.base_profile?.should be_equal(true)
    end

  end

  ["host","cookie","header","path"].each do |type|
    
    describe "#{type}_match_pattern method" do 
      
      it "should exist" do
        @profile2.methods.should include("#{type}_match_pattern".to_sym)
      end
      
      it "should return an Array" do
        @profile2.send("#{type}_match_pattern").class.should be(Array)      
      end
      
      it "should not contents any nil value in the Array" do
        @profile2.send("#{type}_match_pattern").should_not include(nil)
      end
      
      it "should return valid values" do
        patterns = @profile2.send("#{type}_match_pattern")
        patterns.length.should be_>(1)
        patterns.first.pattern.should_not be nil      
      end
    end
    
    describe "set_default_#{type}_match_pattern method" do 

      it "should exist" do
        @profile2.methods.should include("set_default_#{type}_match_pattern".to_sym)
      end
      
      it "should return an empty array" do 
        value = @profile2.send("set_default_#{type}_match_pattern")
        value.class.should be(Array)
      end

      it "should empty the contents of the array after called" do
        register_conversation ["IControl.LocalLB.ProfileHttpClass_before_deletion.get_#{type}_match_pattern",
                               "IControl.LocalLB.ProfileHttpClass_after_deletion.get_#{type}_match_pattern"]
        pattern = @profile.send"get_#{type}_match_pattern"
        pattern.length.should_not be 0
        pattern = @profile.send("set_default_#{type}_match_pattern")
        pattern.length.should be 0
      end
    end

    ["add","remove"].each do |op|
            
      describe "#{op}_#{type}_host_match_pattern method" do 
      
        it "should exist" do
          @profile2.methods.should include("#{op}_#{type}_match_pattern".to_sym)
        end
      
        it "sould return the recently created pattern if it correctly adds it" do
          pattern = IControl::LocalLB::MatchPatternString.new(:pattern => "test_#{type}", :is_glob => true)
          result = @profile2.send("#{op}_#{type}_match_pattern",pattern)
          result.pattern.should ==(pattern.pattern)
          result.is_glob.should be(true)
        end
        
        it "sould allow the addition of string patterns as well" do
          
          pattern = IControl::LocalLB::MatchPatternString.new(:pattern => "test_#{type}-regexp")
          result = @profile2.send("#{op}_#{type}_match_pattern",pattern)
          result.pattern.should ==(pattern.pattern)
          result.is_glob.should be(false)
        end    
        
        it "should #{op} a new #{type} pattern" do
          register_conversation ["IControl.LocalLB.ProfileHttpClass_before_#{op}.get_#{type}_match_pattern",
                                 "IControl.LocalLB.ProfileHttpClass_after_#{op}.get_#{type}_match_pattern"]
          match_pattern =  @profile.send("#{type}_match_pattern")
          case op
          when "add" then 
            match_pattern.length.should be 0 
          when "remove" then  
            match_pattern.length.should > 0
            match_pattern.first.pattern.should ==@arguments[type]
          end
          lambda { @profile.send("#{op}_#{type}_match_pattern",IControl::LocalLB::MatchPatternString.new(:pattern => @arguments[type]))}.should_not raise_exception
          match_pattern =  @profile.send("#{type}_match_pattern")
          case op
          when "add" then 
            match_pattern.length.should_not be 0
            match_pattern.first.pattern.should ==@arguments[type]
          when "remove" then 
            match_pattern.length.should be 0
          end
        end
      end
      
    end
  end
  
  describe "default_profile= method" do 
{'fraction_non_alphanumeric': 0.10485979623117843, 'fraction_numerical': 0.0036065278153457757, 'mean_word_length': 2.7536379018612522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6713525', 'n_tokens_mistral': 3232, 'n_tokens_neox': 3165, 'n_words': 737}