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.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
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.browsing.Engine;
|
||||||
import com.google.refine.exporters.HtmlTableExporter;
|
import com.google.refine.exporters.HtmlTableExporter;
|
||||||
import com.google.refine.exporters.WriterExporter;
|
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.ModelException;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
import com.google.refine.model.Row;
|
import com.google.refine.model.Row;
|
||||||
|
import com.google.refine.tests.ProjectManagerStub;
|
||||||
import com.google.refine.tests.RefineTest;
|
import com.google.refine.tests.RefineTest;
|
||||||
|
|
||||||
public class HtmlExporterTests extends RefineTest {
|
public class HtmlExporterTests extends RefineTest {
|
||||||
|
|
||||||
|
private static final String TEST_PROJECT_NAME = "html table exporter test project";
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void init() {
|
public void init() {
|
||||||
logger = LoggerFactory.getLogger(this.getClass());
|
logger = LoggerFactory.getLogger(this.getClass());
|
||||||
@ -35,6 +40,7 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
StringWriter writer;
|
StringWriter writer;
|
||||||
|
ProjectMetadata projectMetadata;
|
||||||
Project project;
|
Project project;
|
||||||
Engine engine;
|
Engine engine;
|
||||||
Properties options;
|
Properties options;
|
||||||
@ -46,7 +52,11 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
public void SetUp(){
|
public void SetUp(){
|
||||||
SUT = new HtmlTableExporter();
|
SUT = new HtmlTableExporter();
|
||||||
writer = new StringWriter();
|
writer = new StringWriter();
|
||||||
|
ProjectManager.singleton = new ProjectManagerStub();
|
||||||
|
projectMetadata = new ProjectMetadata();
|
||||||
project = new Project();
|
project = new Project();
|
||||||
|
projectMetadata.setName(TEST_PROJECT_NAME);
|
||||||
|
ProjectManager.singleton.registerProject(project, projectMetadata);
|
||||||
engine = new Engine(project);
|
engine = new Engine(project);
|
||||||
options = mock(Properties.class);
|
options = mock(Properties.class);
|
||||||
}
|
}
|
||||||
@ -55,13 +65,15 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
public void TearDown(){
|
public void TearDown(){
|
||||||
SUT = null;
|
SUT = null;
|
||||||
writer = null;
|
writer = null;
|
||||||
|
ProjectManager.singleton.deleteProject(project.id);
|
||||||
project = null;
|
project = null;
|
||||||
|
projectMetadata = null;
|
||||||
engine = null;
|
engine = null;
|
||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exportSimpleCsv(){
|
public void exportSimpleHtmlTable(){
|
||||||
CreateGrid(2, 2);
|
CreateGrid(2, 2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -70,14 +82,23 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(writer.toString(), "column0,column1\n" +
|
Assert.assertEquals(writer.toString(), "<html>\n" +
|
||||||
"row0cell0,row0cell1\n" +
|
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||||
"row1cell0,row1cell1\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
|
@Test
|
||||||
public void exportSimpleCsvNoHeader(){
|
public void exportSimpleHtmlTableNoHeader(){
|
||||||
CreateGrid(2, 2);
|
CreateGrid(2, 2);
|
||||||
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
||||||
try {
|
try {
|
||||||
@ -86,65 +107,21 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(writer.toString(), "row0cell0,row0cell1\n" +
|
Assert.assertEquals(writer.toString(), "<html>\n" +
|
||||||
"row1cell0,row1cell1\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");
|
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
|
@Test
|
||||||
public void exportCsvWithComma(){
|
public void exportHtmlTableWithEmptyCells(){
|
||||||
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(){
|
|
||||||
CreateGrid(3,3);
|
CreateGrid(3,3);
|
||||||
|
|
||||||
project.rows.get(1).cells.set(1, null);
|
project.rows.get(1).cells.set(1, null);
|
||||||
@ -155,11 +132,18 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(writer.toString(), "column0,column1,column2\n" +
|
Assert.assertEquals(writer.toString(), "<html>\n" +
|
||||||
"row0cell0,row0cell1,row0cell2\n" +
|
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||||
"row1cell0,,row1cell2\n" +
|
"<body>\n" +
|
||||||
",row2cell1,row2cell2\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
|
//helper methods
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.google.refine.tests.exporters;
|
package com.google.refine.tests.exporters;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -16,6 +14,8 @@ import org.testng.annotations.BeforeMethod;
|
|||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
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.browsing.Engine;
|
||||||
import com.google.refine.exporters.TemplatingExporter;
|
import com.google.refine.exporters.TemplatingExporter;
|
||||||
import com.google.refine.exporters.WriterExporter;
|
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.ModelException;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
import com.google.refine.model.Row;
|
import com.google.refine.model.Row;
|
||||||
|
import com.google.refine.tests.ProjectManagerStub;
|
||||||
import com.google.refine.tests.RefineTest;
|
import com.google.refine.tests.RefineTest;
|
||||||
|
|
||||||
public class TemplatingExporterTests extends RefineTest {
|
public class TemplatingExporterTests extends RefineTest {
|
||||||
|
|
||||||
|
private static final String TEST_PROJECT_NAME = "templating exporter test project";
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void init() {
|
public void init() {
|
||||||
logger = LoggerFactory.getLogger(this.getClass());
|
logger = LoggerFactory.getLogger(this.getClass());
|
||||||
@ -35,6 +38,7 @@ public class TemplatingExporterTests extends RefineTest {
|
|||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
StringWriter writer;
|
StringWriter writer;
|
||||||
|
ProjectMetadata projectMetadata;
|
||||||
Project project;
|
Project project;
|
||||||
Engine engine;
|
Engine engine;
|
||||||
Properties options;
|
Properties options;
|
||||||
@ -46,7 +50,11 @@ public class TemplatingExporterTests extends RefineTest {
|
|||||||
public void SetUp(){
|
public void SetUp(){
|
||||||
SUT = new TemplatingExporter();
|
SUT = new TemplatingExporter();
|
||||||
writer = new StringWriter();
|
writer = new StringWriter();
|
||||||
|
ProjectManager.singleton = new ProjectManagerStub();
|
||||||
|
projectMetadata = new ProjectMetadata();
|
||||||
project = new Project();
|
project = new Project();
|
||||||
|
projectMetadata.setName(TEST_PROJECT_NAME);
|
||||||
|
ProjectManager.singleton.registerProject(project, projectMetadata);
|
||||||
engine = new Engine(project);
|
engine = new Engine(project);
|
||||||
options = mock(Properties.class);
|
options = mock(Properties.class);
|
||||||
}
|
}
|
||||||
@ -55,96 +63,72 @@ public class TemplatingExporterTests extends RefineTest {
|
|||||||
public void TearDown(){
|
public void TearDown(){
|
||||||
SUT = null;
|
SUT = null;
|
||||||
writer = null;
|
writer = null;
|
||||||
|
ProjectManager.singleton.deleteProject(project.id);
|
||||||
project = null;
|
project = null;
|
||||||
engine = null;
|
engine = null;
|
||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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);
|
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 {
|
try {
|
||||||
SUT.export(project, options, engine, writer);
|
SUT.export(project, options, engine, writer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(writer.toString(), "column0,column1\n" +
|
Assert.assertEquals(writer.toString(),
|
||||||
"row0cell0,row0cell1\n" +
|
prefix
|
||||||
"row1cell0,row1cell1\n");
|
+ 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" +
|
@Test(enabled=false)
|
||||||
"row1cell0,row1cell1\n");
|
public void exportTemplateWithEmptyCells(){
|
||||||
|
|
||||||
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(){
|
|
||||||
CreateGrid(3,3);
|
CreateGrid(3,3);
|
||||||
|
|
||||||
project.rows.get(1).cells.set(1, null);
|
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.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -17,6 +16,8 @@ import org.testng.annotations.BeforeMethod;
|
|||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
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.browsing.Engine;
|
||||||
import com.google.refine.exporters.StreamExporter;
|
import com.google.refine.exporters.StreamExporter;
|
||||||
import com.google.refine.exporters.XlsExporter;
|
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.ModelException;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
import com.google.refine.model.Row;
|
import com.google.refine.model.Row;
|
||||||
|
import com.google.refine.tests.ProjectManagerStub;
|
||||||
import com.google.refine.tests.RefineTest;
|
import com.google.refine.tests.RefineTest;
|
||||||
|
|
||||||
public class XlsExporterTests extends RefineTest {
|
public class XlsExporterTests extends RefineTest {
|
||||||
|
|
||||||
|
private static final String TEST_PROJECT_NAME = "xls exporter test project";
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void init() {
|
public void init() {
|
||||||
logger = LoggerFactory.getLogger(this.getClass());
|
logger = LoggerFactory.getLogger(this.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
OutputStream stream;
|
ByteArrayOutputStream stream;
|
||||||
|
ProjectMetadata projectMetadata;
|
||||||
Project project;
|
Project project;
|
||||||
Engine engine;
|
Engine engine;
|
||||||
Properties options;
|
Properties options;
|
||||||
@ -47,7 +52,11 @@ public class XlsExporterTests extends RefineTest {
|
|||||||
public void SetUp(){
|
public void SetUp(){
|
||||||
SUT = new XlsExporter();
|
SUT = new XlsExporter();
|
||||||
stream = new ByteArrayOutputStream();
|
stream = new ByteArrayOutputStream();
|
||||||
|
ProjectManager.singleton = new ProjectManagerStub();
|
||||||
|
projectMetadata = new ProjectMetadata();
|
||||||
project = new Project();
|
project = new Project();
|
||||||
|
projectMetadata.setName(TEST_PROJECT_NAME);
|
||||||
|
ProjectManager.singleton.registerProject(project, projectMetadata);
|
||||||
engine = new Engine(project);
|
engine = new Engine(project);
|
||||||
options = mock(Properties.class);
|
options = mock(Properties.class);
|
||||||
}
|
}
|
||||||
@ -56,13 +65,14 @@ public class XlsExporterTests extends RefineTest {
|
|||||||
public void TearDown(){
|
public void TearDown(){
|
||||||
SUT = null;
|
SUT = null;
|
||||||
stream = null;
|
stream = null;
|
||||||
|
ProjectManager.singleton.deleteProject(project.id);
|
||||||
project = null;
|
project = null;
|
||||||
engine = null;
|
engine = null;
|
||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exportSimpleCsv(){
|
public void exportSimpleXls(){
|
||||||
CreateGrid(2, 2);
|
CreateGrid(2, 2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -71,14 +81,14 @@ public class XlsExporterTests extends RefineTest {
|
|||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(stream.toString(), "column0,column1\n" +
|
// TODO: Not a very effective test!
|
||||||
"row0cell0,row0cell1\n" +
|
// (it didn't crash though, and it created output)
|
||||||
"row1cell0,row1cell1\n");
|
Assert.assertEquals(stream.size(),4096);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(enabled=false)
|
||||||
public void exportSimpleCsvNoHeader(){
|
public void exportSimpleXlsNoHeader(){
|
||||||
CreateGrid(2, 2);
|
CreateGrid(2, 2);
|
||||||
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
||||||
try {
|
try {
|
||||||
@ -93,59 +103,9 @@ public class XlsExporterTests extends RefineTest {
|
|||||||
verify(options,times(2)).getProperty("printColumnHeader");
|
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));
|
@Test(enabled=false)
|
||||||
try {
|
public void exportXlsWithEmptyCells(){
|
||||||
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(){
|
|
||||||
CreateGrid(3,3);
|
CreateGrid(3,3);
|
||||||
|
|
||||||
project.rows.get(1).cells.set(1, null);
|
project.rows.get(1).cells.set(1, null);
|
||||||
|
Loading…
Reference in New Issue
Block a user