Search in sources :

Example 51 with PropertyString

use of org.ff4j.property.PropertyString in project ff4j by ff4j.

the class FeatureStoreJCacheTest method testUpdateEditPropertyRemoveFixedValues.

/**
 * TDD.
 */
@Test
@SuppressWarnings("unchecked")
public void testUpdateEditPropertyRemoveFixedValues() {
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    Feature myFeature = ff4j.getFeatureStore().read(F1);
    myFeature.addProperty(new PropertyString("regionIdentifier", "AMER", Util.set("AMER", "SSSS", "EAST")));
    testedStore.update(myFeature);
    assertFf4j.assertThatFeatureHasProperty(F1, "regionIdentifier");
    Set<String> fixValues = (Set<String>) ff4j.getFeatureStore().read(// 
    F1).getCustomProperties().get("regionIdentifier").getFixedValues();
    Assert.assertEquals(3, fixValues.size());
    // When
    myFeature = ff4j.getFeatureStore().read(F1);
    PropertyString p1 = new PropertyString("regionIdentifier");
    p1.setValue("AMER");
    p1.setFixedValues(Util.set("AMER", "SSSS"));
    myFeature.getCustomProperties().put(p1.getName(), p1);
    testedStore.update(myFeature);
    // Then
    Set<Integer> fixValues2 = (Set<Integer>) ff4j.getFeatureStore().read(// 
    F1).getCustomProperties().get("regionIdentifier").getFixedValues();
    Assert.assertEquals(2, fixValues2.size());
}
Also used : PropertyString(org.ff4j.property.PropertyString) HashSet(java.util.HashSet) Set(java.util.Set) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 52 with PropertyString

use of org.ff4j.property.PropertyString in project ff4j by ff4j.

the class FeatureStoreJCacheTest method testUpdateEditPropertyValue.

/**
 * TDD.
 */
@Test
public void testUpdateEditPropertyValue() {
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    Feature myFeature = ff4j.getFeatureStore().read(F1);
    if (myFeature.getCustomProperties().isEmpty()) {
        PropertyString p1 = new PropertyString("ppstring");
        p1.setValue("hello");
        myFeature.getCustomProperties().put(p1.getName(), p1);
        testedStore.update(myFeature);
    }
    assertFf4j.assertThatFeatureHasProperty(F1, "ppstring");
    Assert.assertEquals("hello", // 
    ff4j.getFeatureStore().read(F1).getCustomProperties().get(// 
    "ppstring").asString());
    // When
    myFeature = ff4j.getFeatureStore().read(F1);
    PropertyString p1 = new PropertyString("ppstring", "goodbye");
    myFeature.getCustomProperties().put(p1.getName(), p1);
    testedStore.update(myFeature);
    // Then
    Assert.assertEquals("goodbye", // 
    ff4j.getFeatureStore().read(F1).getCustomProperties().get(// 
    "ppstring").asString());
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 53 with PropertyString

use of org.ff4j.property.PropertyString in project ff4j by ff4j.

the class PropertyStoreJCacheTest method readOK.

// ------------------ read --------------------
@Test
public void readOK() {
    // Given
    testedStore.createProperty(new PropertyString("toto", "ff4j"));
    // When
    Property<?> ap = testedStore.readProperty("toto");
    // Then
    Assert.assertNotNull(ap);
    Assert.assertNotNull(ap.getName());
    Assert.assertEquals("toto", ap.getName());
    Assert.assertEquals("ff4j", ap.getValue());
    Assert.assertEquals("ff4j", ap.asString());
    Assert.assertNull(ap.getFixedValues());
}
Also used : PropertyString(org.ff4j.property.PropertyString) Test(org.junit.Test)

Example 54 with PropertyString

use of org.ff4j.property.PropertyString in project ff4j by ff4j.

the class FeatureStoreNeo4jLimitTest method testChangeGroup.

@Test
public void testChangeGroup() {
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.execute("CREATE " + " (h0:FF4J_FEATURE_GROUP { name:'h0' }),\n" + " (h1:FF4J_FEATURE { uid:'h1', enable:false, description:'second', roles:['USER'] }),\n" + " (h1)-[:MEMBER_OF]->(h0);");
        tx.success();
    }
    Feature f1 = testedStore.read("h1");
    Property<?> newP = new PropertyString("ppp", "vvv");
    newP.setDescription("a description");
    f1.addProperty(newP);
    FlippingStrategy fs = new PonderationStrategy(0.1);
    fs.getInitParams().put("p1", "v1");
    fs.getInitParams().put("p2", "v2");
    f1.setFlippingStrategy(fs);
    f1.setGroup("g2");
    testedStore.update(f1);
    Assert.assertEquals("g2", testedStore.read("h1").getGroup());
    f1.getFlippingStrategy().getInitParams().put("p3", "v3");
    testedStore.update(f1);
    testedStore.setGraphDb(testedStore.getGraphDb());
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) PropertyString(org.ff4j.property.PropertyString) Transaction(org.neo4j.graphdb.Transaction) FlippingStrategy(org.ff4j.core.FlippingStrategy) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Aggregations

PropertyString (org.ff4j.property.PropertyString)54 Test (org.junit.Test)52 Feature (org.ff4j.core.Feature)18 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)11 Property (org.ff4j.property.Property)6 HashSet (java.util.HashSet)5 Set (java.util.Set)4 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)4 HashMap (java.util.HashMap)3 FF4j (org.ff4j.FF4j)3 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 DataSource (javax.sql.DataSource)2 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)2 PropertyJsonBean (org.ff4j.property.util.PropertyJsonBean)2 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1