[kune-commits] r1302 - in trunk: . src/main/java/cc/kune/core/client/sitebar/spaces src/main/java/cc/kune/core/client/state src/test/java/cc/kune/core/client/state

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Sun Apr 3 12:41:34 CEST 2011


Author: vjrj_
Date: 2011-04-03 12:41:33 +0200 (Sun, 03 Apr 2011)
New Revision: 1302

Added:
   trunk/src/test/java/cc/kune/core/client/state/StateManagerDefaultTest.java
Removed:
   trunk/src/test/java/cc/kune/core/client/state/StateManagerTest.java
Modified:
   trunk/.classpath
   trunk/pom.xml
   trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java
   trunk/src/main/java/cc/kune/core/client/state/StateManagerDefault.java
Log:
NEW - # 35: Spaces selector integration with login/logout and history 
http://kune.ourproject.org/issues/ticket/35

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2011-04-01 22:07:25 UTC (rev 1301)
+++ trunk/.classpath	2011-04-03 10:41:33 UTC (rev 1302)
@@ -49,7 +49,7 @@
   <classpathentry kind="var" path="M2_REPO/com/google/gwt/gwt-servlet/2.1.1/gwt-servlet-2.1.1.jar" sourcepath="M2_REPO/com/google/gwt/gwt-servlet/2.1.1/gwt-servlet-2.1.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/google/gwt/gwt-user/2.1.1/gwt-user-2.1.1.jar" sourcepath="M2_REPO/com/google/gwt/gwt-user/2.1.1/gwt-user-2.1.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/waveprotocol/gwt-util-src/0.3.0-SNAPSHOT/gwt-util-src-0.3.0-SNAPSHOT.jar"/>
-  <classpathentry kind="var" path="M2_REPO/com/allen_sauer/gwt/voices/gwt-voices/gwt-voices/1.7.0/gwt-voices-1.7.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/com/allen_sauer/gwt/voices/gwt-voices/gwt-voices/2.0.0/gwt-voices-2.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtext/gwtext/2.0.5/gwtext-2.0.5.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtextux/gwtextux/0.4.0.924/gwtextux-0.4.0.924.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-all/0.5/gwtp-all-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-all/0.5/gwtp-all-0.5-sources.jar"/>

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2011-04-01 22:07:25 UTC (rev 1301)
+++ trunk/pom.xml	2011-04-03 10:41:33 UTC (rev 1302)
@@ -284,7 +284,7 @@
     <dependency>
       <groupId>com.allen_sauer.gwt.voices.gwt-voices</groupId>
       <artifactId>gwt-voices</artifactId>
-      <version>1.7.0</version>
+      <version>2.0.0</version>
     </dependency>
     <!-- utilities -->
     <dependency>

Modified: trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java	2011-04-01 22:07:25 UTC (rev 1301)
+++ trunk/src/main/java/cc/kune/core/client/sitebar/spaces/SpaceSelectorPresenter.java	2011-04-03 10:41:33 UTC (rev 1302)
@@ -22,14 +22,12 @@
 import cc.kune.common.client.noti.NotifyLevel;
 import cc.kune.core.client.auth.SignIn;
 import cc.kune.core.client.init.AppStartEvent;
-import cc.kune.core.client.state.HistoryWrapper;
 import cc.kune.core.client.state.Session;
 import cc.kune.core.client.state.SiteTokens;
+import cc.kune.core.client.state.StateManager;
 import cc.kune.core.client.state.TokenUtils;
 import cc.kune.core.client.state.UserSignInEvent;
 import cc.kune.core.client.state.UserSignOutEvent;
-import cc.kune.core.shared.domain.utils.StateToken;
-import cc.kune.core.shared.i18n.I18nTranslationService;
 import cc.kune.gspace.client.WsArmor;
 
 import com.google.gwt.event.dom.client.ClickEvent;
@@ -75,7 +73,6 @@
     private Space currentSpace;
     private String groupToken;
     private String homeToken;
