Some very basic tests for exporters with no test coverage
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1567 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
0041863a13
commit
87b6d940b7
@ -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(), "<html>\n" +
|
||||
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||
"<body>\n" +
|
||||
"<table>\n" +
|
||||
"<tr><th>column0</th><th>column1</th></tr>\n" +
|
||||
"<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" +
|
||||
"<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" +
|
||||
"</table>\n" +
|
||||
"</body>\n" +
|
||||
"</html>\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(), "<html>\n" +
|
||||
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||
"<body>\n" +
|
||||
"<table>\n" +
|
||||
"<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" +
|
||||
"<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" +
|
||||
"</table>\n" +
|
||||
"</body>\n" +
|
||||
"</html>\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(), "<html>\n" +
|
||||
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||
"<body>\n" +
|
||||
"<table>\n" +
|
||||
"<tr><th>column0</th><th>column1</th><th>column2</th></tr>\n" +
|
||||
"<tr><td>row0cell0</td><td>row0cell1</td><td>row0cell2</td></tr>\n" +
|
||||
"<tr><td>row1cell0</td><td></td><td>row1cell2</td></tr>\n" +
|
||||
"<tr><td></td><td>row2cell1</td><td>row2cell2</td></tr>\n" +
|
||||
"</table>\n" +
|
||||
"</body>\n" +
|
||||
"</html>\n");
|
||||
}
|
||||
|
||||
//helper methods
|
||||
|
||||
|
@ -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 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 exportSimpleCsv(){
|
||||
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 = "<test suffix";
|
||||
String rowSeparator = "\n";
|
||||
|
||||
// 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(rowSeparator);
|
||||
// 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(), "column0,column1\n" +
|
||||
"row0cell0,row0cell1\n" +
|
||||
"row1cell0,row1cell1\n");
|
||||
|
||||
Assert.assertEquals(writer.toString(),
|
||||
prefix
|
||||
+ rowPrefix + "row0cell0" + cellSeparator + "row0cell1" + rowSeparator
|
||||
+ rowPrefix + "row1cell0" + cellSeparator + "row1cell1"
|
||||
+ suffix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportSimpleCsvNoHeader(){
|
||||
CreateGrid(2, 2);
|
||||
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
||||
try {
|
||||
SUT.export(project, options, engine, writer);
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.assertEquals(writer.toString(), "row0cell0,row0cell1\n" +
|
||||
"row1cell0,row1cell1\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(){
|
||||
@Test(enabled=false)
|
||||
public void exportTemplateWithEmptyCells(){
|
||||
CreateGrid(3,3);
|
||||
|
||||
project.rows.get(1).cells.set(1, null);
|
||||
|
@ -7,7 +7,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -17,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.StreamExporter;
|
||||
import com.google.refine.exporters.XlsExporter;
|
||||
@ -25,17 +26,21 @@ 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 XlsExporterTests extends RefineTest {
|
||||
|
||||
private static final String TEST_PROJECT_NAME = "xls exporter test project";
|
||||
|
||||
@BeforeTest
|
||||
public void init() {
|
||||
logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
//dependencies
|
||||
OutputStream stream;
|
||||
ByteArrayOutputStream stream;
|
||||
ProjectMetadata projectMetadata;
|
||||
Project project;
|
||||
Engine engine;
|
||||
Properties options;
|
||||
@ -47,7 +52,11 @@ public class XlsExporterTests extends RefineTest {
|
||||
public void SetUp(){
|
||||
SUT = new XlsExporter();
|
||||
stream = new ByteArrayOutputStream();
|
||||
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);
|
||||
}
|
||||
@ -56,13 +65,14 @@ public class XlsExporterTests extends RefineTest {
|
||||
public void TearDown(){
|
||||
SUT = null;
|
||||
stream = null;
|
||||
ProjectManager.singleton.deleteProject(project.id);
|
||||
project = null;
|
||||
engine = null;
|
||||
options = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportSimpleCsv(){
|
||||
public void exportSimpleXls(){
|
||||
CreateGrid(2, 2);
|
||||
|
||||
try {
|
||||
@ -71,14 +81,14 @@ public class XlsExporterTests extends RefineTest {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.assertEquals(stream.toString(), "column0,column1\n" +
|
||||
"row0cell0,row0cell1\n" +
|
||||
"row1cell0,row1cell1\n");
|
||||
// TODO: Not a very effective test!
|
||||
// (it didn't crash though, and it created output)
|
||||
Assert.assertEquals(stream.size(),4096);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportSimpleCsvNoHeader(){
|
||||
@Test(enabled=false)
|
||||
public void exportSimpleXlsNoHeader(){
|
||||
CreateGrid(2, 2);
|
||||
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
||||
try {
|
||||
@ -93,59 +103,9 @@ public class XlsExporterTests extends RefineTest {
|
||||
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, stream);
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.assertEquals(stream.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, stream);
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.assertEquals(stream.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, stream);
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
Assert.assertEquals(stream.toString(), "column0,column1,column2\n" +
|
||||
"row0cell0,row0cell1,row0cell2\n" +
|
||||
"row1cell0,\"line has \"\"quote\"\"\",row1cell2\n" +
|
||||
"row2cell0,row2cell1,row2cell2\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportCsvWithEmptyCells(){
|
||||
@Test(enabled=false)
|
||||
public void exportXlsWithEmptyCells(){
|
||||
CreateGrid(3,3);
|
||||
|
||||
project.rows.get(1).cells.set(1, null);
|
||||
|
Loading…
Reference in New Issue
Block a user