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);
}
Aggregations