Search in sources :

Example 1 with AlternateKeyHelper

use of org.finra.herd.service.helper.AlternateKeyHelper in project herd by FINRAOS.

the class EmrServiceTest method testTerminateEmrClusterWithClusterId.

@Test
public void testTerminateEmrClusterWithClusterId() throws Exception {
    EmrService emrService = new EmrServiceImpl();
    AlternateKeyHelper mockAlternateKeyHelper = mock(AlternateKeyHelper.class);
    ReflectionTestUtils.setField(emrService, "alternateKeyHelper", mockAlternateKeyHelper);
    EmrHelper mockEmrHelper = mock(EmrHelper.class);
    ReflectionTestUtils.setField(emrService, "emrHelper", mockEmrHelper);
    EmrDao mockEmrDao = mock(EmrDao.class);
    ReflectionTestUtils.setField(emrService, "emrDao", mockEmrDao);
    NamespaceDaoHelper mockNamespaceDaoHelper = mock(NamespaceDaoHelper.class);
    ReflectionTestUtils.setField(emrService, "namespaceDaoHelper", mockNamespaceDaoHelper);
    EmrClusterDefinitionDaoHelper mockEmrClusterDefinitionDaoHelper = mock(EmrClusterDefinitionDaoHelper.class);
    ReflectionTestUtils.setField(emrService, "emrClusterDefinitionDaoHelper", mockEmrClusterDefinitionDaoHelper);
    String namespace = "namespace";
    String emrClusterDefinitionName = "emrClusterDefinitionName";
    String emrClusterName = "emrClusterName";
    boolean overrideTerminationProtection = false;
    String emrClusterId = "emrClusterId";
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto();
    emrClusterAlternateKeyDto.setNamespace(namespace);
    emrClusterAlternateKeyDto.setEmrClusterDefinitionName(emrClusterDefinitionName);
    emrClusterAlternateKeyDto.setEmrClusterName(emrClusterName);
    AwsParamsDto awsParamsDto = new AwsParamsDto();
    when(mockEmrHelper.getAwsParamsDtoByAcccountId(any())).thenReturn(awsParamsDto);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    when(mockNamespaceDaoHelper.getNamespaceEntity(any())).thenReturn(namespaceEntity);
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity();
    when(mockEmrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(any(), any())).thenReturn(emrClusterDefinitionEntity);
    String buildEmrClusterNameResult = "buildEmrClusterNameResult";
    when(mockEmrHelper.buildEmrClusterName(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
    when(mockEmrHelper.getActiveEmrClusterId(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
    when(mockEmrDao.getEmrClusterStatusById(any(), any())).thenReturn(buildEmrClusterNameResult);
    emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtection, emrClusterId, null);
    verify(mockAlternateKeyHelper).validateStringParameter("namespace", namespace);
    verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster definition name", emrClusterDefinitionName);
    verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster name", emrClusterName);
    verify(mockNamespaceDaoHelper).getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
    verify(mockEmrClusterDefinitionDaoHelper).getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
    verify(mockEmrHelper).buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    verify(mockEmrHelper).getActiveEmrClusterId(emrClusterId, buildEmrClusterNameResult, null);
    verify(mockEmrDao).terminateEmrCluster(buildEmrClusterNameResult, overrideTerminationProtection, awsParamsDto);
    verify(mockEmrDao).getEmrClusterStatusById(buildEmrClusterNameResult, awsParamsDto);
// verifyNoMoreInteractions(mockEmrHelper, mockNamespaceDaoHelper, mockEmrClusterDefinitionDaoHelper, mockEmrDao);
}
Also used : EmrClusterDefinitionDaoHelper(org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrServiceImpl(org.finra.herd.service.impl.EmrServiceImpl) EmrHelper(org.finra.herd.dao.helper.EmrHelper) NamespaceDaoHelper(org.finra.herd.service.helper.NamespaceDaoHelper) EmrDao(org.finra.herd.dao.EmrDao) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) Test(org.junit.Test)

Aggregations

EmrDao (org.finra.herd.dao.EmrDao)1 EmrHelper (org.finra.herd.dao.helper.EmrHelper)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)1 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 AlternateKeyHelper (org.finra.herd.service.helper.AlternateKeyHelper)1 EmrClusterDefinitionDaoHelper (org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper)1 NamespaceDaoHelper (org.finra.herd.service.helper.NamespaceDaoHelper)1 EmrServiceImpl (org.finra.herd.service.impl.EmrServiceImpl)1 Test (org.junit.Test)1