# InitTest

Chr. Clemens Lee
2000-11-21

## Abstract

This document contains the documentation and source code of the ccl java class ccl.util.test.InitTest.

## Table of Contents

1 InitTest
1.1 Test for project under classes directory
Links

## 1 InitTest

### 1.1 Test for project under classes directory

We want to setup a test where we can check if projects installed under directories with name "classes" are working.

For this we need to create a classes directory inside a temporary directory and inside of this a "inittest" directory. When the test has been finished all temporary directories will be removed together with the files underneath these directories.

In this temporary directory we copy over the ccl.jar file to classes/ccl9.26/lib/ccl.jar. We also need to be able to alter the classpath so that this jar file is the first item in the classpath init uses.

The output we expect from Init.getApplicationPath() is the path to the temporary file (.../classes/ccl9.26/). The question is what input we have to provide for this test.

        private void _testGetApplicationPath( String sRCSHeader_ )
            throws IOException
        {
            String sTempDir = FileUtil.createTempDir();
            String sAppDir = FileUtil.concatPath( sTempDir
                                                  , "classes"
                                                    + File.separator
                                                    + "ccl9.26"      );
            String sTempJar = FileUtil.concatPath( sAppDir
                                                   , "lib"  );
            FileUtil.md( sTempJar );

            // locate and copy ccl.jar
            String sOrigJar = _init.getApplicationPath();
            sOrigJar = FileUtil.concatPath( sOrigJar
                                            , "lib"
                                              + File.separator
                                              + "ccl.jar"      );
            sTempJar = sTempJar + File.separator + "inittest.jar";
            FileUtil.copy( sOrigJar, sTempJar );

            // alter classpath temporarily
            String sOrigClasspath = System.getProperty( "java.class.path" );
            String sTempClasspath = sTempJar + File.pathSeparator + sOrigClasspath;
            System.setProperty( "java.class.path", sTempClasspath );

            // create new Init object
            Init init = new Init( this, null, sRCSHeader_ );
            assert( init.getApplicationName().equals( "InitTest" )
                    , "Application name should be 'Inittest' but is '" + init.getApplicationName() + "'!" );
            assert( FileUtil.equalsPath( init.getApplicationPath()
                                          , sAppDir               )
                    , "Application path should be '" + sAppDir + "' but is '" + init.getApplicationPath() + "'!" );

            System.setProperty( "java.class.path", sOrigClasspath );

            FileUtil.deleteRecursively( sTempDir );
        }

## Links

ccl.util.test.InitTest: | ../src/ccl/util/test/InitTest.java
Clemens' Java Page: | http://www.kclee.com/clemens/java/
Clemens' Home Page: | http://www.kclee.com/clemens/

clemens@kclee.com, last revised: $date: $