Search in sources :

Example 6 with FactMappingValue

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

the class AbstractRunnerHelperTest method getResultWrapper.

@Test
public void getResultWrapper() {
    ExpressionEvaluator expressionEvaluatorMock = mock(ExpressionEvaluator.class);
    Object resultRaw = "test";
    Object expectedResultRaw = "";
    String collectionWrongValue = "value";
    String collectionValuePath = "Item #: 1";
    String genericErrorMessage = "errorMessage";
    // case 1: succeed
    when(expressionEvaluatorMock.evaluateUnaryExpression(any(), any(), any(Class.class))).thenReturn(ExpressionEvaluatorResult.ofSuccessful());
    ValueWrapper valueWrapper = abstractRunnerHelper.getResultWrapper(String.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, String.class);
    assertTrue(valueWrapper.isValid());
    assertNull(valueWrapper.getCollectionPathToValue());
    // case 2: failed with actual value
    when(expressionEvaluatorMock.evaluateUnaryExpression(any(), any(), any(Class.class))).thenReturn(ExpressionEvaluatorResult.ofFailed());
    valueWrapper = abstractRunnerHelper.getResultWrapper(String.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, String.class);
    assertFalse(valueWrapper.isValid());
    assertEquals(resultRaw, valueWrapper.getValue());
    assertNull(valueWrapper.getCollectionPathToValue());
    // case 3: failed without actual value (list)
    valueWrapper = abstractRunnerHelper.getResultWrapper(List.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, List.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertTrue(valueWrapper.getCollectionPathToValue().isEmpty());
    assertNull(valueWrapper.getValue());
    // case 4: failed without actual value (map)
    valueWrapper = abstractRunnerHelper.getResultWrapper(Map.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, Map.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertTrue(valueWrapper.getCollectionPathToValue().isEmpty());
    assertNull(valueWrapper.getValue());
    // case 5: failed with wrong value (list)
    ExpressionEvaluatorResult result = ExpressionEvaluatorResult.ofFailed(collectionWrongValue, collectionValuePath);
    when(expressionEvaluatorMock.evaluateUnaryExpression(any(), any(), any(Class.class))).thenReturn(result);
    valueWrapper = abstractRunnerHelper.getResultWrapper(List.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, List.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertEquals(1, valueWrapper.getCollectionPathToValue().size());
    assertEquals(collectionWrongValue, valueWrapper.getValue());
    // case 6: failed without actual value (map)
    valueWrapper = abstractRunnerHelper.getResultWrapper(Map.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, Map.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertEquals(1, valueWrapper.getCollectionPathToValue().size());
    assertEquals(collectionWrongValue, valueWrapper.getValue());
    // case 7: failed without wrong value (list)
    result = ExpressionEvaluatorResult.ofFailed(null, collectionValuePath);
    when(expressionEvaluatorMock.evaluateUnaryExpression(any(), any(), any(Class.class))).thenReturn(result);
    valueWrapper = abstractRunnerHelper.getResultWrapper(List.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, List.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertEquals(1, valueWrapper.getCollectionPathToValue().size());
    assertNull(valueWrapper.getValue());
    // case 8: failed without actual value (map)
    valueWrapper = abstractRunnerHelper.getResultWrapper(Map.class.getCanonicalName(), new FactMappingValue(), expressionEvaluatorMock, expectedResultRaw, resultRaw, Map.class);
    assertFalse(valueWrapper.getErrorMessage().isPresent());
    assertEquals(1, valueWrapper.getCollectionPathToValue().size());
    assertNull(valueWrapper.getValue());
    // case 9: failed with generic exception
    when(expressionEvaluatorMock.evaluateUnaryExpression(any(), any(), any(Class.class))).thenThrow(new IllegalArgumentException(genericErrorMessage));
    FactMappingValue expectedResult5 = new FactMappingValue();
    valueWrapper = abstractRunnerHelper.getResultWrapper(Map.class.getCanonicalName(), expectedResult5, expressionEvaluatorMock, expectedResultRaw, resultRaw, Map.class);
    assertEquals(genericErrorMessage, valueWrapper.getErrorMessage().get());
    assertEquals(genericErrorMessage, expectedResult5.getExceptionMessage());
}
Also used : ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ExpressionEvaluatorResult(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult) List(java.util.List) BaseExpressionEvaluator(org.drools.scenariosimulation.backend.expression.BaseExpressionEvaluator) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) Map(java.util.Map) Test(org.junit.Test)

Example 7 with FactMappingValue

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

the class AbstractRunnerHelperTest method isFactMappingValueToSkip.

@Test
public void isFactMappingValueToSkip() {
    FactIdentifier factIdentifier = FactIdentifier.create("MyInstance", String.class.getCanonicalName());
    ExpressionIdentifier expressionIdentifier = ExpressionIdentifier.create("MyProperty", FactMappingType.GIVEN);
    FactMappingValue factMappingValueWithValidValue = new FactMappingValue(factIdentifier, expressionIdentifier, VALUE);
    assertFalse(abstractRunnerHelper.isFactMappingValueToSkip(factMappingValueWithValidValue));
    FactMappingValue factMappingValueWithoutValue = new FactMappingValue(factIdentifier, expressionIdentifier, null);
    assertTrue(abstractRunnerHelper.isFactMappingValueToSkip(factMappingValueWithoutValue));
}
Also used : ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Test(org.junit.Test)

Example 8 with FactMappingValue

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

the class AbstractScesimGridModelTest method refreshErrorsRow.

@Test
public void refreshErrorsRow() {
    int expectedCalls = abstractScesimGridModelSpy.getColumnCount();
    FactMappingValue factMappingValue = mock(FactMappingValue.class);
    when(factMappingValue.getStatus()).thenReturn(FactMappingValueStatus.FAILED_WITH_ERROR);
    when(scenarioMock.getFactMappingValue(any(), any())).thenReturn(Optional.empty());
    abstractScesimGridModelSpy.refreshErrorsRow(0);
    verify(gridCellMock, times(expectedCalls)).setErrorMode(false);
    when(scenarioMock.getFactMappingValue(any(), any())).thenReturn(Optional.of(factMappingValue));
    abstractScesimGridModelSpy.refreshErrorsRow(0);
    verify(gridCellMock, times(expectedCalls)).setErrorMode(true);
}
Also used : FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 9 with FactMappingValue

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

the class AbstractScesimGridModel method refreshErrorsRow.

protected void refreshErrorsRow(int rowIndex) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    IntStream.range(0, getColumnCount()).forEach(columnIndex -> {
        ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex);
        if (cell == null) {
            return;
        }
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier());
        if (factMappingValue.isPresent()) {
            cell.setErrorMode(FactMappingValueStatus.SUCCESS != factMappingValue.get().getStatus());
        } else {
            cell.setErrorMode(false);
        }
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

Example 10 with FactMappingValue

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

the class AbstractScesimGridModel method resetError.

/**
 * It resets the <code>FactMappingValue</code> status for a specific CELL
 * @param rowIndex
 * @param columnIndex
 */
public void resetError(int rowIndex, int columnIndex) {
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMapping);
    factMappingValue.ifPresent(FactMappingValue::resetStatus);
    refreshErrors();
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

Aggregations

FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)24 Test (org.junit.Test)15 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)9 ArrayList (java.util.ArrayList)7 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)7 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)7 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)7 ScenarioResult (org.drools.scenariosimulation.backend.runner.model.ScenarioResult)7 ScenarioExpect (org.drools.scenariosimulation.backend.runner.model.ScenarioExpect)6 ValueWrapper (org.drools.scenariosimulation.backend.runner.model.ValueWrapper)6 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)5 InstanceGiven (org.drools.scenariosimulation.backend.runner.model.InstanceGiven)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Background (org.drools.scenariosimulation.api.model.Background)4 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)4 Collectors.toList (java.util.stream.Collectors.toList)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 ExpressionEvaluatorResult (org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult)3