从drools kie workbench加载工件进行测试

时间:2015-09-06 13:50:11

标签: drools-guvnor kie

我在测试使用工作台创建的示例规则时遇到以下问题。

附上模型,规则和日食测试场景。

enter image description here

enter image description here

问题:getCity始终返回null

在工作台中创建的等效模型代码。

规则检查客户ID是否小于100.如果客户ID小于100,则city设置为伦敦。

package com.sample;
public class CustomerDetails implements java.io.Serializable
{

   static final long serialVersionUID = 1L;

   private int customerID;
   private java.lang.String city;

   public CustomerDetails()
   {
   }

   public java.lang.String getCity()
   {
      return this.city;
   }

   public void setCity(java.lang.String city)
   {
      this.city = city;
   }

   public int getCustomerID()
   {
      return this.customerID;
   }

   public void setCustomerID(int customerID)
   {
      this.customerID = customerID;
   }

   public CustomerDetails(int customerID, java.lang.String city)
   {
      this.customerID = customerID;
      this.city = city;
   }

}

用于测试的eclipse中的代码

package com.sample;

import java.io.File;
import java.math.BigInteger;
import java.util.Scanner;

import org.drools.compiler.kproject.ReleaseIdImpl;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;

public class Testing {

    public static void main(String[] args)
    {

        String url = "http://localhost:8080/kie-drools-wb-distribution-wars-6.2.0.Final-jboss-as7/maven2/TestProject/demo/TestProject/1.0/TestProject-1.0.jar";
        ReleaseIdImpl releaseId = new ReleaseIdImpl("demo", "TestProject", "LATEST");
        KieServices kieServices = KieServices.Factory.get();
        kieServices.getResources().newUrlResource(url);
        KieContainer kieContainer = kieServices.newKieContainer(releaseId);
        KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
        kieScanner.scanNow();
        Scanner scanner = new Scanner(System.in);
        System.out.println("kieContainer.getKieBaseNames() "+kieContainer.getKieBaseNames());

        KieSession newKieSession =kieContainer.newKieSession("session1");

       // StatelessKieSession kSession = kieContainer.newStatelessKieSession();
        CustomerDetails testdetails=new CustomerDetails();
        //BigInteger lcustomerID = BigInteger.valueOf(20);
        testdetails.setCustomerID(10);
        newKieSession.insert(testdetails);
        newKieSession.fireAllRules();
        //kSession.execute(testdetails);

        System.out.println("testdetails.getCustomerID()= " +testdetails.getCustomerID());
        System.out.println("City= " +testdetails.getCity());
       // while (true) {
            //runRule(kieContainer);
          //  System.out.println("Press enter in order to run the test again....");
          //  scanner.nextLine();
        //}


    }

}

控制台输出:

18:04:52.734 [main] DEBUG o.d.c.k.b.impl.KieRepositoryImpl - KieModule Lookup. ReleaseId demo:TestProject:1.0.1 was not in cache, checking classpath
18:04:52.739 [main] DEBUG o.d.c.k.b.impl.KieRepositoryImpl - KieModule Lookup. ReleaseId demo:TestProject:1.0.1 was not in cache, checking maven repository
18:04:52.776 [main] WARN  o.kie.scanner.embedder.MavenSettings - Environment variable M2_HOME is not set
18:04:55.172 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:04:55.205 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:04:56.527 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:08.195 [main] DEBUG o.e.a.i.i.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=3, ConflictMarker.markTime=1, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=2, ConflictIdSorter.topsortTime=2, ConflictIdSorter.conflictIdCount=1, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=11, ConflictResolver.conflictItemCount=1, DefaultDependencyCollector.collectTime=340, DefaultDependencyCollector.transformTime=62}
18:05:08.830 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:08.835 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:08.847 [main] DEBUG o.e.a.i.i.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=0, ConflictMarker.markTime=1, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=0, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=0, DefaultDependencyCollector.transformTime=1}
18:05:29.310 [main] INFO  o.d.c.k.b.impl.KieRepositoryImpl - KieModule was added: ZipKieModule[releaseId=demo:TestProject:1.0.1,file=C:\Users\USER\.m2\repository\demo\TestProject\1.0.1\TestProject-1.0.1.jar]
18:05:29.626 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:29.628 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:29.639 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:29.927 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:29.930 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
18:05:29.947 [main] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\USER\.m2\repository
kieContainer.getKieBaseNames() [testsession1]
18:05:31.497 [main] DEBUG o.drools.core.impl.KnowledgeBaseImpl - Starting Engine in PHREAK mode
testdetails.getCustomerID()= 10
City= null

非常感谢任何帮助。

0 个答案:

没有答案