Search in sources :

Example 1 with CosmosDbContainer

use of org.vividus.azure.cosmos.model.CosmosDbContainer in project vividus by vividus-framework.

the class CosmosDbServiceTests method testWithContainer.

private void testWithContainer(BiConsumer<CosmosDbContainer, CosmosContainer> testToRun, String containerId) {
    CosmosDbContainer dbContainer = new CosmosDbContainer();
    dbContainer.setId(containerId);
    dbContainer.setDbKey(DB_KEY);
    try (CosmosClient client = mock(CosmosClient.class);
        MockedConstruction<CosmosClientBuilder> builderConstructor = mockConstruction(CosmosClientBuilder.class, (mock, context) -> {
            when(mock.endpoint(ENDPOINT)).thenReturn(mock);
            when(mock.key(KEY)).thenReturn(mock);
            when(mock.connectionSharingAcrossClientsEnabled(true)).thenReturn(mock);
            when(mock.buildClient()).thenReturn(client);
        })) {
        when(client.getDatabase(DB)).thenReturn(database);
        when(database.getContainer(containerId)).thenReturn(container);
        testToRun.accept(dbContainer, container);
        assertThat(builderConstructor.constructed(), hasSize(1));
    }
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosDbContainer(org.vividus.azure.cosmos.model.CosmosDbContainer) CosmosClient(com.azure.cosmos.CosmosClient)

Aggregations

CosmosClient (com.azure.cosmos.CosmosClient)1 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)1 CosmosDbContainer (org.vividus.azure.cosmos.model.CosmosDbContainer)1