[Schmitzm-commits] r1428 - in trunk/schmitzm-core/src: main/java/de/schmitzm/data test/java/de/schmitzm test/java/de/schmitzm/lang test/resources

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 27 13:03:01 CET 2011


Author: alfonx
Date: 2011-01-27 13:03:01 +0100 (Thu, 27 Jan 2011)
New Revision: 1428

Added:
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LimitedHashMapTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/ResourceProviderTest.java
   trunk/schmitzm-core/src/test/resources/ResourceProviderOperator.cfg
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/data/ObjectStructure.java
Log:


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/data/ObjectStructure.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/data/ObjectStructure.java	2011-01-27 12:00:52 UTC (rev 1427)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/data/ObjectStructure.java	2011-01-27 12:03:01 UTC (rev 1428)
@@ -32,6 +32,9 @@
 import java.util.Enumeration;
 
 import de.schmitzm.data.property.ListProperty;
+import de.schmitzm.data.property.Properties;
+import de.schmitzm.data.property.Property;
+import de.schmitzm.data.property.PropertySet;
 import de.schmitzm.data.property.ScalarProperty;
 
 /**

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-01-27 12:00:52 UTC (rev 1427)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-01-27 12:03:01 UTC (rev 1428)
@@ -0,0 +1,94 @@
+package de.schmitzm.lang;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Enumeration;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+public class LangUtilTest extends TestingClass {
+
+	@Test
+	public void testOnlyZeros() {
+		assertTrue(LangUtil.onlyZero("000000"));
+		assertTrue(LangUtil.onlyZero("0.0"));
+		assertTrue(LangUtil.onlyZero("0,0"));
+		assertTrue(LangUtil.onlyZero("0"));
+		assertTrue(LangUtil.onlyZero(""));
+		assertTrue(LangUtil.onlyZero("000,000,0.0"));
+		assertFalse(LangUtil.onlyZero("  0,02"));
+		assertFalse(LangUtil.onlyZero(" 20,0"));
+		assertFalse(LangUtil.onlyZero(" 00200,0"));
+	}
+
+	@Test
+	public void testParseStringDefaultFalse() {
+		assertTrue(LangUtil.parseStringDefaultFalse("y"));
+		assertTrue(LangUtil.parseStringDefaultFalse("Yes"));
+		assertTrue(LangUtil.parseStringDefaultFalse(" JA BITTE !"));
+		assertTrue(LangUtil.parseStringDefaultFalse("j"));
+		assertTrue(LangUtil.parseStringDefaultFalse("1"));
+
+		assertFalse(LangUtil.parseStringDefaultFalse(null));
+		assertFalse(LangUtil.parseStringDefaultFalse("asdas"));
+		assertFalse(LangUtil.parseStringDefaultFalse("23"));
+		assertFalse(LangUtil.parseStringDefaultFalse("-2"));
+	}
+
+	@Test
+	public void testParseStringDefaultTrue() {
+		assertTrue(LangUtil.parseStringDefaultTrue("y"));
+		assertTrue(LangUtil.parseStringDefaultTrue("j"));
+		assertTrue(LangUtil.parseStringDefaultTrue("1"));
+
+		assertFalse(LangUtil.parseStringDefaultTrue("n"));
+		assertFalse(LangUtil.parseStringDefaultTrue("0"));
+		assertFalse(LangUtil.parseStringDefaultTrue("no"));
+		assertFalse(LangUtil.parseStringDefaultTrue(" NO "));
+
+		assertTrue(LangUtil.parseStringDefaultTrue(null));
+		assertTrue(LangUtil.parseStringDefaultTrue("asdas"));
+		assertTrue(LangUtil.parseStringDefaultTrue("23"));
+		assertTrue(LangUtil.parseStringDefaultTrue("-2"));
+	}
+
+	@Test
+	public void testRoundDoubleIntIntArray() {
+		Double val = 0.01735357917570499;
+		int digits = 3;
+
+		for (int i = 0; i < 10; i++) {
+			val = LangUtil.round(val, digits);
+			assertEquals("0.017", new Double(val).toString());
+		}
+	}
+
+	@Test
+	public void testTrimNewlines() {
+		assertEquals("p12", LangUtil.trimNewlines("\np12\n"));
+		assertEquals("p12", LangUtil.trimNewlines("p12\n"));
+		assertEquals("p12", LangUtil.trimNewlines("p12"));
+		assertEquals("", LangUtil.trimNewlines(""));
+		assertEquals(null, LangUtil.trimNewlines(null));
+	}
+
+	@Test
+	public void testInitializeDefaultLogger() {
+		Logger.getRootLogger().removeAllAppenders();
+		LangUtil.initializeDefaultLogger(null, null);
+		assertEquals(Level.DEBUG, Logger.getRootLogger().getLevel());
+		Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();
+		assertNotNull("Has a first appender!", allAppenders.nextElement());
+		assertFalse("More than one appender?!", allAppenders.hasMoreElements());
+
+		assertEquals("Reduced Logging-Level for libs not applied?!",
+				Level.WARN, Logger.getLogger("org.hibernate").getLevel());
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LimitedHashMapTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LimitedHashMapTest.java	2011-01-27 12:00:52 UTC (rev 1427)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LimitedHashMapTest.java	2011-01-27 12:03:01 UTC (rev 1428)
@@ -0,0 +1,75 @@
+package de.schmitzm.lang;
+
+import static org.junit.Assert.assertEquals;
+
+import java.awt.GraphicsEnvironment;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+public class LimitedHashMapTest extends TestingClass {
+  private static Logger log = Logger.getLogger(LimitedHashMapTest.class);
+  /** If tests are run on a system with head, we may theoretically open dialgs, frames etc. **/
+  boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+	
+
+  @Test
+  public void testLimitedHashMap() throws IOException, InterruptedException {
+    LimitedHashMap<Integer, String> lhm = new LimitedHashMap<Integer, String>(5, LimitedHashMap.TRUNC_METHOD.OLDEST_GET);
+
+    // Initialisierung pruefen
+    assertEquals("Map muss leer sein.", 0, lhm.size());
+    assertEquals("Oldest list muss leer sein.", 0, lhm.oldestKeys.size());
+
+    // Elemente einfuegen bis Map voll ist
+    for (int i=1; i<=lhm.getMaxLoad(); i++) {
+      lhm.put(i, "Element "+i);
+      assertEquals("Map muss "+i+" Elemente haben.", i, lhm.size());
+      assertEquals("Oldest list "+i+" Elemente haben.", i, lhm.oldestKeys.size());
+    }
+    debugLimitedHashMap(lhm);
+
+    // Weiteres Element hinzufuegen
+    lhm.put(6, "Element "+6);
+    debugLimitedHashMap(lhm);
+    // Map muss weiterhin 5 Elemente haben
+    assertEquals("Map muss 5 Elemente haben.", 5, lhm.size());
+    assertEquals("Oldest list 5 Elemente haben.", 5, lhm.oldestKeys.size());
+    switch ( lhm.getTruncMethod() ) {
+      case OLDEST_PUT:
+        // 1 muesste geloescht worden sein
+        assertEquals("Erstes Element in Oldest-List muss 2 sein.", 2, (int)lhm.oldestKeys.firstElement());
+        // 6 muesste letztes Element sein
+        assertEquals("Letztes Element in Oldest-List muss 6 sein.", 6, (int)lhm.oldestKeys.lastElement());
+        // 5 muesste vorletztes Element sein
+        assertEquals("Vorletztes Element in Oldest-List muss 5 sein.", 5, (int)lhm.oldestKeys.elementAt(lhm.size()-2));
+        break;
+      case OLDEST_GET:
+        // 1 muesste geloescht worden sein
+        assertEquals("Erstes Element in Oldest-List muss 2 sein.", 2, (int)lhm.oldestKeys.firstElement());
+        // 6 muesste letztes Element sein
+        assertEquals("Letztes Element in Oldest-List muss 6 sein.", 6, (int)lhm.oldestKeys.lastElement());
+        // 4 muesste vorletztes Element sein
+        assertEquals("Vorletztes Element in Oldest-List muss 5 sein.", 5, (int)lhm.oldestKeys.elementAt(lhm.size()-2));
+        break;
+    }
+    
+    lhm.get(7); // noch nicht drin, nichts darf sich aendern
+    debugLimitedHashMap(lhm);
+    lhm.get(6); // 6 muss ans Ende der Oldest-List rutschen
+    debugLimitedHashMap(lhm);
+    lhm.get(4); // 4 muss ans Ende der Oldest-List rutschen
+    debugLimitedHashMap(lhm);
+    
+    lhm.put(7, "Element "+7);
+    debugLimitedHashMap(lhm);
+  }
+  
+  private void debugLimitedHashMap(LimitedHashMap<?, ?> lhm) {
+    System.out.println("Elemente:   "+LangUtil.listObjects(", ", false, lhm.values()));
+    System.out.println("OldestList: "+LangUtil.listObjects(", ", false, lhm.oldestKeys));
+  }
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LimitedHashMapTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/ResourceProviderTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/ResourceProviderTest.java	2011-01-27 12:00:52 UTC (rev 1427)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/ResourceProviderTest.java	2011-01-27 12:03:01 UTC (rev 1428)
@@ -0,0 +1,120 @@
+package de.schmitzm.lang;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringWriter;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.WriterAppender;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+public class ResourceProviderTest extends TestingClass {
+
+    @Test
+    @Ignore
+    public void testResourceProviderOperator() throws Exception {
+      ResourceProviderOperator.main( new String[] {
+              "-s",
+              "src_junit",
+              "-b",
+              "schmitzm.lang.resource.locales.TestLangResourceBundle;schmitzm.lang.resource.locales.TestLangResourceBundle2",
+      });
+    }
+  
+	@Test
+	public void testGetWrongKeyLogging() {
+		Logger.getRootLogger().removeAllAppenders();
+		StringWriter sw = new StringWriter();
+		Logger.getRootLogger().addAppender(
+				new WriterAppender(new SimpleLayout(), sw));
+
+		assertNotNull(LangUtil.RESOURCE
+				.getObject("OperationTree.err.BracketsNotClosed"));
+		assertTrue("Expect no loggin messages when asking for a corrct key", sw
+				.getBuffer().toString().isEmpty());
+
+		assertNull(LangUtil.RESOURCE.getObject("WeihnachtenIstSch"));
+
+		System.out.println(sw.getBuffer().toString());
+
+		assertFalse("Expect some loggin output", sw.getBuffer().toString()
+				.isEmpty());
+		assertTrue(
+				"Expect the wrong keyname in the logger when asking for a wrong key",
+				sw.getBuffer().toString().contains("WeihnachtenIstSch"));
+	}
+
+	/**
+	 * Martin, dieser Test failed und zeigt einen Bug. Deshalb ist er
+	 * deaktiviert.
+	 */
+	@Test
+	public void testGetStringForSpecificLocale_WhichIsTheDefault() {
+
+		// English ist die default Locale und Deutsch ist als "normale" Sprache
+		// dabei:
+		{
+			Set<Locale> availableLocalesWithRoot = LangUtil.RESOURCE
+					.getAvailableLocales(true);
+			assertTrue(availableLocalesWithRoot.contains(new Locale("de")));
+			assertTrue(availableLocalesWithRoot.contains(new Locale("en")));
+
+			Set<Locale> availableLocalesWithoutRoot = LangUtil.RESOURCE
+					.getAvailableLocales(false);
+			assertTrue(availableLocalesWithoutRoot.contains(new Locale("de")));
+			assertFalse(availableLocalesWithoutRoot.contains(new Locale("en")));
+		}
+
+		// Strings können in explizit angegebenen Sprachen angefragt werden
+		String integerDe = LangUtil.RESOURCE.getString("OperationTree.Integer",
+				new Locale("de"));
+		assertEquals(
+				"Die auf Deutsch angeforderte Übersetzung muss 'Ganzzahl' zurückliefern",
+				"Ganzzahl", integerDe);
+
+		// Wenn ein String in der Sprache des Root-Locale angefragt wird, soll
+		// NICHT die Übersetzung in der Default Localen zurückgeliefert werden,
+		// sondern in der angeforderten Sprache:
+		Locale.setDefault(new Locale("de"));
+
+		String integerEn = LangUtil.RESOURCE.getString("OperationTree.Integer",
+				new Locale("en"));
+		assertEquals(
+				"Die auf English angeforderte Übersetzung muss 'Integer' zurückliefern",
+				"Integer", integerEn);
+	}
+
+	@Test
+	public void testCreatePropertyFile() {
+		String before = "A\nB\nC";
+		String after = before.replaceAll("\\n", "\\\\n");
+		assertFalse(before.equals(after));
+	}
+
+	@Test
+	public void replaceWithDollarSignText() {
+		String orig = LangUtil.RESOURCE
+				.getString("OperationTree.err.IllegalCharacter");
+		String[] repl = new String[] { "$", "Numerisch" };
+
+		String translated = LangUtil.RESOURCE.getString(
+				"OperationTree.err.IllegalCharacter", repl);
+
+		System.out.println("Original:     " + orig);
+		System.out.println("Replacements: "
+				+ LangUtil.stringConcatWithSep(", ", repl));
+		System.out.println("Replaced:     " + translated);
+
+		assertEquals("Ungültiges Zeichen '$' (Numerisch erwartet)", translated);
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/ResourceProviderTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/resources/ResourceProviderOperator.cfg
===================================================================
--- trunk/schmitzm-core/src/test/resources/ResourceProviderOperator.cfg	2011-01-27 12:00:52 UTC (rev 1427)
+++ trunk/schmitzm-core/src/test/resources/ResourceProviderOperator.cfg	2011-01-27 12:03:01 UTC (rev 1428)
@@ -0,0 +1,5 @@
+#Configuration for ResourceProviderOperator
+#Mon Nov 15 18:25:27 CET 2010
+resource.bundles.src.root.folder=E:/Arbeit/SCHMITZM/Trunk/src_junit
+resource.bundles=schmitzm.lang.resource.locales.TestLangResourceBundle
+bundle.keys.indicator.prefix=REMOVEME_



More information about the Schmitzm-commits mailing list