Search in sources :

Example 1 with Entries

use of org.whole.lang.properties.model.Entries 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 2 with Entries

use of org.whole.lang.properties.model.Entries 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)

Example 3 with Entries

use of org.whole.lang.properties.model.Entries in project whole by wholeplatform.

the class PropertiesUtils method translate.

@SuppressWarnings("unchecked")
public static Properties translate(java.util.Properties jProps) throws IOException {
    PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
    Properties props = lf.create(PropertiesEntityDescriptorEnum.Properties);
    Entries entries = props.getEntries();
    if (entries.wSize() == 1)
        // workaround for removing the resolver
        entries.wRemove(0);
    Enumeration<String> names = (Enumeration<String>) jProps.propertyNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = jProps.getProperty(name);
        entries.wAdd(lf.createProperty(lf.createPropertyName(name), // FIXME workaround for null valued property returned from System.getProperties()
        value != null ? lf.createPropertyValue(value) : CommonsEntityAdapterFactory.createResolver(PropertiesEntityDescriptorEnum.PropertyValue)));
    }
    return props;
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Enumeration(java.util.Enumeration) Entries(org.whole.lang.properties.model.Entries) Properties(org.whole.lang.properties.model.Properties)

Example 4 with Entries

use of org.whole.lang.properties.model.Entries in project whole by wholeplatform.

the class FactoriesTest method testCompositeFactoryMethods.

@Test
public void testCompositeFactoryMethods() {
    IEntityRegistry efi = ReflectionFactory.getLanguageKit(PropertiesLanguageKit.URI).getEntityRegistry(RegistryConfigurations.DEFAULT);
    PropertiesEntityFactory ef = PropertiesEntityFactory.instance;
    Entries p = ef.createEntries(ef.createProperty(), ef.create(PropertiesEntityDescriptorEnum.Property, "p2", "v2"));
    efi.put(p);
    Entries e1 = ef.createEntries();
    Assert.assertEquals(2, e1.wSize());
    Entries e2 = ef.createEntries(new Property[0]);
    Assert.assertEquals(0, e2.wSize());
    Entries e3 = ef.createEntries(ef.create(PropertiesEntityDescriptorEnum.Property, "p1", "v1"));
    Assert.assertEquals(1, e3.wSize());
}
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)4 Entries (org.whole.lang.properties.model.Entries)4 Test (org.junit.Test)3 Enumeration (java.util.Enumeration)1 Properties (org.whole.lang.properties.model.Properties)1