19
19
*/
20
20
package org .sonarsource .sonarlint .ls .backend ;
21
21
22
- import org .junit .jupiter .api .BeforeEach ;
22
+ import org .junit .jupiter .api .AfterEach ;
23
23
import org .junit .jupiter .api .Test ;
24
24
import org .sonarsource .sonarlint .core .rpc .client .SonarLintRpcClientDelegate ;
25
+ import org .sonarsource .sonarlint .core .rpc .protocol .backend .initialize .BackendCapability ;
25
26
import org .sonarsource .sonarlint .ls .SonarLintExtendedLanguageClient ;
26
27
import org .sonarsource .sonarlint .ls .log .LanguageClientLogger ;
28
+ import org .sonarsource .sonarlint .ls .telemetry .SonarLintTelemetry ;
27
29
28
30
import static org .assertj .core .api .Assertions .assertThat ;
29
31
import static org .junit .jupiter .api .Assertions .assertThrows ;
30
32
import static org .mockito .Mockito .mock ;
33
+ import static org .mockito .Mockito .when ;
31
34
import static org .sonarsource .sonarlint .ls .backend .BackendServiceFacade .MONITORING_DISABLED_PROPERTY_KEY ;
32
35
33
36
class BackendServiceFacadeTests {
@@ -37,8 +40,8 @@ class BackendServiceFacadeTests {
37
40
SonarLintRpcClientDelegate backend = mock (SonarLintRpcClientDelegate .class );
38
41
BackendServiceFacade underTest = new BackendServiceFacade (backend , mock (LanguageClientLogger .class ), mock (SonarLintExtendedLanguageClient .class ), 0 );
39
42
40
- @ BeforeEach
41
- void setUp () {
43
+ @ AfterEach
44
+ void tearDown () {
42
45
System .clearProperty (MONITORING_DISABLED_PROPERTY_KEY );
43
46
}
44
47
@@ -92,4 +95,62 @@ void shouldEnableMonitoringWhenNotDisabled() {
92
95
assertThat (result ).isTrue ();
93
96
}
94
97
98
+ @ Test
99
+ void shouldComputeBackendCapabilities () {
100
+ // make sure monitoring is disabled
101
+ System .setProperty (MONITORING_DISABLED_PROPERTY_KEY , "true" );
102
+
103
+ // make sure telemetry is disabled
104
+ SonarLintTelemetry telemetryService = mock (SonarLintTelemetry .class );
105
+ underTest .setTelemetry (telemetryService );
106
+ when (telemetryService .enabled ()).thenReturn (false );
107
+
108
+ var backendInitParams = mock (BackendInitParams .class );
109
+ when (backendInitParams .isEnableSecurityHotspots ()).thenReturn (true );
110
+ var backendCapabilities = underTest .getBackendCapabilities (backendInitParams );
111
+
112
+ assertThat (backendCapabilities )
113
+ .isNotNull ()
114
+ .isNotEmpty ()
115
+ .contains (BackendCapability .SMART_NOTIFICATIONS )
116
+ .contains (BackendCapability .SECURITY_HOTSPOTS )
117
+ .contains (BackendCapability .PROJECT_SYNCHRONIZATION )
118
+ .contains (BackendCapability .EMBEDDED_SERVER )
119
+ .contains (BackendCapability .DATAFLOW_BUG_DETECTION )
120
+ .contains (BackendCapability .FULL_SYNCHRONIZATION )
121
+ .contains (BackendCapability .SERVER_SENT_EVENTS )
122
+ .doesNotContain (BackendCapability .TELEMETRY )
123
+ .doesNotContain (BackendCapability .MONITORING );
124
+
125
+ }
126
+
127
+ @ Test
128
+ void shouldComputeBackendCapabilities_withTelemetryAndMonitoring () {
129
+ // make sure monitoring is disabled
130
+ System .setProperty (MONITORING_DISABLED_PROPERTY_KEY , "false" );
131
+
132
+ // make sure telemetry is disabled
133
+ SonarLintTelemetry telemetryService = mock (SonarLintTelemetry .class );
134
+ underTest .setTelemetry (telemetryService );
135
+ when (telemetryService .enabled ()).thenReturn (true );
136
+
137
+ var backendInitParams = mock (BackendInitParams .class );
138
+ when (backendInitParams .isEnableSecurityHotspots ()).thenReturn (true );
139
+ var backendCapabilities = underTest .getBackendCapabilities (backendInitParams );
140
+
141
+ assertThat (backendCapabilities )
142
+ .isNotNull ()
143
+ .isNotEmpty ()
144
+ .contains (BackendCapability .SMART_NOTIFICATIONS )
145
+ .contains (BackendCapability .SECURITY_HOTSPOTS )
146
+ .contains (BackendCapability .PROJECT_SYNCHRONIZATION )
147
+ .contains (BackendCapability .EMBEDDED_SERVER )
148
+ .contains (BackendCapability .DATAFLOW_BUG_DETECTION )
149
+ .contains (BackendCapability .FULL_SYNCHRONIZATION )
150
+ .contains (BackendCapability .SERVER_SENT_EVENTS )
151
+ .contains (BackendCapability .TELEMETRY )
152
+ .contains (BackendCapability .MONITORING );
153
+
154
+ }
155
+
95
156
}
0 commit comments