forked from OpenLiberty/liberty-tools-intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenLiberty#471 from mrglavas/main
Initial integration of automated LSP4Jakarta tests. (attempt #2)
- Loading branch information
Showing
63 changed files
with
4,008 additions
and
0 deletions.
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
62 changes: 62 additions & 0 deletions
62
...ava/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/GeneratedAnnotationTest.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,62 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.intellij.lsp4jakarta.it.annotations; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.openapi.vfs.VfsUtilCore; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import io.openliberty.tools.intellij.lsp4jakarta.it.core.BaseJakartaTest; | ||
import io.openliberty.tools.intellij.lsp4jakarta.it.core.JakartaForJavaAssert; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4jakarta.commons.JakartaDiagnosticsParams; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
@RunWith(JUnit4.class) | ||
public class GeneratedAnnotationTest extends BaseJakartaTest { | ||
|
||
@Test | ||
public void GeneratedAnnotation() throws Exception { | ||
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample")); | ||
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject); | ||
|
||
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module) | ||
+ "/src/main/java/io/openliberty/sample/jakarta/annotations/GeneratedAnnotation.java"); | ||
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString(); | ||
|
||
JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
|
||
// expected annotations | ||
Diagnostic d1 = JakartaForJavaAssert.d(7, 4, 63, | ||
"The annotation @Generated must define the attribute 'date' following the ISO 8601 standard.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "InvalidDateFormat"); | ||
|
||
Diagnostic d2 = JakartaForJavaAssert.d(13, 4, 70, | ||
"The annotation @Generated must define the attribute 'date' following the ISO 8601 standard.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "InvalidDateFormat"); | ||
|
||
|
||
JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d1, d2); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...io/openliberty/tools/intellij/lsp4jakarta/it/annotations/PostConstructAnnotationTest.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,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.intellij.lsp4jakarta.it.annotations; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.openapi.vfs.VfsUtilCore; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import io.openliberty.tools.intellij.lsp4jakarta.it.core.BaseJakartaTest; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.eclipse.lsp4jakarta.commons.JakartaDiagnosticsParams; | ||
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import static io.openliberty.tools.intellij.lsp4jakarta.it.core.JakartaForJavaAssert.*; | ||
|
||
@RunWith(JUnit4.class) | ||
public class PostConstructAnnotationTest extends BaseJakartaTest { | ||
|
||
@Test | ||
@Ignore | ||
public void GeneratedAnnotation() throws Exception { | ||
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample")); | ||
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject); | ||
|
||
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module) | ||
+ "/src/main/java/io/openliberty/sample/jakarta/annotations/PostConstructAnnotation.java"); | ||
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString(); | ||
|
||
JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
|
||
// expected Diagnostics | ||
|
||
Diagnostic d1 = d(15, 19, 31, "A method with the @PostConstruct annotation must be void.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructReturnType"); | ||
|
||
Diagnostic d2 = d(20, 16, 28, "A method with the @PostConstruct annotation must not have any parameters.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructParams"); | ||
|
||
Diagnostic d3 = d(25, 16, 28, "A method with the @PostConstruct annotation must not throw checked exceptions.", | ||
DiagnosticSeverity.Warning, "jakarta-annotations", "PostConstructException"); | ||
|
||
assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3); | ||
|
||
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); | ||
TextEdit te1 = te(19, 4, 20, 4, ""); | ||
TextEdit te2 = te(20, 29, 20, 40, ""); | ||
CodeAction ca1 = ca(uri, "Remove @PostConstruct", d2, te1); | ||
CodeAction ca2 = ca(uri, "Remove all parameters", d2, te2); | ||
assertJavaCodeAction(codeActionParams1, utils, ca1, ca2); | ||
|
||
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d1); | ||
TextEdit te3 = te(15, 11, 15, 18, "void"); | ||
CodeAction ca3 = ca(uri, "Change return type to void", d1, te3); | ||
assertJavaCodeAction(codeActionParams2, utils, ca3); | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...va/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/PreDestroyAnnotationTest.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,86 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.intellij.lsp4jakarta.it.annotations; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.openapi.vfs.VfsUtilCore; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import io.openliberty.tools.intellij.lsp4jakarta.it.core.BaseJakartaTest; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.eclipse.lsp4jakarta.commons.JakartaDiagnosticsParams; | ||
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import static io.openliberty.tools.intellij.lsp4jakarta.it.core.JakartaForJavaAssert.*; | ||
|
||
@RunWith(JUnit4.class) | ||
public class PreDestroyAnnotationTest extends BaseJakartaTest { | ||
|
||
@Test | ||
@Ignore | ||
public void GeneratedAnnotation() throws Exception { | ||
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample")); | ||
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject); | ||
|
||
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module) | ||
+ "/src/main/java/io/openliberty/sample/jakarta/annotations/PreDestroyAnnotation.java"); | ||
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString(); | ||
|
||
JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
|
||
// expected annotations | ||
|
||
Diagnostic d1 = d(20, 16, 28, "A method with the @PreDestroy annotation must not have any parameters.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "PreDestroyParams"); | ||
|
||
Diagnostic d2 = d(26, 20, 31, "A method with the @PreDestroy annotation must not be static.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "PreDestroyStatic"); | ||
d2.setData(9); | ||
|
||
Diagnostic d3 = d(31, 13, 25, "A method with the @PreDestroy annotation must not throw checked exceptions.", | ||
DiagnosticSeverity.Warning, "jakarta-annotations", "PreDestroyException"); | ||
|
||
assertJavaDiagnostics(diagnosticsParams, utils, d2, d1, d3); | ||
|
||
|
||
JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); | ||
TextEdit te = te(19, 1, 20, 1,""); | ||
TextEdit te1 = te(20, 29, 20, 40,""); | ||
CodeAction ca = ca(uri, "Remove @PreDestroy", d1, te); | ||
CodeAction ca1= ca(uri, "Remove all parameters", d1, te1); | ||
assertJavaCodeAction(codeActionParams, utils, ca, ca1); | ||
|
||
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); | ||
TextEdit te2 = te(25, 1, 26, 1,""); | ||
TextEdit te3 = te(26, 7, 26, 14,""); | ||
CodeAction ca2 = ca(uri, "Remove @PreDestroy", d2, te2); | ||
CodeAction ca3= ca(uri, "Remove the 'static' modifier from this method", d2, te3); | ||
assertJavaCodeAction(codeActionParams1, utils, ca2, ca3); | ||
|
||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.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,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.intellij.lsp4jakarta.it.annotations; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.openapi.vfs.VfsUtilCore; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import io.openliberty.tools.intellij.lsp4jakarta.it.core.BaseJakartaTest; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; | ||
import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.eclipse.lsp4jakarta.commons.JakartaDiagnosticsParams; | ||
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import static io.openliberty.tools.intellij.lsp4jakarta.it.core.JakartaForJavaAssert.*; | ||
|
||
@RunWith(JUnit4.class) | ||
public class ResourceAnnotationTest extends BaseJakartaTest { | ||
|
||
@Test | ||
@Ignore | ||
public void ResourceAnnotation() throws Exception { | ||
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample")); | ||
IPsiUtils utils = PsiUtilsLSImpl.getInstance(myProject); | ||
|
||
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module) | ||
+ "/src/main/java/io/openliberty/sample/jakarta/annotations/ResourceAnnotation.java"); | ||
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString(); | ||
|
||
JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
|
||
// expected annotations | ||
Diagnostic d1 = d(22, 0, 22, "The @Resource annotation must define the attribute 'type'.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceTypeAttribute"); | ||
|
||
Diagnostic d2 = d(39, 0, 30, "The @Resource annotation must define the attribute 'name'.", | ||
DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceNameAttribute"); | ||
|
||
|
||
assertJavaDiagnostics(diagnosticsParams, utils, d1, d2); | ||
|
||
|
||
JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); | ||
TextEdit te = te(22, 0, 22, 22, "@Resource(name = \"aa\", type = \"\")"); | ||
CodeAction ca= ca(uri, "Add type to jakarta.annotation.Resource", d1, te); | ||
assertJavaCodeAction(codeActionParams, utils, ca); | ||
|
||
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); | ||
TextEdit te1 = te(39, 0, 39, 30, "@Resource(type = \"\", name = \"\")"); | ||
CodeAction ca1= ca(uri, "Add name to jakarta.annotation.Resource", d2, te1); | ||
assertJavaCodeAction(codeActionParams1, utils, ca1); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.