use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatRestControllerTest method testGenerateBusinessObjectFormatDdl.
@Test
public void testGenerateBusinessObjectFormatDdl() {
BusinessObjectFormatDdl ddl = new BusinessObjectFormatDdl();
ddl.setBusinessObjectDefinitionName(BDEF_NAME);
ddl.setCustomDdlName(CUSTOM_DDL_NAME);
ddl.setNamespace(NAMESPACE);
ddl.setDdl(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(AbstractServiceTest.PARTITION_COLUMNS.length, AbstractServiceTest.FIRST_COLUMN_NAME, AbstractServiceTest.FIRST_COLUMN_DATA_TYPE, AbstractServiceTest.ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true));
// Retrieve business object format ddl.
BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
when(businessObjectFormatService.generateBusinessObjectFormatDdl(request)).thenReturn(ddl);
BusinessObjectFormatDdl resultDdl = businessObjectFormatRestController.generateBusinessObjectFormatDdl(request);
// Verify the external calls.
verify(businessObjectFormatService).generateBusinessObjectFormatDdl(request);
verifyNoMoreInteractions(businessObjectFormatService);
// Validate the returned object.
assertEquals(ddl, resultDdl);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlNoCustomDdlMissingSchemaEscapeCharacter.
@Test
public void testGenerateBusinessObjectFormatDdlNoCustomDdlMissingSchemaEscapeCharacter() {
// Prepare test data without custom ddl.
List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
String partitionKey = partitionColumns.get(0).getName();
businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, partitionKey, SCHEMA_DELIMITER_PIPE, null, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns, null);
// Retrieve business object format ddl.
BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
// Validate the results.
String expectedRowFormat = "ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' NULL DEFINED AS '\\N'";
String expectedDdl = businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(PARTITION_COLUMNS.length, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, expectedRowFormat, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true);
businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl(null, expectedDdl, resultDdl);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlWhenReplaceColumnsAndIncludeDropTableStatementThrowsError.
/**
* Asserts that when replace columns is TRUE, then setting includeDropTableStatement to TRUE will cause an exception.
*/
@Test
public void testGenerateBusinessObjectFormatDdlWhenReplaceColumnsAndIncludeDropTableStatementThrowsError() {
final BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
businessObjectFormatDdlRequest.setReplaceColumns(true);
businessObjectFormatDdlRequest.setIncludeDropTableStatement(true);
businessObjectFormatDdlRequest.setIncludeIfNotExistsOption(null);
businessObjectFormatDdlRequest.setCustomDdlName(null);
assertExceptionThrown(new Runnable() {
public void run() {
businessObjectFormatService.generateBusinessObjectFormatDdl(businessObjectFormatDdlRequest);
}
}, IllegalArgumentException.class, "'includeDropTableStatement' must not be specified when 'replaceColumns' is true");
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTestHelper method getTestBusinessObjectFormatDdlCollectionRequest.
/**
* Creates a generate business object format ddl collection request using hard coded test values.
*
* @return the business object format ddl collection request
*/
public BusinessObjectFormatDdlCollectionRequest getTestBusinessObjectFormatDdlCollectionRequest() {
// Create a generate business object format ddl collection request.
BusinessObjectFormatDdlCollectionRequest businessObjectFormatDdlCollectionRequest = new BusinessObjectFormatDdlCollectionRequest();
// Create a list of generate business object format ddl requests.
List<BusinessObjectFormatDdlRequest> businessObjectFormatDdlRequests = new ArrayList<>();
businessObjectFormatDdlCollectionRequest.setBusinessObjectFormatDdlRequests(businessObjectFormatDdlRequests);
// Create a generate business object format ddl request.
BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = new BusinessObjectFormatDdlRequest(AbstractServiceTest.NAMESPACE, AbstractServiceTest.BDEF_NAME, AbstractServiceTest.FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, AbstractServiceTest.FORMAT_VERSION, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, AbstractServiceTest.TABLE_NAME, AbstractServiceTest.NO_CUSTOM_DDL_NAME, AbstractServiceTest.INCLUDE_DROP_TABLE_STATEMENT, AbstractServiceTest.INCLUDE_IF_NOT_EXISTS_OPTION, null);
// Add two business object ddl requests to the collection request.
businessObjectFormatDdlRequests.add(businessObjectFormatDdlRequest);
businessObjectFormatDdlRequests.add(businessObjectFormatDdlRequest);
return businessObjectFormatDdlCollectionRequest;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class Hive13DdlGeneratorTest method testGenerateReplaceColumnsStatementAssertionErrorIfColumnsEmpty.
/**
* Asserts that generateReplaceColumnsStatement() throws an IllegalArgumentException when the format entity only specified partitions, but no columns.
*/
@Test
public void testGenerateReplaceColumnsStatementAssertionErrorIfColumnsEmpty() {
BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = new BusinessObjectFormatDdlRequest();
businessObjectFormatDdlRequest.setTableName(TABLE_NAME);
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
{
SchemaColumnEntity schemaColumnEntity = new SchemaColumnEntity();
schemaColumnEntity.setPartitionLevel(0);
schemaColumnEntity.setName("col1");
schemaColumnEntity.setType("date");
businessObjectFormatEntity.getSchemaColumns().add(schemaColumnEntity);
}
try {
hive13DdlGenerator.generateReplaceColumnsStatement(businessObjectFormatDdlRequest, businessObjectFormatEntity);
Assert.fail("expected IllegalArgumentException, but no exception was thrown");
} catch (Exception e) {
Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
Assert.assertEquals("thrown exception message", "No schema columns specified for business object format {namespace: \"" + NAMESPACE + "\", businessObjectDefinitionName: \"" + BDEF_NAME + "\", businessObjectFormatUsage: \"" + FORMAT_USAGE_CODE + "\", businessObjectFormatFileType: \"" + FORMAT_FILE_TYPE_CODE + "\", businessObjectFormatVersion: " + FORMAT_VERSION + "}.", e.getMessage());
}
}
Aggregations