This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Huang
committed
Oct 3, 2012
1 parent
cd54e78
commit 2788c17
Showing
13 changed files
with
302 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ta-war/src/test/java/org/zanata/webtrans/server/rpc/EventServiceConnectedHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.zanata.webtrans.server.rpc; | ||
|
||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.model.TestFixture; | ||
import org.zanata.seam.SeamAutowire; | ||
import org.zanata.security.ZanataIdentity; | ||
import org.zanata.webtrans.server.TranslationWorkspace; | ||
import org.zanata.webtrans.server.TranslationWorkspaceManager; | ||
import org.zanata.webtrans.shared.auth.EditorClientId; | ||
import org.zanata.webtrans.shared.model.WorkspaceId; | ||
import org.zanata.webtrans.shared.rpc.EventServiceConnectedAction; | ||
|
||
import net.customware.gwt.dispatch.shared.ActionException; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
@Test(groups = "unit-tests") | ||
public class EventServiceConnectedHandlerTest | ||
{ | ||
private EventServiceConnectedHandler handler; | ||
@Mock | ||
private ZanataIdentity identity; | ||
@Mock | ||
private TranslationWorkspaceManager translationWorkspaceManager; | ||
@Mock | ||
private TranslationWorkspace translationWorkspace; | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception | ||
{ | ||
MockitoAnnotations.initMocks(this); | ||
// @formatter:off | ||
handler = SeamAutowire.instance() | ||
.use("identity", identity) | ||
.use("translationWorkspaceManager", translationWorkspaceManager) | ||
.ignoreNonResolvable() | ||
.autowire(EventServiceConnectedHandler.class); | ||
// @formatter:on | ||
} | ||
|
||
@Test | ||
public void testExecute() throws ActionException | ||
{ | ||
WorkspaceId workspaceId = TestFixture.workspaceId(); | ||
EditorClientId editorClientId = new EditorClientId("sessionId", 1); | ||
EventServiceConnectedAction action = new EventServiceConnectedAction("connectionId"); | ||
action.setWorkspaceId(workspaceId); | ||
action.setEditorClientId(editorClientId); | ||
when(translationWorkspaceManager.getOrRegisterWorkspace(workspaceId)).thenReturn(translationWorkspace); | ||
|
||
handler.execute(action, null); | ||
|
||
verify(identity).checkLoggedIn(); | ||
verify(translationWorkspace).onEventServiceConnected(editorClientId, "connectionId"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
zanata-war/src/test/java/org/zanata/webtrans/server/rpc/ExitWorkspaceHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.zanata.webtrans.server.rpc; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.model.TestFixture; | ||
import org.zanata.seam.SeamAutowire; | ||
import org.zanata.security.ZanataIdentity; | ||
import org.zanata.webtrans.server.TranslationWorkspace; | ||
import org.zanata.webtrans.server.TranslationWorkspaceManager; | ||
import org.zanata.webtrans.shared.auth.EditorClientId; | ||
import org.zanata.webtrans.shared.model.Person; | ||
import org.zanata.webtrans.shared.model.PersonId; | ||
import org.zanata.webtrans.shared.model.WorkspaceId; | ||
import org.zanata.webtrans.shared.rpc.ExitWorkspaceAction; | ||
import org.zanata.webtrans.shared.rpc.ExitWorkspaceResult; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
@Test(groups = "unit-tests") | ||
public class ExitWorkspaceHandlerTest | ||
{ | ||
private ExitWorkspaceHandler handler; | ||
@Mock | ||
private ZanataIdentity identity; | ||
@Mock | ||
private TranslationWorkspaceManager translationWorkspaceManager; | ||
@Mock | ||
private TranslationWorkspace translationWorkspace; | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception | ||
{ | ||
MockitoAnnotations.initMocks(this); | ||
// @formatter:off | ||
handler = SeamAutowire.instance() | ||
.use("identity", identity) | ||
.use("translationWorkspaceManager", translationWorkspaceManager) | ||
.ignoreNonResolvable() | ||
.autowire(ExitWorkspaceHandler.class); | ||
// @formatter:on | ||
} | ||
|
||
@Test | ||
public void testExecute() throws Exception | ||
{ | ||
Person person = new Person(new PersonId("pid"), "admin", null); | ||
EditorClientId editorClientId = new EditorClientId("sessionId", 1); | ||
WorkspaceId workspaceId = TestFixture.workspaceId(); | ||
when(translationWorkspaceManager.getOrRegisterWorkspace(workspaceId)).thenReturn(translationWorkspace); | ||
ExitWorkspaceAction action = new ExitWorkspaceAction(person); | ||
action.setEditorClientId(editorClientId); | ||
action.setWorkspaceId(workspaceId); | ||
|
||
ExitWorkspaceResult result = handler.execute(action, null); | ||
|
||
verify(identity).checkLoggedIn(); | ||
verify(translationWorkspace).removeEditorClient(action.getEditorClientId()); | ||
assertThat(result.getuserName(), Matchers.equalTo(person.getId().toString())); | ||
} | ||
} |
Oops, something went wrong.