use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.
the class ConnectionTestTaskTest method fail_if_no_connection.
@Test
public void fail_if_no_connection() {
SonarQubeServer server = SonarQubeServer.newBuilder().setHostUrl("invalid_url").build();
ConnectionTestTask task = new ConnectionTestTask(server);
ProgressIndicator progress = mock(ProgressIndicator.class);
task.run(progress);
verify(progress).setIndeterminate(true);
assertThat(task.getException()).isNotNull();
assertThat(task.result()).isNull();
verify(globalLogOutput).logError(eq("Connection test failed"), any(Throwable.class));
}
use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.
the class ProjectBindingManagerTest method fail_if_cant_find_server.
@Test
public void fail_if_cant_find_server() throws InvalidBindingException {
settings.setBindingEnabled(true);
settings.setProjectKey("project1");
settings.setServerId("server1");
SonarQubeServer server = SonarQubeServer.newBuilder().setName("server2").build();
globalSettings.setSonarQubeServers(Collections.singletonList(server));
exception.expect(InvalidBindingException.class);
projectBindingManager.getSonarQubeServer();
}
use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.
the class ServerIssueUpdaterTest method testDownloadAllServerIssues.
@Test
public void testDownloadAllServerIssues() throws InvalidBindingException {
List<VirtualFile> files = new LinkedList<>();
for (int i = 0; i < 10; i++) {
VirtualFile file = mock(VirtualFile.class);
String filename = "MyFile" + i + ".txt";
when(file.getPath()).thenReturn(FileUtil.toSystemIndependentName(projectBaseDir.resolve(filename).toString()));
files.add(file);
}
ServerIssue serverIssue = mock(ServerIssue.class);
// mock creation of engine / server
ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
when(bindingManager.getConnectedEngine()).thenReturn(engine);
SonarQubeServer server = mock(SonarQubeServer.class);
when(server.getHostUrl()).thenReturn("http://dummyserver:9000");
when(bindingManager.getSonarQubeServer()).thenReturn(server);
// mock issues fetched
when(engine.getServerIssues(eq(PROJECT_KEY), anyString())).thenReturn(Collections.singletonList(serverIssue));
// run
settings.setBindingEnabled(true);
updater.initComponent();
updater.fetchAndMatchServerIssues(files, indicator, false);
verify(issueManager, timeout(3000).times(10)).matchWithServerIssues(any(VirtualFile.class), argThat(issues -> issues.size() == 1));
verify(engine).downloadServerIssues(any(ServerConfiguration.class), eq(PROJECT_KEY));
verify(bindingManager).getConnectedEngine();
verify(console, never()).error(anyString());
verify(console, never()).error(anyString(), any(Throwable.class));
}
use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.
the class ServerIssueUpdaterTest method testServerIssueTracking.
@Test
public void testServerIssueTracking() throws InvalidBindingException {
VirtualFile file = mock(VirtualFile.class);
ServerIssue serverIssue = mock(ServerIssue.class);
String filename = "MyFile.txt";
when(file.getPath()).thenReturn(FileUtil.toSystemIndependentName(projectBaseDir.resolve(filename).toString()));
// mock creation of engine / server
ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
when(bindingManager.getConnectedEngine()).thenReturn(engine);
SonarQubeServer server = mock(SonarQubeServer.class);
when(server.getHostUrl()).thenReturn("http://dummyserver:9000");
when(bindingManager.getSonarQubeServer()).thenReturn(server);
// mock issues downloaded
when(engine.downloadServerIssues(any(ServerConfiguration.class), eq(PROJECT_KEY), eq(filename))).thenReturn(Collections.singletonList(serverIssue));
// run
settings.setBindingEnabled(true);
updater.initComponent();
updater.fetchAndMatchServerIssues(Collections.singletonList(file), indicator, false);
verify(issueManager, timeout(3000).times(1)).matchWithServerIssues(eq(file), argThat(issues -> issues.size() == 1));
verify(bindingManager).getConnectedEngine();
verify(console, never()).error(anyString());
verify(console, never()).error(anyString(), any(Throwable.class));
}
use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.
the class SonarLintUtilsTest method testServerConfigurationToken.
@Test
public void testServerConfigurationToken() {
SonarApplication app = mock(SonarApplication.class);
when(app.getVersion()).thenReturn("1.0");
super.register(ApplicationManager.getApplication(), SonarApplication.class, app);
SonarQubeServer server = SonarQubeServer.newBuilder().setHostUrl("http://myhost").setEnableProxy(false).setToken("token").build();
ServerConfiguration config = SonarLintUtils.getServerConfiguration(server);
assertThat(config.getLogin()).isEqualTo(server.getToken());
assertThat(config.getPassword()).isNull();
assertThat(config.getConnectTimeoutMs()).isEqualTo(SonarLintUtils.CONNECTION_TIMEOUT_MS);
assertThat(config.getReadTimeoutMs()).isEqualTo(SonarLintUtils.READ_TIMEOUT_MS);
assertThat(config.getUserAgent()).contains("SonarLint");
assertThat(config.getUrl()).isEqualTo(server.getHostUrl());
assertThat(config.getOrganizationKey()).isNull();
}
Aggregations