use of org.finra.herd.model.dto.RelationalStorageAttributesDto in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceImplTest method testGetPasswordCredStashException.
@Test
public void testGetPasswordCredStashException() throws Exception {
// Mock the external calls.
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 to call the method under test.
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 the external calls.
verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT);
verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.dto.RelationalStorageAttributesDto in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceImpl method getRelationalStorageAttributesImpl.
/**
* Gets storage attributes required to perform relation table registration. This method also validates database entities per specified relational table
* registration create request.
*
* @param relationalTableRegistrationCreateRequest the relational table registration create request
* @param appendToExistingBusinessObjectDefinition boolean flag that determines if the format should be appended to an existing business object definition
*
* @return the relational storage attributes DtO
*/
RelationalStorageAttributesDto getRelationalStorageAttributesImpl(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest, Boolean appendToExistingBusinessObjectDefinition) {
// Validate that specified namespace exists.
namespaceDaoHelper.getNamespaceEntity(relationalTableRegistrationCreateRequest.getNamespace());
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName());
// Ensure that a business object definition with the specified key doesn't already exist.
if (BooleanUtils.isNotTrue(appendToExistingBusinessObjectDefinition) && businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey) != null) {
throw new AlreadyExistsException(String.format("Business object definition with name \"%s\" already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
}
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName(), relationalTableRegistrationCreateRequest.getBusinessObjectFormatUsage(), FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, null));
// If the latest version exists, fail with an already exists exception.
if (latestVersionBusinessObjectFormatEntity != null) {
throw new AlreadyExistsException(String.format("Format with file type \"%s\" and usage \"%s\" already exists for business object definition \"%s\".", latestVersionBusinessObjectFormatEntity.getFileType().getCode(), latestVersionBusinessObjectFormatEntity.getUsage(), latestVersionBusinessObjectFormatEntity.getBusinessObjectDefinition().getName()));
}
// Validate that specified data provider exists.
dataProviderDaoHelper.getDataProviderEntity(relationalTableRegistrationCreateRequest.getDataProviderName());
// Get the storage.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(relationalTableRegistrationCreateRequest.getStorageName());
// Only RELATIONAL storage platform is supported for the relational table registration feature.
Assert.isTrue(storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.RELATIONAL), String.format("Cannot register relational table in \"%s\" storage of %s storage platform type. Only %s storage platform type is supported by this feature.", storageEntity.getName(), storageEntity.getStoragePlatform().getName(), StoragePlatformEntity.RELATIONAL));
// Get JDBC URL for this storage. This storage attribute is required and must have a non-blank value.
String jdbcUrl = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_URL), storageEntity, true, true);
// Get JDBC username for this storage. This storage attribute is not required and it is allowed to have a blank value.
String jdbcUsername = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_USERNAME), storageEntity, false, false);
// Get JDBC user credential name for this storage. This storage attribute is not required and it is allowed to have a blank value.
String jdbcUserCredentialName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_USER_CREDENTIAL_NAME), storageEntity, false, false);
// Create and initialize a relational storage attributes DTO.
RelationalStorageAttributesDto relationalStorageAttributesDto = new RelationalStorageAttributesDto();
relationalStorageAttributesDto.setJdbcUrl(jdbcUrl);
relationalStorageAttributesDto.setJdbcUsername(jdbcUsername);
relationalStorageAttributesDto.setJdbcUserCredentialName(jdbcUserCredentialName);
return relationalStorageAttributesDto;
}
use of org.finra.herd.model.dto.RelationalStorageAttributesDto in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceTest method testRetrieveRelationalTableColumnsSqlException.
@Test
public void testRetrieveRelationalTableColumnsSqlException() {
// Create and initialize a relational storage attributes DTO with an invalid JDBC URL.
RelationalStorageAttributesDto relationalStorageAttributesDto = new RelationalStorageAttributesDto();
relationalStorageAttributesDto.setJdbcUrl(INVALID_VALUE);
relationalStorageAttributesDto.setJdbcUsername(USERNAME);
relationalStorageAttributesDto.setJdbcUserCredentialName(NO_USER_CREDENTIAL_NAME);
// Try to get a list of schema columns using an invalid JDBC URL.
try {
relationalTableRegistrationHelperService.retrieveRelationalTableColumns(relationalStorageAttributesDto, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Failed to retrieve description of a relational table with \"%s\" name under \"%s\" schema at jdbc.url=\"%s\" using jdbc.username=\"%s\". " + "Reason: No suitable driver found for %s", RELATIONAL_TABLE_NAME, RELATIONAL_SCHEMA_NAME, INVALID_VALUE, USERNAME, INVALID_VALUE), e.getMessage());
}
}
use of org.finra.herd.model.dto.RelationalStorageAttributesDto in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceTest method testRetrieveRelationalTableColumnsRelationTableNoExists.
@Test
public void testRetrieveRelationalTableColumnsRelationTableNoExists() {
// Create and initialize a relational storage attributes DTO to point to the in-memory database setup as part of DAO mocks.
RelationalStorageAttributesDto relationalStorageAttributesDto = new RelationalStorageAttributesDto();
relationalStorageAttributesDto.setJdbcUrl(JDBC_URL);
relationalStorageAttributesDto.setJdbcUsername(EMPTY_STRING);
relationalStorageAttributesDto.setJdbcUserCredentialName(NO_USER_CREDENTIAL_NAME);
// Try to get a list of schema columns for a non-existing relational table.
try {
relationalTableRegistrationHelperService.retrieveRelationalTableColumns(relationalStorageAttributesDto, RELATIONAL_SCHEMA_NAME, I_DO_NOT_EXIST);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Relational table with \"%s\" name not found under \"%s\" schema at jdbc.url=\"%s\" for jdbc.username=\"%s\".", I_DO_NOT_EXIST, RELATIONAL_SCHEMA_NAME, JDBC_URL, EMPTY_STRING), e.getMessage());
}
}
use of org.finra.herd.model.dto.RelationalStorageAttributesDto in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceTest method testRelationalTableRegistrationHelperServiceMethodsNewTransactionPropagation.
/**
* This unit test is to get coverage for the methods that have an explicit annotation for transaction propagation.
*/
@Test
public void testRelationalTableRegistrationHelperServiceMethodsNewTransactionPropagation() {
try {
relationalTableRegistrationHelperServiceImpl.getRelationalStorageAttributes(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME), APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_FALSE);
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Namespace \"%s\" doesn't exist.", BDEF_NAMESPACE), e.getMessage());
}
try {
relationalTableRegistrationHelperServiceImpl.registerRelationalTable(new RelationalTableRegistrationCreateRequest(), new ArrayList<>(), APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_FALSE);
fail();
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
try {
relationalTableRegistrationHelperServiceImpl.retrieveRelationalTableColumns(new RelationalStorageAttributesDto(JDBC_URL, USERNAME, NO_USER_CREDENTIAL_NAME), RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Failed to retrieve description of a relational table with \"%s\" name under \"%s\" schema at jdbc.url=\"%s\" using jdbc.username=\"%s\". " + "Reason: Wrong user name or password [28000-196]", RELATIONAL_TABLE_NAME, RELATIONAL_SCHEMA_NAME, JDBC_URL, USERNAME), e.getMessage());
}
try {
relationalTableRegistrationHelperServiceImpl.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest());
fail();
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
}
Aggregations