diff --git a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java index ec1ab9a05..b31e8d34a 100644 --- a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java @@ -16,6 +16,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.ProjectManager; +import com.google.refine.ProjectMetadata; import com.google.refine.browsing.Engine; import com.google.refine.exporters.HtmlTableExporter; import com.google.refine.exporters.WriterExporter; @@ -24,10 +26,13 @@ import com.google.refine.model.Column; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Row; +import com.google.refine.tests.ProjectManagerStub; import com.google.refine.tests.RefineTest; public class HtmlExporterTests extends RefineTest { + private static final String TEST_PROJECT_NAME = "html table exporter test project"; + @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); @@ -35,6 +40,7 @@ public class HtmlExporterTests extends RefineTest { //dependencies StringWriter writer; + ProjectMetadata projectMetadata; Project project; Engine engine; Properties options; @@ -46,7 +52,11 @@ public class HtmlExporterTests extends RefineTest { public void SetUp(){ SUT = new HtmlTableExporter(); writer = new StringWriter(); + ProjectManager.singleton = new ProjectManagerStub(); + projectMetadata = new ProjectMetadata(); project = new Project(); + projectMetadata.setName(TEST_PROJECT_NAME); + ProjectManager.singleton.registerProject(project, projectMetadata); engine = new Engine(project); options = mock(Properties.class); } @@ -55,13 +65,15 @@ public class HtmlExporterTests extends RefineTest { public void TearDown(){ SUT = null; writer = null; + ProjectManager.singleton.deleteProject(project.id); project = null; + projectMetadata = null; engine = null; options = null; } @Test - public void exportSimpleCsv(){ + public void exportSimpleHtmlTable(){ CreateGrid(2, 2); try { @@ -70,14 +82,23 @@ public class HtmlExporterTests extends RefineTest { Assert.fail(); } - Assert.assertEquals(writer.toString(), "column0,column1\n" + - "row0cell0,row0cell1\n" + - "row1cell0,row1cell1\n"); + Assert.assertEquals(writer.toString(), "\n" + + "" + TEST_PROJECT_NAME + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
column0column1
row0cell0row0cell1
row1cell0row1cell1
\n" + + "\n" + + "\n"); } + // TODO: This test fails because the HTML table exporter + // apparently doesn't honor the column header option. Should it? @Test - public void exportSimpleCsvNoHeader(){ + public void exportSimpleHtmlTableNoHeader(){ CreateGrid(2, 2); when(options.getProperty("printColumnHeader")).thenReturn("false"); try { @@ -86,65 +107,21 @@ public class HtmlExporterTests extends RefineTest { Assert.fail(); } - Assert.assertEquals(writer.toString(), "row0cell0,row0cell1\n" + - "row1cell0,row1cell1\n"); - + Assert.assertEquals(writer.toString(), "\n" + + "" + TEST_PROJECT_NAME + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
row0cell0row0cell1
row1cell0row1cell1
\n" + + "\n" + + "\n"); verify(options,times(2)).getProperty("printColumnHeader"); } - @Test - public void exportCsvWithLineBreaks(){ - CreateGrid(3,3); - - project.rows.get(1).cells.set(1, new Cell("line\n\n\nbreak", null)); - try { - SUT.export(project, options, engine, writer); - } catch (IOException e) { - Assert.fail(); - } - - Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + - "row0cell0,row0cell1,row0cell2\n" + - "row1cell0,\"line\n\n\nbreak\",row1cell2\n" + - "row2cell0,row2cell1,row2cell2\n"); - } @Test - public void exportCsvWithComma(){ - CreateGrid(3,3); - - project.rows.get(1).cells.set(1, new Cell("with, comma", null)); - try { - SUT.export(project, options, engine, writer); - } catch (IOException e) { - Assert.fail(); - } - - Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + - "row0cell0,row0cell1,row0cell2\n" + - "row1cell0,\"with, comma\",row1cell2\n" + - "row2cell0,row2cell1,row2cell2\n"); - } - - @Test - public void exportCsvWithQuote(){ - CreateGrid(3,3); - - project.rows.get(1).cells.set(1, new Cell("line has \"quote\"", null)); - try { - SUT.export(project, options, engine, writer); - } catch (IOException e) { - Assert.fail(); - } - - Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + - "row0cell0,row0cell1,row0cell2\n" + - "row1cell0,\"line has \"\"quote\"\"\",row1cell2\n" + - "row2cell0,row2cell1,row2cell2\n"); - } - - @Test - public void exportCsvWithEmptyCells(){ + public void exportHtmlTableWithEmptyCells(){ CreateGrid(3,3); project.rows.get(1).cells.set(1, null); @@ -155,11 +132,18 @@ public class HtmlExporterTests extends RefineTest { Assert.fail(); } - Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + - "row0cell0,row0cell1,row0cell2\n" + - "row1cell0,,row1cell2\n" + - ",row2cell1,row2cell2\n"); - } + Assert.assertEquals(writer.toString(), "\n" + + "" + TEST_PROJECT_NAME + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
column0column1column2
row0cell0row0cell1row0cell2
row1cell0row1cell2
row2cell1row2cell2
\n" + + "\n" + + "\n"); + } //helper methods diff --git a/main/tests/server/src/com/google/refine/tests/exporters/TemplatingExporterTests.java b/main/tests/server/src/com/google/refine/tests/exporters/TemplatingExporterTests.java index a5f0990a2..6d7c2fb44 100644 --- a/main/tests/server/src/com/google/refine/tests/exporters/TemplatingExporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/exporters/TemplatingExporterTests.java @@ -1,8 +1,6 @@ package com.google.refine.tests.exporters; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.IOException; @@ -16,6 +14,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.ProjectManager; +import com.google.refine.ProjectMetadata; import com.google.refine.browsing.Engine; import com.google.refine.exporters.TemplatingExporter; import com.google.refine.exporters.WriterExporter; @@ -24,10 +24,13 @@ import com.google.refine.model.Column; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Row; +import com.google.refine.tests.ProjectManagerStub; import com.google.refine.tests.RefineTest; public class TemplatingExporterTests extends RefineTest { + private static final String TEST_PROJECT_NAME = "templating exporter test project"; + @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); @@ -35,6 +38,7 @@ public class TemplatingExporterTests extends RefineTest { //dependencies StringWriter writer; + ProjectMetadata projectMetadata; Project project; Engine engine; Properties options; @@ -46,7 +50,11 @@ public class TemplatingExporterTests extends RefineTest { public void SetUp(){ SUT = new TemplatingExporter(); writer = new StringWriter(); + ProjectManager.singleton = new ProjectManagerStub(); + projectMetadata = new ProjectMetadata(); project = new Project(); + projectMetadata.setName(TEST_PROJECT_NAME); + ProjectManager.singleton.registerProject(project, projectMetadata); engine = new Engine(project); options = mock(Properties.class); } @@ -55,96 +63,72 @@ public class TemplatingExporterTests extends RefineTest { public void TearDown(){ SUT = null; writer = null; + ProjectManager.singleton.deleteProject(project.id); project = null; engine = null; options = null; } - @Test - public void exportSimpleCsv(){ + public void exportEmptyTemplate(){ + + String template = "a simple test template"; + String prefix = "test prefix"; + String suffix = "test suffix"; + String separator = "|"; + +// when(options.getProperty("limit")).thenReturn("100"); // optional integer +// when(options.getProperty("sorting")).thenReturn(""); //optional + when(options.getProperty("template")).thenReturn(template); + when(options.getProperty("prefix")).thenReturn(prefix); + when(options.getProperty("suffix")).thenReturn(suffix); + when(options.getProperty("separator")).thenReturn(separator); +// when(options.getProperty("preview")).thenReturn("false"); // optional true|false + + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + Assert.assertEquals(writer.toString(), prefix + suffix); + } + + @Test + public void exportSimpleTemplate(){ CreateGrid(2, 2); + String rowPrefix = "boilerplate"; + String cellSeparator = "spacer"; + String template = rowPrefix + "${column0}" + cellSeparator + "${column1}"; +// String template = "boilerplate${column0}{{4+3}}${column1}"; + String prefix = "test prefix>"; + String suffix = "