Skip to content

Commit

Permalink
Kie API refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Dec 11, 2012
1 parent f417abf commit 66b81a1
Show file tree
Hide file tree
Showing 53 changed files with 192 additions and 1,144 deletions.
Expand Up @@ -214,7 +214,7 @@ public void traitShed( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitShed.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );


List info = new ArrayList();
Expand Down Expand Up @@ -271,7 +271,7 @@ public void traitDon( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitDon.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -307,7 +307,7 @@ public void mixin( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitMixin.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -339,7 +339,7 @@ public void traitMethodsWithObjects( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitWrapping.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List errors = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -373,7 +373,7 @@ public void traitMethodsWithPrimitives( TraitFactory.VirtualPropertyMode mode )
String source = "org/drools/factmodel/traits/testTraitWrappingPrimitives.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List errors = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -1125,7 +1125,7 @@ public void isA( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitIsA.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public void overrideType( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitOverride.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -1202,7 +1202,7 @@ public void traitLegacy( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitLegacyTrait.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );


List info = new ArrayList();
Expand Down Expand Up @@ -1250,7 +1250,7 @@ public void traitCollections( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitCollections.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );


List info = new ArrayList();
Expand Down Expand Up @@ -1294,7 +1294,7 @@ public void traitCore( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitLegacyCore.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -1338,7 +1338,7 @@ public void traitWithEquality( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitWithEquality.drl";

StatefulKnowledgeSession ks = getSession( source );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

List info = new ArrayList();
ks.setGlobal( "list",
Expand Down Expand Up @@ -1373,7 +1373,7 @@ public void traitDeclared( TraitFactory.VirtualPropertyMode mode ) {
List<Integer> untrueTraits = new ArrayList<Integer>();

StatefulKnowledgeSession ks = getSession( "org/drools/factmodel/traits/testDeclaredFactTrait.drl" );
TraitFactory.setMode( mode, ks.getKnowledgeBase() );
TraitFactory.setMode( mode, ks.getKieBase() );

ks.setGlobal( "trueTraits",
trueTraits );
Expand Down Expand Up @@ -1411,7 +1411,7 @@ public void traitPojo( TraitFactory.VirtualPropertyMode mode ) {
List<Integer> untrueTraits = new ArrayList<Integer>();

StatefulKnowledgeSession session = getSession( "org/drools/factmodel/traits/testPojoFactTrait.drl" );
TraitFactory.setMode( mode, session.getKnowledgeBase() );
TraitFactory.setMode( mode, session.getKieBase() );

session.setGlobal( "trueTraits",
trueTraits );
Expand Down Expand Up @@ -1446,7 +1446,7 @@ public void testPojoMap() {
public void isAOperator( TraitFactory.VirtualPropertyMode mode ) {
String source = "org/drools/factmodel/traits/testTraitIsA2.drl";
StatefulKnowledgeSession ksession = getSession( source );
TraitFactory.setMode( mode, ksession.getKnowledgeBase() );
TraitFactory.setMode( mode, ksession.getKieBase() );


AgendaEventListener ael = mock( AgendaEventListener.class );
Expand All @@ -1459,7 +1459,7 @@ public void isAOperator( TraitFactory.VirtualPropertyMode mode ) {

ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael,
times( 3 ) ).afterActivationFired( cap.capture() );
times( 3 ) ).afterMatchFired(cap.capture());

List<AfterMatchFiredEvent> values = cap.getAllValues();

Expand Down Expand Up @@ -1529,7 +1529,7 @@ protected void manyTraits( TraitFactory.VirtualPropertyMode mode ) {
" list.add(\"OK\");\n" +
" end";
StatefulKnowledgeSession ksession = getSessionFromString( source );
TraitFactory.setMode( mode, ksession.getKnowledgeBase() );
TraitFactory.setMode( mode, ksession.getKieBase() );


List list = new ArrayList();
Expand Down Expand Up @@ -1564,7 +1564,7 @@ public void testManyTraitsMap() {
public void traitManyTimes( TraitFactory.VirtualPropertyMode mode ) {

StatefulKnowledgeSession ksession = getSession( "org/drools/factmodel/traits/testTraitDonMultiple.drl" );
TraitFactory.setMode( mode, ksession.getKnowledgeBase() );
TraitFactory.setMode( mode, ksession.getKieBase() );


List list = new ArrayList();
Expand Down Expand Up @@ -1806,7 +1806,7 @@ public void aliasing( TraitFactory.VirtualPropertyMode mode ) {
"end";

StatefulKnowledgeSession ksession = getSessionFromString( drl );
TraitFactory.setMode( mode, ksession.getKnowledgeBase() );
TraitFactory.setMode( mode, ksession.getKieBase() );

List list = new ArrayList();
ksession.setGlobal( "list", list );
Expand Down Expand Up @@ -1881,7 +1881,7 @@ public void traitLogicalRemoval( TraitFactory.VirtualPropertyMode mode ) {


StatefulKnowledgeSession ksession = getSessionFromString(drl);
TraitFactory.setMode( mode, ksession.getKnowledgeBase() );
TraitFactory.setMode( mode, ksession.getKieBase() );

List list = new ArrayList();
ksession.setGlobal( "list", list );
Expand Down
Expand Up @@ -1578,7 +1578,7 @@ public void execTestAccumulateMultipleFunctions( String fileName ) throws Except
ksession.fireAllRules();

ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

Match activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand All @@ -1596,7 +1596,7 @@ public void execTestAccumulateMultipleFunctions( String fileName ) throws Except
cheese[index] );
ksession.fireAllRules();

Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand All @@ -1613,7 +1613,7 @@ public void execTestAccumulateMultipleFunctions( String fileName ) throws Except
bob );
ksession.fireAllRules();

Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand All @@ -1628,7 +1628,7 @@ public void execTestAccumulateMultipleFunctions( String fileName ) throws Except
ksession.retract( cheeseHandles[3] );
ksession.fireAllRules();

Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand Down Expand Up @@ -1671,7 +1671,7 @@ public void execTestAccumulateMultipleFunctionsConstraint( String fileName ) thr
ksession.fireAllRules();

ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

Match activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand All @@ -1689,7 +1689,7 @@ public void execTestAccumulateMultipleFunctionsConstraint( String fileName ) thr
cheese[index] );
ksession.fireAllRules();

Mockito.verify( ael, Mockito.never() ).afterActivationFired( Mockito.any(AfterMatchFiredEvent.class) );
Mockito.verify( ael, Mockito.never() ).afterMatchFired(Mockito.any(AfterMatchFiredEvent.class));

Mockito.reset( ael );
// ---------------- 3rd scenario
Expand All @@ -1698,7 +1698,7 @@ public void execTestAccumulateMultipleFunctionsConstraint( String fileName ) thr
bob );
ksession.fireAllRules();

Mockito.verify( ael ).afterActivationFired( cap.capture() );
Mockito.verify( ael ).afterMatchFired(cap.capture());

activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
Expand Down
Expand Up @@ -741,13 +741,13 @@ public void testBeforeOperator() throws Exception {
ksession.insert( tick8 );

ArgumentCaptor<MatchCreatedEvent> arg = ArgumentCaptor.forClass( MatchCreatedEvent.class );
verify( ael ).activationCreated( arg.capture() );
verify( ael ).matchCreated(arg.capture());
assertThat( arg.getValue().getMatch().getRule().getName(),
is( "before" ) );

ksession.fireAllRules();

verify( ael ).afterActivationFired( any( AfterMatchFiredEvent.class ) );
verify( ael ).afterMatchFired(any(AfterMatchFiredEvent.class));
}

@Test
Expand Down Expand Up @@ -828,15 +828,15 @@ public void testMetByOperator() throws Exception {
ksession.insert( tick8 );

ArgumentCaptor<MatchCreatedEvent> arg = ArgumentCaptor.forClass( MatchCreatedEvent.class );
verify( ael ).activationCreated( arg.capture() );
verify( ael ).matchCreated(arg.capture());
Match activation = arg.getValue().getMatch();
assertThat( activation.getRule().getName(),
is( "metby" ) );

ksession.fireAllRules();

ArgumentCaptor<AfterMatchFiredEvent> aaf = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael ).afterActivationFired( aaf.capture() );
verify( ael ).afterMatchFired(aaf.capture());
assertThat( (InternalFactHandle) aaf.getValue().getMatch().getFactHandles().toArray()[0],
is( fh2 ) );
}
Expand Down Expand Up @@ -1756,7 +1756,7 @@ public void testStreamModeNoSerialization() throws IOException,

ArgumentCaptor<AfterMatchFiredEvent> aafe1 = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael1,
times( 1 ) ).afterActivationFired( aafe1.capture() );
times( 1 ) ).afterMatchFired(aafe1.capture());
List<AfterMatchFiredEvent> events1 = aafe1.getAllValues();
assertThat( events1.get( 0 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 10 ) );
Expand All @@ -1765,14 +1765,14 @@ public void testStreamModeNoSerialization() throws IOException,
20 ) );
ksession1.fireAllRules();
verify( ael1,
times( 2 ) ).afterActivationFired( aafe1.capture() );
times( 2 ) ).afterMatchFired(aafe1.capture());
assertThat( events1.get( 1 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 15 ) );
ksession1.insert( new Sensor( 30,
30 ) );
ksession1.fireAllRules();
verify( ael1,
times( 3 ) ).afterActivationFired( aafe1.capture() );
times( 3 ) ).afterMatchFired(aafe1.capture());
assertThat( events1.get( 2 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 25 ) );

Expand All @@ -1787,7 +1787,7 @@ public void testStreamModeNoSerialization() throws IOException,
10 ) );
ksession2.fireAllRules();
verify( ael2,
times( 1 ) ).afterActivationFired( aafe2.capture() );
times( 1 ) ).afterMatchFired(aafe2.capture());
List<AfterMatchFiredEvent> events2 = aafe2.getAllValues();
assertThat( events2.get( 0 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 10 ) );
Expand All @@ -1796,15 +1796,15 @@ public void testStreamModeNoSerialization() throws IOException,
20 ) );
ksession2.fireAllRules();
verify( ael2,
times( 2 ) ).afterActivationFired( aafe2.capture() );
times( 2 ) ).afterMatchFired(aafe2.capture());
assertThat( events2.get( 1 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 15 ) );

