Search in sources :

Example 81 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class StoragePolicyProcessorHelperServiceTest method testInitiateStoragePolicyTransitionStorageUnitNoExists.

@Test
public void testInitiateStoragePolicyTransitionStorageUnitNoExists() throws Exception {
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting(STORAGE_POLICY_NAMESPACE_CD, Arrays.asList(STORAGE_POLICY_RULE_TYPE), BDEF_NAMESPACE, BDEF_NAME, Arrays.asList(FORMAT_FILE_TYPE_CODE), Arrays.asList(STORAGE_NAME), Arrays.asList(StoragePolicyTransitionTypeEntity.GLACIER));
    // 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 business object data entity without any storage units.
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist a storage policy entity.
    storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Override configuration to specify some settings required for testing.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN.getKey(), S3_OBJECT_TAGGER_ROLE_ARN);
    overrideMap.put(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME.getKey(), S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    modifyPropertySourceInEnvironment(overrideMap);
    // Try to initiate a storage policy transition when storage unit does not exist.
    try {
        storagePolicyProcessorHelperService.initiateStoragePolicyTransition(new StoragePolicyTransitionParamsDto(), new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, INITIAL_VERSION));
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Could not find storage unit in \"%s\" storage for the business object data {%s}.", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : HashMap(java.util.HashMap) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) StoragePolicySelection(org.finra.herd.model.dto.StoragePolicySelection) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 82 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class StoragePolicyProcessorHelperServiceTest method testCompleteStoragePolicyTransitionBusinessObjectDataNoExists.

@Test
public void testCompleteStoragePolicyTransitionBusinessObjectDataNoExists() {
    // 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 complete a storage policy transition when business object data does not exist.
    StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, NO_STORAGE_FILES, S3_ARCHIVE_TO_GLACIER_TAG_KEY, S3_ARCHIVE_TO_GLACIER_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    try {
        storagePolicyProcessorHelperService.completeStoragePolicyTransition(storagePolicyTransitionParamsDto);
        fail("Should throw an ObjectNotFoundException when business object data does not exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(businessObjectDataKey, null), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 83 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationNoExists.

@Test
public void testDeleteUserNamespaceAuthorizationNoExists() {
    // Create a user namespace authorization key.
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    // Try to delete a user namespace authorization when it does not exist.
    try {
        userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(key);
        fail("Should throw an ObjectNotFoundException when user namespace authorization does not exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("User namespace authorization with user id \"%s\" and namespace \"%s\" doesn't exist.", key.getUserId(), key.getNamespace()), e.getMessage());
    }
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 84 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BaseJavaDelegateTest method testSetSecurityContextProcessDefinitionNoExists.

@Test
public void testSetSecurityContextProcessDefinitionNoExists() throws Exception {
    // Set up expected values.
    String processDefinitionId = "processDefinitionId";
    // Mock dependency methods.
    when(delegateExecution.getProcessDefinitionId()).thenReturn(processDefinitionId);
    when(activitiService.getProcessDefinitionById(any())).thenReturn(null);
    // Clear the security context.
    SecurityContextHolder.clearContext();
    // Try to execute the test method when process definition does not exist.
    try {
        baseJavaDelegate.setSecurityContext(delegateExecution);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Failed to find Activiti process definition for processDefinitionId=\"%s\".", processDefinitionId), e.getMessage());
    }
    // Verify dependencies were invoked correctly.
    InOrder inOrder = inOrder(activitiService);
    inOrder.verify(activitiService).getProcessDefinitionById(processDefinitionId);
    inOrder.verifyNoMoreInteractions();
    verifyNoMoreInteractions(activitiService);
    // Assert that security context is not set.
    assertNull(SecurityContextHolder.getContext().getAuthentication());
}
Also used : InOrder(org.mockito.InOrder) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 85 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class TagServiceTest method testGetTagTagNoExists.

@Test
public void testGetTagTagNoExists() {
    // Try to get a non-existing tag.
    try {
        tagService.getTag(new TagKey(TAG_TYPE, TAG_CODE));
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", TAG_CODE, TAG_TYPE), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Aggregations

ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)216 Test (org.junit.Test)193 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)36 ArrayList (java.util.ArrayList)18 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)16 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)16 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)14 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)12 TagKey (org.finra.herd.model.api.xml.TagKey)11 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)10 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)10 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)9 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)7 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5