@Override protected List<SimulationWithFileName> getChildren() { return getResources().map(elem -> { try { String rawFile = new Scanner(new File(elem)).useDelimiter("\\Z").next(); return new SimulationWithFileName(getXmlReader().unmarshal(rawFile).getSimulation(), elem); } catch (FileNotFoundException e) { throw new ScenarioException("File not found, this should not happen: " + elem, e); } }).collect(Collectors.toList()); }
@Override public ScenarioSimulationModel runTest(final String identifier, final Path path, final ScenarioSimulationModel model) { KieContainer kieContainer = getKieContainer(path); Runner scenarioRunner = getOrCreateRunnerSupplier(model.getSimulation()) .apply(kieContainer, model.getSimulation()); final List<Failure> failures = new ArrayList<>(); final List<Failure> failureDetails = new ArrayList<>(); Result result = runWithJunit(scenarioRunner, failures, failureDetails); defaultTestResultMessageEvent.fire( new TestResultMessage( identifier, result.getRunCount(), result.getRunTime(), failures)); return model; }
protected SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) { SortedMap<String, FactModelTree> toReturn = new TreeMap<>(); // map instance name to base class if (model != null) { final SimulationDescriptor simulationDescriptor = model.getSimulation().getSimulationDescriptor(); simulationDescriptor.getUnmodifiableFactMappings() .stream() .filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())) .forEach(factMapping -> { String dataObjectName = factMapping.getFactIdentifier().getClassName(); if (dataObjectName.contains(".")) { dataObjectName = dataObjectName.substring(dataObjectName.lastIndexOf(".") + 1); } final String instanceName = factMapping.getFactAlias(); if (!instanceName.equals(dataObjectName)) { final FactModelTree factModelTree = sourceMap.get(dataObjectName); if (factModelTree != null) { toReturn.put(instanceName, factModelTree); } } }); } return toReturn; }
@Before public void setup() { when(xmlReaderMock.unmarshal(any())).thenReturn(scenarioSimulationModelMock); when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock); }
protected void refreshModelContent(ScenarioSimulationModel newModel) { this.model = newModel; final Simulation simulation = newModel.getSimulation(); view.refreshContent(simulation); context.getStatus().setSimulation(simulation); scenarioSimulationDocksHandler.expandTestResultsDock(); }
@Test public void populateRightPanel() { ScenarioSimulationModelContent scenarioSimulationModelContentMock = mock(ScenarioSimulationModelContent.class); ScenarioSimulationModel scenarioSimulationModel = mock(ScenarioSimulationModel.class); when(scenarioSimulationModelContentMock.getModel()).thenReturn(scenarioSimulationModel); Simulation simulationMock = mock(Simulation.class); when(scenarioSimulationModel.getSimulation()).thenReturn(simulationMock); SimulationDescriptor simulationDescriptorMock = mock(SimulationDescriptor.class); when(simulationMock.getSimulationDescriptor()).thenReturn(simulationDescriptorMock); dmnDataManagementStrategy.manageScenarioSimulationModelContent(mock(ObservablePath.class), scenarioSimulationModelContentMock); dmnDataManagementStrategy.populateRightPanel(mock(RightPanelView.Presenter.class), mock(ScenarioGridModel.class)); verify(dmnTypeServiceMock, times(1)).retrieveType(any(), anyString()); }
@Override public Function<String, String> from1_2to1_3() { return rawXml -> { ScenarioSimulationXMLPersistence xmlPersistence = ScenarioSimulationXMLPersistence.getInstance(); ScenarioSimulationModel model = xmlPersistence.unmarshal(rawXml, false); for (FactMapping factMapping : model.getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { factMapping.getExpressionElements().add(0, new ExpressionElement(factMapping.getFactIdentifier().getName())); } return xmlPersistence.marshal(model).replaceAll("<ScenarioSimulationModel version=\"1.2\">", "<ScenarioSimulationModel version=\"1.3\">"); }; } }
@Test public void refreshModelContent() { when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock); presenter.refreshModelContent(scenarioSimulationModelMock); assertEquals(scenarioSimulationModelMock, presenter.getModel()); verify(scenarioSimulationViewMock, times(1)).refreshContent(eq(simulationMock)); verify(statusMock, times(1)).setSimulation(eq(simulationMock)); }
@Test public void createRULEScenario() throws Exception { doReturn(false).when(ioService).exists(any()); ScenarioSimulationModel model = new ScenarioSimulationModel(); assertNull(model.getSimulation()); final Path returnPath = service.create(this.path, "test.scesim", model, "Commit comment", ScenarioSimulationModel.Type.RULE, "default"); assertNotNull(returnPath); assertNotNull(model.getSimulation()); verify(ioService, times(2)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), any(CommentedOption.class)); }
@Test public void createDMNScenario() throws Exception { doReturn(false).when(ioService).exists(any()); ScenarioSimulationModel model = new ScenarioSimulationModel(); assertNull(model.getSimulation()); final Path returnPath = service.create(this.path, "test.scesim", model, "Commit comment", ScenarioSimulationModel.Type.DMN, "test"); assertNotNull(returnPath); assertNotNull(model.getSimulation()); verify(ioService, times(2)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), any(CommentedOption.class)); }
@Test public void unmarshalDMN() throws Exception { String toUnmarshal = getFileContent("scesim-dmn.scesim"); final ScenarioSimulationModel retrieved = ScenarioSimulationXMLPersistence.getInstance().unmarshal(toUnmarshal); assertEquals(retrieved.getSimulation().getSimulationDescriptor().getType(), ScenarioSimulationModel.Type.DMN); assertNotNull(retrieved.getSimulation().getSimulationDescriptor().getDmnFilePath()); assertNull(retrieved.getSimulation().getSimulationDescriptor().getDmoSession()); }
@Override public void populateRightPanel(final RightPanelView.Presenter rightPanelPresenter, final ScenarioGridModel scenarioGridModel) { String dmnFilePath = model.getSimulation().getSimulationDescriptor().getDmnFilePath(); if(factModelTreeHolder.getFactModelTuple() != null) { getSuccessCallback(rightPanelPresenter).callback(factModelTreeHolder.getFactModelTuple()); } else { dmnTypeService.call(getSuccessCallback(rightPanelPresenter), getErrorCallback(rightPanelPresenter)) .retrieveType(currentPath, dmnFilePath); } }
@Test public void unmarshalRULE() throws Exception { String toUnmarshal = getFileContent("scesim-rule.scesim"); final ScenarioSimulationModel retrieved = ScenarioSimulationXMLPersistence.getInstance().unmarshal(toUnmarshal); assertEquals(retrieved.getSimulation().getSimulationDescriptor().getType(), ScenarioSimulationModel.Type.RULE); assertNotNull(retrieved.getSimulation().getSimulationDescriptor().getDmoSession()); assertNull(retrieved.getSimulation().getSimulationDescriptor().getDmnFilePath()); }
@Test public void migrateIfNecessary_1_2_to_1_3() throws Exception { String toMigrate = getFileContent("scesim-1-2.scesim"); String migrated = instance.migrateIfNecessary(toMigrate); assertTrue(toMigrate.contains("<ScenarioSimulationModel version=\"1.2\">")); assertFalse(migrated.contains("<ScenarioSimulationModel version=\"1.2\">")); for (FactMapping factMapping : instance.unmarshal(migrated, false).getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { assertTrue(factMapping.getExpressionElements().size() >= 1); } }
ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel(); scenarioSimulationModel.setSimulation(new RULESimulationCreationStrategy().createSimulation(this.path, "default")); Scenario scenario = scenarioSimulationModel.getSimulation().getScenarioByIndex(0); scenario.setDescription("Test Scenario"); String errorMessage = "Test Error";
when(simulationMock.cloneSimulation()).thenReturn(clonedSimulationMock); scenarioSimulationContext.getStatus().setSimulation(simulationMock); when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock); when(scenarioCommandRegistryMock.undo(scenarioSimulationContext)).thenReturn(CommandResultBuilder.SUCCESS); when(scenarioCommandRegistryMock.redo(scenarioSimulationContext)).thenReturn(CommandResultBuilder.SUCCESS);
private RemoteCallback<ScenarioSimulationModelContent> getModelSuccessCallback() { return content -> { //Path is set to null when the Editor is closed (which can happen before async calls complete). if (versionRecordManager.getCurrentPath() == null) { return; } packageName = content.getDataModel().getPackageName(); resetEditorPages(content.getOverview()); if(ScenarioSimulationModel.Type.RULE.equals(content.getModel().getSimulation().getSimulationDescriptor().getType())) { dataManagementStrategy = new DMODataManagementStrategy(oracleFactory); } else { dataManagementStrategy = new DMNDataManagementStrategy(dmnTypeService); } dataManagementStrategy.manageScenarioSimulationModelContent(versionRecordManager.getCurrentPath(), content); populateRightPanel(); model = content.getModel(); if (dataManagementStrategy instanceof DMODataManagementStrategy) { importsWidget.setContent(((DMODataManagementStrategy) dataManagementStrategy).getOracle(), model.getImports(), isReadOnly); addImportsTab(importsWidget); } baseView.hideBusyIndicator(); view.setContent(model.getSimulation()); setOriginalHash(getJsonModel(model).hashCode()); }; }