-    private final I18nTranslationService i18n;
     private boolean nextUserSpace;
     private String publicToken;
     private final Session session;
@@ -83,14 +80,13 @@
     private String userToken;
 
     @Inject
-    public SpaceSelectorPresenter(final EventBus eventBus, final SpaceSelectorView view,
-            final SpaceSelectorProxy proxy, final WsArmor armor, final Session session, final Provider<SignIn> sigIn,
-            final I18nTranslationService i18n, final HistoryWrapper history) {
+    public SpaceSelectorPresenter(final EventBus eventBus, final StateManager stateManager,
+            final SpaceSelectorView view, final SpaceSelectorProxy proxy, final WsArmor armor, final Session session,
+            final Provider<SignIn> sigIn) {
         super(eventBus, view, proxy);
         this.armor = armor;
         this.session = session;
         this.signIn = sigIn;
-        this.i18n = i18n;
         nextUserSpace = false;
         homeToken = SiteTokens.HOME;
         userToken = SiteTokens.WAVEINBOX;
@@ -99,41 +95,29 @@
         view.getHomeBtn().addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent event) {
-                gotoTokenIfDifferent(history, homeToken);
+                stateManager.gotoToken(homeToken);
             }
         });
         view.getUserBtn().addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent event) {
-                gotoTokenIfDifferent(history, userToken);
+                stateManager.gotoToken(userToken);
             }
         });
         view.getGroupBtn().addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent event) {
-                gotoTokenIfDifferent(history, groupToken);
-                onGroupSpaceSelect();
+                stateManager.gotoToken(groupToken);
             }
         });
         view.getPublicBtn().addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent event) {
-                gotoTokenIfDifferent(history, publicToken);
-                onPublicSpaceSelect();
+                stateManager.gotoToken(publicToken);
             }
         });
     }
 
