Search in sources :

Example 1 with PropertiesEntityFactory

use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.

the class DescriptorsTest method testDataEntityDescriptorIndexOf.

@Test
public void testDataEntityDescriptorIndexOf() {
    PropertiesEntityFactory ef = PropertiesEntityFactory.instance;
    PropertyName e1 = ef.createPropertyName("pn1");
    EntityDescriptor<?> ed = e1.wGetEntityDescriptor();
    int i1 = ed.indexOf(CommonsFeatureDescriptorEnum.data_value);
    assertEquals(0, i1);
}
Also used : PropertyName(org.whole.lang.properties.model.PropertyName) PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Test(org.junit.Test)

Example 2 with PropertiesEntityFactory

use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.

the class PropertiesUtils method setProperty.

public static String setProperty(Properties props, String name, String value) {
    PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
    Property pattern = lf.createProperty(lf.createPropertyName(name), createVariable(PropertiesEntityDescriptorEnum.PropertyValue, "value"));
    Property property = Matcher.findChild(pattern, props.getEntries());
    if (property != null) {
        PropertyValue pv = property.getValue();
        String oldValue = pv.wStringValue();
        pv.wSetValue(value);
        return oldValue;
    } else {
        pattern.setValue(lf.createPropertyValue(value));
        props.getEntries().wAdd(pattern);
        return null;
    }
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) PropertyValue(org.whole.lang.properties.model.PropertyValue) Property(org.whole.lang.properties.model.Property)

Example 3 with PropertiesEntityFactory

use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.

the class PropertiesTest method testGetSetProperty.

@Test
public void testGetSetProperty() {
    PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
    Properties props = lf.createProperties(lf.createComment("Test properties"), createResolver(PropertiesEntityDescriptorEnum.Properties), lf.createEntries(new Property[] { lf.createProperty(lf.createPropertyName("prop1"), lf.createPropertyValue("value 1")), lf.createProperty(lf.createPropertyName("prop2"), lf.createPropertyValue("value 2")) }));
    String prop1Value = PropertiesUtils.getProperty(props, "prop1");
    Assert.assertEquals("value 1", prop1Value);
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Properties(org.whole.lang.properties.model.Properties) Property(org.whole.lang.properties.model.Property) Test(org.junit.Test)

Example 4 with PropertiesEntityFactory

use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.

the class NormalizerOperationTest method testDefaultBehavior.

@Test
public void testDefaultBehavior() {
    assertFalse(ReflectionFactory.getLanguageKit(PropertiesLanguageKit.URI).hasVisitor(NormalizerOperation.ID));
    PropertiesEntityFactory ef = PropertiesEntityFactory.instance;
    Entries entries = ef.createEntries(ef.createProperty(), ef.create(PropertiesEntityDescriptorEnum.Property, "p2", "v2"));
    Entries entriesOrig = EntityUtils.clone(entries);
    NormalizerOperation.normalize(entries);
    assertTrue(Matcher.match(entriesOrig, entries));
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Entries(org.whole.lang.properties.model.Entries) Test(org.junit.Test)

Example 5 with PropertiesEntityFactory

use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.

the class DescriptorsTest method testCompositeEntityDescriptorIndexOf.

@Test
public void testCompositeEntityDescriptorIndexOf() {
    PropertiesEntityFactory ef = PropertiesEntityFactory.instance;
    Entries e1 = ef.createEntries();
    EntityDescriptor<?> ed = e1.wGetEntityDescriptor();
    int i1 = ed.indexOf(CommonsFeatureDescriptorEnum.composite_element);
    assertEquals(0, i1);
    int i2 = ed.indexOf(PropertiesFeatureDescriptorEnum.name);
    assertEquals(-1, i2);
    int i3 = e1.wIndexOf(CommonsFeatureDescriptorEnum.composite_element);
    assertEquals(0, i3);
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Entries(org.whole.lang.properties.model.Entries) Test(org.junit.Test)

Aggregations

PropertiesEntityFactory (org.whole.lang.properties.factories.PropertiesEntityFactory)8 Test (org.junit.Test)5 Entries (org.whole.lang.properties.model.Entries)4 Property (org.whole.lang.properties.model.Property)3 Properties (org.whole.lang.properties.model.Properties)2 Enumeration (java.util.Enumeration)1 PropertyName (org.whole.lang.properties.model.PropertyName)1 PropertyValue (org.whole.lang.properties.model.PropertyValue)1