@Test public void pathsToAttempt() throws Exception { FileSystem fileSystem = FileSystems.getDefault(); ImmutableSet<Location> locations = ImmutableSet.of( Location.get("/a/b", "c/d/e.proto")); ProfileLoader loader = new ProfileLoader(fileSystem, "android"); assertThat(loader.pathsToAttempt(locations).asMap()).containsExactly( MapEntry.entry(fileSystem.getPath("/a/b"), ImmutableSet.of( "c/d/android.wire", "c/android.wire", "android.wire"))); }
@Test public void stop_must_remove_local_workerUUIDs() { Set<String> connectedClients = new HashSet<>(); connectedClients.add(clientUUID1); connectedClients.add(clientUUID2); connectedClients.add(clientUUID3); Map modifiableWorkerMap = new HashMap(); modifiableWorkerMap.putAll(workerMap); when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients); when(hzClientWrapper.getReplicatedMap(WORKER_UUIDS)).thenReturn(modifiableWorkerMap); CeDistributedInformationImpl ceDistributedInformation = new CeDistributedInformationImpl(hzClientWrapper, mock(CeWorkerFactory.class)); ceDistributedInformation.stop(); assertThat(modifiableWorkerMap).containsExactly( entry(clientUUID2, ImmutableSet.of("3")), entry(clientUUID3, ImmutableSet.of("4", "5", "6"))); } }
@Test public void getAllFailure() throws StoreAccessException { assertThat(strategy.getAllFailure(asList(1, 2), accessException)).containsExactly(entry(1, null), entry(2, null)); @SuppressWarnings("unchecked") ArgumentCaptor<Iterable<Integer>> captor = ArgumentCaptor.forClass(Iterable.class); verify(store).obliterate(captor.capture()); assertThat(captor.getValue()).contains(1, 2); }
@Test public void index_with_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(true); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", true)); }
@Test public void index_without_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(false); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", false)); }
@Test public void submit_task_with_characteristics() { when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), anyMap(), any())).thenReturn(A_CE_TASK); String[] characteristics = {"branch=foo", "pullRequest=123", "unsupported=bar"}; Ce.SubmitResponse submitResponse = tester.newRequest() .setParam("projectKey", "my_project") .setParam("projectName", "My Project") .setMultiParam("characteristic", asList(characteristics)) .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar") .setMethod("POST") .executeProtobuf(Ce.SubmitResponse.class); assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1"); verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), map.capture(), any()); // unsupported characteristics are ignored assertThat(map.getValue()).containsExactly(entry("branch", "foo"), entry("pullRequest", "123")); }
@Test public void should_not_read_hierarchy_if_metadata_available() { when(reader.readMetadata()).thenReturn(ScannerReport.Metadata.newBuilder() .putModulesProjectRelativePathByKey("module1", "path1") .setRootComponentRef(1) .build()); Map<String, String> pathByModuleKey = reportModulesPath.get(); assertThat(pathByModuleKey).containsExactly(entry("module1", "path1")); verify(reader).readMetadata(); verifyNoMoreInteractions(reader); }
@Test public void index_requires_project_authorization() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); index.createType("issue") // creates a second type "authorization" and configures _parent and _routing fields .requireProjectAuthorization(); // issue type NewIndex.NewIndexType issueType = index.getTypes().get("issue"); assertThat(getAttributeAsMap(issueType, "_parent")).containsExactly(entry("type", "authorization")); assertThat(getAttributeAsMap(issueType, "_routing")).containsExactly(entry("required", true)); // authorization type NewIndex.NewIndexType authorizationType = index.getTypes().get("authorization"); assertThat(getAttributeAsMap(authorizationType, "_parent")).isNull(); assertThat(getAttributeAsMap(authorizationType, "_routing")).containsExactly(entry("required", true)); }
@Test public void getDistributedSystemPropertiesContainsMemberNameAsName() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher("memberOne", "1"); Properties properties = launcher.getDistributedSystemProperties(); assertThat(properties).containsExactly(entry(NAME, "memberOne")); }
@SafeVarargs private final void assertThatFacetHasExactly(IssueQuery.Builder query, String facet, Map.Entry<String, Long>... expectedEntries) { SearchResponse result = underTest.search(query.build(), new SearchOptions().addFacets(singletonList(facet))); Facets facets = new Facets(result, system2.getDefaultTimeZone()); assertThat(facets.getNames()).containsOnly(facet, "effort"); assertThat(facets.get(facet)).containsExactly(expectedEntries); }
@Test public void resolveWhenClientAuthorizationRequiredExceptionAvailableThenResolves() { ClientRegistration clientRegistration = this.registration2; String requestUri = "/path"; MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); request.setServletPath(requestUri); OAuth2AuthorizationRequest authorizationRequest = this.resolver.resolve(request, clientRegistration.getRegistrationId()); assertThat(authorizationRequest).isNotNull(); assertThat(authorizationRequest.getAdditionalParameters()) .containsExactly(entry(OAuth2ParameterNames.REGISTRATION_ID, clientRegistration.getRegistrationId())); }
@Test public void scannerContext_loads_properties_from_scanner_report() { reportReader.putContextProperties(asList(ScannerReport.ContextProperty.newBuilder().setKey("foo").setValue("bar").build())); underTest.finished(true); verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture()); org.sonar.api.ce.posttask.ScannerContext scannerContext = projectAnalysisArgumentCaptor.getValue().getScannerContext(); assertThat(scannerContext.getProperties()).containsExactly(entry("foo", "bar")); }
@Test public void migration_must_set_analysis_uuid() throws SQLException { String ceTaskUuid = randomAlphanumeric(40); String analysisUuid = randomAlphanumeric(40); String webhookDeliveryUuid = randomAlphanumeric(40); insertWebhookDelivery(webhookDeliveryUuid,null, ceTaskUuid); insertCeActivity(ceTaskUuid, analysisUuid); assertThat(db.countRowsOfTable(TABLE_WEBHOOK_DELIVERY)).isEqualTo(1); assertThat(db.countRowsOfTable(TABLE_CE_ACTIVITIY)).isEqualTo(1); underTest.execute(); List<Map<String, Object>> maps = selectAllWebhookDeliveries(); assertThat(maps).hasSize(1); assertThat(maps.get(0)).containsExactly( entry("ANALYSIS_UUID", analysisUuid), entry("UUID", webhookDeliveryUuid), entry("CE_TASK_UUID", ceTaskUuid)); }
@SuppressWarnings("unchecked") private <M extends Map<Long, String>> void testMapCollector(Class<? extends Map> erasedType, GenericType<M> genericType) { JdbiCollectors registry = dbRule.getJdbi().getConfig(JdbiCollectors.class); assertThat(registry.findElementTypeFor(genericType.getType())) .contains(new GenericType<Map.Entry<Long, String>>(){}.getType()); Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) registry .findFor(genericType.getType()) .orElseThrow(() -> new IllegalStateException("Missing collector for " + genericType)); M map = Stream.of(entry(1L, "foo"), entry(2L, "bar")).collect(collector); assertThat(map) .isInstanceOf(erasedType) .containsExactly(entry(1L, "foo"), entry(2L, "bar")); }
@Test public void compare_different_params() { qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("max", "20")))); qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("min", "5")))); QProfileComparisonResult result = comparison.compare(dbSession, left, right); assertThat(result.left().getKee()).isEqualTo(left.getKee()); assertThat(result.right().getKee()).isEqualTo(right.getKee()); assertThat(result.same()).isEmpty(); assertThat(result.inLeft()).isEmpty(); assertThat(result.inRight()).isEmpty(); assertThat(result.modified()).isNotEmpty().containsOnlyKeys(xooRule1.getKey()); assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey()); ActiveRuleDiff activeRuleDiff = result.modified().get(xooRule1.getKey()); assertThat(activeRuleDiff.leftSeverity()).isEqualTo(activeRuleDiff.rightSeverity()).isEqualTo(xooRule1.getSeverityString()); assertThat(activeRuleDiff.paramDifference().areEqual()).isFalse(); assertThat(activeRuleDiff.paramDifference().entriesDiffering()).isEmpty(); assertThat(activeRuleDiff.paramDifference().entriesOnlyOnLeft()).containsExactly(MapEntry.entry("max", "20")); assertThat(activeRuleDiff.paramDifference().entriesOnlyOnRight()).containsExactly(MapEntry.entry("min", "5")); } }
@Test public void should_load_global_multivalue_settings() { assertThat(DefaultSettingsLoader.toMap(asList(Setting.newBuilder() .setKey("sonar.preview.supportedPlugins") .setValues(Values.newBuilder().addValues("java").addValues("php")).build()))) .containsExactly(entry("sonar.preview.supportedPlugins", "java,php")); }
@Test public void should_escape_global_multivalue_settings() { assertThat(DefaultSettingsLoader.toMap(asList(Setting.newBuilder() .setKey("sonar.preview.supportedPlugins") .setValues(Values.newBuilder().addValues("ja,va").addValues("p\"hp")).build()))) .containsExactly(entry("sonar.preview.supportedPlugins", "\"ja,va\",\"p\"\"hp\"")); }
private void assertNclocFacet(ProjectMeasuresQuery query, Long... facetExpectedValues) { checkArgument(facetExpectedValues.length == 5, "5 facet values is required"); Facets facets = underTest.search(query, new SearchOptions().addFacets(NCLOC)).getFacets(); assertThat(facets.get(NCLOC)).containsExactly( entry("*-1000.0", facetExpectedValues[0]), entry("1000.0-10000.0", facetExpectedValues[1]), entry("10000.0-100000.0", facetExpectedValues[2]), entry("100000.0-500000.0", facetExpectedValues[3]), entry("500000.0-*", facetExpectedValues[4])); } }
@Test public void verify_getters() { CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component"); CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component"); CeTask.User submitter = new CeTask.User("UUID_USER_1", "LOGIN_1"); underTest.setOrganizationUuid("org1"); underTest.setType("TYPE_1"); underTest.setUuid("UUID_1"); underTest.setSubmitter(submitter); underTest.setComponent(component); underTest.setMainComponent(mainComponent); underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2")); CeTask task = underTest.build(); assertThat(task.getOrganizationUuid()).isEqualTo("org1"); assertThat(task.getUuid()).isEqualTo("UUID_1"); assertThat(task.getType()).isEqualTo("TYPE_1"); assertThat(task.getSubmitter()).isEqualTo(submitter); assertThat(task.getComponent()).contains(component); assertThat(task.getMainComponent()).contains(mainComponent); assertThat(task.getCharacteristics()).containsExactly(entry("k1", "v1"), entry("k2", "v2")); }
@Test public void keep_order_of_params() { assertThat(underTest.getParams()).isEmpty(); assertThat(underTest.getParameters().getKeys()).isEmpty(); underTest.setParam("keyB", "b"); assertThat(underTest.getParams()).containsExactly(entry("keyB", "b")); assertParameters(entry("keyB", "b")); assertMultiValueParameters(entry("keyB", singletonList("b"))); underTest.setParam("keyA", "a"); assertThat(underTest.getParams()).containsExactly(entry("keyB", "b"), entry("keyA", "a")); assertParameters(entry("keyB", "b"), entry("keyA", "a")); assertMultiValueParameters(entry("keyB", singletonList("b")), entry("keyA", singletonList("a"))); underTest.setParam("keyC", ImmutableList.of("c1", "c2", "c3")); assertParameters(entry("keyB", "b"), entry("keyA", "a"), entry("keyC", "c1")); assertMultiValueParameters( entry("keyB", singletonList("b")), entry("keyA", singletonList("a")), entry("keyC", ImmutableList.of("c1", "c2", "c3"))); }