Search in sources :

Example 16 with List

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

the class ImportDMNResolverUtilTest method testLocateInNSdefaultwithAlias.

@Test
public void testLocateInNSdefaultwithAlias() {
    Import i = makeImport("nsA", "m1", null);
    List<QName> available = Arrays.asList(new QName("nsA", "m1"), new QName("nsA", "m2"), new QName("nsB", "m3"));
    Either<String, QName> result = ImportDMNResolverUtil.resolveImportDMN(i, available, Function.identity());
    assertTrue(result.isRight());
    assertEquals(new QName("nsA", "m1"), result.getOrElse(null));
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 17 with List

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

the class ItemDefinitionDependenciesGeneratedTest method assertOrdering.

private void assertOrdering(final ItemDefinition itemDefinition, final List<ItemDefinition> orderedList) {
    for (ItemDefinition dependency : itemDefinition.getItemComponent()) {
        final String dependencyName = dependency.getTypeRef().getLocalPart();
        final int indexOfDependency = indexOfItemDefinitionByName(dependencyName, orderedList);
        assertTrue("Cannot find dependency " + dependencyName + " in the ordered list!", indexOfDependency > -1);
        assertTrue("Index of " + itemDefinition.getName() + " < " + dependency.getTypeRef().getLocalPart(), orderedList.indexOf(itemDefinition) > indexOfDependency);
        if (dependency.getItemComponent() != null && !dependency.getItemComponent().isEmpty()) {
            assertOrdering(dependency, orderedList);
        }
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition)

Example 18 with List

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

the class ItemDefinitionDependenciesGeneratedTest method getPermutations.

private static void getPermutations(final List<ItemDefinition> itemDefinitions, final List<ItemDefinition> head, final Collection<List<ItemDefinition>> result) {
    if (itemDefinitions.size() == 1) {
        final List<ItemDefinition> resultList = new ArrayList<>(head);
        resultList.addAll(itemDefinitions);
        result.add(resultList);
    } else {
        for (ItemDefinition itemDefinition : itemDefinitions) {
            final List<ItemDefinition> newHead = new ArrayList<>(head);
            newHead.add(itemDefinition);
            final List<ItemDefinition> possibleDependencies = itemDefinitions.stream().filter(item -> !newHead.contains(item)).collect(Collectors.toList());
            getPermutations(possibleDependencies, newHead, result);
        }
    }
}
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) ArrayList(java.util.ArrayList)

Example 19 with List

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

the class ItemDefinitionDependenciesGeneratedTest method testOrdering.

@Test
public void testOrdering() {
    logger.debug("Item definitions:");
    itemDefinitions.forEach(itemDefinition -> {
        logger.debug(itemDefinition.getName());
        itemDefinition.getItemComponent().forEach(dependency -> logger.debug(dependency.getName()));
    });
    List<ItemDefinition> orderedList = orderingStrategy(itemDefinitions);
    for (ItemDefinition itemDefinition : itemDefinitions) {
        assertOrdering(itemDefinition, orderedList);
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Example 20 with List

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

the class ItemDefinitionDependenciesGeneratedTest method getBaseListOfItemDefinitions.

private static List<ItemDefinition> getBaseListOfItemDefinitions(final int nameIndexFrom) {
    final List<ItemDefinition> itemDefinitions = new ArrayList<>();
    for (int i = nameIndexFrom; i < NUMBER_OF_BASE_ITEM_DEFINITIONS + nameIndexFrom; i++) {
        final ItemDefinition it = new ItemDefinition();
        it.setName(ITEM_DEFINITION_NAME_BASE + i);
        itemDefinitions.add(it);
    }
    return itemDefinitions;
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) ArrayList(java.util.ArrayList)

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