@Test public void hasProjectSubscribersForType() { setUpMocks(); PropertiesDao dao = mock(PropertiesDao.class); when(dbClient.propertiesDao()).thenReturn(dao); // no subscribers when(dao.hasProjectNotificationSubscribersForDispatchers( "PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))) .thenReturn(false); assertThat( service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))) .isFalse(); // has subscribers on one dispatcher (among the two) when(dao.hasProjectNotificationSubscribersForDispatchers( "PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))) .thenReturn(true); assertThat( service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))) .isTrue(); }
@Test public void app() throws Exception { userSessionRule .login("john") .addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, COMPONENT_KEY); ComponentDto project = newProject(); ComponentDto file = ComponentTesting.newFileDto(project) .setId(10L) .setKey(COMPONENT_KEY) .setUuid(COMPONENT_UUID) .setName("Plugin.java") .setProjectUuid("THE_PROJECT") .setLongName("src/main/java/org/sonar/api/Plugin.java") .setPath("src/main/java/org/sonar/api/Plugin.java") .setParentProjectId(5L); when(componentDao.selectByUuid(session, COMPONENT_UUID)).thenReturn(Optional.of(file)); when(componentDao.selectOrFailById(session, 5L)) .thenReturn( new ComponentDto() .setId(5L) .setLongName("SonarQube :: Plugin API") .setKey(SUB_PROJECT_KEY)); when(componentDao.selectOrFailByUuid(session, project.uuid())).thenReturn(project); when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))) .thenReturn(newArrayList(new PropertyDto())); WsTester.TestRequest request = tester.newGetRequest("api/components", "app").setParam("uuid", COMPONENT_UUID); request.execute().assertJson(getClass(), "app.json"); }
@Test public void project_settings_override_global_settings() { settings.setProperty("key", "value"); when(dao.selectProjectProperties(PROJECT_KEY)) .thenReturn(newArrayList(new PropertyDto().setKey("key").setValue("value2"))); Settings projectSettings = underTest.newProjectSettings(PROJECT_KEY); assertThat(projectSettings.getString("key")).isEqualTo("value2"); }
@Test public void return_project_settings() { when(dao.selectProjectProperties(PROJECT_KEY)) .thenReturn( newArrayList( new PropertyDto().setKey("1").setValue("val1"), new PropertyDto().setKey("2").setValue("val2"), new PropertyDto().setKey("3").setValue("val3"))); Settings projectSettings = underTest.newProjectSettings(PROJECT_KEY); assertThat(projectSettings.getString("1")).isEqualTo("val1"); assertThat(projectSettings.getString("2")).isEqualTo("val2"); assertThat(projectSettings.getString("3")).isEqualTo("val3"); }
@Test public void return_global_settings() throws Exception { userSessionRule.setGlobalPermissions( GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.PREVIEW_EXECUTION); when(propertiesDao.selectGlobalProperties(session)) .thenReturn( newArrayList( new PropertyDto().setKey("foo").setValue("bar"), new PropertyDto().setKey("foo.secured").setValue("1234"), new PropertyDto().setKey("foo.license.secured").setValue("5678"))); WsTester.TestRequest request = tester.newGetRequest("batch", "global"); request.execute().assertJson(getClass(), "return_global_settings.json"); }
@Test public void access_forbidden_without_scan_and_preview_permission() throws Exception { userSessionRule.setGlobalPermissions(); when(propertiesDao.selectGlobalProperties(session)) .thenReturn( newArrayList( new PropertyDto().setKey("foo").setValue("bar"), new PropertyDto().setKey("foo.secured").setValue("1234"), new PropertyDto().setKey("foo.license.secured").setValue("5678"))); thrown.expect(ForbiddenException.class); tester.newGetRequest("batch", "global").execute(); }