use of com.sequenceiq.consumption.domain.Consumption in project cloudbreak by hortonworks.
the class ConsumptionService method create.
public Consumption create(ConsumptionCreationDto creationDto) {
validateStorageLocationCollision(creationDto);
Consumption consumption = consumptionDtoConverter.creationDtoToConsumption(creationDto);
return create(consumption, consumption.getAccountId());
}
use of com.sequenceiq.consumption.domain.Consumption 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.domain.Consumption in project cloudbreak by hortonworks.
the class AbstractStorageConsumptionCollectionActionTest method setUp.
@BeforeEach
public void setUp() {
consumption = new Consumption();
consumption.setId(RESOURCE_ID);
}
use of com.sequenceiq.consumption.domain.Consumption 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.domain.Consumption 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));
}
Aggregations