Search in sources :

Example 6 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class BusinessObjectDataInitiateRestoreHelperServiceImplTest method testGetStorageUnitStorageUnitAlreadyRestoring.

@Test
public void testGetStorageUnitStorageUnitAlreadyRestoring() {
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    // Create a storage unit status entity.
    StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
    storageUnitStatusEntity.setCode(StorageUnitStatusEntity.RESTORING);
    // Create a storage entity.
    StorageEntity storageEntity = new StorageEntity();
    storageEntity.setName(STORAGE_NAME);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitEntity.setStatus(storageUnitStatusEntity);
    // Mock the external calls.
    when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)).thenReturn(Arrays.asList(storageUnitEntity));
    when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity);
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data is already being restored in \"%s\" S3 storage. Business object data: {%s}", STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);
    verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 7 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class BusinessObjectDataInitiateRestoreHelperServiceImplTest method testGetStorageUnitStorageUnitNoExists.

@Test
public void testGetStorageUnitStorageUnitNoExists() {
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    // Mock the external calls.
    when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)).thenReturn(new ArrayList<>());
    when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity);
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data has no S3 storage unit. Business object data: {%s}", BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);
    verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 8 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class BusinessObjectDataStorageUnitServiceImplTest method testCreateBusinessObjectDataStorageUnit.

@Test
public void testCreateBusinessObjectDataStorageUnit() {
    // 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 directory.
    StorageDirectory storageDirectory = new StorageDirectory(STORAGE_DIRECTORY_PATH);
    // Create a list of storage files.
    List<StorageFile> storageFiles = Arrays.asList(new StorageFile(FILE_NAME, FILE_SIZE, ROW_COUNT), new StorageFile(FILE_NAME_2, FILE_SIZE_2, ROW_COUNT_2));
    // Create a business object data storage unit request.
    BusinessObjectDataStorageUnitCreateRequest request = new BusinessObjectDataStorageUnitCreateRequest(businessObjectDataStorageUnitKey, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setId(ID);
    // Create a storage entity.
    StorageEntity storageEntity = new StorageEntity();
    storageEntity.setName(STORAGE_NAME);
    // Create a list of storage file entities.
    List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity(), new StorageFileEntity());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
    storageUnitEntity.setStorageFiles(storageFileEntities);
    // Create an expected business object data storage unit response.
    BusinessObjectDataStorageUnitCreateResponse expectedResponse = new BusinessObjectDataStorageUnitCreateResponse(businessObjectDataStorageUnitKey, storageDirectory, storageFiles);
    // Mock the external calls.
    when(storageUnitHelper.getBusinessObjectDataKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(storageDaoHelper.getStorageEntity(STORAGE_NAME)).thenReturn(storageEntity);
    when(businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES)).thenReturn(storageUnitEntity);
    when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
    when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
    when(storageFileHelper.createStorageFilesFromEntities(storageFileEntities)).thenReturn(storageFiles);
    // Call the method under test.
    BusinessObjectDataStorageUnitCreateResponse result = businessObjectDataStorageUnitServiceImpl.createBusinessObjectDataStorageUnit(request);
    // Verify the external calls.
    verify(storageUnitHelper).validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(storageFileHelper).validateCreateRequestStorageFiles(storageFiles);
    verify(storageUnitHelper).getBusinessObjectDataKey(businessObjectDataStorageUnitKey);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(storageDaoHelper).getStorageEntity(STORAGE_NAME);
    verify(businessObjectDataDaoHelper).createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
    verify(businessObjectDataHelper).createBusinessObjectDataKeyFromEntity(businessObjectDataEntity);
    verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    verify(storageFileHelper).createStorageFilesFromEntities(storageFileEntities);
    verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(expectedResponse, result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStorageUnitCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest) BusinessObjectDataStorageUnitCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) 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)

Example 9 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class CleanupDestroyedBusinessObjectDataServiceImplTest method testCleanupS3StorageUnitWithIllegalArgumentException.

@Test
public void testCleanupS3StorageUnitWithIllegalArgumentException() {
    // 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);
    // Create storage units
    StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
    storagePlatformEntity.setName(StoragePlatformEntity.S3);
    StorageEntity storageEntity = new StorageEntity();
    storageEntity.setStoragePlatform(storagePlatformEntity);
    StorageUnitEntity storageUnitEntity1 = new StorageUnitEntity();
    storageUnitEntity1.setStorage(storageEntity);
    StorageUnitEntity storageUnitEntity2 = new StorageUnitEntity();
    storageUnitEntity2.setStorage(storageEntity);
    Collection<StorageUnitEntity> storageUnitEntities = Lists.newArrayList();
    storageUnitEntities.add(storageUnitEntity1);
    storageUnitEntities.add(storageUnitEntity2);
    // Mock the external calls.
    when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
    when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(businessObjectDataEntity.getStorageUnits()).thenReturn(storageUnitEntities);
    when(mockBusinessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey));
    // Call the method under test.
    try {
        cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
    } catch (IllegalArgumentException illegalArgumentException) {
        assertThat(illegalArgumentException.getMessage(), is(equalTo("Business object data has multiple (2) S3 storage units. Business object data: {" + businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey) + "}")));
    }
    // Verify the external calls.
    verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(businessObjectDataEntity).getStorageUnits();
    verify(mockBusinessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
    verifyNoMoreInteractions(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) 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)

Example 10 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class StorageUnitDaoHelperTest method testGetStorageUnitEntityByBusinessObjectDataAndStorageNameStorageUnitNoExists.

@Test
public void testGetStorageUnitEntityByBusinessObjectDataAndStorageNameStorageUnitNoExists() {
    // 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 and persist test database entities.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION, true, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    // Get the business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData();
    // Mock the external calls.
    when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorageName(businessObjectDataEntity, STORAGE_NAME)).thenReturn(null);
    when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Could not find storage unit in \"%s\" storage for the business object data {%s}.", STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorageName(businessObjectDataEntity, STORAGE_NAME);
    verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)278 Test (org.junit.Test)184 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)138 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)105 ArrayList (java.util.ArrayList)70 StorageEntity (org.finra.herd.model.jpa.StorageEntity)67 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)63 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)57 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)54 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)31 Attribute (org.finra.herd.model.api.xml.Attribute)28 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)27 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)27 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)27 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)25 Predicate (javax.persistence.criteria.Predicate)24 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)24 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)23 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)21 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19