ksession2.insert( new Sensor( 30,
30 ) );
ksession2.fireAllRules();
verify( ael2,
times( 3 ) ).afterActivationFired( aafe2.capture() );
times( 3 ) ).afterMatchFired(aafe2.capture());
assertThat( events2.get( 2 ).getMatch().getDeclarationValue( "$avg" ),
is( (Object) 25 ) );
ksession2.dispose();
Expand Down Expand Up @@ -1853,7 +1853,7 @@ public void testIdentityAssertBehaviorOnEntryPoints() throws IOException,
ksession.fireAllRules();
// must have fired 3 times, one for each event identity
verify( ael1,
times( 3 ) ).afterActivationFired( any( AfterMatchFiredEvent.class ) );
times( 3 ) ).afterMatchFired(any(AfterMatchFiredEvent.class));

ksession.dispose();
}
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public void testEqualityAssertBehaviorOnEntryPoints() throws IOException,
ksession1.fireAllRules();
// must have fired 2 times, one for each event equality
verify( ael1,
times( 2 ) ).afterActivationFired( any( AfterMatchFiredEvent.class ) );
times( 2 ) ).afterMatchFired(any(AfterMatchFiredEvent.class));

ksession1.dispose();
}
Expand Down Expand Up @@ -2082,7 +2082,7 @@ public void testMultipleSlidingWindows() throws IOException,

