Search in sources :

Example 6 with BusinessObjectDataDestroyDto

use of org.finra.herd.model.dto.BusinessObjectDataDestroyDto in project herd by FINRAOS.

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testExecuteInitiateDestroyAfterStepInvalidStorageUnitStatus.

@Test
public void testExecuteInitiateDestroyAfterStepInvalidStorageUnitStatus() {
    // 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data status entity.
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
    businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    // Create a storage unit status entity with an invalid status (the expected storage unit status is DISABLING).
    StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
    storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ARCHIVING);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStatus(storageUnitStatusEntity);
    // Create a business object data destroy parameters DTO.
    BusinessObjectDataDestroyDto businessObjectDataDestroyDto = new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
    // Create a business object data.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    businessObjectData.setId(ID);
    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
    when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.executeInitiateDestroyAfterStep(businessObjectDataDestroyDto);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Storage unit status is \"%s\", but must be \"%s\". Storage: {%s}, business object data: {%s}", StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.DISABLING, STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), businessObjectDataDestroyDto);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataDestroyDto(org.finra.herd.model.dto.BusinessObjectDataDestroyDto) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BusinessObjectDataDestroyDto (org.finra.herd.model.dto.BusinessObjectDataDestroyDto)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)4 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)4 Test (org.junit.Test)4 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)3 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)3 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)3 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)3 StorageFile (org.finra.herd.model.api.xml.StorageFile)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 Tag (com.amazonaws.services.s3.model.Tag)1 File (java.io.File)1 Timestamp (java.sql.Timestamp)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1