Search in sources :

Example 16 with JdbcFeatureStore

use of org.ff4j.store.JdbcFeatureStore in project ff4j by ff4j.

the class JdbcFeatureStoreErrorTest method testgetReadGroupKO.

@Test(expected = FeatureAccessException.class)
public void testgetReadGroupKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcFeatureStore jrepo = new JdbcFeatureStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.readGroup("xx");
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 17 with JdbcFeatureStore

use of org.ff4j.store.JdbcFeatureStore in project ff4j by ff4j.

the class JdbcFeatureStoreErrorTest method testreadAllKO.

@Test(expected = FeatureAccessException.class)
public void testreadAllKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcFeatureStore jrepo = new JdbcFeatureStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.readAll();
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 18 with JdbcFeatureStore

use of org.ff4j.store.JdbcFeatureStore in project ff4j by ff4j.

the class JdbcFeatureStoreSchemaTest method initStore.

/**
 * {@inheritDoc}
 * @throws SQLException
 */
public void initStore() throws SQLException {
    builder = new EmbeddedDatabaseBuilder();
    db = builder.setType(EmbeddedDatabaseType.HSQL).build();
    PreparedStatement prepareStatement = db.getConnection().prepareStatement("CREATE SCHEMA FF4J");
    prepareStatement.executeUpdate();
    prepareStatement = db.getConnection().prepareStatement("CREATE SCHEMA FF4J_2");
    prepareStatement.executeUpdate();
    testedStore = new JdbcFeatureStore();
    testedStore.setDataSource(db);
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) PreparedStatement(java.sql.PreparedStatement)

Example 19 with JdbcFeatureStore

use of org.ff4j.store.JdbcFeatureStore in project ff4j by ff4j.

the class JdbcFeatureStoreXmlTest method initStore.

/**
 * {@inheritDoc}
 */
@Override
protected FeatureStore initStore() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    db = builder.setType(EmbeddedDatabaseType.HSQL).addScript("classpath:schema-ddl.sql").build();
    return new JdbcFeatureStore(db, "ff4j.xml");
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)

Example 20 with JdbcFeatureStore

use of org.ff4j.store.JdbcFeatureStore in project TP-CORE by ElmarDott.

the class FeatureFlagsFF4j method getFeatureStore.

@Override
public FF4j getFeatureStore(final String propertyFile) throws IOException, ConnectException {
    loadConfigurationFromDatabase();
    if (Boolean.parseBoolean(configuration.get("ff.activation"))) {
        reader.appendPropertiesFromClasspath(propertyFile);
        BasicDataSource cpds = new BasicDataSource();
        cpds.setDriverClassName(reader.getPropertyAsString("jdbc.driverClassName"));
        cpds.setUrl(reader.getPropertyAsString("jdbc.url"));
        cpds.setUsername(reader.getPropertyAsString("jdbc.user"));
        cpds.setPassword(reader.getPropertyAsString("jdbc.password"));
        ff4j = new FF4j();
        ff4j.setFeatureStore(new JdbcFeatureStore(cpds));
        ff4j.setPropertiesStore(new JdbcPropertyStore(cpds));
        ff4j.setEventRepository(new JdbcEventRepository(cpds));
        ff4j.audit(Boolean.parseBoolean(configuration.get("ff.audit")));
        ff4j.autoCreate(Boolean.parseBoolean(configuration.get("ff.autocreate")));
    } else {
        LOGGER.log("Feature Flags are deactivated.", LogLevel.DEBUG);
    }
    return ff4j;
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) JdbcEventRepository(org.ff4j.audit.repository.JdbcEventRepository) FF4j(org.ff4j.FF4j) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) JdbcPropertyStore(org.ff4j.property.store.JdbcPropertyStore)

Aggregations

JdbcFeatureStore (org.ff4j.store.JdbcFeatureStore)20 Test (org.junit.Test)14 SQLException (java.sql.SQLException)13 DataSource (javax.sql.DataSource)13 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)5 Feature (org.ff4j.core.Feature)2 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)1 FF4j (org.ff4j.FF4j)1 JdbcEventRepository (org.ff4j.audit.repository.JdbcEventRepository)1 Property (org.ff4j.property.Property)1 PropertyString (org.ff4j.property.PropertyString)1 JdbcPropertyStore (org.ff4j.property.store.JdbcPropertyStore)1 JdbcQueryBuilder (org.ff4j.store.JdbcQueryBuilder)1 Before (org.junit.Before)1