Search in sources :

Example 96 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class JdbcFeatureStoreErrorTest method testUpdateKO.

@Test(expected = FeatureAccessException.class)
public void testUpdateKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcFeatureStore jrepo = new JdbcFeatureStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.update(new Feature("f1", true));
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) SQLException(java.sql.SQLException) Feature(org.ff4j.core.Feature) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 97 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class JdbcFeatureStoreErrorTest method testCreateKO.

@Test(expected = FeatureAccessException.class)
public void testCreateKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcFeatureStore jrepo = new JdbcFeatureStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.create(new Feature("U1", true));
}
Also used : JdbcFeatureStore(org.ff4j.store.JdbcFeatureStore) SQLException(java.sql.SQLException) Feature(org.ff4j.core.Feature) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 98 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class JdbcFeatureStoreSchemaTest method testworkWithSchema.

@Test
public void testworkWithSchema() {
    // Given
    testedStore.createSchema();
    Assert.assertFalse(testedStore.exist("fx"));
    // When
    Feature fullFeature = new Feature("fx", true);
    fullFeature.setPermissions(Util.set("toto", "tata"));
    fullFeature.setFlippingStrategy(new PonderationStrategy(0.5d));
    Map<String, Property<?>> customProperties = new HashMap<String, Property<?>>();
    fullFeature.setCustomProperties(customProperties);
    testedStore.create(fullFeature);
    // Then
    Assert.assertTrue(testedStore.exist("fx"));
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) HashMap(java.util.HashMap) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 99 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class JdbcFeatureStoreSchemaTest method testCreateCustomProperties.

@SuppressWarnings("unchecked")
@Test
public void testCreateCustomProperties() {
    testedStore.createSchema();
    // When
    Feature fullFeature = new Feature("fx", true);
    fullFeature.setPermissions(Util.set("toto", "tata"));
    fullFeature.setFlippingStrategy(new PonderationStrategy(0.5d));
    Map<String, Property<?>> customProperties = new HashMap<String, Property<?>>();
    fullFeature.setCustomProperties(customProperties);
    testedStore.create(fullFeature);
    testedStore.createCustomProperties("fx", null);
    Property<?> p1 = new PropertyString("p1");
    p1.setFixedValues(null);
    Property<String> p2 = new PropertyString("p2");
    p2.setFixedValues(Util.set("v1", "v3"));
    testedStore.createCustomProperties("fx", Arrays.asList(p2, p1));
    testedStore.createCustomProperties("fx", null);
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) PropertyString(org.ff4j.property.PropertyString) HashMap(java.util.HashMap) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 100 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class ClientFilterStrategyTest method testFilterRequiredContext.

@Test(expected = IllegalArgumentException.class)
public void testFilterRequiredContext() {
    // Given
    Feature f1 = ff4j.getFeature(F1);
    Assert.assertNotNull(f1.getFlippingStrategy());
    org.ff4j.strategy.ClientFilterStrategy cStra = (ClientFilterStrategy) f1.getFlippingStrategy();
    Assert.assertNotNull(cStra.getInitParams());
    Assert.assertEquals(1, cStra.getInitParams().size());
    Assert.assertTrue(f1.isEnable());
    // Then FeatureContext is requires
    ff4j.check(F1);
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Aggregations

Feature (org.ff4j.core.Feature)258 Test (org.junit.Test)136 PropertyString (org.ff4j.property.PropertyString)49 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)29 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)19 LinkedHashMap (java.util.LinkedHashMap)15 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)14 Property (org.ff4j.property.Property)12 Set (java.util.Set)11 FeatureAccessException (org.ff4j.exception.FeatureAccessException)11 FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)11 XmlParser (org.ff4j.conf.XmlParser)10 InputStream (java.io.InputStream)9 Map (java.util.Map)9 FlippingStrategy (org.ff4j.core.FlippingStrategy)9 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 ArrayList (java.util.ArrayList)8 Response (javax.ws.rs.core.Response)8