Skip to content

Instantly share code, notes, and snippets.

@sureshgadupu
Last active August 14, 2021 09:30
Show Gist options
  • Save sureshgadupu/127ced9f1c046da1c35cdbe888b7f1b4 to your computer and use it in GitHub Desktop.
Save sureshgadupu/127ced9f1c046da1c35cdbe888b7f1b4 to your computer and use it in GitHub Desktop.
@Test
public void test_notifyEmployeeCreation() throws JsonMappingException, JsonProcessingException {
ExecutionResult notifyEmployeeCreationSubscription = dgsQueryExecutor.execute(
"subscription { notifyEmployeeCreation { id first_name last_name gender hire_date birth_date} }");
Publisher<ExecutionResult> publisher = notifyEmployeeCreationSubscription.getData();
publisher.subscribe(new Subscriber<ExecutionResult>() {
@Override
public void onSubscribe(Subscription s) {
s.request(1);
;
}
@Override
public void onNext(ExecutionResult executionResult) {
assertThat(executionResult.getErrors()).isEmpty();
Map<String, Object> empData = executionResult.getData();
try {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
Employee emp = objectMapper.convertValue(empData.get("notifyEmployeeCreation"), Employee.class);
assertThat(emp.getFirst_name()).isEqualTo("Suresh");
assertThat(emp.getLast_name()).isEqualTo("Gadupu");
assertThat(emp.getGender()).isEqualTo(Gender.M);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onError(Throwable t) {
System.out.println(t);
assertThat(t).isNull();
}
@Override
public void onComplete() {
}
});
ExecutionResult createEmployeeResult = dgsQueryExecutor.execute(
"mutation { createEmployee (employee : {first_name :\"Suresh\" , last_name : \"Gadupu\" , deptId : 1 ,gender : M , hire_date : \"2014-12-02\" , birth_date:\"1980-12-11\" }) {id first_name last_name gender hire_date birth_date } }");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment