microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
93 stars 68 forks source link

Issues using WebTestClient without enabling repository beans #530

Open thomasmillergb opened 4 years ago

thomasmillergb commented 4 years ago

There seems to be a hole in the ability to tests a SpringFlux application at the controller level without loading up the cosmos context. Ie i just want to test my controller without connecting cosmos

As i would expect to be able to do the following without the cosmos repo being loaded in. As all classes with the @Repository should be ignored.

@ExtendWith(SpringExtension.class)
@WebFluxTest(controllers = MyController.class)
class ControllerTest {
    @Autowired
    private WebTestClient webTestClient;
}

However doing this leads to bean failures in AbstractCosmosConfiguration

It seems there are a couple of issues preventing me from creating a unit tests ,

  1. extending AbstractCosmosConfiguration.class means i need to mock every bean
  2. extending ReactiveCosmosRepository.class with Repository annotation is not respected

Maybe i am missing something or have done something wrong, but there is no documentation testing.

For context by config is


@Configuration
@EnableReactiveCosmosRepositories
public class CosmosConfig extends AbstractCosmosConfiguration {

    @Bean
    public CosmosDBConfig cosmosDatabase(
            @Value("${PRIMARY_KEY_SECRET}") String primaryKeySecret,
            @Value("${COSMOS_DB_URI}") String azureDocumentUrl,
            @Value("${COSMOS_DB_NAME}") String databaseName
    ){
        return CosmosDBConfig.builder(azureDocumentUrl, primaryKeySecret, databaseName).build();
    }
}

And my repo is


@Repository
public interface CosmosTestRepository extends ReactiveCosmosRepository<TestPojo, String> {

}