### Question:
DataEngineCommonHandler { protected String createExternalEntity(String userId, InstanceProperties instanceProperties, InstanceStatus instanceStatus, String entityTypeName, String externalSourceName) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createExternalEntity"; String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); TypeDef entityTypeDef = repositoryHelper.getTypeDefByName(userId, entityTypeName); return repositoryHandler.createExternalEntity(userId, entityTypeDef.getGUID(), entityTypeDef.getName(), externalSourceGUID, externalSourceName, instanceProperties, instanceStatus, methodName); } DataEngineCommonHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler,
                                   RepositoryHandler repositoryHandler, OMRSRepositoryHelper repositoryHelper,
                                   DataEngineRegistrationHandler dataEngineRegistrationHandler);   }### Answer:
@Test void createExternalEntity() throws InvalidParameterException, PropertyServerException, UserNotAuthorizedException { String methodName = "createExternalEntity"; when(repositoryHandler.createExternalEntity(USER, ENTITY_TYPE_GUID, ENTITY_TYPE_NAME, EXTERNAL_SOURCE_DE_GUID, EXTERNAL_SOURCE_DE_QUALIFIED_NAME, instanceProperties, InstanceStatus.ACTIVE, methodName)).thenReturn(GUID); String result = dataEngineCommonHandler.createExternalEntity(USER, instanceProperties, InstanceStatus.ACTIVE, ENTITY_TYPE_NAME, EXTERNAL_SOURCE_DE_QUALIFIED_NAME); assertEquals(GUID, result); }
@Test void createExternalEntity_throwsUserNotAuthorizedException() throws PropertyServerException, UserNotAuthorizedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { String methodName = "createExternalEntity"; UserNotAuthorizedException mockedException = mockException(UserNotAuthorizedException.class, methodName); when(repositoryHandler.createExternalEntity(USER, ENTITY_TYPE_GUID, ENTITY_TYPE_NAME, EXTERNAL_SOURCE_DE_GUID, EXTERNAL_SOURCE_DE_QUALIFIED_NAME, instanceProperties, InstanceStatus.ACTIVE, methodName)).thenThrow(mockedException); UserNotAuthorizedException thrown = assertThrows(UserNotAuthorizedException.class, () -> dataEngineCommonHandler.createExternalEntity(USER, instanceProperties, InstanceStatus.ACTIVE, ENTITY_TYPE_NAME, EXTERNAL_SOURCE_DE_QUALIFIED_NAME)); assertTrue(thrown.getMessage().contains("OMAS-DATA-ENGINE-404-001 ")); }