-    private void gotoTokenIfDifferent(final HistoryWrapper history, final String token) {
-        if (!history.getToken().equals(token)) {
-            if ((new StateToken(token)).equals(session.getCurrentStateToken())) {
-                history.newItem(token, false);
-            } else {
-                history.newItem(token);
-            }
-        }
-    }
-
     @ProxyEvent
     public void onAppStart(final AppStartEvent event) {
         getView().setHomeBtnDown(false);

Modified: trunk/src/main/java/cc/kune/core/client/state/StateManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/state/StateManagerDefault.java	2011-04-01 22:07:25 UTC (rev 1301)
+++ trunk/src/main/java/cc/kune/core/client/state/StateManagerDefault.java	2011-04-03 10:41:33 UTC (rev 1302)
@@ -181,7 +181,7 @@
             Log.debug("StateManager: on history changed (" + newHistoryToken + ")");
             if (tokenListener == null) {
                 // token is not one of #newgroup #signin #translate ...
-                final String nToken = newHistoryToken.toLowerCase();
+                final String nToken = newHistoryToken != null ? newHistoryToken.toLowerCase() : null;
                 if (tokenMatcher.hasRedirect(nToken)) {
                     final Pair<String, String> redirect = tokenMatcher.getRedirect(nToken);
                     final String firstToken = redirect.getLeft();
@@ -222,6 +222,7 @@
                     onHistoryChanged("");
                     SpaceSelectEvent.fire(eventBus, Space.groupSpace);
                 }
+                // Fire the listener of this #hash token
                 tokenListener.onHistoryToken();
             }
         } else {

Copied: trunk/src/test/java/cc/kune/core/client/state/StateManagerDefaultTest.java (from rev 1301, trunk/src/test/java/cc/kune/core/client/state/StateManagerTest.java)
===================================================================
--- trunk/src/test/java/cc/kune/core/client/state/StateManagerDefaultTest.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/core/client/state/StateManagerDefaultTest.java	2011-04-03 10:41:33 UTC (rev 1302)
@@ -0,0 +1,248 @@
+/*
+ *
+ * Copyright (C) 2007-2011 The kune development team (see CREDITS for details)
+ * This file is part of kune.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package cc.kune.core.client.state;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import cc.kune.common.client.actions.BeforeActionListener;
+import cc.kune.core.client.state.GroupChangedEvent.GroupChangedHandler;
+import cc.kune.core.client.state.StateChangedEvent.StateChangedHandler;
+import cc.kune.core.client.state.ToolChangedEvent.ToolChangedHandler;
+import cc.kune.core.shared.domain.utils.StateToken;
+import cc.kune.core.shared.dto.StateAbstractDTO;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public class StateManagerDefaultTest {
+
+    private static final String HASH = "someUserHash";
+    private BeforeActionListener beforeChangeListener1;
+    private BeforeActionListener beforeChangeListener2;
+    private ContentCache contentProvider;
+    private EventBusTester eventBus;
+    private GroupChangedHandler groupChangeHandler;
+    private HistoryWrapper history;
+    private Session session;
+    private StateAbstractDTO state;
+    private StateChangedHandler stateChangeHandler;
+    private StateManagerDefault stateManager;
+    private TokenMatcher tokenMatcher;
+    private ToolChangedHandler toolChangeHandler;
+
+    @Before
+    public void before() {
+        contentProvider = Mockito.mock(ContentCache.class);
+        session = Mockito.mock(Session.class);
+        history = Mockito.mock(HistoryWrapper.class);
+        tokenMatcher = Mockito.mock(TokenMatcher.class);
+        eventBus = new EventBusTester();
+        stateManager = new StateManagerDefault(contentProvider, session, history, tokenMatcher, eventBus);
+        Mockito.when(session.getUserHash()).thenReturn(HASH);
+        state = Mockito.mock(StateAbstractDTO.class);
+        stateChangeHandler = Mockito.mock(StateChangedHandler.class);
+        groupChangeHandler = Mockito.mock(GroupChangedHandler.class);
+        toolChangeHandler = Mockito.mock(ToolChangedHandler.class);
+        beforeChangeListener1 = Mockito.mock(BeforeActionListener.class);
+        beforeChangeListener2 = Mockito.mock(BeforeActionListener.class);
+        eventBus.addHandler(StateChangedEvent.getType(), stateChangeHandler);
+        eventBus.addHandler(GroupChangedEvent.getType(), groupChangeHandler);
+        eventBus.addHandler(ToolChangedEvent.getType(), toolChangeHandler);
+        // new NotifyUser(null, null);
+    }
+
+    @Test
+    public void changeGroupWithNoTool() {
+        changeState("group1", "group2");
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+    }
+
+    private void changeState(final String... tokens) {
+        for (final String token : tokens) {
+            Mockito.when(state.getStateToken()).thenReturn(new StateToken(token));
+            stateManager.setState(state);
+        }
+    }
+
+    @Test
+    public void changeStateWithDifferentAndGroupsToolsMustFireListener() {
+        changeState("group2.tool1", "group1.tool2");
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group2"));
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("group2", "group1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", "tool2"));
+    }
+
+    @Test
+    public void changeStateWithDifferentGroupsMustFireListener() {
+        changeState("group1.tool1", "group2.tool1");
+        // assertTrue(stateChangeListener.isCalled(2));
+        // assertTrue(groupChangeListener.isCalledWithEquals("", "group1",
+        // "group1", "group2"));
+        // assertTrue(toolChangeListener.isCalledWithEquals("", "tool1"));
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("group1", "group2"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
+
+    }
+
+    @Test
+    public void changeStateWithDifferentToolsMustFireListener() {
+        changeState("group1.tool1", "group1.tool2");
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", "tool2"));
+    }
+
+    @Test
+    public void changeToNoTool() {
+        changeState("group1.tool1", "group1");
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", ""));
+    }
+
+    @Test
+    public void changeToSameToken() {
+        changeState("group1.tool1", "group1.tool1");
+        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
+        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
+        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
+    }
+
+    private String confBeforeStateChangeListeners(final boolean value, final boolean value2) {
+        stateManager.addBeforeStateChangeListener(beforeChangeListener1);
+        stateManager.addBeforeStateChangeListener(beforeChangeListener2);
+        final String newToken = "something";
+        Mockito.when(beforeChangeListener1.beforeAction()).thenReturn(value);
+        Mockito.when(beforeChangeListener2.beforeAction()).thenReturn(value2);
+        return newToken;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void getDefGroup() {
+        stateManager.onHistoryChanged("site.docs");
+        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    public void getWaveToken() {
+        stateManager.onHistoryChanged("example.com/w+abcd/~/conv+root/b+45kg");
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void normalStartLoggedUser() {
+        // When a user enter reload state, also if the application is starting
+        // (and the user was logged)
+        Mockito.when(history.getToken()).thenReturn("");
+        stateManager.reload();
+        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneBeforeStateChangeListenerAddAndRemove() {
+        final String newToken = confBeforeStateChangeListeners(false, false);
+        stateManager.onHistoryChanged(newToken);
+        removeBeforeStateChangeListener();
+        stateManager.onHistoryChanged(newToken);
+        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    @Test
+    public void oneBeforeStateChangeListenerFalseAndResume() {
+        final String token = confBeforeStateChangeListeners(false, true);
+        stateManager.onHistoryChanged(token);
+        Mockito.verify(history, Mockito.never()).newItem(token);
+        removeBeforeStateChangeListener();
+        stateManager.resumeTokenChange();
+        Mockito.verify(history, Mockito.times(1)).newItem(token);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneBeforeStateChangeListenerReturnFalse() {
+        stateManager.onHistoryChanged(confBeforeStateChangeListeners(true, false));
+        Mockito.verify(contentProvider, Mockito.never()).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneBeforeStateChangeListenerReturnFalseWithTwo() {
+        stateManager.onHistoryChanged(confBeforeStateChangeListeners(false, false));
+        Mockito.verify(contentProvider, Mockito.never()).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneBeforeStateChangeListenerReturnTrue() {
+        stateManager.onHistoryChanged(confBeforeStateChangeListeners(true, true));
+        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    private void removeBeforeStateChangeListener() {
+        stateManager.removeBeforeStateChangeListener(beforeChangeListener1);
+        stateManager.removeBeforeStateChangeListener(beforeChangeListener2);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void siteTokenFirstLoadDefContentAndFireListener() {
+        final HistoryTokenCallback listener = Mockito.mock(HistoryTokenCallback.class);
+        final String token = SiteTokens.SIGNIN;
+        stateManager.addSiteToken(token, listener);
+        stateManager.onHistoryChanged(token);
+        Mockito.verify(listener, Mockito.times(1)).onHistoryToken();
+        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
+                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
+    }
+
+    @Test
+    public void siteTokenTest() {
+        final HistoryTokenCallback siteTokenListener = Mockito.mock(HistoryTokenCallback.class);
+        stateManager.addSiteToken("signin", siteTokenListener);
+        stateManager.onHistoryChanged("signIn");
+        Mockito.verify(siteTokenListener, Mockito.times(1)).onHistoryToken();
+    }
+}

Deleted: trunk/src/test/java/cc/kune/core/client/state/StateManagerTest.java
===================================================================
--- trunk/src/test/java/cc/kune/core/client/state/StateManagerTest.java	2011-04-01 22:07:25 UTC (rev 1301)
+++ trunk/src/test/java/cc/kune/core/client/state/StateManagerTest.java	2011-04-03 10:41:33 UTC (rev 1302)
@@ -1,251 +0,0 @@
-/*
- *
- * Copyright (C) 2007-2011 The kune development team (see CREDITS for details)
- * This file is part of kune.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package cc.kune.core.client.state;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import cc.kune.common.client.actions.BeforeActionListener;
-import cc.kune.core.client.sitebar.spaces.SpaceSelectorPresenter;
-import cc.kune.core.client.state.GroupChangedEvent.GroupChangedHandler;
-import cc.kune.core.client.state.StateChangedEvent.StateChangedHandler;
-import cc.kune.core.client.state.ToolChangedEvent.ToolChangedHandler;
-import cc.kune.core.shared.domain.utils.StateToken;
-import cc.kune.core.shared.dto.StateAbstractDTO;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-public class StateManagerTest {
-
-    private static final String HASH = "someUserHash";
-    private BeforeActionListener beforeChangeListener1;
-    private BeforeActionListener beforeChangeListener2;
-    private ContentCache contentProvider;
-    private EventBusTester eventBus;
-    private GroupChangedHandler groupChangeHandler;
-    private HistoryWrapper history;
-    private Session session;
-    private SpaceSelectorPresenter spaceSelector;
-    private StateAbstractDTO state;
-    private StateChangedHandler stateChangeHandler;
-    private StateManagerDefault stateManager;
-    private TokenMatcher tokenMatcher;
-    private ToolChangedHandler toolChangeHandler;
-
-    @Before
-    public void before() {
-        contentProvider = Mockito.mock(ContentCache.class);
-        session = Mockito.mock(Session.class);
-        history = Mockito.mock(HistoryWrapper.class);
-        tokenMatcher = Mockito.mock(TokenMatcher.class);
-        spaceSelector = Mockito.mock(SpaceSelectorPresenter.class);
-        eventBus = new EventBusTester();
-        stateManager = new StateManagerDefault(contentProvider, session, history, tokenMatcher, eventBus);
-        Mockito.when(session.getUserHash()).thenReturn(HASH);
-        state = Mockito.mock(StateAbstractDTO.class);
-        stateChangeHandler = Mockito.mock(StateChangedHandler.class);
-        groupChangeHandler = Mockito.mock(GroupChangedHandler.class);
-        toolChangeHandler = Mockito.mock(ToolChangedHandler.class);
-        beforeChangeListener1 = Mockito.mock(BeforeActionListener.class);
-        beforeChangeListener2 = Mockito.mock(BeforeActionListener.class);
-        eventBus.addHandler(StateChangedEvent.getType(), stateChangeHandler);
-        eventBus.addHandler(GroupChangedEvent.getType(), groupChangeHandler);
-        eventBus.addHandler(ToolChangedEvent.getType(), toolChangeHandler);
-        // new NotifyUser(null, null);
-    }
-
-    @Test
-    public void changeGroupWithNoTool() {
-        changeState("group1", "group2");
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-    }
-
-    private void changeState(final String... tokens) {
-        for (final String token : tokens) {
-            Mockito.when(state.getStateToken()).thenReturn(new StateToken(token));
-            stateManager.setState(state);
-        }
-    }
-
-    @Test
-    public void changeStateWithDifferentAndGroupsToolsMustFireListener() {
-        changeState("group2.tool1", "group1.tool2");
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group2"));
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("group2", "group1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", "tool2"));
-    }
-
-    @Test
-    public void changeStateWithDifferentGroupsMustFireListener() {
-        changeState("group1.tool1", "group2.tool1");
-        // assertTrue(stateChangeListener.isCalled(2));
-        // assertTrue(groupChangeListener.isCalledWithEquals("", "group1",
-        // "group1", "group2"));
-        // assertTrue(toolChangeListener.isCalledWithEquals("", "tool1"));
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(2)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("group1", "group2"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
-
-    }
-
-    @Test
-    public void changeStateWithDifferentToolsMustFireListener() {
-        changeState("group1.tool1", "group1.tool2");
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", "tool2"));
-    }
-
-    @Test
-    public void changeToNoTool() {
-        changeState("group1.tool1", "group1");
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(toolChangeHandler, Mockito.times(2)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("tool1", ""));
-    }
-
-    @Test
-    public void changeToSameToken() {
-        changeState("group1.tool1", "group1.tool1");
-        Mockito.verify(stateChangeHandler, Mockito.times(2)).onStateChanged((StateChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged((GroupChangedEvent) Mockito.anyObject());
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged((ToolChangedEvent) Mockito.anyObject());
-        Mockito.verify(groupChangeHandler, Mockito.times(1)).onGroupChanged(new GroupChangedEvent("", "group1"));
-        Mockito.verify(toolChangeHandler, Mockito.times(1)).onToolChanged(new ToolChangedEvent("", "tool1"));
-    }
-
-    private String confBeforeStateChangeListeners(final boolean value, final boolean value2) {
-        stateManager.addBeforeStateChangeListener(beforeChangeListener1);
-        stateManager.addBeforeStateChangeListener(beforeChangeListener2);
-        final String newToken = "something";
-        Mockito.when(beforeChangeListener1.beforeAction()).thenReturn(value);
-        Mockito.when(beforeChangeListener2.beforeAction()).thenReturn(value2);
-        return newToken;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void getDefGroup() {
-        stateManager.onHistoryChanged("site.docs");
-        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    public void getWaveToken() {
-        stateManager.onHistoryChanged("example.com/w+abcd/~/conv+root/b+45kg");
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void normalStartLoggedUser() {
-        // When a user enter reload state, also if the application is starting
-        // (and the user was logged)
-        Mockito.when(history.getToken()).thenReturn("");
-        stateManager.reload();
-        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void oneBeforeStateChangeListenerAddAndRemove() {
-        final String newToken = confBeforeStateChangeListeners(false, false);
-        stateManager.onHistoryChanged(newToken);
-        removeBeforeStateChangeListener();
-        stateManager.onHistoryChanged(newToken);
-        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    @Test
-    public void oneBeforeStateChangeListenerFalseAndResume() {
-        final String token = confBeforeStateChangeListeners(false, true);
-        stateManager.onHistoryChanged(token);
-        Mockito.verify(history, Mockito.never()).newItem(token);
-        removeBeforeStateChangeListener();
-        stateManager.resumeTokenChange();
-        Mockito.verify(history, Mockito.times(1)).newItem(token);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void oneBeforeStateChangeListenerReturnFalse() {
-        stateManager.onHistoryChanged(confBeforeStateChangeListeners(true, false));
-        Mockito.verify(contentProvider, Mockito.never()).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void oneBeforeStateChangeListenerReturnFalseWithTwo() {
-        stateManager.onHistoryChanged(confBeforeStateChangeListeners(false, false));
-        Mockito.verify(contentProvider, Mockito.never()).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void oneBeforeStateChangeListenerReturnTrue() {
-        stateManager.onHistoryChanged(confBeforeStateChangeListeners(true, true));
-        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    private void removeBeforeStateChangeListener() {
-        stateManager.removeBeforeStateChangeListener(beforeChangeListener1);
-        stateManager.removeBeforeStateChangeListener(beforeChangeListener2);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void siteTokenFirstLoadDefContentAndFireListener() {
-        final HistoryTokenCallback listener = Mockito.mock(HistoryTokenCallback.class);
-        final String token = SiteTokens.SIGNIN;
-        stateManager.addSiteToken(token, listener);
-        stateManager.onHistoryChanged(token);
-        Mockito.verify(listener, Mockito.times(1)).onHistoryToken();
-        Mockito.verify(contentProvider, Mockito.times(1)).getContent(Mockito.anyString(),
-                (StateToken) Mockito.anyObject(), (AsyncCallback<StateAbstractDTO>) Mockito.anyObject());
-    }
-
-    @Test
-    public void siteTokenTest() {
-        final HistoryTokenCallback siteTokenListener = Mockito.mock(HistoryTokenCallback.class);
-        stateManager.addSiteToken("signin", siteTokenListener);
-        stateManager.onHistoryChanged("signIn");
-        Mockito.verify(siteTokenListener, Mockito.times(1)).onHistoryToken();
-    }
-}




More information about the kune-commits mailing list