Search in sources :

Example 6 with SonarException

use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.

the class SecurityRealmFactory method start.

@Override
public void start() {
    if (realm != null) {
        Logger logger = Loggers.get("org.sonar.INFO");
        try {
            logger.info("Security realm: " + realm.getName());
            realm.init();
            logger.info("Security realm started");
        } catch (RuntimeException e) {
            if (ignoreStartupFailure) {
                logger.error("IGNORED - Security realm fails to start: " + e.getMessage());
            } else {
                throw new SonarException("Security realm fails to start: " + e.getMessage(), e);
            }
        }
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) Logger(org.sonar.api.utils.log.Logger)

Example 7 with SonarException

use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.

the class UpdateCenterClientTest method ignore_connection_errors.

@Test
public void ignore_connection_errors() {
    when(reader.readString(any(URI.class), eq(StandardCharsets.UTF_8))).thenThrow(new SonarException());
    assertThat(underTest.getUpdateCenter()).isAbsent();
}
Also used : SonarException(org.sonar.api.utils.SonarException) URI(java.net.URI) Test(org.junit.Test)

Example 8 with SonarException

use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.

the class PluginDownloaderTest method throw_exception_if_could_not_download.

@Test
public void throw_exception_if_could_not_download() {
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("file://not_found");
    test.addRelease(test10);
    when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
    pluginDownloader.start();
    try {
        pluginDownloader.download("foo", create("1.0"));
        fail();
    } catch (SonarException e) {
    // ok
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 9 with SonarException

use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.

the class PluginDownloaderTest method throw_exception_if_download_fail.

@Test
public void throw_exception_if_download_fail() {
    Plugin test = Plugin.factory("test");
    Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.jar");
    test.addRelease(test10);
    when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
    doThrow(new RuntimeException()).when(httpDownloader).download(any(URI.class), any(File.class));
    pluginDownloader.start();
    try {
        pluginDownloader.download("foo", create("1.0"));
        fail();
    } catch (SonarException e) {
    // ok
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) URI(java.net.URI) File(java.io.File) Release(org.sonar.updatecenter.common.Release) Plugin(org.sonar.updatecenter.common.Plugin) Test(org.junit.Test)

Example 10 with SonarException

use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method readStringWithTimeout.

@Test
public void readStringWithTimeout() throws URISyntaxException {
    thrown.expect(new BaseMatcher<Exception>() {

        @Override
        public boolean matches(Object ex) {
            return ex instanceof SonarException && ((SonarException) ex).getCause() instanceof SocketTimeoutException;
        }

        @Override
        public void describeTo(Description arg0) {
        }
    });
    new DefaultHttpDownloader(new MapSettings(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) MapSettings(org.sonar.api.config.MapSettings) SonarException(org.sonar.api.utils.SonarException) URI(java.net.URI) SonarException(org.sonar.api.utils.SonarException) URISyntaxException(java.net.URISyntaxException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Aggregations

SonarException (org.sonar.api.utils.SonarException)16 Test (org.junit.Test)6 IOException (java.io.IOException)4 URI (java.net.URI)4 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)3 Release (org.sonar.updatecenter.common.Release)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 MapSettings (org.sonar.api.config.MapSettings)2 Plugin (org.sonar.updatecenter.common.Plugin)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 NoRouteToHostException (java.net.NoRouteToHostException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1