use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.
the class EnvironmentApiConverterTest method testInitEditDto.
@Test
void testInitEditDto() {
EnvironmentEditRequest request = createEditEnvironmentRequest();
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
Features features = mock(Features.class);
NetworkDto networkDto = mock(NetworkDto.class);
when(accountTelemetry.getFeatures()).thenReturn(features);
when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
EnvironmentEditDto actual = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initEditDto(request));
assertEquals("test-aws", actual.getAccountId());
assertEquals(request.getDescription(), actual.getDescription());
assertEquals(environmentTelemetry, actual.getTelemetry());
assertAuthentication(request.getAuthentication(), actual.getAuthentication());
assertEquals(request.getAdminGroupName(), actual.getAdminGroupName());
assertSecurityAccess(request.getSecurityAccess(), actual.getSecurityAccess());
verify(accountTelemetry).getFeatures();
verify(accountTelemetryService).getOrDefault(any());
verify(telemetryApiConverter).convert(eq(request.getTelemetry()), any(), anyString());
verify(networkRequestToDtoConverter).convert(request.getNetwork());
}
use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.
the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName.
@Test
void testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName() {
EnvironmentRequest request = createEnvironmentRequest(AZURE);
request.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withName("myResourceGroup").build()).build());
FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
Features features = mock(Features.class);
NetworkDto networkDto = mock(NetworkDto.class);
when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
when(accountTelemetry.getFeatures()).thenReturn(features);
when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
EnvironmentCreationDto actual = testInitCreationDto(request);
assertNull(actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName());
}
use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.
the class EnvironmentApiConverterTest method testAzureResourceEncryptionParametersAndAzureRequest.
@Test
void testAzureResourceEncryptionParametersAndAzureRequest() {
EnvironmentRequest request = createEnvironmentRequest(AZURE);
request.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_URL_RESOURCE_GROUP).build()).build());
FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
Features features = mock(Features.class);
NetworkDto networkDto = mock(NetworkDto.class);
when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
when(accountTelemetry.getFeatures()).thenReturn(features);
when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
EnvironmentCreationDto actual = testInitCreationDto(request);
assertEquals(KEY_URL, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
assertEquals(KEY_URL_RESOURCE_GROUP, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.
the class AccountTelemetryService method getOrDefault.
public AccountTelemetry getOrDefault(String accountId) {
try {
LOGGER.debug("Get account telemetry for account: {}", accountId);
Optional<AccountTelemetry> telemetry = accountTelemetryRepository.findByAccountId(accountId);
return telemetry.orElse(createDefaultAccuontTelemetry());
} catch (DataIntegrityViolationException e) {
throw new AccessDeniedException("Access denied", e);
}
}
use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.
the class AccountTelemetryConverter method convert.
public AccountTelemetry convert(AccountTelemetryRequest request) {
AccountTelemetry telemetry = null;
if (request != null) {
telemetry = new AccountTelemetry();
telemetry.setFeatures(convertFeatures(request.getFeatures()));
telemetry.setRules(request.getRules());
}
return telemetry;
}
Aggregations