Search in sources :

Example 6 with CloudProject

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

the class CloneCloudRepositoryDialog method getCurrentUrlText.

@Nullable
private String getCurrentUrlText() {
    CloudProject selectedProject = projectSelector.getSelectedProject();
    Optional<CredentialedUser> selectedUser = selectedProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(selectedProject.googleUsername());
    if (selectedProject == null || !selectedUser.isPresent() || StringUtil.isEmpty(repositorySelector.getText())) {
        return null;
    }
    return GcpHttpAuthDataProvider.getGcpUrl(selectedProject.projectId(), repositorySelector.getText());
}
Also used : CloudProject(com.google.cloud.tools.intellij.project.CloudProject) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with CloudProject

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

the class CloneCloudRepositoryDialog method updateButtons.

/**
 * Check fields and display error in the wrapper if there is a problem.
 */
private void updateButtons() {
    CloudProject selectedProject = projectSelector.getSelectedProject();
    Optional<CredentialedUser> selectedUser = selectedProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(selectedProject.googleUsername());
    if (selectedProject != null && !selectedUser.isPresent()) {
        setErrorText(GctBundle.message("cloud.repository.dialog.invalid.project"));
        setOKActionEnabled(false);
        return;
    }
    if (!StringUtil.isEmpty(repositorySelector.getText()) && StringUtil.isEmpty(repositorySelector.getSelectedRepository())) {
        setErrorText(GctBundle.message("cloud.repository.dialog.invalid.repository"));
        setOKActionEnabled(false);
        return;
    }
    if (!selectedUser.isPresent() || StringUtil.isEmpty(repositorySelector.getSelectedRepository())) {
        setErrorText(null);
        setOKActionEnabled(false);
        return;
    }
    if (StringUtil.isEmpty(parentDirectory.getText()) || StringUtil.isEmpty(directoryName.getText())) {
        setErrorText(null);
        setOKActionEnabled(false);
        return;
    }
    File file = new File(parentDirectory.getText(), directoryName.getText());
    if (file.exists()) {
        setErrorText(GctBundle.message("clonefromgcp.destination.exists.error"));
        setOKActionEnabled(false);
        return;
    }
    if (!file.getParentFile().exists()) {
        setErrorText(GctBundle.message("clonefromgcp.parent.missing.error"));
        setOKActionEnabled(false);
        return;
    }
    setErrorText(null);
    setOKActionEnabled(true);
}
Also used : CloudProject(com.google.cloud.tools.intellij.project.CloudProject) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with CloudProject

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

the class GoogleCloudApiSelectorPanelTest method getManagementUI_withLibraryAndProjectSelected_isEnabled.

@Test
public void getManagementUI_withLibraryAndProjectSelected_isEnabled() {
    CloudLibrary library = LIBRARY_1.toCloudLibrary();
    GoogleCloudApiSelectorPanel panel = new GoogleCloudApiSelectorPanel(ImmutableList.of(library), testFixture.getProject());
    JTable table = panel.getCloudLibrariesTable();
    checkAddLibraryCheckbox(table, 0);
    panel.getDetailsPanel().setCloudLibrary(library, BOM_VERSION, panel.getApiManagementMap().get(library));
    CloudProject cloudProject = CloudProject.create("name", "id", "user");
    ProjectSelector projectSelector = panel.getProjectSelector();
    projectSelector.setSelectedProject(cloudProject);
    projectSelector.getProjectSelectionListeners().forEach(listener -> listener.projectSelected(cloudProject));
    assertThat(panel.getDetailsPanel().getEnableApiCheckbox().isEnabled()).isTrue();
    assertThat(panel.getDetailsPanel().getManagementInfoPanel().isVisible()).isFalse();
}
Also used : CloudProject(com.google.cloud.tools.intellij.project.CloudProject) JTable(javax.swing.JTable) TestCloudLibrary(com.google.cloud.tools.intellij.testing.apis.TestCloudLibrary) CloudLibrary(com.google.cloud.tools.libraries.json.CloudLibrary) ProjectSelector(com.google.cloud.tools.intellij.project.ProjectSelector) Test(org.junit.Test)

Example 9 with CloudProject

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

the class AppEngineDeploymentConfigurationPanelTest method projectSelector_invalidProjectSelected_infoPanelShowsError.

@Test
public void projectSelector_invalidProjectSelected_infoPanelShowsError() {
    CloudProject project = CloudProject.create("projectId", "projectId", "some-user-id");
    when(projectSelector.getSelectedProject()).thenReturn(project);
    deploymentConfiguration.setCloudProjectName("projectName");
    deploymentConfiguration.setGoogleUsername("some-user-id");
    configurationPanel.resetEditorFrom(deploymentConfiguration);
    verify(infoPanel).setMessage(GctBundle.getString("appengine.infopanel.no.region"), true);
}
Also used : CloudProject(com.google.cloud.tools.intellij.project.CloudProject) Test(org.junit.Test)

Example 10 with CloudProject

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

the class AppEngineDeploymentConfigurationPanelTest method projectSelector_validProjectSelected_infoPanelShowsProjectDetails.

@Test
public void projectSelector_validProjectSelected_infoPanelShowsProjectDetails() {
    String projectId = "projectId";
    String googleUsername = "some-user-id";
    CloudProject project = CloudProject.create(projectId, projectId, googleUsername);
    when(credentialedUser.getCredential()).thenReturn(credential);
    when(mockGoogleLoginService.getLoggedInUser(googleUsername)).thenReturn(Optional.of(credentialedUser));
    when(projectSelector.getSelectedProject()).thenReturn(project);
    deploymentConfiguration.setCloudProjectName(projectId);
    deploymentConfiguration.setGoogleUsername(googleUsername);
    configurationPanel.resetEditorFrom(deploymentConfiguration);
    verify(infoPanel).refresh(projectId, credential);
}
Also used : CloudProject(com.google.cloud.tools.intellij.project.CloudProject) Test(org.junit.Test)

Aggregations

CloudProject (com.google.cloud.tools.intellij.project.CloudProject)20 Test (org.junit.Test)10 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)5 CloudLibrary (com.google.cloud.tools.libraries.json.CloudLibrary)3 Role (com.google.api.services.iam.v1.model.Role)2 Nullable (org.jetbrains.annotations.Nullable)2 Base64 (com.google.api.client.util.Base64)1 CloudResourceManager (com.google.api.services.cloudresourcemanager.CloudResourceManager)1 Binding (com.google.api.services.cloudresourcemanager.model.Binding)1 GetIamPolicyRequest (com.google.api.services.cloudresourcemanager.model.GetIamPolicyRequest)1 Policy (com.google.api.services.cloudresourcemanager.model.Policy)1 SetIamPolicyRequest (com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest)1 Iam (com.google.api.services.iam.v1.Iam)1 CreateServiceAccountKeyRequest (com.google.api.services.iam.v1.model.CreateServiceAccountKeyRequest)1 CreateServiceAccountRequest (com.google.api.services.iam.v1.model.CreateServiceAccountRequest)1 ServiceAccount (com.google.api.services.iam.v1.model.ServiceAccount)1 ServiceAccountKey (com.google.api.services.iam.v1.model.ServiceAccountKey)1 ServiceManagement (com.google.api.services.servicemanagement.ServiceManagement)1 EnableServiceRequest (com.google.api.services.servicemanagement.model.EnableServiceRequest)1 GoogleCloudCoreIcons (com.google.cloud.tools.intellij.GoogleCloudCoreIcons)1