Java Code Examples for com.google.api.services.cloudresourcemanager.model.ListProjectsResponse#setProjects()

The following examples show how to use com.google.api.services.cloudresourcemanager.model.ListProjectsResponse#setProjects() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectRepositoryTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetProjects_pagination() throws IOException, ProjectRepositoryException {
  Projects.List list = initializeListRequest();
  ListProjectsResponse response1 = new ListProjectsResponse();
  response1.setProjects(Collections.singletonList(project));
  response1.setNextPageToken("a token");
  
  ListProjectsResponse response2 = new ListProjectsResponse();
  Project project2 = new Project();
  project2.setName("project 2").setProjectId("project_2");
  response2.setProjects(Collections.singletonList(project2));
  
  when(list.execute()).thenReturn(response1, response2);

  List<GcpProject> gcpProjects = repository.getProjects(mock(Credential.class));

  assertThat(gcpProjects.size(), is(2));
  GcpProject gcpProject = gcpProjects.get(0);
  assertThat(gcpProject.getName(), is("projectName"));
  assertThat(gcpProject.getId(), is("projectId"));
  GcpProject gcpProject2 = gcpProjects.get(1);
  assertThat(gcpProject2.getName(), is("project 2"));
  assertThat(gcpProject2.getId(), is("project_2"));
}
 
Example 2
Source File: MiniSelectorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void mockProjectsList(Credential credential, GcpProject... gcpProjects) {
  Projects projectsApi = mock(Projects.class);
  Projects.List listApi = mock(Projects.List.class);
  List<Project> projectsList = new ArrayList<>();
  for (GcpProject gcpProject : gcpProjects) {
    Project project = new Project();
    project.setName(gcpProject.getName());
    project.setProjectId(gcpProject.getId());
    projectsList.add(project);
  }
  ListProjectsResponse response = new ListProjectsResponse();
  response.setProjects(projectsList);
  try {
    doReturn(projectsApi).when(apiFactory).newProjectsApi(credential);
    doReturn(listApi).when(listApi).setPageSize(any(Integer.class));
    doReturn(listApi).when(projectsApi).list();
    doReturn(response).when(listApi).execute();
  } catch (IOException ex) {
    fail(ex.toString());
  }
}
 
Example 3
Source File: RunOptionsDefaultsComponentTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void mockProjectList(Credential credential, GcpProject... gcpProjects)
    throws IOException {
  Projects projectsApi = mock(Projects.class);
  Projects.List listApi = mock(Projects.List.class);
  List<Project> projectsList = new ArrayList<>();
  for (GcpProject gcpProject : gcpProjects) {
    Project project = new Project(); // cannot mock final classes
    project.setName(gcpProject.getName());
    project.setProjectId(gcpProject.getId());
    projectsList.add(project);
  }
  ListProjectsResponse response = new ListProjectsResponse(); // cannot mock final classes
  response.setProjects(projectsList);
  doReturn(projectsApi).when(apiFactory).newProjectsApi(credential);
  doReturn(listApi).when(listApi).setPageSize(anyInt());
  doReturn(listApi).when(projectsApi).list();
  doReturn(response).when(listApi).execute();
}
 
Example 4
Source File: AuthenticatorTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException, GeneralSecurityException {
  idTokenPayload.setAudience(STYX_API_HOSTNAME);
  when(idToken.getPayload()).thenReturn(idTokenPayload);
  when(verifier.verify(anyString())).thenReturn(idToken);

  lenient().when(cloudResourceManager.projects()).thenReturn(projects);

  when(projects.getAncestry(any(), any())).thenReturn(projectsGetAncestry);
  when(iam.projects().serviceAccounts().get(any())).thenReturn(serviceAccountsGet);
  verify(iam).projects();

  mockAncestryResponse(FOO_PROJECT, resourceId(FOO_PROJECT), ORGANIZATION_RESOURCE);
  mockAncestryResponse(BAR_PROJECT, resourceId(BAR_PROJECT), FOLDER_RESOURCE);
  mockAncestryResponse(BAZ_PROJECT, resourceId(BAZ_PROJECT));
  mockAncestryResponse(EXTERNAL_PROJECT, resourceId(EXTERNAL_PROJECT));

  when(projects.list()).thenReturn(projectsList);

  final ListProjectsResponse listProjectsResponse1 = new ListProjectsResponse();
  listProjectsResponse1.setProjects(PROJECTS);
  listProjectsResponse1.setNextPageToken("token");

  final ListProjectsResponse listProjectsResponse2 = new ListProjectsResponse();

  when(projectsList.execute())
      .thenReturn(listProjectsResponse1)
      .thenReturn(listProjectsResponse2);

  validator = new Authenticator(verifier, cloudResourceManager, iam, CONFIGURATION,
      RETRY_WAIT_STRATEGY, RETRY_STOP_STRATEGY);
  validator.cacheResources();
}
 
Example 5
Source File: ProjectRepositoryTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProjects_successful() throws IOException, ProjectRepositoryException {
  Projects.List list = initializeListRequest();
  ListProjectsResponse response = new ListProjectsResponse();
  response.setProjects(Collections.singletonList(project));
  when(list.execute()).thenReturn(response);

  List<GcpProject> gcpProjects = repository.getProjects(mock(Credential.class));

  assertNotNull(gcpProjects);
  assertThat(gcpProjects.size(), is(1));
  GcpProject gcpProject = gcpProjects.get(0);
  assertThat(gcpProject.getName(), is("projectName"));
  assertThat(gcpProject.getId(), is("projectId"));
}
 
Example 6
Source File: ProjectRepositoryTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProjects_null() throws IOException, ProjectRepositoryException {
  Projects.List list = initializeListRequest();
  ListProjectsResponse response = new ListProjectsResponse();
  response.setProjects(null);
  when(list.execute()).thenReturn(response);

  List<GcpProject> gcpProjects = repository.getProjects(mock(Credential.class));

  assertNotNull(gcpProjects);
}
 
Example 7
Source File: ProjectRepositoryTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetProjects_onlyDeletedProjectsReturned()
    throws IOException, ProjectRepositoryException {
  Projects.List list = initializeListRequest();
  ListProjectsResponse response = new ListProjectsResponse();
  response.setProjects(Collections.singletonList(project));
  project.setLifecycleState("DELETE_REQUESTED");
  when(list.execute()).thenReturn(response);

  List<GcpProject> gcpProjects = repository.getProjects(mock(Credential.class));

  assertNotNull(gcpProjects);
  assertTrue(gcpProjects.isEmpty());
}