net.joala.condition.regression.Joala45SpringConfigurationUnresolvablePropertyTest.java Source code

Java tutorial

Introduction

Here is the source code for net.joala.condition.regression.Joala45SpringConfigurationUnresolvablePropertyTest.java

Source

/*
 * Copyright 2013 CoreMedia AG
 *
 * This file is part of Joala.
 *
 * Joala is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Joala is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Joala.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.joala.condition.regression;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
 * Case: The Property Placeholder from the Conditions-Context tried to resolve properties
 * it was not responsible for. Thus if the spring context could be loaded was depending on
 * the order of imports and property placeholder definitions in the local context.
 *
 * @since 2013-01-30
 */
public class Joala45SpringConfigurationUnresolvablePropertyTest {
    private static final Logger LOG = LoggerFactory
            .getLogger(Joala45SpringConfigurationUnresolvablePropertyTest.class);

    @Test
    public void scenario_local_property_placeholder_fails_for_property_from_conditions_context_order_1()
            throws Exception {
        try {
            new ClassPathXmlApplicationContext("/META-INF/joala/condition/joala-45-context-1.xml");
            fail("Expected BeansException reporting unresolvable placeholder condition.timeout.seconds");
        } catch (BeansException ignored) {
            // we are fine
        }
    }

    @Test
    public void scenario_local_property_placeholder_fails_for_property_from_conditions_context_order_2()
            throws Exception {
        try {
            new ClassPathXmlApplicationContext("/META-INF/joala/condition/joala-45-context-3.xml");
            fail("Expected BeansException reporting unresolvable placeholder condition.timeout.seconds");
        } catch (BeansException ignored) {
            // we are fine
        }
    }

    @Test
    public void scenario_joala45_ignore_unresolvable_for_local_properties() throws Exception {
        final ClassPathXmlApplicationContext applicationContext;
        try {
            applicationContext = new ClassPathXmlApplicationContext(
                    "/META-INF/joala/condition/joala-45-context-2.xml");
        } catch (BeansException e) {
            final String msg = "Joala 45 Regression: Conditions Context should not try to resolve local properties.";
            LOG.error(msg, e);
            throw new AssertionError(msg);
        }
        final Object myString = applicationContext.getBean("myString");
        assertEquals("Local bean should have been correctly filled with properties.", "myString", myString);
    }

}