/** * Method used to return character large object configuration values * * @param configurationKey the configuration key used to obtain the CLOB * * @return String clob */ public String getClobProperty(String configurationKey) { String clob = ""; ConfigurationEntity configurationEntity = configurationDao.getConfigurationByKey(configurationKey); if (configurationEntity != null && StringUtils.isNotBlank(configurationEntity.getValueClob())) { clob = configurationEntity.getValueClob(); } return clob; }
/** * Method used to return character large object configuration values * * @param configurationKey the configuration key used to obtain the CLOB * * @return String clob */ public String getClobProperty(String configurationKey) { String clob = ""; ConfigurationEntity configurationEntity = configurationDao.getConfigurationByKey(configurationKey); if (configurationEntity != null && StringUtils.isNotBlank(configurationEntity.getValueClob())) { clob = configurationEntity.getValueClob(); } return clob; }
/** * 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 testGetConfigurationByKey() throws Exception { // Create relative database entities. ConfigurationEntity configurationEntity = createConfigurationEntity(CONFIGURATION_KEY, CONFIGURATION_VALUE); // Retrieve the configuration entity by its key. assertEquals(configurationEntity, configurationDao.getConfigurationByKey(CONFIGURATION_KEY)); // Try to retrieve the configuration entity using its key in upper and lower case. assertNull(configurationDao.getConfigurationByKey(CONFIGURATION_KEY.toUpperCase())); assertNull(configurationDao.getConfigurationByKey(CONFIGURATION_KEY.toLowerCase())); // Try to retrieve a configuration using an invalid key. assertNull(configurationDao.getConfigurationByKey("I_DO_NOT_EXIST")); }
/** * 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 testGetClobPropertyConfigurationNoExists() { // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(null); // Call the method under test. String result = configurationDaoHelper.getClobProperty(CONFIGURATION_KEY); // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals("", result); }
@Test public void testCheckNotAllowedMethodBlockedMethodListIsNull() { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(null); // Mock the external calls. when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); // Call the method under test. configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verifyNoMoreInteractionsHelper(); }
@Test public void testGetClobPropertyConfigurationValueIsBlank() { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(BLANK_TEXT); // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); // Call the method under test. String result = configurationDaoHelper.getClobProperty(CONFIGURATION_KEY); // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals("", result); }
@Test public void testGetXmlClobPropertyAndUnmarshallToObjectConfigurationValueIsBlank() { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(BLANK_TEXT); // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); // Call the method under test. String result = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verifyNoMoreInteractionsHelper(); // Validate the results. assertNull(result); }
@Test public void testCheckNotAllowedMethodBlockedMethodListIsBlank() { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(BLANK_TEXT); // Mock the external calls. when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); // Call the method under test. configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verifyNoMoreInteractionsHelper(); }
@Test public void testGetClobProperty() { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(CONFIGURATION_VALUE); // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); // Call the method under test. String result = configurationDaoHelper.getClobProperty(CONFIGURATION_KEY); // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(CONFIGURATION_VALUE, result); }
@Test public void testGetXmlClobPropertyAndUnmarshallToObject() throws JAXBException { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(CONFIGURATION_VALUE); // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); when(xmlHelper.unmarshallXmlToObject(String.class, CONFIGURATION_VALUE)).thenReturn(STRING_VALUE); // Call the method under test. String result = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verify(xmlHelper).unmarshallXmlToObject(String.class, CONFIGURATION_VALUE); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(STRING_VALUE, result); }
@Test public void testCheckNotAllowedMethodMethodIsNotBlocked() { // 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); // Call the method under test. configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME_2); // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }
@Test public void testGetXmlClobPropertyAndUnmarshallToObjectJAXBException() throws JAXBException { // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(CONFIGURATION_VALUE); // Mock the external calls. when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); when(xmlHelper.unmarshallXmlToObject(String.class, CONFIGURATION_VALUE)).thenThrow(new JAXBException(ERROR_MESSAGE)); // Try to call the method under test. try { configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); } catch (IllegalStateException e) { assertEquals(String.format("Failed to unmarshall \"%s\" configuration value to %s.", CONFIGURATION_KEY, String.class.getName()), e.getMessage()); } // Verify the external calls. verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verify(xmlHelper).unmarshallXmlToObject(String.class, CONFIGURATION_VALUE); verifyNoMoreInteractionsHelper(); }
@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(); }