public boolean equals(final Object object) { if ( object == this ) { return true; } if ( object == null || !(object instanceof Cheese) ) { return false; } final Cheese other = (Cheese) object; return (this.type.equals( other.getType() ) && this.price == other.getPrice()); }
private void verifyCheese(final Cheese cheeseToBeVerified, final int price, final String type) { assertThat(cheeseToBeVerified.getPrice()).isEqualTo(price); assertThat(cheeseToBeVerified.getType()).isEqualTo(type); }
@Test public void updateFactOnRuleFireTest() { final Cheese camembert = new Cheese("Camembert", 19); final Cheese cheddar = new Cheese("Cheddar", 45); ksession.insert(camembert); ksession.insert(cheddar); verifyFactsWithQuery(Cheese.class, "cheeseTypes", camembert, cheddar); final List<Cheese> expensiveCheese = new ArrayList<>(); ksession.setGlobal("expensiveCheese", expensiveCheese); final int firedRules = ksession.fireAllRules(); assertThat(firedRules).isEqualTo(2); verifyList(expensiveCheese, camembert, cheddar); verifyFactsWithQuery(Cheese.class, "cheeseTypes", camembert, cheddar); assertThat(camembert.getPrice()).isEqualTo(21); assertThat(cheddar.getPrice()).isEqualTo(45); }
public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) { AgendaItem item = (AgendaItem) knowledgeHelper.getMatch(); final Cheese cheese = (Cheese) item.getTuple().getFactHandle().getObject(); final int oldPrice = cheese.getPrice(); cheese.setPrice(100); item.setActivationUnMatchListener(new ActivationUnMatchListener() { public void unMatch(org.kie.api.runtime.rule.RuleRuntime wm, Match activation) { cheese.setPrice(oldPrice); } }); }