diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java index fd91242654..4b95f1110f 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java @@ -35,6 +35,8 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.framework.selection.Selection; +import org.phoebus.framework.selection.SelectionService; import org.phoebus.logbook.*; import org.phoebus.logbook.olog.ui.HelpViewer; import org.phoebus.logbook.olog.ui.LogbookUIPreferences; @@ -376,10 +378,14 @@ public void onChanged(Change change) { } /** - * Handler for Cancel button + * Handler for Cancel button. Note that any selections in the {@link SelectionService} are + * cleared to prevent next launch of {@link org.phoebus.logbook.olog.ui.menu.SendToLogBookApp} + * to pick them up. */ @FXML public void cancel() { + // Need to clear selections. + SelectionService.getInstance().clearSelection(""); ((LogEntryEditorStage) cancelButton.getScene().getWindow()).handleCloseEditor(isDirty, root); } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java index 6150d9794a..75e0a204d5 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java @@ -628,15 +628,6 @@ public void restore() { LOGGER.log(Level.WARNING, "Not all PVs could be restored for {0}: {1}. The following errors occured:\n{2}", new Object[] { s.getSnapshot().get().getName(), s.getSnapshot().get(), sb.toString() }); - - Platform.runLater(() -> { - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle(Messages.restoreErrorTitle); - alert.setContentText(sb.toString()); - alert.setHeaderText(Messages.restoreErrorContent); - DialogHelper.positionDialog(alert, snapshotTab.getTabPane(), -150, -150); - alert.showAndWait(); - }); } logSnapshotRestored(s.getSnapshot().get(), restoreFailed); }).start(); diff --git a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactory.java b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactory.java new file mode 100644 index 0000000000..ae88e3be8c --- /dev/null +++ b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactory.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 European Spallation Source ERIC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +package org.phoebus.applications.saveandrestore.logging; + +import org.phoebus.logbook.LogEntry; +import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder; +import org.phoebus.logbook.PropertyImpl; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.phoebus.logbook.LogEntryImpl.LogEntryBuilder.log; + +/** + * Adapts save/restore action information to a log entry. + */ +public class RestoreSnapshotActionAdapterFactory extends SaveSnapshotActionAdapterFactory { + + @Override + public Class getAdaptableObject() { + return RestoreSnapshotActionInfo.class; + } + + @Override + public List getAdapterList() { + return Arrays.asList(LogEntry.class); + } + + @Override + public Optional adapt(Object adaptableObject, Class adapterType) { + Map map = new HashMap<>(); + map.put("file", "file:/" + ((RestoreSnapshotActionInfo)adaptableObject).getSnapshotUniqueId() + "?app=saveandrestore"); + map.put("name", ((RestoreSnapshotActionInfo)adaptableObject).getSnapshotName()); + + RestoreSnapshotActionInfo restoreSnapshotActionInfo = (RestoreSnapshotActionInfo)adaptableObject; + String title = restoreSnapshotActionInfo.isGolden() ? + MessageFormat.format(Messages.GoldenSnapshotRestored, restoreSnapshotActionInfo.getSnapshotName()) : + MessageFormat.format(Messages.SnapshotRestored, restoreSnapshotActionInfo.getSnapshotName()); + LogEntryBuilder log = log() + .title(title) + .appendDescription(getBody(restoreSnapshotActionInfo)) + .appendProperty(PropertyImpl.of("resource", map)); + return Optional.of(adapterType.cast(log.build())); + } + + protected String getBody(RestoreSnapshotActionInfo restoreSnapshotActionInfo){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(Messages.RestoreSnapshotTemplateMessage).append(System.lineSeparator()).append(System.lineSeparator()); + getCommonSnapshotInfo(restoreSnapshotActionInfo, stringBuilder); + stringBuilder.append("| Golden | ").append(restoreSnapshotActionInfo.isGolden() ? "yes" : "no").append(" |\n"); + stringBuilder.append("| Restored by | ").append(restoreSnapshotActionInfo.getActionPerformedBy()).append(" |\n\n"); + + if(restoreSnapshotActionInfo.getFailedPVs() != null && !restoreSnapshotActionInfo.getFailedPVs().isEmpty()){ + stringBuilder.append("\n").append(Messages.FailedPVs).append("\n\n"); + // This is needed! + stringBuilder.append("| |\n"); + // This is needed! + stringBuilder.append("|-|\n"); + restoreSnapshotActionInfo.getFailedPVs().forEach(p -> stringBuilder.append("| ").append(p).append(" |\n")); + stringBuilder.append("\n"); + } + + return stringBuilder.toString(); + } +} diff --git a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactory.java b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactory.java deleted file mode 100644 index ab9c98c4c0..0000000000 --- a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactory.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2020 European Spallation Source ERIC. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -package org.phoebus.applications.saveandrestore.logging; - -import org.phoebus.framework.adapter.AdapterFactory; -import org.phoebus.logbook.LogEntry; -import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder; -import org.phoebus.logbook.PropertyImpl; - -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static org.phoebus.logbook.LogEntryImpl.LogEntryBuilder.log; - -/** - * Adapts save/restore action information to a log entry. - */ -public class SaveAndRestoreActionAdapterFactory implements AdapterFactory { - - @Override - public Class getAdaptableObject() { - return SaveSnapshotActionInfo.class; - } - - @Override - public List getAdapterList() { - return Arrays.asList(LogEntry.class); - } - - @Override - public Optional adapt(Object adaptableObject, Class adapterType) { - Map map = new HashMap<>(); - map.put("file", "file:/" + ((SaveSnapshotActionInfo)adaptableObject).getSnapshotUniqueId() + "?app=saveandrestore"); - map.put("name", ((SaveSnapshotActionInfo)adaptableObject).getSnapshotName()); - if(adaptableObject instanceof RestoreSnapshotActionInfo){ - RestoreSnapshotActionInfo restoreSnapshotActionInfo = (RestoreSnapshotActionInfo)adaptableObject; - String title = restoreSnapshotActionInfo.isGolden() ? - MessageFormat.format(Messages.GoldenSnapshotRestored, restoreSnapshotActionInfo.getSnapshotName()) : - MessageFormat.format(Messages.SnapshotRestored, restoreSnapshotActionInfo.getSnapshotName()); - LogEntryBuilder log = log() - .title(title) - .appendDescription(getBody(restoreSnapshotActionInfo)) - .appendProperty(PropertyImpl.of("resource", map)); - return Optional.of(adapterType.cast(log.build())); - } - else { - SaveSnapshotActionInfo saveSnapshotActionInfo = (SaveSnapshotActionInfo)adaptableObject; - LogEntryBuilder log = log() - .title(MessageFormat.format(Messages.SnapshotCreated, saveSnapshotActionInfo.getSnapshotName())) - .appendDescription(getBody(saveSnapshotActionInfo)) - .appendProperty(PropertyImpl.of("resource", map)); - return Optional.of(adapterType.cast(log.build())); - } - } - - private String getBody(SaveSnapshotActionInfo restoreSnapshotActionInfo){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(Messages.RestoreSnapshotTemplateMessage).append(System.lineSeparator()).append(System.lineSeparator()); - getCommonSnapshotInfo(restoreSnapshotActionInfo, stringBuilder); - stringBuilder.append("| Saved by | ").append(restoreSnapshotActionInfo.getActionPerformedBy()).append(" |\n\n"); - - return stringBuilder.toString(); - } - - private String getBody(RestoreSnapshotActionInfo restoreSnapshotActionInfo){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(Messages.SaveSnapshotTemplateMessage).append(System.lineSeparator()).append(System.lineSeparator()); - getCommonSnapshotInfo(restoreSnapshotActionInfo, stringBuilder); - stringBuilder.append("| Golden | ").append(restoreSnapshotActionInfo.isGolden() ? "yes" : "no").append(" |\n"); - stringBuilder.append("| Restored by | ").append(restoreSnapshotActionInfo.getActionPerformedBy()).append(" |\n\n"); - - if(restoreSnapshotActionInfo.getFailedPVs() != null && !restoreSnapshotActionInfo.getFailedPVs().isEmpty()){ - stringBuilder.append(Messages.FailedPVs).append("\n\n"); - // This is needed! - stringBuilder.append("| |\n"); - // This is needed! - stringBuilder.append("|-|\n"); - restoreSnapshotActionInfo.getFailedPVs().forEach(p -> stringBuilder.append("| ").append(p).append(" |\n\n")); - } - - return stringBuilder.toString(); - } - - private void getCommonSnapshotInfo(SaveSnapshotActionInfo saveSnapshotActionInfo, StringBuilder stringBuilder){ - // This is needed! - stringBuilder.append("| | |\n"); - // This is needed! - stringBuilder.append("|-|-|\n"); - stringBuilder.append("| Snapshot name | ").append(saveSnapshotActionInfo.getSnapshotName()).append(" |\n"); - stringBuilder.append("| Comment | ").append(saveSnapshotActionInfo.getComment()).append(" |\n"); - stringBuilder.append("| Created | ").append(saveSnapshotActionInfo.getSnapshotCreatedDate()).append(" |\n"); - } -} diff --git a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java index e007c02c61..53ab73d491 100644 --- a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java +++ b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLogger.java @@ -90,31 +90,4 @@ public void snapshotRestored(Node node, List failedPVs, Consumer SelectionService.getInstance().setSelection("SaveAndRestoreLogging", List.of(restoreSnapshotActionInfo)); Platform.runLater(() -> ApplicationService.createInstance("logbook")); } - - protected String getSnapshotInfoTable(Node node) { - StringBuilder stringBuilder = new StringBuilder(); - // This is needed! - stringBuilder.append("| | |\n"); - // This is needed! - stringBuilder.append("|-|-|\n"); - stringBuilder.append("| Snapshot name | ").append(node.getName()).append(" |\n"); - stringBuilder.append("| Comment | ").append(node.getProperty("comment")).append(" |\n"); - stringBuilder.append("| Created | ").append(node.getCreated()).append(" |\n"); - String isGolden = node.getProperty("golden"); - stringBuilder.append("| Golden | ").append("true".equals(isGolden) ? "yes" : "no").append(" |\n"); - stringBuilder.append("| User id | ").append(node.getUserName()).append(" |\n\n"); - - return stringBuilder.toString(); - } - - protected String getFailedPVsTable(List pvs) { - StringBuilder stringBuilder = new StringBuilder(); - // This is needed! - stringBuilder.append("| |\n"); - // This is needed! - stringBuilder.append("|-|\n"); - pvs.forEach(p -> stringBuilder.append("| ").append(p).append(" |\n")); - - return stringBuilder.toString(); - } } diff --git a/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactory.java b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactory.java new file mode 100644 index 0000000000..ea8ce19750 --- /dev/null +++ b/app/save-and-restore/logging/src/main/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactory.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2020 European Spallation Source ERIC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +package org.phoebus.applications.saveandrestore.logging; + +import org.phoebus.framework.adapter.AdapterFactory; +import org.phoebus.logbook.LogEntry; +import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder; +import org.phoebus.logbook.PropertyImpl; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.phoebus.logbook.LogEntryImpl.LogEntryBuilder.log; + +/** + * Adapts save snapshot action information to a log entry. + */ +public class SaveSnapshotActionAdapterFactory implements AdapterFactory { + + @Override + public Class getAdaptableObject() { + return SaveSnapshotActionInfo.class; + } + + @Override + public List getAdapterList() { + return Arrays.asList(LogEntry.class); + } + + @Override + public Optional adapt(Object adaptableObject, Class adapterType) { + Map map = new HashMap<>(); + map.put("file", "file:/" + ((SaveSnapshotActionInfo) adaptableObject).getSnapshotUniqueId() + "?app=saveandrestore"); + map.put("name", ((SaveSnapshotActionInfo) adaptableObject).getSnapshotName()); + + SaveSnapshotActionInfo saveSnapshotActionInfo = (SaveSnapshotActionInfo) adaptableObject; + LogEntryBuilder log = log() + .title(MessageFormat.format(Messages.SnapshotCreated, saveSnapshotActionInfo.getSnapshotName())) + .appendDescription(getBody(saveSnapshotActionInfo)) + .appendProperty(PropertyImpl.of("resource", map)); + return Optional.of(adapterType.cast(log.build())); + } + + private String getBody(SaveSnapshotActionInfo saveSnapshotActionInfo) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(Messages.SaveSnapshotTemplateMessage).append(System.lineSeparator()).append(System.lineSeparator()); + getCommonSnapshotInfo(saveSnapshotActionInfo, stringBuilder); + stringBuilder.append("| Saved by | ").append(saveSnapshotActionInfo.getActionPerformedBy()).append(" |\n\n"); + + return stringBuilder.toString(); + } + + protected void getCommonSnapshotInfo(SaveSnapshotActionInfo saveSnapshotActionInfo, StringBuilder stringBuilder) { + // This is needed! + stringBuilder.append("| | |\n"); + // This is needed! + stringBuilder.append("|-|-|\n"); + stringBuilder.append("| Snapshot name | ").append(saveSnapshotActionInfo.getSnapshotName()).append(" |\n"); + stringBuilder.append("| Comment | ").append(saveSnapshotActionInfo.getComment()).append(" |\n"); + stringBuilder.append("| Created | ").append(saveSnapshotActionInfo.getSnapshotCreatedDate()).append(" |\n"); + } +} diff --git a/app/save-and-restore/logging/src/main/resources/META-INF/services/org.phoebus.framework.adapter.AdapterFactory b/app/save-and-restore/logging/src/main/resources/META-INF/services/org.phoebus.framework.adapter.AdapterFactory index 40fd2bebf9..3a91efb399 100644 --- a/app/save-and-restore/logging/src/main/resources/META-INF/services/org.phoebus.framework.adapter.AdapterFactory +++ b/app/save-and-restore/logging/src/main/resources/META-INF/services/org.phoebus.framework.adapter.AdapterFactory @@ -1 +1,2 @@ -org.phoebus.applications.saveandrestore.logging.SaveAndRestoreActionAdapterFactory \ No newline at end of file +org.phoebus.applications.saveandrestore.logging.SaveSnapshotActionAdapterFactory +org.phoebus.applications.saveandrestore.logging.RestoreSnapshotActionAdapterFactory \ No newline at end of file diff --git a/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactoryTest.java b/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactoryTest.java similarity index 61% rename from app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactoryTest.java rename to app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactoryTest.java index e0c9f2a787..7c1a7010e8 100644 --- a/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreActionAdapterFactoryTest.java +++ b/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/RestoreSnapshotActionAdapterFactoryTest.java @@ -24,20 +24,20 @@ import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; -public class SaveAndRestoreActionAdapterFactoryTest { +public class RestoreSnapshotActionAdapterFactoryTest { - private SaveAndRestoreActionAdapterFactory saveAndRestoreActionAdapterFactory = new SaveAndRestoreActionAdapterFactory(); + private RestoreSnapshotActionAdapterFactory restoreSnapshotActionAdapterFactory = new RestoreSnapshotActionAdapterFactory(); @Test public void testGetAdaptableObject(){ - assertTrue(saveAndRestoreActionAdapterFactory.getAdaptableObject().isAssignableFrom(RestoreSnapshotActionInfo.class)); + assertTrue(restoreSnapshotActionAdapterFactory.getAdaptableObject().isAssignableFrom(RestoreSnapshotActionInfo.class)); } @Test public void testGetAdapterList(){ - List list = saveAndRestoreActionAdapterFactory.getAdapterList(); + List list = restoreSnapshotActionAdapterFactory.getAdapterList(); assertTrue(list.get(0).isAssignableFrom(LogEntry.class)); } @@ -47,19 +47,9 @@ public void testAdaptRestoreAction(){ restoreSnapshotActionInfo.setSnapshotName("snapshot name"); restoreSnapshotActionInfo.setFailedPVs(List.of("pv name")); - LogEntry logEntry = saveAndRestoreActionAdapterFactory.adapt(restoreSnapshotActionInfo, LogEntry.class).get(); + LogEntry logEntry = restoreSnapshotActionAdapterFactory.adapt(restoreSnapshotActionInfo, LogEntry.class).get(); assertTrue(logEntry.getTitle().contains("snapshot name")); assertTrue(logEntry.getDescription().contains("snapshot name")); assertTrue(logEntry.getDescription().contains("pv name")); } - - @Test - public void testAdaptSaveAction(){ - SaveSnapshotActionInfo saveSnapshotActionInfo = new SaveSnapshotActionInfo(); - saveSnapshotActionInfo.setSnapshotName("snapshot name"); - - LogEntry logEntry = saveAndRestoreActionAdapterFactory.adapt(saveSnapshotActionInfo, LogEntry.class).get(); - assertTrue(logEntry.getTitle().contains("snapshot name")); - assertTrue(logEntry.getDescription().contains("snapshot name")); - } } diff --git a/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLoggerTest.java b/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLoggerTest.java deleted file mode 100644 index 24df687bb8..0000000000 --- a/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveAndRestoreEventLoggerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2020 European Spallation Source ERIC. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -package org.phoebus.applications.saveandrestore.logging; - -import org.junit.Test; -import org.phoebus.applications.saveandrestore.model.Node; - -import java.util.Collections; - -import static org.junit.Assert.*; - -public class SaveAndRestoreEventLoggerTest { - - @Test - public void testGetSnapshotInfoTable(){ - String table = new SaveAndRestoreEventLogger().getSnapshotInfoTable(new Node()); - String[] rows = table.split("\\n"); - assertTrue(rows[0].startsWith("| ")); - assertTrue(rows[1].startsWith("|-")); - } - - @Test - public void testGetPVFailedTable(){ - String table = new SaveAndRestoreEventLogger().getFailedPVsTable(Collections.emptyList()); - String[] rows = table.split("\\n"); - assertTrue(rows[0].startsWith("| ")); - assertTrue(rows[1].startsWith("|-")); - } -} diff --git a/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactoryTest.java b/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactoryTest.java new file mode 100644 index 0000000000..5c8d0a11b5 --- /dev/null +++ b/app/save-and-restore/logging/src/test/java/org/phoebus/applications/saveandrestore/logging/SaveSnapshotActionAdapterFactoryTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 European Spallation Source ERIC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +package org.phoebus.applications.saveandrestore.logging; + +import org.junit.Test; +import org.phoebus.logbook.LogEntry; + +import java.util.List; + +import static org.junit.Assert.*; + +public class SaveSnapshotActionAdapterFactoryTest { + + private SaveSnapshotActionAdapterFactory saveSnapshotActionAdapterFactory = new SaveSnapshotActionAdapterFactory(); + + @Test + public void testGetAdaptableObject(){ + assertTrue(saveSnapshotActionAdapterFactory.getAdaptableObject().isAssignableFrom(SaveSnapshotActionInfo.class)); + } + + @Test + public void testGetAdapterList(){ + List list = saveSnapshotActionAdapterFactory.getAdapterList(); + assertTrue(list.get(0).isAssignableFrom(LogEntry.class)); + } + + @Test + public void testAdaptSaveAction(){ + SaveSnapshotActionInfo saveSnapshotActionInfo = new SaveSnapshotActionInfo(); + saveSnapshotActionInfo.setSnapshotName("snapshot name"); + + LogEntry logEntry = saveSnapshotActionAdapterFactory.adapt(saveSnapshotActionInfo, LogEntry.class).get(); + assertTrue(logEntry.getTitle().contains("snapshot name")); + assertTrue(logEntry.getDescription().contains("snapshot name")); + } +}