Home » geronimo-2.2-source-release » org.apache.geronimo.system.serverinfo » [javadoc | source]

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.system.serverinfo;
   18   
   19   import java.io.File;
   20   import java.io.IOException;
   21   
   22   import junit.framework.TestCase;
   23   
   24   /**
   25    * @version $Rev: 124261 $ $Date: 2005-01-05 11:56:08 -0800 (Wed, 05 Jan 2005) $
   26    */
   27   public class ServerInfoTest extends TestCase {
   28   
   29       public final void testResolvePath() {
   30           ServerInfo si = null;
   31   
   32           String pathArg;
   33           {
   34               si = new ServerInfo();
   35               pathArg = "/";
   36               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   37               pathArg = "/x";
   38               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   39               pathArg = "/x/y";
   40               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   41               pathArg = "C:/Documents and Settings/Administrator/Application Data/geronimo";
   42               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   43   
   44               pathArg = ".";
   45               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   46               pathArg = "x";
   47               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   48               pathArg = "x/y";
   49               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   50               pathArg = "Documents and Settings/Administrator/Application Data/geronimo";
   51               assertEquals(new File(pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   52           }
   53   
   54           try {
   55               String basedir = "/";
   56               si = new ServerInfo(basedir);
   57               pathArg = "Documents and Settings/Administrator/Application Data/geronimo";
   58               assertEquals(new File(basedir, pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   59           } catch (Exception e) {
   60               fail("ServerInfo ctor threw exception " + e);
   61           }
   62   
   63           //try {
   64           //    String basedir = File.listRoots()[0].getAbsolutePath();
   65           //    si = new ServerInfo(basedir);
   66           //    pathArg = "Documents and Settings/Administrator/Application Data/geronimo";
   67           //    assertEquals(new File(basedir, pathArg).getAbsolutePath(), si.resolvePath(pathArg));
   68           //} catch (Exception e) {
   69           //    fail("ServerInfo ctor threw exception " + e);
   70           //}
   71       }
   72   
   73       public final void testServerInfo() throws Exception {
   74   		try {
   75   			File file;
   76   			try {
   77   				file = File.createTempFile("geronimo", null);
   78   				// a workaround - ServerInfo sets system-wide property
   79   				System.setProperty("geronimo.base.dir", file.getName());
   80   				new ServerInfo(file.getName());
   81   				fail("ServerInfo should throw exception when given non-directory path");
   82   			} catch (IOException ioe) {
   83   				fail(ioe.getMessage());
   84   			} catch (Exception expected) {
   85   			}
   86   
   87   			String basedir = ".";
   88   			// a workaround - ServerInfo sets system-wide property
   89   			System.setProperty("geronimo.base.dir", basedir);
   90   			ServerInfo si = new ServerInfo(basedir);
   91   			assertNotNull(System.getProperty("geronimo.base.dir"));
   92   			assertEquals("base directory is incorrect", basedir, si.getBaseDirectory());
   93   		} finally {
   94   			System.getProperties().remove("geronimo.base.dir");
   95   		}
   96       }
   97   }

Home » geronimo-2.2-source-release » org.apache.geronimo.system.serverinfo » [javadoc | source]