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

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


    }

    private void ifFixturesSizeZeroThenAddExecutionTrace() {
        if ( getScenario().getFixtures().size() == 0 ) {
            getScenario().getFixtures().add( new ExecutionTrace() );
        }
    }
View Full Code Here


        List<Fixture> fixtures = scenarioHelper.lumpyMap( getScenario().getFixtures() );
        List<ExecutionTrace> listExecutionTrace = scenarioHelper.getExecutionTraceFor( fixtures );

        int layoutRow = 1;
        int executionTraceLine = 0;
        ExecutionTrace previousExecutionTrace = null;
        for ( final Fixture fixture : fixtures ) {
            if ( fixture instanceof ExecutionTrace ) {
                ExecutionTrace currentExecutionTrace = (ExecutionTrace) fixture;
                createWidgetForEditorLayout( editorLayout,
                                             layoutRow,
                                             0,
                                             scenarioWidgetComponentCreator.createExpectPanel( currentExecutionTrace ) );
View Full Code Here

                    panel.add( new SmallLabel( verifyField.getExplanation() ) );
                    resultsDetail.add( panel );
                }

            } else if ( fixture instanceof ExecutionTrace ) {
                ExecutionTrace ex = (ExecutionTrace) fixture;
                if ( ex.getNumberOfRulesFired() == data.result.getScenario().getMaxRuleFirings() ) {
                    Window.alert( constants.MaxRuleFiringsReachedWarning(
                            data.result.getScenario().getMaxRuleFirings() ) );
                }
            }
View Full Code Here

    @Test
    public void testTrimUneededSection() {
    Scenario sc = getDemo();
    Scenario orig = getDemo();
    sc.getFixtures().add(new ExecutionTrace());

    int origSize = orig.getFixtures().size();

    assertEquals(origSize + 1, sc.getFixtures().size());
    String xml = ScenarioXMLPersistence.getInstance().marshal(sc);
View Full Code Here

    @Test
    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.getFixtures().add(d1);
        sc.getFixtures().add(new ExecutionTrace());

        int size = sc.getFixtures().size();

    String xml = ScenarioXMLPersistence.getInstance().marshal(sc);
    Scenario sc_ = ScenarioXMLPersistence.getInstance().unmarshal(xml);

    assertEquals(size, sc_.getFixtures().size());

    sc = new Scenario();
    sc.getFixtures().add(new ExecutionTrace());
    xml = ScenarioXMLPersistence.getInstance().marshal(sc);
    sc_ = ScenarioXMLPersistence.getInstance().unmarshal(xml);
    assertEquals(1, sc_.getFixtures().size());
  }
View Full Code Here

        sc.getGlobals().add(d3);
        sc.getGlobals().add(d4);
        sc.getRules().add("rule1");
        sc.getRules().add("rule2");

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

        List fields = new ArrayList();
        VerifyField vfl = new VerifyField("age", "42", "==");
        vfl.setActualResult( "43" );
        vfl.setSuccessResult( new Boolean(false) );
View Full Code Here

                                           "p",
                                           new ArrayList(),
                                           false ) );
        sc.getFixtures().addAll( Arrays.asList( facts ) );

        ExecutionTrace executionTrace = new ExecutionTrace();

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

        Expectation[] assertions = new Expectation[5];

        assertions[0] = new VerifyFact( "c1",
                                        ls( new VerifyField( "type",
                                                             "cheddar",
                                                             "==" )

                                        ) );

        assertions[1] = new VerifyFact( "p",
                                        ls( new VerifyField( "name",
                                                             "rule1",
                                                             "==" ),
                                            new VerifyField( "status",
                                                             "rule2",
                                                             "==" ) )

        );

        assertions[2] = new VerifyRuleFired( "rule1",
                                             1,
                                             null );
        assertions[3] = new VerifyRuleFired( "rule2",
                                             1,
                                             null );
        assertions[4] = new VerifyRuleFired( "rule3",
                                             0,
                                             null );

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

        TypeResolver resolver = new ClassTypeResolver( new HashSet<String>(),
                                                       Thread.currentThread().getContextClassLoader() );
        resolver.addImport( "org.drools.Cheese" );
        resolver.addImport( "org.drools.Person" );

        WorkingMemory wm = getWorkingMemory( "test_rules2.drl" );

        ScenarioRunner run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

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

        assertSame( run.getScenario(),
                    sc );

        assertTrue( sc.wasSuccessful() );

        Person p = (Person) run.getGlobalData().get( "p" );
        assertEquals( "rule1",
                      p.getName() );
        assertEquals( "rule2",
                      p.getStatus() );
        assertEquals( 0,
                      p.getAge() );

        Thread.sleep( 50 );

        assertTrue( (new Date()).after( sc.getLastRunResult() ) );
        assertTrue( executionTrace.getExecutionTimeResult() != null );

        assertTrue( executionTrace.getRulesFired().length > 0 );

    }
View Full Code Here

                                           "p",
                                           new ArrayList(),
                                           false ) );
        sc.getFixtures().addAll( Arrays.asList( facts ) );

        ExecutionTrace executionTrace = new ExecutionTrace();

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

        Expectation[] assertions = new Expectation[5];

        assertions[0] = new VerifyFact( "c1",
                                        ls( new VerifyField( "type",
                                                             "cheddar",
                                                             "==" )

                                        ) );

        assertions[1] = new VerifyFact( "p",
                                        ls( new VerifyField( "name",
                                                             "rule1",
                                                             "==" ),
                                            new VerifyField( "status",
                                                             "rule2",
                                                             "==" ) )

        );

        assertions[2] = new VerifyRuleFired( "rule1",
                                             1,
                                             null );
        assertions[3] = new VerifyRuleFired( "rule2",
                                             1,
                                             null );
        assertions[4] = new VerifyRuleFired( "rule3",
                                             0,
                                             null );

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

        TypeResolver resolver = new ClassTypeResolver( new HashSet<String>(),
                                                       Thread.currentThread().getContextClassLoader() );
        resolver.addImport( "org.drools.Cheese" );
        resolver.addImport( "org.drools.Person" );

        WorkingMemory wm = getWorkingMemory( "test_rules_infinite_loop.drl" );

        ScenarioRunner run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

        assertEquals( sc.getMaxRuleFirings(),
                      executionTrace.getNumberOfRulesFired().intValue() );

    }
View Full Code Here

                                                        false )

        };
        sc.getFixtures().addAll( Arrays.asList( facts ) );

        ExecutionTrace executionTrace = new ExecutionTrace();

        sc.getRules().add( "rule1" );
        sc.setInclusive( true );
        sc.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 );

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

        WorkingMemory wm = getWorkingMemory( "test_rules3.drl" );
        ClassLoader cl = ((InternalRuleBase) wm.getRuleBase()).getRootClassLoader();

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

        TypeResolver resolver = new ClassTypeResolver( imports,
                                                       cl );

        Class cls = cl.loadClass( "foo.bar.Coolness" );
        assertNotNull( cls );

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

        //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 run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

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

        assertSame( run.getScenario(),
                    sc );

        assertTrue( sc.wasSuccessful() );
View Full Code Here

                                                      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 );
        workingMemory.getAgenda().getRuleFlowGroup( "asdf" ).setAutoDeactivate( false );
        scenarioRunner = new ScenarioRunner( scenario,
                                             resolver,
                                             (InternalWorkingMemory) workingMemory );

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

        assertSame( scenarioRunner.getScenario(),
                    scenario );

        assertTrue( scenario.wasSuccessful() );
View Full Code Here

TOP

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

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.