Search in sources :

Example 1 with VaultModel

use of com.github.nagyesta.lowkeyvault.http.management.VaultModel in project lowkey-vault by nagyesta.

the class ManagementStepDefs method deletedVaultListContainsVaultNameWithDeletedOnPopulated.

@And("deleted vault list contains {name} with deletedOn populated")
public void deletedVaultListContainsVaultNameWithDeletedOnPopulated(final String vaultName) {
    final List<VaultModel> models = context.getClient().listDeletedVaults();
    final Optional<VaultModel> found = models.stream().filter(v -> v.getBaseUri().getHost().startsWith(vaultName)).findAny();
    assertTrue(found.isPresent());
    // noinspection OptionalGetWithoutIsPresent
    final OffsetDateTime deletedOn = found.get().getDeletedOn();
    assertNotNull(deletedOn);
    assertTrue(deletedOn.isBefore(OffsetDateTime.now()));
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) java.util(java.util) Then(io.cucumber.java.en.Then) When(io.cucumber.java.en.When) ApacheHttpClientProvider(com.github.nagyesta.lowkeyvault.http.ApacheHttpClientProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RecoveryLevel(com.github.nagyesta.lowkeyvault.http.management.RecoveryLevel) ManagementTestContext(com.github.nagyesta.lowkeyvault.context.ManagementTestContext) And(io.cucumber.java.en.And) OffsetDateTime(java.time.OffsetDateTime) AuthorityOverrideFunction(com.github.nagyesta.lowkeyvault.http.AuthorityOverrideFunction) Given(io.cucumber.java.en.Given) CONTAINER_AUTHORITY(com.github.nagyesta.lowkeyvault.context.TestContextConfig.CONTAINER_AUTHORITY) VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) TimeShiftContext(com.github.nagyesta.lowkeyvault.http.management.TimeShiftContext) URI(java.net.URI) OffsetDateTime(java.time.OffsetDateTime) And(io.cucumber.java.en.And)

Example 2 with VaultModel

use of com.github.nagyesta.lowkeyvault.http.management.VaultModel in project lowkey-vault by nagyesta.

the class ManagementStepDefs method theVaultNamedVaultNameIsRecovered.

@And("the vault named {name} is recovered")
public void theVaultNamedVaultNameIsRecovered(final String vaultName) {
    final String vaultUrl = vaultNameToUrl(vaultName);
    final VaultModel model = context.getClient().recover(URI.create(vaultUrl));
    assertNotNull(model);
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) And(io.cucumber.java.en.And)

Example 3 with VaultModel

use of com.github.nagyesta.lowkeyvault.http.management.VaultModel in project lowkey-vault by nagyesta.

the class ResponseEntityTest method testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithSingleObject.

@Test
void testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithSingleObject() {
    // given
    final VaultModel expected = new VaultModel(URI.create(HTTPS_DEFAULT_LOCALHOST_8443), null, null, null, null);
    final HttpResponse response = mock(HttpResponse.class);
    when(response.getStatusCode()).thenReturn(HttpStatus.SC_OK);
    when(response.getBodyAsString(eq(StandardCharsets.UTF_8))).thenReturn(Mono.just(VAULT_MODEL));
    final ObjectReader reader = new ObjectMapper().reader();
    final ResponseEntity underTest = new ResponseEntity(response, reader);
    // when
    final VaultModel actual = underTest.getResponseObject(VaultModel.class);
    // then
    Assertions.assertEquals(expected, actual);
    verify(response).getStatusCode();
    verify(response).getBodyAsString(eq(StandardCharsets.UTF_8));
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) HttpResponse(com.azure.core.http.HttpResponse) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with VaultModel

use of com.github.nagyesta.lowkeyvault.http.management.VaultModel in project lowkey-vault by nagyesta.

the class ResponseEntityTest method testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithList.

