]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix typo preventing StreamVariable cleanup (#9171)
authorLeif Åstrand <leif@vaadin.com>
Wed, 25 Jul 2012 12:43:44 +0000 (12:43 +0000)
committerLeif Åstrand <leif@vaadin.com>
Wed, 25 Jul 2012 12:43:44 +0000 (12:43 +0000)
svn changeset:24025/svn branch:6.8

src/com/vaadin/terminal/gwt/server/CommunicationManager.java
tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java [new file with mode: 0644]

index 9c67a03bb346cec2697fd54719d19ad1d00ae71f..9f6e0a8aaaff5e8e629a8b3f2812df057b681d54 100644 (file)
@@ -233,8 +233,8 @@ public class CommunicationManager extends AbstractCommunicationManager {
         String variableName = parts[1];
         String paintableId = parts[0];
 
-        StreamVariable streamVariable = pidToNameToStreamVariable.get(
-                paintableId).get(variableName);
+        StreamVariable streamVariable = getStreamVariable(paintableId,
+                variableName);
         String secKey = streamVariableToSeckey.get(streamVariable);
         if (secKey.equals(parts[2])) {
 
@@ -262,6 +262,28 @@ public class CommunicationManager extends AbstractCommunicationManager {
 
     }
 
+    /**
+     * Gets a stream variable based on paintable id and variable name. Returns
+     * <code>null</code> if no matching variable has been registered.
+     * 
+     * @param paintableId
+     *            id of paintable to get variable for
+     * @param variableName
+     *            name of the stream variable
+     * @return the corresponding stream variable, or <code>null</code> if not
+     *         found
+     */
+    public StreamVariable getStreamVariable(String paintableId,
+            String variableName) {
+        Map<String, StreamVariable> nameToStreamVariable = pidToNameToStreamVariable
+                .get(paintableId);
+        if (nameToStreamVariable == null) {
+            return null;
+        }
+        StreamVariable streamVariable = nameToStreamVariable.get(variableName);
+        return streamVariable;
+    }
+
     /**
      * Handles UIDL request
      * 
@@ -359,7 +381,7 @@ public class CommunicationManager extends AbstractCommunicationManager {
     private Map<StreamVariable, String> streamVariableToSeckey;
 
     @Override
-    String getStreamVariableTargetUrl(VariableOwner owner, String name,
+    public String getStreamVariableTargetUrl(VariableOwner owner, String name,
             StreamVariable value) {
         /*
          * We will use the same APP/* URI space as ApplicationResources but
@@ -402,10 +424,10 @@ public class CommunicationManager extends AbstractCommunicationManager {
     }
 
     @Override
-    protected void cleanStreamVariable(VariableOwner owner, String name) {
+    public void cleanStreamVariable(VariableOwner owner, String name) {
         Map<String, StreamVariable> nameToStreamVar = pidToNameToStreamVariable
                 .get(getPaintableId((Paintable) owner));
-        nameToStreamVar.remove("name");
+        nameToStreamVar.remove(name);
         if (nameToStreamVar.isEmpty()) {
             pidToNameToStreamVariable.remove(getPaintableId((Paintable) owner));
         }
diff --git a/tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java b/tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java
new file mode 100644 (file)
index 0000000..7e9aefc
--- /dev/null
@@ -0,0 +1,57 @@
+package com.vaadin.tests.server;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.gwt.server.CommunicationManager;
+import com.vaadin.ui.Upload;
+
+public class TestStreamVariableMapping extends TestCase {
+    private static final String variableName = "myName";
+
+    private Upload owner;
+    private StreamVariable streamVariable;
+
+    private CommunicationManager cm;
+
+    @Override
+    protected void setUp() throws Exception {
+        owner = new Upload();
+        streamVariable = EasyMock.createMock(StreamVariable.class);
+        cm = createCommunicationManager();
+
+        super.setUp();
+    }
+
+    public void testAddStreamVariable() {
+        String targetUrl = cm.getStreamVariableTargetUrl(owner, variableName,
+                streamVariable);
+        assertTrue(targetUrl.startsWith("app://APP/UPLOAD/PID0/myName/"));
+
+        StreamVariable streamVariable2 = cm.getStreamVariable(
+                cm.getPaintableId(owner), variableName);
+        assertSame(streamVariable, streamVariable2);
+    }
+
+    public void testRemoverVariable() {
+        cm.getStreamVariableTargetUrl(owner, variableName, streamVariable);
+        assertNotNull(cm.getStreamVariable(cm.getPaintableId(owner),
+                variableName));
+
+        cm.cleanStreamVariable(owner, variableName);
+        assertNull(cm.getStreamVariable(cm.getPaintableId(owner), variableName));
+    }
+
+    private CommunicationManager createCommunicationManager() {
+        return new CommunicationManager(new Application() {
+            @Override
+            public void init() {
+                // TODO Auto-generated method stub
+            }
+        });
+    }
+
+}