ConfigurationDaoHelper { public void checkNotAllowedMethod(String methodName) throws MethodNotAllowedException { boolean needToBlock = false; ConfigurationEntity configurationEntity = configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); if (configurationEntity != null && StringUtils.isNotBlank(configurationEntity.getValueClob())) { List<String> methodsToBeBlocked = herdStringHelper.splitStringWithDefaultDelimiter(configurationEntity.getValueClob()); needToBlock = methodsToBeBlocked.contains(methodName); } if (needToBlock) { throw new MethodNotAllowedException("The requested method is not allowed."); } }  void checkNotAllowedMethod(String methodName); String getClobProperty(String configurationKey); @SuppressWarnings("unchecked") T getXmlClobPropertyAndUnmarshallToObject(Class<T> classType, String configurationKey);  }
@Test public void testCheckNotAllowedMethod() { String blockedMethodListAsText = STRING_VALUE; List<String> blockedMethods = Arrays.asList(METHOD_NAME); ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(blockedMethodListAsText); when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); when(herdStringHelper.splitStringWithDefaultDelimiter(blockedMethodListAsText)).thenReturn(blockedMethods); try { configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); fail(); } catch (MethodNotAllowedException e) { assertEquals("The requested method is not allowed.", e.getMessage()); } verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }
@Test public void testCheckNotAllowedMethodBlockedMethodListIsBlank() { ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(BLANK_TEXT); when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verifyNoMoreInteractionsHelper(); }
@Test public void testCheckNotAllowedMethodBlockedMethodListIsNull() { ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(null); when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verifyNoMoreInteractionsHelper(); }
@Test public void testCheckNotAllowedMethodMethodIsNotBlocked() { String blockedMethodListAsText = STRING_VALUE; List<String> blockedMethods = Arrays.asList(METHOD_NAME); ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(blockedMethodListAsText); when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); when(herdStringHelper.splitStringWithDefaultDelimiter(blockedMethodListAsText)).thenReturn(blockedMethods); configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME_2); verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }