Search in sources :

Example 1 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools by kiegroup.

the class DMNScenarioRunnerHelper method verifyConditions.

@Override
protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) {
    DMNResult dmnResult = (DMNResult) requestContext.get(DMNScenarioExecutableBuilder.DMN_RESULT);
    List<DMNMessage> dmnMessages = dmnResult.getMessages();
    for (ScenarioExpect output : scenarioRunnerData.getExpects()) {
        FactIdentifier factIdentifier = output.getFactIdentifier();
        String decisionName = factIdentifier.getName();
        DMNDecisionResult decisionResult = dmnResult.getDecisionResultByName(decisionName);
        if (decisionResult == null) {
            throw new ScenarioException("DMN execution has not generated a decision result with name " + decisionName);
        }
        for (FactMappingValue expectedResult : output.getExpectedResult()) {
            ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier();
            FactMapping factMapping = scesimModelDescriptor.getFactMapping(factIdentifier, expressionIdentifier).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
            ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(expectedResult);
            ScenarioResult scenarioResult = fillResult(expectedResult, () -> getSingleFactValueResult(factMapping, expectedResult, decisionResult, dmnMessages, expressionEvaluator), expressionEvaluator);
            scenarioRunnerData.addResult(scenarioResult);
        }
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) DMNMessage(org.kie.dmn.api.core.DMNMessage) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult)

Example 2 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools by kiegroup.

the class AbstractRunnerHelper method throwScenarioException.

private void throwScenarioException(FactMappingValue factMappingValue, ScesimModelDescriptor scesimModelDescriptor) {
    FactMapping factMapping = scesimModelDescriptor.getFactMapping(factMappingValue.getFactIdentifier(), factMappingValue.getExpressionIdentifier()).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
    String factName = String.join(".", factMapping.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
    if (FactMappingValueStatus.FAILED_WITH_ERROR == factMappingValue.getStatus()) {
        throw new ScenarioException(determineExceptionMessage(factMappingValue, factName), true);
    } else if (FactMappingValueStatus.FAILED_WITH_EXCEPTION == factMappingValue.getStatus()) {
        throw new ScenarioException(ScenarioSimulationServerMessages.getGenericScenarioExceptionMessage(factMappingValue.getExceptionMessage()));
    } else {
        throw new IllegalStateException("Illegal FactMappingValue status");
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement)

Example 3 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class ScenarioCsvImportExportTest method createFactMapping.

private FactMapping createFactMapping(ScesimModelDescriptor simulationDescriptor, int number) {
    FactMapping toReturn = simulationDescriptor.addFactMapping(FactIdentifier.create(instanceName + number, String.class.getCanonicalName()), ExpressionIdentifier.create(propertyName + number, FactMappingType.GIVEN));
    toReturn.setExpressionAlias(propertyName + number);
    return toReturn;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping)

Example 4 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method addToScenarioMultipleNested.

@Test
public void addToScenarioMultipleNested() {
    FactMapping factMappingMock = mock(FactMapping.class);
    DMNSimulationSettingsCreationStrategy.FactMappingExtractor factMappingExtractorMock = mock(DMNSimulationSettingsCreationStrategy.FactMappingExtractor.class);
    when(factMappingExtractorMock.getFactMapping(any(), anyString(), any(), anyString())).thenReturn(factMappingMock);
    Map<String, FactModelTree> hiddenFacts = new HashMap<>();
    FactModelTree factModelTree = new FactModelTree("myFact", "", new HashMap<>(), Collections.emptyMap());
    factModelTree.addExpandableProperty("nestedProperty", "tNested");
    factModelTree.addExpandableProperty("nestedProperty2", "tNested2");
    FactModelTree nested1 = new FactModelTree("tNested1", "", new HashMap<>(), Collections.emptyMap());
    FactModelTree nested2 = new FactModelTree("tNested2", "", new HashMap<>(), Collections.emptyMap());
    String propertyType = String.class.getCanonicalName();
    String propertyName = "stingProperty";
    nested1.addSimpleProperty(propertyName, new FactModelTree.PropertyTypeName(propertyType));
    String propertyType2 = Boolean.class.getCanonicalName();
    String propertyName2 = "booleanProperty";
    nested2.addSimpleProperty(propertyName2, new FactModelTree.PropertyTypeName(propertyType2));
    hiddenFacts.put("tNested", nested1);
    hiddenFacts.put("tNested2", nested2);
    dmnSimulationCreationStrategy.addFactMapping(factMappingExtractorMock, factModelTree, new ArrayList<>(), hiddenFacts);
    verify(factMappingExtractorMock, times(1)).getFactMapping(eq(nested1), eq(propertyName), eq(Arrays.asList("myFact", "nestedProperty")), eq(propertyType));
    verify(factMappingExtractorMock, times(1)).getFactMapping(eq(nested2), eq(propertyName2), eq(Arrays.asList("myFact", "nestedProperty2")), eq(propertyType2));
    verify(factMappingExtractorMock, times(2)).getFactMapping(any(), any(), any(), any());
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 5 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method addToScenarioRecursive.

@Test
public void addToScenarioRecursive() {
    FactMapping factMappingMock = mock(FactMapping.class);
    DMNSimulationSettingsCreationStrategy.FactMappingExtractor factMappingExtractorMock = mock(DMNSimulationSettingsCreationStrategy.FactMappingExtractor.class);
    when(factMappingExtractorMock.getFactMapping(any(), anyString(), any(), anyString())).thenReturn(factMappingMock);
    Map<String, FactModelTree> hiddenFacts = new HashMap<>();
    FactModelTree factModelTree = new FactModelTree("myFact", "", new HashMap<>(), Collections.emptyMap());
    factModelTree.addExpandableProperty("recursiveProperty", "recursive");
    String propertyType = String.class.getCanonicalName();
    String propertyName = "simpleProperty";
    factModelTree.addSimpleProperty(propertyName, new FactModelTree.PropertyTypeName(propertyType));
    hiddenFacts.put("recursive", factModelTree);
    dmnSimulationCreationStrategy.addFactMapping(factMappingExtractorMock, factModelTree, new ArrayList<>(), hiddenFacts);
    verify(factMappingExtractorMock, times(1)).getFactMapping(eq(factModelTree), eq(propertyName), eq(Arrays.asList("myFact", "recursiveProperty")), eq(propertyType));
    verify(factMappingExtractorMock, times(2)).getFactMapping(any(), any(), any(), any());
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Aggregations

FactMapping (org.drools.scenariosimulation.api.model.FactMapping)55 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)10 List (java.util.List)9 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 HashMap (java.util.HashMap)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)6 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)6 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)5 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)5 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 FactMappingValidationError (org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError)4 Before (org.junit.Before)4 Map (java.util.Map)3