Search in sources :

Example 11 with RelationalTableRegistrationCreateRequest

use of org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest in project herd by FINRAOS.

the class RelationalTableRegistrationHelperServiceTest method testRegisterRelationalTableBusinessObjectDefinitionAlreadyExists.

@Test
public void testRegisterRelationalTableBusinessObjectDefinitionAlreadyExists() {
    // Create a namespace.
    namespaceDaoTestHelper.createNamespaceEntity(BDEF_NAMESPACE);
    // Create a business object definition.
    businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
    // Try to register a relational table when specified business object definition already exists.
    try {
        relationalTableRegistrationHelperService.registerRelationalTable(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME), relationalTableRegistrationServiceTestHelper.getExpectedSchemaColumns(), APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_FALSE);
        fail();
    } catch (AlreadyExistsException ex) {
        Assert.assertEquals(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", BDEF_NAME, BDEF_NAMESPACE), ex.getMessage());
    }
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) RelationalTableRegistrationCreateRequest(org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest) Test(org.junit.Test)

Example 12 with RelationalTableRegistrationCreateRequest

use of org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest 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());
    }
}
Also used : RelationalTableRegistrationCreateRequest(org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest) RelationalStorageAttributesDto(org.finra.herd.model.dto.RelationalStorageAttributesDto) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 13 with RelationalTableRegistrationCreateRequest

use of org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest in project herd by FINRAOS.

the class RelationalTableRegistrationHelperServiceTest method testValidateAndTrimRelationalTableRegistrationCreateRequestMissingRequiredParameters.

@Test
public void testValidateAndTrimRelationalTableRegistrationCreateRequestMissingRequiredParameters() {
    // Try to validate a null create request.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A relational table registration create request must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing namespace.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BLANK_TEXT, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A namespace must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing business object definition name.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BLANK_TEXT, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A business object definition name must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing business object format usage.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, BLANK_TEXT, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format usage must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing data provider name.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, BLANK_TEXT, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A data provider name must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing relational schema name.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, BLANK_TEXT, RELATIONAL_TABLE_NAME, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A relational schema name must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing relational table name.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, BLANK_TEXT, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A relational table name must be specified.", e.getMessage());
    }
    // Try to validate a create request with a missing storage name.
    try {
        relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, BLANK_TEXT));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A storage name must be specified.", e.getMessage());
    }
}
Also used : RelationalTableRegistrationCreateRequest(org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest) Test(org.junit.Test)

Example 14 with RelationalTableRegistrationCreateRequest

use of org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest in project herd by FINRAOS.

the class RelationalTableRegistrationHelperServiceTest method testValidateAndTrimRelationalTableRegistrationCreateRequestTrimParameters.

@Test
public void testValidateAndTrimRelationalTableRegistrationCreateRequestTrimParameters() {
    // Create a relational table registration create request with parameters having leading and trailing empty spaces.
    RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest = new RelationalTableRegistrationCreateRequest(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(BDEF_DISPLAY_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(DATA_PROVIDER_NAME), addWhitespace(RELATIONAL_SCHEMA_NAME), addWhitespace(RELATIONAL_TABLE_NAME), addWhitespace(STORAGE_NAME));
    // Validate and trim the create request.
    relationalTableRegistrationHelperService.validateAndTrimRelationalTableRegistrationCreateRequest(relationalTableRegistrationCreateRequest);
    // Validate the results.
    assertEquals(new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, RELATIONAL_SCHEMA_NAME, RELATIONAL_TABLE_NAME, STORAGE_NAME), relationalTableRegistrationCreateRequest);
}
Also used : RelationalTableRegistrationCreateRequest(org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest) Test(org.junit.Test)

Example 15 with RelationalTableRegistrationCreateRequest

use of org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest in project herd by FINRAOS.

the class RelationalTableRegistrationServiceTest method testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue.

