[jboss-svn-commits] JBL Code SVN: r9261 - in labs/jbossrules/trunk/drools-testing: lib and 22 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Feb 1 09:49:00 EST 2007
Author: mshaw
Date: 2007-02-01 09:49:00 -0500 (Thu, 01 Feb 2007)
New Revision: 9261
Added:
labs/jbossrules/trunk/drools-testing/.classpath
labs/jbossrules/trunk/drools-testing/.project
labs/jbossrules/trunk/drools-testing/build-castor-src.xml
labs/jbossrules/trunk/drools-testing/drl.xml
labs/jbossrules/trunk/drools-testing/lib/
labs/jbossrules/trunk/drools-testing/lib/castor-xml-1.0.5.jar
labs/jbossrules/trunk/drools-testing/lib/xercesImpl-2.4.0.jar
labs/jbossrules/trunk/drools-testing/pom.xml
labs/jbossrules/trunk/drools-testing/rtl/
labs/jbossrules/trunk/drools-testing/rtl/test.rtl
labs/jbossrules/trunk/drools-testing/src/
labs/jbossrules/trunk/drools-testing/src/org/
labs/jbossrules/trunk/drools-testing/src/org/drools/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/ApplicationProperties.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/PropertyNotFoundException.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/ObjectUtilsException.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/RuleTestLanguageException.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/TransformerServiceException.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/SchemaBuilder.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/Testing.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/TransformerService.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/META-INF/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/META-INF/test-lang.xsd
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xml
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xsd
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/castor-mapping.xml
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/properties/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/properties/castorbuilder.properties
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/5_rules.drl
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/META-INF/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/META-INF/drools-3.0.xsd
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/test.drl
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/rtl/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/rtl/rtl.properties
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/RuleSetTest.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Account.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Person.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/TestingTest.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/ThingTester.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/rtl.properties
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/CollectionUtils.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/FieldUtils.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/ObjectUtils.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/OperatorUtils.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FactWrapper.java
labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FieldWrapper.java
Log:
Initial commit
Added: labs/jbossrules/trunk/drools-testing/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-testing/.classpath (rev 0)
+++ labs/jbossrules/trunk/drools-testing/.classpath 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="generated-source"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: labs/jbossrules/trunk/drools-testing/.project
===================================================================
--- labs/jbossrules/trunk/drools-testing/.project (rev 0)
+++ labs/jbossrules/trunk/drools-testing/.project 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>drools-testing</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: labs/jbossrules/trunk/drools-testing/build-castor-src.xml
===================================================================
--- labs/jbossrules/trunk/drools-testing/build-castor-src.xml (rev 0)
+++ labs/jbossrules/trunk/drools-testing/build-castor-src.xml 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,60 @@
+<project name="MyProject" default="castor:gen:src" basedir=".">
+ <description>
+ simple example build file
+ </description>
+ <!-- set global properties for this build -->
+ <property name="src" location="src"/>
+ <property name="build" location="build"/>
+ <property name="dist" location="bin"/>
+ <property name="gen" location="generated-source"/>
+
+
+
+ <target name="init">
+ <!-- Create the time stamp -->
+ <tstamp/>
+ <!-- Create the build directory structure used by compile -->
+ <!--<mkdir dir="${build}"/>-->
+ </target>
+
+ <target name="compile" depends="init"
+ description="compile the source " >
+ <!-- Compile the java code from ${src} into ${build} -->
+ <javac srcdir="${src}" destdir="${build}"/>
+ </target>
+
+ <target name="dist" depends="compile"
+ description="generate the distribution" >
+ <!-- Create the distribution directory -->
+ <mkdir dir="${dist}/lib"/>
+
+ <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
+ <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
+ </target>
+
+ <target name="clean"
+ description="clean up" >
+ <!-- Delete the ${build} and ${dist} directory trees -->
+ <delete dir="${build}"/>
+ <delete dir="${gen}"/>
+ </target>
+
+
+<target name="castor:gen:src" depends="init"
+ description="Generate Java source files from XSD.">
+
+ <taskdef name="castor-srcgen"
+ classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask"
+ />
+ <castor-srcgen dir="C:\eclipse3.2\workspace\testing-core\src\org\drools\testing\core\resources\castor\META-INF\"
+ todir="${gen}"
+ package="org.drools.testing.core.beans"
+ types="j2"
+ warnings="true"
+ bindingfile="C:\eclipse3.2\workspace\testing-core\src\org\drools\testing\core\resources\castor\binding\binding.xml"
+ nodesc="true">
+
+ </castor-srcgen>
+ </target>
+</project>
+
Added: labs/jbossrules/trunk/drools-testing/drl.xml
===================================================================
--- labs/jbossrules/trunk/drools-testing/drl.xml (rev 0)
+++ labs/jbossrules/trunk/drools-testing/drl.xml 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package name="org.drools.testing.core.rules" xmlns="http://drools.org/drools-3.0"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+ xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd">
+ <import name="org.drools.testing.core.rules.model.Account"/>
+
+
+
+ <rule name="rule1">
+
+ <lhs>
+ <column identifier="$acc" object-type="Account">
+ <literal field-name="status" evaluator="==" value="active"/>
+
+ <literal field-name="balance" evaluator="==" value="0"/>
+
+
+ </column>
+
+
+ </lhs>
+ <rhs> $acc . setBalance ( new Integer ( -100 ) ) ; modify ( $acc ) ; System . out . println (
+ "firing rule1" ) ; </rhs>
+ </rule>
+ <rule name="rule2">
+
+ <lhs>
+ <column identifier="$acc" object-type="Account">
+ <literal field-name="status" evaluator="==" value="active"/>
+
+ <literal field-name="balance" evaluator="<" value="0"/>
+
+
+ </column>
+
+
+ </lhs>
+ <rhs> $acc . setStatus ( "overdrawn" ) ; modify ( $acc ) ; System . out . println ( "Your account
+ is overdrawn. Balance: " + $acc . getBalance ( ) ) ; </rhs>
+ </rule>
+ <rule name="rule3">
+
+ <lhs>
+ <column identifier="$acc" object-type="Account">
+ <literal field-name="balance" evaluator=">" value="0"/>
+
+
+ </column>
+
+
+ </lhs>
+ <rhs> System . out . println ( "The banks likes you.. so we're increasing our fees!" ) ; </rhs>
+ </rule>
+</package>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/lib/castor-xml-1.0.5.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-testing/lib/castor-xml-1.0.5.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-testing/lib/xercesImpl-2.4.0.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-testing/lib/xercesImpl-2.4.0.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-testing/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-testing/pom.xml (rev 0)
+++ labs/jbossrules/trunk/drools-testing/pom.xml 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>drools-testing</groupId>
+ <artifactId>drools-testing</artifactId>
+ <name>drools-testing</name>
+ <version>0.0.1</version>
+ <description></description>
+ <packaging>jar</packaging>
+ <repositories>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ <updatePolicy>always</updatePolicy>
+ <checksumPolicy>warn</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </snapshots>
+ <id>codehausSnapshots</id>
+ <name>Codehaus Snapshots</name>
+ <url>http://snapshots.maven.codehaus.org/maven2</url>
+ <layout>default</layout>
+ </repository>
+ </repositories>
+
+ <build>
+ <sourceDirectory>${basedir}/src</sourceDirectory>
+ <outputDirectory>${basedir}/target/classes</outputDirectory>
+ <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
+ <resources>
+ <resource>
+ <filtering>false</filtering>
+ <directory>${basedir}/src</directory>
+ <includes>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>drools</groupId>
+ <artifactId>drools-core</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>castor</groupId>
+ <artifactId>castor-xml</artifactId>
+ <version>1.0.5</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>castor</groupId>
+ <artifactId>castor-srcgen-ant-task</artifactId>
+ <version>1.0.5</version>
+ </dependency>
+ <dependency>
+ <groupId>antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <version>2.7.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <version>3.0ea8</version>
+ </dependency>
+ <dependency>
+ <groupId>drools</groupId>
+ <artifactId>drools-core</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-archiver</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xerces</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/rtl/test.rtl
===================================================================
--- labs/jbossrules/trunk/drools-testing/rtl/test.rtl (rev 0)
+++ labs/jbossrules/trunk/drools-testing/rtl/test.rtl 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-suite scenario-count="1" valid="true">
+ <scenario valid="true" fact-count="2" rule-count="3">
+ <name>Scenario One</name>
+ <fact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" valid="true" field-count="1"
+ id="132676997" xsi:type="java:org.drools.testing.core.wrapper.FactWrapper">
+ <type>org.drools.testing.core.rules.model.Person</type>
+ <field valid="true" xsi:type="java:org.drools.testing.core.wrapper.FieldWrapper">
+ <name>age</name>
+ <type>java.lang.Integer</type>
+ <value>0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59</value>
+ </field>
+ </fact>
+ <fact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" valid="true" field-count="2"
+ id="738530534" xsi:type="java:org.drools.testing.core.wrapper.FactWrapper">
+ <type>org.drools.testing.core.rules.model.Account</type>
+ <field valid="true" xsi:type="java:org.drools.testing.core.wrapper.FieldWrapper">
+ <name>status</name>
+ <type>java.lang.String</type>
+ <value>active</value>
+ </field>
+ <field valid="true" xsi:type="java:org.drools.testing.core.wrapper.FieldWrapper">
+ <name>balance</name>
+ <type>java.lang.Integer</type>
+ <value>0</value>
+ </field>
+ </fact>
+ <rule result-count="0" fire="true" valid="true">
+ <name>rule1</name>
+ </rule>
+ <rule result-count="0" fire="true" valid="true">
+ <name>rule2</name>
+ </rule>
+ <rule result-count="0" fire="true" valid="true">
+ <name>rule3</name>
+ </rule>
+ </scenario>
+ <name>The Test Test Suite</name>
+</test-suite>
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/ApplicationProperties.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/ApplicationProperties.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/ApplicationProperties.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,297 @@
+/*
+ * Created on 26/05/2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.drools.testing.core.configuration;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author mshaw
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ApplicationProperties {
+
+ /**
+ * A reference to the AppProperties Singleton object.
+ */
+ private static ApplicationProperties s_AppProperties;
+ private Properties m_Properties;
+ private String m_FileName = "/org/drools/testing/core/resources/rtl/rtl.properties";
+ public final static String SYSTEM_PROPERTY = "rtl.properties.file";
+ public final static String ENVIRONMENT_PROPERTY = "environment";
+ public final static String DELIMETER = "_";
+
+ static Log log = LogFactory.getLog(ApplicationProperties.class);
+
+
+ /**
+ * Create a new properties instance.
+ *
+ * Retrieves the properties as a RESOURCE.
+ */
+ private ApplicationProperties() {
+
+ String methodName = "ApplicationProperties()";
+
+ BufferedInputStream bis = null;
+ m_Properties = new Properties();
+
+ log.info("AppProperties - using property file: " + m_FileName);
+
+ // Load the properties
+ try {
+ bis = new BufferedInputStream(ApplicationProperties.class.getResourceAsStream( m_FileName ));
+ m_Properties.load(bis);
+ }
+ catch (Exception ex) {
+ log.error(ex);
+ }
+ finally {
+ try {
+ if (bis != null) {
+ bis.close();
+ }
+ }
+ catch (IOException ex) { /* Cannot do anything here */}
+
+ }
+ }
+
+ /**
+ * load properties from the file system
+ *
+ */
+ private ApplicationProperties(String fileName) {
+
+ String methodName = "ApplicationProperties()";
+
+ FileInputStream fis = null;
+ BufferedInputStream bis = null;
+ m_Properties = new Properties();
+
+ log.info("AppProperties - using property file: " + fileName);
+
+ // Load the properties
+ try {
+ fis = new FileInputStream(fileName);
+ bis = new BufferedInputStream(ApplicationProperties.class.getResourceAsStream( m_FileName ));
+ m_Properties.load(bis);
+ }
+ catch (Exception ex) {
+ log.error(ex);
+ }
+ finally {
+ try {
+ if (bis != null) {
+ bis.close();
+ }
+ }
+ catch (IOException ex) { /* Cannot do anything here */}
+ try {
+ if (fis != null) {
+ fis.close();
+ }
+ }
+ catch (IOException ex) { /* Cannot do anything here */}
+ }
+ }
+
+ /**
+ * Returns a String associated with the property specified by
+ * propertyName.
+ *
+ * @param propertyName a string representing the property
+ * @return the associated value
+ */
+ public String getProperty(String propertyName) throws PropertyNotFoundException {
+
+ String result = m_Properties.getProperty(propertyName);
+
+ if (result == null) {
+ throw new PropertyNotFoundException("Could not find property " + propertyName + " in file " +
+ m_FileName);
+ }
+
+ return result;
+
+ }
+
+ /**
+ * Returns a String associated with the property specified by
+ * propertyName.
+ *
+ * @param propertyName a string representing the property
+ * @return the associated value
+ */
+ public String getEnvironmentSpecificProperty(String propertyName) throws PropertyNotFoundException {
+ String environment = System.getProperty(ENVIRONMENT_PROPERTY);
+ if (environment == null) {
+ throw new IllegalStateException("The System parameter: " + ENVIRONMENT_PROPERTY + " must be set");
+ }
+ String result = m_Properties.getProperty(environment + DELIMETER + propertyName);
+
+ if (result == null) {
+ throw new PropertyNotFoundException("Could not find environement specific property " + environment +
+ DELIMETER + propertyName + " in file " + m_FileName);
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns an array of Strings associated with the property specified by
+ * propertyName. The method is used for entries that potentially have
+ * multiple values separated by a particular character or string.
+ *
+ * Typically this will be used for space separated words:
+ * String[] entries =
+ * AppProperties.getInstance().getPropertyEntries("PropertyName", " ");
+ *
+ * @param propertyName the name of the property
+ * @param separatorString the string that separates each entry
+ */
+ public String[] getPropertyEntries(String propertyName, String separatorString) throws PropertyNotFoundException {
+ String prop = m_Properties.getProperty(propertyName);
+
+ if (prop == null) {
+ throw new PropertyNotFoundException("Could not find property " + propertyName + " in file " + m_FileName);
+ }
+
+ StringTokenizer tokeniser = new StringTokenizer(prop, separatorString);
+ String[] result = new String[tokeniser.countTokens()];
+ int i = 0;
+
+ while (tokeniser.hasMoreElements()) {
+ result[i++] = tokeniser.nextToken();
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns an Iterator of property names
+ *
+ * @return all the property names
+ */
+ public Iterator getPropertyNames() {
+ return m_Properties.keySet().iterator();
+ }
+
+ /**
+ * method used to reload the property list at runtime
+ *
+ *
+ */
+ public void loadProprtyFile(String fileName) {
+ String methodName = "loadProprtyFile(String fileName)";
+ if (fileName == null) {
+ log.error("File name is null");
+ }
+ else {
+ s_AppProperties = new ApplicationProperties(fileName);
+ }
+ }
+
+ /**
+ * A string representaion of the properties in the Properties Table
+ */
+
+ public String propertiesToString() {
+ if (m_Properties == null) {
+ return ("Properties have not been initialised");
+ }
+ else {
+ String props = "";
+ Iterator propertyKeys = getPropertyNames();
+ while (propertyKeys.hasNext()) {
+ String currentKey = (String) propertyKeys.next();
+ props += currentKey + "=" + m_Properties.get(currentKey) + "\n";
+ }
+
+ return props;
+ }
+ }
+
+ /**
+ * Returns the instance of the AppProperties class
+ *
+ * @return the singleton instance
+ */
+ public static ApplicationProperties getInstance() {
+ if (s_AppProperties == null) {
+ s_AppProperties = new ApplicationProperties();
+ }
+
+ return s_AppProperties;
+ }
+
+ public String getFileName() {
+ return m_FileName;
+ }
+
+ public static void flushProperties() {
+ String methodName = "flushProperties()";
+ s_AppProperties = null;
+ }
+
+ /**
+ * Get a property but if it does not exist return the default value supplied in the
+ * method call.
+ * @param property
+ * @param defaultValue
+ * @return
+ */
+ public String getPropertyWithDefault(String property, String defaultValue)
+ {
+ try {
+ return getProperty(property);
+ } catch (PropertyNotFoundException e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * Get a property and return it as an int. Throws a property not found exception
+ * if the property exists but cannot be formatted.
+ * @param property
+ * @return
+ * @throws PropertyNotFoundException
+ */
+ public int getPropertyAsInt(String property) throws PropertyNotFoundException
+ {
+ try {
+ return new Integer(getProperty(property)).intValue();
+ } catch (NumberFormatException e) {
+ throw new PropertyNotFoundException("Property was found but could not converted to an int");
+ }
+ }
+
+ /**
+ * Get a property and return it as an int. Returns the default value if the
+ * property cannot be found or formatted as an int.
+ * @param property
+ * @param defaultValue
+ * @return
+ */
+ public int getPropertyAsIntWithDefault(String property, int defaultValue)
+ {
+ try {
+ return new Integer(getProperty(property)).intValue();
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/PropertyNotFoundException.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/PropertyNotFoundException.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/configuration/PropertyNotFoundException.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,30 @@
+/*
+ * Created on 26/05/2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.drools.testing.core.configuration;
+
+import org.drools.testing.core.exception.RuleTestLanguageException;
+
+/**
+ * @author mshaw
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class PropertyNotFoundException extends RuleTestLanguageException {
+
+ public PropertyNotFoundException() {
+ super();
+ }
+
+ public PropertyNotFoundException(String message) {
+ super(message);
+ }
+
+ public PropertyNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/ObjectUtilsException.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/ObjectUtilsException.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/ObjectUtilsException.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,22 @@
+package org.drools.testing.core.exception;
+
+public class ObjectUtilsException extends RuleTestLanguageException {
+
+public ObjectUtilsException () {
+
+ super();
+
+ }
+
+ public ObjectUtilsException (String message) {
+
+ super(message);
+
+ }
+
+ public ObjectUtilsException (String message, Throwable cause) {
+
+ super(message,cause);
+
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/RuleTestLanguageException.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/RuleTestLanguageException.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/RuleTestLanguageException.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,69 @@
+/*
+ * Created on 30/11/2006
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.drools.testing.core.exception;
+
+/**
+ * @author mshaw
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public abstract class RuleTestLanguageException extends Exception {
+
+ private Throwable cause = null;
+
+ public RuleTestLanguageException () {
+ super();
+ }
+
+ public RuleTestLanguageException (String message) {
+ super(message);
+ }
+
+ public RuleTestLanguageException (String message, Throwable cause) {
+ super(message);
+ this.cause = cause;
+ }
+
+ public Throwable getCause() {
+ return cause;
+ }
+
+ public void printStackTrace() {
+ super.printStackTrace();
+ if (cause != null) {
+ System.err.println("Caused by:");
+ cause.printStackTrace();
+ }
+ }
+
+ public void printStackTrace(java.io.PrintStream ps) {
+ super.printStackTrace(ps);
+ if (cause != null) {
+ ps.println("Caused by:");
+ cause.printStackTrace(ps);
+ }
+ }
+
+ public void printStackTrace(java.io.PrintWriter pw) {
+ super.printStackTrace(pw);
+ if (cause != null) {
+ pw.println("Caused by:");
+ cause.printStackTrace(pw);
+ }
+ }
+
+ public String toString()
+ {
+ String exceptionString = super.toString();
+ if (cause != null) {
+ exceptionString += " Caused By: \n";
+ exceptionString += cause.toString();
+ }
+ return exceptionString;
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/TransformerServiceException.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/TransformerServiceException.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/exception/TransformerServiceException.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,22 @@
+package org.drools.testing.core.exception;
+
+public class TransformerServiceException extends RuleTestLanguageException {
+
+public TransformerServiceException () {
+
+ super();
+
+ }
+
+ public TransformerServiceException (String message) {
+
+ super(message);
+
+ }
+
+ public TransformerServiceException (String message, Throwable cause) {
+
+ super(message,cause);
+
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/SchemaBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/SchemaBuilder.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/SchemaBuilder.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,38 @@
+package org.drools.testing.core.main;
+
+import java.io.FileWriter;
+
+import org.drools.lang.descr.PackageDescr;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.xml.XmlDumper;
+
+
+public class SchemaBuilder {
+
+ public static final void main(final String[] args) {
+ SchemaBuilder schemaBuilder = new SchemaBuilder();
+ //schemaBuilder.buildSchema();
+ schemaBuilder.buildTestSuite();
+ }
+
+ public void buildSchema () {
+ try {
+ PackageDescr packageDescr = TransformerService.parseDrl("/org/drools/testing/core/resources/drl/test.drl");
+ XmlDumper xmlDumper = new XmlDumper();
+ FileWriter writer = new FileWriter("drl.xml");
+ writer.write(xmlDumper.dump(packageDescr));
+ writer.close();
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void buildTestSuite () {
+ try {
+ TransformerService trService = new TransformerService();
+ TestSuite testSuite = trService.generateTestSuite("/org/drools/testing/core/resources/drl/test.drl");
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/Testing.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/Testing.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/Testing.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,224 @@
+package org.drools.testing.core.main;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import org.drools.lang.descr.ColumnDescr;
+import org.drools.lang.descr.LiteralDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.drools.testing.core.beans.Rule;
+import org.drools.testing.core.beans.Scenario;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.testing.core.configuration.ApplicationProperties;
+import org.drools.testing.core.configuration.PropertyNotFoundException;
+import org.drools.testing.core.exception.RuleTestLanguageException;
+import org.drools.testing.core.utils.CollectionUtils;
+import org.drools.testing.core.utils.ObjectUtils;
+import org.drools.testing.core.utils.OperatorUtils;
+import org.drools.testing.core.wrapper.FactWrapper;
+import org.drools.testing.core.wrapper.FieldWrapper;
+
+/**
+ *
+ * @author mshaw
+ *
+ * This class is the main class for the drools core testing module. It provides
+ * functionalilty for generating test scenario's based on an input set of rules.
+ *
+ * facts - an internal list which contains a unique list of facts and fields
+ */
+public final class Testing {
+
+ private TestSuite testSuite;
+ private Scenario scenario;
+ private PackageDescr packageDescr;
+ private Random rng;
+ private List facts = new ArrayList();
+ private ApplicationProperties applicationProperties = ApplicationProperties.getInstance();
+
+
+ public Testing () {
+
+ }
+
+ public Testing (String suiteName, PackageDescr packageDescr) {
+ this.testSuite = new TestSuite();
+ this.testSuite.setName(suiteName);
+ this.packageDescr = packageDescr;
+ }
+
+ /**
+ * return a testsuite serializable object with the name
+ *
+ * @param name
+ * @return
+ * @throws RuleTestLanguageException
+ */
+ public TestSuite getTestSuite () throws RuleTestLanguageException {
+
+ return this.testSuite;
+ }
+
+ /**
+ * Create a scenario object which will contain all the rules.
+ * We then make a call to processColumnDescriptors which will
+ * aid in generating our fact types.
+ *
+ * @throws RuleTestLanguageException
+ */
+ public Scenario generateScenario (String name, List rules) throws RuleTestLanguageException {
+
+ scenario = new Scenario();
+ scenario.setName(name);
+ rng = new Random();
+
+ Iterator i = rules.iterator();
+ while (i.hasNext()) {
+ RuleDescr rule = (RuleDescr) i.next();
+ scenario.addRule(getRule(rule));
+ processColumnDescriptors(rule.getLhs().getDescrs());
+ }
+
+ Iterator j = facts.iterator();
+ while (j.hasNext()) {
+ FactWrapper factWrapper = (FactWrapper) j.next();
+ factWrapper.setId(rng.nextInt());
+ scenario.addFact(factWrapper);
+ }
+
+ return scenario;
+ }
+
+ /**
+ *
+ * @param descrs
+ * @return List of facts
+ * @throws RuleTestLanguageException
+ */
+ public List processColumnDescriptors (List descrs) throws RuleTestLanguageException {
+
+ Iterator i = descrs.iterator();
+ while (i.hasNext()) {
+ // each columndescr is for a "when" statment in the drl
+ ColumnDescr columnDescr = (ColumnDescr) i.next();
+
+ Class classDefn = ObjectUtils.getClassDefn(columnDescr.getObjectType(), this.packageDescr.getImports());
+
+ FactWrapper fact = new FactWrapper();
+ fact.setType(classDefn.getName());
+ if (facts.contains(fact)) {
+ fact = (FactWrapper) facts.get(facts.indexOf(fact));
+ facts.remove(fact);
+ }
+
+ processLiteralDescriptors(classDefn, fact,columnDescr.getDescrs());
+ facts.add(fact);
+
+ }
+ return facts;
+ }
+
+ /**
+ *
+ * @param fact
+ * @param descrs
+ * @throws RuleTestLanguageException
+ */
+ public void processLiteralDescriptors (Class classDefn, FactWrapper fact, List descrs) throws RuleTestLanguageException {
+
+ List fields = (List) CollectionUtils.arrayToCollection(fact.getField());
+
+ Iterator i = descrs.iterator();
+ while (i.hasNext()) {
+ LiteralDescr literalDescr = (LiteralDescr) i.next();
+ FieldWrapper field = new FieldWrapper();
+ field.setName(literalDescr.getFieldName());
+ //field.setValue(literalDescr.getText());
+ field.setValue(getValue(literalDescr.getFieldName(), literalDescr.getText(), literalDescr.getEvaluator()));
+ field.setType(getType(classDefn, literalDescr.getFieldName()).getName());
+
+ if (!fields.contains(field))
+ fact.addField(field);
+ }
+ }
+
+ /**
+ *
+ * @param ruleDescr
+ * @return Rule
+ * @throws RuleTestLanguageException
+ */
+ public Rule getRule (RuleDescr ruleDescr) throws RuleTestLanguageException {
+
+ Rule rule = new Rule();
+ rule.setName(ruleDescr.getName());
+ rule.setFire(true);
+
+
+
+
+ return rule;
+ }
+
+ /**
+ *
+ * @param scenario
+ * @throws RuleTestLanguageException
+ */
+ public void addScenarioToSuite (Scenario scenario) throws RuleTestLanguageException {
+
+ this.testSuite.addScenario(scenario);
+ }
+
+ public Class getType (Class classDefn, String fieldName) {
+
+ Class type = null;
+ try {
+ type = classDefn.getDeclaredField(fieldName).getType();
+ }catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ return type;
+ }
+
+ public String getValue (String fieldName, String value, String operator) {
+
+ String result = null;
+
+ // is it a range?
+ if (OperatorUtils.rangeOperators.indexOf(operator) != -1)
+ result = getRangeValue(operator, value);
+ else
+ result = value;
+
+
+ return result;
+ }
+
+ public String getRangeValue (String operator, String value) {
+
+ String result = null;
+
+ try {
+ Integer min = new Integer(applicationProperties.getProperty("range.min"));
+ Integer max = new Integer(applicationProperties.getProperty("range.max"));
+
+ if (operator.indexOf("<") != -1)
+ max = new Integer(value);
+ else if (operator.indexOf(">") != -1)
+ min = new Integer(value);
+
+ result = min.toString();
+ for (int i=min.intValue()+1; i<max.intValue(); i++)
+ result = result + "," + i;
+
+ }catch (PropertyNotFoundException e) {
+
+ }
+
+ return result;
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/TransformerService.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/TransformerService.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/main/TransformerService.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,75 @@
+package org.drools.testing.core.main;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.drools.compiler.DrlParser;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.testing.core.exception.RuleTestLanguageException;
+import org.drools.testing.core.exception.TransformerServiceException;
+import org.drools.testing.core.rules.RuleSetTest;
+import org.drools.xml.XmlDumper;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Unmarshaller;
+import org.xml.sax.InputSource;
+
+public final class TransformerService {
+
+ public TransformerService () {
+ }
+
+ /**
+ * parseDrl uses the drools drl parser to read the drl and return object description
+ */
+ public final static PackageDescr parseDrl (String file) throws RuleTestLanguageException {
+
+ DrlParser drlParser = new DrlParser();
+ try {
+ Reader reader = new InputStreamReader( RuleSetTest.class.getResourceAsStream( file ) );
+ return drlParser.parse(reader);
+ }catch (Exception e) {
+ throw new TransformerServiceException("Exception ocurred ",e);
+ }
+ }
+
+ /**
+ * unMarshallDocument takes a drools PackageDescr and uses castor to
+ * unmarshall the document to a data transfer object indicative of an RTL file
+ */
+
+ public Object unMarshallDocument (PackageDescr packageDescr) throws RuleTestLanguageException {
+
+ Mapping mapping = new Mapping();
+ try {
+ InputSource inputSource = new InputSource(getClass().getResourceAsStream("/org/drools/testing/core/resources/castor/castor-mapping.xml"));
+ mapping.loadMapping(inputSource);
+ Unmarshaller unmarshaller = new Unmarshaller(mapping);
+ XmlDumper xmlDumper = new XmlDumper();
+ Object test = (Object) unmarshaller.unmarshal(new InputSource(new StringReader(xmlDumper.dump(packageDescr))));
+ return test;
+ }catch (Exception e) {
+ throw new TransformerServiceException("Exception ocurred ",e);
+ }
+ }
+
+ /**
+ * generateTestSuite
+ * takes a drl, unmarshalls it to a TestSuite object.
+ *
+ * This method can be overloaded so that the document being parsed and mapped
+ * can be any structure, for the moment I am just handling a mapping
+ * for drools drl files.
+ */
+ public TestSuite generateTestSuite (String file) throws RuleTestLanguageException {
+ TestSuite testSuite=null;
+ try {
+ testSuite = (TestSuite) unMarshallDocument(parseDrl(file));
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ return testSuite;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/META-INF/test-lang.xsd
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/META-INF/test-lang.xsd (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/META-INF/test-lang.xsd 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://drools.org/testing"
+ elementFormDefault="qualified"
+ xmlns:test="http://drools.org/testing">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+ Test schema for jbossrules.org/rtl
+ Copyright 2006 jbossrules.org. All rights reserved.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:element name="testSuite">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="scenario" type="test:scenarioType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="description" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="scenarioType">
+ <xs:sequence>
+ <xs:element name="fact" type="test:factType" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="rule" type="test:ruleType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ </xs:complexType>
+
+ <xs:complexType name="factType">
+ <xs:sequence>
+ <xs:element name="type" type="xs:string"/>
+ <xs:element name="field" type="test:fieldType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="id" use="required" type="xs:integer"/>
+ </xs:complexType>
+
+ <xs:complexType name="fieldType">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="type" type="xs:string"/>
+ <xs:element name="value" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="ruleType">
+ <xs:sequence>
+ <xs:element name="result" type="test:fieldType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="fire" use="required" type="xs:boolean"/>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xml
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xml (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xml 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,11 @@
+<binding xmlns="http://www.castor.org/SourceGenerator/Binding"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.castor.org/SourceGenerator/Binding"
+ defaultBindingType="element">
+
+ <elementBinding name="/testSuite">
+ <java-class>
+ <extends>org.drools.rule.Package</extends>
+ </java-class>
+ </elementBinding>
+</binding>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xsd
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xsd (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/binding/binding.xsd 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,248 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ Castor Source Generator Binding File XML Schema
+ Namespace: http://castor.exolab.org/SourceGenerator/Binding
+ System: http://castor.exolab.org/binding.xsd
+ Public: -//EXOLAB/Castor Binding Schema Version 1.0//EN
+
+ This schema is used to generate part of the
+ org.exolab.castor.builder.binding package
+ *Note*: This schema is under evolution and subject to change.
+ This schema is under the Exolab license
+
+ Author: Arnaud Blandin [blandin at intalio.com]
+ -->
+<!-- $Id: binding.xsd 5951 2006-05-30 22:18:48Z bsnyder $ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.castor.org/SourceGenerator/Binding"
+ xmlns="http://www.castor.org/SourceGenerator/Binding"
+ elementFormDefault="unqualified">
+
+ <!-- The root element -->
+ <xsd:element name="binding">
+ <xsd:annotation>
+ <xsd:documentation>
+ The root element that contains the different binding elements.
+ The binding file is written from a schema point of view and follows the
+ structure of an XML Schema.
+ The root element can also be used to configure the default binding type.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="include" type="includeType" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element name="package" type="packageType" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element name="namingXML" type="namingXMLType" minOccurs="0" maxOccurs="1"/>
+ <xsd:element ref="elementBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="attributeBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="complexTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="groupBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <!-- Not yet implemented -->
+ <!--<xsd:element name="enumBinding" type="enumBindingType" minOccurs="0" maxOccurs="unbounded"/>-->
+ </xsd:sequence>
+ <!-- the binding type: 'element' approach or 'type' approach -->
+ <xsd:attribute name="defaultBindingType" type="bindingType"/>
+ </xsd:complexType>
+ </xsd:element>
+
+ <!--global definition to allow reference-->
+ <xsd:element name="elementBinding" type="componentBindingType"/>
+ <xsd:element name="attributeBinding" type="componentBindingType"/>
+ <xsd:element name="complexTypeBinding" type="componentBindingType"/>
+ <xsd:element name="groupBinding" type="componentBindingType"/>
+
+ <!--ComplexTypes definitions-->
+ <xsd:complexType name="includeType">
+ <xsd:annotation>
+ <xsd:documentation>
+ A binding file can include other binding files by specifying the location
+ (URI) of the binding files to include.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:attribute name="URI" type="xsd:anyURI" use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="packageType">
+ <xsd:annotation>
+ <xsd:documentation>
+ Mappings between a namespace and a java package can directly
+ be defined in the binding file. This element allows also the mapping
+ between a package and a schemaLocation.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <!--fully qualified name-->
+ <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
+ <xsd:choice>
+ <xsd:element name="namespace" type="xsd:string" minOccurs="1" maxOccurs="1"/>
+ <xsd:element name="schemaLocation" type="xsd:string" minOccurs="1" maxOccurs="1"/>
+ </xsd:choice>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="namingXMLType">
+ <xsd:annotation>
+ <xsd:documentation>
+ This element allows to define naming convention when naming a complexType, element or
+ modelGroup. Indeed the user can decide of a prefix to add to each class name as well
+ as a suffix. This naming style won't affect the names entered in the binding file but only
+ the XML Names.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:element name="elementName" type="namingType" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="complexTypeName" type="namingType" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="modelGroupName" type="namingType" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="namingType">
+ <xsd:sequence>
+ <xsd:element name="prefix" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="suffix" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="componentBindingType">
+ <xsd:annotation>
+ <xsd:documentation>
+ A binding element is defined to express the binding between an XML Schema Component
+ and Java class OR a java interface or a java member class. The XML Schema component can
+ be an element, an attribute, a complexType or a group. Attribute cannot be mapped to
+ class, the reader of a binding file will take care that class or interface are not
+ used for component whose xml-type is attribute.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:choice>
+ <xsd:element name="java-class" type="classType"/>
+ <xsd:element name="interface">
+ <xsd:complexType>
+ <xsd:attribute name="name" type="xsd:string" use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="member" type="fieldType"/>
+ </xsd:choice>
+ <xsd:element ref="elementBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="attributeBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="complexTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element ref="groupBinding" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <!--the name of the schema component or an XPath expression that identify the component-->
+ <xsd:attribute name="name" type="pathType" use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="classType">
+ <xsd:annotation>
+ <xsd:documentation>
+ This type gathers the needed information to generate a Java Class
+ from a binding file. Options such as generating the equals method,
+ using wrapper classes for primitives or using bound properties can
+ be defined via that element. When defined locally the options override
+ the values defined in the castor.properties file.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:element name="implements" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element name="extends" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <!-- not yet implemented -->
+ <!--<xsd:element name="javadoc" type="xsd:string" minOccurs="0" maxOccurs="1"/>-->
+ </xsd:sequence>
+ <!--This attribute allows the local redefinition of a package name-->
+ <xsd:attribute name="package" type="xsd:string"/>
+ <xsd:attribute name="name" type="xsd:string"/>
+ <xsd:attribute name="final" type="xsd:boolean"/>
+ <xsd:attribute name="abstract" type="xsd:boolean"/>
+ <!--properties for generating specific methods-->
+ <xsd:attribute name="equals" type="xsd:boolean"/>
+ <xsd:attribute name="bound" type="xsd:boolean"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="fieldType">
+ <xsd:annotation>
+ <xsd:documentation>
+ This type represents the binding for class member. It allows the definition
+ of its name and java type as well as an implementation of FieldHandler
+ to help the Marshalling framework in handling that member. Defining a validator is also
+ possible. The names given for the validator and the fieldHandler must be fully qualified
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:attribute name="name" type="xsd:string"/>
+ <xsd:attribute name="java-type" type="xsd:string"/>
+ <xsd:attribute name="wrapper" type="xsd:boolean"/>
+ <xsd:attribute name="handler" type="xsd:string"/>
+ <!-- if the java-type is a primitive, the collection type must be an array -->
+ <!-- the validation of the above statement must be enforced in the generated sources -->
+ <xsd:attribute name="collection">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="array"/>
+ <xsd:enumeration value="vector"/>
+ <xsd:enumeration value="arraylist"/>
+ <xsd:enumeration value="hashtable"/>
+ <xsd:enumeration value="collection"/>
+ <xsd:enumeration value="odmg"/>
+ <xsd:enumeration value="set"/>
+ <xsd:enumeration value="map"/>
+ <xsd:enumeration value="sortedset"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="validator" type="xsd:string"/>
+ </xsd:complexType>
+
+ <!-- <xsd:complexType name="enumBindingType">
+ <xsd:annotation>
+ <xsd:documentation>
+ This type allows the mapping between an XML schema enumeration
+ and a java class that follows the type-safe enumeration paradigm.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:element name="enumClassName">
+ <xsd:complexType>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="package" type="xsd:string"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="enumMember">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string"/>
+ <xsd:element name="javaName" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>-->
+
+ <!--simpleType definitions-->
+ <xsd:simpleType name="pathType">
+ <xsd:annotation>
+ <xsd:documentation>
+ This type represents an easy path to access an element or an attribute
+ inside a schema. It is a direct restriction of the XPath specification.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:string">
+ <!-- <xsd:pattern value="//any Valid XML name(//|@)any Valid XML Name "/>-->
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="bindingType">
+ <xsd:annotation>
+ <xsd:documentation>
+ List of the allowed values for the binding type from an XML schema
+ to a java class. The type can either be 'element' or 'complexType'.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="element"/>
+ <xsd:enumeration value="type"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+</xsd:schema>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/castor-mapping.xml
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/castor-mapping.xml (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/castor-mapping.xml 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
+ "http://castor.org/mapping.dtd">
+<mapping>
+ <class name="org.drools.testing.core.beans.TestSuite" auto-complete="true">
+ <map-to element="package"/>
+ </class>
+</mapping>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/properties/castorbuilder.properties
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/properties/castorbuilder.properties (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/castor/properties/castorbuilder.properties 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1 @@
+org.exolab.castor.builder.equalsmethod=true
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/5_rules.drl
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/5_rules.drl (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/5_rules.drl 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,38 @@
+package org.drools.samples
+import org.drools.benchmark.models.Account;
+
+rule rule0
+ when
+ $acc : Account(status == "standard", title == "mr", accountId == "acc0")
+ then
+ System.out.println("rule0 fired");
+end
+
+rule rule1
+ when
+ $acc : Account(status == "standard", title == "mr", accountId == "acc1")
+ then
+ System.out.println("rule1 fired");
+end
+
+rule rule2
+ when
+ $acc : Account(status == "standard", title == "mr", accountId == "acc2")
+ then
+ System.out.println("rule2 fired");
+end
+
+rule rule3
+ when
+ $acc : Account(status == "standard", title == "mr", accountId == "acc3")
+ then
+ System.out.println("rule3 fired");
+end
+
+rule rule4
+ when
+ $acc : Account(status == "standard", title == "mr", accountId == "acc4")
+ then
+ System.out.println("rule4 fired");
+end
+
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/META-INF/drools-3.0.xsd
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/META-INF/drools-3.0.xsd (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/META-INF/drools-3.0.xsd 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:drools="http://drools.org/drools-3.0"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ targetNamespace="http://drools.org/drools-3.0">
+
+ <xs:element name="package">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="drools:import"/>
+
+ <xs:element ref="drools:global"/>
+
+ <xs:element ref="drools:function"/>
+
+ <xs:element ref="drools:rule"/>
+
+ <xs:element ref="drools:query"/>
+ </xs:choice>
+
+ <xs:attribute name="name" type="xs:string" use="required"/>
+
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="rule">
+ <xs:complexType>
+ <xs:sequence>
+
+ <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:rule-attribute"/>
+
+ <xs:element ref="drools:lhs"/>
+
+ <xs:element ref="drools:rhs"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="required"/>
+
+ </xs:complexType>
+
+ <!-- All rules must have unique names -->
+ <xs:key name="ruleName">
+ <xs:selector xpath="drools:rule"/>
+ <xs:field xpath="@name"/>
+ </xs:key>
+ </xs:element>
+
+ <xs:element name="query">
+ <xs:complexType>
+ <xs:sequence>
+
+ <xs:element ref="drools:lhs"/>
+
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="required"/>
+
+ </xs:complexType>
+
+ <!-- All rules must have unique names -->
+ <xs:key name="queryName">
+ <xs:selector xpath="drools:query"/>
+ <xs:field xpath="@name"/>
+ </xs:key>
+ </xs:element>
+
+ <xs:element name="rule-attribute">
+ <xs:complexType>
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ <xs:attribute name="value" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+
+ <xs:element name="import">
+ <xs:complexType>
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="global">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required"/>
+ <xs:attribute name="identifier" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="function">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:parameter"/>
+ <xs:element name="body" type="xs:string"/>
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ <xs:attribute name="return-type" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="parameter">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required"/>
+ <xs:attribute name="identifier" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+
+ <xs:element name="rhs" type="xs:string"/>
+
+ <xs:element name="lhs">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="drools:and"/>
+ <xs:element ref="drools:or"/>
+ <xs:element ref="drools:not"/>
+ <xs:element ref="drools:exists"/>
+ <xs:element ref="drools:eval"/>
+ <xs:element ref="drools:column"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="and">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="drools:and"/>
+ <xs:element ref="drools:or"/>
+ <xs:element ref="drools:not"/>
+ <xs:element ref="drools:exists"/>
+ <xs:element ref="drools:eval"/>
+ <xs:element ref="drools:column"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="or">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="drools:and"/>
+ <xs:element ref="drools:or"/>
+ <xs:element ref="drools:not"/>
+ <xs:element ref="drools:exists"/>
+ <xs:element ref="drools:eval"/>
+ <xs:element ref="drools:column"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="not">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="drools:column"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="exists">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="drools:column"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="eval" type="xs:string" />
+
+ <xs:element name="column">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
+ <xs:element ref="drools:field-binding"/>
+ <xs:element ref="drools:literal"/>
+ <xs:element ref="drools:predicate"/>
+ <xs:element ref="drools:return-value"/>
+ <xs:element ref="drools:bound-variable"/>
+ </xs:choice>
+ <xs:attribute name="identifier" type="xs:string" use="optional"/>
+ <xs:attribute name="object-type" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="field-binding">
+ <xs:complexType>
+ <xs:attribute name="field-name" type="xs:string" use="required"/>
+ <xs:attribute name="identifier" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="literal">
+ <xs:complexType>
+ <xs:attribute name="field-name" type="xs:string" use="required"/>
+ <xs:attribute name="evaluator" type="xs:string" use="required"/>
+ <xs:attribute name="value" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="predicate">
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="field-name" type="xs:string" use="required"/>
+ <xs:attribute name="identifier" type="xs:string" use="required"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="return-value">
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="field-name" type="xs:string" use="required"/>
+ <xs:attribute name="evaluator" type="xs:string" use="required"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="bound-variable">
+ <xs:complexType>
+ <xs:attribute name="field-name" type="xs:string" use="required"/>
+ <xs:attribute name="evaluator" type="xs:string" use="required"/>
+ <xs:attribute name="identifier" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/test.drl
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/test.drl (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/drl/test.drl 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,29 @@
+package org.drools.testing.core.rules
+import org.drools.testing.core.rules.model.Account;
+import org.drools.testing.core.rules.model.Person;
+
+rule rule1
+ when
+ $acc : Account (status == "active", balance == 0)
+ $person : Person ( age < 60 )
+ then
+ $acc.setBalance(new Integer(0));
+ modify($acc);
+ System.out.println("firing rule1");
+end
+
+rule rule2
+ when
+ $acc : Account (status == "active", balance < 0)
+ then
+ $acc.setStatus("overdrawn");
+ modify($acc);
+ System.out.println("Your account is overdrawn. Balance: "+$acc.getBalance());
+end
+
+rule rule3
+ when
+ $acc : Account (balance > 0)
+ then
+ System.out.println("The banks likes you.. so we're increasing our fees!");
+end
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/rtl/rtl.properties
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/rtl/rtl.properties (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/resources/rtl/rtl.properties 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,3 @@
+# standard properties for rtl parsing
+range.min=0
+range.max=100
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/RuleSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/RuleSetTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/RuleSetTest.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,59 @@
+package org.drools.testing.core.rules;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.WorkingMemory;
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.PackageBuilder;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.rule.Package;
+import org.drools.testing.core.rules.model.Account;
+
+public class RuleSetTest {
+
+ public static final void main(final String[] args) {
+ RuleSetTest test = new RuleSetTest();
+ test.testRules();
+ }
+
+ /**
+ * Loads a package and creates a rulebase
+ *
+ * @param file
+ * @return
+ * @throws Exception
+ */
+ private static RuleBase readRule(String file) throws Exception {
+ //read in the source
+ Reader reader = new InputStreamReader( RuleSetTest.class.getResourceAsStream( file ) );
+ DrlParser parser = new DrlParser();
+ PackageDescr packageDescr = parser.parse( reader );
+
+ //pre build the package
+ PackageBuilder builder = new PackageBuilder();
+ builder.addPackage( packageDescr );
+ Package pkg = builder.getPackage();
+
+ //add the package to a rulebase
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage( pkg );
+ return ruleBase;
+ }
+
+ public void testRules() {
+ try {
+ String file = "test.drl";
+ RuleBase ruleBase = readRule( file );
+ WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ Account acc = new Account();
+ workingMemory.assertObject(acc);
+ workingMemory.fireAllRules();
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Account.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Account.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Account.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,27 @@
+package org.drools.testing.core.rules.model;
+
+
+public class Account {
+
+ private Integer balance = new Integer(0);
+ private String status = "active";
+
+ public Account () {}
+
+ public Integer getBalance() {
+ return balance;
+ }
+
+ public void setBalance(Integer balance) {
+ this.balance = balance;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Person.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Person.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/rules/model/Person.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,26 @@
+package org.drools.testing.core.rules.model;
+
+public class Person {
+
+ private String name;
+ private Integer age;
+
+ public Person () {
+
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/TestingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/TestingTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/TestingTest.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,32 @@
+package org.drools.testing.core.test;
+
+import java.io.FileWriter;
+
+import junit.framework.TestCase;
+
+import org.drools.lang.descr.PackageDescr;
+import org.drools.testing.core.beans.Scenario;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.testing.core.main.Testing;
+import org.drools.testing.core.main.TransformerService;
+
+public class TestingTest extends TestCase {
+
+ public void testGetScenario () throws Exception {
+
+ PackageDescr paDescr = TransformerService.parseDrl("/org/drools/testing/core/resources/drl/test.drl");
+ Testing testing = new Testing("The Test Test Suite", paDescr);
+ Scenario scenario = testing.generateScenario("Scenario One",paDescr.getRules());
+ assertTrue(scenario.getFactCount() > 0);
+ }
+
+ public void testGenerateRTL () throws Exception {
+ PackageDescr paDescr = TransformerService.parseDrl("/org/drools/testing/core/resources/drl/test.drl");
+ Testing testing = new Testing("The Test Test Suite", paDescr);
+ Scenario scenario = testing.generateScenario("Scenario One",paDescr.getRules());
+ testing.addScenarioToSuite(scenario);
+ TestSuite testSuite = testing.getTestSuite();
+ FileWriter out = new FileWriter("rtl/test.rtl");
+ testSuite.marshal(out);
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/ThingTester.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/ThingTester.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/ThingTester.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,13 @@
+package org.drools.testing.core.test;
+
+import org.drools.testing.core.utils.OperatorUtils;
+
+import junit.framework.TestCase;
+
+public class ThingTester extends TestCase {
+
+ public void testFieldUtils () {
+
+ System.out.println(OperatorUtils.rangeOperators.indexOf("<"));
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/test/rtl.properties
===================================================================
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/CollectionUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/CollectionUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/CollectionUtils.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,68 @@
+package org.drools.testing.core.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * A Collection of utilities that can be used modify collections. Many
+ * utilities are provided within the java.util.Collections class and
+ * should not be duplicated here.
+ * @see java.util.Collections
+ */
+public class CollectionUtils {
+
+ /**
+ * A method used to return a sub collection given an original, a to
+ * and from index. The subCollection is backed by a java.util.ArrayList. This method
+ * should be used when a subCollection is required to be passed as a
+ * Serializable object. For example, the method List.subList(int fromIndex, int toIndex)
+ * is not appropriate as it not Serializable.
+ * @param original The original collection
+ * @param fromIndex The starting index to inclusive add from
+ * @param toIndex The endIndex to inclusive add too
+ * @return Collection with 0 or more elements fom the original.
+ */
+ public static Collection getSubCollection(Collection original, int fromIndex, int toIndex)
+ {
+ String methodName = "getSubCollection(Collection original, int fromIndex, int toIndex)";
+ ArrayList subCollection = new ArrayList();
+ Iterator originalIterator = original.iterator();
+ int count = 0;
+ while (originalIterator.hasNext())
+ {
+ Object nextObject = originalIterator.next();
+ if (count >= fromIndex && count <= toIndex)
+ {
+ subCollection.add(nextObject);
+ }
+ count++;
+ }
+ return subCollection;
+ }
+
+ /**
+ * Convert an Object array to a Collection
+ * @param objectArray
+ * @return
+ */
+ public static Collection arrayToCollection(Object[] objectArray)
+ {
+ ArrayList conversion = new ArrayList();
+ for (int i = 0; i < objectArray.length; i++)
+ {
+ conversion.add(objectArray[i]);
+ }
+ return conversion;
+ }
+
+ public static Object getLastItem (Collection items) {
+ Object nextObject = new Object();
+ Iterator i = items.iterator();
+ while (i.hasNext()) {
+ nextObject = i.next();
+ }
+ return nextObject;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/FieldUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/FieldUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/FieldUtils.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,10 @@
+package org.drools.testing.core.utils;
+
+
+public final class FieldUtils {
+
+
+
+
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/ObjectUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/ObjectUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/ObjectUtils.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,43 @@
+package org.drools.testing.core.utils;
+
+import java.util.List;
+
+import org.drools.semantics.java.ClassTypeResolver;
+
+public final class ObjectUtils {
+
+ public static Object createObject(String className) {
+ Object object = null;
+ try {
+ //Class classDefinition = Class.forName(className, false, ClassLoader.getSystemClassLoader());
+ Class classDefinition = Class.forName(className);
+ object = classDefinition.newInstance();
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ return object;
+ }
+
+ public static Class getClassDefn (String className) {
+ Class classDefinition = null;
+ try {
+ //classDefinition = Class.forName(className, false, ClassLoader.getSystemClassLoader());
+ classDefinition = Class.forName(className);
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ return classDefinition;
+ }
+
+ public static Class getClassDefn (String className, List imports) {
+ Class classDefinition = null;
+ try {
+ ClassTypeResolver cResolver = new ClassTypeResolver(imports);
+ classDefinition = cResolver.resolveType(className);
+ }catch (Exception e) {
+ System.out.println(e);
+ }
+ return classDefinition;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/OperatorUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/OperatorUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/utils/OperatorUtils.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,6 @@
+package org.drools.testing.core.utils;
+
+public final class OperatorUtils {
+
+ public static final String rangeOperators = "<,>";
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FactWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FactWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FactWrapper.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,31 @@
+package org.drools.testing.core.wrapper;
+
+import org.drools.testing.core.beans.Fact;
+
+public class FactWrapper extends Fact {
+
+ public FactWrapper () {
+ super();
+ }
+
+ public boolean equals(java.lang.Object obj)
+ {
+ if ( this == obj )
+ return true;
+
+ if (obj instanceof Fact) {
+
+ Fact temp = (Fact)obj;
+ if (this.getType() != null) {
+ if (temp.getType() == null) return false;
+ else if (!(this.getType().equals(temp.getType())))
+ return false;
+ }
+ else if (temp.getType() != null)
+ return false;
+
+ return true;
+ }
+ return false;
+ }
+}
Added: labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FieldWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FieldWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-testing/src/org/drools/testing/core/wrapper/FieldWrapper.java 2007-02-01 14:49:00 UTC (rev 9261)
@@ -0,0 +1,31 @@
+package org.drools.testing.core.wrapper;
+
+import org.drools.testing.core.beans.Field;
+
+public class FieldWrapper extends Field {
+
+ public FieldWrapper () {
+ super();
+ }
+
+ public boolean equals(java.lang.Object obj)
+ {
+ if ( this == obj )
+ return true;
+
+ if (obj instanceof Field) {
+
+ Field temp = (Field)obj;
+ if (this.getName() != null) {
+ if (temp.getName() == null) return false;
+ else if (!(this.getName().equals(temp.getName())))
+ return false;
+ }
+ else if (temp.getName() != null)
+ return false;
+
+ return true;
+ }
+ return false;
+ }
+}
More information about the jboss-svn-commits
mailing list