/** * Replaces the attributes of the project with the attributes of this project. * * <p>The caller must have modify permissions for this project. * * @return the Project representing the new project metadata * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/update">Cloud * Resource Manager update</a> */ public Project replace() { return resourceManager.replace(this); }
@Test public void testReplace() { initializeExpectedProject(2); Project expectedReplacedProject = expectedProject.toBuilder().addLabel("k3", "v3").build(); expect(resourceManager.getOptions()).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); }
@Test public void testReplace() { ProjectInfo createdProject = RESOURCE_MANAGER.create(COMPLETE_PROJECT); Map<String, String> newLabels = ImmutableMap.of("new k1", "new v1"); ProjectInfo anotherCompleteProject = ProjectInfo.newBuilder(COMPLETE_PROJECT.getProjectId()) .setLabels(newLabels) .setProjectNumber(987654321L) .setCreateTimeMillis(230682061315L) .setState(ProjectInfo.State.DELETE_REQUESTED) .setParent(createdProject.getParent()) .build(); Project returnedProject = RESOURCE_MANAGER.replace(anotherCompleteProject); compareReadWriteFields(anotherCompleteProject, returnedProject); assertEquals(createdProject.getProjectNumber(), returnedProject.getProjectNumber()); assertEquals(createdProject.getCreateTimeMillis(), returnedProject.getCreateTimeMillis()); assertEquals(createdProject.getState(), returnedProject.getState()); assertEquals(RESOURCE_MANAGER, returnedProject.getResourceManager()); ProjectInfo nonexistantProject = ProjectInfo.newBuilder("some-project-id-that-does-not-exist").build(); try { RESOURCE_MANAGER.replace(nonexistantProject); fail("Should fail because the project doesn't exist."); } catch (ResourceManagerException e) { assertEquals(403, e.getCode()); assertTrue(e.getMessage().contains("the project was not found")); } }
/** * Replaces the attributes of the project with the attributes of this project. * * <p>The caller must have modify permissions for this project. * * @return the Project representing the new project metadata * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/update">Cloud * Resource Manager update</a> */ public Project replace() { return resourceManager.replace(this); }