public boolean accept(Match activation) { RuleImpl rule = (RuleImpl)activation.getRule(); if (currentSalience == null){ currentSalience = rule.getSalience() != null ? Integer.valueOf(rule.getSalience().toString()) : 0; } boolean nocancel = currentSalience >= Integer.valueOf(rule.getSalience().toString()); if(!nocancel){ logger.info("cancelling -> {}", rule.getName()); } return nocancel; } }
public void matchCreated(MatchCreatedEvent event) { String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup(); if ( "DROOLS_SYSTEM".equals( ruleFlowGroup ) ) {
public RuleImpl getRule() { return new RuleImpl( ruleName ); }
@Test public void testGetSalienceValue() { final RuleImpl rule = new RuleImpl( "myrule" ); final int salienceValue = 100; Salience salience = new SalienceInteger(salienceValue); rule.setSalience(salience); assertEquals(salienceValue, rule.getSalienceValue()); assertFalse(rule.isSalienceDynamic()); }
@Test public void testRuleEnabled() { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(); final RuleImpl rule = new RuleImpl( "myrule" ); rule.setEnabled( EnabledBoolean.ENABLED_FALSE ); assertFalse( rule.isEffective( null, new RuleTerminalNode(), wm ) ); final Calendar past = Calendar.getInstance(); past.setTimeInMillis( 10 ); rule.setDateEffective( past ); assertFalse( rule.isEffective( null, new RuleTerminalNode(), wm ) ); rule.setEnabled( EnabledBoolean.ENABLED_TRUE ); assertTrue( rule.isEffective( null, new RuleTerminalNode(), wm ) ); }
@Test public void testIsSalienceDynamic() { final RuleImpl rule = new RuleImpl( "myrule" ); Salience salience = new MVELSalienceExpression(); rule.setSalience(salience); assertTrue(rule.isSalienceDynamic()); }
@Test public void testDefaultConsequenceCompilation() { String consequence = " System.out.println(\"this is a test\");\n "; setupTest( consequence, new HashMap<String, Object>() ); assertNotNull( context.getRule().getConsequence() ); assertFalse( context.getRule().hasNamedConsequences() ); assertTrue( context.getRule().getConsequence() instanceof CompiledInvoker ); assertTrue( context.getRule().getConsequence() instanceof Consequence ); }
@Test public void testRuleStreamingWithCalendar() throws Exception { // DROOLS-260 RuleImpl rule = new RuleImpl ("test"); rule.setCalendars(new String[] {"mycalendar"}); byte[] buf = marshal(rule); RuleImpl retrievedRule = (RuleImpl)unmarshal(buf); assertNotNull(retrievedRule); assertNotNull(retrievedRule.getCalendars()); assertEquals(1, retrievedRule.getCalendars().length); assertEquals("mycalendar", retrievedRule.getCalendars()[0]); } }
@Test public void testDateExpires() throws Exception { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(); final RuleImpl rule = new RuleImpl( "myrule" ); assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) ); final Calendar earlier = Calendar.getInstance(); earlier.setTimeInMillis( 10 ); rule.setDateExpires( earlier ); assertFalse( rule.isEffective(null, new RuleTerminalNode(), wm ) ); final Calendar later = Calendar.getInstance(); later.setTimeInMillis( later.getTimeInMillis() + 100000000 ); rule.setDateExpires( later ); assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) ); }
public Consequence getConsequence() { return getRule().getConsequence(); }
public static void addRule(String ruleName, RuleImpl firingRule) throws Exception { String rule = rules.get(ruleName); CommonTestMethodBase testBaseMethod = new CommonTestMethodBase(); kbase.addPackages(testBaseMethod.loadKnowledgePackagesFromString( rule )); if (firingRule != null) { kbase.removeRule("defaultpkg", firingRule.getName()); } }
@Test public void testDefaultConsequenceCompilation() { String consequence = " System.out.println(\"this is a test\");\n "; setupTest( consequence, new HashMap<String, Object>() ); assertNotNull( context.getRule().getConsequence() ); assertFalse( context.getRule().hasNamedConsequences() ); assertTrue( context.getRule().getConsequence() instanceof CompiledInvoker ); assertTrue( context.getRule().getConsequence() instanceof Consequence ); }
public MockActivation( ) { this.rule = new RuleImpl(); }
public void matchCreated(MatchCreatedEvent event) { // check whether this activation is from the DROOLS_SYSTEM agenda group String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup(); if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) { // new activations of the rule associate with a milestone node // trigger node instances of that milestone node String ruleName = event.getMatch().getRule().getName(); String milestoneName = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getNodeId(); if (milestoneName.equals(ruleName) && checkProcessInstance((Activation) event.getMatch()) && checkDeclarationMatch(event.getMatch(), (String) getVariable("MatchVariable"))) { synchronized(getProcessInstance()) { DynamicNodeInstance.this.removeEventListeners(); DynamicNodeInstance.this.triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } } } }
public Consequence getConsequence() { return getRule().getConsequence(); }
@Test public void testDefaultConsequenceCompilation() { String consequence = " System.out.println(\"this is a test:\" + $cheese);\n " + "c1 = new Cheese().{ type = $cheese.type };" + "c2 = new Cheese().{ type = $map[$cheese.type] };" + "c3 = new Cheese().{ type = $map['key'] };"; setupTest( consequence, new HashMap<String, Object>() ); assertNotNull( context.getRule().getConsequence() ); assertFalse( context.getRule().hasNamedConsequences() ); assertTrue( context.getRule().getConsequence() instanceof MVELConsequence ); }
private Activation prepareActivation() { final Activation activation = mock(Activation.class); when(activation.getRule()).thenReturn(new RuleImpl()); return activation; } }
public void matchCreated(MatchCreatedEvent event) { // check whether this activation is from the DROOLS_SYSTEM agenda group String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup(); if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) { // new activations of the rule associate with a milestone node // trigger node instances of that milestone node String ruleName = event.getMatch().getRule().getName(); String milestoneName = "RuleFlow-Milestone-" + getProcessInstance().getProcessId() + "-" + getMilestoneNode().getUniqueId(); if (milestoneName.equals(ruleName) && checkProcessInstance((Activation) event.getMatch()) && checkDeclarationMatch(event.getMatch(), getMilestoneNode().getMatchVariable())) { synchronized(getProcessInstance()) { removeEventListeners(); triggerCompleted(); } } } }
public Consequence getConsequence() { return getRule().getConsequence(); }
@Before public void prepareGuard() { guardedUnit = new TestRuleUnit(new Integer[]{}, BigDecimal.TEN); guardingRule = new RuleImpl(); guard = new Guard(guardedUnit, guardingRule); }