Search in sources :

Example 56 with Feature

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

the class CoreFeatureStoreTestSupport method testUpdateFeatureCoreData.

/**
 * TDD.
 */
@Test
public void testUpdateFeatureCoreData() {
    // Parameters
    String newDescription = "new-description";
    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());
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) FlippingStrategy(org.ff4j.core.FlippingStrategy) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 57 with Feature

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

the class CoreFeatureStoreTestSupport 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)

Example 58 with Feature

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

the class CoreFeatureStoreTestSupport method testAddFeatureAlreadyExis.

/**
 * TDD.
 */
@Test(expected = FeatureAlreadyExistException.class)
public void testAddFeatureAlreadyExis() throws Exception {
    // Given
    assertFf4j.assertThatFeatureDoesNotExist("GOLOGOLO");
    // When (first creation)
    Feature fp = new Feature("GOLOGOLO", true, "description2");
    testedStore.create(fp);
    // Then (first creation)
    assertFf4j.assertThatFeatureExist("GOLOGOLO");
    // When (second creation)
    Set<String> rights = new HashSet<String>(Arrays.asList(new String[] { ROLE_USER }));
    Feature fp2 = new Feature("GOLOGOLO", true, G1, "description3", rights);
    testedStore.create(fp2);
// Then, expected exception
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with Feature

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

the class CoreFeatureStoreTestSupport method testUpdateEditPropertyRemoveFixedValues.

/**
 * TDD.
 */
@Test
@SuppressWarnings("unchecked")
public void testUpdateEditPropertyRemoveFixedValues() {
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    assertFf4j.assertThatFeatureHasProperty(F1, "regionIdentifier");
    Set<String> fixValues = (Set<String>) ff4j.getFeatureStore().read(// 
    F1).getCustomProperties().get("regionIdentifier").getFixedValues();
    Assert.assertEquals(3, fixValues.size());
    // When
    Feature 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) Set(java.util.Set) HashSet(java.util.HashSet) PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 60 with Feature

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

the class JdbcFeatureStoreErrorTest method testCreateKO.

@Test(expected = FeatureAccessException.class)
public void testCreateKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcFeatureStore jrepo = new JdbcFeatureStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.create(new Feature("U1", 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)

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