Java Code Examples for org.sonar.api.utils.MessageException

The following examples show how to use org.sonar.api.utils.MessageException. These examples are extracted from open source projects. 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
@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
@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
@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
@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 Project: sonar-auth-google   Source File: GoogleIdentityProvider.java    License: 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 Project: sonar-clover   Source File: CloverXmlReportParserTest.java    License: 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"));
}