Search in sources :

Example 1 with Consumption

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());
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption)

Example 2 with Consumption

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());
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) ConsumptionCreationDto(com.sequenceiq.consumption.dto.ConsumptionCreationDto) Test(org.junit.jupiter.api.Test)

Example 3 with Consumption

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);
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Consumption

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));
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) ConsumptionCreationDto(com.sequenceiq.consumption.dto.ConsumptionCreationDto) Test(org.junit.jupiter.api.Test)

Example 5 with Consumption

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));
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) ConsumptionCreationDto(com.sequenceiq.consumption.dto.ConsumptionCreationDto) Test(org.junit.jupiter.api.Test)

Aggregations

Consumption (com.sequenceiq.consumption.domain.Consumption)10 Test (org.junit.jupiter.api.Test)4 ConsumptionCreationDto (com.sequenceiq.consumption.dto.ConsumptionCreationDto)3 StorageConsumptionCollectionHandlerEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent)2 InternalOnly (com.sequenceiq.authorization.annotation.InternalOnly)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)1 CDPConsumptionStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.consumption.CDPConsumptionStructuredFlowEvent)1 Credential (com.sequenceiq.consumption.dto.Credential)1 ConsumptionContext (com.sequenceiq.consumption.flow.consumption.ConsumptionContext)1 StorageConsumptionCollectionEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionEvent)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1