Examples of Cheese


Examples of org.drools.examples.templates.Cheese

        final RuleBase rb = buildRuleBase(drl);

        WorkingMemory wm = rb.newStatefulSession();
       
        //now create some test data
        wm.insert( new Cheese( "stilton",
                               42 ) );
        wm.insert( new Person( "michael",
                               "stilton",
                               42 ) );
        final List<String> list = new ArrayList<String>();
View Full Code Here

Examples of org.drools.guvnor.models.testscenarios.backend.Cheese

    public void testVerifyAnonymousFacts() throws Exception {
        TypeResolver typeResolver = mock( TypeResolver.class );
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        FactVerifier factVerifier = new FactVerifier( new HashMap<String, Object>(), typeResolver, classLoader, ksession, new HashMap<String, Object>() );

        Cheese c = new Cheese();
        c.setPrice( 42 );
        c.setType( "stilton" );

        // configure the mock to return the value
        Set o = Collections.singleton( (Object) c );
        when( ksession.getObjects() ).thenReturn( o );
View Full Code Here

Examples of org.drools.rule.ConstraintTest.Cheese

                                                               stringObjectType,
                                                               typeOfCheeseExtractor,
                                                               0 );

        /* Create some facts */
        Cheese cheddar = new Cheese( "cheddar",
                                     5 );

        /* Check we can extract Declarations correctly */
        assertEquals( "cheddar",
                      typeOfCheeseDeclaration.getValue( cheddar ) );
View Full Code Here

