Search in sources :

Example 11 with PersisterFactoryByMap

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

the class RouterTest method setUp.

@Before
public void setUp() {
    N2oEnvironment env = new N2oEnvironment();
    env.setSystemProperties(new SimplePropertyResolver(new Properties()));
    env.setNamespacePersisterFactory(new PersisterFactoryByMap());
    env.setNamespaceReaderFactory(new ReaderFactoryByMap());
    builder = new N2oApplicationBuilder(env).packs(new N2oOperationsPack());
}
Also used : N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) N2oApplicationBuilder(net.n2oapp.framework.config.N2oApplicationBuilder) N2oOperationsPack(net.n2oapp.framework.config.metadata.pack.N2oOperationsPack) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Properties(java.util.Properties) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Before(org.junit.Before)

Example 12 with PersisterFactoryByMap

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

the class IOProcessorTest method testChildren.

@Test
public void testChildren() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    readerFactory.register(new BodyNamespaceEntityIO());
    IOProcessor p = new IOProcessorImpl(readerFactory);
    Element in1 = dom("net/n2oapp/framework/config/io/ioprocessor12.xml");
    Element in2 = dom("net/n2oapp/framework/config/io/ioprocessor15.xml");
    ChildrenEntityList childrenEntityList1 = new ChildrenEntityList();
    ChildrenEntityList childrenEntityList2 = new ChildrenEntityList();
    p.children(in1, "children", "el1", childrenEntityList1::getChildEntities, childrenEntityList1::setChildEntities, IOProcessorTest.ChildEntity::new, this::children);
    p.children(in2, null, "el1", childrenEntityList2::getChildEntities, childrenEntityList2::setChildEntities, IOProcessorTest.ChildEntity::new, this::children);
    assertThat(childrenEntityList1.getChildEntities().length, equalTo(3));
    assertThat(childrenEntityList1.getChildEntities()[0].getAtt(), equalTo("test1"));
    assertThat(childrenEntityList1.getChildEntities()[1].getAtt(), equalTo("test2"));
    assertThat(childrenEntityList1.getChildEntities()[2].getAtt(), equalTo("test3"));
    assertThat(childrenEntityList2.getChildEntities().length, equalTo(3));
    assertThat(childrenEntityList2.getChildEntities()[0].getAtt(), equalTo("test1"));
    assertThat(childrenEntityList2.getChildEntities()[1].getAtt(), equalTo("test2"));
    assertThat(childrenEntityList2.getChildEntities()[2].getAtt(), equalTo("test3"));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new BodyNamespaceEntityIO());
    p = new IOProcessorImpl(persisterFactory);
    Element out1 = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    Element out2 = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    p.children(out1, "children", "el1", childrenEntityList1::getChildEntities, childrenEntityList1::setChildEntities, IOProcessorTest.ChildEntity::new, this::children);
    p.children(out2, null, "el1", childrenEntityList2::getChildEntities, childrenEntityList2::setChildEntities, IOProcessorTest.ChildEntity::new, this::children);
    assertThat(in1, isSimilarTo(out1));
    assertThat(in2, isSimilarTo(out2));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Test(org.junit.Test)

Example 13 with PersisterFactoryByMap

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

the class IOProcessorTest method testChildrenToMap.

@Test
public void testChildrenToMap() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    IOProcessor pR = new IOProcessorImpl(readerFactory);
    readerFactory.register(new BodyNamespaceEntityIO());
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor7.xml");
    MapNamespaceEntity map = new MapNamespaceEntity();
    pR.childrenToMap(in, "children", "el2", "attr", null, map::getEntityMap, map::setEntityMap);
    assertThat(map.getEntityMap().get("1"), equalTo(1));
    assertThat(map.getEntityMap().get("test2"), equalTo("test2"));
    PersisterFactoryByMap persisterFactory = new PersisterFactoryByMap();
    persisterFactory.register(new BodyNamespaceEntityIO());
    IOProcessor pW = new IOProcessorImpl(persisterFactory);
    Element out = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    pW.childrenToMap(out, "children", "el2", "attr", null, map::getEntityMap, map::setEntityMap);
    assertThat(in, isSimilarTo(out));
    map.entityMap.clear();
    in = dom("net/n2oapp/framework/config/io/ioprocessor24.xml");
    pR.childrenToMap(in, "children", "el", map::getEntityMap, map::setEntityMap);
    assertThat(map.getEntityMap().get("attr"), equalTo(1));
    assertThat(map.getEntityMap().get("attr1"), equalTo("test1"));
    out = new Element("test", Namespace.getNamespace("http://example.com/n2o/ext-1.0"));
    pW.childrenToMap(out, "children", "el", map::getEntityMap, map::setEntityMap);
    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 14 with PersisterFactoryByMap

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

the class IOProcessorTest method testElement.

@Test
public void testElement() throws Exception {
    ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
    readerFactory.register(new BodyNamespaceEntityIO());
    IOProcessor p = new IOProcessorImpl(readerFactory);
    Element in = dom("net/n2oapp/framework/config/io/ioprocessor17.xml");
    BaseEntity baseEntity = new BaseEntity();
    p.element(in, "attr", baseEntity::getAttr, baseEntity::setAttr);
    assertThat(baseEntity.getAttr(), 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.element(out, "attr", baseEntity::getAttr, baseEntity::setAttr);
    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