Search in sources :

Example 11 with RuleChange

use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.

the class SonarLintClientsRegistryTest method listen_givenOneClientInterestedInJavaEvents_sendOneJavaEvent.

@Test
public void listen_givenOneClientInterestedInJavaEvents_sendOneJavaEvent() throws IOException {
    Set<String> javaLanguageKey = Set.of("java");
    when(defaultAsyncContext.getResponse()).thenReturn(response);
    when(response.getOutputStream()).thenReturn(outputStream);
    SonarLintClient sonarLintClient = new SonarLintClient(defaultAsyncContext, exampleKeys, javaLanguageKey, USER_UUID);
    underTest.registerClient(sonarLintClient);
    RuleChange javaRule = createRuleChange();
    RuleChange[] activatedRules = { javaRule };
    RuleChange[] deactivatedRules = { javaRule };
    RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules);
    underTest.listen(ruleSetChangedEvent);
    ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
    verify(outputStream).write(captor.capture());
    String message = new String(captor.getValue());
    assertThatEvent(message).hasType("RuleSetChanged").hasJsonData(getClass().getResource("rule-change-event-data.json"));
}
Also used : RuleChange(org.sonar.core.util.RuleChange) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuleSetChangedEvent(org.sonar.core.util.RuleSetChangedEvent) Test(org.junit.Test)

Aggregations

RuleChange (org.sonar.core.util.RuleChange)11 RuleSetChangedEvent (org.sonar.core.util.RuleSetChangedEvent)7 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ArrayList (java.util.ArrayList)4 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)4 ParamChange (org.sonar.core.util.ParamChange)3 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)3 OrgActiveRuleDto (org.sonar.db.qualityprofile.OrgActiveRuleDto)3 DbSession (org.sonar.db.DbSession)2 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)2 RuleDto (org.sonar.db.rule.RuleDto)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1