Search in sources :

Example 1 with IntegratedGoogleLoginService

use of com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelector method updateCloudProjectSelection.

private void updateCloudProjectSelection(CloudProject selection) {
    projectNameLabel.setHyperlinkText(selection.projectName());
    projectAccountSeparatorLabel.setVisible(true);
    // first just show account email, then expand with name/picture if this account is signed in.
    // if not signed in, hide icon and account name completely and prompt to sign in.
    accountInfoLabel.setHyperlinkText(selection.googleUsername());
    IntegratedGoogleLoginService loginService = Services.getLoginService();
    Optional<CredentialedUser> loggedInUser = loginService.getLoggedInUser(selection.googleUsername());
    if (!loggedInUser.isPresent()) {
        accountInfoLabel.setHyperlinkText(GoogleCloudCoreMessageBundle.message("cloud.project.selector.not.signed.in", selection.googleUsername()));
    } else if (loggedInUser.isPresent()) {
        accountInfoLabel.setHyperlinkText(String.format("%s (%s)", Strings.nullToEmpty(loggedInUser.get().getName()), loggedInUser.get().getEmail()));
    }
    accountInfoLabel.setIcon(loginService.isLoggedIn() ? GoogleLoginIcons.getScaledUserIcon(ACCOUNT_ICON_SIZE, loggedInUser.orElse(null)) : null);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser)

Example 2 with IntegratedGoogleLoginService

use of com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudAttachDialogTest method mockCredentials.

private void mockCredentials() throws Exception {
    IntegratedGoogleLoginService mockLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
    GoogleLoginState googleLoginState = mock(GoogleLoginState.class);
    Credential credential = mock(Credential.class);
    this.user = mock(CredentialedUser.class);
    LinkedHashMap<String, CredentialedUser> allusers = new LinkedHashMap<String, CredentialedUser>();
    when(this.user.getCredential()).thenReturn(credential);
    when(this.user.getEmail()).thenReturn(USER);
    when(this.user.getGoogleLoginState()).thenReturn(googleLoginState);
    when(googleLoginState.fetchAccessToken()).thenReturn(PASSWORD);
    when(mockLoginService.getAllUsers()).thenReturn(allusers);
    allusers.put(USER, this.user);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) Credential(com.google.api.client.auth.oauth2.Credential) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with IntegratedGoogleLoginService

use of com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method testRemoveConsolePane.

public void testRemoveConsolePane() {
    // if this was a JUnit4 test case, we could set the LoggedErrorProcessor to a mock that does
    // not fail the test if an error is logged using @BeforeClass. Since this is a JUnit3 test
    // case, we need to elaborately initialize a user in GoogleLogin
    CloudDebugProcessState state = // Mockito.mock(CloudDebugProcessState.class);
    new CloudDebugProcessState();
    state.setUserEmail("mockUser@foo.com");
    CredentialedUser credentialedUser = mock(CredentialedUser.class);
    when(credentialedUser.getGoogleLoginState()).thenReturn(mock(GoogleLoginState.class));
    LinkedHashMap<String, CredentialedUser> users = new LinkedHashMap<String, CredentialedUser>();
    users.put(state.getUserEmail(), credentialedUser);
    IntegratedGoogleLoginService mockGoogleLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
    when(mockGoogleLoginService.getAllUsers()).thenReturn(users);
    process.initialize(state);
    XDebugTabLayouter layouter = process.createTabLayouter();
    RunnerLayoutUi ui = mock(RunnerLayoutUi.class);
    Content console = mock(Content.class);
    when(ui.findContent(DebuggerContentInfo.CONSOLE_CONTENT)).thenReturn(console);
    ui.removeContent(console, false);
    LayoutStateDefaults defaults = mock(LayoutStateDefaults.class);
    when(ui.getDefaults()).thenReturn(defaults);
    layouter.registerAdditionalContent(ui);
    verify(ui, Mockito.atLeast(1)).removeContent(console, false);
    process.getStateController().stopBackgroundListening();
    UIUtil.dispatchAllInvocationEvents();
}
Also used : GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) Content(com.intellij.ui.content.Content) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) XDebugTabLayouter(com.intellij.xdebugger.ui.XDebugTabLayouter) Matchers.anyString(org.mockito.Matchers.anyString) LayoutStateDefaults(com.intellij.execution.ui.layout.LayoutStateDefaults) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with IntegratedGoogleLoginService

use of com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
    fixture.setUp();
    project = new MockProjectEx(getTestRootDisposable());
    PsiManager psiManager = Mockito.mock(PsiManager.class);
    project.registerService(PsiManager.class, psiManager);
    IntegratedGoogleLoginService mockLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
    GoogleLoginState googleLoginState = Mockito.mock(GoogleLoginState.class);
    CredentialedUser user = Mockito.mock(CredentialedUser.class);
    LinkedHashMap<String, CredentialedUser> allusers = new LinkedHashMap<String, CredentialedUser>();
    when(user.getEmail()).thenReturn(USER);
    when(user.getGoogleLoginState()).thenReturn(googleLoginState);
    when(googleLoginState.fetchAccessToken()).thenReturn(PASSWORD);
    when(mockLoginService.getAllUsers()).thenReturn(allusers);
    allusers.put(USER, user);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) PsiManager(com.intellij.psi.PsiManager) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) MockProjectEx(com.intellij.mock.MockProjectEx) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with IntegratedGoogleLoginService

use of com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebuggerClientTest method setUp.

@Before
public void setUp() {
    IntegratedGoogleLoginService mockLogin = Mockito.mock(IntegratedGoogleLoginService.class);
    registerService(IntegratedGoogleLoginService.class, mockLogin);
    registerService(PluginInfoService.class, mockInfoService);
    LinkedHashMap<String, CredentialedUser> allUsers = new LinkedHashMap<String, CredentialedUser>();
    CredentialedUser user = Mockito.mock(CredentialedUser.class);
    allUsers.put("foo@example.com", user);
    when(mockLogin.getAllUsers()).thenReturn(allUsers);
    Credential credential = Mockito.mock(Credential.class);
    when(user.getCredential()).thenReturn(credential);
    GoogleLoginState loginState = Mockito.mock(GoogleLoginState.class);
    when(user.getGoogleLoginState()).thenReturn(loginState);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) Credential(com.google.api.client.auth.oauth2.Credential) GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Aggregations

CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)5 IntegratedGoogleLoginService (com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService)5 GoogleLoginState (com.google.gdt.eclipse.login.common.GoogleLoginState)4 LinkedHashMap (java.util.LinkedHashMap)4 Credential (com.google.api.client.auth.oauth2.Credential)2 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1 LayoutStateDefaults (com.intellij.execution.ui.layout.LayoutStateDefaults)1 MockProjectEx (com.intellij.mock.MockProjectEx)1 PsiManager (com.intellij.psi.PsiManager)1 Content (com.intellij.ui.content.Content)1 XDebugTabLayouter (com.intellij.xdebugger.ui.XDebugTabLayouter)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1