From 580fd92c10a8d00482fbea0dc10f88bd0cfa44e7 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 16:08:05 +0100 Subject: [PATCH] Add JSON serialization tests for processes --- .../tests/process/HistoryProcessTests.java | 44 +++++++++++++++++++ .../process/LongRunningProcessTests.java | 33 ++++++++++++++ .../tests/process/ProcessManagerTests.java | 31 +++++++++++++ .../QuickHistoryEntryProcessTests.java | 40 +++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java diff --git a/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java new file mode 100644 index 000000000..0c4da94da --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java @@ -0,0 +1,44 @@ +package com.google.refine.tests.process; + +import static org.mockito.Mockito.mock; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.refine.ProjectManager; +import com.google.refine.history.Change; +import com.google.refine.history.HistoryEntry; +import com.google.refine.history.HistoryProcess; +import com.google.refine.model.AbstractOperation; +import com.google.refine.model.Project; +import com.google.refine.model.metadata.ProjectMetadata; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class HistoryProcessTests extends RefineTest { + + private Project project; + private ProjectMetadata projectMetadata; + + @BeforeMethod + public void setUp() { + project = new Project(); + projectMetadata = mock(ProjectMetadata.class); + ProjectManager.singleton.registerProject(project, projectMetadata); + AbstractOperation op = mock(AbstractOperation.class); + Change ch = mock(Change.class); + HistoryEntry entry = new HistoryEntry(1234L, project, "first operation", op, ch); + project.history.addEntry(entry); + entry = new HistoryEntry(5678L, project, "second operation", op, ch); + project.history.addEntry(entry); + } + + @Test + public void serializeHistoryProcess() { + HistoryProcess process = new HistoryProcess(project, 1234L); + TestUtils.isSerializedTo(process, "{" + + "\"description\":\"Undo/redo until after first operation\"," + + "\"immediate\":true," + + "\"status\":\"pending\"}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java new file mode 100644 index 000000000..6afab6845 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java @@ -0,0 +1,33 @@ +package com.google.refine.tests.process; + +import org.testng.annotations.Test; + +import com.google.refine.process.LongRunningProcess; +import com.google.refine.tests.util.TestUtils; + +public class LongRunningProcessTests { + + public static class LongRunningProcessStub extends LongRunningProcess { + + protected LongRunningProcessStub(String description) { + super(description); + } + + @Override + protected Runnable getRunnable() { + return null; + } + + } + @Test + public void serializeLongRunningProcess() { + LongRunningProcess process = new LongRunningProcessStub("some description"); + int hashCode = process.hashCode(); + TestUtils.isSerializedTo(process, "{" + + "\"id\":"+hashCode+"," + + "\"description\":\"some description\"," + + "\"immediate\":false," + + "\"status\":\"pending\"," + + "\"progress\":0}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java new file mode 100644 index 000000000..6a366518b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java @@ -0,0 +1,31 @@ +package com.google.refine.tests.process; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.refine.process.LongRunningProcess; +import com.google.refine.process.ProcessManager; +import com.google.refine.process.Process; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.util.JSONUtilities; + +public class ProcessManagerTests { + + ProcessManager processManager; + Process process; + + @BeforeMethod + public void setUp() { + processManager = new ProcessManager(); + process = new LongRunningProcessTests.LongRunningProcessStub("some description"); + + } + + @Test + public void serializeProcessManager() throws Exception { + processManager.queueProcess(process); + String processJson = JSONUtilities.serialize(process); + TestUtils.isSerializedTo(processManager, "{" + + "\"processes\":["+processJson+"]}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java new file mode 100644 index 000000000..538eb3b01 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java @@ -0,0 +1,40 @@ +package com.google.refine.tests.process; + +import static org.mockito.Mockito.mock; +import org.testng.annotations.Test; + +import com.google.refine.history.HistoryEntry; +import com.google.refine.model.Project; +import com.google.refine.process.QuickHistoryEntryProcess; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.process.Process; + +public class QuickHistoryEntryProcessTests { + public static class QuickHistoryEntryProcessStub extends QuickHistoryEntryProcess { + + public QuickHistoryEntryProcessStub(Project project, String briefDescription) { + super(project, briefDescription); + + } + + @Override + protected HistoryEntry createHistoryEntry(long historyEntryID) + throws Exception { + return null; + } + + } + + @Test + public void serializeQuickHistoryEntryProcess() { + Project project = mock(Project.class); + Process process = new QuickHistoryEntryProcessStub(project, "quick description"); + int hashCode = process.hashCode(); + TestUtils.isSerializedTo(process, "{" + + "\"id\":"+hashCode+"," + + "\"description\":" + + "\"quick description\"," + + "\"immediate\":true," + + "\"status\":\"pending\"}"); + } +}