Integration Test fails, /graphql enpoint not found
See original GitHub issueIf i try to execute an integration test the graphql endpoint is not found, the test returns a “404”
RunWith(SpringRunner.class)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@EnableConfigurationProperties(GraphQLServletProperties.class)
@TestPropertySource(
locations = "classpath:application-integrationtest.yaml")
public class GraphQlControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void myTests() throws Exception {
String request = "{\"query\": \"query{groups{id}}\", \"variables\": null}";
ResultActions response = mvc.perform(post("/graphql").content(request).contentType(MediaType.APPLICATION_JSON));
response.andExpect(status().isOk());
}
}
output of the test is:
MockHttpServletRequest:
HTTP Method = POST
Request URI = /graphql
Parameters = {}
Headers = {Content-Type=[application/json;charset=UTF-8]}
Handler:
Type = org.springframework.web.servlet.resource.ResourceHttpRequestHandler
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 404
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
java.lang.AssertionError: Status
Expected :200
Actual :404
has anyone an working example for writing integration tests?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:5 (1 by maintainers)
Top Results From Across the Web
GraphQL Test returns 404 not found - Stack Overflow
I am not sure why this worked although the GraphQLTest interface has the @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.
Read more >Integration Test fails, /graphql enpoint not found - Bountysource
If i try to execute an integration test the graphql endpoint is not found, the test returns a "404" RunWith(SpringRunner.class) ...
Read more >Full Stack Error Handling with GraphQL and Apollo
If networkError is present in your response, it means your entire query was rejected, and therefore no data was returned. For example, the ......
Read more >Debug "Resource not accessible by integration" error when ...
This error basically talks about a permission issue. When working with Github apps, you may not have set the necessary permission to access...
Read more >Testing your GraphQL APIs in a Spring-boot app - Medium
If it's not already done, create this directory in your project: src/test/resources/graphql then create these 3 request file in it. create-user.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came to the conclusion that MockMvc is not supposed to be used for testing raw servlets, as here we are not exposing
/graphql
endpoint as a Spring MVC Controller, but rather as a rawHttpServlet
.The following works for me quite nicely:
and then:
I also have problems with the test. I also get the error 404 in the GraphQLResult. The loading of the test query getAllRoutes.graphql works, that I have checked. I think the problem is that the application will not start up, because the spring beans will not be created. I have set a few breakpoints that are not called.
The https://github.com/Thinkenterprise/spring-boot-graphql
Here is the excerpt from my test.