@Test public void refreshErrorsRow() { FactMappingValue factMappingValue = mock(FactMappingValue.class); when(factMappingValue.isError()).thenReturn(true); when(scenarioMock.getFactMappingValue(any(), any())).thenReturn(Optional.empty()); scenarioGridModel.refreshErrorsRow(0); verify(gridCellMock, times(6)).setErrorMode(false); when(scenarioMock.getFactMappingValue(any(), any())).thenReturn(Optional.of(factMappingValue)); scenarioGridModel.refreshErrorsRow(0); verify(gridCellMock, times(6)).setErrorMode(true); } }
@Test public void refreshErrorsTest() { scenarioGridModel.refreshErrors(); verify(gridCellMock, times(24)).setErrorMode(eq(true)); reset(gridCellMock); when(factMappingValueMock.isError()).thenReturn(false); scenarioGridModel.refreshErrors(); verify(gridCellMock, times(24)).setErrorMode(eq(false)); }
protected void refreshErrorsRow(int rowIndex) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); Scenario scenarioByIndex = simulation.getScenarioByIndex(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 = scenarioByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); if (factMappingValue.isPresent()) { cell.setErrorMode(factMappingValue.get().isError()); } else { cell.setErrorMode(false); } }); }
@Test public void executeTest() { when(registryContext.lookup(KieSession.class)).thenReturn(kieSession); Function<Object, ResultWrapper> alwaysMatchFunction = ResultWrapper::createResult; ValidateFactCommand validateFactCommand = new ValidateFactCommand(asList(new FactCheckerHandle(String.class, alwaysMatchFunction, scenarioResult))); when(kieSession.getObjects(any(ObjectFilter.class))).thenReturn(Collections.singleton(null)); validateFactCommand.execute(registryContext); verify(scenarioResult, times(1)).setResult(anyBoolean()); reset(scenarioResult); boolean expectedResult = true; when(kieSession.getObjects(any(ObjectFilter.class))).thenReturn(Collections.emptyList()); when(scenarioResult.getFactMappingValue()).thenReturn(factMappingValue); when(factMappingValue.isError()).thenReturn(expectedResult); validateFactCommand.execute(registryContext); verify(scenarioResult, times(0)).setResult(expectedResult); } }
@Test public void getParamsForBeanTest() { List<FactMappingValue> factMappingValues = new ArrayList<>(); FactMappingValue factMappingValue = new FactMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, "NOT PARSABLE"); factMappingValues.add(factMappingValue); try { runnerHelper.getParamsForBean(simulation.getSimulationDescriptor(), disputeFactIdentifier, factMappingValues, classLoader, expressionEvaluator); fail(); } catch (ScenarioException ignored) { } Assert.assertTrue(factMappingValue.isError()); }
when(factMappingValueMock.isError()).thenReturn(true);
mock(ExpressionEvaluator.class), requestContext); assertTrue(newScenarioRunnerData.getResults().get(0).getFactMappingValue().isError());