use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class BusinessObjectDefinitionSubjectMatterExpertServiceTest method testCreateBusinessObjectDefinitionSubjectMatterExpertBusinessObjectDefinitionSubjectMatterExpertAlreadyExists.
@Test
public void testCreateBusinessObjectDefinitionSubjectMatterExpertBusinessObjectDefinitionSubjectMatterExpertAlreadyExists() {
// Create and persist a business object definition subject matter expert entity.
businessObjectDefinitionSubjectMatterExpertDaoTestHelper.createBusinessObjectDefinitionSubjectMatterExpertEntity(new BusinessObjectDefinitionSubjectMatterExpertKey(BDEF_NAMESPACE, BDEF_NAME, USER_ID));
// Try to add a duplicate business object definition subject matter expert.
for (String userId : Arrays.asList(USER_ID, USER_ID.toUpperCase(), USER_ID.toLowerCase())) {
try {
businessObjectDefinitionSubjectMatterExpertService.createBusinessObjectDefinitionSubjectMatterExpert(new BusinessObjectDefinitionSubjectMatterExpertCreateRequest(new BusinessObjectDefinitionSubjectMatterExpertKey(BDEF_NAMESPACE, BDEF_NAME, userId)));
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create business object definition subject matter expert with user id \"%s\" " + "because it already exists for the business object definition {%s}.", userId, businessObjectDefinitionServiceTestHelper.getExpectedBusinessObjectDefinitionKeyAsString(BDEF_NAMESPACE, BDEF_NAME)), e.getMessage());
}
}
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataInitialDataVersionExists.
@Test
public void testCreateBusinessObjectDataInitialDataVersionExists() {
// Create relative database entities including the initial version of the business object data.
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, true, BDATA_STATUS);
storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
// Build a list of storage files.
List<StorageFile> storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES);
// Build a new business object data create request.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, STORAGE_NAME, testS3KeyPrefix, storageFiles);
// Try to create the second version of the business object data (version 1) with createNewVersion flag set to null and to false.
for (Boolean createNewVersionFlag : new Boolean[] { null, Boolean.FALSE }) {
request.setCreateNewVersion(createNewVersionFlag);
try {
businessObjectDataService.createBusinessObjectData(request);
fail(String.format("Should throw an IllegalArgumentException when the initial data version exists and createNewVersion flag is set to \"%s\".", createNewVersionFlag));
} catch (AlreadyExistsException e) {
assertEquals("Unable to create business object data because it already exists.", e.getMessage());
}
}
// Try to create the second version of the business object data with createNewVersion flag set to true.
request.setCreateNewVersion(true);
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
// Validate the results for the second version if the business object data.
businessObjectDataServiceTestHelper.validateBusinessObjectData(request, SECOND_DATA_VERSION, true, resultBusinessObjectData);
// Confirm that the initial version of the business object data now does not have the latestFlag set.
BusinessObjectDataEntity initialVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION));
assertEquals(false, initialVersionBusinessObjectDataEntity.getLatestVersion());
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataS3ManagedBucketFileAlreadyRegistered.
@Test
public void testCreateBusinessObjectDataS3ManagedBucketFileAlreadyRegistered() {
// Create relative database entities including a storage file entity registered by a test business object data with PARTITION_VALUE_2 partition value.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE_2, INITIAL_DATA_VERSION, true, BDATA_STATUS);
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageDao.getStorageByName(StorageEntity.MANAGED_STORAGE), businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, String.format("%s/%s", testS3KeyPrefix, LOCAL_FILE), FILE_SIZE_1_KB, ROW_COUNT_1000);
// Build a new business object data create request containing the already registered storage file.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE)));
try {
// Try to create a business object data instance.
businessObjectDataService.createBusinessObjectData(request);
fail("Should throw an AlreadyExistsException when a storage file in S3 managed storage is already registered by another business object data.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Found 1 storage file(s) matching \"%s\" S3 key prefix in \"%s\" storage that is registered with another business object data.", testS3KeyPrefix, StorageEntity.MANAGED_STORAGE), e.getMessage());
}
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataS3ManagedBucketDirectoryPathAlreadyRegistered.
@Test
public void testCreateBusinessObjectDataS3ManagedBucketDirectoryPathAlreadyRegistered() {
// Create relative database entities including a storage unit for the business object data with PARTITION_VALUE_2 partition value,
// but with a directory path that would actually match with a test business object data with PARTITION_VALUE partition value.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE_2, INITIAL_DATA_VERSION, true, BDATA_STATUS);
storageUnitDaoTestHelper.createStorageUnitEntity(storageDao.getStorageByName(StorageEntity.MANAGED_STORAGE), businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, testS3KeyPrefix);
// Build a new business object data create request containing the already registered storage directory path.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE)));
try {
// Try to create a business object data instance.
businessObjectDataService.createBusinessObjectData(request);
fail("Should throw an AlreadyExistsException when directory path in S3 managed " + "storage matches the location of an already registered business object data.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Storage directory \"%s\" in \"%s\" storage is already registered by the business object data {%s}.", testS3KeyPrefix, StorageEntity.MANAGED_STORAGE, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE_2, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION)), e.getMessage());
}
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class AttributeValueListServiceTest method createAttributeValueListAlreadyExists.
@Test
public void createAttributeValueListAlreadyExists() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create an attribute value list create request.
AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey);
// Mock calls to external methods.
when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(new NamespaceEntity());
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(new AttributeValueListEntity());
// Try to call the method under test.
try {
attributeValueListService.createAttributeValueList(request);
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", ATTRIBUTE_VALUE_LIST_NAME, ATTRIBUTE_VALUE_LIST_NAMESPACE), e.getMessage());
}
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
verifyNoMoreInteractionsHelper();
}
Aggregations