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());
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations