Skip to content

Commit

Permalink
Merge pull request OpenLiberty#471 from mrglavas/main
Browse files Browse the repository at this point in the history
Initial integration of automated LSP4Jakarta tests. (attempt #2)
  • Loading branch information
mrglavas authored Jun 30, 2023
2 parents 784eb1c + 9873332 commit 502aa77
Show file tree
Hide file tree
Showing 63 changed files with 4,008 additions and 0 deletions.
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ repositories {
maven {
url = "https://packages.jetbrains.team/maven/p/ij/intellij-dependencies"
}
maven {
url = "https://www.jetbrains.com/intellij-repository/releases"
}
maven {
url = "https://packages.jetbrains.team/maven/p/kpm/public"
}
maven {
url = "https://cache-redirector.jetbrains.com/packages.jetbrains.team/maven/p/grazi/grazie-platform-public"
}
maven {
url = "https://download.jetbrains.com/teamcity-repository"
}
maven {
url = "https://cache-redirector.jetbrains.com/download-pgp-verifier"
}

mavenLocal() // TODO remove once Liberty LS is publicly available
}

Expand Down Expand Up @@ -66,9 +82,16 @@ dependencies {
testImplementation 'com.intellij.remoterobot:remote-robot:' + remoteRobotVersion
testImplementation 'com.intellij.remoterobot:remote-fixtures:' + remoteRobotVersion
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation('com.jetbrains.intellij.maven:maven-test-framework:231.9011.34') {
transitive = false
}
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.9.2'

// JUnit 4
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.3'

// Test: Logging Network Calls.
testImplementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

Expand Down
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);
}

}
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);
}

}
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);

}

}
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);

}

}
Loading

0 comments on commit 502aa77

Please sign in to comment.