Search in sources :

Example 56 with BusinessObjectDataStorageUnitKey

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

the class StorageUnitHelperTest method testValidateBusinessObjectDataStorageUnitKeyInvalidParameters.

@Test
public void testValidateBusinessObjectDataStorageUnitKeyInvalidParameters() {
    // Try to call the method under test when business object data storage unit key is not specified.
    try {
        storageUnitHelper.validateBusinessObjectDataStorageUnitKey(null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A business object data storage unit key must be specified.", e.getMessage());
    }
    // Try to call the method under test when business object format version is not specified.
    try {
        storageUnitHelper.validateBusinessObjectDataStorageUnitKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format version must be specified.", e.getMessage());
    }
    // Try to call the method under test when business object data version is not specified.
    try {
        storageUnitHelper.validateBusinessObjectDataStorageUnitKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, NO_DATA_VERSION, STORAGE_NAME));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A business object data version must be specified.", e.getMessage());
    }
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 57 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreServiceImplTest method testFinalizeRestore.

@Test
public void testFinalizeRestore() {
    // 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 storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a DTO for business object data restore parameters.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)), NO_EXCEPTION);
    // Mock the external calls.
    when(businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey)).thenReturn(businessObjectDataRestoreDto);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            // Get the parameters DTO for the business object data restore.
            BusinessObjectDataRestoreDto businessObjectDataRestoreDto = (BusinessObjectDataRestoreDto) invocation.getArguments()[0];
            // Set the value for the new and old storage unit statuses.
            businessObjectDataRestoreDto.setNewStorageUnitStatus(StorageUnitStatusEntity.RESTORED);
            businessObjectDataRestoreDto.setOldStorageUnitStatus(StorageUnitStatusEntity.RESTORING);
            return null;
        }
    }).when(businessObjectDataFinalizeRestoreHelperService).completeFinalizeRestore(businessObjectDataRestoreDto);
    // Call the method under test.
    businessObjectDataFinalizeRestoreServiceImpl.finalizeRestore(storageUnitKey);
    // Verify the external calls.
    verify(businessObjectDataFinalizeRestoreHelperService).prepareToFinalizeRestore(storageUnitKey);
    verify(businessObjectDataFinalizeRestoreHelperService).executeS3SpecificSteps(businessObjectDataRestoreDto);
    verify(businessObjectDataFinalizeRestoreHelperService).completeFinalizeRestore(businessObjectDataRestoreDto);
    verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, StorageUnitStatusEntity.RESTORED, StorageUnitStatusEntity.RESTORING);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 58 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreServiceImplTest method testGetS3StorageUnitsToRestore.

@Test
public void testGetS3StorageUnitsToRestore() {
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    // Create a list of storage unit entities.
    List<StorageUnitEntity> storageUnitEntities = Arrays.asList(storageUnitEntity);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Mock the external calls.
    when(storageUnitDao.getS3StorageUnitsToRestore(MAX_RESULT)).thenReturn(storageUnitEntities);
    when(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity)).thenReturn(storageUnitKey);
    // Call the method under test.
    List<BusinessObjectDataStorageUnitKey> result = businessObjectDataFinalizeRestoreServiceImpl.getS3StorageUnitsToRestore(MAX_RESULT);
    // Verify the external calls.
    verify(storageUnitDao).getS3StorageUnitsToRestore(MAX_RESULT);
    verify(storageUnitHelper).createStorageUnitKeyFromEntity(storageUnitEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(Arrays.asList(storageUnitKey), result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 59 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataStorageUnitServiceImplTest method testCreateBusinessObjectDataStorageUnitCreateResponseDirectoryOnlyRegistration.

@Test
public void testCreateBusinessObjectDataStorageUnitCreateResponseDirectoryOnlyRegistration() {
    // 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 business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
    storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
    // Create an expected business object data storage unit response.
    BusinessObjectDataStorageUnitCreateResponse expectedResponse = new BusinessObjectDataStorageUnitCreateResponse(businessObjectDataStorageUnitKey, new StorageDirectory(STORAGE_DIRECTORY_PATH), null);
    // Mock the external calls.
    when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData())).thenReturn(businessObjectDataKey);
    when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
    // Call the method under test.
    BusinessObjectDataStorageUnitCreateResponse result = businessObjectDataStorageUnitServiceImpl.createBusinessObjectDataStorageUnitCreateResponse(storageUnitEntity);
    // Verify the external calls.
    verify(businessObjectDataHelper).createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData());
    verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(expectedResponse, result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStorageUnitCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 60 with BusinessObjectDataStorageUnitKey

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

the class CleanupDestroyedBusinessObjectDataServiceImplTest method testCleanupS3StorageUnit.

@Test
public void testCleanupS3StorageUnit() {
    // 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 storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create mocks
    BusinessObjectDataEntity businessObjectDataEntity = mock(BusinessObjectDataEntity.class);
    // Mock the external calls.
    when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
    when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(mockBusinessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
    when(businessObjectDataEntity.getLatestVersion()).thenReturn(true);
    when(mockBusinessObjectDataDao.getBusinessObjectDataMaxVersion(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_MAX_VERSION);
    when(mockBusinessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION))).thenReturn(businessObjectDataEntity);
    // Call the method under test.
    cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
    // Verify the external calls.
    verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(businessObjectDataEntity).getStorageUnits();
    verify(mockBusinessObjectDataDao).delete(businessObjectDataEntity);
    verify(mockNotificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, null, StorageUnitStatusEntity.DISABLED);
    verify(mockNotificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, businessObjectDataKey, null, BusinessObjectDataStatusEntity.DELETED);
    verify(businessObjectDataEntity).getBusinessObjectDataChildren();
    verify(businessObjectDataEntity).getBusinessObjectDataParents();
    verify(businessObjectDataEntity).getLatestVersion();
    verify(mockBusinessObjectDataDao).getBusinessObjectDataMaxVersion(businessObjectDataKey);
    verify(mockBusinessObjectDataDao).getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION));
    verify(businessObjectDataEntity).setLatestVersion(true);
    verify(mockBusinessObjectDataDao).saveAndRefresh(businessObjectDataEntity);
    verifyNoMoreInteractions(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)62 Test (org.junit.Test)51 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)33 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)30 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)26 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)14 ArrayList (java.util.ArrayList)10 StorageFile (org.finra.herd.model.api.xml.StorageFile)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 BusinessObjectDataStorageUnitStatusUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest)6 BusinessObjectDataStorageUnitStatusUpdateResponse (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateResponse)6 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)6 BusinessObjectDataRestoreDto (org.finra.herd.model.dto.BusinessObjectDataRestoreDto)6 BusinessObjectDataStorageUnitCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)5 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)5 HashMap (java.util.HashMap)4 FieldExtension (org.activiti.bpmn.model.FieldExtension)4 Parameter (org.finra.herd.model.api.xml.Parameter)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 BusinessObjectDataStorageUnitCreateResponse (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse)3