ArgumentCaptor<AfterMatchFiredEvent> captor = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael,
times( 7 ) ).afterActivationFired( captor.capture() );
times( 7 ) ).afterMatchFired(captor.capture());

List<AfterMatchFiredEvent> values = captor.getAllValues();
// first rule
Expand Down Expand Up @@ -2282,7 +2282,7 @@ public void testSalienceWithEventsPseudoClock() throws IOException,

ArgumentCaptor<AfterMatchFiredEvent> captor = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael,
times( 4 ) ).afterActivationFired( captor.capture() );
times( 4 ) ).afterMatchFired(captor.capture());
List<AfterMatchFiredEvent> aafe = captor.getAllValues();

Assert.assertThat( aafe.get( 0 ).getMatch().getRule().getName(),
Expand Down Expand Up @@ -2357,7 +2357,7 @@ public void testSalienceWithEventsRealtimeClock() throws IOException,

ArgumentCaptor<AfterMatchFiredEvent> captor = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael,
times( 4 ) ).afterActivationFired( captor.capture() );
times( 4 ) ).afterMatchFired(captor.capture());
List<AfterMatchFiredEvent> aafe = captor.getAllValues();

Assert.assertThat( aafe.get( 0 ).getMatch().getRule().getName(),
Expand Down
Expand Up @@ -642,7 +642,7 @@ public void testCancelActivation() {

ksession.addEventListener( new AgendaEventListener() {

public void beforeActivationFired(BeforeMatchFiredEvent event) {
public void beforeMatchFired(BeforeMatchFiredEvent event) {
}

public void agendaGroupPushed(AgendaGroupPushedEvent event) {
Expand All @@ -651,10 +651,10 @@ public void agendaGroupPushed(AgendaGroupPushedEvent event) {
public void agendaGroupPopped(AgendaGroupPoppedEvent event) {
}

public void afterActivationFired(AfterMatchFiredEvent event) {
public void afterMatchFired(AfterMatchFiredEvent event) {
}

public void activationCreated(MatchCreatedEvent event) {
public void matchCreated(MatchCreatedEvent event) {
}

public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
Expand All @@ -669,7 +669,7 @@ public void beforeRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event)
public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) {
}

public void activationCancelled(MatchCancelledEvent event) {
public void matchCancelled(MatchCancelledEvent event) {
cancelled.add( event );
}
} );
Expand Down

0 comments on commit 66b81a1

Please sign in to comment.