⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 declarationtest.java

📁 drools 一个开放源码的规则引擎
💻 JAVA
字号:
package org.drools.rule;

import org.drools.rule.ConstraintTest.Cheese;
import org.drools.spi.ClassObjectType;
import org.drools.spi.Extractor;
import org.drools.spi.ObjectType;

import junit.framework.TestCase;

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)
            {
                return ((Cheese) object).getType();
            }
        };

        /* Bind the extractor to a decleration */
        /* Declarations know the column they derive their value form */
        Declaration declaration = new Declaration( 3,
                                                   "typeOfCheese",
                                                   stringObjectType,
                                                   typeOfCheeseExtractor,
                                                   5 );
        assertEquals( 3,
                      declaration.getIndex() );

        assertEquals( "typeOfCheese",
                      declaration.getIdentifier() );

        assertSame( stringObjectType,
                    declaration.getObjectType() );

        assertSame( typeOfCheeseExtractor,
                    declaration.getExtractor() );

        assertEquals( 5,
                      declaration.getColumn() );

    }

    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)
            {
                return ((Cheese) object).getType();
            }
        };

        /* Bind the extractor to a decleration */
        /* Declarations know the column they derive their value form */
        Declaration typeOfCheeseDeclaration = new Declaration( 0,
                                                               "typeOfCheese",
                                                               stringObjectType,
                                                               typeOfCheeseExtractor,
                                                               0 );

        /* Create some facts */
        Cheese cheddar = new Cheese( "cheddar",
                                     5 );

        /* Check we can extract Declarations correctly */
        assertEquals( "cheddar",
                      typeOfCheeseDeclaration.getValue( cheddar ) );
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -