[jboss-svn-commits] JBL Code SVN: r9786 - in labs/jbossrules/trunk/drools-compiler: src/main/java/org/drools/rule/builder and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 26 19:28:08 EST 2007
Author: mark.proctor at jboss.com
Date: 2007-02-26 19:28:08 -0500 (Mon, 26 Feb 2007)
New Revision: 9786
Added:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java
Removed:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/
Modified:
labs/jbossrules/trunk/drools-compiler/META-INF/MANIFEST.MF
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleBuilder.java
Log:
JBRULES-708 MVEL Integration
-More interface/implementation seperation for dialects
Modified: labs/jbossrules/trunk/drools-compiler/META-INF/MANIFEST.MF
===================================================================
--- labs/jbossrules/trunk/drools-compiler/META-INF/MANIFEST.MF 2007-02-27 00:24:45 UTC (rev 9785)
+++ labs/jbossrules/trunk/drools-compiler/META-INF/MANIFEST.MF 2007-02-27 00:28:08 UTC (rev 9786)
@@ -10,8 +10,8 @@
org.drools.lang.descr,
org.drools.lang.dsl,
org.drools.lang.dsl.template,
- org.drools.rule.builder.dialect.java.parser,
- org.drools.semantics.java
+ org.drools.rule.builder.dialect.java,
+ org.drools.rule.builder.dialect.java.parser
Require-Bundle: org.eclipse.osgi,
org.drools.core
Bundle-ClassPath: lib/antlr-2.7.6.jar,
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleBuilder.java 2007-02-27 00:24:45 UTC (rev 9785)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleBuilder.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -195,7 +195,7 @@
* @param rule
* @param attributes
*/
- void setAttributes(final Rule rule,
+ public void setAttributes(final Rule rule,
final List attributes) {
for ( final Iterator it = attributes.iterator(); it.hasNext(); ) {
Copied: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java (from rev 9781, labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java)
Deleted: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java 2007-02-27 00:11:32 UTC (rev 9781)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -1,112 +0,0 @@
-package org.drools.semantics.java;
-
-import java.io.InputStreamReader;
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.antlr.stringtemplate.StringTemplateGroup;
-import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
-import org.drools.Cheese;
-import org.drools.Person;
-import org.drools.base.ClassFieldExtractor;
-import org.drools.base.ClassObjectType;
-import org.drools.dialect.java.RuleBuilder;
-import org.drools.rule.Declaration;
-import org.drools.spi.ColumnExtractor;
-
-public class AccumulateTemplateTest extends TestCase {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testMethodGeneration() {
- StringTemplateGroup ruleGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaRule.stg" ) ),
- AngleBracketTemplateLexer.class );
- StringTemplate accMethod = ruleGroup.getInstanceOf( "accumulateMethod" );
-
- final String[] declarationTypes = new String[]{"String", "int"};
- final Declaration[] declarations = new Declaration[]{new Declaration( "name",
- null,
- null ),
- new Declaration( "age",
- null,
- null )};
- final Declaration[] inner = new Declaration[]{new Declaration( "cheese",
- new ColumnExtractor(new ClassObjectType(Cheese.class)),
- null ),
- new Declaration( "price",
- new ClassFieldExtractor(Cheese.class, "price"),
- null )};
- final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
- final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
-
- accMethod.setAttribute( "declarations",
- declarations );
- accMethod.setAttribute( "declarationTypes",
- declarationTypes );
- accMethod.setAttribute( "innerDeclarations",
- inner );
- accMethod.setAttribute( "globals",
- globals );
- accMethod.setAttribute( "globalTypes",
- globalTypes );
- accMethod.setAttribute( "methodName",
- "accumulateTestMethod" );
- accMethod.setAttribute( "columnType",
- "MyClass" );
- accMethod.setAttribute( "columnDeclaration",
- "$myclass" );
- accMethod.setAttribute( "initCode",
- "int x = 0;" );
- accMethod.setAttribute( "actionCode",
- "x += 1;" );
- accMethod.setAttribute( "resultCode",
- "x + 10" );
-
- System.out.println( accMethod.toString() );
- }
-
- public void testInvokerGeneration() {
- StringTemplateGroup ruleGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaInvokers.stg" ) ),
- AngleBracketTemplateLexer.class );
- StringTemplate accMethod = ruleGroup.getInstanceOf( "accumulateInvoker" );
-
- final String[] declarationTypes = new String[]{"String", "int"};
- final Declaration[] declarations = new Declaration[]{new Declaration( "name",
- new ClassFieldExtractor(Person.class, "name"),
- null ), new Declaration( "age",
- new ClassFieldExtractor(Person.class, "age"),
- null )};
- final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
- final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
-
- accMethod.setAttribute( "declarations",
- declarations );
- accMethod.setAttribute( "declarationTypes",
- declarationTypes );
- accMethod.setAttribute( "globals",
- globals );
- accMethod.setAttribute( "globalTypes",
- globalTypes );
- accMethod.setAttribute( "package",
- "org.drools.semantics.java" );
- accMethod.setAttribute( "invokerClassName",
- "AccumulateInvokerClass" );
- accMethod.setAttribute( "ruleClassName",
- "RuleWithAccumulate" );
- accMethod.setAttribute( "methodName",
- "accumulateTestMethod" );
- accMethod.setAttribute( "hashCode",
- new Integer(13) );
-
- System.out.println( accMethod.toString() );
- }
-}
Copied: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java (from rev 9785, labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -0,0 +1,112 @@
+package org.drools.rule.builder.dialect.java;
+
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
+import org.drools.Cheese;
+import org.drools.Person;
+import org.drools.base.ClassFieldExtractor;
+import org.drools.base.ClassObjectType;
+import org.drools.rule.Declaration;
+import org.drools.rule.builder.RuleBuilder;
+import org.drools.spi.ColumnExtractor;
+
+public class AccumulateTemplateTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testMethodGeneration() {
+ StringTemplateGroup ruleGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaRule.stg" ) ),
+ AngleBracketTemplateLexer.class );
+ StringTemplate accMethod = ruleGroup.getInstanceOf( "accumulateMethod" );
+
+ final String[] declarationTypes = new String[]{"String", "int"};
+ final Declaration[] declarations = new Declaration[]{new Declaration( "name",
+ null,
+ null ),
+ new Declaration( "age",
+ null,
+ null )};
+ final Declaration[] inner = new Declaration[]{new Declaration( "cheese",
+ new ColumnExtractor(new ClassObjectType(Cheese.class)),
+ null ),
+ new Declaration( "price",
+ new ClassFieldExtractor(Cheese.class, "price"),
+ null )};
+ final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
+ final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
+
+ accMethod.setAttribute( "declarations",
+ declarations );
+ accMethod.setAttribute( "declarationTypes",
+ declarationTypes );
+ accMethod.setAttribute( "innerDeclarations",
+ inner );
+ accMethod.setAttribute( "globals",
+ globals );
+ accMethod.setAttribute( "globalTypes",
+ globalTypes );
+ accMethod.setAttribute( "methodName",
+ "accumulateTestMethod" );
+ accMethod.setAttribute( "columnType",
+ "MyClass" );
+ accMethod.setAttribute( "columnDeclaration",
+ "$myclass" );
+ accMethod.setAttribute( "initCode",
+ "int x = 0;" );
+ accMethod.setAttribute( "actionCode",
+ "x += 1;" );
+ accMethod.setAttribute( "resultCode",
+ "x + 10" );
+
+ System.out.println( accMethod.toString() );
+ }
+
+ public void testInvokerGeneration() {
+ StringTemplateGroup ruleGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaInvokers.stg" ) ),
+ AngleBracketTemplateLexer.class );
+ StringTemplate accMethod = ruleGroup.getInstanceOf( "accumulateInvoker" );
+
+ final String[] declarationTypes = new String[]{"String", "int"};
+ final Declaration[] declarations = new Declaration[]{new Declaration( "name",
+ new ClassFieldExtractor(Person.class, "name"),
+ null ), new Declaration( "age",
+ new ClassFieldExtractor(Person.class, "age"),
+ null )};
+ final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
+ final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
+
+ accMethod.setAttribute( "declarations",
+ declarations );
+ accMethod.setAttribute( "declarationTypes",
+ declarationTypes );
+ accMethod.setAttribute( "globals",
+ globals );
+ accMethod.setAttribute( "globalTypes",
+ globalTypes );
+ accMethod.setAttribute( "package",
+ "org.drools.semantics.java" );
+ accMethod.setAttribute( "invokerClassName",
+ "AccumulateInvokerClass" );
+ accMethod.setAttribute( "ruleClassName",
+ "RuleWithAccumulate" );
+ accMethod.setAttribute( "methodName",
+ "accumulateTestMethod" );
+ accMethod.setAttribute( "hashCode",
+ new Integer(13) );
+
+ System.out.println( accMethod.toString() );
+ }
+}
Deleted: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java 2007-02-27 00:11:32 UTC (rev 9781)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -1,138 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * 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.
- */
-
-import org.drools.dialect.java.KnowledgeHelperFixer;
-
-import junit.framework.TestCase;
-
-public class KnowledgeHelperFixerTest extends TestCase {
-
- private static final KnowledgeHelperFixer fixer = new KnowledgeHelperFixer();
-
- public void testAdd__Handle__Simple() {
- String result = KnowledgeHelperFixerTest.fixer.fix( "modify(myObject )" );
- assertEquals( "drools.modifyObject(myObject__Handle__, myObject)",
- result );
-
- result = KnowledgeHelperFixerTest.fixer.fix( "modify ( myObject )" );
- assertEquals( "drools.modifyObject(myObject__Handle__, myObject)",
- result );
- }
-
- public void testAdd__Handle__withNewLines() {
- final String result = KnowledgeHelperFixerTest.fixer.fix( "\n\t\n\tmodify(myObject )" );
- assertEquals( "\n\t\n\tdrools.modifyObject(myObject__Handle__, myObject)",
- result );
- }
-
- public void testAdd__Handle__rComplex() {
- String result = KnowledgeHelperFixerTest.fixer.fix( "something modify(myObject ); other" );
- assertEquals( "something drools.modifyObject(myObject__Handle__, myObject); other",
- result );
-
- result = KnowledgeHelperFixerTest.fixer.fix( "something modify (myObject )" );
- assertEquals( "something drools.modifyObject(myObject__Handle__, myObject)",
- result );
-
- result = KnowledgeHelperFixerTest.fixer.fix( " modify(myObject ) x" );
- assertEquals( " drools.modifyObject(myObject__Handle__, myObject) x",
- result );
-
- //should not touch, as it is not a stand alone word
- result = KnowledgeHelperFixerTest.fixer.fix( "xxmodify(myObject ) x" );
- assertEquals( "xxmodify(myObject ) x",
- result );
- }
-
- public void testMultipleMatches() {
- String result = KnowledgeHelperFixerTest.fixer.fix( "modify(myObject) modify(myObject )" );
- assertEquals( "drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(myObject__Handle__, myObject)",
- result );
-
- result = KnowledgeHelperFixerTest.fixer.fix( "xxx modify(myObject ) modify(myObject ) modify(yourObject ) yyy" );
- assertEquals( "xxx drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(yourObject__Handle__, yourObject) yyy",
- result );
-
- }
-
- public void testAssert() {
- final String raw = "some code; assert(new String(\"foo\"));\n More();";
- final String result = "some code; drools.assertObject(new String(\"foo\"));\n More();";
- assertEquals( result,
- KnowledgeHelperFixerTest.fixer.fix( raw ) );
- }
-
- public void testAssertLogical() {
- final String raw = "some code; assertLogical(new String(\"foo\"));\n More();";
- final String result = "some code; drools.assertLogicalObject(new String(\"foo\"));\n More();";
- assertEquals( result,
- KnowledgeHelperFixerTest.fixer.fix( raw ) );
- }
-
- public void testAllActionsMushedTogether() {
- String result = KnowledgeHelperFixerTest.fixer.fix( "assert(myObject ) modify(ourObject);\t retract(herObject)" );
- assertEquals( "drools.assertObject(myObject ) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)",
- result );
-
- result = KnowledgeHelperFixerTest.fixer.fix( "assert(myObject ) modify(ourObject);\t retract(herObject)\nassert(myObject) modify(ourObject);\t retract(herObject)" );
- assertEquals( "drools.assertObject(myObject ) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)\ndrools.assertObject(myObject) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)",
- result );
- }
-
- public void testLeaveLargeAlone() {
- final String original = "yeah yeah yeah massert( xxx ) this is a long() thing Person (name=='drools') modify a thing";
- final String result = KnowledgeHelperFixerTest.fixer.fix( original );
- assertEquals( original,
- result );
- }
-
- public void testWithNull() {
- final String original = null;
- final String result = KnowledgeHelperFixerTest.fixer.fix( original );
- assertEquals( original,
- result );
- }
-
- public void testLeaveAssertAlone() {
- final String original = "drools.assertObject(foo)";
- assertEquals( original,
- KnowledgeHelperFixerTest.fixer.fix( original ) );
- }
-
- public void testLeaveAssertLogicalAlone() {
- final String original = "drools.assertLogicalObject(foo)";
- assertEquals( original,
- KnowledgeHelperFixerTest.fixer.fix( original ) );
- }
-
- public void testWackyAssert() {
- final String raw = "System.out.println($person1.getName() + \" and \" + $person2.getName() +\" are sisters\");\n" + "assert($person1.getName(\"foo\") + \" and \" + $person2.getName() +\" are sisters\"); yeah();";
- final String expected = "System.out.println($person1.getName() + \" and \" + $person2.getName() +\" are sisters\");\n" + "drools.assertObject($person1.getName(\"foo\") + \" and \" + $person2.getName() +\" are sisters\"); yeah();";
-
- assertEquals( expected,
- KnowledgeHelperFixerTest.fixer.fix( raw ) );
-
- }
-
- public void testMoreAssertCraziness() {
- final String raw = "foobar(); (assert(new String(\"blah\").get()); bangBangYudoHono();)";
- assertEquals( "foobar(); (drools.assertObject(new String(\"blah\").get()); bangBangYudoHono();)",
- KnowledgeHelperFixerTest.fixer.fix( raw ) );
- }
-
-}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java (from rev 9785, labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/KnowledgeHelperFixerTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -0,0 +1,138 @@
+package org.drools.rule.builder.dialect.java;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * 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.
+ */
+
+import org.drools.rule.builder.dialect.java.KnowledgeHelperFixer;
+
+import junit.framework.TestCase;
+
+public class KnowledgeHelperFixerTest extends TestCase {
+
+ private static final KnowledgeHelperFixer fixer = new KnowledgeHelperFixer();
+
+ public void testAdd__Handle__Simple() {
+ String result = KnowledgeHelperFixerTest.fixer.fix( "modify(myObject )" );
+ assertEquals( "drools.modifyObject(myObject__Handle__, myObject)",
+ result );
+
+ result = KnowledgeHelperFixerTest.fixer.fix( "modify ( myObject )" );
+ assertEquals( "drools.modifyObject(myObject__Handle__, myObject)",
+ result );
+ }
+
+ public void testAdd__Handle__withNewLines() {
+ final String result = KnowledgeHelperFixerTest.fixer.fix( "\n\t\n\tmodify(myObject )" );
+ assertEquals( "\n\t\n\tdrools.modifyObject(myObject__Handle__, myObject)",
+ result );
+ }
+
+ public void testAdd__Handle__rComplex() {
+ String result = KnowledgeHelperFixerTest.fixer.fix( "something modify(myObject ); other" );
+ assertEquals( "something drools.modifyObject(myObject__Handle__, myObject); other",
+ result );
+
+ result = KnowledgeHelperFixerTest.fixer.fix( "something modify (myObject )" );
+ assertEquals( "something drools.modifyObject(myObject__Handle__, myObject)",
+ result );
+
+ result = KnowledgeHelperFixerTest.fixer.fix( " modify(myObject ) x" );
+ assertEquals( " drools.modifyObject(myObject__Handle__, myObject) x",
+ result );
+
+ //should not touch, as it is not a stand alone word
+ result = KnowledgeHelperFixerTest.fixer.fix( "xxmodify(myObject ) x" );
+ assertEquals( "xxmodify(myObject ) x",
+ result );
+ }
+
+ public void testMultipleMatches() {
+ String result = KnowledgeHelperFixerTest.fixer.fix( "modify(myObject) modify(myObject )" );
+ assertEquals( "drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(myObject__Handle__, myObject)",
+ result );
+
+ result = KnowledgeHelperFixerTest.fixer.fix( "xxx modify(myObject ) modify(myObject ) modify(yourObject ) yyy" );
+ assertEquals( "xxx drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(myObject__Handle__, myObject) drools.modifyObject(yourObject__Handle__, yourObject) yyy",
+ result );
+
+ }
+
+ public void testAssert() {
+ final String raw = "some code; assert(new String(\"foo\"));\n More();";
+ final String result = "some code; drools.assertObject(new String(\"foo\"));\n More();";
+ assertEquals( result,
+ KnowledgeHelperFixerTest.fixer.fix( raw ) );
+ }
+
+ public void testAssertLogical() {
+ final String raw = "some code; assertLogical(new String(\"foo\"));\n More();";
+ final String result = "some code; drools.assertLogicalObject(new String(\"foo\"));\n More();";
+ assertEquals( result,
+ KnowledgeHelperFixerTest.fixer.fix( raw ) );
+ }
+
+ public void testAllActionsMushedTogether() {
+ String result = KnowledgeHelperFixerTest.fixer.fix( "assert(myObject ) modify(ourObject);\t retract(herObject)" );
+ assertEquals( "drools.assertObject(myObject ) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)",
+ result );
+
+ result = KnowledgeHelperFixerTest.fixer.fix( "assert(myObject ) modify(ourObject);\t retract(herObject)\nassert(myObject) modify(ourObject);\t retract(herObject)" );
+ assertEquals( "drools.assertObject(myObject ) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)\ndrools.assertObject(myObject) drools.modifyObject(ourObject__Handle__, ourObject);\t drools.retractObject(herObject__Handle__)",
+ result );
+ }
+
+ public void testLeaveLargeAlone() {
+ final String original = "yeah yeah yeah massert( xxx ) this is a long() thing Person (name=='drools') modify a thing";
+ final String result = KnowledgeHelperFixerTest.fixer.fix( original );
+ assertEquals( original,
+ result );
+ }
+
+ public void testWithNull() {
+ final String original = null;
+ final String result = KnowledgeHelperFixerTest.fixer.fix( original );
+ assertEquals( original,
+ result );
+ }
+
+ public void testLeaveAssertAlone() {
+ final String original = "drools.assertObject(foo)";
+ assertEquals( original,
+ KnowledgeHelperFixerTest.fixer.fix( original ) );
+ }
+
+ public void testLeaveAssertLogicalAlone() {
+ final String original = "drools.assertLogicalObject(foo)";
+ assertEquals( original,
+ KnowledgeHelperFixerTest.fixer.fix( original ) );
+ }
+
+ public void testWackyAssert() {
+ final String raw = "System.out.println($person1.getName() + \" and \" + $person2.getName() +\" are sisters\");\n" + "assert($person1.getName(\"foo\") + \" and \" + $person2.getName() +\" are sisters\"); yeah();";
+ final String expected = "System.out.println($person1.getName() + \" and \" + $person2.getName() +\" are sisters\");\n" + "drools.assertObject($person1.getName(\"foo\") + \" and \" + $person2.getName() +\" are sisters\"); yeah();";
+
+ assertEquals( expected,
+ KnowledgeHelperFixerTest.fixer.fix( raw ) );
+
+ }
+
+ public void testMoreAssertCraziness() {
+ final String raw = "foobar(); (assert(new String(\"blah\").get()); bangBangYudoHono();)";
+ assertEquals( "foobar(); (drools.assertObject(new String(\"blah\").get()); bangBangYudoHono();)",
+ KnowledgeHelperFixerTest.fixer.fix( raw ) );
+ }
+
+}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java 2007-02-27 00:11:32 UTC (rev 9781)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -1,160 +0,0 @@
-/*
- * Copyright 2006 JBoss Inc
- *
- * 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.semantics.java;
-
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.codehaus.jfdi.interpreter.ClassTypeResolver;
-import org.codehaus.jfdi.interpreter.TypeResolver;
-import org.drools.base.ClassFieldExtractorCache;
-import org.drools.compiler.DrlParser;
-import org.drools.dialect.java.RuleBuilder;
-import org.drools.lang.descr.AttributeDescr;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.lang.descr.RuleDescr;
-import org.drools.rule.GroupElement;
-import org.drools.rule.Package;
-import org.drools.rule.Rule;
-import org.drools.spi.FunctionResolver;
-
-/**
- * @author etirelli
- *
- */
-public class RuleBuilderTest extends TestCase {
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Test method for {@link org.drools.dialect.java.RuleBuilder#build(org.drools.rule.Package, org.drools.lang.descr.RuleDescr)}.
- */
- public void testBuild() {
- try {
- final DrlParser parser = new DrlParser();
- final PackageDescr pkgDescr = parser.parse( new InputStreamReader( getClass().getResourceAsStream( "nestedConditionalElements.drl" ) ) );
-
- // just checking there is no parsing errors
- Assert.assertFalse( parser.getErrors().toString(),
- parser.hasErrors() );
-
- Package pkg = new Package( "org.drools" );
-
- RuleDescr ruleDescr = (RuleDescr) pkgDescr.getRules().get( 0 );
- final String ruleClassName = "RuleClassName.java";
- ruleDescr.setClassName( ruleClassName );
-
- TypeResolver typeResolver = new ClassTypeResolver( new ArrayList(),
- this.getClass().getClassLoader() );
- // make an automatic import for the current package
- typeResolver.addImport( pkgDescr.getName() + ".*" );
- typeResolver.addImport( "java.lang.*" );
-
- final RuleBuilder builder = new RuleBuilder( typeResolver,
- new ClassFieldExtractorCache() );
-
- builder.build( pkg,
- ruleDescr );
-
- Assert.assertTrue( builder.getErrors().toString(),
- builder.getErrors().isEmpty() );
-
- final Rule rule = builder.getRule();
-
- assertEquals( "There should be 2 rule level declarations", 2, rule.getDeclarations().length );
-
- // second GE should be a not
- GroupElement not = (GroupElement) rule.getLhs().getChildren().get( 1 );
- assertTrue( not.isNot() );
- // not has no outer declarations
- assertTrue( not.getOuterDeclarations().isEmpty() );
- assertEquals( 1, not.getInnerDeclarations().size() );
- assertTrue( not.getInnerDeclarations().keySet().contains( "$state" ) );
-
- // second not
- GroupElement not2 = (GroupElement) ((GroupElement) not.getChildren().get( 0 )).getChildren().get( 1 );
- assertTrue( not2.isNot() );
- // not has no outer declarations
- assertTrue( not2.getOuterDeclarations().isEmpty() );
- assertEquals( 1, not2.getInnerDeclarations().size() );
- assertTrue( not2.getInnerDeclarations().keySet().contains( "$likes" ) );
-
- } catch ( Exception e ) {
- e.printStackTrace();
- fail( "This test is not supposed to throw any exception: " + e.getMessage() );
- }
-
- }
-
- public void testBuildAttributes() throws Exception {
- RuleBuilder builder = new RuleBuilder(null, null);
- Rule rule = new Rule("myrule");
- List attributes = new ArrayList();
-
- attributes.add( new AttributeDescr("no-loop", "true") );
- attributes.add( new AttributeDescr("enabled", "false") );
- attributes.add( new AttributeDescr("ruleflow-group", "mygroup") );
- builder.setAttributes( rule, attributes );
-
- assertTrue(rule.getNoLoop());
- assertFalse(rule.isEffective());
- assertEquals("mygroup", rule.getRuleFlowGroup() );
-
- attributes = new ArrayList();
- attributes.add(new AttributeDescr("date-effective", "10-Jul-1974"));
- attributes.add(new AttributeDescr("date-expires", "10-Jul-2040") );
-
- rule = new Rule("myrule");
-
- builder.setAttributes( rule, attributes );
-
- Field eff = rule.getClass().getDeclaredField( "dateEffective" );
- eff.setAccessible( true );
- Calendar effectiveDate = (Calendar) eff.get( rule );
- assertNotNull(effectiveDate);
-
- assertEquals(1974, effectiveDate.get( Calendar.YEAR ));
-
- Field exp = rule.getClass().getDeclaredField( "dateExpires" );
- exp.setAccessible( true );
- Calendar expiryDate = (Calendar) exp.get( rule );
-
- assertEquals(2040, expiryDate.get(Calendar.YEAR));
-
- assertNotNull(expiryDate);
-
- }
-
-}
Copied: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java (from rev 9785, labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/RuleBuilderTest.java 2007-02-27 00:28:08 UTC (rev 9786)
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2006 JBoss Inc
+ *
+ * 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.rule.builder.dialect.java;
+
+import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.codehaus.jfdi.interpreter.ClassTypeResolver;
+import org.codehaus.jfdi.interpreter.TypeResolver;
+import org.drools.base.ClassFieldExtractorCache;
+import org.drools.compiler.DrlParser;
+import org.drools.lang.descr.AttributeDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+import org.drools.rule.builder.RuleBuilder;
+import org.drools.spi.FunctionResolver;
+
+/**
+ * @author etirelli
+ *
+ */
+public class RuleBuilderTest extends TestCase {
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.drools.rule.builder.RuleBuilder#build(org.drools.rule.Package, org.drools.lang.descr.RuleDescr)}.
+ */
+ public void testBuild() {
+ try {
+ final DrlParser parser = new DrlParser();
+ final PackageDescr pkgDescr = parser.parse( new InputStreamReader( getClass().getResourceAsStream( "nestedConditionalElements.drl" ) ) );
+
+ // just checking there is no parsing errors
+ Assert.assertFalse( parser.getErrors().toString(),
+ parser.hasErrors() );
+
+ Package pkg = new Package( "org.drools" );
+
+ RuleDescr ruleDescr = (RuleDescr) pkgDescr.getRules().get( 0 );
+ final String ruleClassName = "RuleClassName.java";
+ ruleDescr.setClassName( ruleClassName );
+
+ TypeResolver typeResolver = new ClassTypeResolver( new ArrayList(),
+ this.getClass().getClassLoader() );
+ // make an automatic import for the current package
+ typeResolver.addImport( pkgDescr.getName() + ".*" );
+ typeResolver.addImport( "java.lang.*" );
+
+ final RuleBuilder builder = new RuleBuilder( typeResolver,
+ new ClassFieldExtractorCache() );
+
+ builder.build( pkg,
+ ruleDescr );
+
+ Assert.assertTrue( builder.getErrors().toString(),
+ builder.getErrors().isEmpty() );
+
+ final Rule rule = builder.getRule();
+
+ assertEquals( "There should be 2 rule level declarations", 2, rule.getDeclarations().length );
+
+ // second GE should be a not
+ GroupElement not = (GroupElement) rule.getLhs().getChildren().get( 1 );
+ assertTrue( not.isNot() );
+ // not has no outer declarations
+ assertTrue( not.getOuterDeclarations().isEmpty() );
+ assertEquals( 1, not.getInnerDeclarations().size() );
+ assertTrue( not.getInnerDeclarations().keySet().contains( "$state" ) );
+
+ // second not
+ GroupElement not2 = (GroupElement) ((GroupElement) not.getChildren().get( 0 )).getChildren().get( 1 );
+ assertTrue( not2.isNot() );
+ // not has no outer declarations
+ assertTrue( not2.getOuterDeclarations().isEmpty() );
+ assertEquals( 1, not2.getInnerDeclarations().size() );
+ assertTrue( not2.getInnerDeclarations().keySet().contains( "$likes" ) );
+
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ fail( "This test is not supposed to throw any exception: " + e.getMessage() );
+ }
+
+ }
+
+ public void testBuildAttributes() throws Exception {
+ RuleBuilder builder = new RuleBuilder(null, null);
+ Rule rule = new Rule("myrule");
+ List attributes = new ArrayList();
+
+ attributes.add( new AttributeDescr("no-loop", "true") );
+ attributes.add( new AttributeDescr("enabled", "false") );
+ attributes.add( new AttributeDescr("ruleflow-group", "mygroup") );
+ builder.setAttributes( rule, attributes );
+
+ assertTrue(rule.getNoLoop());
+ assertFalse(rule.isEffective());
+ assertEquals("mygroup", rule.getRuleFlowGroup() );
+
+ attributes = new ArrayList();
+ attributes.add(new AttributeDescr("date-effective", "10-Jul-1974"));
+ attributes.add(new AttributeDescr("date-expires", "10-Jul-2040") );
+
+ rule = new Rule("myrule");
+
+ builder.setAttributes( rule, attributes );
+
+ Field eff = rule.getClass().getDeclaredField( "dateEffective" );
+ eff.setAccessible( true );
+ Calendar effectiveDate = (Calendar) eff.get( rule );
+ assertNotNull(effectiveDate);
+
+ assertEquals(1974, effectiveDate.get( Calendar.YEAR ));
+
+ Field exp = rule.getClass().getDeclaredField( "dateExpires" );
+ exp.setAccessible( true );
+ Calendar expiryDate = (Calendar) exp.get( rule );
+
+ assertEquals(2040, expiryDate.get(Calendar.YEAR));
+
+ assertNotNull(expiryDate);
+
+ }
+
+}
More information about the jboss-svn-commits
mailing list