private void insertEvent() { db.executeInsert( "events", "UUID", randomAlphabetic(5), "ANALYSIS_UUID", randomAlphabetic(5), "COMPONENT_UUID", randomAlphabetic(5), "EVENT_DATE", random.nextInt(), "CREATED_AT", random.nextInt()); } }
private void insertGroupRole(long componentId) { db.executeInsert( TABLE_GROUP_ROLES, "ORGANIZATION_UUID", randomAlphabetic(3), "RESOURCE_ID", valueOf(componentId), "ROLE", randomAlphabetic(4)); }
private void insertSnapshot(String componentUuid) { db.executeInsert( TABLE_SNAPSHOTS, "UUID", randomAlphabetic(4), "COMPONENT_UUID", componentUuid, "STATUS", randomAlphabetic(3), "ISLAST", valueOf(random.nextBoolean())); }
@DataProvider public static Object[][] validOldFormatServerIds() { return new Object[][] { {UuidFactoryImpl.INSTANCE.create()}, {randomAlphabetic(NOT_UUID_DATASET_ID_LENGTH)}, {repeat(SPLIT_CHARACTER + "", NOT_UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(UUID_DATASET_ID_LENGTH)}, {repeat(SPLIT_CHARACTER + "", UUID_DATASET_ID_LENGTH)} }; }
private String insertEvent(String analysisUuid, @Nullable String componentUuid) { String uuid = randomAlphabetic(5); db.executeInsert( TABLE_EVENTS, "UUID", uuid, "ANALYSIS_UUID", analysisUuid, "COMPONENT_UUID", componentUuid, "EVENT_DATE", random.nextInt(), "CREATED_AT", random.nextInt()); return uuid; }
@DataProvider public static Object[][] previousVersionOrVersion() { return new Object[][] { {"previous_version"}, {randomAlphabetic(3)} }; }
@DataProvider public static Object[][] stringConsideredAsVersions() { return new Object[][] { {RandomStringUtils.randomAlphabetic(5)}, {"1,3"}, {"1.3"}, {"0 1"}, {"1-SNAPSHOT"}, {"01-12-2018"}, // unsupported date format }; }
@Test public void getServerBaseUrl_returns_property_value() { String expected = RandomStringUtils.randomAlphabetic(15); settings.setProperty(SERVER_BASE_URL, expected); assertThat(underTest.getServerBaseURL()).isEqualTo(expected); }
@Test public void getLoggerName_returns_name_passed_to_builder() { String rootLoggerName = RandomStringUtils.randomAlphabetic(32); LogLevelConfig logLevelConfig = newBuilder(rootLoggerName).build(); assertThat(logLevelConfig.getRootLoggerName()).isEqualTo(rootLoggerName); }
@Test public void dumpAsCsv_has_no_effect_if_configuration_is_empty() throws IOException { String taskUuid = randomAlphabetic(6); when(ceTask.getUuid()).thenReturn(taskUuid); underTest.dumpAsCsv(A_SCORE_MATRIX); assertThat(listDumpFilesForTaskUuid(taskUuid)).isEmpty(); }
@Test public void execute_does_not_delete_roles_of_children_of_developer() throws SQLException { String devUuid = insertComponent(SCOPE_PROJECT, QUALIFIER_DEVELOPER, null); String childUuid = insertComponent(randomAlphabetic(3), randomAlphabetic(3), devUuid); long childId = idOfComponent(childUuid); insertUserRole(childId); insertGroupRole(childId); underTest.execute(); assertThat(db.countRowsOfTable(TABLE_GROUP_ROLES)).isEqualTo(1); assertThat(db.countRowsOfTable(TABLE_USER_ROLES)).isEqualTo(1); }
@Test public void add_counts_issue_per_tags_on_leak_globally_and_per_assignee() { List<String> tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(tags).setAssigneeUuid(assignee).setNew(true)); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> tags.forEach(tag -> assertStats(distribution, tag, 1, 0, 1))); }
@Test public void of_throws_NPE_if_datasetId_is_null() { expectedException.expect(NullPointerException.class); ServerId.of(randomAlphabetic(DATABASE_ID_LENGTH), null); }
public static ProjectLinkDto newCustomLinkDto() { String nameAndType = randomAlphabetic(20); return newCommonLinkDto() .setName(nameAndType) .setType(nameAndType); }
@Test public void check_fails_with_ISE_if_thread_is_executing_a_CeTask_but_on_start_has_not_been_called_on_it() { String taskUuid = randomAlphabetic(15); Thread t = new Thread(); mockWorkerOnThread(t, ceWorker); mockWorkerWithTask(ceTask); when(ceTask.getUuid()).thenReturn(taskUuid); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("No start time recorded for task " + taskUuid); underTest.check(t); }
@Test public void execute_populates_components_uuid_of_events_which_analysis_exists() throws SQLException { String componentUuid = "foo"; String existingAnalysisUuid = insertSnapshot(componentUuid); String missingAnalysisUuid = randomAlphabetic(5); String uuid = insertEvent(existingAnalysisUuid, null); insertEvent(missingAnalysisUuid, null); underTest.execute(); assertThat(getAllEventUuids()).containsOnly(uuid); assertThat(getComponentUuidOf(uuid)).isEqualTo(componentUuid); }
@Test public void start_logs_a_warning_if_property_ceWorkerCount_exists_with_a_value() { settings.setProperty(PROPERTY_SONAR_CE_WORKER_COUNT, randomAlphabetic(12)); underTest.start(); verifyWarnMessage(); }
@Test public void project_name_is_loaded_from_report_if_present_and_on_main_branch() { String reportName = randomAlphabetic(5); ScannerReport.Component reportProject = newBuilder() .setType(PROJECT) .setName(reportName) .build(); Component root = newUnderTest(null, true).buildProject(reportProject, NO_SCM_BASE_PATH); assertThat(root.getName()).isEqualTo(reportName); }
@Test public void project_description_is_loaded_from_db_if_not_on_main_branch() { String reportDescription = randomAlphabetic(5); ScannerReport.Component reportProject = newBuilder() .setType(PROJECT) .setDescription(reportDescription) .build(); Component root = newUnderTest(null, false).buildProject(reportProject, NO_SCM_BASE_PATH); assertThat(root.getDescription()).isEqualTo(projectInDb.getDescription()); }
@Test public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() { String componentUuid = randomAlphabetic(3); String mainComponentUuid = randomAlphabetic(4); CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, new Component(componentUuid, mainComponentUuid), "submitter uuid"); UserDto userDto = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit.getSubmitterUuid()); CeTask task = underTest.submit(taskSubmit); verifyCeTask(taskSubmit, task, null, userDto); verifyCeQueueDtoForTaskSubmit(taskSubmit); }