Error executing queries for integration test #1009
-
|
Edited: Hi I can't seem to be able to test my queries using WebClient. I want to simply assert the value of a field but I can't seem to print the String value. If I print System.out.println(mono) it shows as MonoMapFusable. I also tried suggestions here https://stackoverflow.com/questions/57353856/how-to-extract-string-from-monostring-in-reactor-core
but it doesnt print anything It seems like the issue is that my I have attached the error and my code |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Could you please share some code sample to reproduce? It's hard to pinpoint
just looking at that error.
…On Mon, Apr 25, 2022 at 6:56 AM Sonali Sharma ***@***.***> wrote:
Hi I can't seem to find an example on integration testing queries. I saw
an example for testing subscriptions
https://netflix.github.io/dgs/advanced/subscriptions/
and tried to test my queries with this code (modifying the URL) , however
I get the error:
reactor.core.Exceptions$ErrorCallbackNotImplemented:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection
refused: no further information: localhost/127.0.0.1:8080
Any way to resolve this? Thanks :)
—
Reply to this email directly, view it on GitHub
<#1009>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXIBCBFCJ7HI2AAFPP3VG2QA3ANCNFSM5UIVJD7Q>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Took me ages to get a client going, my fault, not the fault of the library. I ended up creating a common function to be called by my integration tests. public static String simpleJsonCall(String query, String JSONPath) {
// The GraphQLResponse contains data and errors.
Mono<GraphQLResponse> graphQLResponseMono = graphQLClient.reactiveExecuteQuery(query);
Mono<LinkedHashMap> obj = graphQLResponseMono.flatMap(r -> {
if (r.hasErrors()) {
log.error("[simpleJsonCall] {}", r.getErrors().toString());
return Mono.error(new RuntimeException(r.getErrors().toString()));
}
if (r.extractValue(JSONPath) == null) {
log.error("[simpleJsonCall] No results found for {}", JSONPath);
return Mono.empty();
} else {
if (r.extractValue(JSONPath) instanceof LinkedHashMap) {
return Mono.just(r.extractValue(JSONPath));
} else {
log.error("[simpleJsonCall] Expected LinkedHashMap but found {}",
r.extractValue(JSONPath).getClass().getName());
return Mono.empty();
}
//return Mono.just(r.extractValue(JSONPath));
}
});
// Execute call to web server.
obj.subscribe();
// Parse the response to a JSON string.
ObjectMapper mapper = new ObjectMapper();
String jsonResult = "";
obj.metrics();
if (obj.blockOptional().isPresent()) {
try {
jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj.block());
} catch (Exception e) {
log.error(e.getMessage());
}
log.info(jsonResult);
}
return jsonResult;
}Then after using the typesafe query generator I call it like this . results = RunTestLocally.simpleJsonCall(localGraphQLQueryRequest.serialize(),"address[0].regexSuburb");Then I assert the results assertThat(results)
.contains("regexSuburb")
.contains( other stuff);Does this help ? |
Beta Was this translation helpful? Give feedback.
Took me ages to get a client going, my fault, not the fault of the library.
I ended up creating a common function to be called by my integration tests.