use of com.yahoo.elide.core.request.EntityProjection 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);
}
use of com.yahoo.elide.core.request.EntityProjection 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);
}
use of com.yahoo.elide.core.request.EntityProjection 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);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class JSONExportFormatterTest method testFormat.
@Test
public void testFormat() {
JSONExportFormatter formatter = new JSONExportFormatter(elide);
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 start = "{\"query\":\"{ tableExport { edges { node { query queryType createdOn} } } }\"," + "\"queryType\":\"GRAPHQL_V1_0\",\"createdOn\":\"" + 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(start));
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class JSONExportFormatterTest method testResourceToJSON.
@Test
public void testResourceToJSON() {
JSONExportFormatter formatter = new JSONExportFormatter(elide);
TableExport queryObj = new TableExport();
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
String start = "{\"query\":\"{ tableExport { edges { node { query queryType} } } }\"," + "\"queryType\":\"GRAPHQL_V1_0\"}";
// 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();
Map<String, Object> resourceAttributes = new LinkedHashMap<>();
resourceAttributes.put("query", "{ tableExport { edges { node { query queryType} } } }");
resourceAttributes.put("queryType", QueryType.GRAPHQL_V1_0);
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.resourceToJSON(elide.getMapper().getObjectMapper(), persistentResource);
assertTrue(output.contains(start));
}
Aggregations