Search in sources :

Example 6 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class CSVExportFormatterTest method testProjectionWithNullAttributesHeader.

@Test
public void testProjectionWithNullAttributesHeader() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    // Prepare EntityProjection
    Set<Attribute> attributes = null;
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    String output = formatter.preFormat(projection, queryObj);
    assertEquals("", output);
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 7 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class CSVExportFormatterTest method testResourceToCSV.

@Test
public void testResourceToCSV() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    String query = "{ tableExport { edges { node { query queryType createdOn} } } }";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    queryObj.setResultType(ResultType.CSV);
    String row = "\"{ tableExport { edges { node { query queryType createdOn} } } }\", \"GRAPHQL_V1_0\"" + ", \"" + FORMATTER.format(queryObj.getCreatedOn());
    // Prepare EntityProjection
    Set<Attribute> attributes = new LinkedHashSet<>();
    attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("query").build());
    attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
    attributes.add(Attribute.builder().type(TableExport.class).name("createdOn").build());
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    Map<String, Object> resourceAttributes = new LinkedHashMap<>();
    resourceAttributes.put("query", query);
    resourceAttributes.put("queryType", queryObj.getQueryType());
    resourceAttributes.put("createdOn", queryObj.getCreatedOn());
    Resource resource = new Resource("tableExport", "0", resourceAttributes, null, null, null);
    PersistentResource persistentResource = mock(PersistentResource.class);
    when(persistentResource.getObject()).thenReturn(queryObj);
    when(persistentResource.getRequestScope()).thenReturn(scope);
    when(persistentResource.toResource(any(), any())).thenReturn(resource);
    when(scope.getEntityProjection()).thenReturn(projection);
    String output = formatter.format(persistentResource, 1);
    assertTrue(output.contains(row));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) PersistentResource(com.yahoo.elide.core.PersistentResource) Attribute(com.yahoo.elide.core.request.Attribute) Resource(com.yahoo.elide.jsonapi.models.Resource) PersistentResource(com.yahoo.elide.core.PersistentResource) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 8 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class CSVExportFormatterTest method testHeader.

@Test
public void testHeader() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    String query = "{ tableExport { edges { node { query queryType } } } }";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    queryObj.setResultType(ResultType.CSV);
    // Prepare EntityProjection
    Set<Attribute> attributes = new LinkedHashSet<>();
    attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("query").build());
    attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    String output = formatter.preFormat(projection, queryObj);
    assertEquals("\"query\",\"queryType\"", output);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 9 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class CSVExportFormatterTest method testHeaderWithArguments.

@Test
public void testHeaderWithArguments() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    String query = "{ tableExport { edges { node { query queryType } } } }";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    queryObj.setResultType(ResultType.CSV);
    // Prepare EntityProjection
    Set<Attribute> attributes = new LinkedHashSet<>();
    attributes.add(Attribute.builder().type(TableExport.class).name("query").argument(Argument.builder().name("foo").value("bar").build()).alias("query").build());
    attributes.add(Attribute.builder().type(TableExport.class).argument(Argument.builder().name("foo").value("bar").build()).argument(Argument.builder().name("baz").value("boo").build()).name("queryType").build());
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    String output = formatter.preFormat(projection, queryObj);
    assertEquals("\"query(foo=bar)\",\"queryType(foo=bar baz=boo)\"", output);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 10 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class CSVExportFormatterTest method testProjectionWithEmptyAttributeSetHeader.

@Test
public void testProjectionWithEmptyAttributeSetHeader() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    // Prepare EntityProjection
    Set<Attribute> attributes = new LinkedHashSet<>();
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    String output = formatter.preFormat(projection, queryObj);
    assertEquals("", output);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (com.yahoo.elide.core.request.Attribute)24 Test (org.junit.jupiter.api.Test)19 EntityProjection (com.yahoo.elide.core.request.EntityProjection)11 TableExport (com.yahoo.elide.async.models.TableExport)9 LinkedHashSet (java.util.LinkedHashSet)8 LinkedHashMap (java.util.LinkedHashMap)5 Argument (com.yahoo.elide.core.request.Argument)4 PersistentResource (com.yahoo.elide.core.PersistentResource)3 Resource (com.yahoo.elide.jsonapi.models.Resource)3 PersistentResourceFetcherTest (com.yahoo.elide.graphql.PersistentResourceFetcherTest)2 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)2 Parent (example.Parent)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Path (com.yahoo.elide.core.Path)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 InvalidEntityBodyException (com.yahoo.elide.core.exceptions.InvalidEntityBodyException)1 InvalidParameterizedAttributeException (com.yahoo.elide.core.exceptions.InvalidParameterizedAttributeException)1