public ScenarioSimulationModel unmarshal(final String rawXml, boolean migrate) { if (rawXml == null) { return new ScenarioSimulationModel(); } if (rawXml.trim().equals("")) { return new ScenarioSimulationModel(); } String xml = migrate ? migrateIfNecessary(rawXml) : rawXml; return internalUnmarshal(xml); }
@Test(expected = FileAlreadyExistsException.class) public void createFileExists() throws Exception { doReturn(true).when(ioService).exists(any()); ScenarioSimulationModel model = new ScenarioSimulationModel(); service.create(this.path, "test.scesim", model, "Commit comment"); }
@Test public void runScenario() throws Exception { doReturn("test user").when(user).getIdentifier(); final Path path = mock(Path.class); final ScenarioSimulationModel model = new ScenarioSimulationModel(); service.runScenario(path, model); verify(scenarioRunnerService).runTest("test user", path, model); }
@Test public void runTest() throws Exception { when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock); when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock); ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel(); scenarioSimulationModel.setSimulation(new RULESimulationCreationStrategy().createSimulation(this.path, "default")); scenarioRunnerService.runTest("test", mock(Path.class), scenarioSimulationModel); verify(defaultTestResultMessageEventMock).fire(any()); }
@Test public void saveAndRename() throws Exception { final Metadata metadata = mock(Metadata.class); final ScenarioSimulationModel model = new ScenarioSimulationModel(); service.saveAndRename(path, "newName.scesim", metadata, model, "comment"); verify(saveAndRenameService).saveAndRename(path, "newName.scesim", metadata, model, "comment"); }
public void setup() { // Mock FileMenuBuilder usage since we cannot use FileMenuBuilderImpl either when(fileMenuBuilderMock.addSave(any(MenuItem.class))).thenReturn(fileMenuBuilderMock); when(fileMenuBuilderMock.addCopy(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(fileMenuBuilderMock); when(fileMenuBuilderMock.addRename(any(Command.class))).thenReturn(fileMenuBuilderMock); when(fileMenuBuilderMock.addDelete(any(ObservablePath.class))).thenReturn(fileMenuBuilderMock); when(fileMenuBuilderMock.addValidate(any(Command.class))).thenReturn(fileMenuBuilderMock); when(fileMenuBuilderMock.addNewTopLevelMenu(any(MenuItem.class))).thenReturn(fileMenuBuilderMock); when(versionRecordManagerMock.getCurrentPath()).thenReturn(observablePathMock); when(versionRecordManagerMock.getPathToLatest()).thenReturn(observablePathMock); when(workbenchContextMock.getActiveWorkspaceProject()).thenReturn(Optional.empty()); when(gridContextMenuMock.getView()).thenReturn(gridContextMenuViewMock); when(headerGivenContextMenuMock.getView()).thenReturn(headerContextMenuViewMock); this.model = new ScenarioSimulationModel(); model.setSimulation(getSimulation(ScenarioSimulationModel.Type.RULE, "default")); this.content = new ScenarioSimulationModelContent(model, overviewMock, mock(PackageDataModelOracleBaselinePayload.class)); when(scenarioSimulationServiceMock.loadContent(observablePathMock)).thenReturn(content); }
@Test public void save() throws Exception { final Path returnPath = service.save(this.path, new ScenarioSimulationModel(), new Metadata(), "Commit comment"); assertNotNull(returnPath); verify(ioService).write(any(org.uberfire.java.nio.file.Path.class), anyString(), anyMap(), any(CommentedOption.class)); }
@Test public void versionAttributeExists() throws Exception { final String xml = instance.marshal(new ScenarioSimulationModel()); assertTrue(xml.startsWith("<ScenarioSimulationModel version=\"" + ScenarioSimulationXMLPersistence.getCurrentVersion() + "\">")); }
@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 noFQCNUsed() throws Exception { final ScenarioSimulationModel simulationModel = new ScenarioSimulationModel(); simulationModel.getImports().addImport(new Import("org.test.Test")); final String xml = instance.marshal(simulationModel); assertFalse(xml.contains("org.drools.workbench.screens.scenariosimulation.model")); assertFalse(xml.contains("org.kie.soup.project.datamodel.imports")); }
@Override public void create(final Package pkg, final String baseFileName, final NewResourcePresenter presenter) { final ScenarioSimulationModel.Type selectedType = sourceTypeSelector.getSelectedType(); String value; switch (selectedType) { case DMN: value = uploadWidget.getSelectedPath(); if (value == null || value.isEmpty()) { return; } break; case RULE: default: value = "default"; } busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving()); scenarioSimulationService.call(getSuccessCallback(presenter), new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)).create(pkg.getPackageTestResourcesPath(), buildFileName(baseFileName, resourceType), new ScenarioSimulationModel(), "", selectedType, value); }
when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock); when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock); ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel(); scenarioSimulationModel.setSimulation(new RULESimulationCreationStrategy().createSimulation(this.path, "default")); Scenario scenario = scenarioSimulationModel.getSimulation().getScenarioByIndex(0);