@Test
public void testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue() {
    // Create an existing business object definition.
    BusinessObjectDefinitionEntity existingBusinessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME, new ArrayList<>());
    // Create database entities required for relational table registration testing.
    relationalTableRegistrationServiceTestHelper.createDatabaseEntitiesForRelationalTableRegistrationTesting(STORAGE_NAME);
    // Pick one of the in-memory database tables to be registered as a relational table.
    String relationalSchemaName = "PUBLIC";
    String relationalTableName = BusinessObjectDefinitionEntity.TABLE_NAME.toUpperCase();
    // Create a relational table registration create request for a table that is part of the in-memory database setup as part of DAO mocks.
    RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest = new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, relationalSchemaName, relationalTableName, STORAGE_NAME);
    // Create a relational table registration.
    BusinessObjectData businessObjectData = relationalTableRegistrationService.createRelationalTableRegistration(relationalTableRegistrationCreateRequest, APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_TRUE);
    // Create an expected storage unit.
    StorageUnit expectedStorageUnit = new StorageUnit();
    expectedStorageUnit.setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes()));
    expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
    // Create an expected business object data.
    BusinessObjectData expectedBusinessObjectData = new BusinessObjectData();
    expectedBusinessObjectData.setId(businessObjectData.getId());
    expectedBusinessObjectData.setNamespace(BDEF_NAMESPACE);
    expectedBusinessObjectData.setBusinessObjectDefinitionName(BDEF_NAME);
    expectedBusinessObjectData.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
    expectedBusinessObjectData.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
    expectedBusinessObjectData.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
    expectedBusinessObjectData.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
    expectedBusinessObjectData.setSubPartitionValues(new ArrayList<>());
    expectedBusinessObjectData.setVersion(INITIAL_DATA_VERSION);
    expectedBusinessObjectData.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
    expectedBusinessObjectData.setLatestVersion(LATEST_VERSION_FLAG_SET);
    expectedBusinessObjectData.setStatus(BusinessObjectDataStatusEntity.VALID);
    expectedBusinessObjectData.setStorageUnits(Collections.singletonList(expectedStorageUnit));
    expectedBusinessObjectData.setAttributes(new ArrayList<>());
    expectedBusinessObjectData.setBusinessObjectDataParents(new ArrayList<>());
    expectedBusinessObjectData.setBusinessObjectDataChildren(new ArrayList<>());
    // Validate the response.
    assertEquals(expectedBusinessObjectData, businessObjectData);
    // Create a business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, INITIAL_FORMAT_VERSION);
    // Retrieve business object format that was created as part of the relational table registration.
    BusinessObjectFormat businessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKey);
    // Create an expected schema.
    Schema expectedSchema = new Schema();
    expectedSchema.setColumns(relationalTableRegistrationServiceTestHelper.getExpectedSchemaColumns());
    expectedSchema.setNullValue(EMPTY_STRING);
    // Build an expected business object format.
    BusinessObjectFormat expectedBusinessObjectFormat = new BusinessObjectFormat();
    expectedBusinessObjectFormat.setId(businessObjectFormat.getId());
    expectedBusinessObjectFormat.setNamespace(BDEF_NAMESPACE);
    expectedBusinessObjectFormat.setBusinessObjectDefinitionName(BDEF_NAME);
    expectedBusinessObjectFormat.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
    expectedBusinessObjectFormat.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
    expectedBusinessObjectFormat.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
    expectedBusinessObjectFormat.setLatestVersion(LATEST_VERSION_FLAG_SET);
    expectedBusinessObjectFormat.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
    expectedBusinessObjectFormat.setBusinessObjectFormatParents(new ArrayList<>());
    expectedBusinessObjectFormat.setBusinessObjectFormatChildren(new ArrayList<>());
    expectedBusinessObjectFormat.setAttributeDefinitions(new ArrayList<>());
    expectedBusinessObjectFormat.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalSchemaName), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName)));
    expectedBusinessObjectFormat.setSchema(expectedSchema);
    // Validate the newly created business object format.
    assertEquals(expectedBusinessObjectFormat, businessObjectFormat);
    // Create a business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
    // Retrieve business object definition that was created as part of the relational table registration.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
    // Validate the newly created business object definition.
    assertEquals(existingBusinessObjectDefinitionEntity, businessObjectDefinitionEntity);
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) RelationalTableRegistrationCreateRequest(org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) Schema(org.finra.herd.model.api.xml.Schema) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) Test(org.junit.Test)

Aggregations

RelationalTableRegistrationCreateRequest (org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest)17 Test (org.junit.Test)17 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)4 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)3 Attribute (org.finra.herd.model.api.xml.Attribute)2 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)2 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)2 Schema (org.finra.herd.model.api.xml.Schema)2 Storage (org.finra.herd.model.api.xml.Storage)2 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)2 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)1 RelationalStorageAttributesDto (org.finra.herd.model.dto.RelationalStorageAttributesDto)1 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)1