Skip to content

Commit

Permalink
Adapting test to triple-slashed file: uris
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Oct 22, 2024
1 parent feecae3 commit 7d06051
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.java.lsp.server;

/**
*
* @author sdedic
*/
public class LspTestUtils {
public static String tripleSlashUri(String uri) {
if (!uri.startsWith("file:/") || uri.startsWith("file:///") || uri.length() <= 7) {
return uri;
}
if (uri.charAt(7) == ':') {
return uri;
} else {
return "file://" + uri.substring(5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.netbeans.api.sendopts.CommandLine;
import org.netbeans.api.templates.FileBuilder;
import org.netbeans.junit.NbTestCase;
import static org.netbeans.modules.java.lsp.server.LspTestUtils.tripleSlashUri;
import org.netbeans.modules.java.lsp.server.explorer.api.CreateExplorerParams;
import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
import org.netbeans.modules.java.lsp.server.explorer.api.NodeOperationParams;
Expand Down Expand Up @@ -504,7 +505,7 @@ public void testCreatedPeerFileAppears() throws Exception {
}
}

assertEquals(URLMapper.findURL(newFile, URLMapper.EXTERNAL).toString(), found.resourceUri);
assertEquals(tripleSlashUri(URLMapper.findURL(newFile, URLMapper.EXTERNAL).toString()), found.resourceUri);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.netbeans.modules.gsf.testrunner.api.TestSession;
import org.netbeans.modules.gsf.testrunner.api.Testcase;
import org.netbeans.modules.gsf.testrunner.api.Trouble;
import static org.netbeans.modules.java.lsp.server.LspTestUtils.tripleSlashUri;
import org.netbeans.modules.java.lsp.server.TestCodeLanguageClient;
import org.netbeans.modules.java.lsp.server.protocol.DecorationRenderOptions;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeClientCapabilities;
Expand Down Expand Up @@ -130,13 +131,13 @@ public FileObject find(String filename) {
TestSuiteInfo.TestCaseInfo testCase = suite.getTests().get(0);
assertEquals("TestSuiteName:TestSuiteName.test1", testCase.getId());
assertEquals("TestSuiteName.test1", testCase.getName());
assertEquals(fo.toURI().toString(), testCase.getFile());
assertEquals(tripleSlashUri(fo.toURI().toString()), testCase.getFile());
assertEquals(TestSuiteInfo.State.Passed, testCase.getState());
assertNull(testCase.getStackTrace());
testCase = suite.getTests().get(1);
assertEquals("TestSuiteName:TestSuiteName.test2", testCase.getId());
assertEquals("TestSuiteName.test2", testCase.getName());
assertEquals(fo.toURI().toString(), testCase.getFile());
assertEquals(tripleSlashUri(fo.toURI().toString()), testCase.getFile());
assertEquals(TestSuiteInfo.State.Failed, testCase.getState());
assertNotNull(testCase.getStackTrace());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
import org.netbeans.api.sendopts.CommandLine;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.java.hints.infrastructure.JavaErrorProvider;
import static org.netbeans.modules.java.lsp.server.LspTestUtils.tripleSlashUri;
import org.netbeans.modules.java.lsp.server.TestCodeLanguageClient;
import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
Expand Down Expand Up @@ -984,23 +985,23 @@ public void logMessage(MessageParams arg0) {
Position pos = new Position(3, 30);
List<? extends Location> definition = server.getTextDocumentService().definition(new DefinitionParams(new TextDocumentIdentifier(toURI(src)), pos)).get().getLeft();
assertEquals(1, definition.size());
assertEquals(toURI(src), definition.get(0).getUri());
assertEquals(tripleSlashUri(toURI(src)), definition.get(0).getUri());
assertEquals(1, definition.get(0).getRange().getStart().getLine());
assertEquals(16, definition.get(0).getRange().getStart().getCharacter());
assertEquals(1, definition.get(0).getRange().getEnd().getLine());
assertEquals(21, definition.get(0).getRange().getEnd().getCharacter());
pos = new Position(4, 30);
definition = server.getTextDocumentService().definition(new DefinitionParams(new TextDocumentIdentifier(toURI(src)), pos)).get().getLeft();
assertEquals(1, definition.size());
assertEquals(toURI(src), definition.get(0).getUri());
assertEquals(tripleSlashUri(toURI(src)), definition.get(0).getUri());
assertEquals(2, definition.get(0).getRange().getStart().getLine());
assertEquals(27, definition.get(0).getRange().getStart().getCharacter());
assertEquals(2, definition.get(0).getRange().getEnd().getLine());
assertEquals(30, definition.get(0).getRange().getEnd().getCharacter());
pos = new Position(5, 22);
definition = server.getTextDocumentService().definition(new DefinitionParams(new TextDocumentIdentifier(toURI(src)), pos)).get().getLeft();
assertEquals(1, definition.size());
assertEquals(toURI(otherSrc), definition.get(0).getUri());
assertEquals(tripleSlashUri(toURI(otherSrc)), definition.get(0).getUri());
assertEquals(2, definition.get(0).getRange().getStart().getLine());
assertEquals(16, definition.get(0).getRange().getStart().getCharacter());
assertEquals(2, definition.get(0).getRange().getEnd().getLine());
Expand Down Expand Up @@ -1067,7 +1068,7 @@ public void logMessage(MessageParams arg0) {
Position pos = new Position(3, 30);
List<? extends Location> typeDefinition = server.getTextDocumentService().typeDefinition(new TypeDefinitionParams(new TextDocumentIdentifier(toURI(src)), pos)).get().getLeft();
assertEquals(1, typeDefinition.size());
assertEquals(toURI(otherSrc), typeDefinition.get(0).getUri());
assertEquals(tripleSlashUri(toURI(otherSrc)), typeDefinition.get(0).getUri());
assertEquals(1, typeDefinition.get(0).getRange().getStart().getLine());
assertEquals(13, typeDefinition.get(0).getRange().getStart().getCharacter());
assertEquals(1, typeDefinition.get(0).getRange().getEnd().getLine());
Expand Down Expand Up @@ -1131,7 +1132,7 @@ public void logMessage(MessageParams params) {
Position pos = new Position(1, 10);
List<? extends Location> implementations = server.getTextDocumentService().implementation(new ImplementationParams(new TextDocumentIdentifier(toURI(src)), pos)).get().getLeft();
assertEquals(1, implementations.size());
assertEquals(toURI(otherSrc), implementations.get(0).getUri());
assertEquals(tripleSlashUri(toURI(otherSrc)), implementations.get(0).getUri());
assertEquals(2, implementations.get(0).getRange().getStart().getLine());
assertEquals(16, implementations.get(0).getRange().getStart().getCharacter());
assertEquals(2, implementations.get(0).getRange().getEnd().getLine());
Expand Down Expand Up @@ -1190,7 +1191,7 @@ public void logMessage(MessageParams params) {
assertNotNull(locs);
assertEquals(1, locs.length);
Location loc = locs[0];
assertEquals(toURI(otherSrc), loc.getUri());
assertEquals(tripleSlashUri(toURI(otherSrc)), loc.getUri());
assertEquals(2, loc.getRange().getStart().getLine());
assertEquals(9, loc.getRange().getStart().getCharacter());
assertEquals(2, loc.getRange().getEnd().getLine());
Expand Down Expand Up @@ -2643,7 +2644,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
assertEquals(1, changes.size());
assertTrue(changes.get(0).isLeft());
TextDocumentEdit edit = changes.get(0).getLeft();
assertEquals(edit.getTextDocument().getUri(), uri);
assertEquals(edit.getTextDocument().getUri(), tripleSlashUri(uri));
List<TextEdit> fileChanges = edit.getEdits();
assertNotNull(fileChanges);
assertEquals(4, fileChanges.size());
Expand Down Expand Up @@ -2751,7 +2752,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
assertEquals(1, changes.size());
assertTrue(changes.get(0).isLeft());
TextDocumentEdit edit = changes.get(0).getLeft();
assertEquals(edit.getTextDocument().getUri(), uri);
assertEquals(edit.getTextDocument().getUri(), tripleSlashUri(uri));
List<TextEdit> fileChanges = edit.getEdits();
assertNotNull(fileChanges);
assertEquals(3, fileChanges.size());
Expand Down Expand Up @@ -2854,7 +2855,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
assertEquals(1, changes.size());
assertTrue(changes.get(0).isLeft());
TextDocumentEdit edit = changes.get(0).getLeft();
assertEquals(edit.getTextDocument().getUri(), uri);
assertEquals(edit.getTextDocument().getUri(), tripleSlashUri(uri));
List<TextEdit> fileChanges = edit.getEdits();
assertNotNull(fileChanges);
assertEquals(3, fileChanges.size());
Expand Down Expand Up @@ -2957,7 +2958,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
assertEquals(1, changes.size());
assertTrue(changes.get(0).isLeft());
TextDocumentEdit edit = changes.get(0).getLeft();
assertEquals(edit.getTextDocument().getUri(), uri);
assertEquals(edit.getTextDocument().getUri(), tripleSlashUri(uri));
List<TextEdit> fileChanges = edit.getEdits();
assertNotNull(fileChanges);
assertEquals(3, fileChanges.size());
Expand Down Expand Up @@ -3057,7 +3058,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(6, 0),
Expand Down Expand Up @@ -3125,7 +3126,7 @@ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showM
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(3, 0),
Expand All @@ -3137,7 +3138,7 @@ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showM
" }\n",
fileChanges.get(0).getNewText());
}

public void testSourceActionGetterSetter() throws Exception {
File src = new File(getWorkDir(), "Test.java");
src.getParentFile().mkdirs();
Expand Down Expand Up @@ -3202,7 +3203,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(3, 0),
Expand Down Expand Up @@ -3237,7 +3238,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
fileChanges = edit.getChanges().get(uri);
fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(11, 0),
Expand Down Expand Up @@ -3303,7 +3304,7 @@ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showM
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(2, 0),
Expand Down Expand Up @@ -3386,7 +3387,7 @@ public CompletableFuture<List<QuickPickItem>> showQuickPick(ShowQuickPickParams
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(13, 0),
Expand Down Expand Up @@ -3459,7 +3460,7 @@ public CompletableFuture<List<QuickPickItem>> showQuickPick(ShowQuickPickParams
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(2, 0),
Expand Down Expand Up @@ -3548,7 +3549,7 @@ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showM
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(2, fileChanges.size());
assertEquals(new Range(new Position(0, 0),
Expand Down Expand Up @@ -3616,7 +3617,7 @@ public CompletableFuture<List<QuickPickItem>> showQuickPick(ShowQuickPickParams
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(1, fileChanges.size());
assertEquals(new Range(new Position(2, 0),
Expand Down Expand Up @@ -3686,7 +3687,7 @@ public CompletableFuture<String> showInputBox(ShowInputBoxParams params) {
WorkspaceEdit edit = gson.fromJson(gson.toJsonTree(ret), WorkspaceEdit.class);
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(2, fileChanges.size());
assertEquals(new Range(new Position(0, 0),
Expand Down Expand Up @@ -3763,7 +3764,7 @@ public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEdi
WorkspaceEdit edit = resolvedCodeAction.getEdit();
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
List<TextEdit> fileChanges = edit.getChanges().get(uri);
List<TextEdit> fileChanges = edit.getChanges().get(tripleSlashUri(uri));
assertNotNull(fileChanges);
assertEquals(2, fileChanges.size());
assertEquals(new Range(new Position(0, 0),
Expand Down

0 comments on commit 7d06051

Please sign in to comment.