Examples of org.drools.rule.ConstraintTest.Cheese

        LiteralExpressionConstraint isCheddar = new LiteralExpressionConstraint() {

            public boolean isAllowed(Object object,
                                     ConstraintComparator comparator)
            {
                Cheese cheese = (Cheese) object;
                return comparator.compare( cheese.getType(),
                                           "cheddar" );

            }
        };

        /*
         * Creates a constraint with the given expression
         */
        LiteralConstraint constraint0 = new LiteralConstraint( isCheddar,
                                                               new StringConstraintComparator( ConstraintComparator.EQUAL ) );

        /* Without Memory */
        AlphaNode alphaNode = new AlphaNode( 2,
                                             constraint0,
                                             false,
                                             source );
        MockObjectSink sink = new MockObjectSink();
        alphaNode.addObjectSink( sink );

        Cheese cheddar = new Cheese( "cheddar",
                                     5 );

        FactHandleImpl f0 = new FactHandleImpl( 0 );
        workingMemory.putObject( f0,
                                 cheddar );

        /* check sink is empty */
        assertLength( 0,
                      sink.getAsserted() );

        /* check alpha memory is empty */
        Set memory = (Set) workingMemory.getNodeMemory( alphaNode );
        assertLength( 0,
                      memory );

        /* object should assert as it passes test */
        alphaNode.assertObject( cheddar,
                                f0,
                                context,
                                workingMemory );

        assertLength( 1,
                      sink.getAsserted() );
        assertLength( 0,
                      memory );

        Object[] list = (Object[]) sink.getAsserted().get( 0 );
        assertSame( cheddar,
                    list[0] );

        FactHandleImpl f1 = new FactHandleImpl( 0 );
        Cheese stilton = new Cheese( "stilton",
                                     6 );

        /* object should NOT assert as it does not pass test */
        alphaNode.assertObject( stilton,
                                f1,
View Full Code Here

Examples of org.drools.rule.ConstraintTest.Cheese

        LiteralExpressionConstraint isCheddar = new LiteralExpressionConstraint() {

            public boolean isAllowed(Object object,
                                     ConstraintComparator comparator)
            {
                Cheese cheese = (Cheese) object;
                return comparator.compare( cheese.getType(),
                                           "cheddar" );

            }
        };

        /*
         * Creates a constraint with the given expression
         */
        LiteralConstraint constraint0 = new LiteralConstraint( isCheddar,
                                                               new StringConstraintComparator( ConstraintComparator.EQUAL ) );

        /* With Memory */
        AlphaNode alphaNode = new AlphaNode( 2,
                                             constraint0,
                                             true,
                                             source );

        MockObjectSink sink = new MockObjectSink();
        alphaNode.addObjectSink( sink );

        FactHandleImpl f0 = new FactHandleImpl( 0 );
        Cheese cheddar = new Cheese( "cheddar",
                                     5 );
        workingMemory.putObject( f0,
                                 cheddar );

        /* check sink is empty */
        assertLength( 0,
                      sink.getAsserted() );

        /* check alpha memory is empty */
        Set memory = (Set) workingMemory.getNodeMemory( alphaNode );
        assertLength( 0,
                      memory );

        /* object should assert as it passes text */
        alphaNode.assertObject( cheddar,
                                f0,
                                context,
                                workingMemory );

        assertLength( 1,
                      sink.getAsserted() );
        assertLength( 1,
                      memory );
        Object[] list = (Object[]) sink.getAsserted().get( 0 );
        assertSame( cheddar,
                    list[0] );
        assertTrue( "Should contain 'cheddar handle'",
                    memory.contains( f0 ) );

        /* object should not assert as it already exists */
        alphaNode.assertObject( cheddar,
                                f0,
                                context,
                                workingMemory );

        assertLength( 1,
                      sink.getAsserted() );
        assertLength( 1,
                      memory );

        FactHandleImpl f1 = new FactHandleImpl( 1 );
        Cheese stilton = new Cheese( "stilton",
                                     6 );

        /* object should NOT assert as it does not pass test */
        alphaNode.assertObject( stilton,
                                f1,
View Full Code Here

Examples of org.drools.rule.ConstraintTest.Cheese

        ReturnValueExpressionConstraint isCheddar = new ReturnValueExpressionConstraint() {

            public boolean isAllowed(Object object,
                                     ConstraintComparator comparator)
            {
                Cheese cheese = (Cheese) object;
                return comparator.compare( cheese.getType(),
                                           "cheddar" );
            }

            /* everything is ignored - except object */
            public boolean isAllowed(Object object,
                                     FactHandle handle,
                                     Declaration[] declarations,
                                     Tuple tuple,
                                     ConstraintComparator comparator)
            {
                Cheese cheese = (Cheese) object;
                return comparator.compare( cheese.getType(),
                                           "cheddar" );
            }
        };

        /*
         * Creates a constraint with the given expression
         */
        ReturnValueConstraint constraint0 = new ReturnValueConstraint( isCheddar,
                                                                       null, // alpha nodes cannot have required declarations
                                                                       new StringConstraintComparator( ConstraintComparator.EQUAL ) );

        AlphaNode alphaNode = new AlphaNode( 2,
                                             constraint0,
                                             true,
                                             source );
        MockObjectSink sink = new MockObjectSink();
        alphaNode.addObjectSink( sink );

        Cheese cheddar = new Cheese( "cheddar",
                                     5 );

        FactHandleImpl f0 = new FactHandleImpl( 0 );
        workingMemory.putObject( f0,
                                 cheddar );

        assertLength( 0,
                      sink.getAsserted() );

        /* object should assert as it passes text */
        alphaNode.assertObject( cheddar,
                                f0,
                                context,
                                workingMemory );

        assertLength( 1,
                      sink.getAsserted() );
        Object[] list = (Object[]) sink.getAsserted().get( 0 );
        assertSame( cheddar,
                    list[0] );

        Cheese stilton = new Cheese( "stilton",
                                     6 );

        /* object should not assert as it does not pass text */
        alphaNode.assertObject( stilton,
                                f0,
View Full Code Here

Examples of org.drools.rule.ConstraintTest.Cheese

        LiteralExpressionConstraint isCheddar = new LiteralExpressionConstraint() {

            public boolean isAllowed(Object object,
                                     ConstraintComparator comparator)
            {
                Cheese cheese = (Cheese) object;
                return comparator.compare( cheese.getType(),
                                           "cheddar" );

            }
        };

        /*
         * Creates a constraint with the given expression
         */
        LiteralConstraint constraint0 = new LiteralConstraint( isCheddar,
                                                               new StringConstraintComparator( ConstraintComparator.EQUAL ) );

        /* With Memory */
        AlphaNode alphaNode = new AlphaNode( 2,
                                             constraint0,
                                             true,
                                             source );
        MockObjectSink sink = new MockObjectSink();
        alphaNode.addObjectSink( sink );

        Cheese cheddar = new Cheese( "cheddar",
                                     5 );

        FactHandleImpl f0 = new FactHandleImpl( 0 );
        workingMemory.putObject( f0,
                                 cheddar );
View Full Code Here

Examples of org.drools.workbench.models.testscenarios.backend.Cheese

    @Test
    public void testVerifyAnonymousFacts() throws Exception {
        TypeResolver typeResolver = mock( TypeResolver.class );
        FactVerifier factVerifier = new FactVerifier( new HashMap<String, Object>(), typeResolver, ksession, new HashMap<String, Object>() );

        Cheese c = new Cheese();
        c.setPrice( 42 );
        c.setType( "stilton" );

        // configure the mock to return the value
        Set o = Collections.singleton( (Object) c );
        when( ksession.getObjects() ).thenReturn( o );
View Full Code Here

Examples of org.kie.camel.testdomain.Cheese

                                    ((FactHandle) result.getFactHandle( "changes" )).toExternalForm(),
                                    ((FactHandle) result.getFactHandle( "person" )).toExternalForm() ),
                        outXml );

        ChangeCollector collector = (ChangeCollector) result.getValue( "changes" );
        Cheese c = (Cheese) collector.getChanges().get( 0 );
        assertEquals( 42,
                      c.getPrice() );

        result = execContent( "testListenForChanges.in.3",
                              ExecutionResults.class );

        collector = (ChangeCollector) result.getValue( "changes" );
View Full Code Here

Examples of org.mvel2.tests.core.res.Cheese

    Map<String,Object> vars = new HashMap<String, Object>();
    Column c = new Column("x", 1);
    c.setCheeses( new Cheese[5][5] );
    vars.put( "$c", c );
    MVEL.executeExpression(stmt, null, vars);
    assertEquals( new Cheese("brie", 15), c.getCheeses()[0][0]);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.