Refine search
@Test public void set_project_version() { String version = randomAlphanumeric(5); underTest.setProjectVersion(version); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isEqualTo(version); }
@Test public void getETag_should_return_same_value_for_same_input() { String input = randomAlphanumeric(200); assertThat(ETagUtils.getETag(input)).isEqualTo(ETagUtils.getETag(input)); } }
@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 isEditionBundled_on_Plugin_returns_false_for_SonarSource_and_non_commercial_license() { Plugin plugin = newPlugin(randomizeCase("SonarSource"), randomAlphanumeric(3)); assertThat(EditionBundledPlugins.isEditionBundled(plugin)).isFalse(); }
@Test public void isEditionBundled_on_PluginInfo_returns_false_for_license_Commercial_and_non_SonarSource_organization() { PluginInfo pluginInfo = newPluginInfo(randomAlphanumeric(3), randomizeCase("Commercial")); assertThat(EditionBundledPlugins.isEditionBundled(pluginInfo)).isFalse(); }
@Test public void newProperties_constructor_fails_with_IAE_if_workerUuid_is_41_or_more() { String workerUuid = RandomStringUtils.randomAlphanumeric(41 + new Random().nextInt(5)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("worker uuid is too long: " + workerUuid); new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, workerUuid, 123, 456); }
@Test public void isEditionBundled_on_Plugin_returns_false_for_license_Commercial_and_non_SonarSource_organization() { Plugin plugin = newPlugin(randomAlphanumeric(3), randomizeCase("Commercial")); assertThat(EditionBundledPlugins.isEditionBundled(plugin)).isFalse(); }
@Test public void createComponentKey_fails_with_IAE_if_characteristics_is_not_empty_and_deprecatedBranchName_is_non_null() { String projectKey = randomAlphanumeric(12); String deprecatedBranchName = randomAlphanumeric(13); Map<String, String> nonEmptyMap = newRandomNonEmptyMap(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Deprecated branch feature can't be used at the same time as new branch support"); underTestWithBranch.createComponentKey(projectKey, deprecatedBranchName, nonEmptyMap); }
@Test public void createComponentKey_delegates_to_delegate_if_characteristics_is_not_empty() { String projectKey = randomAlphanumeric(12); Map<String, String> nonEmptyMap = newRandomNonEmptyMap(); ComponentKey expected = mock(ComponentKey.class); when(branchSupportDelegate.createComponentKey(projectKey, nonEmptyMap)).thenReturn(expected); ComponentKey componentKey = underTestWithBranch.createComponentKey(projectKey, null, nonEmptyMap); assertThat(componentKey).isSameAs(expected); }
@Test public void remove_should_remove_value() { String key = randomAlphanumeric(10); String childValue = randomAlphanumeric(10); underTest.set(key, childValue); assertThat(underTest.get(key)).isEqualTo(Optional.of(childValue)); underTest.remove(key); assertThat(underTest.get(key)).isEqualTo(Optional.empty()); }
@Test public void constructor_throws_NPE_if_project_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("project can't be null"); new RekeyedProject(null, randomAlphanumeric(3)); }
@Test public void get_returns_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); String key = randomAlphanumeric(3); doThrow(toBeThrown).when(settingLoaderMock).load(key); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); assertThat(underTest.get(key)).isEmpty(); }
@Test public void set_will_throw_NPE_if_value_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("value can't be null"); underTest.set(randomAlphanumeric(10), null); }
@Test public void constructor_throws_ISE_if_node_port_property_is_not_set() { mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(23)); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Property sonar.cluster.node.port is not defined"); new NodeHealthProviderImpl(mapSettings.asConfig(), healthChecker, server, networkUtils); }
@Test public void update_uuid_when_login_is_present() throws SQLException { String login1 = insertUser(NO_UUID, randomAlphanumeric(10)); String login2 = insertUser(NO_UUID, randomAlphanumeric(10)); String login3 = insertUser(NO_UUID, randomAlphanumeric(10)); underTest.execute(); assertUser( tuple(login1, login1, PAST, NOW), tuple(login2, login2, PAST, NOW), tuple(login3, login3, PAST, NOW) ); }
@Test public void get_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); String key = randomAlphanumeric(3); doThrow(toBeThrown).when(settingLoaderMock).load(key); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); underTest.load(); assertThat(underTest.get(key)).isEmpty(); }
@Test public void execute_deletes_rows_of_component_without_qualifier_PRJ() throws SQLException { String scope = randomAlphanumeric(3); insertUserRole(insertComponent(scope, QUALIFIER_TRK)); insertUserRole(insertComponent(scope, QUALIFIER_VW)); insertUserRole(insertComponent(scope, randomAlphanumeric(3))); assertThat(db.countRowsOfTable(TABLE_USER_ROLES)).isEqualTo(3); underTest.execute(); assertThat(db.countRowsOfTable(TABLE_USER_ROLES)).isEqualTo(0); }
@Test public void analysisDate_and_analysisUuid_comes_from_AnalysisMetadataHolder_when_set() { analysisMetadataHolder.setAnalysisDate(8465132498L); analysisMetadataHolder.setUuid(RandomStringUtils.randomAlphanumeric(40)); underTest.finished(true); verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture()); assertThat(projectAnalysisArgumentCaptor.getValue().getAnalysis().get().getDate()) .isEqualTo(new Date(analysisMetadataHolder.getAnalysisDate())); assertThat(projectAnalysisArgumentCaptor.getValue().getAnalysis().get().getAnalysisUuid()) .isEqualTo(analysisMetadataHolder.getUuid()); }
@Test public void add_does_not_count_tags_if_empty_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(Collections.emptyList()).setAssigneeUuid(assignee).setNew(new Random().nextBoolean())); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { assertThat(distribution.getTotal()).isEqualTo(0); assertThat(distribution.getForLabel(null).isPresent()).isFalse(); }); }
@Test public void set_accepts_empty_value_and_trims_it() { MapSettings underTest = new MapSettings(); Random random = new Random(); String key = randomAlphanumeric(3); underTest.set(key, blank(random)); assertThat(underTest.getString(key)).isEmpty(); }