@Before public void init() { simulation = new Simulation(); simulationDescriptor = simulation.getSimulationDescriptor(); scenario = simulation.addScenario(); factIdentifier = FactIdentifier.create("test fact", String.class.getCanonicalName()); expressionIdentifier = ExpressionIdentifier.create("test expression", FactMappingType.EXPECT); }
@Override public Range deleteCell(int rowIndex, int columnIndex) { FactMapping factMapping = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); simulation.getScenarioByIndex(rowIndex) .removeFactMappingValueByIdentifiers(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier()); return super.deleteCell(rowIndex, columnIndex); }
public static Map<Integer, Scenario> toScenarioMap(Simulation simulation) { List<Scenario> scenarios = simulation.getUnmodifiableScenarios(); Map<Integer, Scenario> indexToScenario = new HashMap<>(); for (int index = 0; index < scenarios.size(); index += 1) { indexToScenario.put(index + 1, scenarios.get(index)); } return indexToScenario; }
public Simulation cloneSimulation() { Simulation toReturn = new Simulation(); toReturn.getSimulationDescriptor().setType(simulationDescriptor.getType()); toReturn.getSimulationDescriptor().setDmnFilePath(simulationDescriptor.getDmnFilePath()); toReturn.getSimulationDescriptor().setDmoSession(simulationDescriptor.getDmoSession()); final List<FactMapping> originalFactMappings = this.simulationDescriptor.getUnmodifiableFactMappings(); for (int i = 0; i < originalFactMappings.size(); i++) { final FactMapping originalFactMapping = originalFactMappings.get(i); toReturn.simulationDescriptor.addFactMapping(i, originalFactMapping); } this.scenarios.forEach(scenario -> toReturn.scenarios.add(scenario.cloneScenario())); return toReturn; }
public AbstractScenarioRunner(KieContainer kieContainer, Simulation simulation, String fileName, Function<ClassLoader, ExpressionEvaluator> expressionEvaluatorFactory) { this(kieContainer, simulation.getSimulationDescriptor(), toScenarioMap(simulation), fileName, expressionEvaluatorFactory); }
private Simulation getSimulation() { Simulation toReturn = new Simulation(); SimulationDescriptor simulationDescriptor = toReturn.getSimulationDescriptor(); simulationDescriptor.setType(ScenarioSimulationModel.Type.RULE); simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX); simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION); Scenario scenario = toReturn.addScenario(); int row = toReturn.getUnmodifiableScenarios().indexOf(scenario); scenario.setDescription(null); // Add GIVEN Facts IntStream.range(2, 4).forEach(id -> { ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN); simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression); scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null); }); // Add EXPECT Facts IntStream.range(2, 4).forEach(id -> { id += 2; // This is to have consistent labels/names even when adding columns at runtime ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT); simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression); scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null); }); return toReturn; } }
doReturn(factMappingMock).when(simulationDescriptorMock).addFactMapping(anyInt(), anyString(), anyObject(), anyObject()); when(simulationMock.getSimulationDescriptor()).thenReturn(simulationDescriptorMock); when(gridCellMock.getValue()).thenReturn(gridCellValueMock); when(gridCellValueMock.getValue()).thenReturn(GRID_CELL_TEXT); when(simulationMock.addScenario(rowIndex)).thenReturn(scenarioMock); when(simulationMock.getScenarioByIndex(rowIndex)).thenReturn(scenarioMock); when(simulationMock.cloneScenario(rowIndex, rowIndex + 1)).thenReturn(scenarioMock); gridRows.add(gridRowMock); }); when(simulationMock.addScenario(ROW_COUNT)).thenReturn(scenarioMock); when(simulationMock.getScenarioByIndex(ROW_COUNT)).thenReturn(scenarioMock); when(simulationMock.cloneScenario(ROW_COUNT, ROW_COUNT + 1)).thenReturn(scenarioMock);
@Override public Simulation createSimulation(Path context, String dmnFilePath) throws Exception { final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath); Simulation toReturn = new Simulation(); SimulationDescriptor simulationDescriptor = toReturn.getSimulationDescriptor(); simulationDescriptor.setType(ScenarioSimulationModel.Type.DMN); simulationDescriptor.setDmnFilePath(dmnFilePath); Scenario scenario = createScenario(toReturn, simulationDescriptor); int row = toReturn.getUnmodifiableScenarios().indexOf(scenario); 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(); return aType.equals(bType) ? 0 : (Type.INPUT.equals(aType) ? -1 : 1); }).forEach(factModelTree -> { FactIdentifier factIdentifier = new FactIdentifier(factModelTree.getFactName(), factModelTree.getFactName()); FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, row, id, convert(factModelTree.getType()), simulationDescriptor, scenario); addToScenario(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues); }); return toReturn; }
@Test public void removeFactMappingByIndex() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMappingByIndex(0); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
public Scenario addScenario() { return addScenario(scenarios.size()); }
@Test public void removeFactMapping() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMapping(simulation.getSimulationDescriptor().getFactMappingByIndex(0)); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
protected void commonAddRow(int rowIndex) { Scenario scenario = simulation.addScenario(rowIndex); final SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); IntStream.range(1, getColumnCount()).forEach(columnIndex -> { final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).isPropertyAssigned() ? ScenarioSimulationEditorConstants.INSTANCE.insertValue() : ScenarioSimulationEditorConstants.INSTANCE.defineValidType(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))); }); updateIndexColumn(); }
@Test public void cloneScenarioTest() { Scenario clonedScenario = simulation.cloneScenario(0, 1); assertEquals(originalScenario.getDescription(), clonedScenario.getDescription()); assertEquals(originalScenario.getUnmodifiableFactMappingValues().size(), clonedScenario.getUnmodifiableFactMappingValues().size()); assertEquals(originalScenario, simulation.getScenarioByIndex(0)); assertEquals(clonedScenario, simulation.getScenarioByIndex(1)); assertNotEquals(originalScenario, clonedScenario); assertNotEquals(originalScenario.getUnmodifiableFactMappingValues().get(0), clonedScenario.getUnmodifiableFactMappingValues().get(0)); }
SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); String instanceTitle = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getTitle(); String propertyTitle = ((ScenarioGridColumn) column).getPropertyHeaderMetaData().getTitle(); final List<Scenario> scenarios = simulation.getUnmodifiableScenarios(); String placeHolder = ((ScenarioGridColumn) column).getPlaceHolder(); IntStream.range(0, scenarios.size())
public Scenario cloneScenario(int sourceIndex, int targetIndex) { if (sourceIndex < 0 || sourceIndex >= scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("SourceIndex out of range ").append(sourceIndex).toString()); } if (targetIndex < 0 || targetIndex > scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("TargetIndex out of range ").append(targetIndex).toString()); } Scenario scenarioByIndex = getScenarioByIndex(sourceIndex); Scenario clonedScenario = scenarioByIndex.cloneScenario(); scenarios.add(targetIndex, clonedScenario); return clonedScenario; }
@Before public void setup() { when(simulationMock.getSimulationDescriptor()).thenReturn(simulationDescriptorMock); IntStream.range(0, 4).forEach(index -> gridColumns.add(gridColumnMock)); GridData.Range range = new GridData.Range(FIRST_INDEX_LEFT, FIRST_INDEX_RIGHT - 1); when(scenarioSimulationEditorPresenterMock.getModel()).thenReturn(scenarioSimulationModelMock); scenarioSimulationContext.setScenarioSimulationEditorPresenter(scenarioSimulationEditorPresenterMock); when(simulationMock.cloneSimulation()).thenReturn(clonedSimulationMock); scenarioSimulationContext.getStatus().setSimulation(simulationMock); when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock);
/** * This method <i>duplicate</i> the row at the given index from both the grid <b>and</b> the underlying model * and insert just below the original one * @param rowIndex */ public void duplicateRow(int rowIndex, GridRow row) { checkSimulation(); int newRowIndex = rowIndex + 1; final Scenario toDuplicate = simulation.cloneScenario(rowIndex, newRowIndex); insertRowGridOnly(newRowIndex, row, toDuplicate); }
@Before public void setup() throws Exception { Set<Package> packages = new HashSet<>(); packages.add(new Package(path, path, path, path, path, "Test", "", "")); when(kieModuleService.resolveModule(any())).thenReturn(module); when(kieModuleService.resolvePackages(any(KieModule.class))).thenReturn(packages); when(ioService.exists(activatorPath)).thenReturn(false); when(kieModuleService.resolveModule(any())).thenReturn(module); when(module.getPom()).thenReturn(projectPom); when(projectPom.getGav()).thenReturn(gav); when(gav.getGroupId()).thenReturn("Test"); when(projectPom.getDependencies()).thenReturn(dependencies); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); when(mockedPackage.getPackageTestSrcPath()).thenReturn(path); when(scenarioSimulationBuilderMock.createSimulation(any(), any(), any())).thenReturn(new Simulation()); service.scenarioSimulationBuilder = scenarioSimulationBuilderMock; }
/** * This method <i>delete</i> the column at the given index from both the grid <b>and</b> the underlying model * @param columnIndex */ public void deleteColumn(int columnIndex) { checkSimulation(); final GridColumn<?> toDelete = getColumns().get(columnIndex); deleteColumn(toDelete); simulation.removeFactMappingByIndex(columnIndex); }
/** * This method <i>delete</i> the row at the given index from both the grid <b>and</b> the underlying model * @param rowIndex */ @Override public Range deleteRow(int rowIndex) { checkSimulation(); Range toReturn = super.deleteRow(rowIndex); simulation.removeScenarioByIndex(rowIndex); updateIndexColumn(); return toReturn; }