use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.
the class MapHelperTest method getNestedMap_returnsValue_forNestedSupplier.
@Test
void getNestedMap_returnsValue_forNestedSupplier() {
LocalDate date = LocalDate.of(2020, 1, 1);
Map<String, Object> data = new HashMap<>();
data.put("key", new DateSupplier(false, date));
Map<String, Object> arguments = Map.of("arg", Map.of("arg1", data));
Map<String, Object> result = getNestedMap(arguments, "arg");
assertThat(result, is(Map.of("arg1", Map.of("key", date))));
}
use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.
the class BackendRequestFactoryTest method initExecutionStepInfoMock.
private ExecutionStepInfo initExecutionStepInfoMock() {
var executionStepInfo = mock(ExecutionStepInfo.class);
var resultPath = ResultPath.rootPath().segment("a");
lenient().when(executionStepInfo.getPath()).thenReturn(resultPath);
var objectType = mock(GraphQLObjectType.class);
lenient().when(objectType.getName()).thenReturn("Brewery");
lenient().when(executionStepInfo.getType()).thenReturn(objectType);
var date = LocalDate.of(2021, 1, 1);
Map<String, Object> data = new HashMap<>();
Map<String, Object> argument = Map.of("name", Map.of("eq", "name-value"));
data.put("key", new DateSupplier(false, date));
Map<String, Object> arguments = new HashMap<>();
arguments.put("arg", Map.of("arg1", data));
arguments.put("filter", argument);
lenient().when(executionStepInfo.getArguments()).thenReturn(arguments);
lenient().when(executionStepInfo.getArgument(eq("filter"))).thenReturn(argument);
lenient().when(executionStepInfo.getArgument(eq("sort"))).thenReturn("NAME");
var fieldDefinitionBuilder = newFieldDefinition();
List<GraphQLArgument> argumentList = new ArrayList<>();
fieldDefinitionBuilder.arguments(argumentList);
fieldDefinitionBuilder.name("a");
fieldDefinitionBuilder.description("any");
fieldDefinitionBuilder.type(mock(GraphQLOutputType.class));
fieldDefinitionBuilder.definition(FieldDefinition.newFieldDefinition().build());
when(executionStepInfo.getFieldDefinition()).thenReturn(fieldDefinitionBuilder.build());
return executionStepInfo;
}
use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.
the class BackendRequestFactoryTest method createRequestContext_returnsRequestContext_whithObjectFieldType_Address.
@Test
void createRequestContext_returnsRequestContext_whithObjectFieldType_Address() {
LocalDate date = LocalDate.of(2021, 1, 1);
Map<String, Object> data = new HashMap<>();
data.put("key", new DateSupplier(false, date));
Map<String, Object> source = Map.of("arg", Map.of("arg1", data));
DataFetchingEnvironmentImpl.Builder envBuilder = new DataFetchingEnvironmentImpl.Builder();
envBuilder.source(source);
ExecutionStepInfo executionStepInfo = mock(ExecutionStepInfo.class);
GraphQLObjectType objectType = mock(GraphQLObjectType.class);
when(objectType.getName()).thenReturn("Brewery");
when(executionStepInfo.getObjectType()).thenReturn(objectType);
MergedField mergedField = mock(MergedField.class);
when(mergedField.getName()).thenReturn("addresses");
when(executionStepInfo.getField()).thenReturn(mergedField);
envBuilder.executionStepInfo(executionStepInfo);
envBuilder.fieldDefinition(newFieldDefinition().name("field").type(Scalars.GraphQLID).definition(FieldDefinition.newFieldDefinition().additionalData(GraphQlConstants.IS_PAGING_NODE, Boolean.TRUE.toString()).build()).build());
envBuilder.fieldDefinition(newFieldDefinition().name("field").type(Scalars.GraphQLID).definition(FieldDefinition.newFieldDefinition().additionalData(GraphQlConstants.IS_PAGING_NODE, Boolean.TRUE.toString()).build()).build());
var schema = testHelper.loadSchema("dotwebstack/dotwebstack-objecttypes.yaml");
var backendRequestFactory = new BackendRequestFactory(schema, new BackendExecutionStepInfo());
var result = backendRequestFactory.createRequestContext(envBuilder.build());
assertThat(result, is(notNullValue()));
assertThat(result.getObjectField().getName(), is("addresses"));
assertThat(result.getObjectField().getType(), is("Address"));
}
use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.
the class MapHelperTest method getNestedMap_returnsValue_forSupplier.
@Test
void getNestedMap_returnsValue_forSupplier() {
LocalDate date = LocalDate.of(2020, 1, 1);
Map<String, Object> data = new HashMap<>();
data.put("key", new DateSupplier(false, date));
Map<String, Object> arguments = Map.of("arg", data);
Map<String, Object> result = getNestedMap(arguments, "arg");
assertThat(result, is(Map.of("key", date)));
}
Aggregations