Search in sources :

Example 76 with List

use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.

the class ItemDefinitionDependenciesGeneratedTest method createItemDefinitionWithDeps.

private static ItemDefinition createItemDefinitionWithDeps(final ItemDefinition itemDefinitionTemplate, final List<ItemDefinition> dependencies, final int maxNumberOfDepsPerItemDefinition, final Set<String> usedNames) {
    // New ItemDefinition is created, so the original one stays untouched.
    final ItemDefinition it = new ItemDefinition();
    it.setName(itemDefinitionTemplate.getName());
    final List<ItemDefinition> possibleDependencies = dependencies.stream().filter(item -> !item.getName().equals(it.getName())).collect(Collectors.toList());
    addDepsToItemDefinition(it, possibleDependencies, maxNumberOfDepsPerItemDefinition, usedNames);
    return it;
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) QName(javax.xml.namespace.QName) Parameterized(org.junit.runners.Parameterized) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition)

Example 77 with List

use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.

the class ItemDefinitionDependenciesTest method testOrdering1.

@Test
public void testOrdering1() {
    ItemDefinition tCollateralRiskCategory = build("tCollateralRiskCategory");
    ItemDefinition tCreditRiskCategory = build("tCreditRiskCategory");
    ItemDefinition tAffordabilityCategory = build("tAffordabilityCategory");
    ItemDefinition tLoanRecommendation = build("tLoanRecommendation");
    ItemDefinition tLoan = build("tLoan");
    ItemDefinition tAge = build("tAge");
    ItemDefinition temploementStatus = build("temploementStatus");
    ItemDefinition tCreditScore = build("tCreditScore");
    ItemDefinition tRiskCategory = build("tRiskCategory");
    ItemDefinition tIncomeRisk = build("tIncomeRisk");
    ItemDefinition tBorrowe = build("tBorrowe", tAge, temploementStatus);
    ItemDefinition tPrequalification = build("tPrequalification");
    List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { tCollateralRiskCategory, tCreditRiskCategory, tAffordabilityCategory, tLoanRecommendation, tLoan, tAge, temploementStatus, tCreditScore, tRiskCategory, tIncomeRisk, tBorrowe, tPrequalification });
    List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertTrue("Index of tAge < tBorrowe", orderedList.indexOf(tAge) < orderedList.indexOf(tBorrowe));
    assertTrue("Index of temploementStatus < tBorrowe", orderedList.indexOf(temploementStatus) < orderedList.indexOf(tBorrowe));
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Example 78 with List

use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.

the class ItemDefinitionDependenciesTest method testOrdering3.

@Test
public void testOrdering3() {
    ItemDefinition tNumberList = build("tNumberList");
    ItemDefinition tTax = build("tTax");
    ItemDefinition tStateModel = build("tStateModel");
    ItemDefinition tTaxList = build("tTaxList", tTax);
    ItemDefinition tCategory = build("tCategory");
    ItemDefinition tItem = build("tItem", tCategory);
    ItemDefinition tItemList = build("tItemList", tItem);
    ItemDefinition tOrder = build("tOrder", tItemList);
    List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { tOrder, tItem, tCategory, tNumberList, tItemList, tTax, tStateModel, tTaxList });
    List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertTrue("Index of tCategory < tItem", orderedList.indexOf(tCategory) < orderedList.indexOf(tItem));
    assertTrue("Index of tItem < tItemList", orderedList.indexOf(tItem) < orderedList.indexOf(tItemList));
    assertTrue("Index of tItemList < tOrder", orderedList.indexOf(tItemList) < orderedList.indexOf(tOrder));
    assertTrue("Index of tTax < tTaxList", orderedList.indexOf(tTax) < orderedList.indexOf(tTaxList));
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Example 79 with List

use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.

the class ItemDefinitionDependenciesTest method testOrdering2.

@Test
public void testOrdering2() {
    ItemDefinition tMortgageType = build("tMortgageType");
    ItemDefinition tObjective = build("tObjective");
    ItemDefinition tRequested = build("tRequested", tMortgageType, tObjective);
    ItemDefinition tProduct = build("tProduct");
    ItemDefinition tProductCollection = build("tProductCollection", tProduct);
    ItemDefinition tConformanceType = build("tConformanceType");
    ItemDefinition tLoanTypes = build("tLoanTypes", tMortgageType, tConformanceType);
    List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { tRequested, tProduct, tProductCollection, tMortgageType, tObjective, tConformanceType, tLoanTypes });
    List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertTrue("Index of tMortgageType < tRequested", orderedList.indexOf(tMortgageType) < orderedList.indexOf(tRequested));
    assertTrue("Index of tObjective < tRequested", orderedList.indexOf(tObjective) < orderedList.indexOf(tRequested));
    assertTrue("Index of tProduct < tProductCollection", orderedList.indexOf(tProduct) < orderedList.indexOf(tProductCollection));
    assertTrue("Index of tMortgageType < tLoanTypes", orderedList.indexOf(tMortgageType) < orderedList.indexOf(tLoanTypes));
    assertTrue("Index of tConformanceType < tLoanTypes", orderedList.indexOf(tConformanceType) < orderedList.indexOf(tLoanTypes));
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Example 80 with List

use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.

the class DMNValidatorImpl method validate.

@Override
public List<DMNMessage> validate(File xmlFile, Validation... options) {
    DMNMessageManager results = new DefaultDMNMessagesManager();
    EnumSet<Validation> flags = EnumSet.copyOf(Arrays.asList(options));
    if (flags.contains(VALIDATE_SCHEMA)) {
        results.addAll(validateSchema(xmlFile));
    }
    if (flags.contains(VALIDATE_MODEL) || flags.contains(VALIDATE_COMPILATION)) {
        Definitions dmndefs = null;
        try {
            dmndefs = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(new FileReader(xmlFile));
            Definitions.normalize(dmndefs);
            validateModelCompilation(dmndefs, results, flags);
        } catch (Throwable t) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, null, results, t, null, Msg.FAILED_VALIDATOR);
        }
    }
    return results.getMessages();
}
Also used : DMNMessageManager(org.kie.dmn.core.api.DMNMessageManager) Definitions(org.kie.dmn.model.v1_1.Definitions) FileReader(java.io.FileReader) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager)

Aggregations

Test (org.junit.Test)54 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)26 ItemDefinition (org.kie.dmn.model.v1_1.ItemDefinition)21 QName (javax.xml.namespace.QName)17 ArrayList (java.util.ArrayList)15 List (java.util.List)14 DMNMessage (org.kie.dmn.api.core.DMNMessage)14 Import (org.kie.dmn.model.v1_1.Import)13 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)13 CoreMatchers.is (org.hamcrest.CoreMatchers.is)11 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)11 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)11 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)10 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 Definitions (org.kie.dmn.model.v1_1.Definitions)9 IOException (java.io.IOException)8 Collectors (java.util.stream.Collectors)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Reader (java.io.Reader)7