Fixed bug in CsvExporter, all unit tests for CsvExporter and TsvExporter now working.

History now has the beginnings of a unit test.

Additional source documentation on public methods in ProjectManager and History.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@989 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Iain Sproat 2010-06-17 15:37:28 +00:00
parent e7d0fc5ed6
commit 846cf1d57e
7 changed files with 121 additions and 18 deletions

View File

@ -56,10 +56,28 @@ public abstract class ProjectManager {
}
}
/**
* Load project from data storage
* @param projectID
* @return
*/
public abstract boolean importProject(long projectID);
/**
* Import project from a Gridworks archive
* @param projectID
* @param inputStream
* @param gziped
* @throws IOException
*/
public abstract void importProject(long projectID, InputStream inputStream, boolean gziped) throws IOException;
/**
* Export project to a Gridworks archive
* @param projectId
* @param tos
* @throws IOException
*/
public abstract void exportProject(long projectId, TarOutputStream tos) throws IOException;
public abstract void ensureProjectSaved(long id);
@ -117,14 +135,26 @@ public abstract class ProjectManager {
return ((TopList) _preferenceStore.get("expressions")).getList();
}
/**
* Save project to data store
* @param b
*/
public abstract void save(boolean b);
public void deleteProject(Project project) {
deleteProject(project.id);
}
/**
* Remove project from data store
* @param projectID
*/
public abstract void deleteProject(long projectID) ;
/**
* The history entry manager deals with changes
* @return manager for handling history
*/
public abstract HistoryEntryManager getHistoryEntryManager();
static protected void preparePreferenceStore(PreferenceStore ps) {

View File

@ -42,7 +42,7 @@ public class CsvExporter implements Exporter{
public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException {
boolean printColumnHeader = true;
if (options != null) {
if (options != null && options.getProperty("printColumnHeader") != null) {
printColumnHeader = Boolean.parseBoolean(options.getProperty("printColumnHeader"));
}

View File

@ -89,6 +89,11 @@ public class History implements Jsonizable {
_futureEntries = new ArrayList<HistoryEntry>();
}
/**
* Adds a HistoryEntry to the list of past histories
* Adding a new entry clears all currently held future histories
* @param entry
*/
synchronized public void addEntry(HistoryEntry entry) {
entry.apply(ProjectManager.singleton.getProject(_projectID));
_pastEntries.add(entry);

View File

@ -49,7 +49,7 @@ public class FileProjectManager extends ProjectManager {
}
private FileProjectManager(File dir) {
protected FileProjectManager(File dir) {
_workspaceDir = dir;
_workspaceDir.mkdirs();

View File

@ -26,12 +26,12 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.tests.GridworksTest;
public class CsvExporterTests extends GridworksTest {
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
//dependencies
StringWriter writer;
Project project;
@ -59,7 +59,7 @@ public class CsvExporterTests extends GridworksTest {
options = null;
}
@Test(groups={"broken"})
@Test
public void exportSimpleCsv(){
CreateGrid(2, 2);
@ -88,10 +88,10 @@ public class CsvExporterTests extends GridworksTest {
Assert.assertEquals(writer.toString(), "row0cell0,row0cell1\n" +
"row1cell0,row1cell1\n");
verify(options,times(1)).getProperty("printColumnHeader");
verify(options,times(2)).getProperty("printColumnHeader");
}
@Test(groups={"broken"})
@Test
public void exportCsvWithLineBreaks(){
CreateGrid(3,3);
@ -108,7 +108,7 @@ public class CsvExporterTests extends GridworksTest {
"row2cell0,row2cell1,row2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportCsvWithComma(){
CreateGrid(3,3);
@ -125,7 +125,7 @@ public class CsvExporterTests extends GridworksTest {
"row2cell0,row2cell1,row2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportCsvWithQuote(){
CreateGrid(3,3);
@ -142,7 +142,7 @@ public class CsvExporterTests extends GridworksTest {
"row2cell0,row2cell1,row2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportCsvWithEmptyCells(){
CreateGrid(3,3);

View File

@ -26,12 +26,12 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.tests.GridworksTest;
public class TsvExporterTests extends GridworksTest {
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
//dependencies
StringWriter writer;
Project project;
@ -59,7 +59,7 @@ public class TsvExporterTests extends GridworksTest {
options = null;
}
@Test(groups={"broken"})
@Test
public void exportSimpleTsv(){
CreateGrid(2, 2);
@ -88,10 +88,10 @@ public class TsvExporterTests extends GridworksTest {
Assert.assertEquals(writer.toString(), "row0cell0\trow0cell1\n" +
"row1cell0\trow1cell1\n");
verify(options,times(1)).getProperty("printColumnHeader");
verify(options,times(2)).getProperty("printColumnHeader");
}
@Test(groups={"broken"})
@Test
public void exportTsvWithLineBreaks(){
CreateGrid(3,3);
@ -108,7 +108,7 @@ public class TsvExporterTests extends GridworksTest {
"row2cell0\trow2cell1\trow2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportTsvWithComma(){
CreateGrid(3,3);
@ -125,7 +125,7 @@ public class TsvExporterTests extends GridworksTest {
"row2cell0\trow2cell1\trow2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportTsvWithQuote(){
CreateGrid(3,3);
@ -142,7 +142,7 @@ public class TsvExporterTests extends GridworksTest {
"row2cell0\trow2cell1\trow2cell2\n");
}
@Test(groups={"broken"})
@Test
public void exportTsvWithEmptyCells(){
CreateGrid(3,3);

View File

@ -0,0 +1,68 @@
package com.metaweb.gridworks.tests.history;
import org.mockito.Mockito;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.ProjectMetadata;
import com.metaweb.gridworks.history.History;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.tests.GridworksTest;
public class HistoryTests extends GridworksTest {
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
//System Under Test
History SUT;
//dependencies
Project proj;
ProjectManager projectManager;
@BeforeMethod
public void SetUp(){
projectManager = mock(ProjectManager.class);
ProjectManager.singleton = projectManager;
proj = new Project();
SUT = new History(proj);
}
@AfterMethod
public void TearDown(){
SUT = null;
proj = null;
}
@Test
public void canAddEntry(){
//local dependencies
HistoryEntry entry = mock(HistoryEntry.class);
Project project = mock(Project.class);
ProjectMetadata projectMetadata = mock(ProjectMetadata.class);
when(projectManager.getProject(Mockito.anyLong())).thenReturn(project);
when(projectManager.getProjectMetadata(Mockito.anyLong())).thenReturn(projectMetadata);
SUT.addEntry(entry);
verify(projectManager, times(1)).getProject(Mockito.anyLong());
verify(entry, times(1)).apply(project);
verify(projectMetadata, times(1)).updateModified();
Assert.assertEquals(SUT.getLastPastEntries(1).get(0), entry);
}
}