public Sandwich() { super(); // Compiler adds it if it is not explicitly added by programmer // All the instance variable initialization is moved here by the compiler. b = new Bread(); c = new Cheese(); l = new Lettuce(); System.out.println("Sandwich()"); }
private Bread b = new Bread(); private Cheese c = new Cheese(); private Lettuce l = new Lettuce();
@Test public void updateWithDifferentClassGetObjectsTest() { final Person person = new Person("George", 18); final FactHandle factPerson = ksession.insert(person); final Person personToBeVerified = verifyFactsPresentInSession(1, Person.class).get(0); assertThat(personToBeVerified).isEqualTo(person); final Cheese cheese = new Cheese("Camembert", 50); ksession.update(factPerson, cheese); verifyFactsPresentInSession(1, Cheese.class); final Cheese cheeseToBeVerified = (Cheese) ksession.getObjects().iterator().next(); verifyCheese(cheeseToBeVerified, 50, "Camembert"); }
@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); }
@Test public void deleteUpdatedFactDifferentClassTest() { FactHandle fact = ksession.insert(new Person("George", 18)); Assertions.assertThat(ksession.getObjects()).hasSize(1); Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Person.class); ksession.update(fact, new Cheese("Cheddar", 50)); Assertions.assertThat(ksession.getObjects()).hasSize(1); Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Cheese.class); ksession.delete(fact); Assertions.assertThat(ksession.getObjects()).isEmpty(); }
@Test public void testEmptyIterator() { final TupleList map = new TupleList(); final Cheese stilton1 = new Cheese( "stilton", 35 ); final InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 ); assertNull( map.getFirst( new LeftTupleImpl( h1, null, true ) ) ); } }
@Test public void updateWithDifferentClassGetQueryResultsTest() { final Person person = new Person("George", 18); final FactHandle fact = ksession.insert(person); verifyFactsWithQuery(Person.class, "persons", person); final Cheese cheese = new Cheese("Camembert", 2); ksession.update(fact, cheese); verifyWithQueryNoPersonsPresentInFacts(); verifyFactsPresentInSession(1, Cheese.class); Cheese cheeseToBeVerified = (Cheese) ksession.getObjects().iterator().next(); verifyCheese(cheeseToBeVerified, 2, "Camembert"); cheeseToBeVerified = verifyFactPresentInSession(fact, Cheese.class); verifyCheese(cheeseToBeVerified, 2, "Camembert"); }
1 ); Tuple tuple = new RightTupleImpl( new DefaultFactHandle( 1, new Cheese("stilton", 10) ) ); final TupleList index = new AbstractHashTable.SingleIndexTupleList( singleIndex, tuple, "stilton".hashCode(), false ); index.hashCode() ); final Cheese stilton1 = new Cheese( "stilton", 35 ); final InternalFactHandle h1 = new DefaultFactHandle( 1,
@Test public void testObjectIterator() { InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); KieSession ksession = kBase.newKieSession(); ksession.insert( new Person( "bob", 35) ); ksession.insert( new Cheese( "stilton", 35) ); ksession.insert( new Cheese( "brie", 35) ); ksession.insert( new Person( "steve", 55) ); ksession.insert( new Person( "tom", 100) ); int i = 0; for ( FactHandle fh : ksession.getFactHandles()) { if ( i++ > 5 ) { fail( "should not iterate for than 3 times" ); } } i = 0; for ( FactHandle fh : ksession.getFactHandles()) { if ( i++ > 5 ) { fail( "should not iterate for than 3 times" ); } } }
@Test public void testDeclarationsObjectType() throws Exception { final ObjectType type = new ClassObjectType( Cheese.class ); final Pattern col = new Pattern( 0, type, "foo" ); final Declaration dec = col.getDeclaration(); final InternalReadAccessor ext = dec.getExtractor(); assertEquals( Cheese.class, ext.getExtractToClass() ); final Cheese stilton = new Cheese( "stilton", 42 ); assertEquals( stilton, dec.getValue( null, stilton ) ); }
@Test public void testGetFieldValue() { final InternalReadAccessor extractor = store.getReader( Cheese.class, "type" ); final Pattern pattern = new Pattern( 5, new ClassObjectType( Cheese.class ) ); // Bind the extractor to a decleration // Declarations know the pattern they derive their value from final Declaration declaration = new Declaration( "typeOfCheese", extractor, pattern ); // Create some facts final Cheese cheddar = new Cheese( "cheddar", 5 ); // Check we can extract Declarations correctly assertEquals( "cheddar", declaration.getValue( null, cheddar ) ); }
final Cheese cheese = new Cheese("brie", 15); final DefaultFactHandle h1 = new DefaultFactHandle(1,
@Test public void testIsShadowed() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList final Rete rete = kBase.getRete(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(Cheese.class), buildContext); objectTypeNode.attach(buildContext); final MockObjectSink sink1 = new MockObjectSink(); objectTypeNode.addObjectSink(sink1); // There are no String ObjectTypeNodes, make sure its not propagated final Cheese cheese = new Cheese("brie", 15); final DefaultFactHandle h1 = new DefaultFactHandle(1, cheese); rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession); ksession.fireAllRules(); final Object[] results = (Object[]) sink1.getAsserted().get(0); }
@Test public void testEmptyIterator() { final InternalReadAccessor extractor = store.getReader( Cheese.class, "type" ); final Pattern pattern = new Pattern( 0, new ClassObjectType( Cheese.class ) ); final Declaration declaration = new Declaration( "typeOfCheese", extractor, pattern ); final FieldIndex fieldIndex = new FieldIndex( extractor, declaration, MvelConstraint.INDEX_EVALUATOR ); final TupleIndexHashTable map = new TupleIndexHashTable( new FieldIndex[]{fieldIndex}, false ); final Cheese stilton = new Cheese( "stilton", 55 ); final InternalFactHandle stiltonHandle = new DefaultFactHandle( 2, stilton ); assertNull( map.getFirst( new LeftTupleImpl( stiltonHandle, null, true ) ) ); }
alphaNode.addObjectSink( sink ); final Cheese cheddar = new Cheese( "cheddar", 5 ); final DefaultFactHandle f0 = (DefaultFactHandle) ksession.insert( cheddar ); ksession.getObject( (DefaultFactHandle) list[0] ) ); final Cheese stilton = new Cheese( "stilton", 6 ); final DefaultFactHandle f1 = new DefaultFactHandle( 1,
ReteooFactHandleFactory factory = new ReteooFactHandleFactory(); InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), null, null, null ); EqualityKey key = new EqualityKey( ch1 ); assertEquals( 1, key.size() ); InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), null, null, null ); key.addFactHandle( ch2 );