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
            }
        });
    }

}

@@ -166,16 +166,59 @@
 riable;%0A
+import com.vaadin.terminal.WrappedRequest;%0A
 import c
@@ -269,16 +269,43 @@
 anager;%0A
+import com.vaadin.ui.Root;%0A
 import c
@@ -622,28 +622,519 @@
     
-owner = new Upload()
+final Application application = new Application();%0A        final Root root = new Root() %7B%0A            @Override%0A            protected void init(WrappedRequest request) %7B%0A                // TODO Auto-generated method stub%0A%0A            %7D%0A%0A            @Override%0A            public Application getApplication() %7B%0A                return application;%0A            %7D%0A        %7D;%0A        owner = new Upload() %7B%0A            @Override%0A            public Root getRoot() %7B%0A                return root;%0A            %7D%0A        %7D
 ;%0A  
@@ -1488,12 +1488,12 @@
 OAD/
-PID0
+-1/1
 /myN
@@ -1581,39 +1581,37 @@
         
-cm.getPaintableId(owner
+owner.getConnectorId(
 ), varia
@@ -1812,32 +1812,49 @@
 assertNotNull(cm
+%0A                
 .getStreamVariab
@@ -1860,49 +1860,31 @@
 ble(
-cm.getPaintableId(owner),%0A               
+owner.getConnectorId(),
  var
@@ -1994,31 +1994,29 @@
 ble(
-cm.getPaintableId(owner
+owner.getConnectorId(
 ), v

Update test to work with Vaadin 7