Refine search
@Test public void testBasic() throws Exception { final Object[] objArray = new Object[1]; final TestBean obj = new TestBean(); obj.setBlah( false ); obj.setSomething( "no" ); obj.setObjArray( objArray ); final ClassFieldReader ext = store.getReader( TestBean.class, "blah" ); assertEquals( false, ((Boolean) ext.getValue( null, obj )).booleanValue() ); final ClassFieldReader ext2 = store.getReader( TestBean.class, "fooBar" ); assertEquals( "fooBar", ext2.getValue( null, obj ) ); final ClassFieldReader ext3 = store.getReader( TestBean.class, "objArray" ); assertEquals( objArray, ext3.getValue( null, obj ) ); }
@Test public void testIsNullValue() { assertFalse( this.reader.isNullValue( null, this.bean ) ); ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor nullExtractor = store.getReader( TestBean.class, "nullAttr" ); assertTrue( nullExtractor.isNullValue( null, this.bean ) ); } }
@Test public void testInvokerGenerationSinglePattern() { final String className = "accumulate0"; store.getReader( Person.class, "name" ), null ), new Declaration( "age", store.getReader( Person.class, "age" ), null )}; new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "price", store.getReader( Cheese.class, "price" ), null )};
@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 ) ); }
@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 ) ) ); }
@Test public void testDeclaration() { 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 ); assertEquals( "typeOfCheese", declaration.getIdentifier() ); assertSame( String.class, declaration.getDeclarationClass() ); assertSame( extractor, declaration.getExtractor() ); assertEquals( 5, declaration.getPattern().getOffset() ); }
@Test public void testPrimitiveLiteralConstraint() { InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); final ClassFieldReader extractor = store.getReader(Cheese.class, "price");