[LOGBack-dev] svn commit: r61 - logback/core/trunk/src/test/java/ch/qos/logback/core/rolling/helper

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Jul 13 16:33:54 CEST 2006


Author: seb
Date: Thu Jul 13 16:33:53 2006
New Revision: 61

Modified:
   logback/core/trunk/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
Log:
using new paths to access files + added some copying/cleaning in setUp()

Modified: logback/core/trunk/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
==============================================================================
--- logback/core/trunk/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java	(original)
+++ logback/core/trunk/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java	Thu Jul 13 16:33:53 2006
@@ -9,12 +9,20 @@
  */
 package ch.qos.logback.core.rolling.helper;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
-
-import ch.qos.logback.core.rolling.helper.Compress;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.util.Compare;
+import ch.qos.logback.core.util.StatusPrinter;
 
 
 /**
@@ -22,32 +30,70 @@
  */
 public class CompressTest extends TestCase {
 
-  Compress compress = new Compress();
-
+  Compress compress;
+  Context context = new ContextBase();
+  
   public CompressTest(String arg0) {
     super(arg0);
+    compress = new Compress();
+    compress.setContext(context);
   }
 
-  public void setUp() {
+  public void setUp() throws IOException {
+	  //Copy source files
+	  //Delete output files
+	  {
+		  File source = new File("src/test/input/compress1.copy");
+		  File dest = new File("src/test/input/compress1.txt");
+		  copy(source, dest);
+		  File target = new File("src/test/output/compress1.txt.gz");
+		  target.mkdirs();
+		  target.delete();
+	  }
+	  {
+		  File source = new File("src/test/input/compress2.copy");
+		  File dest = new File("src/test/input/compress2.txt");
+		  copy(source, dest);
+		  File target = new File("src/test/output/compress2.txt.gz");
+		  target.mkdirs();
+		  target.delete();
+	  }
+	  {
+		  File source = new File("src/test/input/compress3.copy");
+		  File dest = new File("src/test/input/compress3.txt");
+		  copy(source, dest);
+		  File target = new File("src/test/output/compress3.txt.zip");
+		  target.mkdirs();
+		  target.delete();
+	  }
   }
 
   public void tearDown() {
   }
 
   public void test1() throws Exception {
-    compress.GZCompress("input/compress1.txt", "output/compress1.txt.gz");
-    assertTrue(Compare.gzCompare("output/compress1.txt.gz",
-        "witness/compress1.txt.gz"));
+	compress.GZCompress("src/test/input/compress1.txt", "src/test/output/compress1.txt.gz");
+  
+	StatusPrinter.print(context.getStatusManager());
+	assertEquals(0, context.getStatusManager().getCount());
+	assertTrue(Compare.gzCompare("src/test/output/compress1.txt.gz",
+        "src/test/witness/compress1.txt.gz"));
   }
 
   public void test2() throws Exception {
-    compress.GZCompress("input/compress2.txt", "output/compress2.txt");
-    assertTrue(Compare.gzCompare("output/compress2.txt.gz",
-        "witness/compress2.txt.gz"));
+	compress.GZCompress("src/test/input/compress2.txt", "src/test/output/compress2.txt");
+    
+	StatusPrinter.print(context.getStatusManager());
+	assertEquals(0, context.getStatusManager().getCount());
+    assertTrue(Compare.gzCompare("src/test/output/compress2.txt.gz",
+        "src/test/witness/compress2.txt.gz"));
   }
 
   public void test3() throws Exception {
-    compress.ZIPCompress("input/compress3.txt", "output/compress3.txt");
+    compress.ZIPCompress("src/test/input/compress3.txt", "src/test/output/compress3.txt");
+	
+	StatusPrinter.print(context.getStatusManager());
+	assertEquals(0, context.getStatusManager().getCount());
     // assertTrue(Compare.compare("output/compress3.txt.zip",
     // "witness/compress3.txt.zip"));
   }
@@ -59,4 +105,18 @@
     suite.addTest(new CompressTest("test3"));
     return suite;
   }
+  
+  private void copy(File src, File dst) throws IOException {
+      InputStream in = new FileInputStream(src);
+      OutputStream out = new FileOutputStream(dst);
+      byte[] buf = new byte[1024];
+      int len;
+      while ((len = in.read(buf)) > 0) {
+          out.write(buf, 0, len);
+      }
+      in.close();
+      out.close();
+  }
+  
+  
 }



More information about the logback-dev mailing list