Package org.drools.ide.common.client.modeldriven.testing

Examples of org.drools.ide.common.client.modeldriven.testing.FieldData


    @Test
    public void testRuleFlowGroupActivation() throws Exception {
        Scenario scenario = new Scenario();
        Fixture[] given = new Fixture[]{new FactData( "Coolness",
                                                      "c",
                                                      ls( new FieldData( "num",
                                                                         "42" ),
                                                          new FieldData( "name",
                                                                         "mic" ) ),
                                                      false )

        };
        scenario.getFixtures().addAll( Arrays.asList( given ) );

        ExecutionTrace executionTrace = new ExecutionTrace();

        scenario.getRules().add( "rule1" );
        scenario.setInclusive( true );
        scenario.getFixtures().add( executionTrace );

        Expectation[] assertions = new Expectation[2];

        assertions[0] = new VerifyFact( "c",
                                        ls( new VerifyField( "num",
                                                             "42",
                                                             "==" ) ) );

        assertions[1] = new VerifyRuleFired( "rule1",
                                             1,
                                             null );

        scenario.getFixtures().addAll( Arrays.asList( assertions ) );

        WorkingMemory workingMemory = getWorkingMemory( "rule_flow_actication.drl" );
        ClassLoader classLoader = ((InternalRuleBase) workingMemory.getRuleBase()).getRootClassLoader();

        HashSet<String> imports = new HashSet<String>();
        imports.add( "foo.bar.*" );

        TypeResolver resolver = new ClassTypeResolver( imports,
                                                       classLoader );

        Class< ? > coolnessClass = classLoader.loadClass( "foo.bar.Coolness" );
        assertNotNull( coolnessClass );

        ClassLoader cl_ = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader( classLoader );

        //resolver will need to have generated beans in it - possibly using a composite classloader from the package,
        //including whatever CL has the generated beans...
        ScenarioRunner scenarioRunner = new ScenarioRunner( scenario,
                                                            resolver,
                                                            (InternalWorkingMemory) workingMemory );

        assertEquals( 0,
                      executionTrace.getNumberOfRulesFired().intValue() );

        assertSame( scenarioRunner.getScenario(),
                    scenario );

        assertFalse( scenario.wasSuccessful() );

        // Activate rule flow
        scenario.getFixtures().clear();
        given = new Fixture[]{new FactData( "Coolness",
                                            "c",
                                            ls( new FieldData( "num",
                                                               "42" ),
                                                new FieldData( "name",
                                                               "mic" ) ),
                                            false ), new ActivateRuleFlowGroup( "asdf" )};
        workingMemory.clearAgenda();
        scenario.getFixtures().addAll( Arrays.asList( given ) );
        scenario.getFixtures().add( executionTrace );
View Full Code Here


    @Test
    public void testIntgerationStateful() throws Exception {
        Scenario sc = new Scenario();
        sc.getFixtures().add( new FactData( "Cheese",
                                            "c1",
                                            ls( new FieldData( "price",
                                                               "1" ) ),
                                            false ) );
        ExecutionTrace ex = new ExecutionTrace();
        sc.getFixtures().add( ex );
        sc.getFixtures().add( new FactData( "Cheese",
                                            "c2",
                                            ls( new FieldData( "price",
                                                               "2" ) ),
                                            false ) );
        sc.getFixtures().add( new VerifyFact( "c1",
                                              ls( new VerifyField( "type",
                                                                   "rule1",
View Full Code Here

    @Test
    public void testIntegrationWithModify() throws Exception {
        Scenario sc = new Scenario();
        sc.getFixtures().add( new FactData( "Cheese",
                                            "c1",
                                            ls( new FieldData( "price",
                                                               "1" ) ),
                                            false ) );

        sc.getFixtures().add( new ExecutionTrace() );

        sc.getFixtures().add( new VerifyFact( "c1",
                                              ls( new VerifyField( "type",
                                                                   "rule1",
                                                                   "==" ) ) ) );

        sc.getFixtures().add( new FactData( "Cheese",
                                            "c1",
                                            ls( new FieldData( "price",
                                                               "42" ) ),
                                            true ) );
        sc.getFixtures().add( new ExecutionTrace() );

        sc.getFixtures().add( new VerifyFact( "c1",
View Full Code Here

    @Test
    public void testIntegrationWithRetract() throws Exception {
        Scenario sc = new Scenario();
        sc.getFixtures().add( new FactData( "Cheese",
                                            "c1",
                                            ls( new FieldData( "price",
                                                               "46" ),
                                                new FieldData( "type",
                                                               "XXX" ) ),
                                            false ) );
        sc.getFixtures().add( new FactData( "Cheese",
                                            "c2",
                                            ls( new FieldData( "price",
                                                               "42" ) ),
                                            false ) );
        sc.getFixtures().add( new ExecutionTrace() );

        sc.getFixtures().add( new VerifyFact( "c1",
View Full Code Here

    }

    private Expectation[] populateScenarioForFailure(Scenario sc) {
        FactData[] facts = new FactData[]{new FactData( "Cheese",
                                                        "c1",
                                                        ls( new FieldData( "type",
                                                                           "cheddar" ),
                                                            new FieldData( "price",
                                                                           "42" ) ),
                                                        false )

        };
        sc.getFixtures().addAll( Arrays.asList( facts ) );
View Full Code Here

                                       f2 );
        runner.getPopulatedData().put( "f3",
                                       f3 );
        FactData fd1 = new FactData( "Cheese",
                                     "f1",
                                     ls( new FieldData( "type",
                                                        "" ),
                                         new FieldData( "price",
                                                        "42" ) ),
                                     false );
        FactData fd2 = new FactData( "Cheese",
                                     "f2",
                                     ls( new FieldData( "type",
                                                        "" ),
                                         new FieldData( "price",
                                                        "43" ) ),
                                     false );
        FactData fd3 = new FactData( "Cheese",
                                     "f3",
                                     ls( new FieldData( "type",
                                                        "" ),
                                         new FieldData( "price",
                                                        "45" ) ),
                                     false );
        runner.getPopulatedData().put( "ACheesery",
                                       listChesse );
        FieldData field = new FieldData();
        field.setName( "cheeses" );
        field.collectionType = "Cheese";
        field.setNature( FieldData.TYPE_COLLECTION );
        field.setValue( "=[f1,f2,f3]" );
        List<FieldData> lstField = new ArrayList<FieldData>();
        lstField.add( field );
        FactData lst = new FactData( "Cheesery",
                                     "listChesse",
                                     lstField,
View Full Code Here

    Object populateFields(FactData fact,
                          Map<String, Object> factData,
                          Object factObject) {
        for ( int i = 0; i < fact.fieldData.size(); i++ ) {
            FieldData field = (FieldData) fact.fieldData.get( i );
            Object val;
            if ( field.value != null && !field.value.equals( "" ) ) {
                if ( field.value.startsWith( "=" ) ) {
                    // eval the val into existence
                    val = eval( field.value.substring( 1 ),
View Full Code Here

    Object populateFields(FactData fact,
                          Map<String, Object> factData,
                          Object factObject) {
        for ( int i = 0; i < fact.fieldData.size(); i++ ) {
            FieldData field = (FieldData) fact.fieldData.get( i );
            Object val;
            if ( field.value != null && !field.value.equals( "" ) ) {
                if ( field.value.startsWith( "=" ) ) {
                    // eval the val into existence
                    val = eval( field.value.substring( 1 ),
View Full Code Here

  }


  public void testNewScenario() {
        FactData d1 = new FactData("Driver", "d1", ls(new FieldData[] {new FieldData("age", "42"), new FieldData("name", "david")}), false);
        Scenario sc = new Scenario();
        sc.fixtures.add(d1);
        sc.fixtures.add(new ExecutionTrace());

        int size = sc.fixtures.size();
View Full Code Here

    assertEquals(1, sc_.fixtures.size());
  }

  private Scenario getDemo() {
        //Sample data
        FactData d1 = new FactData("Driver", "d1", ls(new FieldData[] {new FieldData("age", "42"), new FieldData("name", "david")}), false);
        FactData d2 = new FactData("Driver", "d2", ls(new FieldData[] {new FieldData("name", "michael")}), false);
        FactData d3 = new FactData("Driver", "d3", ls(new FieldData[] {new FieldData("name", "michael2")}), false);
        FactData d4 = new FactData("Accident", "a1", ls(new FieldData[] {new FieldData("name", "michael2")}), false);
        Scenario sc = new Scenario();
        sc.fixtures.add(d1);
        sc.fixtures.add(d2);
        sc.globals.add(d3);
        sc.globals.add(d4);
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.testing.FieldData

Copyright © 2018 www.massapicom. 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.