Package com.alibaba.citrus.springext.support.context

Examples of com.alibaba.citrus.springext.support.context.XmlApplicationContext


    private ApplicationContext factory;
    private Configuration      conf;

    @Test
    public void defaultValue() {
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder.xml")));
        conf = (Configuration) factory.getBean("simpleConfiguration");

        // ${productionMode:false}
        assertEquals(false, conf.isProductionMode());
    }
View Full Code Here


    @Test
    public void systemPropertyValue() {
        System.setProperty("productionMode", "true");

        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder.xml")));
        conf = (Configuration) factory.getBean("simpleConfiguration");

        // ${productionMode:false}
        assertEquals(true, conf.isProductionMode());
    }
View Full Code Here

    @Test
    public void invalidValue() {
        System.setProperty("productionMode", "invalid");

        try {
            new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder.xml")));
            fail();
        } catch (Exception e) {
            assertThat(e, exception(IllegalArgumentException.class, "invalid"));
        } finally {
            System.clearProperty("productionMode");
View Full Code Here

    @Test
    public void location() {
        // with system property: -Dtest1=test1.props
        System.setProperty("test1", "test1.props");
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-2.xml")));
        List<?> list = (List<?>) factory.getBean("list");
        assertArrayEquals(new Object[] { "111", "222", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));

        // no system property: -Dtest1, but has default value
        System.clearProperty("test1");
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-2.xml")));
        list = (List<?>) factory.getBean("list");
        assertArrayEquals(new Object[] { "111", "222", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));

        // override default value
        System.setProperty("test1", "test3.props");
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-2.xml")));
        list = (List<?>) factory.getBean("list");
        assertArrayEquals(new Object[] { "11111", "222", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));

        // no system property and no default value
        System.clearProperty("test1");

        try {
            new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-4.xml")));
            fail();
        } catch (BeansException e) {
            assertThat(e, exception("${test1}"));
        }

        // no system property and with empty default value
        System.clearProperty("test1");
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-5.xml")));
        list = (List<?>) factory.getBean("list");

        // ${x:} with empty default value
        assertArrayEquals(new Object[] { "", "222", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }
View Full Code Here

        assertArrayEquals(new Object[] { "", "222", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }

    @Test
    public void propertiesRef() {
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-3.xml")));
        List<?> list = (List<?>) factory.getBean("list");
        assertArrayEquals(new Object[] { "aaa", "bbb", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }
View Full Code Here

        assertArrayEquals(new Object[] { "aaa", "bbb", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }

    @Test
    public void propertiesRef_specificProperties() {
        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-1.xml")));
        List<?> list = (List<?>) factory.getBean("list");
        assertArrayEquals(new Object[] { "aaa", "ccc", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }
View Full Code Here

    public void unresolvable_ignored() {
        System.clearProperty("x");
        System.clearProperty("y");
        System.clearProperty("z");

        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-6.xml")));
        List<?> list = (List<?>) factory.getBean("list");

        assertArrayEquals(new Object[] { "${x}", "${y}", "defaultValue" }, list.toArray(EMPTY_OBJECT_ARRAY));
    }
View Full Code Here

        System.clearProperty("x");
        System.clearProperty("y");
        System.clearProperty("z");

        try {
            new XmlApplicationContext(new FileSystemResource(new File(srcdir, "property-placeholder-7.xml")));
            fail();
        } catch (BeansException e) {
            assertThat(e, exception("Could not resolve placeholder 'x'"));
        }
    }
View Full Code Here

    public void init() {
        if (skipValidation) {
            System.setProperty("skipValidation", "true");
        }

        factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, "services-skip-validation.xml")));
        mappingRuleService = (MappingRuleServiceImpl) factory.getBean("mappingRuleService");
        rules = getFieldValue(mappingRuleService, "rules", Map.class);
    }
View Full Code Here

        factory = initFactory("services.xml");
        System.setProperty("user.name", "baobao"); // javamail Service类会去取user.name,此处明确设定该值。
    }

    protected static final XmlApplicationContext initFactory(String configFile) {
        XmlApplicationContext factory = new XmlApplicationContext(new FileSystemResource(new File(srcdir, configFile)));
        factory.setResourceLoadingExtender(new ResourceLoadingSupport(factory));
        return factory;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.springext.support.context.XmlApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.