Search in sources :

Example 66 with Attribute

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

the class BusinessObjectDataRestControllerTest method testUpdateBusinessObjectDataAttributes.

@Test
public void testUpdateBusinessObjectDataAttributes() {
    // Create a list of business object data keys with all possible number of sub-partition values.
    List<BusinessObjectDataKey> businessObjectDataKeys = new ArrayList<>();
    for (int subPartitionValuesCount = 0; subPartitionValuesCount <= SUBPARTITION_VALUES.size(); subPartitionValuesCount++) {
        businessObjectDataKeys.add(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.subList(0, subPartitionValuesCount), DATA_VERSION));
    }
    // Create a business object data attributes update request.
    BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest = new BusinessObjectDataAttributesUpdateRequest(Collections.singletonList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE)));
    // Create a list of business object data instances one per business object data key.
    List<BusinessObjectData> businessObjectDataList = new ArrayList<>();
    for (BusinessObjectDataKey businessObjectDataKey : businessObjectDataKeys) {
        BusinessObjectData businessObjectData = new BusinessObjectData();
        businessObjectData.setNamespace(businessObjectDataKey.getNamespace());
        businessObjectData.setBusinessObjectDefinitionName(businessObjectDataKey.getBusinessObjectDefinitionName());
        businessObjectData.setBusinessObjectFormatUsage(businessObjectDataKey.getBusinessObjectFormatUsage());
        businessObjectData.setBusinessObjectFormatFileType(businessObjectDataKey.getBusinessObjectFormatFileType());
        businessObjectData.setBusinessObjectFormatVersion(businessObjectDataKey.getBusinessObjectFormatVersion());
        businessObjectData.setPartitionValue(businessObjectDataKey.getPartitionValue());
        businessObjectData.setSubPartitionValues(businessObjectDataKey.getSubPartitionValues());
        businessObjectData.setVersion(businessObjectDataKey.getBusinessObjectDataVersion());
        businessObjectDataList.add(businessObjectData);
    }
    // Mock the external calls.
    for (int subPartitionValuesCount = 0; subPartitionValuesCount <= SUBPARTITION_VALUES.size(); subPartitionValuesCount++) {
        when(businessObjectDataService.updateBusinessObjectDataAttributes(businessObjectDataKeys.get(subPartitionValuesCount), businessObjectDataAttributesUpdateRequest)).thenReturn(businessObjectDataList.get(subPartitionValuesCount));
    }
    // Call the methods under test and validate the results.
    assertEquals(businessObjectDataList.get(0), businessObjectDataRestController.updateBusinessObjectDataAttributes(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, businessObjectDataAttributesUpdateRequest));
    assertEquals(businessObjectDataList.get(1), businessObjectDataRestController.updateBusinessObjectDataAttributes(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.get(0), DATA_VERSION, businessObjectDataAttributesUpdateRequest));
    assertEquals(businessObjectDataList.get(2), businessObjectDataRestController.updateBusinessObjectDataAttributes(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.get(0), SUBPARTITION_VALUES.get(1), DATA_VERSION, businessObjectDataAttributesUpdateRequest));
    assertEquals(businessObjectDataList.get(3), businessObjectDataRestController.updateBusinessObjectDataAttributes(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.get(0), SUBPARTITION_VALUES.get(1), SUBPARTITION_VALUES.get(2), DATA_VERSION, businessObjectDataAttributesUpdateRequest));
    assertEquals(businessObjectDataList.get(4), businessObjectDataRestController.updateBusinessObjectDataAttributes(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.get(0), SUBPARTITION_VALUES.get(1), SUBPARTITION_VALUES.get(2), SUBPARTITION_VALUES.get(3), DATA_VERSION, businessObjectDataAttributesUpdateRequest));
    // Verify the external calls.
    for (BusinessObjectDataKey businessObjectDataKey : businessObjectDataKeys) {
        verify(businessObjectDataService).updateBusinessObjectDataAttributes(businessObjectDataKey, businessObjectDataAttributesUpdateRequest);
    }
    verifyNoMoreInteractionsHelper();
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) BusinessObjectDataAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 67 with Attribute

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

the class MessageNotificationEventServiceTest method testProcessBusinessObjectDataStatusChangeNotificationEventBusinessObjectDataAttributeSpecialValues.

@Test
public void testProcessBusinessObjectDataStatusChangeNotificationEventBusinessObjectDataAttributeSpecialValues() throws Exception {
    // Create a business object data entity with a publishable attributes that have special values such as a blank text and an empty string.
    List<Attribute> testAttributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, BLANK_TEXT), new Attribute(ATTRIBUTE_NAME_2_MIXED_CASE, EMPTY_STRING));
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createTestValidBusinessObjectData(SUBPARTITION_VALUES, Arrays.asList(new AttributeDefinition(ATTRIBUTE_NAME_1_MIXED_CASE, PUBLISH_ATTRIBUTE), new AttributeDefinition(ATTRIBUTE_NAME_2_MIXED_CASE, PUBLISH_ATTRIBUTE)), testAttributes);
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_XML, NO_MESSAGE_HEADER_DEFINITIONS)))));
    configurationDao.saveAndRefresh(configurationEntity);
    // Trigger the notification.
    List<NotificationMessage> result = messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID);
    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    businessObjectDataServiceTestHelper.validateBusinessObjectDataStatusChangeMessageWithXmlPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectDataKey, businessObjectDataEntity.getId(), HerdDaoSecurityHelper.SYSTEM_USER, BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID, testAttributes, NO_MESSAGE_HEADERS, result.get(0));
}
Also used : NotificationMessageDefinition(org.finra.herd.model.api.xml.NotificationMessageDefinition) NotificationMessageDefinitions(org.finra.herd.model.api.xml.NotificationMessageDefinitions) NotificationMessage(org.finra.herd.model.dto.NotificationMessage) Attribute(org.finra.herd.model.api.xml.Attribute) ConfigurationEntity(org.finra.herd.model.jpa.ConfigurationEntity) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 68 with Attribute

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

