Search in sources :

Example 1 with StorageUnitStatusEntity

use of org.finra.herd.model.jpa.StorageUnitStatusEntity 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 2 with StorageUnitStatusEntity

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

the class BusinessObjectDataStorageUnitStatusServiceImplTest method testUpdateBusinessObjectDataStorageUnitStatus.

@Test
public void testUpdateBusinessObjectDataStorageUnitStatus() {
    // 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);
    // Create a storage unit status entity.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    // Create a business object data storage unit status update request.
    BusinessObjectDataStorageUnitStatusUpdateRequest request = new BusinessObjectDataStorageUnitStatusUpdateRequest(STORAGE_UNIT_STATUS_2);
    // Create a business object data storage unit status update response.
    BusinessObjectDataStorageUnitStatusUpdateResponse expectedResponse = new BusinessObjectDataStorageUnitStatusUpdateResponse(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
    // Mock the external calls.
    when(storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey)).thenReturn(storageUnitEntity);
    when(storageUnitStatusDaoHelper.getStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2)).thenReturn(storageUnitStatusEntity);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            // Get the storage unit entity parameter.
            StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
            StorageUnitStatusEntity storageUnitStatusEntity = (StorageUnitStatusEntity) invocation.getArguments()[1];
            // Update storage unit status.
            storageUnitEntity.setStatus(storageUnitStatusEntity);
            return null;
        }
    }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity, STORAGE_UNIT_STATUS_2);
    when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData())).thenReturn(businessObjectDataKey);
    when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
    // Call the method under test.
    BusinessObjectDataStorageUnitStatusUpdateResponse result = businessObjectDataStorageUnitStatusServiceImpl.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, request);
    // Verify the external calls.
    verify(storageUnitHelper).validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(storageUnitDaoHelper).getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
    verify(storageUnitStatusDaoHelper).getStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity, STORAGE_UNIT_STATUS_2);
    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) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataStorageUnitStatusUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest) BusinessObjectDataStorageUnitStatusUpdateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateResponse) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 3 with StorageUnitStatusEntity

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

the class StorageUnitDaoHelperTest method testUpdateStorageUnitStatusNewStatusPassedAsString.

@Test
public void testUpdateStorageUnitStatusNewStatusPassedAsString() {
    // 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 a storage unit entity.
    StorageUnitEntity storageUnitEntity = 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, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    // Create and persist a storage status entity.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    // Mock the external calls.
    when(storageUnitStatusDaoHelper.getStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2)).thenReturn(storageUnitStatusEntity);
    when(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData())).thenReturn(businessObjectDataKey);
    // Call the method under test.
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS_2);
    // Verify the external calls.
    verify(storageUnitStatusDaoHelper).getStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
    verify(businessObjectDataHelper).getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData());
    verify(messageNotificationEventService).processStorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 4 with StorageUnitStatusEntity

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

the class StorageUnitDaoHelperTest method testUpdateStorageUnitStatusNewStatusPassedAsEntity.

@Test
public void testUpdateStorageUnitStatusNewStatusPassedAsEntity() {
    // 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 a storage unit entity.
    StorageUnitEntity storageUnitEntity = 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, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    // Create and persist a storage status entity.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    // Mock the external calls.
    when(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData())).thenReturn(businessObjectDataKey);
    // Call the method under test.
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity, STORAGE_UNIT_STATUS_2);
    // Verify the external calls.
    verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
    verify(businessObjectDataHelper).getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData());
    verify(messageNotificationEventService).processStorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 5 with StorageUnitStatusEntity

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

the class StorageUnitDaoHelperTest method testSetStorageUnitStatus.

@Test
public void testSetStorageUnitStatus() {
    // 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 a storage unit entity.
    StorageUnitEntity storageUnitEntity = 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, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    // Create and persist a storage status entity.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    // Mock the external calls.
    when(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData())).thenReturn(businessObjectDataKey);
    // Call the method under test.
    storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity);
    // Verify the external calls.
    verify(businessObjectDataHelper).getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData());
    verify(messageNotificationEventService).processStorageUnitStatusChangeNotificationEvent(businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS_2, NO_STORAGE_UNIT_STATUS);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)47 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)35 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)30 StorageEntity (org.finra.herd.model.jpa.StorageEntity)24 Test (org.junit.Test)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)18 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)15 ArrayList (java.util.ArrayList)11 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)11 Predicate (javax.persistence.criteria.Predicate)10 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)9 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 StorageFile (org.finra.herd.model.api.xml.StorageFile)8 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)8 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 Order (javax.persistence.criteria.Order)6 Timestamp (java.sql.Timestamp)5