Search in sources :

Example 1 with BusinessObjectDataAttributesUpdateRequest

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

the class BusinessObjectDataServiceImplTest method testUpdateBusinessObjectDataAttributesMissingRequiredParameters.

@Test
public void testUpdateBusinessObjectDataAttributesMissingRequiredParameters() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Try to update business object data attributes when the update request is not specified.
    try {
        businessObjectDataServiceImpl.updateBusinessObjectDataAttributes(businessObjectDataKey, null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("A business object data attributes update request must be specified."), e.getMessage());
    }
    // Try to update business object data attributes when the list of attributes is not specified.
    try {
        businessObjectDataServiceImpl.updateBusinessObjectDataAttributes(businessObjectDataKey, new BusinessObjectDataAttributesUpdateRequest());
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("A list of business object data attributes must be specified."), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectDataHelper, times(2)).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with BusinessObjectDataAttributesUpdateRequest

use of org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest 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 3 with BusinessObjectDataAttributesUpdateRequest

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

the class BusinessObjectDataServiceImplTest method testUpdateBusinessObjectDataAttributes.

@Test
public void testUpdateBusinessObjectDataAttributes() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a list of attributes.
    List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE));
    // Create a business object data attributes update request.
    BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest = new BusinessObjectDataAttributesUpdateRequest(attributes);
    // Create a list of attribute definitions.
    List<BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntities = Arrays.asList(new BusinessObjectDataAttributeDefinitionEntity());
    // Create a business object format definition.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setAttributeDefinitions(attributeDefinitionEntities);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    // Create a business object data.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    businessObjectData.setId(ID);
    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(businessObjectDataDao.saveAndRefresh(businessObjectDataEntity)).thenReturn(businessObjectDataEntity);
    when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity)).thenReturn(businessObjectData);
    // Call the method under test.
    BusinessObjectData result = businessObjectDataServiceImpl.updateBusinessObjectDataAttributes(businessObjectDataKey, businessObjectDataAttributesUpdateRequest);
    // Verify the external calls.
    verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    verify(attributeHelper).validateAttributes(attributes);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(attributeDaoHelper).validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, attributeDefinitionEntities);
    verify(attributeDaoHelper).updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes);
    verify(businessObjectDataDao).saveAndRefresh(businessObjectDataEntity);
    verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(businessObjectData, result);
}
Also used : BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BusinessObjectDataAttributesUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest)3 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 Test (org.junit.Test)3 Attribute (org.finra.herd.model.api.xml.Attribute)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 ArrayList (java.util.ArrayList)1 BusinessObjectDataAttributeDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1