Search in sources :

Example 11 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class EsSettingsTest method minProps.

private Props minProps() throws IOException {
    File homeDir = temp.newFolder();
    Props props = new Props(new Properties());
    ProcessProperties.completeDefaults(props);
    props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
    return props;
}
Also used : Props(org.sonar.process.Props) ProcessProperties(org.sonar.process.ProcessProperties) Properties(java.util.Properties) File(java.io.File)

Example 12 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class EmbeddedTomcatTest method start.

@Test
public void start() throws Exception {
    Props props = new Props(new Properties());
    // prepare file system
    File home = temp.newFolder();
    File data = temp.newFolder();
    File webDir = new File(home, "web");
    FileUtils.write(new File(home, "web/WEB-INF/web.xml"), "<web-app/>");
    props.set("sonar.path.home", home.getAbsolutePath());
    props.set("sonar.path.data", data.getAbsolutePath());
    props.set("sonar.path.web", webDir.getAbsolutePath());
    props.set("sonar.path.logs", temp.newFolder().getAbsolutePath());
    // start server on a random port
    int httpPort = NetworkUtils.freePort();
    int ajpPort = NetworkUtils.freePort();
    props.set("sonar.web.port", String.valueOf(httpPort));
    props.set("sonar.ajp.port", String.valueOf(ajpPort));
    EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
    assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.DOWN);
    tomcat.start();
    assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.UP);
    // check that http connector accepts requests
    URL url = new URL("http://" + Inet4Address.getLocalHost().getHostAddress() + ":" + httpPort);
    url.openConnection().connect();
    // stop server
    tomcat.terminate();
    // tomcat.isUp() must not be called. It is used to wait for server startup, not shutdown.
    try {
        url.openConnection().connect();
        fail();
    } catch (ConnectException e) {
    // expected
    }
}
Also used : Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 13 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method test_max_post_size_for_http_connection.

@Test
public void test_max_post_size_for_http_connection() throws Exception {
    Properties properties = new Properties();
    Props props = new Props(properties);
    TomcatConnectors.configure(tomcat, props);
    verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {

        @Override
        public boolean matches(Object o) {
            Connector c = (Connector) o;
            return c.getMaxPostSize() == -1;
        }
    }));
}
Also used : Connector(org.apache.catalina.connector.Connector) ArgumentMatcher(org.mockito.ArgumentMatcher) Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 14 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method fail_with_ISE_if_http_port_is_invalid.

@Test
public void fail_with_ISE_if_http_port_is_invalid() {
    Properties p = new Properties();
    p.setProperty("sonar.web.port", "-1");
    try {
        TomcatConnectors.configure(tomcat, new Props(p));
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("HTTP port '-1' is invalid");
    }
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 15 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method bind_to_specific_address.

@Test
public void bind_to_specific_address() {
    Properties p = new Properties();
    p.setProperty("sonar.web.port", "9000");
    p.setProperty("sonar.web.host", "1.2.3.4");
    TomcatConnectors.configure(tomcat, new Props(p));
    verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {

        @Override
        public boolean matches(Object o) {
            Connector c = (Connector) o;
            return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("1.2.3.4");
        }
    }));
}
Also used : Connector(org.apache.catalina.connector.Connector) ArgumentMatcher(org.mockito.ArgumentMatcher) Properties(java.util.Properties) Props(org.sonar.process.Props) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

Props (org.sonar.process.Props)39 Test (org.junit.Test)32 Properties (java.util.Properties)20 File (java.io.File)11 ProcessProperties (org.sonar.process.ProcessProperties)9 Settings (org.elasticsearch.common.settings.Settings)7 InetAddress (java.net.InetAddress)3 Connector (org.apache.catalina.connector.Connector)3 ArgumentMatcher (org.mockito.ArgumentMatcher)3 ProcessEntryPoint (org.sonar.process.ProcessEntryPoint)3 ConnectException (java.net.ConnectException)1 URL (java.net.URL)1 Date (java.util.Date)1 StandardContext (org.apache.catalina.core.StandardContext)1 Tomcat (org.apache.catalina.startup.Tomcat)1 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 Matchers.anyString (org.mockito.Matchers.anyString)1 MutablePicoContainer (org.picocontainer.MutablePicoContainer)1 CoreProperties (org.sonar.api.CoreProperties)1