Add JSON serialization tests for processes
This commit is contained in:
parent
debe9bde37
commit
580fd92c10
@ -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\"}");
|
||||
}
|
||||
}
|
@ -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}");
|
||||
}
|
||||
}
|
@ -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+"]}");
|
||||
}
|
||||
}
|
@ -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\"}");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user