Search in sources :

Example 1 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenBothIdAndNameNotSpecified.

@Test
public void testGetActiveEmrClusterIdAssertErrorWhenBothIdAndNameNotSpecified() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = null;
        String emrClusterName = null;
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("One of EMR cluster ID or EMR cluster name must be specified.", e.getMessage());
        }
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : EmrDao(org.finra.herd.dao.EmrDao) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterDoesNotExist.

@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterDoesNotExist() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(null);
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(String.format("The cluster with ID \"%s\" does not exist.", emrClusterId), e.getMessage());
        }
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : EmrDao(org.finra.herd.dao.EmrDao) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 3 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdNoIdSpecifiedAssertErrorWhenClusterDoesNotExist.

@Test
public void testGetActiveEmrClusterIdNoIdSpecifiedAssertErrorWhenClusterDoesNotExist() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = null;
        String emrClusterName = "emrClusterName";
        when(mockEmrDao.getActiveEmrClusterByName(any(), any())).thenReturn(null);
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(String.format("The cluster with name \"%s\" does not exist.", emrClusterName), e.getMessage());
        }
        verify(mockEmrDao).getActiveEmrClusterByName(eq(emrClusterName), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : EmrDao(org.finra.herd.dao.EmrDao) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 4 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertReturnActualClusterIdWhenClusterIdSpecifiedAndClusterStateActiveAndNameMatch.

@Test
public void testGetActiveEmrClusterIdAssertReturnActualClusterIdWhenClusterIdSpecifiedAndClusterStateActiveAndNameMatch() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null));
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 5 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertParametersCaseIgnored.

@Test
public void testGetActiveEmrClusterIdAssertParametersCaseIgnored() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(StringUtils.upperCase(emrClusterId), StringUtils.upperCase(emrClusterName), null));
        verify(mockEmrDao).getEmrClusterById(eq(StringUtils.upperCase(emrClusterId)), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Aggregations

EmrDao (org.finra.herd.dao.EmrDao)11 Test (org.junit.Test)11 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)10 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)6 ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)6 ClusterState (com.amazonaws.services.elasticmapreduce.model.ClusterState)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)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