@Test
void testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithList() {
    // given
    final VaultModel vaultModel = new VaultModel(URI.create(HTTPS_DEFAULT_LOCALHOST_8443), null, null, null, null);
    final List<VaultModel> expected = Collections.singletonList(vaultModel);
    final HttpResponse response = mock(HttpResponse.class);
    when(response.getStatusCode()).thenReturn(HttpStatus.SC_OK);
    when(response.getBodyAsString(eq(StandardCharsets.UTF_8))).thenReturn(Mono.just(VAULT_MODEL_LIST));
    final ObjectReader reader = new ObjectMapper().reader();
    final ResponseEntity underTest = new ResponseEntity(response, reader);
    // when
    final List<VaultModel> actual = underTest.getResponseObject(VAULT_MODEL_LIST_TYPE_REF);
    // then
    Assertions.assertEquals(expected, actual);
    verify(response).getStatusCode();
    verify(response).getBodyAsString(eq(StandardCharsets.UTF_8));
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) HttpResponse(com.azure.core.http.HttpResponse) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with VaultModel

use of com.github.nagyesta.lowkeyvault.http.management.VaultModel in project lowkey-vault by nagyesta.

the class ManagementStepDefs method vaultListContainsVaultNameWithDeletedOnAsNull.

@And("vault list contains {name} with deletedOn as null")
public void vaultListContainsVaultNameWithDeletedOnAsNull(final String vaultName) {
    final List<VaultModel> models = context.getClient().listVaults();
    final Optional<VaultModel> found = models.stream().filter(v -> v.getBaseUri().getHost().startsWith(vaultName)).findAny();
    assertTrue(found.isPresent());
    // noinspection OptionalGetWithoutIsPresent
    final VaultModel vaultModel = found.get();
    assertNull(vaultModel.getDeletedOn());
    assertTrue(vaultModel.getCreatedOn().isBefore(OffsetDateTime.now()));
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) java.util(java.util) Then(io.cucumber.java.en.Then) When(io.cucumber.java.en.When) ApacheHttpClientProvider(com.github.nagyesta.lowkeyvault.http.ApacheHttpClientProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RecoveryLevel(com.github.nagyesta.lowkeyvault.http.management.RecoveryLevel) ManagementTestContext(com.github.nagyesta.lowkeyvault.context.ManagementTestContext) And(io.cucumber.java.en.And) OffsetDateTime(java.time.OffsetDateTime) AuthorityOverrideFunction(com.github.nagyesta.lowkeyvault.http.AuthorityOverrideFunction) Given(io.cucumber.java.en.Given) CONTAINER_AUTHORITY(com.github.nagyesta.lowkeyvault.context.TestContextConfig.CONTAINER_AUTHORITY) VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) TimeShiftContext(com.github.nagyesta.lowkeyvault.http.management.TimeShiftContext) URI(java.net.URI) And(io.cucumber.java.en.And)

Aggregations

VaultModel (com.github.nagyesta.lowkeyvault.http.management.VaultModel)5 And (io.cucumber.java.en.And)3 HttpResponse (com.azure.core.http.HttpResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)2 ManagementTestContext (com.github.nagyesta.lowkeyvault.context.ManagementTestContext)2 CONTAINER_AUTHORITY (com.github.nagyesta.lowkeyvault.context.TestContextConfig.CONTAINER_AUTHORITY)2 ApacheHttpClientProvider (com.github.nagyesta.lowkeyvault.http.ApacheHttpClientProvider)2 AuthorityOverrideFunction (com.github.nagyesta.lowkeyvault.http.AuthorityOverrideFunction)2 RecoveryLevel (com.github.nagyesta.lowkeyvault.http.management.RecoveryLevel)2 TimeShiftContext (com.github.nagyesta.lowkeyvault.http.management.TimeShiftContext)2 Given (io.cucumber.java.en.Given)2 Then (io.cucumber.java.en.Then)2 When (io.cucumber.java.en.When)2 URI (java.net.URI)2 OffsetDateTime (java.time.OffsetDateTime)2 java.util (java.util)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2