Package org.drools.core.impl

Examples of org.drools.core.impl.KnowledgeBaseImpl


    @Test @Ignore
    public void testAgendaView() throws Exception {
        Reader source = new InputStreamReader(DebugViewsTest.class.getResourceAsStream("/debug.drl"));
        KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
        builder.addPackageFromDrl(source);
        KnowledgeBaseImpl ruleBase = (KnowledgeBaseImpl) KnowledgeBaseFactory.newKnowledgeBase();
        ruleBase.addPackage(builder.getPackage());
        StatefulKnowledgeSession session = ruleBase.newStatefulSession();
        List list = new ArrayList();
        session.setGlobal("list", list);
        session.insert("String1");
        String focusName = ((InternalAgenda)session.getAgenda()).getFocusName();
        assertEquals("MAIN", focusName);
View Full Code Here


     * VIEWS (which are using reflection)
     */
   
    @Test
    public void testWorkingMemoryView() throws Exception {
      KnowledgeBaseImpl ruleBase = (KnowledgeBaseImpl) KnowledgeBaseFactory.newKnowledgeBase();
      StatefulKnowledgeSession session = ruleBase.newStatefulSession();
        session.insert("Test1");
        session.insert("Test2");
        Object[] objects = ((StatefulKnowledgeSessionImpl)session).iterateObjectsToList().toArray();
        assertEquals(2, objects.length);
        assertTrue(("Test1".equals(objects[0]) && "Test2".equals(objects[1])) ||
View Full Code Here

    }

    public SingleSessionCommandService(RuleBase ruleBase,
                                       SessionConfiguration conf,
                                       Environment env) {
        this( new KnowledgeBaseImpl( ruleBase ),
              conf,
              env );
    }
View Full Code Here

    public SingleSessionCommandService(Integer sessionId,
                                       RuleBase ruleBase,
                                       SessionConfiguration conf,
                                       Environment env) {
        this( sessionId,
              new KnowledgeBaseImpl( ruleBase ),
              conf,
              env );
    }
View Full Code Here

    private KieSession ksession;

    @Before
    public void setUp() throws Exception {
        ksession = mock(KieSession.class);
        KnowledgeBaseImpl knowledgeBase = mock(KnowledgeBaseImpl.class);
        when(
                ksession.getKieBase()
        ).thenReturn(
                knowledgeBase
        );

        InternalRuleBase internalRuleBase = mock(InternalRuleBase.class);
        when(
                knowledgeBase.getRuleBase()
        ).thenReturn(
                internalRuleBase
        );

        CompositeClassLoader compositeClassLoader = new CompositeClassLoader();
View Full Code Here

                // so we read it, but we don't need it, so just ignore.
                ReteooStatefulSession rsession = (ReteooStatefulSession) ois.readObject();
   
                // now unmarshall that byte[]
                ByteArrayInputStream bais = new ByteArrayInputStream( rsession.bytes );
                Marshaller marshaller = MarshallerFactory.newMarshaller( new KnowledgeBaseImpl( this )new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy() }   );
               
                Environment environment = EnvironmentFactory.newEnvironment();
                KieSession ksession = marshaller.unmarshall( bais,
                                                             conf,
                                                             environment );
View Full Code Here

    }

    public SingleSessionCommandService(RuleBase ruleBase,
                                       SessionConfiguration conf,
                                       Environment env) {
        this( new KnowledgeBaseImpl( ruleBase ),
              conf,
              env );
    }
View Full Code Here

    public SingleSessionCommandService(Integer sessionId,
                                       RuleBase ruleBase,
                                       SessionConfiguration conf,
                                       Environment env) {
        this( sessionId,
              new KnowledgeBaseImpl( ruleBase ),
              conf,
              env );
    }
View Full Code Here

                      ksession.getObjects().size() );
    }

    @Test @Ignore("This test is suspicious to say the least...")
    public void testScheduledActivation() {
        KnowledgeBaseImpl knowledgeBase = (KnowledgeBaseImpl) KnowledgeBaseFactory.newKnowledgeBase();
        KnowledgePackageImp impl = new KnowledgePackageImp();
        impl.pkg = new org.drools.core.rule.Package( "test" );

        BuildContext buildContext = new BuildContext( (InternalRuleBase) knowledgeBase.getRuleBase(), ((ReteooRuleBase) knowledgeBase.getRuleBase())
                .getReteooBuilder().getIdGenerator() );
        //simple rule that fires after 10 seconds
        final Rule rule = new Rule( "test-rule" );
        new RuleTerminalNode( 1, new MockTupleSource( 2 ), rule, rule.getLhs(), 0, buildContext );

        final List<String> fired = new ArrayList<String>();

        rule.setConsequence( new Consequence() {
            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) throws Exception {
                fired.add( "a" );
            }

            public String getName() {
                return "default";
            }
        } );

        rule.setTimer( new DurationTimer( 10000 ) );
        rule.setPackage( "test" );
        impl.pkg.addRule( rule );

        knowledgeBase.addKnowledgePackages( Collections.singleton( (KnowledgePackage) impl ) );
        SessionConfiguration config = new SessionConfiguration();
        config.setClockType( ClockType.PSEUDO_CLOCK );
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession( config, KnowledgeBaseFactory.newEnvironment() );
        PseudoClockScheduler scheduler = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock();
        Marshaller marshaller = MarshallerFactory.newMarshaller( knowledgeBase );

        ksession.insert( "cheese" );
        assertTrue( fired.isEmpty() );
View Full Code Here

    private KieSession ksession;

    @Before
    public void setUp() throws Exception {
        ksession = mock(KieSession.class);
        KnowledgeBaseImpl knowledgeBase = mock(KnowledgeBaseImpl.class);
        when(
                ksession.getKieBase()
        ).thenReturn(
                knowledgeBase
        );

        InternalRuleBase internalRuleBase = mock(InternalRuleBase.class);
        when(
                knowledgeBase.getRuleBase()
        ).thenReturn(
                internalRuleBase
        );

        CompositeClassLoader compositeClassLoader = new CompositeClassLoader();
View Full Code Here

TOP

Related Classes of org.drools.core.impl.KnowledgeBaseImpl

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.