package net.hyperic.sigar.test;

import java.io.PrintStream;
import junit.framework.TestCase;

import net.hyperic.sigar.Sigar;

//helper to add optional tracing.
public abstract class SigarTestCase extends TestCase {

    private Sigar sigar = null;
    private static boolean verbose = false;
    private static PrintStream out = System.out;

    public SigarTestCase(String name) {
        super(name);
    }

    public Sigar getSigar() {
        if (this.sigar == null) {
            this.sigar = new Sigar();
            if (getVerbose()) {
                this.sigar.enableLogging(true);
            }
        }
        return this.sigar;
    }

    public static void setVerbose(boolean value) {
        verbose = value;
    }

    public static boolean getVerbose() {
        return verbose;
    }

    public static void setWriter(PrintStream value) {
        out = value;
    }

    public static PrintStream getWriter() {
        return out;
    }

    public void traceln(String msg) {
        if (getVerbose()) {
            getWriter().println(msg);
        }
    }

    public void trace(String msg) {
        if (getVerbose()) {
            getWriter().print(msg);
        }
    }

    public void assertTrueTrace(String msg, String value) {
        traceln(msg + "=" + value);
        assertTrue(msg, value != null);
    }

    public void assertLengthTrace(String msg, String value) {
        assertTrueTrace(msg, value);
        assertTrue(msg, value.length() > 0);
    }

    public void assertGtZeroTrace(String msg, long value) {
        traceln(msg + "=" + value);
        assertTrue(msg, value > 0);
    }

    public void assertGtEqZeroTrace(String msg, long value) {
        traceln(msg + "=" + value);
        assertTrue(msg, value >= 0);
    }

    public void assertEqualsTrace(String msg, long expected, long actual) {
        traceln(msg + "=" + actual + "/" + expected);
        assertEquals(msg, expected, actual);
    }
}

@@ -54,16 +54,128 @@
 Stream;%0A
+import java.io.IOException;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0A%0Aimport java.util.Properties;%0A%0A
 import j
@@ -355,16 +355,66 @@
 = null;%0A
+    private Properties props = new Properties();%0A%0A
     priv
@@ -564,246 +564,1047 @@
 e);%0A
-    %7D%0A%0A    public Sigar getSigar() %7B%0A        if (this.sigar == null) %7B%0A            this.sigar = new Sigar();%0A            if (getVerbose()) %7B%0A                this.sigar.enableLogging(true);%0A            %7D%0A        %7D%0A        return this.sigar
+%0A        File f = new File(System.getProperty(%22user.home%22),%0A                          %22.sigar.properties%22);%0A%0A        if (f.exists()) %7B%0A            FileInputStream is = null;%0A%0A            try %7B%0A                is = new FileInputStream(f);%0A                this.props.load(is);%0A            %7D catch (IOException e) %7B%0A                e.printStackTrace();%0A            %7D finally %7B%0A                if (is != null) %7B%0A                    try %7B is.close(); %7D catch (IOException e) %7B %7D%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    public Sigar getSigar() %7B%0A        if (this.sigar == null) %7B%0A            this.sigar = new Sigar();%0A            if (getVerbose()) %7B%0A                this.sigar.enableLogging(true);%0A            %7D%0A        %7D%0A        return this.sigar;%0A    %7D%0A%0A    public Properties getProperties() %7B%0A        return this.props;%0A    %7D%0A    %0A    public String getProperty(String key, String val) %7B%0A        return getProperties().getProperty(key, val);%0A    %7D%0A%0A    public String getProperty(String key) %7B%0A        return getProperty(key, null)
 ;%0A  

add properties methods