EmrClusterDefinitionDaoHelper { public EmrClusterDefinitionEntity getEmrClusterDefinitionEntity(EmrClusterDefinitionKey emrClusterDefinitionKey) throws ObjectNotFoundException { EmrClusterDefinitionEntity emrClusterDefinitionEntity = null; NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(emrClusterDefinitionKey.getNamespace()); if (namespaceEntity != null) { emrClusterDefinitionEntity = emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, emrClusterDefinitionKey.getEmrClusterDefinitionName()); } if (emrClusterDefinitionEntity == null) { throw new ObjectNotFoundException(String .format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", emrClusterDefinitionKey.getEmrClusterDefinitionName(), emrClusterDefinitionKey.getNamespace())); } return emrClusterDefinitionEntity; }  EmrClusterDefinitionEntity getEmrClusterDefinitionEntity(EmrClusterDefinitionKey emrClusterDefinitionKey); List<EmrClusterDefinitionKey> getEmrClusterDefinitionKeys(String namespace);  }
@Test public void testGetEmrClusterDefinitionEntity() { NamespaceEntity namespaceEntity = new NamespaceEntity(); EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity(); EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(namespaceEntity); when(emrClusterDefinitionDao.getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME)) .thenReturn(emrClusterDefinitionEntity); EmrClusterDefinitionEntity result = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey); verify(namespaceDao).getNamespaceByCd(NAMESPACE); verify(emrClusterDefinitionDao).getEmrClusterDefinitionByNamespaceAndName(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME); verifyNoMoreInteractionsHelper(); assertEquals(emrClusterDefinitionEntity, result); }
@Test public void testGetEmrClusterDefinitionEntityNamespaceNoExists() { EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); when(namespaceDao.getNamespaceByCd(NAMESPACE)).thenReturn(null); try { emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey); fail(); } catch (ObjectNotFoundException e) { assertEquals(String.format("EMR cluster definition with name \"%s\" doesn't exist for namespace \"%s\".", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), e.getMessage()); } verify(namespaceDao).getNamespaceByCd(NAMESPACE); verifyNoMoreInteractionsHelper(); }