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])) {
}
+ /**
+ * 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
*
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
}
@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));
}
--- /dev/null
+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
+ }
+ });
+ }
+
+}