RelationalTableRegistrationHelperServiceImpl implements RelationalTableRegistrationHelperService { String getPassword(RelationalStorageAttributesDto relationalStorageAttributesDto) { String password = null; if (StringUtils.isNotBlank(relationalStorageAttributesDto.getJdbcUserCredentialName())) { final String credStashEncryptionContext = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT); try { password = credStashHelper.getCredentialFromCredStash(credStashEncryptionContext, relationalStorageAttributesDto.getJdbcUserCredentialName()); } catch (CredStashGetCredentialFailedException e) { throw new IllegalStateException(e); } } return password; }  @Override @Transactional(propagation = Propagation.REQUIRES_NEW) RelationalStorageAttributesDto prepareForRelationalTableRegistration(
        RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest, Boolean appendToExistingBusinessObjectDefinition); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) RelationalTableRegistrationDto prepareForRelationalTableSchemaUpdate(BusinessObjectDataStorageUnitKey storageUnitKey); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData registerRelationalTable(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest,
        List<SchemaColumn> schemaColumns, Boolean appendToExistingBusinessObjectDefinition); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) List<SchemaColumn> retrieveRelationalTableColumns(RelationalStorageAttributesDto relationalStorageAttributesDto, String relationalSchemaName,
        String relationalTableName); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData updateRelationalTableSchema(RelationalTableRegistrationDto relationalTableRegistrationDto, List<SchemaColumn> schemaColumns); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) void validateAndTrimRelationalTableRegistrationCreateRequest(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest);  }
@Test public void testGetPassword() throws Exception { when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT)).thenReturn(CREDSTASH_ENCRYPTION_CONTEXT); when(credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME)).thenReturn(PASSWORD); String result = relationalTableRegistrationHelperServiceImpl.getPassword(new RelationalStorageAttributesDto(JDBC_URL, USERNAME, USER_CREDENTIAL_NAME)); verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT); verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME); verifyNoMoreInteractionsHelper(); assertEquals(PASSWORD, result); }
@Test public void testGetPasswordCredStashException() throws Exception { when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT)).thenReturn(CREDSTASH_ENCRYPTION_CONTEXT); when(credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME)) .thenThrow(new CredStashGetCredentialFailedException(ERROR_MESSAGE)); try { relationalTableRegistrationHelperServiceImpl.getPassword(new RelationalStorageAttributesDto(JDBC_URL, USERNAME, USER_CREDENTIAL_NAME)); fail(); } catch (IllegalStateException e) { assertEquals(String.format("%s: %s", CredStashGetCredentialFailedException.class.getName(), ERROR_MESSAGE), e.getMessage()); } verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT); verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME); verifyNoMoreInteractionsHelper(); }
@Test public void testGetPasswordNoUserCredentialName() { String result = relationalTableRegistrationHelperServiceImpl.getPassword(new RelationalStorageAttributesDto(JDBC_URL, USERNAME, NO_USER_CREDENTIAL_NAME)); verifyNoMoreInteractionsHelper(); assertNull(result); }