/** * Loads active {@link CloudProject}, if IDE {@link Project} has been specified. This should be * called when project selector and the related UI are completely initialized. Calls listeners to * notify on new project selection. */ public void loadActiveCloudProject() { Optional<CloudProject> projectOptional = Optional.ofNullable(ideProject) .map(p -> ActiveCloudProjectManager.getInstance().getActiveCloudProject(p)); projectOptional.ifPresent( activeCloudProject -> { // do not preset and notify on active project if not signed in to avoid misleading client // code to assume project selection is made with an active account. if (Services.getLoginService().isLoggedIn()) { setSelectedProject(activeCloudProject); notifyProjectSelectionListeners(); } }); }
private void mockLoggedInUser() { when(Services.getLoginService().isLoggedIn()).thenReturn(true); }
private void mockLoggedOutUser() { when(Services.getLoginService().isLoggedIn()).thenReturn(false); }
private void mockUserLoggedIn(String username) { when(mockLoginService.isLoggedIn()).thenReturn(true); CredentialedUser mockUser = mock(CredentialedUser.class); when(mockLoginService.getLoggedInUser(TEST_PROJECT.googleUsername())) .thenReturn(Optional.of(mockUser)); when(mockUser.getEmail()).thenReturn(username); } }
@Override public void connect(@NotNull ConnectionCallback<AppEngineDeploymentConfiguration> callback) { Services.getLoginService().logInIfNot(); if (!Services.getLoginService().isLoggedIn()) { callback.errorOccurred( AppEngineMessageBundle.message("appengine.deployment.error.not.logged.in")); return; } callback.connected(new AppEngineRuntimeInstance()); } }
@Before public void setUp() { projectSelector = new ProjectSelector(null /* no IDE project by default for tests. */) { @Override ProjectSelectionDialog createProjectSelectionDialog(Component parent) { return projectSelectionDialog; } }; projectSelector.addProjectSelectionListener(projectSelectionListener); ActiveCloudProjectManager.setInstance(mockActiveCloudProjectManager); when(mockLoginService.isLoggedIn()).thenReturn(true); }
@Before public void setUp() { GcsTestUtils.setupVirtualFileWithBucketMocks(bucketVirtualFile); when(loginService.isLoggedIn()).thenReturn(true); when(directoryBlob.isDirectory()).thenReturn(true); when(directoryBlob.getName()).thenReturn(DIR_NAME); when(binaryBlob.isDirectory()).thenReturn(false); when(binaryBlob.getName()).thenReturn(BLOB_NAME); when(binaryBlob.getSize()).thenReturn(1024L); when(binaryBlob.getContentType()).thenReturn(BLOB_CONTENT_TYPE); when(binaryBlob.getUpdateTime()).thenReturn(0L); when(binaryBlobInDirectory.getName()).thenReturn(NESTED_BLOB_FULL_NAME); // TODO: consider shutting down timer instead when clear what is creating the timer. ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Timer-0"); }
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); }
@Before public void setUp() { when(loginService.isLoggedIn()).thenReturn(true); bucketPanel = new GcsBucketPanel(testFixture.getProject()); bucketPanel.setProjectSelector(projectSelector); }
void refresh() { showNotificationPanel(); if (!Services.getLoginService().isLoggedIn()) { notificationLabel.setText( GoogleCloudStorageMessageBundle.message("gcs.panel.bucket.listing.not.logged.in")); } else if (projectSelector.getSelectedProject() == null) { notificationLabel.setText( GoogleCloudStorageMessageBundle.message("gcs.panel.bucket.listing.no.project.selected")); } else { CloudProject cloudProject = projectSelector.getSelectedProject(); Optional<CredentialedUser> user = Services.getLoginService().getLoggedInUser(cloudProject.googleUsername()); if (user.isPresent()) { loadAndDisplayBuckets(cloudProject.projectId(), user.get()); } else { notificationLabel.setText( GoogleCloudStorageMessageBundle.message( "gcs.panel.bucket.listing.error.loading.buckets")); log.warn("Cloud not load credentialed user for GCS operation. User may not be logged."); } } }
@Test public void testLoginMessageShown_whenLoggedOut() { when(loginService.isLoggedIn()).thenReturn(false); editorPanel = new GcsBucketContentEditorPanel(bucketVirtualFile.getBucket()); editorPanel.initTableModel(); assertTrue(editorPanel.getMessagePanel().isVisible()); assertThat(editorPanel.getMessageLabel().getText()) .isEqualTo("To view bucket contents log in to your Google Cloud Platform account"); }
(event) -> { if (event.getEventType() == EventType.ACTIVATED) { if (Services.getLoginService().isLoggedIn()) { handleOpenProjectSelectionDialog(); } else {
@Override protected ValidationInfo doValidate() { if (!Services.getLoginService().isLoggedIn()) { return new ValidationInfo(StackdriverDebuggerBundle.getString("clouddebug.nologin"));
@Test public void testNotificationLabel_userLoggedOut() { when(loginService.isLoggedIn()).thenReturn(false); bucketPanel.refresh(); assertTrue(bucketPanel.getNotificationPanel().isVisible()); assertFalse(bucketPanel.getBucketListPanel().isVisible()); assertThat(bucketPanel.getNotificationLabel().getText()) .isEqualTo("To view your buckets log in to your Google Cloud Platform account."); }
@Test public void validProject_no_LoggedInUsers_showLoginPrompt() { when(mockLoginService.isLoggedIn()).thenReturn(false); projectSelector.setSelectedProject(TEST_PROJECT); assertThat(projectSelector.getAccountInfoLabel().getHyperlinkText()) .isEqualTo( GoogleCloudCoreMessageBundle.message( "cloud.project.selector.not.signed.in", TEST_PROJECT.googleUsername())); assertThat(projectSelector.getAccountInfoLabel().getIcon()).isNull(); }
@Test public void validProject_newLogIn_changesTo_AccountInformation() { when(mockLoginService.isLoggedIn()).thenReturn(false); projectSelector.setSelectedProject(TEST_PROJECT); // log in now, fire event mockUserLoggedIn(TEST_PROJECT.googleUsername()); projectSelector.googleLoginListener.statusChanged(); // drain UI events. ApplicationManager.getApplication().invokeAndWait(() -> {}); verifyUiStateForProject(TEST_PROJECT); }
void initTableModel() { if (!Services.getLoginService().isLoggedIn()) { showMessage( GoogleCloudStorageMessageBundle.message("gcs.content.explorer.not.logged.in.text")); return; } UsageTrackerService.getInstance().trackEvent(GctTracking.GCS_BLOB_BROWSE).ping(); Consumer<List<Blob>> afterLoad = blobs -> { if (blobs.isEmpty()) { showMessage( GoogleCloudStorageMessageBundle.message("gcs.content.explorer.empty.bucket.text")); } else { showBlobTable(); tableModel = new GcsBlobTableModel(); tableModel.setDataVector(blobs, ""); bucketContentTable.setModel(tableModel); } }; breadcrumbs.render(bucket.getName()); loadBlobsStartingWith("", afterLoad); }
@Test public void validProject_logOut_changesTo_loginPrompt() { projectSelector.setSelectedProject(TEST_PROJECT); // log out all users, notify login listeners. when(mockLoginService.isLoggedIn()).thenReturn(false); projectSelector.googleLoginListener.statusChanged(); // drain UI events. ApplicationManager.getApplication().invokeAndWait(() -> {}); assertThat(projectSelector.getAccountInfoLabel().getHyperlinkText()) .isEqualTo( GoogleCloudCoreMessageBundle.message( "cloud.project.selector.not.signed.in", TEST_PROJECT.googleUsername())); assertThat(projectSelector.getAccountInfoLabel().getIcon()).isNull(); }
if (!Services.getLoginService().isLoggedIn()) { callback.errorOccurred( AppEngineMessageBundle.message("appengine.deployment.error.not.logged.in"));
void updateTableModel(String prefix) { if (!Services.getLoginService().isLoggedIn()) { showMessage( GoogleCloudStorageMessageBundle.message("gcs.content.explorer.not.logged.in.text"));