Skip to content

Commit

Permalink
Fixed datasource snippet (redhat-developer#317)
Browse files Browse the repository at this point in the history
Restores commit 2c39f6e

Signed-off-by: Fred Bricon <fbricon@gmail.com>
  • Loading branch information
fbricon committed May 28, 2020
1 parent dcf926c commit 475d3a1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.redhat.microprofile.services.MicroProfileAssert.c;
import static com.redhat.microprofile.services.MicroProfileAssert.r;
import static com.redhat.microprofile.services.MicroProfileAssert.testCompletionFor;
import static com.redhat.microprofile.services.MicroProfileAssert.assertCompletionWithDependencies;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -297,5 +298,33 @@ public void completionSpacingSurroundingEquals() throws BadLocationException {
testCompletionFor(value, true, true,
c("quarkus.http.cors", "quarkus.http.cors = ${1|false,true|}", r(0, 0, 0)));
}

@Test
public void snippetCompletionDatasource() throws BadLocationException {
String value = "qds|";
assertCompletionWithDependencies(value, null, new String[] {"quarkus-agroal"},
c("qds",
"quarkus.datasource.db-kind=${1|mariadb,mysql,h2,postgresql,derby,mssql|}" + System.lineSeparator() +
"quarkus.datasource.username=${2:developer}" + System.lineSeparator() +
"quarkus.datasource.password=${3:developer}" + System.lineSeparator() +
"quarkus.datasource.jdbc.url=${4|jdbc:mariadb://localhost:3306/mydb,jdbc:mysql://localhost:3306/test,jdbc:h2:mem:mydb,jdbc:postgresql://localhost:5432/mydb,jdbc:derby://localhost:1527/mydb,jdbc:sqlserver://localhost:1433;databaseName=mydb|}" + System.lineSeparator() +
"quarkus.datasource.jdbc.min-size=${5:5}" + System.lineSeparator() +
"quarkus.datasource.jdbc.max-size=${6:15}",
r(0, 0, 3)));
assertCompletionWithDependencies(value, 0, new String[]{});
}

@Test
public void snippetCompletionJaeger() throws BadLocationException {
String value = "qj|";
assertCompletionWithDependencies(value, null, new String[] {"quarkus-jaeger"},
c("qj",
"quarkus.jaeger.service-name=${1:myservice}" + System.lineSeparator() +
"quarkus.jaeger.sampler-type=${2:const}" + System.lineSeparator() +
"quarkus.jaeger.sampler-param=${3:1}" + System.lineSeparator() +
"quarkus.jaeger.endpoint=${4:http://localhost:14268/api/traces}",
r(0, 0, 2)));
assertCompletionWithDependencies(value, 0, new String[]{});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -63,6 +64,8 @@
import com.redhat.microprofile.settings.MicroProfileFormattingSettings;
import com.redhat.microprofile.settings.MicroProfileHoverSettings;
import com.redhat.microprofile.settings.MicroProfileValidationSettings;
import com.redhat.microprofile.snippets.LanguageId;
import com.redhat.microprofile.snippets.SnippetContextForProperties;
import com.redhat.microprofile.utils.DocumentationUtils;
import com.redhat.microprofile.utils.PositionUtils;

Expand Down Expand Up @@ -265,6 +268,22 @@ public static void assertCompletion(String value, Integer expectedCount, TextDoc
CompletionList actual = new CompletionList(items);
assertCompletions(actual, expectedCount, expectedItems);
}

public static void assertCompletionWithDependencies(String value, Integer expectedCount, String[] dependencies, CompletionItem... expectedItems) {
int offset = value.indexOf('|');
value = value.substring(0, offset) + value.substring(offset + 1);
TextDocumentSnippetRegistry registry = new TextDocumentSnippetRegistry(LanguageId.properties.name());
TextDocument document = new TextDocument(value, "application.properties");
List<CompletionItem> items = registry.getCompletionItems(document, offset, true, context -> {
if (context instanceof SnippetContextForProperties) {
SnippetContextForProperties contextProperties = (SnippetContextForProperties) context;
return contextProperties.isMatch(new HashSet<>(Arrays.asList(dependencies)));
}
return false;
});
CompletionList actual = new CompletionList(items);
assertCompletions(actual, expectedCount, expectedItems);
}

// ------------------- Hover assert

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"Add datasource properties": {
"prefix": "qds",
"body": [
"quarkus.datasource.url=${1|jdbc:mariadb://localhost:3306/mydb,jdbc:mysql://localhost:3306/test,jdbc:h2:mem:mydb,jdbc:postgresql://localhost:5432/mydb,jdbc:derby://localhost:1527/mydb,jdbc:sqlserver://localhost:1433;databaseName=mydb|}",
"quarkus.datasource.db-kind=${2|mariadb,mysql,h2,postgresql,derby,mssql|}",
"quarkus.datasource.username=${3:developer}",
"quarkus.datasource.password=${4:developer}",
"quarkus.hibernate-orm.database.generation=${5|none,drop-and-create,create,drop,update|}"
"quarkus.datasource.db-kind=${1|mariadb,mysql,h2,postgresql,derby,mssql|}",
"quarkus.datasource.username=${2:developer}",
"quarkus.datasource.password=${3:developer}",
"quarkus.datasource.jdbc.url=${4|jdbc:mariadb://localhost:3306/mydb,jdbc:mysql://localhost:3306/test,jdbc:h2:mem:mydb,jdbc:postgresql://localhost:5432/mydb,jdbc:derby://localhost:1527/mydb,jdbc:sqlserver://localhost:1433;databaseName=mydb|}",
"quarkus.datasource.jdbc.min-size=${5:5}",
"quarkus.datasource.jdbc.max-size=${6:15}"
],
"description": "Configure Quarkus datasource",
"context": {
Expand Down

0 comments on commit 475d3a1

Please sign in to comment.