Package org.drools.spi

Examples of org.drools.spi.ClassObjectType


public class DeclarationTest extends TestCase
{

    public void testDeclaration()
    {
        ObjectType stringObjectType = new ClassObjectType( String.class );

        /* Determines how the bound value is extracted from the column */
        Extractor typeOfCheeseExtractor = new Extractor()
        {
            public Object getValue(Object object)
View Full Code Here


    }

    public void testGetFieldValue()
    {
        ObjectType stringObjectType = new ClassObjectType( String.class );

        /* Determines how the bound value is extracted from the column */
        Extractor typeOfCheeseExtractor = new Extractor()
        {
            public Object getValue(Object object)
View Full Code Here

     */
    public void testBoundConstraint()
    {
        InstrumentedWorkingMemoryImpl workingMemory = new InstrumentedWorkingMemoryImpl( );

        ObjectType stringObjectType = new ClassObjectType( String.class );

        /* Determines how the bound value is extracted from the column */
        Extractor typeOfCheeseExtractor = new Extractor( ) {
            public Object getValue(Object object)
            {
View Full Code Here

     */
    public void testDoubleBoundConstraint()
    {
        InstrumentedWorkingMemoryImpl workingMemory = new InstrumentedWorkingMemoryImpl( );

        ObjectType stringObjectType = new ClassObjectType( String.class );

        /* Determines how the bound value is extracted from the column */
        Extractor typeOfCheeseExtractor = new Extractor( ) {
            public Object getValue(Object object)
            {
View Full Code Here

     */
    public void testBooleanExpressionConstraint()
    {
        InstrumentedWorkingMemoryImpl workingMemory = new InstrumentedWorkingMemoryImpl( );

        ObjectType integerObjectType = new ClassObjectType( Integer.class );

        /* Determines how the bound value is extracted from the column */
        Extractor priceOfCheeseExtractor = new Extractor( ) {
            public Object getValue(Object object)
            {
View Full Code Here

     */
    public void testReturnValueConstraint()
    {
        InstrumentedWorkingMemoryImpl workingMemory = new InstrumentedWorkingMemoryImpl( );

        ObjectType integerObjectType = new ClassObjectType( Integer.class );

        /* Determines how the bound value is extracted from the column */
        Extractor priceOfCheeseExtractor = new Extractor( ) {
            public Object getValue(Object object)
            {
View Full Code Here

    {
        this.rete = new Rete();

        this.workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( this.rete ) );

        this.objectTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( Object.class ) );
        this.objectTypeNode.addObjectSink( new MockObjectSink() );

        this.stringTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( String.class ) );
        this.stringTypeNode.addObjectSink( new MockObjectSink() );

        this.cheeseTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( Cheese.class ) );
        this.cheeseTypeNode.addObjectSink( new MockObjectSink() );

        this.rete.ruleAdded();

    }
View Full Code Here

                        objectTypeNodes );
        assertContains( this.cheeseTypeNode,
                        objectTypeNodes );

        ObjectTypeNode node = new ObjectTypeNode( 0,
                                                  new ClassObjectType( Map.class ),
                                                  null );

        assertFalse( objectTypeNodes.contains( node ) );
    }
View Full Code Here

        /* Create an initial rete with just two object type nodes */
        this.rete = new Rete();
        this.workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( this.rete ) );

        this.objectTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( Object.class ) );
        this.objectTypeNode.addObjectSink( new MockObjectSink() );

        this.stringTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( String.class ) );
        this.stringTypeNode.addObjectSink( new MockObjectSink() );

        this.rete.ruleAdded();

        /* Create three objects and assert them */
        Object object1 = new Object();
        String string1 = "cheese";
        String string2 = "bread";
       
        FactHandleImpl handle1 = new FactHandleImpl( 1 );
        FactHandleImpl handle2 = new FactHandleImpl( 2 );
        FactHandleImpl handle3 = new FactHandleImpl( 3 );

        this.workingMemory.putObject( handle1,
                                      object1 );
        this.workingMemory.putObject( handle2,
                                      string1 );
        this.workingMemory.putObject( handle3,
                                      string2 );

        this.rete.assertObject( object1,
                                handle1,
                                context,
                                this.workingMemory );

        this.rete.assertObject( string1,
                                handle2,
                                context,
                                this.workingMemory );

        this.rete.assertObject( string2,
                                handle3,
                                context,
                                this.workingMemory );

        /* check object was asserted correctly */
        MockObjectSink sink1 = (MockObjectSink) this.objectTypeNode.getObjectSinks().get( 0 );
        assertLength( 3,
                      sink1.getAsserted() );

        /* check string was asserted correctly */
        MockObjectSink sink2 = (MockObjectSink) this.stringTypeNode.getObjectSinks().get( 0 );
        assertLength( 2,
                      sink2.getAsserted() );

        /* Now lets try adding a new "rule". We simulate this by getting/creating the string ObjectTypeNode
         * and then adding a tuplesink - at this point its obvlivious that the ObjectTypeNode already exists
         */
        this.stringTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( String.class ) );
        this.stringTypeNode.addObjectSink( new MockObjectSink() );
        assertLength( 2,
                      this.stringTypeNode.getObjectSinks() );
        MockObjectSink sink3 = (MockObjectSink) this.stringTypeNode.getObjectSinks().get( 1 );
        /* TupleSink is added but has no assertions */
        assertLength( 0,
                      sink3.getAsserted() );

        /* Lets add a Cheese ObjectTypeNode just to see show what happens when a totally new ObjectTypeNode is asserted */
        this.cheeseTypeNode = this.rete.getOrCreateObjectTypeNode( new ClassObjectType( Cheese.class ) );
        this.cheeseTypeNode.addObjectSink( new MockObjectSink() );

        /* And ofcourse its got zero assertions */
        MockObjectSink sink4 = (MockObjectSink) this.cheeseTypeNode.getObjectSinks().get( 0 );
        assertLength( 0,
View Full Code Here

    {
        /*
         * create a RuleBase with a single ObjectTypeNode we attach a MockObjectSink so we can detect assertions and retractions
         */
        Rete rete = new Rete();
        ObjectTypeNode objectTypeNode = rete.getOrCreateObjectTypeNode( new ClassObjectType( String.class ) );
        MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        RuleBase ruleBase = new RuleBaseImpl( rete );
        WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory();
       
View Full Code Here

TOP

Related Classes of org.drools.spi.ClassObjectType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.