Skip to content
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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>aarch64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
Expand Down
2 changes: 1 addition & 1 deletion releng/io.openliberty.tools.update/category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</feature>

<category-def name="io.openliberty.tools.eclipse" label="Liberty Tools" />

<repository-reference location="https://download.eclipse.org/lsp4mp/releases/0.7.0/repository" enabled="true" />
<repository-reference location="https://download.eclipse.org/lsp4jakarta/releases/0.1.1/repository" enabled="true" />

Expand Down
4 changes: 3 additions & 1 deletion tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Bundle-Version: 23.0.9.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: junit-jupiter-api;bundle-version="[5.8.0,6.0.0)",
org.eclipse.ui,
org.hamcrest.library;bundle-version="[1.3.0,2.2)"
org.hamcrest.library;bundle-version="[1.3.0,2.2)",
io.openliberty.tools.eclipse.lsp4e
Import-Package: io.openliberty.tools.eclipse,
io.openliberty.tools.eclipse.ui.dashboard,
io.openliberty.tools.eclipse.ui.launch,
Expand All @@ -18,6 +19,7 @@ Import-Package: io.openliberty.tools.eclipse,
org.eclipse.core.runtime.preferences,
org.eclipse.debug.core,
org.eclipse.debug.ui,
org.eclipse.jdt.core,
org.eclipse.jdt.launching,
org.eclipse.m2e.core,
org.eclipse.m2e.core.embedder,
Expand Down
12 changes: 11 additions & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<properties>
<testAppImportWait>60000</testAppImportWait>
</properties>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -100,6 +100,16 @@
<id>org.eclipse.lsp4e.jdt</id>
<versionRange>0.0.0</versionRange>
</requirement>
<requirement>
Copy link
Member

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?

<type>p2-installable-unit</type>
<id>org.eclipse.lsp4jakarta.jdt.core</id>
<versionRange>0.0.0</versionRange>
</requirement>
<requirement>
<type>p2-installable-unit</type>
<id>org.eclipse.jdt.ls.core</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/servlet")
public class HelloServlet extends HttpServlet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-->
<server description="Sample Servlet server">
<featureManager>
<feature>jsp-2.3</feature>
<feature>jsp-3.1</feature>
</featureManager>

<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/servlet")
public class HelloServlet extends HttpServlet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-->
<server description="Sample Servlet server">
<featureManager>
<feature>jsp-2.3</feature>
<feature>jsp-3.1</feature>
</featureManager>

<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" />
Expand Down
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"));
}
}
}
Loading
Loading