use of net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap 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.reader.ReaderFactoryByMap 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.reader.ReaderFactoryByMap 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.reader.ReaderFactoryByMap 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));
}
use of net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap in project n2o-framework by i-novus-llc.
the class IOProcessorTest method testProps.
@Test
public void testProps() throws Exception {
// test properties
ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
readerFactory.register(new BodyNamespaceEntityIO());
IOProcessorImpl p = new IOProcessorImpl(readerFactory);
Properties properties = new Properties();
properties.setProperty("testProp1", "testProp1");
PropertyResolver systemProperties = new SimplePropertyResolver(properties);
p.setSystemProperties(systemProperties);
testElementWithProperty(p, "testProp1");
// test params
HashMap<String, String> params = new HashMap<>();
params.put("testProp1", "testProp2");
p = new IOProcessorImpl(readerFactory);
try {
MetadataParamHolder.setParams(params);
testElementWithProperty(p, "testProp2");
} finally {
MetadataParamHolder.setParams(null);
}
// test messages
p = new IOProcessorImpl(readerFactory);
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("test_messages");
messageSource.setDefaultEncoding("UTF-8");
p.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
testElementWithProperty(p, "testProp3");
// test override
p = new IOProcessorImpl(readerFactory);
p.setSystemProperties(systemProperties);
p.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
try {
MetadataParamHolder.setParams(params);
// самый приоритетный params
testElementWithProperty(p, "testProp2");
} finally {
MetadataParamHolder.setParams(null);
}
// test fail fast
p = new IOProcessorImpl(readerFactory);
p.setFailFast(true);
// p.setSystemProperties(systemProperties); not set to fail
try {
testElementWithProperty(p, "testProp1");
fail();
} catch (N2oException ignored) {
}
// test fail tolerance
p = new IOProcessorImpl(readerFactory);
p.setFailFast(false);
// p.setSystemProperties(systemProperties); not set to fail
try {
Element in = dom("net/n2oapp/framework/config/io/ioprocessor22.xml");
BaseEntity baseEntity = new BaseEntity();
p.element(in, "attr", baseEntity::getAttr, baseEntity::setAttr);
assertThat(baseEntity.getAttr(), equalTo("${testProp1}"));
} catch (N2oException e) {
fail();
}
}
Aggregations