@Test public void testExceptionMessageConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(TEST_MESSAGE_1); assertTrue(exception.getMessage().equals(TEST_MESSAGE_1)); }
@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 testExceptionNoArgConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(); assertTrue(exception.getMessage() == null); }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@Test public void testCreateNamespaceAlreadyExists() throws Exception { // Create and persist a namespace. namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); // Try to create a namespace when it already exists. try { namespaceService.createNamespace(namespaceServiceTestHelper.createNamespaceCreateRequest(NAMESPACE)); fail("Should throw an AlreadyExistsException when namespace already exists."); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create namespace \"%s\" because it already exists.", NAMESPACE), e.getMessage()); } }
@Test public void testCreateDataProviderAlreadyExists() throws Exception { // Create and persist a data provider. dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME); // Try to create a data provider when it already exists. try { dataProviderService.createDataProvider(new DataProviderCreateRequest(DATA_PROVIDER_NAME)); fail("Should throw an AlreadyExistsException when data provider already exists."); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create data provider \"%s\" because it already exists.", DATA_PROVIDER_NAME), e.getMessage()); } }
@Test public void testCreateBusinessObjectDefinitionAlreadyExists() throws Exception { // Create and persist a business object definition. businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, null); // Try to create a business object definition when it already exists. try { businessObjectDefinitionService.createBusinessObjectDefinition( new BusinessObjectDefinitionCreateRequest(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, NO_ATTRIBUTES)); fail("Should throw an AlreadyExistsException when business object definition already exists."); } catch (AlreadyExistsException e) { assertEquals(String .format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", BDEF_NAME, NAMESPACE), e.getMessage()); } }
@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()); } }
@Test public void testCreateStorageStorageAlreadyExists() { // Create and persist a valid storage. StorageCreateRequest storageCreateRequest = getNewStorageCreateRequest(); storageService.createStorage(storageCreateRequest); // Try creating that storage again which is invalid since it already exists. try { storageService.createStorage(storageCreateRequest); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Storage with name \"%s\" already exists.", storageCreateRequest.getName()), e.getMessage()); } }
@Test public void testCreateTagTypeDisplayNameAlreadyExists() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Try to create a duplicate tag type instance (uses the same display name). try { tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE_2), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Display name \"%s\" already exists for tag type \"%s\".", TAG_TYPE_DISPLAY_NAME, TAG_TYPE), e.getMessage()); } }
@Test public void testCreateTagTypeTagTypeAlreadyExists() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Try to create a duplicate tag type instance (uses the same tag type code). try { tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create tag type with code \"%s\" because it already exists.", TAG_TYPE), e.getMessage()); } }
@Test public void testUpdateTagTypeDisplayNameAlreadyExists() { // Create and persist two tag type entities with the second one having display name that we want to update to. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2); // Try to update a tag type instance when display name already exists. try { tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Display name \"%s\" already exists for tag type \"%s\".", TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_2), e.getMessage()); } }
@Test public void testGetS3KeyPrefixNoDataVersionSpecifiedLatestDataVersionExistsCreateNewVersionIsFalse() { // Create database entities required for testing. Please note that we are passing the flag to create a business object data entity. businessObjectDataServiceTestHelper.createDatabaseEntitiesForGetS3KeyPrefixTesting(true); // Get the test partition columns. List<SchemaColumn> testPartitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns(); String testPartitionKey = testPartitionColumns.get(0).getName(); // Try to get an S3 key prefix for the next business object data with the create new version flag not set to "true". try { storageUnitService.getS3KeyPrefix( new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, null), testPartitionKey, STORAGE_NAME, false); } catch (AlreadyExistsException e) { assertEquals("Initial version of the business object data already exists.", e.getMessage()); } }
@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()); } }
@Test public void testCreateBusinessObjectDefinitionTagBusinessObjectDefinitionTagAlreadyExists() { // Create a business object definition tag key. BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey = new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE)); // Create and persist a business object definition tag entity. businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionTagKey); // Try to add a duplicate business object definition tag. try { businessObjectDefinitionTagService.createBusinessObjectDefinitionTag(new BusinessObjectDefinitionTagCreateRequest(businessObjectDefinitionTagKey)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Tag with tag type \"%s\" and code \"%s\" already exists for business object definition {%s}.", TAG_TYPE, TAG_CODE, businessObjectDefinitionServiceTestHelper.getExpectedBusinessObjectDefinitionKeyAsString(BDEF_NAMESPACE, BDEF_NAME)), e.getMessage()); } }