Package org.kie.api.runtime

Examples of org.kie.api.runtime.KieSession


    @Test
    public void testScorecard() throws Exception {
        setKSession( getModelSession( source1, VERBOSE ) );
        setKbase( getKSession().getKieBase() );
        KieSession kSession = getKSession();

        kSession.fireAllRules()//init model

        kSession.getEntryPoint( "in_Age" ).insert( 33.0 );
        kSession.getEntryPoint( "in_Occupation" ).insert( "SKYDIVER" );
        kSession.getEntryPoint( "in_ResidenceState" ).insert( "KN" );
        kSession.getEntryPoint( "in_ValidLicense" ).insert( true );

        kSession.fireAllRules()//init model

        FactType scoreCardType = getKbase().getFactType( PMML4Helper.pmmlDefaultPackageName(), "ScoreCard" );
        assertNotNull( scoreCardType );

        assertEquals( 1, kSession.getObjects( new ClassObjectFilter( scoreCardType.getFactClass() ) ).size() );
        Object scoreCard = kSession.getObjects( new ClassObjectFilter( scoreCardType.getFactClass() ) ).iterator().next();

        System.out.printreportWMObjects( kSession )
        );
        assertEquals( "SampleScore", scoreCardType.get( scoreCard, "modelName" ) );
        assertEquals( 41.345, scoreCardType.get( scoreCard, "score" ) );
View Full Code Here


    @Test
    public void testScorecardOutputs() throws Exception {
        setKSession( getModelSession( source2, VERBOSE ) );
        setKbase( getKSession().getKieBase() );
        KieSession kSession = getKSession();

        kSession.fireAllRules()//init model

        kSession.getEntryPoint( "in_Cage" ).insert( "engineering" );
        kSession.getEntryPoint( "in_Age" ).insert( 25 );
        kSession.getEntryPoint( "in_Wage" ).insert( 500.0 );

        kSession.fireAllRules()//init model

        checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName,"OutRC1"),
                        true, false,"SampleScorecard", "RC2" );
        checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName,"OutRC2"),
                        true, false,"SampleScorecard", "RC1" );
View Full Code Here


    @Test
    public void invokePmmlWithRawData() {

        KieSession kSession = getModelSession( pmmlSource, false );
        // One entry-point per input field
        //      field name "xyz" => entry point name "in_Xyz"
        kSession.getEntryPoint( "in_Temp" ).insert( 22.0 );
        kSession.fireAllRules();

        // Query results
        //      output field name   --> query name
        //      model name          --> first arg
        //      value               --> second arg ( Variable.v for output, any value for testing )
        QueryResults qrs = kSession.getQueryResults( "Cold", "MockCold", Variable.v );
        assertTrue( qrs.iterator().hasNext() );
        Object val = qrs.iterator().next().get( "$result" );

        assertEquals( 0.56, val );

        QueryResults qrs2 = kSession.getQueryResults( "Cold", "MockCold", 0.56 );
        assertTrue( qrs2.iterator().hasNext() );

        QueryResults qrs3 = kSession.getQueryResults( "Cold", "MockCold", 0.99 );
        assertFalse( qrs3.iterator().hasNext() );

    }
View Full Code Here

        assertTrue(annotation);
        assertTrue(appl);



        KieSession ksession = getSession( theory );
        KiePackage pack = ksession.getKieBase().getKiePackage( "org.drools.pmml.pmml_4_2.test" );
        assertNotNull(pack);

        ksession.dispose();
    }
View Full Code Here

        if ( res.hasMessages( Message.Level.ERROR ) ) {
            System.out.println( res.getMessages( Message.Level.ERROR ) );
        }
        assertEquals( 0, res.getMessages( Message.Level.ERROR ).size() );

        KieSession kSession = ks.newKieContainer( ks.getRepository().getDefaultReleaseId() ).newKieSession();

        kSession.insert( "trigger" );
        kSession.fireAllRules();

        System.out.println( reportWMObjects( kSession ) );

        QueryResults qrs = kSession.getQueryResults( "Cold", "MockCold", Variable.v );
        assertTrue( qrs.iterator().hasNext() );
        Object val = qrs.iterator().next().get( "$result" );
        Assert.assertEquals( 0.56, val );
    }
View Full Code Here

            throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
        }

        KieContainer kContainer = ks.newKieContainer(rid);

        KieSession kSession = kContainer.newKieSession("ksession6");
        kSession.setGlobal("out", out);

        Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
        kSession.insert(msg1);
        kSession.fireAllRules();

        Object msg2 = createMessage(kContainer, "Dave", "Open the pod bay doors, HAL.");
        kSession.insert(msg2);
        kSession.fireAllRules();

        Object msg3 = createMessage(kContainer, "Dave", "What's the problem?");
        kSession.insert(msg3);
        kSession.fireAllRules();
    }
View Full Code Here

    public void testExecuteUsingKieAPI() throws Exception {
        // get the resource
        Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass());
       
        // create the builder
        KieSession ksession = getKieSession( dt );

        ksession.insert( new Cheese( "stilton",
                                    42 ) );
        ksession.insert( new Person( "michael",
                                    "stilton",
                                    42 ) );
        final List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list",
                           list );
        ksession.fireAllRules();
        assertEquals( 1,
                      list.size() );
        assertEquals( "Old man stilton",
                      list.get( 0 ) );
    }
View Full Code Here

        KieFileSystem kfs = ks.newKieFileSystem().write( dt );
        KieBuilder kb = ks.newKieBuilder( kfs ).buildAll();
        assertTrue( kb.getResults().getMessages().isEmpty() );

        // get the session
        KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
        return ksession;
    }
View Full Code Here

    }

    @Test
    public void testExecuteJBRULES3005() throws Exception {
        Resource dt = ResourceFactory.newClassPathResource( "/data/IntegrationExampleTest.xls", getClass() );
        KieSession ksession = getKieSession( dt );

        //ASSERT AND FIRE
        ksession.insert( new Cheese( "stilton",
                                    42 ) );
        ksession.insert( new Person( "michael",
                                    "stilton",
                                    42 ) );
        final List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list",
                           list );
        ksession.fireAllRules();
        assertEquals( 1,
                      list.size() );
        assertEquals( "Old man stilton",
                      list.get( 0 ) );
    }
View Full Code Here

        dtconf.setInputType( DecisionTableInputType.XLS );
        dtconf.setWorksheetName( "Tables_2" );

        Resource dt = ResourceFactory.newClassPathResource( "/data/IntegrationExampleTest.xls", getClass() )
                                     .setConfiguration( dtconf );
        KieSession ksession = getKieSession( dt );

        //ASSERT AND FIRE
        ksession.insert( new Cheese( "cheddar",
                                    42 ) );
        ksession.insert( new Person( "michael",
                                    "stilton",
                                    25 ) );
        final List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list",
                           list );
        ksession.fireAllRules();
        assertEquals( 1,
                      list.size() );
        assertEquals( "Young man cheddar",
                      list.get( 0 ) );
    }
View Full Code Here

TOP

Related Classes of org.kie.api.runtime.KieSession

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.