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

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


      assertFalse("".equals(failures));
      System.err.println(failures);
    }

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

        };
        sc.fixtures.addAll( Arrays.asList( facts ) );
        sc.globals.add( new FactData( "Person",
                                      "p",
                                      new ArrayList(),
                                      false ) );

        ExecutionTrace executionTrace = new ExecutionTrace();
View Full Code Here


   * Group the globals together by fact type.
   */
   public Map lumpyMapGlobals(List globals) {
     Map g = new HashMap();
     for (Iterator iterator = globals.iterator(); iterator.hasNext();) {
      FactData f = (FactData) iterator.next();
      accumulateFactData(g, f);
    }
     return g;
   }
View Full Code Here

    }
     return g;
   }

  private void accumulateFactData(Map dataInput, Fixture f) {
    FactData fd = (FactData) f;
    if (! dataInput.containsKey(fd.type)) {
      dataInput.put(fd.type, new ArrayList());
    }
    ((List) dataInput.get(fd.type)).add(fd);
  }
View Full Code Here

  }


  static void removeFields(List factData, String field) {
    for (Iterator iterator = factData.iterator(); iterator.hasNext();) {
      FactData fa = (FactData) iterator.next();
      for (Iterator iterator2 = fa.fieldData.iterator(); iterator2.hasNext();) {
        FieldData fi = (FieldData) iterator2.next();
        if (fi.name.equals(field)) {
          iterator2.remove();
        }
View Full Code Here

          public void onClick(Widget w) {
              String fn = factTypes.getItemText(factTypes.getSelectedIndex());
              if (scenario.isFactNameExisting(fn)) {
                                Window.alert(Format.format(constants.TheName0IsAlreadyInUsePleaseChooseAnotherName(), fn));
              } else {
                FactData ng = new FactData((String) sce.globalTypes.get(fn), fn, new ArrayList(), false);
                scenario.globals.add(ng);
                renderEditor();
                pop.hide();
              }
          }
View Full Code Here

              Window.alert(constants.YouMustEnterAValidFactName());
            } else {
              if (scenario.isFactNameExisting(fn)) {
                                Window.alert(Format.format(constants.TheFactName0IsAlreadyInUsePleaseChooseAnotherName(), fn));
              } else {
                scenario.insertBetween(previousEx, new FactData(factTypes.getItemText(factTypes.getSelectedIndex()), factName.getText(), new ArrayList(), false ));
                renderEditor();
                pop.hide();
              }
            }
          }
        });

            HorizontalPanel insertFact = new HorizontalPanel();
            insertFact.add(factTypes); insertFact.add(new SmallLabel(constants.FactName())); insertFact.add(factName); insertFact.add(add);
            pop.addAttribute(constants.InsertANewFact1(), insertFact);

            List varsInScope = scenario.getFactNamesInScope(previousEx, false);
            //now we do modifies & retracts
            if (varsInScope.size() > 0) {
              final ListBox modifyFacts = new ListBox();
              for (int j = 0; j < varsInScope.size(); j++) { modifyFacts.addItem((String) varsInScope.get(j));}
              add = new Button(constants.Add());
              add.addClickListener(new ClickListener() {
            public void onClick(Widget w) {
              String fn = modifyFacts.getItemText(modifyFacts.getSelectedIndex());
              String type  = (String) scenario.getVariableTypes().get(fn);
              scenario.insertBetween(previousEx, new FactData(type, fn, new ArrayList(), true));
              renderEditor();
              pop.hide();
            }
          });
              HorizontalPanel modifyFact = new HorizontalPanel();
View Full Code Here


        if (isGlobal) {
            outer.setWidget(0, 0, getLabel(Format.format(constants.globalForScenario(), factType), defList));
        } else {
            FactData first = (FactData) defList.get(0);
            if (first.isModify) {
                outer.setWidget(0, 0,  getLabel(Format.format(constants.modifyForScenario(), factType), defList));
            } else {
                outer.setWidget(0, 0, getLabel(Format.format(constants.insertForScenario(), factType), defList));
            }
View Full Code Here

      public void onClick(Widget w) {

        //build up a list of what we have got, don't want to add it twice
        HashSet existingFields = new HashSet();
        if (defList.size() > 0) {
          FactData d = (FactData) defList.get(0);
          for (Iterator iterator = d.fieldData.iterator(); iterator.hasNext();) {
            FieldData f = (FieldData) iterator.next();
            existingFields.add(f.name);
          }

        }
        String[] fields = (String[]) sce.fieldsForType.get(type);
        final FormStylePopup pop = new FormStylePopup("images/rule_asset.gif", constants.ChooseAFieldToAdd()); //NON-NLS
        final ListBox b = new ListBox();
        for (int i = 0; i < fields.length; i++) {
          String fld = fields[i];
          if (!existingFields.contains(fld)) b.addItem(fld);
        }
        pop.addRow(b);
        Button ok = new Button(constants.OK());
        ok.addClickListener(new ClickListener() {
                  public void onClick(Widget w) {
                    String f = b.getItemText(b.getSelectedIndex());
                    for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
                      FactData fd = (FactData) iterator.next();
                      fd.fieldData.add(new FieldData(f, ""));
                    }
                        outer.setWidget(1, 0, render(defList));
                        pop.hide();
                  }
View Full Code Here

        Map fields = new HashMap();
        int col = 0;
        int totalCols = defList.size();
        for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
            final FactData d = (FactData) iterator.next();

            for (int i = 0; i < d.fieldData.size(); i++) {
                final FieldData fd = d.fieldData.get(i);
                if (!fields.containsKey(fd.name)) {
                    int idx = fields.size() + 1;
                    fields.put(fd.name, new Integer(idx));
                    t.setWidget(idx, 0, new SmallLabel(fd.name + ":"));
                    Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRow(), new ClickListener() {
                public void onClick(Widget w) {
                  if (Window.confirm(constants.AreYouSureYouWantToRemoveThisRow())) {
                    ScenarioHelper.removeFields(defList, fd.name);
                    outer.setWidget(1, 0, render(defList));

                  }
                }
              });
                    t.setWidget(idx, totalCols + 1, del);
                    t.getCellFormatter().setHorizontalAlignment(idx, 0, HasHorizontalAlignment.ALIGN_RIGHT);
                }
            }
        }

        int totalRows = fields.size();

        t.getFlexCellFormatter().setHorizontalAlignment(totalRows + 1, 0, HasHorizontalAlignment.ALIGN_RIGHT);

        //now we go through the facts and the fields, adding them to the grid
        //if a fact is missing a FieldData, we will add it in (so people can enter data later on)
        col = 0;
        for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
            final FactData d = (FactData) iterator.next();
            t.setWidget(0, ++col, new SmallLabel("[" + d.name + "]"));
            Image del = new ImageButton("images/delete_item_small.gif", Format.format(constants.RemoveTheColumnForScenario(), d.name), new ClickListener() {
        public void onClick(Widget w) {
          if (scenario.isFactNameUsed(d)) {
                        Window.alert(Format.format(constants.CanTRemoveThisColumnAsTheName0IsBeingUsed(), d.name));
View Full Code Here

    //TestingEventListener.stubOutRules(ruleList, wm.getRuleBase(), scenario.inclusive);

    TestingEventListener listener = null;

    for (Iterator iterator = scenario.globals.iterator(); iterator.hasNext();) {
      FactData fact = (FactData) iterator.next();
      Object f = eval("new " + resolver.getFullTypeName(fact.type) + "()");
      populateFields(fact, globalData, f);
      globalData.put(fact.name, f);
      wm.setGlobal(fact.name, f);
    }

    for (Iterator<Fixture> iterator = scenario.fixtures.iterator(); iterator.hasNext();) {
      Fixture fx = iterator.next();

      if (fx instanceof FactData) {
        //deal with facts and globals
        FactData fact = (FactData)fx;
        Object f = (fact.isModify)? this.populatedData.get(fact.name) : eval("new " + resolver.getFullTypeName(fact.type) + "()");
        if (fact.isModify) {
          if (!this.factHandles.containsKey(fact.name)) {
            throw new IllegalArgumentException("Was not a previously inserted fact. [" + fact.name  + "]");
          }
View Full Code Here

TOP

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

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.