Skip to content

Commit

Permalink
Test use XMLLangugeService instead of a connection
Browse files Browse the repository at this point in the history
+ Enable tests in CI

Signed-off-by: Mickael Istria <mistria@redhat.com>
  • Loading branch information
mickaelistria committed Apr 27, 2020
1 parent 284d629 commit 58b9cb9
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 491 deletions.
10 changes: 2 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@ pipeline{
stage("Maven Build"){
steps {
withMaven {
sh 'mvn -B verify --file lemminx-maven/pom.xml -Dmaven.test.error.ignore=true -Dmaven.test.failure.ignore=true -DskipTests'
sh 'mvn -B verify --file lemminx-maven/pom.xml -Dmaven.test.error.ignore=true -Dmaven.test.failure.ignore=true -Dmaven.repo.local=$WORKSPACE/.m2/repository'
}
}
post {
always {
junit 'lemminx-maven/target/surefire-reports/TEST-*.xml'
archiveArtifacts artifacts: 'lemminx-maven/target/*.jar'
}
}
}
stage ('Deploy Maven artifacts') {
when {
branch 'master'
}
steps {
withMaven {
sh 'mvn deploy -B -DskipTests -Dcbi.jarsigner.skip=false --file lemminx-maven/pom.xml'
sh 'mvn -B deploy --file lemminx-maven/pom.xml -DskipTests -Dcbi.jarsigner.skip=false -Dmaven.repo.local=$WORKSPACE/.m2/repository'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ LocalRepoTests.class, MavenParseUtilsTest.class, MavenProjectCacheTest.class, PluginTest.class,
@SuiteClasses({ LocalRepoTests.class, MavenParseUtilsTest.class, MavenProjectCacheTest.class, LocalPluginTest.class,
RemoteRepositoryTest.class, SimpleModelTest.class })
public class AllTests {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lemminx.maven.test;

import static org.eclipse.lemminx.maven.test.MavenLemminxTestsUtils.createDOMDocument;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.eclipse.lemminx.services.XMLLanguageService;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lemminx.settings.XMLHoverSettings;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextEdit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

public class LocalPluginTest {

@Rule public NoMavenCentralIndexTestRule rule = new NoMavenCentralIndexTestRule();

private XMLLanguageService languageService;

@Before
public void setUp() throws IOException {
languageService = new XMLLanguageService();
}

@After
public void tearDown() throws InterruptedException, ExecutionException {
languageService.dispose();
languageService = null;
}

// Completion related tests

@Test(timeout=15000)
public void testCompleteGoal() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
assertTrue(languageService.doComplete(createDOMDocument("/pom-complete-plugin-goal.xml", languageService),
new Position(18, 19), new SharedSettings())
.getItems().stream().map(CompletionItem::getTextEdit).map(TextEdit::getNewText).anyMatch("test"::equals));
}

@Test(timeout=15000)
public void testCompleteConfigurationParameters() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
assertTrue(languageService.doComplete(createDOMDocument("/pom-complete-plugin-goal.xml", languageService),
new Position(23, 7), new SharedSettings())
.getItems().stream().map(CompletionItem::getLabel).anyMatch("failIfNoTests"::equals));
}

@Test(timeout=15000)
public void testCompleteConfigurationParametersInTag() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
assertTrue(languageService.doComplete(createDOMDocument("/pom-plugin-config-tag.xml", languageService),
new Position(20, 9), new SharedSettings())
.getItems().stream().map(CompletionItem::getLabel).anyMatch("failIfNoTests"::equals));
}

// Hover related tests

@Test(timeout=15000)
public void testPluginConfigurationHover() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
assertTrue(languageService.doHover(createDOMDocument("/pom-plugin-configuration-hover.xml", languageService),
new Position(15, 5), new XMLHoverSettings()).getContents().getRight().getValue().contains("The -source argument for the Java compiler."));
}

@Test(timeout=15000)
public void testPluginGoalHover() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
assertTrue(languageService.doHover(createDOMDocument("/pom-plugin-goal-hover.xml", languageService),
new Position(18, 22), new XMLHoverSettings()).getContents().getRight().getValue().contains("Run tests using Surefire."));
}

@Test(timeout=15000)
public void testPluginArtifactHover() throws IOException, InterruptedException, ExecutionException, URISyntaxException, TimeoutException {
assertTrue(languageService.doHover(createDOMDocument("/pom-plugin-artifact-hover.xml", languageService),
new Position(14, 18), new XMLHoverSettings()).getContents().getRight().getValue().contains("Maven Surefire MOJO in maven-surefire-plugin"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,48 @@
*******************************************************************************/
package org.eclipse.lemminx.maven.test;

import static org.eclipse.lemminx.maven.test.MavenLemminxTestsUtils.createTextDocumentItem;
import static org.eclipse.lemminx.maven.test.MavenLemminxTestsUtils.createDOMDocument;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import org.eclipse.lemminx.services.XMLLanguageService;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.CompletionParams;
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextDocumentItem;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LocalRepoTests {

private ClientServerConnection connection;

private XMLLanguageService languageService;

@Before
public void setUp() throws IOException {
connection = new ClientServerConnection();
languageService = new XMLLanguageService();
}

@After
public void tearDown() throws InterruptedException, ExecutionException {
connection.stop();
languageService.dispose();
languageService = null;
}

@Test(timeout=90000)
public void testCompleteDependency()
throws IOException, InterruptedException, ExecutionException, URISyntaxException {
TextDocumentItem textDocumentItem = createTextDocumentItem("/pom-with-dependency.xml");
DidOpenTextDocumentParams params = new DidOpenTextDocumentParams(textDocumentItem);
connection.languageServer.getTextDocumentService().didOpen(params);
Either<List<CompletionItem>, CompletionList> completion = connection.languageServer.getTextDocumentService()
.completion(new CompletionParams(new TextDocumentIdentifier(textDocumentItem.getUri()),
new Position(11, 7)))
.get();
List<CompletionItem> items = completion.getRight().getItems();
Optional<String> mavenCoreCompletionItem = items.stream().map(CompletionItem::getLabel)
.filter(label -> label.contains("org.apache.maven:maven-core")).findAny();
assertTrue(mavenCoreCompletionItem.isPresent());
assertTrue(languageService.doComplete(createDOMDocument("/pom-with-dependency.xml", languageService), new Position(11, 7), new SharedSettings())
.getItems().stream().map(CompletionItem::getLabel).anyMatch(label -> label.contains("org.apache.maven:maven-core")));
}

@Test(timeout=90000)
public void testCompleteLocalGroupdId()
throws IOException, InterruptedException, ExecutionException, URISyntaxException {
TextDocumentItem textDocumentItem = createTextDocumentItem("/pom-local-groupId-complete.xml");
DidOpenTextDocumentParams params = new DidOpenTextDocumentParams(textDocumentItem);
connection.languageServer.getTextDocumentService().didOpen(params);
Either<List<CompletionItem>, CompletionList> completion = connection.languageServer.getTextDocumentService()
.completion(new CompletionParams(new TextDocumentIdentifier(textDocumentItem.getUri()),
new Position(11, 12)))
.get();
List<CompletionItem> items = completion.getRight().getItems();
Optional<String> mavenGroupCompletionItem = items.stream().map(CompletionItem::getLabel)
.filter(label -> label.contains("org.apache.maven")).findAny();
assertTrue(mavenGroupCompletionItem.isPresent());
assertTrue(languageService.doComplete(createDOMDocument("/pom-local-groupId-complete.xml", languageService), new Position(11, 12), new SharedSettings())
.getItems().stream().map(CompletionItem::getLabel).anyMatch(label -> label.contains("org.apache.maven")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.util.List;
import java.util.Map;

import org.eclipse.lemminx.commons.TextDocument;
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.services.XMLLanguageService;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.TextDocumentItem;

Expand All @@ -24,6 +27,10 @@ public interface MavenLemminxTestsUtils {
public static TextDocumentItem createTextDocumentItem(String resourcePath) throws IOException, URISyntaxException {
return createTextDocumentItem(resourcePath, null);
}

public static DOMDocument createDOMDocument(String resourcePath, XMLLanguageService languageService) throws IOException, URISyntaxException {
return org.eclipse.lemminx.dom.DOMParser.getInstance().parse(new TextDocument(createTextDocumentItem(resourcePath)), languageService.getResolverExtensionManager());
}

public static TextDocumentItem createTextDocumentItem(String resourcePath, Map<String, String> replacements) throws IOException, URISyntaxException {
URI uri = MavenLemminxTestsUtils.class.getResource(resourcePath).toURI();
Expand Down
Loading

0 comments on commit 58b9cb9

Please sign in to comment.