Search in sources :

Example 6 with FeatureStore

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

the class FeatureStoreMongoDBCore1Test method emptyListAttributes.

/**
 * LazyBSONObjectList vs BasicBSONObjectList
 */
@Test
@Ignore
public void emptyListAttributes() throws UnknownHostException {
    DBCollection features = getMongoClient().getDB("FF4J").getCollection("feature");
    // When
    FeatureStore mongoStore = new FeatureStoreMongoDB(features, "ff4j.xml");
    // Then (no error)
    Assert.assertTrue(mongoStore.readAll().keySet().size() > 0);
}
Also used : DBCollection(com.mongodb.DBCollection) FeatureStoreMongoDB(org.ff4j.store.FeatureStoreMongoDB) FeatureStore(org.ff4j.core.FeatureStore) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with FeatureStore

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

the class RedisCacheManagerTestIT method testPutGet.

@Test
public void testPutGet() {
    // Initializing cache manager
    FF4JCacheManager cache = new FF4jCacheManagerRedis();
    // Initializing Features for test
    FeatureStore store = new InMemoryFeatureStore(TEST_FEATURES_FILE);
    Feature fold = store.read(F4);
    // Put in Cache
    cache.putFeature(fold);
    // Retrieve object
    Feature fcached = cache.getFeature(F4);
    Assert.assertEquals(fcached.getUid(), fold.getUid());
    Assert.assertEquals(fcached.getPermissions(), fold.getPermissions());
}
Also used : InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Feature(org.ff4j.core.Feature) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FeatureStore(org.ff4j.core.FeatureStore) Test(org.junit.Test)

Example 8 with FeatureStore

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

the class FF4jCliDisplay method displayEnvironments.

/**
 * Display a table of available environments.
 *
 * @param envs
 * 		environnements in config file
 */
public static void displayEnvironments(Map<String, FF4j> envs) {
    yellow("+--------------------+----------+------------+-------+----------+\n");
    System.out.print("|");
    cyan(" Environments       ");
    yellow("|");
    cyan(" Features ");
    yellow("|");
    cyan(" Properties ");
    yellow("|");
    cyan(" Audit ");
    yellow("|");
    cyan(" Security ");
    yellow("|\n");
    System.out.println("+--------------------+----------+------------+-------+----------+");
    for (Map.Entry<String, FF4j> entries : envs.entrySet()) {
        FeatureStore fs = entries.getValue().getFeatureStore();
        PropertyStore ps = entries.getValue().getPropertiesStore();
        yellow("|  ");
        green(StringUtils.rightPad(entries.getKey(), 18));
        yellow("|  ");
        String featureStore = "---";
        if (fs != null) {
            featureStore = String.valueOf(fs.readAll().size());
        }
        white(StringUtils.rightPad(featureStore, 8));
        yellow("|  ");
        String propertyStore = "---";
        if (fs != null) {
            propertyStore = String.valueOf(ps.listPropertyNames().size());
        }
        white(StringUtils.rightPad(propertyStore, 10));
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().isEnableAudit()) {
            green("  ON   ");
        } else {
            red("  OFF  ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().getAuthorizationsManager() != null) {
            green("  ON      ");
        } else {
            red("  OFF     ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|\n");
    }
    System.out.println("+--------------------+----------+------------+-------+----------+");
    System.out.println("");
}
Also used : FF4j(org.ff4j.FF4j) PropertyString(org.ff4j.property.PropertyString) HashMap(java.util.HashMap) Map(java.util.Map) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Example 9 with FeatureStore

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

the class MappingUtilsTest method testJsonMapping.

@Test
public void testJsonMapping() {
    JsonUtils.permissionsAsJson(null);
    JsonUtils.customPropertiesAsJson(null);
    JsonUtils.customPropertiesAsJson(new HashMap<String, Property<?>>());
    FeatureStore store1 = new InMemoryFeatureStore();
    FF4jCacheProxy proxy = new FF4jCacheProxy(store1, null, null);
    JsonUtils.cacheJson(proxy);
}
Also used : InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) PropertyString(org.ff4j.property.PropertyString) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Property(org.ff4j.property.Property) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FeatureStore(org.ff4j.core.FeatureStore) Test(org.junit.Test)

Example 10 with FeatureStore

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

the class ConsoleOperations method importFile.

/**
 * User action to import Features from a properties files.
 *
 * @param in
 *            inpustream from configuration file
 * @throws IOException
 *             Error raised if the configuration cannot be read
 */
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
    FeatureStore store = ff4j.getFeatureStore();
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
    Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
    for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
        if (store.exist(feature.getKey())) {
            store.update(feature.getValue());
        } else {
            store.create(feature.getValue());
        }
    }
    LOGGER.info(mapsOfFeat.size() + " features have been imported.");
    PropertyStore pstore = ff4j.getPropertiesStore();
    Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
    for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
        if (pstore.existProperty(p.getKey())) {
            pstore.updateProperty(p.getValue());
        } else {
            pstore.createProperty(p.getValue());
        }
    }
    LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Aggregations

FeatureStore (org.ff4j.core.FeatureStore)11 Test (org.junit.Test)7 FF4j (org.ff4j.FF4j)3 PropertyStore (org.ff4j.property.store.PropertyStore)3 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)3 Map (java.util.Map)2 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)2 Feature (org.ff4j.core.Feature)2 Property (org.ff4j.property.Property)2 PropertyString (org.ff4j.property.PropertyString)2 Ignore (org.junit.Ignore)2 DBCollection (com.mongodb.DBCollection)1 HashMap (java.util.HashMap)1 Document (org.bson.Document)1 FF4JCacheManager (org.ff4j.cache.FF4JCacheManager)1 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)1 Store2CachePollingScheduler (org.ff4j.cache.Store2CachePollingScheduler)1 XmlConfig (org.ff4j.conf.XmlConfig)1 XmlParser (org.ff4j.conf.XmlParser)1 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)1