labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r740983 - in /labs/magma/trunk: foundation-i18n/src/main/java/org/apache/magma/i18n/ foundation-i18n/src/test/java/org/apache/magma/i18n/ foundation-website/src/test/java/org/apache/magma/website/templating/ foundation-website/src/test/java...
Date Thu, 05 Feb 2009 03:07:26 GMT
Author: simoneg
Date: Thu Feb  5 03:07:26 2009
New Revision: 740983

URL: http://svn.apache.org/viewvc?rev=740983&view=rev
Log:
LABS-236 : i18n should not rely on last segment being in the context, check that producers
are contextualized properly also when in template

Added:
    labs/magma/trunk/foundation-website/src/test/resources/META-INF/
    labs/magma/trunk/foundation-website/src/test/resources/META-INF/messages.properties
Modified:
    labs/magma/trunk/foundation-i18n/src/main/java/org/apache/magma/i18n/ContextMatrix.java
    labs/magma/trunk/foundation-i18n/src/test/java/org/apache/magma/i18n/MatchingTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/FakeHtmlProducer.java

Modified: labs/magma/trunk/foundation-i18n/src/main/java/org/apache/magma/i18n/ContextMatrix.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-i18n/src/main/java/org/apache/magma/i18n/ContextMatrix.java?rev=740983&r1=740982&r2=740983&view=diff
==============================================================================
--- labs/magma/trunk/foundation-i18n/src/main/java/org/apache/magma/i18n/ContextMatrix.java
(original)
+++ labs/magma/trunk/foundation-i18n/src/main/java/org/apache/magma/i18n/ContextMatrix.java
Thu Feb  5 03:07:26 2009
@@ -56,6 +56,7 @@
 	 */
 	public int getScore(Stack<ContextElement> mc) {
 		//int maxscore = (mc.size() * (mc.size() + 1)) / 2;
+		if (parts.length == 1) return 0;
 		int total = 0;
 		int upto = 0;
 		int pos = 0;
@@ -67,7 +68,7 @@
 					if (parts[upto].equalsIgnoreCase(seg)) {
 						upto++;
 						total += pos;
-						if (upto == parts.length) return total;
+						if (upto == parts.length - 1) return total;
 					}
 				} else {
 					String[] segs = ((I18nMultiSegmentContextElement)ele).getI18nSegments();
@@ -76,13 +77,13 @@
 						if (parts[upto].equalsIgnoreCase(seg)) {
 							upto++;
 							total += pos;
-							if (upto == parts.length) return total;
+							if (upto == parts.length - 1) return total;
 						}						
 					}
 				}
 			}
 		}
