Skip to content

Commit

Permalink
Enabled the tests are working
Browse files Browse the repository at this point in the history
  • Loading branch information
vaisakhkannan committed Mar 5, 2024
1 parent 8486071 commit 463435b
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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;
Expand Down Expand Up @@ -57,7 +56,7 @@ public void managedBeanAnnotations() throws Exception {
Diagnostic d1 = d(6, 12, 13,
"The @Dependent annotation must be the only scope defined by a managed bean with a non-static public field.",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidManagedBeanAnnotation");

Diagnostic d2 = d(5, 13, 24,
"Managed bean class of generic type must have scope @Dependent.",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidManagedBeanAnnotation");
Expand Down Expand Up @@ -87,7 +86,7 @@ public void managedBeanAnnotations() throws Exception {
CodeAction ca2 = ca(uri, "Replace current scope with @Dependent", d2, te2);
assertJavaCodeAction(codeActionParams2, utils, ca2);
}

@Test
public void scopeDeclaration() throws Exception {
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
Expand All @@ -104,46 +103,92 @@ public void scopeDeclaration() throws Exception {
Diagnostic d1 = d(12, 16, 17,
"Scope type annotations must be specified by a producer field at most once.",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidScopeDecl");
d1.setData(new Gson().toJsonTree(Arrays.asList("Dependent", "ApplicationScoped", "Produces")));
d1.setData(new Gson().toJsonTree(Arrays.asList("jakarta.enterprise.context.Dependent",
"jakarta.enterprise.context.ApplicationScoped", "Produces")));

Diagnostic d2 = d(15, 25, 41, "Scope type annotations must be specified by a producer method at most once.",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidScopeDecl");
d2.setData(new Gson().toJsonTree(Arrays.asList("ApplicationScoped", "RequestScoped", "Produces")));

Diagnostic d3 = d(10, 13, 29, "Scope type annotations must be specified by a managed bean class at most once.",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidScopeDecl");
d3.setData(new Gson().toJsonTree(Arrays.asList("ApplicationScoped", "RequestScoped")));
Diagnostic d2 = d(15, 25, 41, "Scope type annotations must be specified " +
"by a producer method at most once.", DiagnosticSeverity.Error, "jakarta-cdi",
"InvalidScopeDecl");
d2.setData(new Gson().toJsonTree(Arrays.asList("jakarta.enterprise.context.ApplicationScoped",
"jakarta.enterprise.context.RequestScoped", "Produces")));

Diagnostic d3 = d(10, 13, 29, "Scope type annotations must be " +
"specified by a managed bean class at most once.", DiagnosticSeverity.Error,
"jakarta-cdi", "InvalidScopeDecl");
d3.setData(new Gson().toJsonTree(Arrays.asList("jakarta.enterprise.context.ApplicationScoped",
"jakarta.enterprise.context.RequestScoped")));

assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3);

if (CHECK_CODE_ACTIONS) {
// Assert for the diagnostic d1
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d1);
TextEdit te1 = te(11, 33, 12, 4, "");
TextEdit te2 = te(11, 14, 11, 33, "");
CodeAction ca1 = ca(uri, "Remove @ApplicationScoped", d1, te2);
CodeAction ca2 = ca(uri, "Remove @Dependent", d1, te1);

assertJavaCodeAction(codeActionParams1, utils, ca1, ca2);

// Assert for the diagnostic d2
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d2);
TextEdit te3 = te(14, 33, 15, 4, "");
TextEdit te4 = te(14, 14, 14, 33, "");
CodeAction ca3 = ca(uri, "Remove @RequestScoped", d2, te3);
CodeAction ca4 = ca(uri, "Remove @ApplicationScoped", d2, te4);

assertJavaCodeAction(codeActionParams2, utils, ca3, ca4);

// Assert for the diagnostic d3
JakartaJavaCodeActionParams codeActionParams3 = createCodeActionParams(uri, d3);
TextEdit te5 = te(9, 19, 10, 0, "");
TextEdit te6 = te(9, 0, 9, 19, "");
CodeAction ca5 = ca(uri, "Remove @RequestScoped", d3, te5);
CodeAction ca6 = ca(uri, "Remove @ApplicationScoped", d3, te6);

assertJavaCodeAction(codeActionParams3, utils, ca5, ca6);
}
//TODO: Uncomment this line of code once all the quickfix changes are done.
// if (CHECK_CODE_ACTIONS) {
// Assert for the diagnostic d1
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d1);
String newText = "package io.openliberty.sample.jakarta.cdi;\n\nimport java.util.Collections;" +
"\nimport java.util.List;\n\nimport jakarta.enterprise.inject.Produces;\n\n" +
"import jakarta.enterprise.context.*;\n\n@ApplicationScoped @RequestScoped\n" +
"public class ScopeDeclaration {\n @Produces @Dependent\n private int n;\n " +
" \n @Produces @ApplicationScoped @RequestScoped\n public List<Integer> getAllProductIds() " +
"{\n return Collections.emptyList();\n }\n}";

String newText1 = "package io.openliberty.sample.jakarta.cdi;\n\n" +
"import java.util.Collections;\nimport java.util.List;\n\n" +
"import jakarta.enterprise.inject.Produces;\n\nimport jakarta.enterprise.context.*;" +
"\n\n@ApplicationScoped @RequestScoped\npublic class ScopeDeclaration {\n " +
" @Produces @ApplicationScoped\n private int n;\n \n @Produces @ApplicationScoped" +
" @RequestScoped\n public List<Integer> getAllProductIds() {\n " +
"return Collections.emptyList();\n }\n}";

TextEdit te1 = te(0, 0, 18, 1, newText);
TextEdit te2 = te(0, 0, 18, 1, newText1);
CodeAction ca1 = ca(uri, "Remove @ApplicationScoped", d1, te1);
CodeAction ca2 = ca(uri, "Remove @Dependent", d1, te2);
assertJavaCodeAction(codeActionParams1, utils, ca1,ca2);

// Assert for the diagnostic d2
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d2);
newText = "package io.openliberty.sample.jakarta.cdi;\n\nimport java.util.Collections;\n" +
"import java.util.List;\n\nimport jakarta.enterprise.inject.Produces;\n\n" +
"import jakarta.enterprise.context.*;\n\n@ApplicationScoped @RequestScoped\n" +
"public class ScopeDeclaration {\n @Produces @ApplicationScoped @Dependent\n " +
" private int n;\n \n @Produces @RequestScoped\n public List<Integer> getAllProductIds()" +
" {\n return Collections.emptyList();\n }\n}";

newText1 = "package io.openliberty.sample.jakarta.cdi;\n\nimport java.util.Collections;\nimport " +
"java.util.List;\n\nimport jakarta.enterprise.inject.Produces;\n\nimport " +
"jakarta.enterprise.context.*;\n\n@ApplicationScoped @RequestScoped\npublic class ScopeDeclaration" +
" {\n @Produces @ApplicationScoped @Dependent\n private int n;\n \n " +
" @Produces @ApplicationScoped\n public List<Integer> getAllProductIds() {\n " +
" return Collections.emptyList();\n }\n}";

TextEdit te3 = te(0, 0, 18, 1, newText1);
TextEdit te4 = te(0, 0, 18, 1, newText);
CodeAction ca3 = ca(uri, "Remove @RequestScoped", d2, te3);
CodeAction ca4 = ca(uri, "Remove @ApplicationScoped", d2, te4);
assertJavaCodeAction(codeActionParams2, utils, ca4, ca3);

// Assert for the diagnostic d3
JakartaJavaCodeActionParams codeActionParams3 = createCodeActionParams(uri, d3);
newText = "package io.openliberty.sample.jakarta.cdi;\n\nimport java.util.Collections;\n" +
"import java.util.List;\n\nimport jakarta.enterprise.inject.Produces;\n\n" +
"import jakarta.enterprise.context.*;\n\n@RequestScoped\npublic class ScopeDeclaration {\n " +
" @Produces @ApplicationScoped @Dependent\n private int n;\n \n " +
" @Produces @ApplicationScoped @RequestScoped\n public List<Integer> getAllProductIds() {\n " +
" return Collections.emptyList();\n }\n}";

newText1 = "package io.openliberty.sample.jakarta.cdi;\n\nimport java.util.Collections;" +
"\nimport java.util.List;\n\nimport jakarta.enterprise.inject.Produces;\n\n" +
"import jakarta.enterprise.context.*;\n\n@ApplicationScoped\npublic class ScopeDeclaration {\n " +
" @Produces @ApplicationScoped @Dependent\n private int n;\n \n " +
"@Produces @ApplicationScoped @RequestScoped\n public List<Integer> getAllProductIds() {\n " +
" return Collections.emptyList();\n }\n}";

TextEdit te5 = te(0, 0, 18, 1, newText1);
TextEdit te6 = te(0, 0, 18, 1, newText);
CodeAction ca5 = ca(uri, "Remove @RequestScoped", d3, te5);
CodeAction ca6 = ca(uri, "Remove @ApplicationScoped", d3, te6);
assertJavaCodeAction(codeActionParams3, utils, ca6, ca5);
// }
}

@Test
Expand Down Expand Up @@ -1257,7 +1302,7 @@ public void producesAndDisposesObservesObservesAsync() throws Exception {
assertJavaCodeAction(codeActionParams8, utils, ca20, ca21);
}


@Test
public void multipleDisposes() throws Exception {
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
Expand All @@ -1266,14 +1311,14 @@ public void multipleDisposes() throws Exception {
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(ModuleUtilCore.getModuleDirPath(module)
+ "/src/main/java/io/openliberty/sample/jakarta/cdi/MultipleDisposes.java");
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

JakartaDiagnosticsParams diagnosticsParams = new JakartaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

Diagnostic d = d(9, 18, 23,
"The @Disposes annotation must not be defined on more than one parameter of a method.",
DiagnosticSeverity.Error, "jakarta-cdi", "RemoveExtraDisposes");

assertJavaDiagnostics(diagnosticsParams, utils, d);
}
}
Loading

0 comments on commit 463435b

Please sign in to comment.