-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LSP4Jakarta tests #407
Open
awisniew90
wants to merge
5
commits into
OpenLiberty:main
Choose a base branch
from
awisniew90:lsp_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
...rc/main/java/io/openliberty/tools/eclipse/test/it/LibertyPluginSWTBotLSP4JakartaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.eclipse.test.it; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.openliberty.tools.eclipse.test.it.utils.LibertyPluginTestUtils; | ||
import io.openliberty.tools.eclipse.test.it.utils.SWTBotPluginOperations; | ||
|
||
/** | ||
* Tests LSP4Jakarta functionality within Liberty Tools for Eclipse | ||
*/ | ||
public class LibertyPluginSWTBotLSP4JakartaTest extends AbstractLibertyPluginSWTBotTest { | ||
|
||
/** | ||
* Wrapper Application name. | ||
*/ | ||
static final String MVN_WRAPPER_APP_NAME = "liberty.maven.test.wrapper.app"; | ||
|
||
/** | ||
* Test app relative path. | ||
*/ | ||
static final Path wrapperProjectPath = Paths.get("resources", "applications", "maven", "liberty-maven-test-wrapper-app"); | ||
|
||
static ArrayList<String> projectPaths = new ArrayList<String>(); | ||
|
||
/** | ||
* Text to add to editor | ||
*/ | ||
static final String WEB_SERVLET_IMPORT_STRING = "import jakarta.servlet.annotation.WebServlet;\r\n"; | ||
static final String WEB_SERVLET_EMPTY_ANNO_STRING = "@WebServlet()\r\n"; | ||
|
||
/** | ||
* Expected quick-fixes | ||
*/ | ||
static String[] webServlet_quickFixes = new String[] { "Add the `urlPatterns` attribute to @WebServlet", | ||
"Add the `value` attribute to @WebServlet" }; | ||
|
||
/** | ||
* Expected type-ahead options when at highest level in class. | ||
*/ | ||
static String[] typeAheadOptions_classLevel = new String[] { "rest_class", "persist_entity", "servlet_doget", "servlet_dopost", | ||
"servlet_generic", "servlet_webfilter" }; | ||
|
||
/** | ||
* Expected type-ahead options within REST class | ||
*/ | ||
static String[] typeAheadOptions_inClass = new String[] { "persist_context", "persist_context_extended", | ||
"persist_context_extended_unsync", "rest_head", "rest_get", "rest_post", "rest_put", "rest_delete", "tx_user_inject", | ||
"tx_user_jndi" }; | ||
|
||
/** | ||
* Setup. | ||
* | ||
* @throws Exception | ||
*/ | ||
@BeforeAll | ||
public static void setup() throws Exception { | ||
|
||
commonSetup(); | ||
|
||
File workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile(); | ||
projectPaths.add(wrapperProjectPath.toString()); | ||
|
||
// Maybe redundant but we really want to cleanup. We really want to | ||
// avoid wasting time debugging tricky differences in behavior because of a dirty re-run | ||
for (String p : projectPaths) { | ||
cleanupProject(p); | ||
} | ||
|
||
importMavenProjects(workspaceRoot, projectPaths); | ||
} | ||
|
||
@AfterAll | ||
public static void cleanup() { | ||
for (String p : projectPaths) { | ||
cleanupProject(p); | ||
} | ||
} | ||
|
||
/** | ||
* Verify the class level snippets are available | ||
*/ | ||
@Test | ||
public void testClassLevelSnippets() { | ||
|
||
try { | ||
// Open new class file | ||
SWTBotPluginOperations.createNewClass(bot, MVN_WRAPPER_APP_NAME, "MyClass", true); | ||
|
||
// Get type-ahead list | ||
List<String> typeAheadOptions = SWTBotPluginOperations.getTypeAheadList(bot, "MyClass.java", "", 0, 0); | ||
System.out.println("INFO: Type-ahead options found = " + Arrays.toString(typeAheadOptions.toArray())); | ||
|
||
boolean allFound = true; | ||
List<String> missingOptions = new ArrayList<String>(); | ||
for (String option : typeAheadOptions_classLevel) { | ||
if (!typeAheadOptions.contains(option)) { | ||
allFound = false; | ||
missingOptions.add(option); | ||
} | ||
} | ||
|
||
assertTrue(allFound, "Missing type-ahead options: " + Arrays.toString(missingOptions.toArray())); | ||
|
||
} catch (Exception e) { | ||
fail("Unexpected exception was thrown: " + e); | ||
} finally { | ||
|
||
// Delete new file | ||
System.out.println("INFO: Deleting MyClass.java file"); | ||
LibertyPluginTestUtils.deleteFile(new File(wrapperProjectPath + "/src/main/java/test/maven/liberty/web/app/MyClass.java")); | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Verify the in class snippets are available | ||
*/ | ||
@Test | ||
public void testInClassSnippets() { | ||
|
||
try { | ||
// Open new class file | ||
SWTBotPluginOperations.createNewClass(bot, MVN_WRAPPER_APP_NAME, "MyClass", false); | ||
|
||
// Get type-ahead list | ||
List<String> typeAheadOptions = SWTBotPluginOperations.getTypeAheadList(bot, "MyClass.java", "", 3, 0); | ||
System.out.println("INFO: Type-ahead options found = " + Arrays.toString(typeAheadOptions.toArray())); | ||
|
||
boolean allFound = true; | ||
List<String> missingOptions = new ArrayList<String>(); | ||
for (String option : typeAheadOptions_inClass) { | ||
if (!typeAheadOptions.contains(option)) { | ||
allFound = false; | ||
missingOptions.add(option); | ||
} | ||
} | ||
|
||
assertTrue(allFound, "Missing type-ahead options: " + Arrays.toString(missingOptions.toArray())); | ||
|
||
} catch (Exception e) { | ||
fail("Unexpected exception was thrown: " + e); | ||
} finally { | ||
|
||
// Delete new file | ||
System.out.println("INFO: Deleting MyClass.java file"); | ||
LibertyPluginTestUtils.deleteFile(new File(wrapperProjectPath + "/src/main/java/test/maven/liberty/web/app/MyClass.java")); | ||
} | ||
} | ||
|
||
/** | ||
* Verify diagnostics and quick fixes | ||
*/ | ||
@Test | ||
@Disabled("Issue 377") | ||
public void testDiagnosticsAndQuickFixes() { | ||
|
||
try { | ||
// Open new class file | ||
SWTBotPluginOperations.createNewClass(bot, MVN_WRAPPER_APP_NAME, "MyClass", true); | ||
|
||
// Select the "servlet_generic" snippet | ||
SWTBotPluginOperations.selectTypeAheadOption(bot, "MyClass.java", "servlet_generic", 0, 0); | ||
|
||
// Add WebServlet annotation | ||
SWTBotPluginOperations.addTextToEditor(bot, "MyClass.java", WEB_SERVLET_EMPTY_ANNO_STRING, 8, 0); | ||
SWTBotPluginOperations.addTextToEditor(bot, "MyClass.java", WEB_SERVLET_IMPORT_STRING, 7, 0); | ||
|
||
// Get quick-fix list | ||
List<String> quickFixes = SWTBotPluginOperations.getQuickFixList(bot, "MyClass.java"); | ||
|
||
boolean allFound = true; | ||
List<String> missingFixes = new ArrayList<String>(); | ||
for (String fix : webServlet_quickFixes) { | ||
if (!quickFixes.contains(fix)) { | ||
allFound = false; | ||
missingFixes.add(fix); | ||
} | ||
} | ||
|
||
assertTrue(allFound, "Missing quick-fixes: " + Arrays.toString(missingFixes.toArray())); | ||
|
||
} catch (Exception e) { | ||
fail("Unexpected exception was thrown: " + e); | ||
} finally { | ||
|
||
// Delete new file | ||
System.out.println("INFO: Deleting MyClass.java file"); | ||
LibertyPluginTestUtils.deleteFile(new File(wrapperProjectPath + "/src/main/java/test/maven/liberty/web/app/MyClass.java")); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have one for lsp4mp but not lsp4jakarta?