Refine search
public Pattern getPattern(int index, String type) throws ClassNotFoundException { return new Pattern(index, new ClassObjectType(typeResolver.resolveType(type))); }
@Test public void testAddRuleWithPatterns() { final RuleImpl rule = new RuleImpl( "only patterns" ); final Pattern c1 = new Pattern( 0, new ClassObjectType( String.class ) ); final Pattern c2 = new Pattern( 1, new ClassObjectType( String.class ) ); final Pattern c3 = new Pattern( 2, new ClassObjectType( String.class ) );
/** * Tests ObjectTypeNodes are correctly added to the Rete object * * @throws Exception */ @Test public void testObjectTypeNodes() throws Exception { final Rete rete = kBase.getRete(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(Object.class), buildContext); objectTypeNode.attach(buildContext); final ObjectTypeNode stringTypeNode = new ObjectTypeNode(2, this.entryPoint, new ClassObjectType(String.class), buildContext); stringTypeNode.attach(buildContext); final List<ObjectTypeNode> list = rete.getObjectTypeNodes(); // Check the ObjectTypeNodes are correctly added to Rete assertEquals(3, list.size()); assertTrue(list.contains(objectTypeNode)); assertTrue(list.contains(stringTypeNode)); }
@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 testInvokerGenerationMultiPattern() { final String className = "accumulate0"; null )}; final Declaration[] inner = new Declaration[]{new Declaration( "$cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "$person", new PatternExtractor( new ClassObjectType( Person.class ) ), null )}; final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier(); return new MvelConstraintTestUtil(expression, declaration, extractor); }
@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 testMethodGeneration() { final String className = "accumulate0"; null )}; final Declaration[] inner = new Declaration[]{new Declaration( "cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "price", store.getReader( Cheese.class,
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + identifier; return new MvelConstraintTestUtil(expression, operator.getOperatorString(), declaration, extractor); }
@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 testInvokerGenerationSinglePattern() { final String className = "accumulate0"; null )}; final Declaration[] inner = new Declaration[]{new Declaration( "cheese", new PatternExtractor( new ClassObjectType( Cheese.class ) ), null ), new Declaration( "price", store.getReader( Cheese.class,
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) { ClassFieldAccessorStore store = new ClassFieldAccessorStore(); store.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) ); store.setEagerWire( true ); InternalReadAccessor extractor = store.getReader( clazz, fieldName ); Declaration declaration = new Declaration( identifier, extractor, new Pattern( 0, new ClassObjectType( clazz ) ) ); String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier(); return new MvelConstraintTestUtil(expression, declaration, extractor); }
@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 test1() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1, this.entryPoint, new ClassObjectType( State.class ), buildContext ); objectTypeNode.attach(buildContext); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink ); final State a = new State( "go" ); ksession.insert( a, true ); ksession.fireAllRules(); assertEquals( 1, sink.getAsserted().size() ); a.setState( "stop" ); }
@Before public void setUp() throws Exception { final ObjectType list1ObjectType = new ClassObjectType( String.class ); final ObjectType list2ObjectType = new ClassObjectType( String.class ); final Pattern list1Pattern = new Pattern( 0, list1ObjectType, "s1" ); final Pattern list2Pattern = new Pattern( 1, list2ObjectType, "s2" );
@Test public void testDeclarationOrdering() { final GroupElement and1 = GroupElementFactory.newAndInstance(); final Pattern pattern1 = new Pattern( 0, new ClassObjectType( Person.class), "x" ); and1.addChild( pattern1 ); final Pattern pattern2 = new Pattern( 2, new ClassObjectType( Person.class), "y" ); and1.addChild( pattern2 ); and2.addChild( and1 ); final Pattern pattern3 = new Pattern( 3, new ClassObjectType( Person.class), "x" ); and2.addChild( pattern3 );
@Test public void testAdd() { /* * create a RuleBase with a single ObjectTypeNode we attach a * MockObjectSink so we can detect assertions and retractions */ InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); BuildContext context = new BuildContext(kBase); NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService(); EntryPointNode entryPoint = context.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next(); final ObjectTypeNode objectTypeNode = nFacotry.buildObjectTypeNode( 0, entryPoint, new ClassObjectType( Object.class ), context ); objectTypeNode.attach(context); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink ); kBase.newKieSession(); // objectTypeNode. }
new ClassObjectType(leftType), buildContext); new ClassObjectType(rightType), buildContext); Pattern pattern = new Pattern(0, new ClassObjectType(leftType));
@Test public void testPredicateConstraint() { InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); "price" ); Pattern pattern = new Pattern( 0, new ClassObjectType( Cheese.class ) ); pattern ); pattern = new Pattern( 1, new ClassObjectType( Cheese.class ) );
@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); }