Beispiel #1
0
 @Test
 public void testReplacePolicy() {
   expect(resourceManager.options()).andReturn(mockOptions).times(1);
   expect(resourceManager.replacePolicy(PROJECT_ID, POLICY)).andReturn(POLICY);
   replay(resourceManager);
   initializeProject();
   assertEquals(POLICY, project.replacePolicy(POLICY));
 }
Beispiel #2
0
 @Test
 public void testUndelete() {
   initializeExpectedProject(1);
   expect(resourceManager.options()).andReturn(mockOptions);
   resourceManager.undelete(PROJECT_INFO.projectId());
   replay(resourceManager);
   initializeProject();
   project.undelete();
 }
Beispiel #3
0
 @Test
 public void testReloadNull() {
   initializeExpectedProject(1);
   expect(resourceManager.options()).andReturn(mockOptions);
   expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
   replay(resourceManager);
   Project reloadedProject =
       new Project(resourceManager, new ProjectInfo.BuilderImpl(PROJECT_INFO)).reload();
   assertNull(reloadedProject);
 }
Beispiel #4
0
 @Test
 public void testBuilder() {
   expect(resourceManager.options()).andReturn(mockOptions).times(7);
   replay(resourceManager);
   Project.Builder builder =
       new Project.Builder(new Project(resourceManager, new ProjectInfo.BuilderImpl("wrong-id")));
   Project project =
       builder
           .projectId(PROJECT_ID)
           .name(NAME)
           .labels(LABELS)
           .projectNumber(PROJECT_NUMBER)
           .createTimeMillis(CREATE_TIME_MILLIS)
           .state(STATE)
           .build();
   assertEquals(PROJECT_ID, project.projectId());
   assertEquals(NAME, project.name());
   assertEquals(LABELS, project.labels());
   assertEquals(PROJECT_NUMBER, project.projectNumber());
   assertEquals(CREATE_TIME_MILLIS, project.createTimeMillis());
   assertEquals(STATE, project.state());
   assertEquals(resourceManager.options(), project.resourceManager().options());
   assertNull(project.parent());
   ResourceId parent = new ResourceId("id", "type");
   project =
       project
           .toBuilder()
           .clearLabels()
           .addLabel("k3", "v3")
           .addLabel("k4", "v4")
           .removeLabel("k4")
           .parent(parent)
           .build();
   assertEquals(PROJECT_ID, project.projectId());
   assertEquals(NAME, project.name());
   assertEquals(ImmutableMap.of("k3", "v3"), project.labels());
   assertEquals(PROJECT_NUMBER, project.projectNumber());
   assertEquals(CREATE_TIME_MILLIS, project.createTimeMillis());
   assertEquals(STATE, project.state());
   assertEquals(resourceManager.options(), project.resourceManager().options());
   assertEquals(parent, project.parent());
 }
Beispiel #5
0
 @Test
 public void testReplace() {
   initializeExpectedProject(2);
   Project expectedReplacedProject = expectedProject.toBuilder().addLabel("k3", "v3").build();
   expect(resourceManager.options()).andReturn(mockOptions).times(2);
   expect(resourceManager.replace(anyObject(Project.class))).andReturn(expectedReplacedProject);
   replay(resourceManager);
   initializeProject();
   Project newProject =
       new Project(resourceManager, new ProjectInfo.BuilderImpl(expectedReplacedProject));
   Project actualReplacedProject = newProject.replace();
   compareProjectInfos(expectedReplacedProject, actualReplacedProject);
 }
Beispiel #6
0
 @Test
 public void testReload() {
   initializeExpectedProject(2);
   ProjectInfo newInfo = PROJECT_INFO.toBuilder().addLabel("k3", "v3").build();
   Project expectedProject =
       new Project(serviceMockReturnsOptions, new ProjectInfo.BuilderImpl(newInfo));
   expect(resourceManager.options()).andReturn(mockOptions);
   expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(expectedProject);
   replay(resourceManager);
   initializeProject();
   Project newProject = project.reload();
   assertEquals(expectedProject, newProject);
 }
Beispiel #7
0
 @Test
 public void testTestPermissions() {
   List<Boolean> response = ImmutableList.of(true, true);
   String getPermission = "resourcemanager.projects.get";
   String deletePermission = "resourcemanager.projects.delete";
   expect(resourceManager.options()).andReturn(mockOptions).times(1);
   expect(
           resourceManager.testPermissions(
               PROJECT_ID, ImmutableList.of(getPermission, deletePermission)))
       .andReturn(response);
   replay(resourceManager);
   initializeProject();
   assertEquals(
       response, project.testPermissions(ImmutableList.of(getPermission, deletePermission)));
 }
Beispiel #8
0
 private void initializeExpectedProject(int optionsCalls) {
   expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls);
   replay(serviceMockReturnsOptions);
   expectedProject =
       new Project(serviceMockReturnsOptions, new ProjectInfo.BuilderImpl(PROJECT_INFO));
 }