Package org.drools.guvnor.client.modeldriven.testing

Examples of org.drools.guvnor.client.modeldriven.testing.Scenario



  }

  public void testMapFactTypes() {
    Scenario sc = new Scenario();
    sc.fixtures.add(new FactData("X", "q", null, false));
    sc.globals.add(new FactData("Q", "x", null, false));

    Map r = sc.getVariableTypes();
    assertEquals(2, r.size());

    assertEquals("X", r.get("q"));
    assertEquals("Q", r.get("x"));
View Full Code Here


    assertEquals("Q", r.get("x"));

  }

  public void testVariablesInScope() {
    Scenario sc = new Scenario();
    sc.globals.add(new FactData("X", "x", new ArrayList(), false));

    sc.fixtures.add(new FactData("Q", "q", new ArrayList(), true));
    sc.fixtures.add(new FactData("Z", "z", new ArrayList(), false));
    ExecutionTrace ex1 = new ExecutionTrace();

    sc.fixtures.add(ex1);
    sc.fixtures.add(new RetractFact("z"));
    sc.fixtures.add(new FactData("Y", "y", new ArrayList(), false));

    ExecutionTrace ex2 = new ExecutionTrace();
    sc.fixtures.add(ex2);

    List l = sc.getFactNamesInScope(ex1, true);

    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("z", l.get(1));
    assertEquals("x", l.get(2));


    l = sc.getFactNamesInScope(ex1, false);
    assertEquals(2, l.size());
    assertFalse(l.contains(sc.globals.get(0)));

    l = sc.getFactNamesInScope(ex2, true);
    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("y", l.get(1));
    assertEquals("x", l.get(2));

    l= sc.getFactNamesInScope(null, true);
    assertEquals(0, l.size());

  }
View Full Code Here

    assertEquals(0, l.size());

  }

  public void testAllowRemoveFact() {
    Scenario sc = new Scenario();

    FactData fd1 = new FactData("X", "x", new ArrayList(), false);
    sc.fixtures.add(fd1);
    FactData fd2 = new FactData("Q", "q", new ArrayList(), false);
    sc.fixtures.add(fd2);
    FactData fd3 = new FactData("Z", "z", new ArrayList(), false);
    sc.fixtures.add(fd3);
    ExecutionTrace ex1 = new ExecutionTrace();
    FactData fd4 = new FactData("I", "i", new ArrayList(), false);
    sc.globals.add(fd4);

    sc.fixtures.add(ex1);
    sc.fixtures.add(new RetractFact("z"));
    sc.fixtures.add(new FactData("Z", "z", new ArrayList(), true));
    sc.fixtures.add(new VerifyFact("q", new ArrayList()));

    assertFalse(sc.isFactNameUsed(fd1));
    assertTrue(sc.isFactNameUsed(fd2));
    assertTrue(sc.isFactNameUsed(fd3));
    assertFalse(sc.isFactNameUsed(fd4));
  }
View Full Code Here

    assertTrue(sc.isFactNameUsed(fd3));
    assertFalse(sc.isFactNameUsed(fd4));
  }

  public void testIsFactNameUsed() {
    Scenario sc = new Scenario();
    sc.globals.add(new FactData("X", "x", null, false));
    sc.fixtures.add(new FactData("Q", "q", null, false));
    sc.fixtures.add(new ExecutionTrace());

    assertTrue(sc.isFactNameExisting("x"));
    assertTrue(sc.isFactNameExisting("q"));
    assertFalse(sc.isFactNameExisting("w"));


    sc = new Scenario();
    assertFalse(sc.isFactNameExisting("w"));
  }
