/*
 * Copyright 2017 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.drools.compiler.integrationtests.operators;

import org.drools.compiler.CommonTestMethodBase;
import org.drools.compiler.Person;
import org.junit.Test;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;

public class SoundsLikeTest extends CommonTestMethodBase {

    @Test
    public void testSoundsLike() {
        // JBRULES-2991: Operator soundslike is broken

        final String str = "package org.drools.compiler\n" +
                "rule SoundsLike\n" +
                "when\n" +
                "    Person( name soundslike \"Bob\" )\n" +
                "then\n" +
                "end";

        final KieBase kbase = loadKnowledgeBaseFromString(str);
        final KieSession ksession = createKnowledgeSession(kbase);

        ksession.insert(new Person("Bob"));
        ksession.insert(new Person("Mark"));

        final int rules = ksession.fireAllRules();
        assertEquals(1, rules);
    }

}

@@ -673,16 +673,49 @@
 ators;%0A%0A
+import java.util.stream.Stream;%0A%0A
 import o
@@ -1054,27 +1054,1509 @@
     
-final String str = 
+testFiredRules(%22package org.drools.compiler%5Cn%22 +%0A                               %22rule SoundsLike%5Cn%22 +%0A                               %22when%5Cn%22 +%0A                               %22    Person( name soundslike %5C%22Bob%5C%22 )%5Cn%22 +%0A                               %22then%5Cn%22 +%0A                               %22end%22,%0A                       1,%0A                       %22Mark%22,%0A                       %22Bob%22);%0A    %7D%0A%0A    @Test%0A    public void testSoundsLikeNegativeCase() %7B%0A        // JBRULES-2991: Operator soundslike is broken%0A%0A        testFiredRules(%22package org.drools.compiler%5Cn%22 +%0A                               %22rule SoundsLike%5Cn%22 +%0A                               %22when%5Cn%22 +%0A                               %22    Person( name soundslike %5C%22Bob%5C%22 )%5Cn%22 +%0A                               %22then%5Cn%22 +%0A                               %22end%22,%0A                       0,%0A                       %22Mark%22);%0A    %7D%0A%0A    @Test%0A    public void testNotSoundsLike() %7B%0A        // JBRULES-2991: Operator soundslike is broken%0A%0A        testFiredRules(%22package org.drools.compiler%5Cn%22 +%0A                               %22rule NotSoundsLike%5Cn%22 +%0A                               %22when%5Cn%22 +%0A                               %22    Person( name not soundslike %5C%22Bob%5C%22 )%5Cn%22 +%0A                               %22then%5Cn%22 +%0A                               %22end%22,%0A                       1,%0A                       %22John%22);%0A    %7D%0A%0A    @Test%0A    public void testNotSoundsLikeNegativeCase() %7B%0A        // JBRULES-2991: Operator soundslike is broken%0A%0A        testFiredRules(
 %22pac
@@ -2593,38 +2593,56 @@
                 
+     
+          
 %22rule 
+Not
 SoundsLike%5Cn%22 +%0A
@@ -2649,32 +2649,47 @@
                 
+  
+             
 %22when%5Cn%22 +%0A     
@@ -2691,32 +2691,47 @@
                 
+  
+             
 %22    Person( nam
@@ -2724,32 +2724,36 @@
    Person( name 
+not 
 soundslike %5C%22Bob
@@ -2770,32 +2770,47 @@
                 
+            
+   
 %22then%5Cn%22 +%0A     
@@ -2824,15 +2824,262 @@
     
+            
+   
 %22end%22
-;%0A
+,%0A                       0,%0A                       %22Bob%22);%0A    %7D%0A%0A    private void testFiredRules(final String rule,%0A                                final int firedRulesCount,%0A                                final String... persons) %7B
 %0A   
@@ -3133,19 +3133,20 @@
 mString(
-str
+rule
 );%0A     
@@ -3220,51 +3220,44 @@
     
-ksession.insert(new Person(%22Bob%22));%0A       
+Stream.of(persons).forEach(person -%3E
  kse
@@ -3280,22 +3280,23 @@
  Person(
-%22Mark%22
+person)
 ));%0A%0A   
@@ -3364,18 +3364,53 @@
 tEquals(
-1,
+firedRulesCount,%0A                    
  rules);
@@ -3416,11 +3416,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

test not soundslike operator (#1481)