use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class AlreadyExistsExceptionTest method testExceptionMessageConstructor.
@Test
public void testExceptionMessageConstructor() throws Exception {
AlreadyExistsException exception = new AlreadyExistsException(TEST_MESSAGE_1);
assertTrue(exception.getMessage().equals(TEST_MESSAGE_1));
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class PartitionKeyGroupServiceImpl method createPartitionKeyGroup.
/**
* Creates a new partition key group.
*
* @param request the information needed to create a partition key group
*
* @return the newly created partition key group information
*/
@Override
public PartitionKeyGroup createPartitionKeyGroup(PartitionKeyGroupCreateRequest request) {
// Perform the validation.
partitionKeyGroupHelper.validatePartitionKeyGroupKey(request.getPartitionKeyGroupKey());
// Ensure a partition key group with the specified name doesn't already exist.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDao.getPartitionKeyGroupByKey(request.getPartitionKeyGroupKey());
if (partitionKeyGroupEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create partition key group with name \"%s\" because it already exists.", request.getPartitionKeyGroupKey().getPartitionKeyGroupName()));
}
// Create a partition key group entity from the request information.
partitionKeyGroupEntity = createPartitionKeyGroupEntity(request);
// Persist the new entity.
partitionKeyGroupEntity = partitionKeyGroupDao.saveAndRefresh(partitionKeyGroupEntity);
// Create and return the partition key group object from the persisted entity.
return createPartitionKeyGroupFromEntity(partitionKeyGroupEntity);
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationAlreadyExists.
@Test
public void testCreateUserNamespaceAuthorizationAlreadyExists() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
// Try to create a user namespace authorization when it already exists.
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)));
fail("Should throw an AlreadyExistsException when user namespace authorization already exists.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create user namespace authorization with user id \"%s\" and namespace \"%s\" because it already exists.", key.getUserId(), key.getNamespace()), e.getMessage());
}
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceTest method testCreateStorageUnitNotificationRegistrationAlreadyExists.
@Test
public void testCreateStorageUnitNotificationRegistrationAlreadyExists() {
NotificationRegistrationKey notificationRegistrationKey = new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME);
// Create and persist a storage unit notification registration entity.
notificationRegistrationDaoTestHelper.createStorageUnitNotificationRegistrationEntity(notificationRegistrationKey, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2, notificationRegistrationDaoTestHelper.getTestJobActions(), NotificationRegistrationStatusEntity.ENABLED);
// Try to create a storage unit notification when it already exists.
try {
storageUnitNotificationRegistrationService.createStorageUnitNotificationRegistration(new StorageUnitNotificationRegistrationCreateRequest(notificationRegistrationKey, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), new StorageUnitNotificationFilter(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2), notificationRegistrationDaoTestHelper.getTestJobActions(), NotificationRegistrationStatusEntity.ENABLED));
fail("Should throw an AlreadyExistsException when storage unit notification already exists.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()), e.getMessage());
}
}
use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.
the class TagServiceTest method testCreateTagDisplayNameAlreadyExists.
@Test
public void testCreateTagDisplayNameAlreadyExists() {
// Create and persist a tag entity.
tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME.toUpperCase(), TAG_DESCRIPTION);
// Try to create a tag with a duplicate tag display name.
try {
tagService.createTag(new TagCreateRequest(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME.toLowerCase(), TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", TAG_DISPLAY_NAME.toLowerCase(), TAG_TYPE, TAG_CODE), e.getMessage());
}
}
Aggregations