Search in sources :

Example 1 with ReaderFactoryByMap

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

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));
}
Also used : PersisterFactoryByMap(net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Test(org.junit.Test)

Example 3 with ReaderFactoryByMap

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));
}
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 ReaderFactoryByMap

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));
}
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 ReaderFactoryByMap

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();
    }
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) HashMap(java.util.HashMap) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) ReaderFactoryByMap(net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap) Properties(java.util.Properties) PropertyResolver(org.springframework.core.env.PropertyResolver) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Aggregations

ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)16 PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)13 Test (org.junit.Test)11 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)5 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)5 SimplePropertyResolver (net.n2oapp.framework.config.test.SimplePropertyResolver)5 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)5 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)5 OverrideProperties (net.n2oapp.properties.OverrideProperties)4 Before (org.junit.Before)4 Properties (java.util.Properties)2 SimplePageElementIOv3 (net.n2oapp.framework.config.io.page.v3.SimplePageElementIOv3)2 XmlMetadataLoader (net.n2oapp.framework.config.reader.XmlMetadataLoader)2 XmlInfo (net.n2oapp.framework.config.register.XmlInfo)2 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 DataSet (net.n2oapp.criteria.dataset.DataSet)1 N2oException (net.n2oapp.framework.api.exception.N2oException)1 SourceMetadata (net.n2oapp.framework.api.metadata.SourceMetadata)1 N2oPage (net.n2oapp.framework.api.metadata.global.view.page.N2oPage)1