[logback-dev] svn commit: r1633 - in logback/trunk/logback-core/src/test: input/joran java/ch/qos/logback/core/joran/implicitAction

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Mar 5 14:31:07 CET 2008


Author: ceki
Date: Wed Mar  5 14:31:06 2008
New Revision: 1633

Added:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Cake.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/ImplicitActionTest.java
      - copied, changed from r1632, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/SimplePropertyIATest.java
Removed:
   logback/trunk/logback-core/src/test/input/joran/simplePropertyIA1.xml
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/SimplePropertyIATest.java
Modified:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Fruit.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/PackageTest.java

Log:
- added a new test, checking the configuration of nested collection of complex objects

Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Cake.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Cake.java	Wed Mar  5 14:31:06 2008
@@ -0,0 +1,22 @@
+package ch.qos.logback.core.joran.implicitAction;
+
+public class Cake {
+
+  String type;
+  int code;
+  
+  public String getType() {
+    return type;
+  }
+  public void setType(String type) {
+    this.type = type;
+  }
+  public int getCode() {
+    return code;
+  }
+  public void setCode(int code) {
+    this.code = code;
+  }
+  
+  
+}

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Fruit.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Fruit.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/Fruit.java	Wed Mar  5 14:31:06 2008
@@ -7,6 +7,7 @@
 
   String name;
   List<String> textList = new ArrayList<String>();
+  List<Cake> cakeList = new ArrayList<Cake>();
   
   public Fruit() {
   }
@@ -23,4 +24,7 @@
     textList.add(s);
   }
   
+  public void addCake(Cake c) {
+    cakeList.add(c);
+  }
 }

Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/ImplicitActionTest.java (from r1632, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/SimplePropertyIATest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/SimplePropertyIATest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/ImplicitActionTest.java	Wed Mar  5 14:31:06 2008
@@ -1,42 +1,44 @@
 package ch.qos.logback.core.joran.implicitAction;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.util.HashMap;
 import java.util.List;
 
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+
 import ch.qos.logback.core.joran.SimpleConfigurator;
 import ch.qos.logback.core.joran.action.Action;
 import ch.qos.logback.core.joran.spi.Pattern;
 import ch.qos.logback.core.util.Constants;
 import ch.qos.logback.core.util.StatusPrinter;
 
-public class SimplePropertyIATest extends TestCase {
+public class ImplicitActionTest {
 
+  static final String IMPLCIT_DIR = Constants.TEST_DIR_PREFIX +"input/joran/implicitAction/";
+  
   FruitContext fruitContext = new FruitContext();
+  SimpleConfigurator simpleConfigurator;
   
-  public SimplePropertyIATest(String arg0) {
-    super(arg0);
+  public ImplicitActionTest() {
   }
 
-  protected void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public void setUp() throws Exception {
     fruitContext.setName("fruits");
+    HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
+    rulesMap.put(new Pattern("/context/"), new FruitContextAction());
+    simpleConfigurator = new SimpleConfigurator(rulesMap);
+    simpleConfigurator.setContext(fruitContext);
   }
 
-  protected void tearDown() throws Exception {
-    super.tearDown();
-  }
-
-  public void test() throws Exception {
+  @Test
+  public void nested() throws Exception {
       try {
-      HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
-      rulesMap.put(new Pattern("/context/"), new FruitContextAction());
-      SimpleConfigurator simpleConfigurator = new SimpleConfigurator(rulesMap);
-
-      simpleConfigurator.setContext(fruitContext);
-
-      simpleConfigurator.doConfigure(Constants.TEST_DIR_PREFIX + "input/joran/"
-          + "simplePropertyIA1.xml");
+          simpleConfigurator.doConfigure(IMPLCIT_DIR + "nestedComponent.xml");
+      
       List<Fruit> fList = fruitContext.getFruitList();
       assertNotNull(fList);
       assertEquals(1, fList.size());
@@ -46,11 +48,35 @@
       assertEquals(2, f0.textList.size());
       assertEquals("hello", f0.textList.get(0));
       assertEquals("world", f0.textList.get(1));
+      
     } catch (Exception je) {
       StatusPrinter.print(fruitContext);
       throw je;
     }
   }
   
+  @Test
+  public void nestedCollection() throws Exception {
+      try {
+          simpleConfigurator.doConfigure(IMPLCIT_DIR + "nestedComponentCollection.xml");
+      
+      List<Fruit> fList = fruitContext.getFruitList();
+      assertNotNull(fList);
+      assertEquals(1, fList.size());
+      
+      Fruit f0 = fList.get(0);
+      assertEquals(2, f0.cakeList.size());
+      
+      Cake cakeA = f0.cakeList.get(0);
+      assertEquals("A", cakeA.getType());
+      
+      Cake cakeB = f0.cakeList.get(1);
+      assertEquals("B", cakeB.getType());
+      
+    } catch (Exception je) {
+      StatusPrinter.print(fruitContext);
+      throw je;
+    }
+  }
   
 }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/PackageTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/implicitAction/PackageTest.java	Wed Mar  5 14:31:06 2008
@@ -9,6 +9,7 @@
  */
 package ch.qos.logback.core.joran.implicitAction;
 
+import junit.framework.JUnit4TestAdapter;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -17,7 +18,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(SimplePropertyIATest.class);
+    suite.addTest(new JUnit4TestAdapter(ImplicitActionTest.class));
     return suite;
   }
 }



More information about the logback-dev mailing list