Search in sources :

Example 61 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 62 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)

Example 63 with Feature

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

the class PonderationStrategyTest method testExpressionCustom.

@Test
public void testExpressionCustom() {
    Feature f = ff4j.getFeature("pond_6");
    Assert.assertEquals(new Double(0.6), Double.valueOf(((PonderationStrategy) f.getFlippingStrategy()).getInitParams().get("weight")));
    int nbOK = 0;
    int nbKO = 0;
    for (int i = 0; i < 1000; i++) {
        if (ff4j.check(f.getUid())) {
            nbOK++;
        } else {
            nbKO++;
        }
    }
    Assert.assertTrue("both result occured", nbOK > 0 && nbKO > 0);
}
Also used : Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 64 with Feature

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

the class ServerFilterStrategyTest method testFilterInvalidClient.

@Test
public void testFilterInvalidClient() throws ParseException {
    // Given
    Feature f1 = ff4j.getFeature(F1);
    Assert.assertNotNull(f1.getFlippingStrategy());
    ServerFilterStrategy cStra = (ServerFilterStrategy) f1.getFlippingStrategy();
    Assert.assertNotNull(cStra.getInitParams());
    Assert.assertEquals(1, cStra.getInitParams().size());
    Assert.assertTrue(f1.isEnable());
    // When (add invalid client name)
    FlippingExecutionContext fex = new FlippingExecutionContext();
    fex.addValue(ServerFilterStrategy.SERVER_HOSTNAME, FEATURE_NEW);
    // Then
    Assert.assertFalse(ff4j.check(F1, fex));
}
Also used : ServerFilterStrategy(org.ff4j.strategy.ServerFilterStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 65 with Feature

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

the class FeatureJsonMarshallTest method testEmbeddedQuoteJson.

@Test
public void testEmbeddedQuoteJson() throws Exception {
    Feature f = new FF4j(new XmlParser(), "test-feature-json1.xml").getFeature("embedded\"quote");
    assertMarshalling(f);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) FF4j(org.ff4j.FF4j) TestConstantsFF4j(org.ff4j.test.TestConstantsFF4j) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Aggregations

Feature (org.ff4j.core.Feature)295 Test (org.junit.Test)144 PropertyString (org.ff4j.property.PropertyString)53 HashMap (java.util.HashMap)38 HashSet (java.util.HashSet)27 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)19 Property (org.ff4j.property.Property)16 LinkedHashMap (java.util.LinkedHashMap)15 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)15 Map (java.util.Map)14 XmlParser (org.ff4j.conf.XmlParser)14 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)14 FeatureAccessException (org.ff4j.exception.FeatureAccessException)13 InputStream (java.io.InputStream)11 FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)11 Set (java.util.Set)10 Response (javax.ws.rs.core.Response)10 FlippingStrategy (org.ff4j.core.FlippingStrategy)10 CouchDbFeature (org.ff4j.couchdb.document.CouchDbFeature)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9