Search in sources :

Example 1 with ToCsv

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with ToCsv

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) Test(org.junit.jupiter.api.Test)

Example 3 with ToCsv

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) Test(org.junit.jupiter.api.Test)

Example 4 with ToCsv

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 ToCsv (uk.gov.gchq.gaffer.operation.impl.output.ToCsv)4 Context (uk.gov.gchq.gaffer.store.Context)4 CsvGenerator (uk.gov.gchq.gaffer.data.generator.CsvGenerator)1