Search in sources :

Example 11 with PropertyString

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

the class JdbcPropertyStoreErrorTest method testCreateKO.

@Test(expected = PropertyAccessException.class)
public void testCreateKO() throws SQLException {
    DataSource mockDS = Mockito.mock(DataSource.class);
    doThrow(new SQLException()).when(mockDS).getConnection();
    JdbcPropertyStore jrepo = new JdbcPropertyStore(mockDS);
    jrepo.setDataSource(mockDS);
    jrepo.createProperty(new PropertyString("p1", "v1"));
}
Also used : PropertyString(org.ff4j.property.PropertyString) SQLException(java.sql.SQLException) JdbcPropertyStore(org.ff4j.property.store.JdbcPropertyStore) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 12 with PropertyString

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

the class PropertyFactoryTest method testPropertyFactory.

@Test
public void testPropertyFactory() {
    new PropertyFactory();
    PropertyFactory.createProperty("p1", (int) 1);
    PropertyFactory.createProperty("p1", (long) 1);
    PropertyFactory.createProperty("p1", (double) 1);
    PropertyFactory.createProperty("p1", (float) 1);
    PropertyFactory.createProperty("p1", (short) 1);
    PropertyFactory.createProperty("p1", (boolean) true);
    PropertyFactory.createProperty("p1", new BigDecimal(1.1d));
    PropertyFactory.createProperty("p1", new BigInteger("1"));
    PropertyFactory.createProperty("p1", new Byte("2"));
    PropertyFactory.createProperty("p1", PropertyLogLevel.LogLevel.DEBUG);
    PropertyFactory.createProperty("p1", new PropertyString("tata"));
    PropertyFactory.createProperty("p1", new Date());
    PropertyFactory.createProperty("p1", "sample");
    PropertyFactory.createProperty("p1", Calendar.getInstance());
    Property<?> pList = PropertyFactory.createProperty("p1", Util.list("a", "b", "c"));
    Assert.assertTrue(pList.getClass().equals(PropertyString.class));
}
Also used : PropertyString(org.ff4j.property.PropertyString) PropertyFactory(org.ff4j.property.util.PropertyFactory) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 13 with PropertyString

use of org.ff4j.property.PropertyString 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 14 with PropertyString

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

the class CoreFeatureStoreTestSupport method testUpdateAddProperty.

/**
 * TDD.
 */
@Test
public void testUpdateAddProperty() {
    // Given
    assertFf4j.assertThatFeatureExist(F2);
    assertFf4j.assertThatFeatureHasNotProperty(F2, "p1");
    // When
    Feature myFeature = ff4j.getFeatureStore().read(F2);
    PropertyString p1 = new PropertyString("p1", "v1");
    myFeature.getCustomProperties().put(p1.getName(), p1);
    testedStore.update(myFeature);
    // Then
    assertFf4j.assertThatFeatureHasProperty(F2, "p1");
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 15 with PropertyString

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

the class CoreFeatureStoreTestSupport method testUpdateEditPropertyValue.

/**
 * TDD.
 */
@Test
public void testUpdateEditPropertyValue() {
    // Given
    assertFf4j.assertThatFeatureExist(F1);
    assertFf4j.assertThatFeatureHasProperty(F1, "ppstring");
    Assert.assertEquals("hello", // 
    ff4j.getFeatureStore().read(F1).getCustomProperties().get(// 
    "ppstring").asString());
    // When
    Feature 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)

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