@Test public void testCreateIssue() throws Exception { Mockito.when(jiraAppService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> pageComponents = new ArrayList<>(); pageComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); PageOfProjectsResponseModel pageOfProjects = new PageOfProjectsResponseModel(pageComponents); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(pageOfProjects); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); List<UserDetailsResponseModel> userDetails = new ArrayList<>(); userDetails.add(new TestIssueCreator()); Mockito.when(userSearchService.findUser(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel(); List<IssueResponseModel> issues = new ArrayList<>(); searchResponseModel.setIssues(issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); IssueResponseModel issue = createIssueResponse(); Mockito.when(issueService.createIssue(Mockito.any(IssueCreationRequestModel.class))).thenReturn(issue); JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(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 Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests);  }