Search in sources :

Example 1 with MethodNotAllowedException

use of org.finra.herd.model.MethodNotAllowedException in project herd by FINRAOS.

the class ConfigurationDaoHelper method checkNotAllowedMethod.

/**
 * 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.");
    }
}
Also used : MethodNotAllowedException(org.finra.herd.model.MethodNotAllowedException) ConfigurationEntity(org.finra.herd.model.jpa.ConfigurationEntity)

Example 2 with MethodNotAllowedException

use of org.finra.herd.model.MethodNotAllowedException in project herd by FINRAOS.

the class ConfigurationDaoHelperTest method testCheckNotAllowedMethod.

@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();
}
Also used : MethodNotAllowedException(org.finra.herd.model.MethodNotAllowedException) ConfigurationEntity(org.finra.herd.model.jpa.ConfigurationEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

MethodNotAllowedException (org.finra.herd.model.MethodNotAllowedException)2 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 Test (org.junit.Test)1