shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhor...@apache.org
Subject svn commit: r1149261 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
Date Thu, 21 Jul 2011 16:20:38 GMT
Author: zhoresh
Date: Thu Jul 21 16:20:35 2011
New Revision: 1149261

URL: http://svn.apache.org/viewvc?rev=1149261&view=rev
Log:
Keep the order of user prefs | https://reviews.apache.org/r/1156/

Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java?rev=1149261&r1=1149260&r2=1149261&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/GadgetSpec.java
Thu Jul 21 16:20:35 2011
@@ -72,8 +72,9 @@ public class GadgetSpec {
     setAttribute(ATTR_SPECIFICATION_VERSION,doc.getAttribute(ATTR_SPECIFICATION_VERSION));
 
     ModulePrefs modulePrefs = null;
-    Map<String,UserPref> prefsBuilder = Maps.newHashMap();
-    Map<String, List<Element>> views = Maps.newHashMap();
+    // Lets try keep order of user prefs and views
+    Map<String,UserPref> prefsBuilder = Maps.newLinkedHashMap();
+    Map<String, List<Element>> views = Maps.newLinkedHashMap();
     for (int i = 0, j = children.getLength(); i < j; ++i) {
       Node child = children.item(i);
       if (!(child instanceof Element)) {

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java?rev=1149261&r1=1149260&r2=1149261&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
Thu Jul 21 16:20:35 2011
@@ -27,6 +27,9 @@ import org.apache.shindig.gadgets.variab
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.Collection;
+import java.util.Iterator;
+
 public class GadgetSpecTest extends Assert {
   private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
 
@@ -44,6 +47,26 @@ public class GadgetSpecTest extends Asse
     assertEquals("Hello!", spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
   }
 
+  @Test
+  public void testUserPrefsOrder() throws Exception {
+    String xml = "<Module>" +
+                 "<ModulePrefs title=\"title\"/>" +
+                 "<UserPref name=\"a\" datatype=\"string\"/>" +
+                 "<UserPref name=\"z\" datatype=\"string\"/>" +
+                 "<UserPref name=\"b\" datatype=\"string\"/>" +
+                 "<UserPref name=\"y\" datatype=\"string\"/>" +
+                 "<Content type=\"html\">Hello!</Content>" +
+                 "</Module>";
+    GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
+    assertEquals("title", spec.getModulePrefs().getTitle());
+    Collection<UserPref> prefs = spec.getUserPrefs().values();
+    Iterator<UserPref> iter = prefs.iterator();
+    assertEquals("a", iter.next().getName());
+    assertEquals("z", iter.next().getName());
+    assertEquals("b", iter.next().getName());
+    assertEquals("y", iter.next().getName());
+    assertEquals("Hello!", spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
+  }
 
   @Test
   public void testAlternativeConstructor() throws Exception {



Mime
View raw message