Package org.ff4j.core

Examples of org.ff4j.core.Feature


    /** {@inheritDoc} */
    @Override
    public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
        String featUid = rs.getString(COL_FEAT_UID);
        Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
        f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
        f.setGroup(rs.getString(COL_FEAT_GROUPNAME));

        // Build Flipping Strategy From DataBase
        String strategy = rs.getString(COL_FEAT_STRATEGY);
        if (strategy != null && !"".equals(strategy)) {
            try {
                FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
                flipStrategy.init(featUid, ParameterUtils.toMap(rs.getString(COL_FEAT_EXPRESSION)));
                f.setFlippingStrategy(flipStrategy);
            } catch (InstantiationException ie) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
            } catch (IllegalAccessException iae) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no visible constructor", iae);
            } catch (ClassNotFoundException e) {
View Full Code Here


        // When
        Map<String, Feature> features = testedStore.readAll();
        // Then
        Assert.assertEquals(EXPECTED_FEATURES_NUMBERS, features.size());
        // Then testing whole structure
        Feature f = features.get(F4);
        Assert.assertEquals(F4 + " does not exist", f.getUid(), F4);
        Assert.assertTrue("no description", f.getDescription() != null && !"".equals(f.getDescription()));
        Assert.assertTrue("no authorizations", f.getPermissions() != null && !f.getPermissions().isEmpty());
        assertFf4j.assertThatFeatureHasRole(F4, ROLE_ADMIN);
        assertFf4j.assertThatFeatureIsInGroup(F4, G1);
    }
View Full Code Here

    @Test
    public void testReadFullFeature() {
        // Given
        assertFf4j.assertThatFeatureExist(F4);
        // When
        Feature f = testedStore.read(F4);
        // Then
        Assert.assertEquals(f.getUid(), F4);
        Assert.assertTrue(f.getDescription() != null && !"".equals(f.getDescription()));
        Assert.assertTrue(f.getPermissions() != null && !f.getPermissions().isEmpty());
        assertFf4j.assertThatFeatureHasRole(F4, ROLE_ADMIN);
        assertFf4j.assertThatFeatureIsInGroup(F4, G1);
    }
View Full Code Here

    public void testAddFeature() throws Exception {
        // Given
        assertFf4j.assertThatFeatureDoesNotExist(FEATURE_NEW);
        // When
        Set<String> rights = new HashSet<String>(Arrays.asList(new String[] {ROLE_USER}));
        Feature fp = new Feature(FEATURE_NEW, true, "description", G1, rights);
        testedStore.create(fp);
        // Then
        assertFf4j.assertThatStoreHasSize(EXPECTED_FEATURES_NUMBERS + 1);
        assertFf4j.assertThatFeatureExist(FEATURE_NEW);
        assertFf4j.assertThatFeatureIsInGroup(FEATURE_NEW, G1);
View Full Code Here

    @Test(expected = FeatureAlreadyExistException.class)
    public void testAddFeatureAlreadyExis() throws Exception {
        // Given
        assertFf4j.assertThatFeatureDoesNotExist(FEATURE_NEW);
        // When (first creation)
        Feature fp = new Feature(FEATURE_NEW, true, "description2");
        testedStore.create(fp);
        // Then (first creation)
        assertFf4j.assertThatFeatureExist(FEATURE_NEW);
        // When (second creation)
        Set<String> rights = new HashSet<String>(Arrays.asList(new String[] {ROLE_USER}));
        Feature fp2 = new Feature(FEATURE_NEW, true, G1, "description3", rights);
        testedStore.create(fp2);
        // Then, expected exception
    }
View Full Code Here

     */
    @Test
    public void testDeleteFeature() throws Exception {
        // Given
        assertFf4j.assertThatFeatureExist(F1);
        Feature tmpf1 = testedStore.read(F1);
        int initialNumber = testedStore.readAll().size();
        // When
        testedStore.delete(F1);
        // Then
        assertFf4j.assertThatStoreHasSize(initialNumber - 1);
View Full Code Here

        FlippingStrategy newStrategy = new PonderationStrategy(0.12);
        // Given
        assertFf4j.assertThatFeatureExist(F1);
        Assert.assertFalse(newDescription.equals(testedStore.read(F1).getDescription()));
        // When
        Feature fpBis = testedStore.read(F1);
        fpBis.setDescription(newDescription);
        fpBis.setFlippingStrategy(newStrategy);
        testedStore.update(fpBis);
        // Then
        Feature updatedFeature = testedStore.read(F1);
        Assert.assertTrue(newDescription.equals(updatedFeature.getDescription()));
        Assert.assertNotNull(updatedFeature.getFlippingStrategy());
        Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString());
    }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public Map<String, Feature> readAll() {
        LinkedHashMap<String, Feature> mapFP = new LinkedHashMap<String, Feature>();
        for(DBObject dbObject : collection.find()) {
            Feature feature = MAPPER.mapFeature(dbObject);
            mapFP.put(feature.getUid(), feature);
        }
        return mapFP;
    }
View Full Code Here

    @Override
    public void update(Feature fp) {
        if (fp == null) {
            throw new IllegalArgumentException("Feature cannot be null nor empty");
        }
        Feature fpExist = read(fp.getUid());
        collection.save(MAPPER.toDBObject(fp));
        // enable/disable
        if (fp.isEnable() != fpExist.isEnable()) {
            if (fp.isEnable()) {
                enable(fp.getUid());
            } else {
                disable(fp.getUid());
            }
View Full Code Here

        if (!existGroup(groupName)) {
            throw new GroupNotFoundException(groupName);
        }
        LinkedHashMap<String, Feature> mapFP = new LinkedHashMap<String, Feature>();
        for (DBObject dbObject : collection.find(BUILDER.getGroupName(groupName))) {
            Feature feature = MAPPER.mapFeature(dbObject);
            mapFP.put(feature.getUid(), feature);
        }
        return mapFP;
    }
View Full Code Here

TOP

Related Classes of org.ff4j.core.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.