Search in sources :

Example 31 with AlreadyExistsException

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

the class EmrClusterDefinitionServiceTest method testCreateEmrClusterDefinitionEmrClusterDefinitionAlreadyExists.

@Test
public void testCreateEmrClusterDefinitionEmrClusterDefinitionAlreadyExists() throws Exception {
    // Create and persist the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create and persist the EMR cluster definition entity.
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH));
    // Try to perform a create using an already existing EMR cluster definition name.
    try {
        emrClusterDefinitionService.createEmrClusterDefinition(createEmrClusterDefinitionCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)));
        fail("Should throw an AlreadyExistsException when EMR cluster definition already exists.");
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create EMR cluster definition with name \"%s\" for namespace \"%s\" because it already exists.", EMR_CLUSTER_DEFINITION_NAME, NAMESPACE), e.getMessage());
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 32 with AlreadyExistsException

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

the class ExpectedPartitionValueServiceTest method testCreateExpectedPartitionValuesExpectedPartitionValueAlreadyExists.

@Test
public void testCreateExpectedPartitionValuesExpectedPartitionValueAlreadyExists() {
    // Create and persist a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Create and persist a single test expected partition value.
    expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE));
    // Try to perform a create using an already existing expected partition value.
    ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, Arrays.asList(PARTITION_VALUE));
    try {
        expectedPartitionValueService.createExpectedPartitionValues(request);
        fail("Should throw an AlreadyExistsException when expected partition value already exists.");
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Expected partition value \"%s\" already exists in \"%s\" partition key group.", PARTITION_VALUE, PARTITION_KEY_GROUP), e.getMessage());
    }
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) ExpectedPartitionValuesCreateRequest(org.finra.herd.model.api.xml.ExpectedPartitionValuesCreateRequest) Test(org.junit.Test)

Example 33 with AlreadyExistsException

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

the class GlobalAttributeDefinitionDaoHelperTest method testValidateGlobalAttributeDefinitionNoExistsEntityExists.

@Test
public void testValidateGlobalAttributeDefinitionNoExistsEntityExists() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    // Mock calls to external methods.
    when(globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity);
    // Try to call the method under test.
    try {
        globalAttributeDefinitionDaoHelper.validateGlobalAttributeDefinitionNoExists(globalAttributeDefinitionKey);
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create global attribute definition with global attribute definition level \"%s\" " + "and global attribute definition name \"%s\" because it already exists.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName()), e.getMessage());
    }
    // Verify the external calls.
    verify(globalAttributeDefinitionDao).getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey);
    verifyNoMoreInteractions(globalAttributeDefinitionDao);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 34 with AlreadyExistsException

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

the class BusinessObjectDataStorageFileServiceTest method testCreateBusinessObjectDataStorageFilesS3ManagedStorageFilePreviouslyRegistered.

@Test
public void testCreateBusinessObjectDataStorageFilesS3ManagedStorageFilePreviouslyRegistered() {
    // Create a test file path.
    String testFilePath = testS3KeyPrefix + "/" + FILE_PATH_1;
    // Create test data.
    createData(null, true, Arrays.asList(testFilePath));
    // Try to add an already registered storage file.
    try {
        businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(new BusinessObjectDataStorageFilesCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, StorageEntity.MANAGED_STORAGE, Arrays.asList(createFile(testFilePath, FILE_SIZE_1_KB, ROW_COUNT_1000)), NO_DISCOVER_STORAGE_FILES));
        fail("Should throw an AlreadyExistsException when request contains storage file what is already registered.");
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("S3 file \"%s\" in \"%s\" storage is already registered by the business object data {%s}.", testFilePath, StorageEntity.MANAGED_STORAGE, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION)), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageFilesCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateRequest) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 35 with AlreadyExistsException

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

the class BusinessObjectDataStorageFileServiceTest method testCreateBusinessObjectDataStorageFilesStorageFilePreviouslyRegistered.

@Test
public void testCreateBusinessObjectDataStorageFilesStorageFilePreviouslyRegistered() {
    createData(null, false);
    // Try to add an already registered storage file.
    try {
        businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(new BusinessObjectDataStorageFilesCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, STORAGE_NAME, Arrays.asList(createFile(FILE_PATH_1, FILE_SIZE_1_KB, ROW_COUNT_1000)), NO_DISCOVER_STORAGE_FILES));
        fail("Should throw an AlreadyExistsException when request contains storage file what is already registered.");
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("S3 file \"%s\" in \"%s\" storage is already registered by the business object data {%s}.", FILE_PATH_1, STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION)), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageFilesCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateRequest) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Aggregations

AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)62 Test (org.junit.Test)35 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)12 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)11 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)9 ArrayList (java.util.ArrayList)7 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 StorageEntity (org.finra.herd.model.jpa.StorageEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)5 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)4 StorageFile (org.finra.herd.model.api.xml.StorageFile)4 TagKey (org.finra.herd.model.api.xml.TagKey)4 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)3 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)3 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)3 RelationalTableRegistrationCreateRequest (org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest)3 TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)3