Search in sources :

Example 6 with ItemDefinition

use of org.kie.dmn.model.v1_1.ItemDefinition 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 7 with ItemDefinition

use of org.kie.dmn.model.v1_1.ItemDefinition 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 8 with ItemDefinition

use of org.kie.dmn.model.v1_1.ItemDefinition 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 9 with ItemDefinition

use of org.kie.dmn.model.v1_1.ItemDefinition 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)

Example 10 with ItemDefinition

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

the class ItemDefinitionDependenciesTest method testGeneric2.

@Test
public void testGeneric2() {
    ItemDefinition z = build("z");
    ItemDefinition b = build("b");
    ItemDefinition a = build("a", z);
    List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { z, b, a });
    List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertTrue("Index of z < a", orderedList.indexOf(z) < orderedList.indexOf(a));
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Aggregations

ItemDefinition (org.kie.dmn.model.v1_1.ItemDefinition)22 Test (org.junit.Test)10 QName (javax.xml.namespace.QName)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 RunWith (org.junit.runner.RunWith)2 Parameterized (org.junit.runners.Parameterized)2 DMNType (org.kie.dmn.api.core.DMNType)2 Definitions (org.kie.dmn.model.v1_1.Definitions)2 XStream (com.thoughtworks.xstream.XStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1