Search in sources :

Example 1 with MockSpotPrice

use of org.finra.herd.dao.impl.MockSpotPrice in project herd by FINRAOS.

the class Ec2DaoTest method testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances.

@Test
public void testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances() {
    // Initialize inputs.
    Collection<String> instanceTypes = Arrays.asList(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.INSTANCE_TYPE_2);
    Collection<String> productDescriptions = Arrays.asList("b", "c");
    // Set up mock.
    mock(RetryPolicyFactory.class);
    Ec2Operations ec2Operations = mock(Ec2Operations.class);
    ((Ec2DaoImpl) ec2Dao).setEc2Operations(ec2Operations);
    DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = new DescribeSpotPriceHistoryResult();
    List<SpotPrice> spotPrices = new ArrayList<>();
    spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_1, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
    spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_2, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
    describeSpotPriceHistoryResult.setSpotPriceHistory(spotPrices);
    when(ec2Operations.describeSpotPriceHistory(any(), any())).thenReturn(describeSpotPriceHistoryResult);
    // Execute MUT.
    List<SpotPrice> result = ec2Dao.getLatestSpotPrices(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions, new AwsParamsDto());
    // Verify that the dependency was called with the correct parameters.
    verify(ec2Operations).describeSpotPriceHistory(any(), equalsDescribeSpotPriceHistoryRequest(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions));
    // Verify that result contains only one spot price entry.
    assertEquals(1, CollectionUtils.size(result));
}
Also used : DescribeSpotPriceHistoryResult(com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult) MockSpotPrice(org.finra.herd.dao.impl.MockSpotPrice) SpotPrice(com.amazonaws.services.ec2.model.SpotPrice) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) Ec2DaoImpl(org.finra.herd.dao.impl.Ec2DaoImpl) MockSpotPrice(org.finra.herd.dao.impl.MockSpotPrice) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

DescribeSpotPriceHistoryResult (com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult)1 SpotPrice (com.amazonaws.services.ec2.model.SpotPrice)1 ArrayList (java.util.ArrayList)1 Ec2DaoImpl (org.finra.herd.dao.impl.Ec2DaoImpl)1 MockSpotPrice (org.finra.herd.dao.impl.MockSpotPrice)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 Test (org.junit.Test)1