-		return 0;
+		return -1;
 	}
 
 	/**

Modified: labs/magma/trunk/foundation-i18n/src/test/java/org/apache/magma/i18n/MatchingTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-i18n/src/test/java/org/apache/magma/i18n/MatchingTest.java?rev=740983&r1=740982&r2=740983&view=diff
==============================================================================
--- labs/magma/trunk/foundation-i18n/src/test/java/org/apache/magma/i18n/MatchingTest.java
(original)
+++ labs/magma/trunk/foundation-i18n/src/test/java/org/apache/magma/i18n/MatchingTest.java
Thu Feb  5 03:07:26 2009
@@ -15,45 +15,39 @@
 	@SuppressWarnings("deprecation")
 	@After
 	public void cleanupRunningContext() {
-		SubRunningContext context = RunningContext.get();
-		while(context.size() > 0) {
-			context.pop();
-		}
+		RunningContext.cleanup();
 	}
 	
 	@Test
 	public void simpleCompleteMatching() throws Exception {
 		SubRunningContext mc = RunningContext.get();
 		mc.push(getClass());
-		mc.push("test");
 		
 		ContextMatrix cm = new ContextMatrix(getClass().getSimpleName() + ".test", "test");
 		assertThat(cm.getMainDiscriminator(), equalTo("test"));
 		
 		int score = cm.getScore(mc);
-		assertThat(score, equalTo(3));
+		assertThat(score, equalTo(1));
 	}
 
 	@Test
 	public void simplePartialMatching() throws Exception {
 		SubRunningContext mc = RunningContext.get();
 		mc.push(getClass());
-		mc.push("test");
 		
 		ContextMatrix cm = new ContextMatrix("test", "test");
 		int score = cm.getScore(mc);
-		assertTrue("Expected a match", score > 0);		
+		assertTrue("Expected a match", score > -1);		
 	}
 	
 	@Test
 	public void simpleNotMatching() throws Exception {
 		SubRunningContext mc = RunningContext.get();
-		mc.push("test");
 		
 		ContextMatrix cm = new ContextMatrix(getClass().getSimpleName() + ".test", "test");
 		
 		int score = cm.getScore(mc);
-		assertThat(score, equalTo(0));		
+		assertThat(score, equalTo(-1));		
 	}
 	
 	@Test
@@ -61,12 +55,11 @@
 		SubRunningContext mc = RunningContext.get();
 		mc.push("testingthejump");
 		mc.push(getClass());
-		mc.push("test");
 		
 		ContextMatrix cm = new ContextMatrix("testingthejump.test", "test");
 		
 		int score = cm.getScore(mc);
-		assertTrue("Expected a match", score > 0);		
+		assertTrue("Expected a match", score > -1);		
 	}
 	
 	@Test
@@ -74,7 +67,6 @@
 		SubRunningContext mc = RunningContext.get();
 		mc.push("testingthejump");
 		mc.push(getClass());
-		mc.push("test");
 		
 		ContextMatrix cm1 = new ContextMatrix("testingthejump.test", "test");
 		int score1 = cm1.getScore(mc);
@@ -96,11 +88,10 @@
 		mc.push("field2");
 		mc.push("field2");
 		mc.push("field2");
-		mc.push("key");
 		
-		ContextMatrix cm1 = new ContextMatrix("UserBean.field2", "key");
+		ContextMatrix cm1 = new ContextMatrix("UserBean.field2.key", "key");
 		int score1 = cm1.getScore(mc);
-		ContextMatrix cm2 = new ContextMatrix("UserBean.field1", "key");
+		ContextMatrix cm2 = new ContextMatrix("UserBean.field1.key", "key");
 		int score2 = cm2.getScore(mc);
 		assertTrue(score1 + " is not > than " + score2, score1 > score2);		
 	}

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java?rev=740983&r1=740982&r2=740983&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
Thu Feb  5 03:07:26 2009
@@ -54,6 +54,24 @@
 		assertStructure(def.out.toString(), "<div id=\"zoneMain", "ConvertedSessionHandler.doSetUser]",
"<div id=\"zoneSide", "AuxiliaryWebHandler.doAuxSearch]", "AuxiliaryWebHandler.doAuxPoll]");
 	}
 
+
+	// See bug LABS-236
+	@Test
+	public void simpleTemplateI18n() throws Exception {
+		DefaultExpectations def = new DefaultExpectations() {{
+			one(session).setAttribute("user", "Simone");
+			one(session).getAttribute("user"); will(returnValue("Massimo"));						
+		}};
+		UnitTestDispatch disp = new UnitTestDispatch();
+		disp.setTemplate(new SimpleTemplate());
+		def.disp = disp;
+		def.setupMinimal("/testSession/setUser");
+		def.start();
+		
+		assertStructure(def.out.toString(), "<div id=\"zoneMain", "ConvertedSessionHandler.doSetUser]i18n",
"<div id=\"zoneSide", "AuxiliaryWebHandler.doAuxSearch]", "AuxiliaryWebHandler.doAuxPoll]test
message");
+	}
+	
+	
 	@Test
 	public void notReusingTemplate() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/FakeHtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/FakeHtmlProducer.java?rev=740983&r1=740982&r2=740983&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/FakeHtmlProducer.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/FakeHtmlProducer.java
Thu Feb  5 03:07:26 2009
@@ -17,6 +17,7 @@
 package org.apache.magma.website.teststuff;
 
 import org.apache.magma.basics.MagmaException;
+import org.apache.magma.i18n.I18nRenderingHelper;
 import org.apache.magma.website.Head;
 import org.apache.magma.website.HtmlProducer;
 import org.apache.magma.website.producers.ParametrizableHtmlProducerBase;
@@ -49,6 +50,8 @@
 			str += ".";
 			str += getCreatingMethod().getName();
 			str += "]";
+			I18nRenderingHelper i18nh = (I18nRenderingHelper) getParameters().getParameters().get("i18n");
+			str += i18nh.tr("test message");
 			stream.write(str.getBytes());
 		} catch (IOException e) {
 			throw new MagmaException(e, "Error writing output");

Added: labs/magma/trunk/foundation-website/src/test/resources/META-INF/messages.properties
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/resources/META-INF/messages.properties?rev=740983&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/resources/META-INF/messages.properties (added)
+++ labs/magma/trunk/foundation-website/src/test/resources/META-INF/messages.properties Thu
Feb  5 03:07:26 2009
@@ -0,0 +1 @@
+convertedsessionhandler.testmessage=i18n
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message