the class MessageNotificationEventServiceTest method testProcessBusinessObjectDataStatusChangeNotificationEvent.

@Test
public void testProcessBusinessObjectDataStatusChangeNotificationEvent() throws Exception {
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createTestValidBusinessObjectData(SUBPARTITION_VALUES, businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), businessObjectDefinitionServiceTestHelper.getNewAttributes());
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_XML, NO_MESSAGE_HEADER_DEFINITIONS)))));
    configurationDao.saveAndRefresh(configurationEntity);
    // Trigger the notification.
    List<NotificationMessage> result = messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID);
    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    businessObjectDataServiceTestHelper.validateBusinessObjectDataStatusChangeMessageWithXmlPayload(MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectDataKey, businessObjectDataEntity.getId(), HerdDaoSecurityHelper.SYSTEM_USER, BusinessObjectDataStatusEntity.VALID, BusinessObjectDataStatusEntity.INVALID, Collections.singletonList(new Attribute(ATTRIBUTE_NAME_3_MIXED_CASE, ATTRIBUTE_VALUE_3)), NO_MESSAGE_HEADERS, result.get(0));
}
Also used : NotificationMessageDefinition(org.finra.herd.model.api.xml.NotificationMessageDefinition) NotificationMessageDefinitions(org.finra.herd.model.api.xml.NotificationMessageDefinitions) NotificationMessage(org.finra.herd.model.dto.NotificationMessage) Attribute(org.finra.herd.model.api.xml.Attribute) ConfigurationEntity(org.finra.herd.model.jpa.ConfigurationEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 69 with Attribute

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

the class BusinessObjectDataStorageFileServiceTest method testCreateBusinessObjectDataStorageFilesStorageHasValidateFileSizeEnabledWithoutValidateFileExistence.

@Test
public void testCreateBusinessObjectDataStorageFilesStorageHasValidateFileSizeEnabledWithoutValidateFileExistence() {
    // Create an S3 storage with file size validation enabled without file existence validation.
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME_2), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_SIZE), Boolean.toString(true))));
    // Create a storage unit.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Try to add storage files to an S3 storage with file existence validation enabled without file size validation.
    try {
        businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(new BusinessObjectDataStorageFilesCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME, Arrays.asList(createFile(FILE_PATH_1, FILE_SIZE_1_KB, ROW_COUNT_1000)), NO_DISCOVER_STORAGE_FILES));
        fail("Should throw an IllegalArgumentException when adding files to storage with file existence validation enabled without file size validation.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Storage \"%s\" has file size validation enabled without file existence validation.", STORAGE_NAME), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageFilesCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateRequest) Attribute(org.finra.herd.model.api.xml.Attribute) Test(org.junit.Test)

Example 70 with Attribute

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

the class BusinessObjectDataStorageFileServiceTest method testCreateBusinessObjectDataStorageFilesBadStorageUnitStatus.

@Test
public void testCreateBusinessObjectDataStorageFilesBadStorageUnitStatus() {
    // Create an S3 storage with file size validation enabled without file existence validation.
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME_2), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_SIZE), Boolean.toString(true))));
    // Create a storage unit.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING, StorageUnitStatusEntity.ARCHIVED, NO_STORAGE_DIRECTORY_PATH);
    // Try to add storage files to an S3 storage unit with non-ENABLED status.
    try {
        businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(new BusinessObjectDataStorageFilesCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME, Arrays.asList(createFile(FILE_PATH_1, FILE_SIZE_1_KB, ROW_COUNT_1000)), NO_DISCOVER_STORAGE_FILES));
        fail("Should throw an IllegalArgumentException when adding files to storage unit with status that is not ENABLED.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Storage unit must be in the ENABLED status. Storage unit status {%s}, business object data {%s}", StorageUnitStatusEntity.ARCHIVED, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION)), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageFilesCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateRequest) Attribute(org.finra.herd.model.api.xml.Attribute) Test(org.junit.Test)

Aggregations

Attribute (org.finra.herd.model.api.xml.Attribute)165 Test (org.junit.Test)121 ArrayList (java.util.ArrayList)68 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)34 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)32 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)30 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)28 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)28 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)26 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)23 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)22 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)20 StorageEntity (org.finra.herd.model.jpa.StorageEntity)18 SampleDataFile (org.finra.herd.model.api.xml.SampleDataFile)16 HashMap (java.util.HashMap)15 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)15 BusinessObjectDefinitionCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest)15 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)14 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)13 AttributeDefinition (org.finra.herd.model.api.xml.AttributeDefinition)12