use of uk.gov.gchq.gaffer.operation.impl.output.ToCsv in project Gaffer by gchq.
the class ToCsvHandlerTest method shouldConvertToCsvWithCommaReplacement.
@Test
public void shouldConvertToCsvWithCommaReplacement() throws OperationException {
// Given
final List<Element> elements = Lists.newArrayList(makeEntity("vertex1,with comma", "count", 1), makeEntity("vertex2"), makeEdge("source1,with comma", "count", 1), makeEdge("source2"));
final ToCsv operation = new ToCsv.Builder().input(elements).generator(new CsvGenerator.Builder().group("Group Label").vertex("Vertex Label").source("Source Label").property("count", "Count Label").constant("A Constant", "Some constant value").quoted(false).commaReplacement("-").build()).includeHeader(false).build();
final ToCsvHandler handler = new ToCsvHandler();
// When
final Iterable<? extends String> results = handler.doOperation(operation, new Context(), null);
// Then
final List<String> resultList = Lists.newArrayList(results);
final List<String> expected = Arrays.asList("Foo,vertex1-with comma,,1,A Constant", "Foo,vertex2,,,A Constant", "Bar,,source1-with comma,1,A Constant", "Bar,,source2,,A Constant");
assertEquals(expected, resultList);
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToCsv in project Gaffer by gchq.
the class ToCsvHandlerTest method shouldConvertToCsv.
@Test
public void shouldConvertToCsv() throws OperationException {
// Given
final List<Element> elements = Lists.newArrayList(makeEntity("vertex1", "count", 1), makeEntity("vertex2"), makeEdge("source1", "count", 1), makeEdge("source2"));
final ToCsv operation = new ToCsv.Builder().input(elements).generator(new CsvGenerator.Builder().group("Group Label").vertex("Vertex Label").source("Source Label").property("count", "Count Label").constant("A Constant", "Some constant value").quoted(false).build()).includeHeader(false).build();
final ToCsvHandler handler = new ToCsvHandler();
// When
final Iterable<? extends String> results = handler.doOperation(operation, new Context(), null);
// Then
final List<String> resultList = Lists.newArrayList(results);
final List<String> expected = Arrays.asList("Foo,vertex1,,1,A Constant", "Foo,vertex2,,,A Constant", "Bar,,source1,1,A Constant", "Bar,,source2,,A Constant");
assertEquals(expected, resultList);
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToCsv in project Gaffer by gchq.
the class ToCsvHandlerTest method shouldConvertToCsvWithHeader.
@Test
public void shouldConvertToCsvWithHeader() throws OperationException {
// Given
final List<Element> elements = Lists.newArrayList(makeEntity("vertex1", "count", 1), makeEntity("vertex2"), makeEdge("source1", "count", 1), makeEdge("source2"));
final ToCsv operation = new ToCsv.Builder().input(elements).generator(new CsvGenerator.Builder().group("Group Label").vertex("Vertex Label").source("Source Label").property("count", "Count Label").constant("A Constant", "Some constant value").quoted(false).build()).includeHeader(true).build();
final ToCsvHandler handler = new ToCsvHandler();
// When
final Iterable<? extends String> results = handler.doOperation(operation, new Context(), null);
// Then
final List<String> resultList = Lists.newArrayList(results);
final List<String> expected = Arrays.asList("Group Label,Vertex Label,Source Label,Count Label,Some constant value", "Foo,vertex1,,1,A Constant", "Foo,vertex2,,,A Constant", "Bar,,source1,1,A Constant", "Bar,,source2,,A Constant");
assertEquals(expected, resultList);
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToCsv in project Gaffer by gchq.
the class ToCsvHandlerTest method shouldConvertToQuotedCsv.
@Test
public void shouldConvertToQuotedCsv() throws OperationException {
// Given
final List<Element> elements = Lists.newArrayList(makeEntity("vertex1", "count", 1), makeEntity("vertex2"), makeEdge("source1", "count", 1), makeEdge("source2"));
final ToCsv operation = new ToCsv.Builder().input(elements).generator(new CsvGenerator.Builder().group("Group Label").vertex("Vertex Label").source("Source Label").property("count", "Count Label").constant("A Constant", "Some constant value").quoted(true).build()).includeHeader(false).build();
final ToCsvHandler handler = new ToCsvHandler();
// When
final Iterable<? extends String> results = handler.doOperation(operation, new Context(), null);
// Then
final List<String> resultList = Lists.newArrayList(results);
final List<String> expected = Arrays.asList("\"Foo\",\"vertex1\",,\"1\",\"A Constant\"", "\"Foo\",\"vertex2\",,,\"A Constant\"", "\"Bar\",,\"source1\",\"1\",\"A Constant\"", "\"Bar\",,\"source2\",,\"A Constant\"");
assertEquals(expected, resultList);
}
Aggregations