View Full Code Here

    sc = new Scenario();
    assertFalse(sc.isFactNameExisting("w"));
  }

  public void testCountSuccessFailures() {
    Scenario sc = new Scenario();
    sc.fixtures.add(new FactData());
    sc.fixtures.add(new ExecutionTrace());
    VerifyRuleFired vr = new VerifyRuleFired();
    vr.successResult = false;
    sc.fixtures.add(vr);

    VerifyField vf = new VerifyField();
    vf.successResult = true;
    VerifyField vf2 = new VerifyField();
    vf2.successResult = false;
    VerifyFact vfact = new VerifyFact();
    vfact.fieldValues.add(vf);
    vfact.fieldValues.add(vf2);
    sc.fixtures.add(vfact);


    int[] totals = sc.countFailuresTotal();
    assertEquals(2, totals[0]);
    assertEquals(3, totals[1]);


View Full Code Here

        Thread.currentThread().setContextClassLoader(cl_);

    }

    public void testIntgerationStateful() throws Exception {
        Scenario sc = new Scenario();
        sc.fixtures.add( new FactData( "Cheese",
                                       "c1",
                                       ls( new FieldData( "price",
                                                          "1" ) ),
                                       false ) );
        ExecutionTrace ex = new ExecutionTrace();
        sc.fixtures.add( ex );
        sc.fixtures.add( new FactData( "Cheese",
                                       "c2",
                                       ls( new FieldData( "price",
                                                          "2" ) ),
                                       false ) );
        sc.fixtures.add( new VerifyFact( "c1",
                                         ls( new VerifyField( "type",
                                                              "rule1",
                                                              "==" ) ) ) );
        ex = new ExecutionTrace();
        sc.fixtures.add( ex );
        sc.fixtures.add( new VerifyFact( "c1",
                                         ls( new VerifyField( "type",
                                                              "rule2",
                                                              "==" ) ) ) );

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

        WorkingMemory wm = getWorkingMemory( "test_stateful.drl" );
        ScenarioRunner run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

        Cheese c1 = (Cheese) run.populatedData.get( "c1" );
        Cheese c2 = (Cheese) run.populatedData.get( "c2" );

        assertEquals( "rule2",
                      c1.getType() );
        assertEquals( "rule2",
                      c2.getType() );

        assertTrue( sc.wasSuccessful() );

    }
View Full Code Here

        assertTrue( sc.wasSuccessful() );

    }

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

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

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

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

        sc.fixtures.add( new VerifyFact( "c1",
                                         ls( new VerifyField( "type",
                                                              "rule3",
                                                              "==" ) ) ) );

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

        WorkingMemory wm = getWorkingMemory( "test_stateful.drl" );
        ScenarioRunner run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

        Cheese c1 = (Cheese) run.populatedData.get( "c1" );

        assertEquals( "rule3",
                      c1.getType() );

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

        assertTrue( sc.wasSuccessful() );
    }

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

        sc.fixtures.add( new VerifyFact( "c1",
                                         ls( new VerifyField( "type",
                                                              "XXX",
                                                              "==" ) ) ) );

        sc.fixtures.add( new RetractFact( "c2" ) );
        sc.fixtures.add( new ExecutionTrace() );

        sc.fixtures.add( new VerifyFact( "c1",
                                         ls( new VerifyField( "type",
                                                              "rule4",
                                                              "==" ) ) ) );

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

        WorkingMemory wm = getWorkingMemory( "test_stateful.drl" );
        ScenarioRunner run = new ScenarioRunner( sc,
                                                 resolver,
                                                 (InternalWorkingMemory) wm );

        Cheese c1 = (Cheese) run.populatedData.get( "c1" );

        assertEquals( "rule4",
                      c1.getType() );
        assertFalse( run.populatedData.containsKey( "c2" ) );

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

        assertTrue( sc.wasSuccessful() );
    }

    public void testIntegrationWithFailure() throws Exception {
        Scenario sc = new Scenario();
        Expectation[] assertions = populateScenarioForFailure(sc);

        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 );

        assertSame( run.scenario,
                    sc );

        assertFalse( sc.wasSuccessful() );

        VerifyFact vf = (VerifyFact) assertions[1];
        assertFalse( ((VerifyField) vf.fieldValues.get( 0 )).successResult );
        assertEquals( "XXX",
                      ((VerifyField) vf.fieldValues.get( 0 )).expected );
View Full Code Here

                      vr.actualResult.intValue() );

    }

    public void testRunAsString() throws Exception {
      Scenario sc = new Scenario();
      populateScenarioForFailure(sc);
      String xml = ScenarioXMLPersistence.getInstance().marshal(sc);
      WorkingMemory wm = getWorkingMemory( "test_rules2.drl" );
      ScenarioRunner runner = new ScenarioRunner(xml, wm.getRuleBase());
      assertFalse(runner.wasSuccess());
View Full Code Here

TOP

Related Classes of org.drools.guvnor.client.modeldriven.testing.Scenario

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.