Package org.jostraca.resource.test

Source Code of org.jostraca.resource.test.SimpleDataObjectTest

/*
* Name:    SimpleDataObjectTest
* 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.resource.test;


// import
import org.jostraca.resource.SimpleDataObject;

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

import java.util.Arrays;



/** Test cases for org.jostraca.resource.SimpleDataObject
*/
public class SimpleDataObjectTest extends TestCase {

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

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

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



  public void testNameOnly() {
    String foo = "Foo";
    String d   = foo;

    SimpleDataObject sdo = new SimpleDataObject( d, 0 );
    assertTrue( foo.equals( sdo.getName() ) );
    assertTrue( !sdo.nextField() );

    sdo = new SimpleDataObject( d, 1 );
    assertTrue( foo.equals( sdo.getName() ) );
    assertTrue( !sdo.nextField() );

    d = " "+foo+" ";
    sdo = new SimpleDataObject( d, 2 );
    assertTrue( foo.equals( sdo.getName() ) );
    assertTrue( !sdo.nextField() );

    d = " \n\t"+foo+"\n\t ";
    sdo = new SimpleDataObject( d, 3 );
    assertTrue( foo.equals( sdo.getName() ) );
    assertTrue( !sdo.nextField() );
  }

 
  public void testTwoItems() {

    String d
      = "\nPerson"
      + "\nFirstName  String"
      + "\nSecondName String"
      ;

    SimpleDataObject sdo = new SimpleDataObject( d );

    assertEquals( "Person",      sdo.getName() );
    assertTrue(   sdo.nextField() );
    assertEquals( "FirstName",   sdo.getFieldName() );
    assertEquals( "String",      sdo.getFieldType() );
    assertTrue(   sdo.nextField() );
    assertEquals( "SecondName",  sdo.getFieldName() );
    assertEquals( "String",      sdo.getFieldType() );
    assertTrue(   !sdo.nextField() );

    assertTrue(   sdo.nextField() );
    assertEquals( "FirstName",   sdo.getFieldName() );
    assertEquals( "String",      sdo.getFieldType() );
    assertTrue(   sdo.nextField() );
    assertEquals( "SecondName",  sdo.getFieldName() );
    assertEquals( "String",      sdo.getFieldType() );
    assertTrue(   !sdo.nextField() );
    assertTrue(   sdo.nextField() );

  }


  public void testThreeItems() {

    String d
      = "\nConfig"
      + "\nsystem           system  internal-error"
      + "\ncannot_read_file user    cannot-read-file"
      + "\nconfig           user    config-parse-error"
      + "\nmissing field"
      + "\n"
      ;

    SimpleDataObject sdo = new SimpleDataObject( d, 3 );

    assertEquals( "Config",      sdo.getName() );
    assertTrue(   sdo.nextField() );
    assertEquals( "system",         sdo.getFirst() );
    assertEquals( "system",         sdo.getSecond() );
    assertEquals( "internal-error", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertEquals( "cannot_read_file", sdo.getFirst() );
    assertEquals( "user",             sdo.getSecond() );
    assertEquals( "cannot-read-file", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertEquals( "config",             sdo.getFirst() );
    assertEquals( "user",               sdo.getSecond() );
    assertEquals( "config-parse-error", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertTrue(   !sdo.nextField() );

    assertTrue(   sdo.nextField() );
    assertEquals( "system",         sdo.getFirst() );
    assertEquals( "system",         sdo.getSecond() );
    assertEquals( "internal-error", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertEquals( "cannot_read_file", sdo.getFirst() );
    assertEquals( "user",             sdo.getSecond() );
    assertEquals( "cannot-read-file", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertEquals( "config",             sdo.getFirst() );
    assertEquals( "user",               sdo.getSecond() );
    assertEquals( "config-parse-error", sdo.getThird() );
    assertTrue(   sdo.nextField() );
    assertTrue(   !sdo.nextField() );

  }


  public void testMultipleObjects() {
   
    SimpleDataObject[] sdo = new SimpleDataObject[3];

    sdo[0] = new SimpleDataObject
      ( "\nAAA"
        + "\na11  a12"
        + "\na21  a22" );

    sdo[1] = new SimpleDataObject
      ( "\nBBB"
        + "\nb11  b12"
        + "\nb21  b22" );

    sdo[2] = new SimpleDataObject
      ( "\nCCC"
        + "\nc11  c12"
        + "\nc21  c22" );

    String[] names = SimpleDataObject.getNames( sdo );
    assertTrue( Arrays.equals( names, new String[] { "AAA", "BBB", "CCC" } ) );
  }


}






TOP

Related Classes of org.jostraca.resource.test.SimpleDataObjectTest

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.