protected void prepareRegisteredResource(Path path, Def registeredDef, DeploymentInfo deploymentInfo) throws Exception { when(defRegistry.getEntry(path)).thenReturn(registeredDef); if (registeredDef != null && deploymentInfo != null) { if (registeredDef instanceof DataSourceDef) { when(runtimeManager.getDataSourceDeploymentInfo(registeredDef.getUuid())).thenReturn((DataSourceDeploymentInfo) deploymentInfo); } else { when(runtimeManager.getDriverDeploymentInfo(registeredDef.getUuid())).thenReturn((DriverDeploymentInfo) deploymentInfo); } } }
protected void unDeploy(Def def) throws Exception { if (def instanceof DataSourceDef) { DataSourceDeploymentInfo deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(def.getUuid()); if (deploymentInfo != null) { runtimeManager.unDeployDataSource(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); } } else { DriverDeploymentInfo deploymentInfo = runtimeManager.getDriverDeploymentInfo(def.getUuid()); if (deploymentInfo != null) { runtimeManager.unDeployDriver(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); } } }
@Test public void testDelete() throws Exception { //current file String content = getExpectedDefString(); when(path.toURI()).thenReturn(FILE_URI); org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); when(ioService.readAllString(nioPath)).thenReturn(content); when(ioService.exists(nioPath)).thenReturn(true); when(moduleService.resolveModule(path)).thenReturn(module); when(runtimeManager.getDataSourceDeploymentInfo( getExpectedDef().getUuid())).thenReturn(dataSourceDeploymentInfo); when(runtimeManager.getDriverDeploymentInfo( getExpectedDef().getUuid())).thenReturn(driverDeploymentInfo); editorService.delete(path, COMMENT); //we wants that: //1) the file was deleted, and the definition was un-registered verify(ioService, times(1)).delete(eq(Paths.convert(path)), any(CommentedOption.class)); verify(optionsFactory, times(1)).makeCommentedOption(COMMENT); verify(defRegistry, times(1)).invalidateCache(path); //2) the definition was un-deployed, and 3) the delete notification was fired. verifyDeleteConditions(); }
/** * Verifies that the given definition has been un-deployed. */ protected void verifyUnDeployed(Def def) throws Exception { // the definition should have been un-deployed. if (def instanceof DataSourceDef) { DataSourceDeploymentInfo deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(def.getUuid()); // is deployed by construction assertNotNull(deploymentInfo); verify(runtimeManager, times(1)).unDeployDataSource(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); } else { DriverDeploymentInfo deploymentInfo = runtimeManager.getDriverDeploymentInfo(def.getUuid()); // is deployed by construction assertNotNull(deploymentInfo); verify(runtimeManager, times(1)).unDeployDriver(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); } }
context); if (def.getUuid() == null) { def.setUuid(UUIDGenerator.generateUUID());
public void delete(final Path path, final String comment) { checkNotNull("path", path); final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (ioService.exists(nioPath)) { String content = ioService.readAllString(Paths.convert(path)); D def = deserializeDef(content); Module module = moduleService.resolveModule(path); try { I deploymentInfo = readDeploymentInfo(def.getUuid()); if (deploymentInfo != null) { unDeploy(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); } serviceHelper.getDefRegistry().invalidateCache(path); ioService.delete(Paths.convert(path), optionsFactory.makeCommentedOption(comment)); fireDeleteEvent(def, module); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } } } }
final String content = serializeDef(editorContent.getDef()); I deploymentInfo = readDeploymentInfo(editorContent.getDef().getUuid()); if (deploymentInfo != null) { unDeploy(deploymentInfo,