Refine search
private void assertProperties(String... expectedSettingKeys) { assertThat(db.select("SELECT PROP_KEY FROM PROPERTIES") .stream() .map(map -> (String)map.get("PROP_KEY")) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedSettingKeys); }
@Test public void keys_whose_length_is_lower_than_40_should_not_be_updated() throws SQLException { // Create 10 permission templates with keys' length lower or equals than 40 List<String> correctKeys = IntStream.range(0, 10) .mapToObj(i -> insertTemplate(randomAlphanumeric(RANDOM.nextInt(41)))) .collect(toList()); underTest.execute(); assertThat(UUID_FACTORY.getRecordedUuids()).hasSize(0); List<String> kees = dbTester.select("select kee from permission_templates").stream() .map(r -> (String) r.get("KEE")).collect(toList()); assertThat(kees).containsExactlyInAnyOrder(correctKeys.toArray(new String[] {})); }
@Test public void selectForIndexing_project() { assertSelectForIndexing("U1") .doesNotContain("DIS7") .doesNotContain("COPY8") .containsExactlyInAnyOrder("U1", "U2", "U3", "U4"); }
@Test public void shouldDefineMultiModuleProjectWithPomFileAtRootLevel() throws IOException { ProjectDefinition project = execMultiModule("multi-module-pom-in-root"); assertThat(project.sources()).containsExactlyInAnyOrder("pom.xml", "sources"); }
@Test public void selectForIndexing_all() { assertSelectForIndexing(null) .doesNotContain("DIS7") .doesNotContain("COPY8") .containsExactlyInAnyOrder("U1", "U2", "U3", "U4", "U5", "U6", "VW1"); }
private void assertConditions(Long... expectedIds) { assertThat(db.select("SELECT id FROM quality_gate_conditions") .stream() .map(row -> (long) row.get("ID")) .collect(toList())) .containsExactlyInAnyOrder(expectedIds); }
@Test public void keys_whose_length_is_greater_than_40_should_be_updated() throws SQLException { // Create 10 permission templates with keys' length greater or equals than 40 List<String> tooLongKeys = IntStream.range(0, 10) .mapToObj(i -> insertTemplate(randomAlphanumeric(41 + RANDOM.nextInt(60)))) .collect(toList()); underTest.execute(); assertThat(UUID_FACTORY.getRecordedUuids()).hasSize(tooLongKeys.size()); List<String> kees = dbTester.select("select kee from permission_templates").stream() .map(r -> (String) r.get("KEE")).collect(toList()); assertThat(kees).containsExactlyInAnyOrder(UUID_FACTORY.getRecordedUuids().toArray(new String[] {})); }
private void assertProjectBranches(Tuple... expectedTuples) { assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, BRANCH_TYPE, CREATED_AT, UPDATED_AT FROM PROJECT_BRANCHES") .stream() .map(row -> new Tuple(row.get("KEE"), row.get("UUID"), row.get("PROJECT_UUID"), row.get("BRANCH_TYPE"), row.get("CREATED_AT"), row.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }
@Test public void createWebCommand_adds_configured_jdbc_driver_to_classpath() throws Exception { Properties props = new Properties(); File driverFile = temp.newFile(); props.setProperty("sonar.jdbc.driverPath", driverFile.getAbsolutePath()); JavaCommand command = newFactory(props).createWebCommand(true); assertThat(command.getClasspath()) .containsExactlyInAnyOrder("./lib/common/*", driverFile.getAbsolutePath()); }
private void assertPermTemplateUserRoles(Tuple... expectedTuples) { assertThat(db.select("SELECT TEMPLATE_ID, USER_ID, PERMISSION_REFERENCE, CREATED_AT, UPDATED_AT FROM PERM_TEMPLATES_USERS") .stream() .map(map -> new Tuple(map.get("TEMPLATE_ID"), map.get("USER_ID"), map.get("PERMISSION_REFERENCE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }
@Test public void redirect_when_failing_because_of_Exception() throws Exception { FailWithIllegalStateException identityProvider = new FailWithIllegalStateException(); when(request.getRequestURI()).thenReturn("/oauth2/callback/" + identityProvider.getKey()); identityProviderRepository.addIdentityProvider(identityProvider); underTest.doFilter(request, response, chain); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(logTester.logs(LoggerLevel.WARN)).containsExactlyInAnyOrder("Fail to callback authentication with 'failing'"); verify(oAuthRedirection).delete(eq(request), eq(response)); }
private void assertPermTemplateCharacteristics(Tuple... expectedTuples) { assertThat(db.select("SELECT TEMPLATE_ID, PERMISSION_KEY, WITH_PROJECT_CREATOR, CREATED_AT, UPDATED_AT FROM PERM_TPL_CHARACTERISTICS") .stream() .map(map -> new Tuple(map.get("TEMPLATE_ID"), map.get("PERMISSION_KEY"), map.get("WITH_PROJECT_CREATOR"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }
@Test public void log_warning_when_login_is_null() throws SQLException { insertUser(null, "user", "bitbucket"); long id = (long) db.selectFirst("SELECT ID FROM USERS").get("ID"); underTest.execute(); assertThat(logTester.logs(LoggerLevel.WARN)) .containsExactlyInAnyOrder(format("No login has been found for user id '%s'. A UUID has been generated to not have null value.", id)); }
private void assertProjectBranches(Tuple... expectedTuples) { assertThat(db.select("SELECT KEE, UUID, PROJECT_UUID, BRANCH_TYPE, CREATED_AT, UPDATED_AT FROM PROJECT_BRANCHES") .stream() .map(map -> new Tuple(map.get("KEE"), map.get("UUID"), map.get("PROJECT_UUID"), map.get("BRANCH_TYPE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }
@Test public void test_errorTypes() { assertThat(underTest.getErrorTypes()).isNull(); underTest.setErrorTypes(asList("foo", "bar")); assertThat(underTest.getErrorTypes()).containsExactlyInAnyOrder("foo", "bar"); }
private void assertPermTemplateGroupRoles(Tuple... expectedTuples) { assertThat(db.select("SELECT TEMPLATE_ID, GROUP_ID, PERMISSION_REFERENCE, CREATED_AT, UPDATED_AT FROM PERM_TEMPLATES_GROUPS") .stream() .map(map -> new Tuple(map.get("TEMPLATE_ID"), map.get("GROUP_ID"), map.get("PERMISSION_REFERENCE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); } }
@Test public void getFiles() { assertThat(fileResult.getFiles()).isEmpty(); File file1 = new File("file1.txt"); File file2 = new File("file2.txt"); fileResult.addFile(file1); fileResult.addFile(file2); assertThat(fileResult.getFiles()).containsExactlyInAnyOrder(file1, file2); } }
private void assertOrganizations(Tuple... expectedTuples) { assertThat(db.select("SELECT uuid, default_perm_template_view, default_perm_template_app, default_perm_template_port, updated_at FROM organizations") .stream() .map(row -> new Tuple(row.get("UUID"), row.get("DEFAULT_PERM_TEMPLATE_VIEW"), row.get("DEFAULT_PERM_TEMPLATE_APP"), row.get("DEFAULT_PERM_TEMPLATE_PORT"), row.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }
@Test public void redirect_when_failing_because_of_Exception() throws Exception { IdentityProvider identityProvider = new FailWithIllegalStateException("failing"); when(request.getRequestURI()).thenReturn("/sessions/init/" + identityProvider.getKey()); identityProviderRepository.addIdentityProvider(identityProvider); underTest.doFilter(request, response, chain); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(logTester.logs(LoggerLevel.WARN)).containsExactlyInAnyOrder("Fail to initialize authentication with provider 'failing'"); verifyDeleteAuthCookie(); }
private void assertPermTemplateGroupRoles(Tuple... expectedTuples) { assertThat(db.select("SELECT TEMPLATE_ID, GROUP_ID, PERMISSION_REFERENCE, CREATED_AT, UPDATED_AT FROM PERM_TEMPLATES_GROUPS") .stream() .map(map -> new Tuple(map.get("TEMPLATE_ID"), map.get("GROUP_ID"), map.get("PERMISSION_REFERENCE"), map.get("CREATED_AT"), map.get("UPDATED_AT"))) .collect(Collectors.toList())) .containsExactlyInAnyOrder(expectedTuples); }