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); } } }
public void processResourceUpdate(Path path, SessionInfo sessionInfo) { Def registeredDef; Def def = readDef(path); if (def != null) { registeredDef = serviceHelper.getDefRegistry().getEntry(path); if (registeredDef == null || !registeredDef.equals(def)) { updateDeployment(path, registeredDef, def, sessionInfo, ResourceChangeType.UPDATE); } } }
context); if (def.getUuid() == null) { def.setUuid(UUIDGenerator.generateUUID()); def); } catch (Exception e) { logger.error("It was not possible to create: " + def.getName(), e); ioService.endBatch(); DeploymentOptions.create()); } catch (Exception e1) { logger.error("It was not possible to create: " + def.getName(), e1); serviceHelper.getDefRegistry().invalidateCache(newPath);
final String content = serializeDef(editorContent.getDef()); I deploymentInfo = readDeploymentInfo(editorContent.getDef().getUuid()); if (deploymentInfo != null) { unDeploy(deploymentInfo, optionsFactory.makeCommentedOption(comment)); if (originalDef.getName() != null && !originalDef.getName().equals(editorContent.getDef().getName())) { editorContent.getDef().getName()));
@Test public void testSave() { //The name was not chanted. getExpectedContent().getDef().setName(getOriginalDef().getName()); String originalSource = getOriginalDefString(); //expected path when(path.toURI()).thenReturn(FILE_URI); org.uberfire.java.nio.file.Path targetNioPath = Paths.convert(path); when(ioService.readAllString(targetNioPath)).thenReturn(originalSource); when(moduleService.resolveModule(path)).thenReturn(module); editorService.save(path, getExpectedContent(), COMMENT); //we wants that: // 1) previous definition was un-registered and the expected file was saved verify(defRegistry, times(1)).invalidateCache(path); verify(ioService, times(1)).write(eq(targetNioPath), eq(getExpectedDefString()), any(CommentedOption.class)); verify(optionsFactory, times(1)).makeCommentedOption(COMMENT); // 2) the new definition was registered. verify(defRegistry, times(1)).setEntry(path, getExpectedDef()); // 3) the definition was deployed and 4) the notification was fired. verifySaveConditions(); }
getExpectedDef().getName())).thenReturn(renamedPath); org.uberfire.java.nio.file.Path renamedNioPath = Paths.convert(renamedPath);
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()); } } }
public void processResourceAdd(Path path, SessionInfo sessionInfo) { Def registeredDef; Def def = readDef(path); if (def != null) { registeredDef = serviceHelper.getDefRegistry().getEntry(path); if (registeredDef == null || !registeredDef.equals(def)) { updateDeployment(path, registeredDef, def, sessionInfo, ResourceChangeType.ADD); } } }
@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(); }
public void processResourceRename(Path originalPath, Path targetPath, SessionInfo sessionInfo) { Def originalDef; Def registeredDef; Def def = readDef(targetPath); if (def != null) { if ((originalDef = serviceHelper.getDefRegistry().getEntry(originalPath)) != null) { try { serviceHelper.getDefRegistry().invalidateCache(originalPath); unDeploy(originalDef); } catch (Exception e) { logger.error("Un-deployment failure for file: " + originalPath, e); } } registeredDef = serviceHelper.getDefRegistry().getEntry(targetPath); if (registeredDef == null || !registeredDef.equals(def)) { updateDeployment(targetPath, registeredDef, def, sessionInfo, ResourceChangeType.RENAME); } } }
/** * 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()); } }
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); } } } }