public static ProjectState buildDefaultProjectInstance() { ProjectState project = new ProjectState(); project.documentSelfLink = DEFAULT_PROJECT_LINK; project.name = DEFAULT_PROJECT_ID; project.id = project.name; project.customProperties = new HashMap<>(); project.customProperties.put(CUSTOM_PROPERTY_PROJECT_INDEX, DEFAULT_PROJECT_INDEX); return project; }
@Test public void testGetHarborId() { ProjectState state = new ProjectState(); state.customProperties = null; assertNull(ProjectUtil.getProjectIndex(state)); state.customProperties = new HashMap<>(); assertNull(ProjectUtil.getProjectIndex(state)); String projectId = "" + new Random().nextInt(1000); state.customProperties.put(ProjectService.CUSTOM_PROPERTY_PROJECT_INDEX, projectId); assertEquals(projectId, ProjectUtil.getProjectIndex(state)); } }
@Test public void testProjectSelfLinkShouldBeRemovedFromTenantLinksSingleProject() throws Throwable { ProjectState projectState = new ProjectState(); projectState.name = "test-project"; projectState = doPost(projectState, ProjectFactoryService.SELF_LINK); List<String> tenantLinks = new ArrayList<String>(); tenantLinks.add("project1"); tenantLinks.add("project2"); tenantLinks.add(projectState.documentSelfLink); projectState.tenantLinks = tenantLinks; doPatch(projectState, projectState.documentSelfLink); host.registerForServiceAvailability(ProjectsTransformationBootstrapService.startTask(host), true, ProjectsTransformationBootstrapService.FACTORY_LINK); String projectSelfLink = projectState.documentSelfLink; waitFor(() -> { ProjectState state = getDocument(ProjectState.class, projectSelfLink); return !state.tenantLinks.contains(state.documentSelfLink); }); }
@Test public void testProjectNameIsUnclaimedAfterUpdateOrDelete() throws Throwable { ProjectState project = createProject("test-name"); assertNotNull(project.documentSelfLink); ProjectState project1 = new ProjectState(); project1.name = "new-name"; project = patchProject(project1, project.documentSelfLink); assertEquals(project1.name, project.name); project1 = createProject("test-name"); assertNotNull(project1.documentSelfLink); deleteProject(project1); project1 = createProject("test-name"); assertNotNull(project1.documentSelfLink); ProjectState projectPut = new ProjectState(); projectPut.name = "updated-name"; projectPut.documentSelfLink = project1.documentSelfLink; updateProject(projectPut); project1 = createProject("test-name"); assertNotNull(project1.documentSelfLink); }
private void createProject(ProjectContentBody projectContent, Runnable callback) { ProjectState state = new ProjectState(); state.name = projectContent.name; state.description = projectContent.description; state.isPublic = projectContent.isPublic; sendRequest(Operation.createPost(this, ProjectFactoryService.SELF_LINK) .setBody(state) .setReferer(getHost().getUri()) .setCompletion((o, ex) -> { if (ex != null) { logWarning("Failed to create project: %s", Utils.toString(ex)); callback.run(); } else { ProjectState created = o.getBody(ProjectState.class); updateProjectWithMembers(created, projectContent, callback); } })); }
@Test public void testProjectAdminRestrictionsToProjectsHeDoesNotBelongToAsAdmin() throws Throwable { ProjectState project = new ProjectState(); project.name = "test-name"; host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); ProjectState createdState = doPost(project, ProjectFactoryService.SELF_LINK); assertNotNull(createdState); assertNotNull(createdState.documentSelfLink); host.assumeIdentity(buildUserServicePath(USER_EMAIL_GLORIA)); // POST project.name = "test.name"; doPostWithRestrictionVerification(project, ProjectFactoryService.SELF_LINK); // PUT createdState.name = "updated-name"; doPutWithRestrictionVerification(createdState, ProjectFactoryService.SELF_LINK); // DELETE doDeleteWithRestrictionVerification(createdState, ProjectFactoryService.SELF_LINK); }
@Test public void testPut() throws Throwable { final String updatedName = "updated-name"; final String updatedDescription = "updatedDescription"; final boolean updatedIsPublic = !PROJECT_IS_PUBLIC; ProjectState updateState = new ProjectState(); updateState.name = updatedName; updateState.description = updatedDescription; updateState.isPublic = updatedIsPublic; updateState.documentSelfLink = project.documentSelfLink; ProjectState updatedState = updateProject(updateState); assertEquals(updatedName, updatedState.name); assertEquals(updatedDescription, updatedState.description); assertEquals(updatedIsPublic, updatedState.isPublic); }
@Test public void testPatchProjectWithDuplicateNameShouldFail() throws Throwable { createProject("test-name"); ProjectState testProject = createProject("test-name-1"); ProjectState state = new ProjectState(); state.name = "test-name"; state.documentSelfLink = testProject.documentSelfLink; try { patchProject(state, state.documentSelfLink); fail("Project update with same name should've failed"); } catch (Exception ex) { assertTrue(ex.getCause() instanceof IllegalStateException); assertTrue(ex.getMessage().contains("test-name")); } }
@Test public void testPropertiesValidationOnUpdate() throws Throwable { ProjectState updateState = new ProjectState(); updateState.documentSelfLink = project.documentSelfLink; try { updateProject(updateState); fail("Update of project should have failed due to invalid name"); } catch (AssertionError e) { e.printStackTrace(); throw e; } catch (LocalizableValidationException e) { verifyExceptionMessage(String.format(AssertUtil.PROPERTY_CANNOT_BE_NULL_MESSAGE_FORMAT, ProjectState.FIELD_NAME_NAME), e.getMessage()); } }
@Test public void testUpdateProjectWithDuplicateNameShouldFail() throws Throwable { createProject("test-name"); ProjectState testProject = createProject("test-name-1"); ProjectState state = new ProjectState(); state.name = "test-name"; state.documentSelfLink = testProject.documentSelfLink; try { updateProject(state); fail("Project update with same name should've failed"); } catch (Exception ex) { assertTrue(ex instanceof IllegalStateException); assertTrue(ex.getMessage().contains("test-name")); } }
@Test public void testProjectMemberCannotModifyProject() throws Throwable { host.assumeIdentity(buildUserServicePath(USER_EMAIL_TONY)); String projectLink = getProjectLinkByName(PROJECT_NAME_TEST_PROJECT_1); ProjectState project = new ProjectState(); project.name = "test-name"; try { doPatch(project, projectLink); fail(EXPECTED_ILLEGAL_ACCESS_ERROR_MESSAGE); } catch (IllegalAccessError e) { assertForbiddenMessage(e); } }
protected ProjectState createProjectExpectFailure(String name) throws Throwable { ProjectState state = new ProjectState(); state.name = name; state = doOperation(state, UriUtils.buildUri(host, ProjectFactoryService.SELF_LINK), ProjectState.class, true, Action.POST); return state; }
@Test public void testUpdateProjectCustomProperty() throws Throwable { final String updatedValA = CUSTOM_PROP_VAL_A + "-updated"; ProjectState patchState = new ProjectState(); patchState.customProperties = createCustomPropertiesMap(CUSTOM_PROP_KEY_A, updatedValA); ProjectState updatedProject = doPatch(patchState, project.documentSelfLink); assertNotNull(updatedProject.customProperties); assertEquals(3, updatedProject.customProperties.size()); assertEquals(updatedValA, updatedProject.customProperties.get(CUSTOM_PROP_KEY_A)); assertEquals(CUSTOM_PROP_VAL_B, updatedProject.customProperties.get(CUSTOM_PROP_KEY_B)); }
@Test public void testSetCustomPropertyOnExistingProject() throws Throwable { project = createProject("test-name1"); ProjectState patchState = new ProjectState(); patchState.customProperties = createCustomPropertiesMap(CUSTOM_PROP_KEY_A, CUSTOM_PROP_VAL_A); project = doPatch(patchState, project.documentSelfLink); assertNotNull(project.customProperties); assertEquals(2, project.customProperties.size()); assertEquals(CUSTOM_PROP_VAL_A, project.customProperties.get(CUSTOM_PROP_KEY_A)); }
@Test public void testPutWithSameName() throws Throwable { final String updatedDescription = "updatedDescription"; final boolean updatedIsPublic = !PROJECT_IS_PUBLIC; ProjectState updateState = new ProjectState(); updateState.name = project.name; updateState.description = updatedDescription; updateState.isPublic = updatedIsPublic; updateState.documentSelfLink = project.documentSelfLink; ProjectState updatedState = updateProject(updateState); assertEquals(updatedDescription, updatedState.description); assertEquals(updatedIsPublic, updatedState.isPublic); }
@Test public void testProjectAdminCanModifyProject() throws Throwable { host.assumeIdentity(buildUserServicePath(USER_EMAIL_FRITZ)); String projectLink = getProjectLinkByName(PROJECT_NAME_TEST_PROJECT_1); ProjectState project = new ProjectState(); project.name = "test-name"; doPatch(project, projectLink); }
@Test public void testPropertiesValidationOnPatch() throws Throwable { ProjectState patchState = new ProjectState(); ProjectState patchedState = patchProject(patchState, project.documentSelfLink); assertEquals(PROJECT_NAME, patchedState.name); assertEquals(PROJECT_DESCRIPTION, patchedState.description); assertEquals(PROJECT_IS_PUBLIC, patchedState.isPublic); }
@Test public void testPostUpgradeDefaultProject() throws Throwable { ProjectState projectState = new ProjectState(); projectState.name = "test"; projectState.documentSelfLink = ProjectService.DEFAULT_PROJECT_LINK; projectState.administratorsUserGroupLink = "test"; ProjectState updatedState = doPost(projectState, ProjectFactoryService.SELF_LINK); assertNull(updatedState.administratorsUserGroupLink); }
private ProjectState createProject(String name) throws Throwable { ProjectState state = new ProjectState(); state.name = name; return doPost(state, ProjectFactoryService.SELF_LINK); }
public static ProjectState copyOf(ProjectState source) { if (source == null) { return null; } ProjectState result = new ProjectState(); source.copyTo(result); return result; } }