Package simtools.ui.test.junit

Source Code of simtools.ui.test.junit.UserPropertiesTest

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: UserPropertiesTest.java,v 1.2 2006/11/21 16:24:20 booba_skaya Exp $
*
*/
package simtools.ui.test.junit;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import simtools.ui.UserProperties;

/**
* Class UserPropertiesTest
*
*/
public class UserPropertiesTest extends TestCase {
    /**
     * Test method for {@link simtools.ui.UserProperties#getProperty(java.lang.String)}.
     */
    public final void testGetPropertyString() {
        UserProperties childUp = new UserProperties(new File(UserPropertiesTest.class.getResource("property.txt").getPath()));
        childUp.read();
        //Test some properties
        String expected = "0";
        assertEquals(expected, childUp.getProperty("child.property0"));
        expected = "1";
        assertEquals(expected, childUp.getProperty("child.property1"));
        //retrieve master properties from child.
        expected = "0";
        assertEquals(expected, childUp.getProperty("master.property0"));
        //retrieve overriden property.
        expected = "2";
        assertEquals(expected, childUp.getProperty("master.property1"));
    }

    /**
     * Test method for {@link simtools.ui.UserProperties#setProperty(java.lang.String, java.lang.String)}.
     */
    public final void testSetPropertyStringString() {
        UserProperties childUp = new UserProperties(new File(UserPropertiesTest.class.getResource("property.txt").getPath()));
        childUp.read();
        //Set a child property.
        String expected = "0";
        //The set property must return old value, which should be 1.
        assertEquals(expected, childUp.setProperty("child.property0", "1"));
        //And then the property should be 1
        expected = "1";
        assertEquals(expected, childUp.getProperty("child.property0"));
        //Set a master property with the same value.
        expected = "0";
        assertEquals(expected, childUp.setProperty("master.property0", "0"));
        assertEquals(expected, childUp.getProperty("master.property0"));
        //Now check that this property has been saved in the child file, as it was the same value as the master.
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            childUp.store(out, "");
            String savedProperties = out.toString();
            //We have to check that master properties has not been saved.
            assertTrue(savedProperties.indexOf("master.property0") == -1);
        } catch (IOException e) {
            fail("IOException :"+e);
        }
        //Set a master property with a overriden value.
        expected = null;
        //expected value is the previous value, and as child file did have this property set, expected should be null.
        assertEquals(expected, childUp.setProperty("master.property0", "3"));
        //Now expected value is the newly set one.
        expected = "3";
        assertEquals(expected, childUp.getProperty("master.property0"));
        //Now check that this property has been saved in the child file, as it was the same value as the master.
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            childUp.store(out, "");
            String savedProperties = out.toString();
            //We have to check that master properties has been saved in child file.
            assertTrue(savedProperties.indexOf("master.property0") != -1);
        } catch (IOException e) {
            fail("IOException :"+e);
        }

        //Now try to set a new property.
        expected = "4";
        //The set property must return old value, which should null (new property).
        assertEquals(null, childUp.setProperty("child.property4", "4"));
        assertEquals(expected, childUp.getProperty("child.property4"));
    }
}
TOP

Related Classes of simtools.ui.test.junit.UserPropertiesTest

TOP
Copyright © 2018 www.massapi.com. 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.