use of com.yahoo.elide.core.PersistentResource 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));
}
use of com.yahoo.elide.core.PersistentResource 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.PersistentResource in project elide by yahoo.
the class JSONExportFormatterTest method testNullResourceToJSON.
@Test
public void testNullResourceToJSON() {
JSONExportFormatter formatter = new JSONExportFormatter(elide);
PersistentResource persistentResource = null;
String output = formatter.format(persistentResource, 1);
assertNull(output);
}
use of com.yahoo.elide.core.PersistentResource 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));
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class SubscriptionDataFetcher method get.
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
OperationDefinition.Operation op = environment.getOperationDefinition().getOperation();
if (op != OperationDefinition.Operation.SUBSCRIPTION) {
throw new InvalidEntityBodyException(String.format("%s not supported for subscription models.", op));
}
/* build environment object, extracts required fields */
Environment context = new Environment(environment, nonEntityDictionary);
/* safe enable debugging */
if (log.isDebugEnabled()) {
logContext(log, RelationshipOp.FETCH, context);
}
if (context.isRoot()) {
String entityName = context.field.getName();
String aliasName = context.field.getAlias();
EntityProjection projection = context.requestScope.getProjectionInfo().getProjection(aliasName, entityName);
Flowable<PersistentResource> recordPublisher = PersistentResource.loadRecords(projection, new ArrayList<>(), context.requestScope).toFlowable(BackpressureStrategy.BUFFER).onBackpressureBuffer(bufferSize, true, false);
return recordPublisher.map(SubscriptionNodeContainer::new);
}
// as the PersistentResourceFetcher.
return context.container.processFetch(context);
}
Aggregations