use of org.ff4j.property.PropertyString in project ff4j by ff4j.
the class PropertyStoreJCacheTest method updateKOPropertyNotFound.
/**
* TDD.
*/
@Test(expected = PropertyNotFoundException.class)
public void updateKOPropertyNotFound() {
// When
PropertyString ps = new PropertyString("does-not-exist");
testedStore.updateProperty(ps);
// Expected error
Assert.fail();
}
use of org.ff4j.property.PropertyString in project ff4j by ff4j.
the class XmlParser method parsePropertiesTag.
/**
* Parse Properties.
*
* @param properties tag
* @param uid
* current featureid
* @return
* properties map
*/
private Map<String, Property<?>> parsePropertiesTag(Element propertiesTag) {
Map<String, Property<?>> properties = new HashMap<String, Property<?>>();
// <properties>
NodeList lisOfProperties = propertiesTag.getElementsByTagName(PROPERTY_TAG);
for (int k = 0; k < lisOfProperties.getLength(); k++) {
// <property name='' value='' (type='') >
Element propertyTag = (Element) lisOfProperties.item(k);
NamedNodeMap attMap = propertyTag.getAttributes();
if (attMap.getNamedItem(PROPERTY_PARAMNAME) == null) {
throw new IllegalArgumentException("Invalid XML Syntax, 'name' is a required attribute of 'property' TAG");
}
if (attMap.getNamedItem(PROPERTY_PARAMVALUE) == null) {
throw new IllegalArgumentException("Invalid XML Syntax, 'value' is a required attribute of 'property' TAG");
}
String name = attMap.getNamedItem(PROPERTY_PARAMNAME).getNodeValue();
String value = attMap.getNamedItem(PROPERTY_PARAMVALUE).getNodeValue();
Property<?> ap = new PropertyString(name, value);
// If specific type defined ?
if (null != attMap.getNamedItem(PROPERTY_PARAMTYPE)) {
String optionalType = attMap.getNamedItem(PROPERTY_PARAMTYPE).getNodeValue();
// Substitution if relevant (e.g. 'int' -> 'org.ff4j.property.PropertyInt')
optionalType = MappingUtil.mapPropertyType(optionalType);
try {
// Constructor (String, String) is mandatory in Property interface
Constructor<?> constr = Class.forName(optionalType).getConstructor(String.class, String.class);
ap = (Property<?>) constr.newInstance(name, value);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot instantiate '" + optionalType + "' check default constructor", e);
}
}
if (null != attMap.getNamedItem(PROPERTY_PARAMDESCRIPTION)) {
ap.setDescription(attMap.getNamedItem(PROPERTY_PARAMDESCRIPTION).getNodeValue());
}
// Is there any fixed Value ?
NodeList listOfFixedValue = propertyTag.getElementsByTagName(PROPERTY_PARAMFIXED_VALUES);
if (listOfFixedValue.getLength() != 0) {
Element fixedValueTag = (Element) listOfFixedValue.item(0);
NodeList listOfValues = fixedValueTag.getElementsByTagName(PROPERTY_PARAMVALUE);
for (int l = 0; l < listOfValues.getLength(); l++) {
Element valueTag = (Element) listOfValues.item(l);
ap.add2FixedValueFromString(valueTag.getTextContent());
}
}
// Check fixed value
if (ap.getFixedValues() != null && !ap.getFixedValues().contains(ap.getValue())) {
throw new IllegalArgumentException("Cannot create property <" + ap.getName() + "> invalid value <" + ap.getValue() + "> expected one of " + ap.getFixedValues());
}
properties.put(name, ap);
}
return properties;
}
use of org.ff4j.property.PropertyString in project ff4j by ff4j.
the class FF4jTest method testImportProperties.
@Test
public void testImportProperties() {
FF4j ff4j = new FF4j();
List<Property<?>> listOfProperties = new ArrayList<Property<?>>();
listOfProperties.add(new PropertyString("p1", "v1"));
ff4j.importProperties(listOfProperties);
Assert.assertTrue(ff4j.getPropertiesStore().existProperty("p1"));
// no Error
ff4j.importProperties(null);
}
use of org.ff4j.property.PropertyString in project ff4j by ff4j.
the class FeatureTest method testCopyConstructorFeature.
@Test
public void testCopyConstructorFeature() {
Feature f = new Feature("abc", true, "samething", "groupA", Util.set("a", "b"));
f.getPermissions().add("USER");
f.setFlippingStrategy(new PonderationStrategy(0.5d));
f.getCustomProperties().put("p1", new PropertyString("p1", "v1"));
f.getCustomProperties().put("p2", new PropertyString("p1", "v1", Util.set("v1", "v2")));
Feature f2 = new Feature(f);
Assert.assertEquals(f2.getUid(), f.getUid());
Assert.assertEquals(f2.getPermissions(), f.getPermissions());
new Feature("f3", true, "samething", "groupA", Util.set("a", "b"), null);
new Feature(new Feature("f4", true));
}
use of org.ff4j.property.PropertyString in project ff4j by ff4j.
the class FeatureTest method testProperty.
@Test
public void testProperty() {
Feature f = new Feature("f1");
f.toggle();
f.toggle();
f.getCustomProperties().put("p1", new PropertyString("p1", "v1"));
f.getProperty("p1");
}
Aggregations