use of com.sequenceiq.consumption.dto.ConsumptionCreationDto in project cloudbreak by hortonworks.
the class ConsumptionDtoConverterTest method testConsumptionCreationDtoToConsumption.
@Test
void testConsumptionCreationDtoToConsumption() {
ConsumptionCreationDto creationDto = ConsumptionCreationDto.builder().withName(NAME).withDescription(DESCRIPTION).withEnvironmentCrn(ENVIRONMENT_CRN).withAccountId(ACCOUNT_ID).withResourceCrn(CONSUMPTION_CRN).withMonitoredResourceType(MONITORED_TYPE).withMonitoredResourceCrn(MONITORED_CRN).withConsumptionType(TYPE).withStorageLocation(STORAGE).build();
Consumption result = underTest.creationDtoToConsumption(creationDto);
assertEquals(NAME, result.getName());
assertEquals(DESCRIPTION, result.getDescription());
assertEquals(ENVIRONMENT_CRN, result.getEnvironmentCrn());
assertEquals(ACCOUNT_ID, result.getAccountId());
assertEquals(CONSUMPTION_CRN, result.getResourceCrn());
assertEquals(MONITORED_TYPE, result.getMonitoredResourceType());
assertEquals(MONITORED_CRN, result.getMonitoredResourceCrn());
assertEquals(TYPE, result.getConsumptionType());
assertEquals(STORAGE, result.getStorageLocation());
}
use of com.sequenceiq.consumption.dto.ConsumptionCreationDto in project cloudbreak by hortonworks.
the class ConsumptionServiceTest method testCreateWhenConsumptionAlreadyExists.
@Test
void testCreateWhenConsumptionAlreadyExists() {
ConsumptionCreationDto consumptionCreationDto = ConsumptionCreationDto.builder().withName(NAME).withConsumptionType(CONSUMPTION_TYPE).withEnvironmentCrn(ENVIRONMENT_CRN).withAccountId(ACCOUNT_ID).withResourceCrn(CRN).withMonitoredResourceType(RESOURCE_TYPE).withMonitoredResourceCrn(MONITORED_RESOURCE_CRN).withStorageLocation(STORAGE_LOCATION).build();
Consumption consumption = new Consumption();
consumption.setName(NAME);
consumption.setId(1L);
consumption.setAccountId(ACCOUNT_ID);
when(consumptionRepository.doesStorageConsumptionExistWithLocationForMonitoredCrn(MONITORED_RESOURCE_CRN, STORAGE_LOCATION)).thenReturn(true);
assertThrows(BadRequestException.class, () -> underTest.create(consumptionCreationDto));
verify(consumptionRepository, Mockito.times(1)).doesStorageConsumptionExistWithLocationForMonitoredCrn(MONITORED_RESOURCE_CRN, STORAGE_LOCATION);
verify(consumptionRepository, Mockito.times(0)).save(consumption);
verify(consumptionDtoConverter, Mockito.times(0)).creationDtoToConsumption(eq(consumptionCreationDto));
}
use of com.sequenceiq.consumption.dto.ConsumptionCreationDto in project cloudbreak by hortonworks.
the class ConsumptionServiceTest method testCreate.
@Test
void testCreate() {
ConsumptionCreationDto consumptionCreationDto = ConsumptionCreationDto.builder().withName(NAME).withConsumptionType(CONSUMPTION_TYPE).withEnvironmentCrn(ENVIRONMENT_CRN).withAccountId(ACCOUNT_ID).withResourceCrn(CRN).withMonitoredResourceType(RESOURCE_TYPE).withMonitoredResourceCrn(MONITORED_RESOURCE_CRN).withStorageLocation(STORAGE_LOCATION).build();
Consumption consumption = new Consumption();
consumption.setName(NAME);
consumption.setId(1L);
consumption.setAccountId(ACCOUNT_ID);
when(consumptionDtoConverter.creationDtoToConsumption(eq(consumptionCreationDto))).thenReturn(consumption);
when(consumptionRepository.save(consumption)).thenReturn(consumption);
when(consumptionRepository.doesStorageConsumptionExistWithLocationForMonitoredCrn(MONITORED_RESOURCE_CRN, STORAGE_LOCATION)).thenReturn(false);
Consumption result = underTest.create(consumptionCreationDto);
assertEquals(consumption, result);
verify(consumptionRepository, Mockito.times(1)).doesStorageConsumptionExistWithLocationForMonitoredCrn(MONITORED_RESOURCE_CRN, STORAGE_LOCATION);
verify(consumptionRepository).save(consumption);
verify(consumptionDtoConverter).creationDtoToConsumption(eq(consumptionCreationDto));
}
use of com.sequenceiq.consumption.dto.ConsumptionCreationDto in project cloudbreak by hortonworks.
the class ConsumptionInternalV1Controller method scheduleStorageConsumptionCollection.
@Override
@InternalOnly
public void scheduleStorageConsumptionCollection(@AccountId String accountId, @Valid @NotNull StorageConsumptionRequest request) {
ConsumptionCreationDto consumptionCreationDto = consumptionApiConverter.initCreationDtoForStorage(request);
consumptionService.create(consumptionCreationDto);
}
use of com.sequenceiq.consumption.dto.ConsumptionCreationDto in project cloudbreak by hortonworks.
the class ConsumptionApiConverterTest method testInitCreationDtoForStorage.
@Test
void testInitCreationDtoForStorage() {
StorageConsumptionRequest request = new StorageConsumptionRequest();
request.setEnvironmentCrn("env-crn");
request.setMonitoredResourceType(ResourceType.DATALAKE);
request.setMonitoredResourceName("name");
request.setMonitoredResourceCrn("dl-crn");
request.setStorageLocation("location");
ConsumptionCreationDto result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initCreationDtoForStorage(request));
Assertions.assertEquals("name_STORAGE", result.getName());
Assertions.assertNull(result.getDescription());
Assertions.assertEquals("test-aws", result.getAccountId());
Assertions.assertTrue(result.getResourceCrn().startsWith("crn:cdp:consumption:us-west-1:test-aws:consumption:"));
Assertions.assertEquals("env-crn", result.getEnvironmentCrn());
Assertions.assertEquals(ResourceType.DATALAKE, result.getMonitoredResourceType());
Assertions.assertEquals("dl-crn", result.getMonitoredResourceCrn());
Assertions.assertEquals(ConsumptionType.STORAGE, result.getConsumptionType());
Assertions.assertEquals("location", result.getStorageLocation());
}
Aggregations