Search in sources :

Example 6 with Project

use of com.google.api.services.cloudresourcemanager.model.Project in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectionDialogTest method mockUserProjects.

/**
 * Mocks list of project returned for a user when selection dialog calls for it.
 */
private void mockUserProjects(CredentialedUser user, List<Project> projectList) {
    @SuppressWarnings("unchecked") ListenableFuture<List<Project>> mockFuture = (ListenableFuture<List<Project>>) mock(ListenableFuture.class);
    when(mockProjectLoader.loadUserProjectsInBackground(user)).thenReturn(mockFuture);
    doAnswer(new Answer() {

        @Override
        @SuppressWarnings("unchecked")
        public Object answer(InvocationOnMock invocation) {
            ((FutureCallback<List<Project>>) invocation.getArgument(1)).onSuccess(projectList);
            return null;
        }
    }).when(projectSelectionDialog).addProjectListFutureCallback(any(), any());
}
Also used : Project(com.google.api.services.cloudresourcemanager.model.Project) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List)

Example 7 with Project

use of com.google.api.services.cloudresourcemanager.model.Project in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectionDialogTest method setUp.

@Before
public void setUp() {
    projectSelectionDialog.setProjectLoader(mockProjectLoader);
    projectSelectionDialog.setDialogWrapper(dialogWrapper);
    doReturn(mockDialogButton).when(projectSelectionDialog).getDialogButton(any());
    doNothing().when(projectSelectionDialog).installTableSpeedSearch(any());
    doNothing().when(projectSelectionDialog).setLoading(anyBoolean());
    projectSelectionDialog.createUIComponents();
    projectSelectionDialog.loadAllProjects();
    testUiProject = CloudProject.create(TEST_PROJECT_NAME, TEST_PROJECT_ID, TEST_USER_EMAIL);
    testGoogleProject = new Project();
    testGoogleProject.setName(TEST_PROJECT_NAME);
    testGoogleProject.setProjectId(TEST_PROJECT_NAME + "-id");
    when(mockTestUser.getEmail()).thenReturn(TEST_USER_EMAIL);
}
Also used : Project(com.google.api.services.cloudresourcemanager.model.Project) Before(org.junit.Before)

Example 8 with Project

use of com.google.api.services.cloudresourcemanager.model.Project in project google-cloud-java by GoogleCloudPlatform.

the class LocalResourceManagerHelper method changeLifecycleState.

/**
   * Utility method to change the lifecycle state of the specified project.
   *
   * @return true if the lifecycle state was successfully updated, false otherwise
   */
public synchronized boolean changeLifecycleState(String projectId, String lifecycleState) {
    checkArgument("ACTIVE".equals(lifecycleState) || "DELETE_REQUESTED".equals(lifecycleState) || "DELETE_IN_PROGRESS".equals(lifecycleState), "Lifecycle state must be ACTIVE, DELETE_REQUESTED, or DELETE_IN_PROGRESS");
    Project project = projects.get(checkNotNull(projectId));
    if (project != null) {
        project.setLifecycleState(lifecycleState);
        return true;
    }
    return false;
}
Also used : Project(com.google.api.services.cloudresourcemanager.model.Project)

Example 9 with Project

use of com.google.api.services.cloudresourcemanager.model.Project in project google-cloud-java by GoogleCloudPlatform.

the class LocalResourceManagerHelper method replace.

synchronized Response replace(String projectId, Project project) {
    Project originalProject = projects.get(projectId);
    if (originalProject == null) {
        return Error.PERMISSION_DENIED.response("Error when replacing " + projectId + " because the project was not found.");
    } else if (!originalProject.getLifecycleState().equals("ACTIVE")) {
        return Error.FAILED_PRECONDITION.response("Error when replacing " + projectId + " because the lifecycle state was not ACTIVE.");
    } else if (!Objects.equal(originalProject.getParent(), project.getParent())) {
        return Error.INVALID_ARGUMENT.response("The server currently only supports setting the parent once " + "and does not allow unsetting it.");
    }
    project.setProjectId(projectId);
    project.setLifecycleState(originalProject.getLifecycleState());
    project.setCreateTime(originalProject.getCreateTime());
    project.setProjectNumber(originalProject.getProjectNumber());
    // replace cannot fail because both this method and removeProject are synchronized
    projects.replace(projectId, project);
    try {
        return new Response(HTTP_OK, jsonFactory.toString(project));
    } catch (IOException e) {
        return Error.INTERNAL_ERROR.response("Error when serializing project " + projectId);
    }
}
Also used : TestIamPermissionsResponse(com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse) Project(com.google.api.services.cloudresourcemanager.model.Project) IOException(java.io.IOException)

Example 10 with Project

use of com.google.api.services.cloudresourcemanager.model.Project in project google-cloud-java by GoogleCloudPlatform.

the class LocalResourceManagerHelper method undelete.

synchronized Response undelete(String projectId) {
    Project project = projects.get(projectId);
    Response response;
    if (project == null) {
        response = Error.PERMISSION_DENIED.response("Error when undeleting " + projectId + " because the project was not found.");
    } else if (!project.getLifecycleState().equals("DELETE_REQUESTED")) {
        response = Error.FAILED_PRECONDITION.response("Error when undeleting " + projectId + " because the lifecycle state was not DELETE_REQUESTED.");
    } else {
        project.setLifecycleState("ACTIVE");
        response = new Response(HTTP_OK, "{}");
    }
    return response;
}
Also used : TestIamPermissionsResponse(com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse) Project(com.google.api.services.cloudresourcemanager.model.Project)

Aggregations

Project (com.google.api.services.cloudresourcemanager.model.Project)12 IOException (java.io.IOException)4 List (java.util.List)4 TestIamPermissionsResponse (com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Before (org.junit.Before)3 Test (org.junit.Test)3 CloudResourceManager (com.google.api.services.cloudresourcemanager.CloudResourceManager)2 ListProjectsResponse (com.google.api.services.cloudresourcemanager.model.ListProjectsResponse)2 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)2 GoogleApiClientFactory (com.google.cloud.tools.intellij.resources.GoogleApiClientFactory)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ArrayList (java.util.ArrayList)2 Answer (org.mockito.stubbing.Answer)2 Strings (com.google.api.client.repackaged.com.google.common.base.Strings)1 CloudToolsRule (com.google.cloud.tools.intellij.testing.CloudToolsRule)1 TestService (com.google.cloud.tools.intellij.testing.TestService)1 ThreadUtil (com.google.cloud.tools.intellij.util.ThreadUtil)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Futures (com.google.common.util.concurrent.Futures)1