1

I have controller on groovy

@RestController
@RequestMapping('/v1')
@CompileStatic
class DatasourceResource {

    private final DatasourceService datasourceService

    @Autowired
    DatasourceResource(final DatasourceService datasourceService) {
        this.datasourceService = datasourceService
    }
    @Secured(hasAuthority = 'RADAR_LITE_SERVICE_DATA_ACCESS')
    @GetMapping(value = '`/datasources/types', headers = 'token', produces = MediaType.APPLICATION_JSON_VALUE)
    Response<List<String>> getDatabaseType() {
        return new Response(DatabaseType.values()*.toString())
    }
}

I wrote simple test on java

@RunWith(SpringRunner.class)
@WebMvcTest(DatasourceResource.class)
public class DatasourceResourceTest {

    @MockBean
    private DatasourceService datasourceService;
    @Autowired
    private MockMvc mockMvc;

    @Test
    public void getDatabaseType() throws Exception {
        mockMvc.perform(post("/v1/datasources/types"))
                .andExpect(status().isOk());
    }
}

But when i run test, it stucking on 'instantiate tests' step in IDEA. Test task just stucking even when i start this task from terminal. And its stucks only on it test, if i remove @WebMvcTest annotation and mockMvc field and test body it will not stuck, and will passed. Looks like spring cant start context or tomcat. How can i check this or fix?

We using SpringBoot 2.1.0.RELEASE

newakkoff
  • 270
  • 2
  • 13

1 Answers1

1

Okay. Problem was in configuration of config service connection. Soma bad guy(not me) placed this in bootstrap.yml file

retry:
        max-attempts: 10000

and when i started @WebMvcTest he tried to connect to config service 1000 times, and its looks like it stack. I created bootstrap.yml in test package to override this config.

spring:
  cloud:
    config:
      enabled: false

And now its do not trying connect to config service and start with default properties. If you now how i can do it more right way, please, let me know!

newakkoff
  • 270
  • 2
  • 13