/** * Checks if the method name is not allowed against the configuration. * * @param methodName the method name * * @throws org.finra.herd.model.MethodNotAllowedException if requested method is not allowed. */ 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."); } }
@Test public void testCheckNotAllowedMethod() { // Create a list of methods to be blocked. String blockedMethodListAsText = STRING_VALUE; List<String> blockedMethods = Arrays.asList(METHOD_NAME); // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(blockedMethodListAsText); // Mock the external calls. when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); when(herdStringHelper.splitStringWithDefaultDelimiter(blockedMethodListAsText)).thenReturn(blockedMethods); // Try to call the method under test. try { configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); fail(); } catch (MethodNotAllowedException e) { assertEquals("The requested method is not allowed.", e.getMessage()); } // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }
/** * Checks if the method name is not allowed against the configuration. * * @param methodName the method name * * @throws org.finra.herd.model.MethodNotAllowedException if requested method is not allowed. */ 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."); } }
@Test public void testHandleOperationNotAllowedFound() throws Exception { validateErrorInformation(exceptionHandler.handleOperationNotAllowedException(new MethodNotAllowedException(MESSAGE)), HttpStatus.METHOD_NOT_ALLOWED); }