Package org.jostraca.util.test

Source Code of org.jostraca.util.test.PropertySetManagerTest

/*
* Name:    PropertySetManagerTest
* Authors: Richard Rodger
*
* Copyright (c) 2001-2003 Richard Rodger
*
* This program 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 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.util.test;


/* Import << */
import org.jostraca.Tools;

import org.jostraca.util.PropertySet;
import org.jostraca.util.PropertySetManager;
import org.jostraca.util.PropertySetException;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import java.io.File;

import java.util.Hashtable;
/* Import >> */


/** <b>Description:</b><br>
*  Test cases for PropertySetManager
*/
public class PropertySetManagerTest extends TestCase {

  public PropertySetManagerTest( String pName ) {
    super( pName );
  }

  public static TestSuite suite() {
    return new TestSuite( PropertySetManagerTest.class );
  }

  public static void main( String[] pArgs ) {
    TestRunner.run( suite() );
  }


  public void testConstructor() {
    Hashtable defps = new Hashtable();

    try {
      PropertySetManager psm04 = new PropertySetManager( null );
      fail();
    } catch( IllegalArgumentException iae ) {}

    PropertySetManager psm01 = new PropertySetManager();
    PropertySetManager psm02 = new PropertySetManager( defps );

    PropertySet ps01 = new PropertySet();
    defps.put( "ps01", ps01 );
    PropertySetManager psm03 = new PropertySetManager( defps );

    defps.put( "ps02", new Object() );
    try {
      PropertySetManager psm04 = new PropertySetManager( defps );
      fail();
    } catch( IllegalArgumentException iae ) {}

    defps.remove( "ps02" );

    defps.put( new Object(), ps01 );
    try {
      PropertySetManager psm04 = new PropertySetManager( defps );
      fail();
    } catch( IllegalArgumentException iae ) {}
  }


  public void testLoad() throws Exception {
    PropertySetManager psm01 = new PropertySetManager();
    PropertySet ps01 = psm01.load( "test01", Tools.findRelativeSystemPath("src/org/jostraca/util/test/test.conf") );
    assertEquals( "0", ps01.get("a") );
    assertEquals( "1", ps01.get("b") );

    try {
      psm01.load( "test02", new File("notest.conf") );
      fail();    
    } catch( PropertySetException ioe ) {}

    try {
      psm01.load( "test02", new File("notest.conf"), PropertySetManager.FILE_MUST_EXIST );
      fail();
    } catch( PropertySetException ioe ) {}

    try {
      PropertySet ps01o = psm01.load( "test01", new File("notest.conf"), PropertySetManager.USE_DEFAULT_IF_FILE_DOES_NOT_EXIST );
      assertEquals( ps01o, ps01 );
    } catch( PropertySetException ioe ) { fail(); }
  }


  public void testAdd() {
    PropertySetManager psm01 = new PropertySetManager();
    PropertySet ps01 = new PropertySet();
    psm01.put( "ps01", ps01 );

    try {
      psm01.put( null, ps01 );
      fail();
    } catch( IllegalArgumentException iae ) {}
    try {
      psm01.put( "ps01", null );
      fail();
    } catch( IllegalArgumentException iae ) {}
    try {
      psm01.put( null, null );
      fail();
    } catch( IllegalArgumentException iae ) {}

  }


  public void testGet() {
    PropertySetManager psm01 = new PropertySetManager();
    PropertySet ps01 = new PropertySet();
    psm01.put( "ps01", ps01 );

    PropertySet ps01o = psm01.get( "ps01" );
    assertEquals( ps01, ps01o );

    try {
      psm01.get( "ps02" );
      fail();
    } catch( Exception iae ) {}
  }


  public void testRemove() {
    PropertySetManager psm01 = new PropertySetManager();
    PropertySet ps01 = new PropertySet();
    psm01.put( "ps01", ps01 );
    PropertySet ps01o = psm01.remove( "ps01" );
    assertEquals( ps01, ps01o );

    try {
      psm01.get( "ps01" );
      fail();
    } catch( Exception iae ) {}

  }


 

}




TOP

Related Classes of org.jostraca.util.test.PropertySetManagerTest

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.