@Test public void fail_when_component_is_not_a_project() { UserDto user = db.users().insertUser(); userSession.logIn(user); db.components().insertViewAndSnapshot(newView(db.organizations().insert()).setDbKey("VIEW_1")); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Component 'VIEW_1' must be a project"); call(NOTIF_MY_NEW_ISSUES, null, "VIEW_1", null); }
@Test public void fail_when_component_is_not_a_project() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); db.components().insertViewAndSnapshot(newView(db.organizations().insert()).setDbKey("VIEW_1")); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Component 'VIEW_1' must be a project"); call(request.setProject("VIEW_1")); }
@Test public void return_projects_composing_a_view() { ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); db.components().insertProjectAndSnapshot(project); ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); db.components().insertViewAndSnapshot(view); db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); userSession.logIn() .registerComponents(project, view); TreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_ID, view.uuid()).executeProtobuf(TreeWsResponse.class); assertThat(response.getBaseComponent().getId()).isEqualTo(view.uuid()); assertThat(response.getComponentsCount()).isEqualTo(1); assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid"); assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid"); }
@Test public void fail_if_create_on_view() { ComponentDto view = newView(db.organizations().insert()); SnapshotDto analysis = db.components().insertViewAndSnapshot(view); logInAsProjectAdministrator(view); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("An event must be created on a project or an application"); call(OTHER.name(), "View Event", analysis.getUuid()); }
@Test public void fail_if_create_version_event_on_application() { ComponentDto application = newApplication(db.organizations().insert()); SnapshotDto analysis = db.components().insertViewAndSnapshot(application); logInAsProjectAdministrator(application); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("A version event must be created on a project"); call(VERSION.name(), "5.6.3", analysis.getUuid()); }
@Test public void select_descendants_of_a_view_and_filter_by_name() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto view = newView(organizationDto, A_VIEW_UUID); db.components().insertViewAndSnapshot(view); // one subview ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name"); db.components().insertComponent(subView); // one project and its copy linked to the view ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name"); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build(); List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid()); }
@Test public void project_reference_from_portfolio() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto view = newView(organizationDto, "view-uuid"); db.components().insertViewAndSnapshot(view); ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid-1").setName("project-name").setDbKey("project-key-1"); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project, view)); db.components().insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name")); db.commit(); userSession.logIn() .registerComponents(view, project); TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "children") .setParam(PARAM_COMPONENT_ID, "view-uuid") .setParam(Param.TEXT_QUERY, "name").executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsList()).extracting("id").containsExactly("project-uuid-1-copy", "sub-view-uuid"); assertThat(response.getComponentsList()).extracting("refId").containsExactly("project-uuid-1", ""); assertThat(response.getComponentsList()).extracting("refKey").containsExactly("project-key-1", ""); }