Package org.jostraca.test

Source Code of org.jostraca.test.BasicTemplatePathTest

/*
* Name:    BasicTemplatePathTest
* Authors: Richard Rodger
* Release: 0.3
*
* 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.test;


/* Import << */
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.jostraca.TemplateException;
import org.jostraca.BasicTemplatePath;

import org.jostraca.util.StandardException;

import java.io.File;
/* Import >> */


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

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

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

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


  public void testSetTemplateName() throws Exception {

    BasicTemplatePath btp = new BasicTemplatePath( "file.txt" );

    try {
      btp.setTemplateName( null );
      fail();
    } catch( IllegalArgumentException e ) {}

    try {
      btp.setTemplateName( "nonexistent-file.txt" );
      btp.resolve( new String[] {} );
      fail();
    } catch( TemplateException tpe ) {
      assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
    }

    try {
      btp.setTemplateName( "/tmp" );
      btp.resolve( new String[] {} );
      fail();
    } catch( TemplateException tpe ) {
      assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
    }

    try {
      btp.setTemplateName( "file.txt" );
      btp.resolve( new String[] {} );
      assertTrue( "file.txt".equals( btp.getTemplateName() ) );
      assertTrue( "file.txt".equals( btp.getTemplateFileName() ) );
      btp.resolve( new String[] {} );
    } catch( TemplateException tpe ) {
      fail();
    }

  }



  public void testSetTemplateNameFromFile() throws Exception {

    BasicTemplatePath btp = new BasicTemplatePath( "file.txt" );

    try {
      btp.setTemplateNameFromFile( null, null );
      fail();
    } catch( IllegalArgumentException e ) {}
    try {
      btp.setTemplateNameFromFile( "", null );
      fail();
    } catch( IllegalArgumentException e ) {}

    try {
      btp.setTemplateNameFromFile( null, "" );
      fail();
    } catch( IllegalArgumentException e ) {}


    try {
      btp.setTemplateNameFromFile( "nonexistent-file.txt", "nonexistant-folder/filelist.txt"  );
      btp.resolve( new String[] {} );
      fail();
    } catch( TemplateException tpe ) {
      assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
    }

    // REVIEW: file.txt is found because it exists in the current folder - is this good?
    try {
      btp.setTemplateNameFromFile( "file.txt", "nonexistent-folder/filelist.txt"  );
      btp.resolve( new String[] {} );
    } catch( TemplateException tpe ) {
      fail();
    }
    try {
      btp.setTemplateNameFromFile( "some-file.txt", "nonexistent-folder/filelist.txt"  );
      btp.resolve( new String[] {} );
      fail();
    } catch( TemplateException tpe ) {
      assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
    }


    try {
      btp.setTemplateNameFromFile( "nonexistent-file.txt", "folder/filelist.txt" );
      btp.resolve( new String[] {} );
      fail();
    } catch( TemplateException tpe ) {
      assertEquals( StandardException.Code.CAT_user, tpe.getCat() );
    }

    try {
      btp.setTemplateNameFromFile( "file.txt", "folder/filelist.txt" );
      btp.resolve( new String[] {} );
      assertTrue( ("folder"+File.separator+"file.txt").equals( btp.getTemplatePath() ) );
    }
    catch( TemplateException tpe ) {
      fail();
    }

    try {
      File tmpFile = File.createTempFile( "jostraca", "test" );
      btp.setTemplateNameFromFile( tmpFile.getAbsolutePath(), "folder/filelist.txt" );
      btp.resolve( new String[] {} );
      assertTrue( tmpFile.getAbsolutePath().equals( btp.getTemplatePath() ) );
    }
    catch( TemplateException tpe ) {
      fail();
    }

    try {
      btp.setTemplateNameFromFile( "file.txt", "filelist.txt" );
      assertTrue( "file.txt".equals( btp.getTemplateName() ) );
    } catch( TemplateException tpe ) {
      fail();
    }
   
  }

}




TOP

Related Classes of org.jostraca.test.BasicTemplatePathTest

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.