Search in sources :

Example 1 with PersisterFactoryByMap

use of net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap in project n2o-framework by i-novus-llc.

the class DataControllerTestBase method setUp.

@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    SimplePropertyResolver propertyResolver = new SimplePropertyResolver(properties);
    setUpStaticProperties(propertyResolver);
    environment.setSystemProperties(propertyResolver);
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
Also used : N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) N2oApplicationBuilder(net.n2oapp.framework.config.N2oApplicationBuilder) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) OverrideProperties(net.n2oapp.properties.OverrideProperties) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Before(org.junit.Before)

Example 2 with PersisterFactoryByMap

use of net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap in project n2o-framework by i-novus-llc.

the class IOProcessorTest method testChildrenToStringArray.

@Test
public void testChildrenToStringArray() throws JDOMException, IOException {
    IOProcessor p = new IOProcessorImpl(true);
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor20.xml");
    ArrayEntity arrayEntity = new ArrayEntity();
    p.childrenToStringArray(in, "children", "value", arrayEntity::getArrayAttr, arrayEntity::setArrayAttr);
    assertThat(arrayEntity.getArrayAttr()[0], equalTo("1"));
    assertThat(arrayEntity.getArrayAttr()[1], equalTo("test2"));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new BodyNamespaceEntityIO());
    p = new IOProcessorImpl(persisterFactory);
    Element out = new Element("test");
    p.childrenToStringArray(out, "children", "value", arrayEntity::getArrayAttr, arrayEntity::setArrayAttr);
    assertThat(in, isSimilarTo(out));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) Test(org.junit.Test)

Example 3 with PersisterFactoryByMap

use of net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap in project n2o-framework by i-novus-llc.

the class IOProcessorTest method testChildrenText.

@Test
public void testChildrenText() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    IOProcessor p = new IOProcessorImpl(readerFactory);
    readerFactory.register(new BodyNamespaceEntityIO());
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor10.xml");
    ChildEntity childrenEntity = new ChildEntity();
    p.childrenText(in, "el1", childrenEntity::getText, childrenEntity::setText);
    assertThat(childrenEntity.getText(), equalTo("test"));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new BodyNamespaceEntityIO());
    p = new IOProcessorImpl(persisterFactory);
    Element out = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    p.childrenText(out, "el1", childrenEntity::getText, childrenEntity::setText);
    assertThat(in, isSimilarTo(out));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Test(org.junit.Test)

Example 4 with PersisterFactoryByMap

use of net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap in project n2o-framework by i-novus-llc.

the class IOProcessorTest method anyChildrenByNamespace.

@Test
public void anyChildrenByNamespace() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    readerFactory.register(new EnumNamespaceEntityIO());
    readerFactory.register(new BodyNamespaceEntityIO());
    IOProcessor p = new IOProcessorImpl(readerFactory);
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor5.xml");
    ListNamespaceEntity listNamespaceEntity = new ListNamespaceEntity();
    p.anyChildren(in, "children", listNamespaceEntity::getEntityList, listNamespaceEntity::setEntityList, p.anyOf(NamespaceEntity.class), Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    assertThat(listNamespaceEntity.entityList.length, equalTo(2));
    assertThat(listNamespaceEntity.entityList[0].getClass(), equalTo(EnumNamespaceEntity.class));
    assertThat(listNamespaceEntity.entityList[1].getClass(), equalTo(BodyNamespaceEntity.class));
    assertThat(listNamespaceEntity.entityList[0].getAttr(), equalTo("1"));
    assertThat(listNamespaceEntity.entityList[1].getAttr(), equalTo("2"));
    assertThat(((EnumNamespaceEntity) listNamespaceEntity.entityList[0]).getEn(), equalTo(MyEnum.en1));
    assertThat(((BodyNamespaceEntity) listNamespaceEntity.entityList[1]).getBody(), equalTo("test"));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new EnumNamespaceEntityIO());
    persisterFactory.register(new BodyNamespaceEntityIO());
    p = new IOProcessorImpl(persisterFactory);
    Element out = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    p.anyChildren(out, "children", listNamespaceEntity::getEntityList, listNamespaceEntity::setEntityList, p.anyOf(NamespaceEntity.class), Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    assertThat(in, isSimilarTo(out));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Test(org.junit.Test)

Example 5 with PersisterFactoryByMap

use of net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap in project n2o-framework by i-novus-llc.

the class IOProcessorTest method testChildrenAttributes.

@Test
public void testChildrenAttributes() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    readerFactory.register(new EnumNamespaceEntityIO());
    readerFactory.register(new BodyNamespaceEntityIO());
    IOProcessor p = new IOProcessorImpl(readerFactory);
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor11.xml");
    ChildEntity childrenEntity = new ChildEntity();
    p.childAttribute(in, "el1", "attr", childrenEntity::getAtt, childrenEntity::setAtt);
    p.childAttributeBoolean(in, "el1", "attr1", childrenEntity::getBool, childrenEntity::setBool);
    p.childAttributeInteger(in, "el1", "attr2", childrenEntity::getInt, childrenEntity::setInt);
    p.childAttributeEnum(in, "el1", "enum1", childrenEntity::getEn, childrenEntity::setEn, MyEnum.class);
    assertThat(childrenEntity.getAtt(), equalTo("test"));
    assertThat(childrenEntity.getBool(), equalTo(true));
    assertThat(childrenEntity.getInt(), equalTo(5));
    assertThat(childrenEntity.getEn(), equalTo(MyEnum.en1));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new EnumNamespaceEntityIO());
    persisterFactory.register(new BodyNamespaceEntityIO());
    p = new IOProcessorImpl(persisterFactory);
    Element out = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    p.childAttribute(out, "el1", "attr", childrenEntity::getAtt, childrenEntity::setAtt);
    p.childAttributeBoolean(out, "el1", "attr1", childrenEntity::getBool, childrenEntity::setBool);
    p.childAttributeInteger(out, "el1", "attr2", childrenEntity::getInt, childrenEntity::setInt);
    p.childAttributeEnum(out, "el1", "enum1", childrenEntity::getEn, childrenEntity::setEn, MyEnum.class);
    assertThat(in, isSimilarTo(out));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Test(org.junit.Test)

Aggregations

PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)14 ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)13 Test (org.junit.Test)9 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)5 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)5 SimplePropertyResolver (net.n2oapp.framework.config.test.SimplePropertyResolver)4 OverrideProperties (net.n2oapp.properties.OverrideProperties)4 Before (org.junit.Before)4 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)4 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)4 Locale (java.util.Locale)1 Properties (java.util.Properties)1 N2oOperationsPack (net.n2oapp.framework.config.metadata.pack.N2oOperationsPack)1