public C loadContent(final Path path) { checkNotNull("path", path); C editorContent = newContent(); String content = ioService.readAllString(Paths.convert(path)); D def = deserializeDef(content); editorContent.setDef(def); editorContent.setModule(moduleService.resolveModule(path)); return editorContent; }
try { final D originalDef = deserializeDef(ioService.readAllString(Paths.convert(path))); final String content = serializeDef(editorContent.getDef()); I deploymentInfo = readDeploymentInfo(editorContent.getDef().getUuid()); if (deploymentInfo != null) { unDeploy(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); deploy(editorContent.getDef(), DeploymentOptions.create()); !originalDef.getName().equals(editorContent.getDef().getName())) { editorContent.getDef().getName())); editorContent.getDef()); fireUpdateEvent(editorContent.getDef(), editorContent.getModule(), originalDef); } catch (Exception e) {
@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(); }