/** * 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; }
/** * Creates and persists a new configuration entity. * * @param key the configuration key * @param value the configuration value * * @return the newly created configuration entity */ private ConfigurationEntity createConfigurationEntity(String key, String value) { ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(key); configurationEntity.setValue(value); return configurationDao.saveAndRefresh(configurationEntity); } }
@Test public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayload() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, FORMAT_VERSION_2.toString())); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(), FORMAT_VERSION_2.toString(), getExpectedMessageHeaders(uuid), result.get(0)); }
/** * 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; }
new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, NO_MESSAGE_HEADER_DEFINITIONS))))); configurationDao.saveAndRefresh(configurationEntity);
/** * 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 testBuildUserNamespaceAuthorizationChangeMessagesNoMessageDefinitions() throws Exception { // Create a user namespace authorization key. UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey(USER_ID, BDEF_NAMESPACE); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_USER_NAMESPACE_AUTHORIZATION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(null); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, userNamespaceAuthorizationChangeMessageBuilder .buildNotificationMessages(new UserNamespaceAuthorizationChangeNotificationEvent(userNamespaceAuthorizationKey)).size()); // Override configuration, so there will be an empty list of notification message definitions configured in the system. configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions())); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, userNamespaceAuthorizationChangeMessageBuilder .buildNotificationMessages(new UserNamespaceAuthorizationChangeNotificationEvent(userNamespaceAuthorizationKey)).size()); }
@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")); }
@Test public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayloadNoMessageHeaders() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, NO_MESSAGE_HEADER_DEFINITIONS))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, FORMAT_VERSION_2.toString())); // Validate the results. assertEquals(1, CollectionUtils.size(result)); validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(), FORMAT_VERSION_2.toString(), NO_MESSAGE_HEADERS, result.get(0)); }
/** * 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 testBuildStorageUnitStatusChangeMessagesNoMessageDefinitions() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Override configuration, so there will be no notification message definitions configured in the system. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(null); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, storageUnitStatusChangeMessageBuilder.buildNotificationMessages( new StorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2)).size()); // Override configuration, so there will be an empty list of notification message definitions configured in the system. configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions())); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, storageUnitStatusChangeMessageBuilder.buildNotificationMessages( new StorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2)).size()); }
@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 testBuildBusinessObjectDataStatusChangeMessagesNoMessageDefinitions() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Override configuration, so there will be no notification message definitions configured in the system. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(null); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, businessObjectDataStatusChangeMessageBuilder .buildNotificationMessages(new BusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2)).size()); // Override configuration, so there will be an empty list of notification message definitions configured in the system. configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions())); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, businessObjectDataStatusChangeMessageBuilder .buildNotificationMessages(new BusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2)).size()); }
@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 testBuildBusinessObjectFormatVersionChangeMessagesNoMessageDefinitions() throws Exception { // Create a business object format key. BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(null); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, NO_OLD_BUSINESS_OBJECT_FORMAT_VERSION)) .size()); // Override configuration, so there will be an empty list of notification message definitions configured in the system. configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions())); configurationDao.saveAndRefresh(configurationEntity); // Try to build a notification message and validate the results. assertEquals(0, businessObjectFormatVersionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, NO_OLD_BUSINESS_OBJECT_FORMAT_VERSION)) .size()); }
@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 testBuildStorageUnitStatusChangeMessagesJsonPayload() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, STORAGE_UNIT_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = storageUnitStatusChangeMessageBuilder.buildNotificationMessages( new StorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2)); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateStorageUnitStatusChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2, getExpectedMessageHeaders(uuid), result.get(0)); }
@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 testBuildUserNamespaceAuthorizationChangeMessagesJsonPayload() throws Exception { // Create a user namespace authorization key. UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey(USER_ID, BDEF_NAMESPACE); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_USER_NAMESPACE_AUTHORIZATION_CHANGE_MESSAGE_DEFINITIONS.getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList( new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, USER_NAMESPACE_AUTHORIZATION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = userNamespaceAuthorizationChangeMessageBuilder .buildNotificationMessages(new UserNamespaceAuthorizationChangeNotificationEvent(userNamespaceAuthorizationKey)); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateUserNamespaceAuthorizationChangeMessageWithJsonPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, userNamespaceAuthorizationKey, getExpectedMessageHeaders(uuid), result.get(0)); }
@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(); }