/** * Gets a security function entity and ensure it exists. * * @param securityFunctionName the security function name (case insensitive) * * @return the security function entity */ public SecurityFunctionEntity getSecurityFunctionEntity(String securityFunctionName) { SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(securityFunctionName); if (securityFunctionEntity == null) { throw new ObjectNotFoundException(String.format("Security function with name \"%s\" doesn't exist.", securityFunctionName)); } return securityFunctionEntity; } }
@Test public void testExceptionMessageAndThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); ObjectNotFoundException ObjectNotFoundException = new ObjectNotFoundException(TEST_MESSAGE_1, exception); assertTrue(ObjectNotFoundException.getMessage().equals(TEST_MESSAGE_1)); assertTrue(ObjectNotFoundException.getCause().getMessage().equals(TEST_MESSAGE_2)); }
@Test public void testExceptionThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); ObjectNotFoundException ObjectNotFoundException = new ObjectNotFoundException(exception); assertTrue(ObjectNotFoundException.getCause().getMessage().equals(TEST_MESSAGE_2)); } }
@Test public void testExceptionNoArgConstructor() throws Exception { ObjectNotFoundException exception = new ObjectNotFoundException(); assertTrue(exception.getMessage() == null); }
@Test public void testGetTagsTagTypeNoExists() { // Try to retrieve a list of tag keys for a non-existing tag type. try { tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE); fail(); } catch (ObjectNotFoundException e) { assertEquals(String.format("Tag type with code \"%s\" doesn't exist.", TAG_TYPE), e.getMessage()); } }
@Test public void testGetBusinessObjectDataNotificationRegistrationsByNamespaceNamespaceNoExists() { // Try to retrieve business object data notifications for a non-existing namespace. try { businessObjectDataNotificationRegistrationService.getBusinessObjectDataNotificationRegistrationsByNamespace(NAMESPACE); fail("Should throw an ObjectNotFoundException when using non-existing namespace."); } catch (ObjectNotFoundException e) { assertEquals(String.format("Namespace \"%s\" doesn't exist.", NAMESPACE), e.getMessage()); } }
@Test public void testExceptionMessageConstructor() throws Exception { ObjectNotFoundException exception = new ObjectNotFoundException(TEST_MESSAGE_1); assertTrue(exception.getMessage().equals(TEST_MESSAGE_1)); }
/** * Gets a security role entity and ensure it exists. * * @param securityRoleName the security role name (case insensitive) * * @return the security role entity */ public SecurityRoleEntity getSecurityRoleEntity(String securityRoleName) { SecurityRoleEntity securityRoleEntity = securityRoleDao.getSecurityRoleByName(securityRoleName); if (securityRoleEntity == null) { throw new ObjectNotFoundException(String.format("Security role with name \"%s\" doesn't exist.", securityRoleName)); } return securityRoleEntity; } }
@Test public void testGetStorageUnitNotificationRegistrationsByNamespaceNamespaceNoExists() { // Try to retrieve storage unit notifications for a non-existing namespace. try { storageUnitNotificationRegistrationService.getStorageUnitNotificationRegistrationsByNamespace(NAMESPACE); fail("Should throw an ObjectNotFoundException when using non-existing namespace."); } catch (ObjectNotFoundException e) { assertEquals(String.format("Namespace \"%s\" doesn't exist.", NAMESPACE), e.getMessage()); } }
/** * Gets record retention type entity form retention type code * * @param retentionTypeCode retention type code * * @return the retention type entity */ public RetentionTypeEntity getRecordRetentionTypeEntity(String retentionTypeCode) { RetentionTypeEntity recordRetentionTypeEntity = retentionTypeDao.getRetentionTypeByCode(retentionTypeCode); if (recordRetentionTypeEntity == null) { throw new ObjectNotFoundException(String.format("Record retention type with code \"%s\" doesn't exist.", retentionTypeCode)); } return recordRetentionTypeEntity; } }
@Test public void testGetSecurityRoleThatDoesNotExist() { try { // Retrieve the security role that does not exist. securityRoleService.getSecurityRole(new SecurityRoleKey(SECURITY_ROLE)); fail("Should throw ObjectNotFoundException when security role does not exist"); } catch (ObjectNotFoundException e) { assertEquals(String.format("Security role with name \"%s\" doesn't exist.", SECURITY_ROLE), e.getMessage()); } }
/** * Gets a message type entity by its code and ensure it exists. * * @param code the message type code (case insensitive) * * @return the message type entity */ public MessageTypeEntity getMessageTypeEntity(String code) { MessageTypeEntity messageTypeEntity = messageTypeDao.getMessageTypeByCode(code); if (messageTypeEntity == null) { throw new ObjectNotFoundException(String.format("Message type with code \"%s\" doesn't exist.", code)); } return messageTypeEntity; } }
@Test public void testGetNamespaceNoExists() throws Exception { // Try to get a non-existing namespace. try { namespaceService.getNamespace(new NamespaceKey(NAMESPACE)); fail("Should throw an ObjectNotFoundException when namespace doesn't exist."); } catch (ObjectNotFoundException e) { assertEquals(String.format("Namespace \"%s\" doesn't exist.", NAMESPACE), e.getMessage()); } }
/** * Gets a storage entity based on the storage name and makes sure that it exists. * * @param storageName the storage name (case insensitive) * * @return the storage entity * @throws ObjectNotFoundException if the storage entity doesn't exist */ public StorageEntity getStorageEntity(String storageName) throws ObjectNotFoundException { StorageEntity storageEntity = storageDao.getStorageByName(storageName); if (storageEntity == null) { throw new ObjectNotFoundException(String.format("Storage with name \"%s\" doesn't exist.", storageName)); } return storageEntity; }
@Test public void testGetDataProviderNoExists() throws Exception { // Try to get a non-existing data provider. try { dataProviderService.getDataProvider(new DataProviderKey(DATA_PROVIDER_NAME)); fail("Should throw an ObjectNotFoundException when data provider doesn't exist."); } catch (ObjectNotFoundException e) { assertEquals(String.format("Data provider with name \"%s\" doesn't exist.", DATA_PROVIDER_NAME), e.getMessage()); } }
/** * Gets a security role entity and ensure it exists. * * @param securityRoleName the security role name (case insensitive) * * @return the security role entity */ public SecurityRoleEntity getSecurityRoleEntity(String securityRoleName) { SecurityRoleEntity securityRoleEntity = securityRoleDao.getSecurityRoleByName(securityRoleName); if (securityRoleEntity == null) { throw new ObjectNotFoundException(String.format("Security role with name \"%s\" doesn't exist.", securityRoleName)); } return securityRoleEntity; } }
@Test public void testDeleteStorageInvalidName() { // Try to delete a storage which doesn't exist. try { storageService.deleteStorage(new StorageKey(INVALID_VALUE)); fail(); } catch (ObjectNotFoundException e) { assertEquals(String.format("Storage with name \"%s\" doesn't exist.", INVALID_VALUE), e.getMessage()); } }
/** * Gets an external interface entity and ensure it exists. * * @param externalInterfaceName the external interface name (case insensitive) * * @return the external interface entity */ public ExternalInterfaceEntity getExternalInterfaceEntity(String externalInterfaceName) { ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDao.getExternalInterfaceByName(externalInterfaceName); if (externalInterfaceEntity == null) { throw new ObjectNotFoundException(String.format("External interface with name \"%s\" doesn't exist.", externalInterfaceName)); } return externalInterfaceEntity; } }
@Test public void testGetTagTypeTagTypeNotExists() { // Try to retrieve a tag type instance when tag type code is not registered. try { tagTypeService.getTagType(new TagTypeKey(TAG_TYPE)); fail(); } catch (ObjectNotFoundException e) { assertEquals(String.format("Tag type with code \"%s\" doesn't exist.", TAG_TYPE), e.getMessage()); } }
/** * Gets a security function entity and ensure it exists. * * @param securityFunctionName the security function name (case insensitive) * * @return the security function entity */ public SecurityFunctionEntity getSecurityFunctionEntity(String securityFunctionName) { SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(securityFunctionName); if (securityFunctionEntity == null) { throw new ObjectNotFoundException(String.format("Security function with name \"%s\" doesn't exist.", securityFunctionName)); } return securityFunctionEntity; } }