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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations