Search in sources :

Example 86 with Feature

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

the class FeatureStoreJCacheTest method testUpdateFlipMoreAutorisationNotExist.

/**
 * TDD.
 */
@Test
public void testUpdateFlipMoreAutorisationNotExist() {
    // Given
    assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_NEW);
    Set<String> rights2 = new HashSet<String>(Arrays.asList(new String[] { ROLE_USER, ROLE_NEW }));
    Feature fpBis = new Feature(F1, false, G1, "desci2", rights2);
    // When
    testedStore.update(fpBis);
    // Then
    assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
    assertFf4j.assertThatFeatureHasRole(F1, ROLE_NEW);
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with Feature

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

the class FeatureStoreJCacheTest method testReadAllFeatures.

/**
 * TDD.
 */
@Test
public void testReadAllFeatures() {
    // Given
    assertFf4j.assertThatFeatureExist(F4);
    assertFf4j.assertThatStoreHasSize(EXPECTED_FEATURES_NUMBERS);
    // 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);
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 88 with Feature

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

the class FeatureStoreJCacheTest method testReadFullFeature.

/**
 * TDD.
 */
@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);
}
Also used : Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 89 with Feature

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

the class FeatureStoreJCacheTest method testUpdateEditPropertyAddFixedValues.

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

Example 90 with Feature

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

the class FeatureStoreJCacheTest method testUpdateFeatureMoreAutorisation.

/**
 * TDD.
 */
@Test
public void testUpdateFeatureMoreAutorisation() {
    // Parameters
    Set<String> rights2 = new HashSet<String>(Arrays.asList(new String[] { ROLE_USER, ROLE_ADMIN }));
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_ADMIN);
    // When
    Feature fpBis = testedStore.read(F1);
    fpBis.setPermissions(rights2);
    testedStore.update(fpBis);
    // Then
    assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
    assertFf4j.assertThatFeatureHasRole(F1, ROLE_ADMIN);
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) HashSet(java.util.HashSet) 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