org.sonar.api.utils.MessageException Java Examples

The following examples show how to use org.sonar.api.utils.MessageException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommunityProjectBranchesLoaderTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMessageExceptionOnIOException() {
    WsResponse mockResponse = mock(WsResponse.class);
    when(scannerWsClient.call(any())).thenReturn(mockResponse);

    Reader mockReader = new BufferedReader(new StringReader(
            GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>())))) {
        public void close() throws IOException {
            throw new IOException("Dummy IO Exception");
        }
    };
    when(mockResponse.contentReader()).thenReturn(mockReader);

    expectedException.expectMessage("Could not load branches from server");
    expectedException.expect(MessageException.class);

    CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient);
    testCase.load("project");


}
 
Example #2
Source File: CommunityProjectBranchesLoaderTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testErrorOnNon404HttpResponse() {
    WsResponse mockResponse = mock(WsResponse.class);
    when(scannerWsClient.call(any())).thenReturn(mockResponse);

    Reader mockReader = new BufferedReader(new StringReader(
            GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>())))) {
        public void close() {
            throw new HttpException("url", 12, "content");
        }
    };
    when(mockResponse.contentReader()).thenReturn(mockReader);

    expectedException.expectMessage("Could not load branches from server");
    expectedException.expect(MessageException.class);

    CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient);
    testCase.load("project");
}
 
Example #3
Source File: CommunityProjectPullRequestsLoaderTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMessageExceptionOnIOException() {
    WsResponse mockResponse = mock(WsResponse.class);
    when(scannerWsClient.call(any())).thenReturn(mockResponse);

    Reader mockReader = new BufferedReader(new StringReader(GsonHelper.create()
                                                                    .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse(
                                                                            new ArrayList<>())))) {
        public void close() throws IOException {
            throw new IOException("Dummy IO Exception");
        }
    };
    when(mockResponse.contentReader()).thenReturn(mockReader);

    expectedException.expectMessage("Could not load pull requests from server");
    expectedException.expect(MessageException.class);

    CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient);
    testCase.load("project");


}
 
Example #4
Source File: CommunityProjectPullRequestsLoaderTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testErrorOnNon404HttpResponse() {
    WsResponse mockResponse = mock(WsResponse.class);
    when(scannerWsClient.call(any())).thenReturn(mockResponse);

    Reader mockReader = new BufferedReader(new StringReader(GsonHelper.create()
                                                                    .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse(
                                                                            new ArrayList<>())))) {
        public void close() {
            throw new HttpException("url", 12, "content");
        }
    };
    when(mockResponse.contentReader()).thenReturn(mockReader);

    expectedException.expectMessage("Could not load pull requests from server");
    expectedException.expect(MessageException.class);

    CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient);
    testCase.load("project");
}
 
Example #5
Source File: GoogleIdentityProvider.java    From sonar-auth-google with Apache License 2.0 5 votes vote down vote up
@Override
public void callback(CallbackContext context) {
  HttpServletRequest request = context.getRequest();
  OAuthService scribe = newScribeBuilder(context).build();
  String oAuthVerifier = request.getParameter("code");
  Token accessToken = scribe.getAccessToken(EMPTY_TOKEN, new Verifier(oAuthVerifier));

  GsonUser gsonUser = requestUser(scribe, accessToken);
  String redirectTo;
  if (settings.oauthDomain()==null || (checkValidDomain(settings.oauthDomain(), gsonUser.getEmail()))) {
      redirectTo = settings.getSonarBaseURL();
      String referer_url = request.getHeader("referer");
      try {
          URL urlObj = new URL(referer_url);
          String returnToValue = null;
          for( String param : urlObj.getQuery().split("&")) {
              if( param.startsWith("return_to=")){
                  System.out.println("Return_to param : " + param);
                  System.out.println("Web context : " + settings.getWebContext());
                  param = URLDecoder.decode(param,"UTF-8");
                  returnToValue = param.split("=",2)[1].replace(settings.getWebContext(),"");
              }
          }
          if(returnToValue != null){
              redirectTo = redirectTo.concat(returnToValue);
          }
      } catch(Exception e) {
          LOGGER.trace("Exception while parsing return to URL");
      }
    UserIdentity userIdentity = userIdentityFactory.create(gsonUser);
    context.authenticate(userIdentity);
  } else {
    redirectTo = settings.getSonarBaseURL()+"/sessions/unauthorized#";
  }
  try {
    context.getResponse().sendRedirect(redirectTo);
  } catch (IOException ioe) {
    throw MessageException.of("Unable to redirect after OAuth login", ioe);
  }
}
 
Example #6
Source File: CloverXmlReportParserTest.java    From sonar-clover with Apache License 2.0 4 votes vote down vote up
@Test(expected = MessageException.class)
public void bad_clover_should_throw_exception() throws Exception {
  reportParser.collect(TestUtils.getResource(getClass(), "bad_clover.xml"));
}