/** * Asserts that no NamespaceIamRoleAuthorizationEntities exist for the given namespace. Throws a AlreadyExistsException if any * NamespaceIamRoleAuthorizationEntity exist. * * @param namespaceEntity The namespace entity */ private void assertNamespaceIamRoleAuthorizationNotExist(NamespaceEntity namespaceEntity) { if (CollectionUtils.isNotEmpty(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity))) { throw new AlreadyExistsException(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", namespaceEntity.getCode())); } }
@Test public void testCreateBusinessObjectDataAttributeBusinessObjectDataAttributeAlreadyExists() { // Create and persist a business object data attribute entity. businessObjectDataAttributeDaoTestHelper .createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), ATTRIBUTE_VALUE_1); // Try to add a duplicate business object data attribute. try { businessObjectDataAttributeService.createBusinessObjectDataAttribute(businessObjectDataAttributeServiceTestHelper .createBusinessObjectDataAttributeCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), ATTRIBUTE_VALUE_2)); fail("Should throw an AlreadyExistsException when business object data attribute already exists."); } catch (AlreadyExistsException e) { assertEquals(String.format( "Unable to create business object data attribute with name \"%s\" because it already exists for the business object data {" + "namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", businessObjectFormatFileType: \"%s\", " + "businessObjectFormatVersion: %d, businessObjectDataPartitionValue: \"%s\", businessObjectDataSubPartitionValues: \"%s,%s,%s,%s\", " + "businessObjectDataVersion: %d}.", ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES.get(0), SUBPARTITION_VALUES.get(1), SUBPARTITION_VALUES.get(2), SUBPARTITION_VALUES.get(3), DATA_VERSION), e.getMessage()); } }
@Test public void testExceptionMessageAndThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); AlreadyExistsException alreadyExistsException = new AlreadyExistsException(TEST_MESSAGE_1, exception); assertTrue(alreadyExistsException.getMessage().equals(TEST_MESSAGE_1)); assertTrue(alreadyExistsException.getCause().getMessage().equals(TEST_MESSAGE_2)); }
@Test public void testExceptionThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); AlreadyExistsException alreadyExistsException = new AlreadyExistsException(exception); assertTrue(alreadyExistsException.getCause().getMessage().equals(TEST_MESSAGE_2)); } }
@Test public void testExceptionNoArgConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(); assertTrue(exception.getMessage() == null); }
@Test public void testExceptionMessageConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(TEST_MESSAGE_1); assertTrue(exception.getMessage().equals(TEST_MESSAGE_1)); }
/** * Asserts that no NamespaceIamRoleAuthorizationEntities exist for the given namespace. Throws a AlreadyExistsException if any * NamespaceIamRoleAuthorizationEntity exist. * * @param namespaceEntity The namespace entity */ private void assertNamespaceIamRoleAuthorizationNotExist(NamespaceEntity namespaceEntity) { if (CollectionUtils.isNotEmpty(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity))) { throw new AlreadyExistsException(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", namespaceEntity.getCode())); } }
@Test public void testCreatePartitionKeyGroupEntityAlreadyExists() { // Create and persist a partition key group entity. partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); // Try to create a partition key group with the same partition key group name. try { partitionKeyGroupServiceTestHelper.createPartitionKeyGroup(PARTITION_KEY_GROUP); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create partition key group with name \"%s\" because it already exists.", PARTITION_KEY_GROUP), e.getMessage()); } }
/** * Gets a tag type entity by its display name and ensure it doesn't already exist. * * @param displayName the tag display name (case insensitive) * * @throws AlreadyExistsException if the tag type entity already exists */ public void assertTagTypeDisplayNameDoesNotExist(String displayName) throws AlreadyExistsException { TagTypeEntity tagTypeEntity = tagTypeDao.getTagTypeByDisplayName(displayName); if (tagTypeEntity != null) { throw new AlreadyExistsException(String.format("Display name \"%s\" already exists for tag type \"%s\".", displayName, tagTypeEntity.getCode())); } } }
@Test public void testCreateCustomDdlCustomDdlAlreadyExists() { // Create and persist a custom DDL entity. customDdlDaoTestHelper .createCustomDdlEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME.toUpperCase(), TEST_DDL); // Try to create a duplicate custom DDL instance (uses the same custom DDL name). try { customDdlService.createCustomDdl(customDdlServiceTestHelper .createCustomDdlCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME.toLowerCase(), TEST_DDL_2)); fail("Should throw an AlreadyExistsException when custom DDL already exists."); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create custom DDL with name \"%s\" because it already exists for the business object format " + "{namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", businessObjectFormatFileType: \"%s\", " + "businessObjectFormatVersion: %d}.", CUSTOM_DDL_NAME.toLowerCase(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage()); } }
/** * Gets a tag type entity by its display name and ensure it doesn't already exist. * * @param displayName the tag display name (case insensitive) * * @throws AlreadyExistsException if the tag type entity already exists */ public void assertTagTypeDisplayNameDoesNotExist(String displayName) throws AlreadyExistsException { TagTypeEntity tagTypeEntity = tagTypeDao.getTagTypeByDisplayName(displayName); if (tagTypeEntity != null) { throw new AlreadyExistsException(String.format("Display name \"%s\" already exists for tag type \"%s\".", displayName, tagTypeEntity.getCode())); } } }
@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()); } }
/** * Gets a global Attribute Definition entity and checks if it already exists. * * @param globalAttributeDefinitionKey the global Attribute Definition key (case insensitive) * * @throws AlreadyExistsException if the global Attribute Definition entity already exist */ public void validateGlobalAttributeDefinitionNoExists(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) throws AlreadyExistsException { // Validate that the global attribute definition entity does not already exist. if (globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey) != null) { throw new AlreadyExistsException(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())); } }
@Test public void testCreateTagTagAlreadyExists() { // Create and persist a tag entity. tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE.toUpperCase(), TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION); // Try to create a duplicate tag (uses the same tag type and tag name). try { tagService.createTag( new TagCreateRequest(new TagKey(TAG_TYPE, TAG_CODE.toLowerCase()), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_PARENT_TAG_KEY)); fail(); } catch (AlreadyExistsException e) { assertEquals(String .format("Unable to create tag with tag type code \"%s\" and tag code \"%s\" because it already exists.", TAG_TYPE, TAG_CODE.toLowerCase()), e.getMessage()); } }
/** * Gets a global Attribute Definition entity and checks if it already exists. * * @param globalAttributeDefinitionKey the global Attribute Definition key (case insensitive) * * @throws AlreadyExistsException if the global Attribute Definition entity already exist */ public void validateGlobalAttributeDefinitionNoExists(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) throws AlreadyExistsException { // Validate that the global attribute definition entity does not already exist. if (globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey) != null) { throw new AlreadyExistsException(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())); } }
@Test public void testUpdateTagDisplayNameAlreadyExistsForThisTagType() { // Create and persist a tag entity. tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION); // Create and persist a second tag entity for the same tag type that would have the display name to be updated to. tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2, TAG_DISPLAY_NAME_2.toUpperCase(), TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION); // Try to update a tag with an already existing display name. try { tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE), new TagUpdateRequest(TAG_DISPLAY_NAME_2.toLowerCase(), TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, 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_2.toLowerCase(), TAG_TYPE, TAG_CODE_2), e.getMessage()); } }
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
@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()); } }
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
@Test public void testCreateSecurityRoleAlreadyExists() { // Create a security role. securityRoleDaoTestHelper.createSecurityRoleEntity(SECURITY_ROLE, DESCRIPTION); try { securityRoleService.createSecurityRole(new SecurityRoleCreateRequest(SECURITY_ROLE, DESCRIPTION)); fail("Should throw an AlreadyExistsException when security role already exists"); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create security role \"%s\" because it already exists.", SECURITY_ROLE), e.getMessage()); } }