@Override public LayoutTemplate getLayoutTemplate(Path perspectivePath) { LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(perspectivePath, PluginType.PERSPECTIVE_LAYOUT); if (layoutEditorModel.isEmptyLayout()) { return new LayoutTemplate(layoutEditorModel.getName(), LayoutTemplate.Style.PAGE); } return layoutServices.convertLayoutFromString(layoutEditorModel.getLayoutEditorModel()); }
private LayoutEditorModel loadLayoutEditor(String pluginName, org.uberfire.backend.vfs.Path path, PluginType type) { final Path path1 = getLayoutEditorPath(getPluginPath(pluginName), type.toString().toLowerCase()); if (getIoService().exists(path1)) { String fileContent = getIoService().readAllString(path1); return new LayoutEditorModel(pluginName, PluginType.PERSPECTIVE_LAYOUT, path, fileContent); } return new LayoutEditorModel(pluginName, PluginType.PERSPECTIVE_LAYOUT, path, null).emptyLayout(); }
@Test public void testRename() { Path result = perspectiveServices.rename(path, "newName", ""); ArgumentCaptor<LayoutEditorModel> layoutModelArg = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).saveLayout(layoutModelArg.capture(), anyString()); LayoutEditorModel layoutModelCopy = layoutModelArg.getValue(); assertEquals(layoutModelCopy.getName(), "newName"); assertEquals(layoutModelCopy.getPath(), result); }
@Override public org.uberfire.backend.vfs.Path saveLayout(LayoutEditorModel plugin, String commitMessage) { final Path pluginPath = convert(plugin.getPath()); final boolean isNewPlugin = !getIoService().exists(pluginPath); try { getIoService().startBatch(fileSystem, commentedOption(commitMessage)); final Path itemsPath = getLayoutEditorPath(getPluginPath(plugin.getName()), plugin.getType().toString().toLowerCase()); getIoService().write(itemsPath, plugin.getLayoutEditorModel()); updatePlugin(pluginPath, plugin, isNewPlugin); } finally { getIoService().endBatch(); } return plugin.getPath(); }
@Test public void testLoadEmptyLayout() { Path pluginPath = createPlugin("emptyLayout", PluginType.PERSPECTIVE_LAYOUT, null); LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(pluginPath, PluginType.PERSPECTIVE_LAYOUT); assertEquals(layoutEditorModel.getName(), "emptyLayout"); assertEquals(layoutEditorModel.getPath(), pluginPath); assertTrue(layoutEditorModel.isEmptyLayout()); }
@Test public void testCreate() { perspectiveServices.createNewPerspective("test", LayoutTemplate.Style.FLUID); ArgumentCaptor<LayoutEditorModel> arg1 = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).createNewPlugin("test", PluginType.PERSPECTIVE_LAYOUT); verify(pluginServices).saveLayout(arg1.capture(), eq("Perspective 'test' check-in")); LayoutEditorModel layoutEditorModel = arg1.getValue(); assertEquals(layoutEditorModel.getName(), "test"); }
@Override public Path saveLayoutTemplate(Path perspectivePath, LayoutTemplate layoutTemplate, String commitMessage) { String layoutModel = layoutServices.convertLayoutToString(layoutTemplate); LayoutEditorModel plugin = new LayoutEditorModel(layoutTemplate.getName(), PluginType.PERSPECTIVE_LAYOUT, perspectivePath, layoutModel); pluginServices.saveLayout(plugin, commitMessage); return perspectivePath; }
@Override public LayoutTemplate getLayoutTemplate(Plugin perspectivePlugin) { LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(perspectivePlugin.getPath(), PluginType.PERSPECTIVE_LAYOUT); return layoutServices.convertLayoutFromString(layoutEditorModel.getLayoutEditorModel()); }
@Test public void testCopy() { Path result = perspectiveServices.copy(path, "newName", ""); ArgumentCaptor<LayoutEditorModel> layoutModelArg = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).saveLayout(layoutModelArg.capture(), anyString()); LayoutEditorModel layoutModelCopy = layoutModelArg.getValue(); assertEquals(layoutModelCopy.getName(), "newName"); assertEquals(layoutModelCopy.getPath(), result); }
@Test public void testLoadEmptyLayout() { Path pluginPath = createPlugin("emptyLayout", PluginType.PERSPECTIVE_LAYOUT, null); LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(pluginPath, PluginType.PERSPECTIVE_LAYOUT); assertEquals(layoutEditorModel.getName(), "emptyLayout"); assertEquals(layoutEditorModel.getPath(), pluginPath); assertTrue(layoutEditorModel.isEmptyLayout()); }
@Test public void testCreate() { perspectiveServices.createNewPerspective("test", LayoutTemplate.Style.FLUID); ArgumentCaptor<LayoutEditorModel> arg1 = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).createNewPlugin("test", PluginType.PERSPECTIVE_LAYOUT); verify(pluginServices).saveLayout(arg1.capture(), eq("Perspective 'test' check-in")); LayoutEditorModel layoutEditorModel = arg1.getValue(); assertEquals(layoutEditorModel.getName(), "test"); }
@Override public Path saveLayoutTemplate(Path perspectivePath, LayoutTemplate layoutTemplate, String commitMessage) { String layoutModel = layoutServices.convertLayoutToString(layoutTemplate); LayoutEditorModel plugin = new LayoutEditorModel(layoutTemplate.getName(), PluginType.PERSPECTIVE_LAYOUT, perspectivePath, layoutModel); pluginServices.saveLayout(plugin, commitMessage); return perspectivePath; }
@Override public LayoutTemplate getLayoutTemplate(Plugin perspectivePlugin) { LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(perspectivePlugin.getPath(), PluginType.PERSPECTIVE_LAYOUT); return layoutServices.convertLayoutFromString(layoutEditorModel.getLayoutEditorModel()); }
@Test public void testRename() { Path result = perspectiveServices.rename(path, "newName", ""); ArgumentCaptor<LayoutEditorModel> layoutModelArg = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).saveLayout(layoutModelArg.capture(), anyString()); LayoutEditorModel layoutModelCopy = layoutModelArg.getValue(); assertEquals(layoutModelCopy.getName(), "newName"); assertEquals(layoutModelCopy.getPath(), result); }
@Override public LayoutTemplate getLayoutTemplate(Path perspectivePath) { LayoutEditorModel layoutEditorModel = pluginServices.getLayoutEditor(perspectivePath, PluginType.PERSPECTIVE_LAYOUT); if (layoutEditorModel.isEmptyLayout()) { return new LayoutTemplate(layoutEditorModel.getName(), LayoutTemplate.Style.PAGE); } return layoutServices.convertLayoutFromString(layoutEditorModel.getLayoutEditorModel()); }
@Before public void setup() { LayoutEditorModel layoutEditorModel = new LayoutEditorModel("layout", PluginType.PERSPECTIVE_LAYOUT, path2, "").emptyLayout(); when(pluginServices.createNewPlugin(anyString(), any())).thenReturn(plugin); when(plugin.getPath()).thenReturn(path); when(pluginServices.copy(any(), anyString(), anyString())).thenReturn(path2); when(pluginServices.copy(any(), anyString(), any(), anyString())).thenReturn(path2); when(pluginServices.rename(any(), anyString(), anyString())).thenReturn(path2); when(pluginServices.getLayoutEditor(eq(path2), eq(PluginType.PERSPECTIVE_LAYOUT))).thenReturn(layoutEditorModel); perspectiveServices = spy(new PerspectiveServicesImpl(pluginServices, layoutServices, saveAndRenameService)); }
@Test public void testSave() { LayoutTemplate layoutTemplate = new LayoutTemplate("newName"); Path savedPath = perspectiveServices.saveLayoutTemplate(path, layoutTemplate, "save"); assertEquals(savedPath, path); ArgumentCaptor<LayoutEditorModel> layoutModelArg = ArgumentCaptor.forClass(LayoutEditorModel.class); ArgumentCaptor<String> commitArg = ArgumentCaptor.forClass(String.class); verify(pluginServices).saveLayout(layoutModelArg.capture(), commitArg.capture()); LayoutEditorModel layoutModelCopy = layoutModelArg.getValue(); assertEquals(layoutModelCopy.getName(), "newName"); assertEquals(commitArg.getValue(), "save"); }
private void setLayoutTemplateName(Path path, String newName, String comment) { LayoutTemplate layoutTemplate = getLayoutTemplate(path); layoutTemplate.setName(newName); String layoutModel = layoutServices.convertLayoutToString(layoutTemplate); LayoutEditorModel pluginCopy = new LayoutEditorModel(newName, PluginType.PERSPECTIVE_LAYOUT, path, layoutModel); pluginServices.saveLayout(pluginCopy, comment); }
@Test public void testCopy() { Path result = perspectiveServices.copy(path, "newName", ""); ArgumentCaptor<LayoutEditorModel> layoutModelArg = ArgumentCaptor.forClass(LayoutEditorModel.class); verify(pluginServices).saveLayout(layoutModelArg.capture(), anyString()); LayoutEditorModel layoutModelCopy = layoutModelArg.getValue(); assertEquals(layoutModelCopy.getName(), "newName"); assertEquals(layoutModelCopy.getPath(), result); }
@Before public void setup() { LayoutEditorModel layoutEditorModel = new LayoutEditorModel("layout", PluginType.PERSPECTIVE_LAYOUT, path2, "").emptyLayout(); when(pluginServices.createNewPlugin(anyString(), any())).thenReturn(plugin); when(plugin.getPath()).thenReturn(path); when(pluginServices.copy(any(), anyString(), anyString())).thenReturn(path2); when(pluginServices.copy(any(), anyString(), any(), anyString())).thenReturn(path2); when(pluginServices.rename(any(), anyString(), anyString())).thenReturn(path2); when(pluginServices.getLayoutEditor(eq(path2), eq(PluginType.PERSPECTIVE_LAYOUT))).thenReturn(layoutEditorModel); perspectiveServices = spy(new PerspectiveServicesImpl(pluginServices, layoutServices, saveAndRenameService)); }