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

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


        //first, the green scenario
        Scenario sc = new Scenario();
        FactData person = new FactData();
        person.setName( "p" );
        person.setType( "Person" );
        person.getFieldData().add( new FieldData( "age",
                                                  "40" ) );
        person.getFieldData().add( new FieldData( "name",
                                                  "michael" ) );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        VerifyRuleFired vr = new VerifyRuleFired( "rule1",
                                                  1,
                                                  null );
        sc.getFixtures().add( vr );

        VerifyFact vf = new VerifyFact();
        vf.setName( "p" );
        vf.getFieldValues().add( new VerifyField( "name",
                                                  "michael",
                                                  "==" ) );
        vf.getFieldValues().add( new VerifyField( "age",
                                                  "42",
                                                  "==" ) );
        sc.getFixtures().add( vf );

        AssetItem scenario1 = pkg.addAsset( "scen1",
                                            "" );
        scenario1.updateFormat( AssetFormats.TEST_SCENARIO );
        scenario1.updateContent( ScenarioXMLPersistence.getInstance().marshal( sc ) );
        scenario1.checkin( "" );

        //now the bad scenario
        sc = new Scenario();
        person = new FactData();
        person.setName( "p" );
        person.setType( "Person" );
        person.getFieldData().add( new FieldData( "age",
                                                  "40" ) );
        person.getFieldData().add( new FieldData( "name",
                                                  "michael" ) );

        sc.getFixtures().add( person );
        sc.getFixtures().add( new ExecutionTrace() );
        vr = new VerifyRuleFired( "rule2",
View Full Code Here


    }

    Object populateFields(FactData fact,
                          Object factObject) {
        for (int i = 0; i < fact.getFieldData().size(); i++) {
            FieldData field = (FieldData) fact.getFieldData().get(i);
            Object val = null;

            if (field.getValue() != null && !field.getValue().equals("")) {

                if (field.getValue().startsWith("=")) {
                    // eval the val into existence
                    val = eval(field.getValue().substring(1),
                            populatedData);
                } else if (field.getNature() == FieldData.TYPE_ENUM) {
                    // The string representation of a java enum value is a
                    // format like CheeseType.CHEDDAR
                    String valueOfEnum = field.getValue();
                    String fullName = null;
                    if (field.getValue().indexOf(".") != -1) {
                        String classNameOfEnum = field.getValue().substring(0,
                                field.getValue().lastIndexOf("."));
                        valueOfEnum = field.getValue().substring(
                                field.getValue().lastIndexOf(".") + 1);
                        try {
                            //This is a Java enum type if the type can be resolved by ClassTypeResolver
                            //Revisit: Better way to determine java enum type or Guvnor enum type.
                            fullName = resolver
                                    .getFullTypeName(classNameOfEnum);
                            if (fullName != null && !"".equals(fullName)) {
                                valueOfEnum = fullName + "." + valueOfEnum;
                            }
                            val = eval(valueOfEnum);
                        } catch (ClassNotFoundException e) {
                            // This is a Guvnor enum type
                            fullName = classNameOfEnum;
                            if (fullName != null && !"".equals(fullName)) {
                                valueOfEnum = fullName + "." + valueOfEnum;
                            }
                            val = valueOfEnum;
                        }
                    } else {
                        val = valueOfEnum;
                    }
                } else {
                    val = field.getValue();
                }

                Map<String, Object> vars = new HashMap<String, Object>();
                vars.putAll(populatedData);
                vars.put("__val__",
                        val);
                vars.put("__fact__",
                        factObject);
                eval("__fact__." + field.getName() + " = __val__",
                        vars);
            }
        }
        return factObject;
    }
View Full Code Here

            if (selectionEvent.getSelectedItem() == FieldData.TYPE_COLLECTION) {
                CollectionFieldData collectionFieldData = new CollectionFieldData();
                collectionFieldData.setName(field.getName());
                return collectionFieldData;
            } else {
                FieldData fieldData = new FieldData(field.getName(), "");
                fieldData.setNature(selectionEvent.getSelectedItem());
                return fieldData;
            }
        }
    }
View Full Code Here

            add(new ImageButton(DroolsGuvnorImages.INSTANCE.newItem(),
                    Constants.INSTANCE.AElementToAddInCollectionList(),
                    new ClickHandler() {

                        public void onClick(ClickEvent w) {
                            FieldData fieldData = new FieldData();
                            fieldData.setName(field.getName());
                            field.getCollectionFieldList().add(fieldData);
                            parent.renderEditor();
                        }
                    }));
        } else {
View Full Code Here

        parent.renderEditor();
    }

    @UiHandler("newItemBelow")
    public void newItemBelow(ClickEvent event) {
        FieldData newFieldData = new FieldData();
        newFieldData.setName(parentField.getName());
        parentField.getCollectionFieldList().add(index + 1,
                newFieldData);
        parent.renderEditor();
    }
View Full Code Here

    }

    @UiHandler("suffleDown")
    public void suffleDown(ClickEvent event) {
        if (index < parentField.getCollectionFieldList().size() - 1) {
            FieldData onMyLine = parentField.getCollectionFieldList().get(index);
            FieldData onDown = parentField.getCollectionFieldList().get(index + 1);
            parentField.getCollectionFieldList().set(index + 1,
                    onMyLine);
            parentField.getCollectionFieldList().set(index,
                    onDown);
            parent.renderEditor();
View Full Code Here

    }

    @UiHandler("suffleUp")
    public void suffleUp(ClickEvent event) {
        if (index > 0) {
            FieldData oneUp = parentField.getCollectionFieldList().get(index - 1);
            FieldData onMyLine = parentField.getCollectionFieldList().get(index);
            parentField.getCollectionFieldList().set(index,
                    oneUp);
            parentField.getCollectionFieldList().set(index - 1,
                    onMyLine);
            parent.renderEditor();
View Full Code Here

            image.setAltText(Constants.INSTANCE.AElementToAddInCollectionList());
            image.setTitle(Constants.INSTANCE.AElementToAddInCollectionList());
            image.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent w) {
                    FieldData fieldData = new FieldData();
                    fieldData.setName(field.getName());
                    field.getCollectionFieldList().add(fieldData);
                    parent.renderEditor();
                }
            });
View Full Code Here

            if (selectionEvent.getSelectedItem() == FieldData.TYPE_COLLECTION) {
                CollectionFieldData collectionFieldData = new CollectionFieldData();
                collectionFieldData.setName(field.getName());
                return collectionFieldData;
            } else {
                FieldData fieldData = new FieldData(field.getName(), "");
                fieldData.setNature(selectionEvent.getSelectedItem());
                return fieldData;
            }
        }
    }
View Full Code Here

                    public void onClick(ClickEvent event) {
                        String field = fieldsListBox.getItemText( fieldsListBox.getSelectedIndex() );
                        for ( Fixture fixture : definitionList ) {
                            if ( fixture instanceof FactData ) {
                                FactData factData = (FactData) fixture;
                                factData.getFieldData().add( new FieldData( field,
                                                                            "" ) );
                            }
                        }
                        render();
                        pop.hide();
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.