@Test public void testCreateIssue() throws Exception { Mockito.when(pluginManagerService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> projectComponents = new ArrayList<>(); projectComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(projectComponents); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); Optional<UserDetailsResponseModel> userDetails = Optional.of(new TestIssueCreator()); Mockito.when(userSearchService.findUserByUsername(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); List<IssueSearchIssueComponent> issues = new ArrayList<>(); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel("", issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); IssueResponseModel issue = createIssueResponse(); Mockito.when(issueService.createIssue(Mockito.any(IssueCreationRequestModel.class))).thenReturn(issue); JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = Mockito.mock(JiraIssueSearchProperties.class); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCreationRequest.of(searchProperties, content, alertIssueOrigin)); IssueTrackerResponse response = service.sendRequests(requests); assertNotNull(response); assertNotNull(response.getStatusMessage()); boolean anyIssuesMatchKey = response.getUpdatedIssues() .stream() .map(IssueTrackerIssueResponseModel::getIssueKey) .anyMatch("project-1"::equals); assertTrue(anyIssuesMatchKey, "No issues matched the expected key"); }
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
JiraServerRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
JiraServerRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
JiraServerRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
JiraServerRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }