You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/01/02 22:54:33 UTC

svn commit: r895300 - in /incubator/wookie/trunk: src-tests/org/apache/wookie/tests/functional/ src/org/apache/wookie/controller/ widgets/localetest/ widgets/localetest/locales/en-gb-yorks/ widgets/localetest/locales/en/

Author: scottbw
Date: Sat Jan  2 21:54:33 2010
New Revision: 895300

URL: http://svn.apache.org/viewvc?rev=895300&view=rev
Log:
More localization test improvements, plus fallback behaviour for start files in rare cases (e.g. no matching localized version and no non-localized default version)

Added:
    incubator/wookie/trunk/widgets/localetest/index.htm
    incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/
    incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/index.htm
    incubator/wookie/trunk/widgets/localetest/locales/en/test.txt
Modified:
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java
    incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java?rev=895300&r1=895299&r2=895300&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java Sat Jan  2 21:54:33 2010
@@ -52,6 +52,25 @@
 	}
 	
 	@Test
+	// Tests if specifying "early modern french" locale returns standard FR start file
+	public void getGracefulLocalizedInstance(){
+	    try {
+	        HttpClient client = new HttpClient();
+	        PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+	        post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+LOCALIZED_WIDGET+"&userid=localetest1b&shareddatakey=localetest1b&locale=fr-1694acad");
+	        client.executeMethod(post);
+	        int code = post.getStatusCode();
+	        assertEquals(201,code);
+	        assertTrue(post.getResponseBodyAsString().contains("locales/fr/index.htm"));
+	        post.releaseConnection();
+	    }
+	    catch (Exception e) {
+	    	e.printStackTrace();
+	    	fail("post failed");
+	    }		
+	}
+	
+	@Test
 	public void getNonLocalizedInstance(){
 	    try {
 	        HttpClient client = new HttpClient();
@@ -62,6 +81,7 @@
 	        assertEquals(201,code);
 	        assertFalse(post.getResponseBodyAsString().contains("locales/fr/index.htm"));
 	        assertFalse(post.getResponseBodyAsString().contains("locales/en/index.htm"));
+	        assertTrue(post.getResponseBodyAsString().contains("index.htm"));
 	        post.releaseConnection();
 	    }
 	    catch (Exception e) {

Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=895300&r1=895299&r2=895300&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java Sat Jan  2 21:54:33 2010
@@ -275,7 +275,13 @@
 	 */
 	protected static String getUrl(HttpServletRequest request, WidgetInstance instance) throws IOException{
 		String url = "";
+		
 		StartFile sf = (StartFile) LocalizationUtils.getLocalizedElement(StartFile.findByValue("widget", instance.getWidget()), new String[]{instance.getLang()});
+		// Try default locale if no appropriate localization found
+		if (sf == null) sf = (StartFile) LocalizationUtils.getLocalizedElement(StartFile.findByValue("widget", instance.getWidget()), null);
+		// No start file found, so throw an exception
+		if (sf == null) throw new IOException("No start file located for widget "+instance.getWidget().getGuid());
+		
 		URL urlWidget =  new URL(request.getScheme() ,
 				request.getServerName() ,
 				request.getServerPort() , sf.getUrl());

Added: incubator/wookie/trunk/widgets/localetest/index.htm
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/index.htm?rev=895300&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/index.htm (added)
+++ incubator/wookie/trunk/widgets/localetest/index.htm Sat Jan  2 21:54:33 2010
@@ -0,0 +1,3 @@
+<p>Hello World! (default, not localized version)</p>
+
+<p><img src="Images/test.png"/></p>
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/index.htm
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/index.htm?rev=895300&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/index.htm (added)
+++ incubator/wookie/trunk/widgets/localetest/locales/en-gb-yorks/index.htm Sat Jan  2 21:54:33 2010
@@ -0,0 +1,3 @@
+<p>Ayup World!</p>
+
+<p><img src="Images/test.png"/></p>
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/localetest/locales/en/test.txt
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/en/test.txt?rev=895300&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/locales/en/test.txt (added)
+++ incubator/wookie/trunk/widgets/localetest/locales/en/test.txt Sat Jan  2 21:54:33 2010
@@ -0,0 +1 @@
+test
\ No newline at end of file