@Test public void shouldCollectIssuesByPriority() throws Exception { Filter filter = new Filter(null, 1l, null, null, null, null, null, null, false); JiraSoapService jiraSoapService = mock(JiraSoapService.class); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings); when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any())) .thenReturn(wrapper); RemoteIssue issue1 = new RemoteIssue(); issue1.setPriority("1"); issue1.setId("1"); RemoteIssue issue2 = new RemoteIssue(); issue2.setPriority("1"); issue2.setId("2"); RemoteIssue issue3 = new RemoteIssue(); issue3.setPriority("2"); issue3.setId("3"); when(jiraSoapService.getIssuesFromFilter("token", "1")) .thenReturn(new RemoteIssue[] {issue1, issue2, issue3}); Map<Long, Integer> foundIssues = sensor.collectIssuesByPriority(wrapper, "token", filter); assertThat(foundIssues.size()).isEqualTo(2); assertThat(foundIssues.get(1l)).isEqualTo(2); assertThat(foundIssues.get(2l)).isEqualTo(1); }
@Test public void faillIfNoFilterFound() throws Exception { JiraSoapService jiraSoapService = mock(JiraSoapService.class); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings); when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any())) .thenReturn(wrapper); when(jiraSoapService.getFavouriteFilters("token")).thenReturn(new RemoteFilter[0]); thrown.expect(IllegalStateException.class); thrown.expectMessage("Unable to find filter 'myFilter' in JIRA"); sensor.findJiraFilter(wrapper, "token"); }
@Test public void shouldCollectPriorities() throws Exception { JiraSoapService jiraSoapService = mock(JiraSoapService.class); RemotePriority priority1 = new RemotePriority(); priority1.setId("1"); priority1.setName("Minor"); when(jiraSoapService.getPriorities("token")).thenReturn(new RemotePriority[] {priority1}); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings); when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any())) .thenReturn(wrapper); Map<Long, String> foundPriorities = sensor.collectPriorities(wrapper, "token"); assertThat(foundPriorities.size()).isEqualTo(1); assertThat(foundPriorities.get(1l)).isEqualTo("Minor"); }
@Test public void shouldCreateIssue() throws Exception { // Given that RemoteIssue issue = new RemoteIssue(); JiraSoapService jiraSoapService = mock(JiraSoapService.class); when(jiraSoapService.createIssue(anyString(), any(RemoteIssue.class))).thenReturn(issue); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); // Verify RemoteIssue returnedIssue = jiraIssueCreator.doCreateIssue(sonarIssue, soapSession, settings, ""); verify(soapSession).connect("foo", "bar"); verify(soapSession).getJiraSoapService(); verify(soapSession).getAuthenticationToken(); assertThat(returnedIssue).isEqualTo(issue); }
@Test public void shouldFindFiltersWithPreviousJiraVersions() throws Exception { JiraSoapService jiraSoapService = mock(JiraSoapService.class); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings); when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any())) .thenReturn(wrapper); RemoteFilter myFilter = new RemoteFilter(); myFilter.setName("myFilter"); myFilter.setId("1"); when(jiraSoapService.getSavedFilters("token")).thenReturn(new RemoteFilter[] {myFilter}); when(jiraSoapService.getFavouriteFilters("token")).thenThrow(RemoteException.class); Filter foundFilter = sensor.findJiraFilter(wrapper, "token"); assertThat(foundFilter.getName()).isEqualTo(myFilter.getName()); }
@Test public void shouldCreateSoapSession() throws Exception { JiraSoapSession soapSession = jiraIssueCreator.createSoapSession(settings); assertThat(soapSession.getWebServiceUrl().toString()) .isEqualTo("http://my.jira.com/rpc/soap/jirasoapservice-v2"); }