Search in sources :

Example 11 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNTypeServiceImplTest method retrieveFactModelTupleDmnListComposite.

@Test
public void retrieveFactModelTupleDmnListComposite() {
    setDmnModelLocal("dmn-list-composite.dmn", "https://github.com/kiegroup/drools/kie-dmn/_25BF2679-3109-488F-9AD1-DDBCCEBBE5F1", "dmn-list-composite");
    FactModelTuple factModelTuple = dmnTypeServiceImpl.retrieveFactModelTuple(mock(Path.class), null);
    // VisibleFacts should match inputs and decisions on given model
    int expectedVisibleFacts = dmnModelLocal.getInputs().size() + dmnModelLocal.getDecisions().size();
    assertEquals(expectedVisibleFacts, factModelTuple.getVisibleFacts().size());
    Map<String, String> importedModelsMap = dmnModelLocal.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
    // Verify each inputDataNode has been correctly mapped
    dmnModelLocal.getInputs().forEach(inputDataNode -> verifyFactModelTree(factModelTuple, inputDataNode, factModelTuple.getHiddenFacts(), importedModelsMap));
    // Verify each decisionNode has been correctly mapped
    dmnModelLocal.getDecisions().forEach(decisionNode -> verifyFactModelTree(factModelTuple, decisionNode, factModelTuple.getHiddenFacts(), importedModelsMap));
}
Also used : Path(org.uberfire.backend.vfs.Path) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Test(org.junit.Test)

Example 12 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNTypeServiceImplTest method retrieveFactModelTupleUsingImportedTrafficViolation.

@Test
public void retrieveFactModelTupleUsingImportedTrafficViolation() {
    setDmnModelLocal("Using Imported.dmn", "https://kiegroup.org/dmn/_7120AA2F-BEB6-4CB1-BCC7-427A17AEF71D", "Using Imported", "Traffic Violation.dmn");
    FactModelTuple factModelTuple = dmnTypeServiceImpl.retrieveFactModelTuple(mock(Path.class), null);
    // VisibleFacts should match inputs and decisions on given model
    int expectedVisibleFacts = dmnModelLocal.getInputs().size() + dmnModelLocal.getDecisions().size();
    assertEquals(expectedVisibleFacts, factModelTuple.getVisibleFacts().size());
    Map<String, String> importedModelsMap = dmnModelLocal.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
    // Verify each inputDataNode has been correctly mapped
    dmnModelLocal.getInputs().forEach(inputDataNode -> verifyFactModelTree(factModelTuple, inputDataNode, factModelTuple.getHiddenFacts(), importedModelsMap));
    // Verify each decisionNode has been correctly mapped
    dmnModelLocal.getDecisions().forEach(decisionNode -> verifyFactModelTree(factModelTuple, decisionNode, factModelTuple.getHiddenFacts(), importedModelsMap));
}
Also used : Path(org.uberfire.backend.vfs.Path) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Test(org.junit.Test)

Example 13 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method createSimulation.

@Test
public void createSimulation() throws Exception {
    FactModelTuple factModelTuple = getFactModelTuple();
    final Path pathMock = mock(Path.class);
    final String dmnFilePath = "test";
    doReturn(factModelTuple).when(dmnSimulationCreationStrategy).getFactModelTuple(any(), any());
    final Simulation retrieved = dmnSimulationCreationStrategy.createSimulation(pathMock, dmnFilePath);
    assertNotNull(retrieved);
    verify(dmnTypeServiceMock, never()).initializeNameAndNamespace(any(Settings.class), eq(pathMock), eq(dmnFilePath));
}
Also used : Path(org.uberfire.backend.vfs.Path) Simulation(org.drools.scenariosimulation.api.model.Simulation) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Matchers.anyString(org.mockito.Matchers.anyString) Settings(org.drools.scenariosimulation.api.model.Settings) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 14 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
    final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
    AtomicInteger id = new AtomicInteger(1);
    final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
    final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
    visibleFactTrees.stream().sorted((a, b) -> {
        Type aType = a.getType();
        Type bType = b.getType();
        int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
        return aType.equals(bType) ? 0 : inputFirstOrder;
    }).forEach(factModelTree -> {
        FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
        FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
        addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
    });
    addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Collection(java.util.Collection) Settings(org.drools.scenariosimulation.api.model.Settings) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ApplicationScoped(javax.enterprise.context.ApplicationScoped) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Simulation(org.drools.scenariosimulation.api.model.Simulation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 15 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class AbstractDMNDataManagementStrategyTest method setup.

@Before
public void setup() {
    super.setup();
    factModelTupleLocal = new FactModelTuple(visibleFactsLocal, hiddenFactsLocal);
    factModelTreeHolderlocal = new AbstractDataManagementStrategy.ResultHolder();
    factModelTreeHolderlocal.setFactModelTuple(factModelTupleLocal);
    when(dmnTypeServiceMock.retrieveFactModelTuple(any(), anyString())).thenReturn(factModelTupleLocal);
    modelLocal.getSettings().setDmnFilePath(DMN_FILE_PATH);
    abstractDMNDataManagementStrategySpy = spy(new AbstractDMNDataManagementStrategy(mock(EventBus.class)) {

        @Override
        protected void retrieveFactModelTuple(TestToolsView.Presenter testToolsPresenter, ScenarioSimulationContext context, GridWidget gridWidget) {
        }

        {
            this.currentPath = mock(Path.class);
            this.model = modelLocal;
            this.factModelTreeHolder = factModelTreeHolderlocal;
            this.dmnFilePath = DMN_FILE_PATH;
        }
    });
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) Path(org.uberfire.backend.vfs.Path) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) EventBus(com.google.gwt.event.shared.EventBus) Before(org.junit.Before)

Aggregations

FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)17 Test (org.junit.Test)9 TreeMap (java.util.TreeMap)8 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)7 SortedMap (java.util.SortedMap)6 Path (org.uberfire.backend.vfs.Path)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)5 HashMap (java.util.HashMap)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)4 Settings (org.drools.scenariosimulation.api.model.Settings)4 Simulation (org.drools.scenariosimulation.api.model.Simulation)4 VALUE (org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE)4 Before (org.junit.Before)4 DMNType (org.kie.dmn.api.core.DMNType)4 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)4 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)4