Example usage for org.apache.commons.configuration PropertiesConfiguration setProperty

List of usage examples for org.apache.commons.configuration PropertiesConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Document

Sets a new value for the specified property.

Usage

From source file:org.sonar.batch.MavenProjectBuilderTest.java

@Test
public void isNotLatestAnalysis() {
    setupData("isNotLatestAnalysis");

    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-12-25");

    Project project = new Project("my:key");
    builder.configure(project, configuration);

    assertThat(project.isLatestAnalysis(), is(false));
}

From source file:org.sonar.batch.phases.MavenPhaseExecutorTest.java

@Test
public void executePhase() {
    MavenPluginExecutor mavenPluginExecutor = mock(MavenPluginExecutor.class);
    MavenPhaseExecutor phaseExecutor = new MavenPhaseExecutor(mavenPluginExecutor);

    Project project = new Project("key");
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(MavenPhaseExecutor.PROP_PHASE, "myphase");
    project.setConfiguration(conf);//w  w w.j a  va2 s .co m

    phaseExecutor.execute(project);

    verify(mavenPluginExecutor).execute(project, "myphase");
}

From source file:org.sonar.batch.ServerMetadataTest.java

@Test
public void testLoadProperties() throws ParseException {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(CoreProperties.SERVER_ID, "123");
    conf.setProperty(CoreProperties.SERVER_VERSION, "2.2");
    conf.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
    conf.setProperty("sonar.host.url", "http://foo.com");

    ServerMetadata server = new ServerMetadata(conf);

    assertThat(server.getId(), is("123"));
    assertThat(server.getVersion(), is("2.2"));
    assertThat(server.getStartedAt().getDate(), is(18));
    assertThat(server.getURL(), is("http://foo.com"));
}

From source file:org.sonar.batch.ServerMetadataTest.java

/**
 * http://jira.codehaus.org/browse/SONAR-1685
 * The maven plugin fails if the property sonar.host.url ends with a slash
 *///from w  ww.  j a va 2s.c om
@Test
public void urlMustNotEndWithSlash() throws ParseException {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty("sonar.host.url", "http://localhost:80/");

    ServerMetadata server = new ServerMetadata(conf);
    assertThat(server.getURL(), is("http://localhost:80"));
}

From source file:org.sonar.jpa.session.AbstractDatabaseConnectorTest.java

@Test
public void getHibernateProperties() {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty("sonar.foo", "foo value");

    // all properties prefixed by sonar.hibernate are propagated to hibernate configuration (the prefix "sonar." is removed)
    conf.setProperty("sonar.hibernate.foo", "hibernate.foo value");

    // hardcoded property. Should be replaced by sonar.hibernate.hbm2ddl.auto
    conf.setProperty("sonar.jdbc.hibernate.hbm2ddl", "hibernate.hbm2ddl value");

    // the dialect is mandatory if the JDBC url is not set
    conf.setProperty("sonar.jdbc.dialect", DatabaseProperties.DIALECT_ORACLE);

    AbstractDatabaseConnector connector = new TestDatabaseConnector(conf);
    connector.start();//from   w  w w  .  j  a v a  2  s  .co  m

    Properties hibernateProps = connector.getHibernateProperties();
    assertThat(hibernateProps.getProperty("sonar.foo"), Matchers.nullValue()); // not an hibernate property
    assertThat(hibernateProps.getProperty("hibernate.foo"), Matchers.is("hibernate.foo value"));
    assertThat(hibernateProps.getProperty("hibernate.hbm2ddl.auto"), Matchers.is("hibernate.hbm2ddl value"));
    assertThat(hibernateProps.getProperty("hibernate.dialect"),
            Matchers.is(Oracle.Oracle10gWithDecimalDialect.class.getName()));
}

From source file:org.sonar.jpa.session.DriverDatabaseConnectorTest.java

@Test(expected = DatabaseException.class)
public void failsIfUnvalidConfiguration() throws SQLException {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(DatabaseProperties.PROP_URL, "jdbc:foo:bar//xxx");
    conf.setProperty(DatabaseProperties.PROP_DRIVER, MemoryDatabaseConnector.DRIVER);
    conf.setProperty(DatabaseProperties.PROP_USER, "sa");
    conf.setProperty(DatabaseProperties.PROP_PASSWORD, null);
    connector = new DriverDatabaseConnector(conf);
    try {// w  ww .  j av a 2 s  .c o  m
        connector.start();
    } finally {
        assertFalse(connector.isStarted());
        assertFalse(connector.isOperational());
    }
}

From source file:org.sonar.jpa.session.DriverDatabaseConnectorTest.java

@Test
public void deprecatedParametersAreStillValid() {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(DatabaseProperties.PROP_DRIVER_DEPRECATED, MemoryDatabaseConnector.DRIVER);
    conf.setProperty(DatabaseProperties.PROP_USER_DEPRECATED, "freddy");
    connector = new DriverDatabaseConnector(conf);

    assertThat(connector.getDriver(), is(MemoryDatabaseConnector.DRIVER));
    assertThat(connector.getUsername(), Matchers.is("freddy"));
}

From source file:org.sonar.jpa.session.MemoryDatabaseConnector.java

protected static Configuration getInMemoryConfiguration(boolean createSchema) {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(DatabaseProperties.PROP_URL, URL);
    conf.setProperty(DatabaseProperties.PROP_DRIVER, DRIVER);
    conf.setProperty(DatabaseProperties.PROP_USER, USER);
    conf.setProperty(DatabaseProperties.PROP_PASSWORD, PASSWORD);
    conf.setProperty(DatabaseProperties.PROP_ISOLATION, ISOLATION);
    if (createSchema) {
        conf.setProperty(DatabaseProperties.PROP_HIBERNATE_HBM2DLL, "create-drop");
    }/*from  w ww. jav a  2s.com*/
    return conf;
}

From source file:org.sonar.plugins.codesize.SizingProfileTest.java

@Test
public void profileTest() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CodesizeConstants.SONAR_CODESIZE_PROFILE, "Java\nincludes=*\nexcludes=*");
    SizingProfile profile = new SizingProfile(configuration);

    assertEquals(1, profile.getFileSetDefinitions().size());
    assertEquals(1, profile.getFileSetDefinitions().get(0).getIncludes().size());
    assertEquals(1, profile.getFileSetDefinitions().get(0).getExcludes().size());
}

From source file:org.sonar.plugins.core.batch.ExcludedResourceFilterTest.java

@Test
public void noPatternsMatch() {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[] { "**/foo/*.java", "**/bar/*" });
    Project project = new Project("foo").setConfiguration(conf);
    ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
    assertThat(filter.isIgnored(mock(Resource.class)), is(false));
}