-
Notifications
You must be signed in to change notification settings - Fork 73
test: added test case for jakarta/java/codeAction cancellation #1363
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
9728ddf
e5544be
8477a03
5707c8a
f2bb45e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Red Hat, Inc. | ||
| * Distributed under license by Red Hat, Inc. All rights reserved. | ||
| * This program is made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, | ||
| * and is available at http://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| ******************************************************************************/ | ||
| package com.redhat.devtools.lsp4ij.features.codeAction; | ||
|
|
||
| import com.redhat.devtools.lsp4ij.fixtures.LSPCodeActionFixtureTestCase; | ||
|
|
||
| /** | ||
| * Test case for InvalidWebFilter quick fix | ||
| */ | ||
| public class CodeActionCancellationTest extends LSPCodeActionFixtureTestCase { | ||
|
|
||
| private static final String NOT_JAVA_EXTENSION = "javax"; | ||
| private static final String TEST_FILE_NAME = "InvalidWebFilter." + NOT_JAVA_EXTENSION; | ||
|
|
||
| public CodeActionCancellationTest() { | ||
| super("*." + NOT_JAVA_EXTENSION); | ||
| } | ||
|
|
||
| public void testWebFilterQuickFix() { | ||
|
|
||
| assertCodeActions(TEST_FILE_NAME, | ||
| IntentionActionKind.QUICK_FIX_ONLY, | ||
| // language=JAVA | ||
| """ | ||
| package io.openliberty.sample.jakarta.servlet; | ||
| import jakarta.servlet.Filter; | ||
| import jakarta.servlet.annotation.WebFilter; | ||
| @WebFilter(<caret>) | ||
| public abstract class InvalidWebFilter implements Filter { | ||
| }""", | ||
| // language=JSON | ||
| """ | ||
| [ | ||
| { | ||
| "title": "Add the `servletNames` attribute to @WebFilter", | ||
| "kind": "quickfix", | ||
| "diagnostics": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "severity": 1, | ||
| "code": "CompleteWebFilterAttributes", | ||
| "source": "jakarta-servlet", | ||
| "message": "The annotation @WebFilter must define the attribute \\u0027urlPatterns\\u0027, \\u0027servletNames\\u0027 or \\u0027value\\u0027." | ||
| } | ||
| ], | ||
| "data": { | ||
| "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix", | ||
| "documentUri": "unused", | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "extendedData": { | ||
| "annotation": "jakarta.servlet.annotation.WebFilter", | ||
| "attribute": "servletNames", | ||
| "diagnosticCode": "CompleteWebFilterAttributes" | ||
| }, | ||
| "resourceOperationSupported": true, | ||
| "commandConfigurationUpdateSupported": false | ||
| } | ||
| }, | ||
| { | ||
| "title": "Add the `urlPatterns` attribute to @WebFilter", | ||
| "kind": "quickfix", | ||
| "diagnostics": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "severity": 1, | ||
| "code": "CompleteWebFilterAttributes", | ||
| "source": "jakarta-servlet", | ||
| "message": "The annotation @WebFilter must define the attribute \\u0027urlPatterns\\u0027, \\u0027servletNames\\u0027 or \\u0027value\\u0027." | ||
| } | ||
| ], | ||
| "data": { | ||
| "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix", | ||
| "documentUri": "unused", | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "extendedData": { | ||
| "annotation": "jakarta.servlet.annotation.WebFilter", | ||
| "attribute": "urlPatterns", | ||
| "diagnosticCode": "CompleteWebFilterAttributes" | ||
| }, | ||
| "resourceOperationSupported": true, | ||
| "commandConfigurationUpdateSupported": false | ||
| } | ||
| }, | ||
| { | ||
| "title": "Add the `value` attribute to @WebFilter", | ||
| "kind": "quickfix", | ||
| "diagnostics": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "severity": 1, | ||
| "code": "CompleteWebFilterAttributes", | ||
| "source": "jakarta-servlet", | ||
| "message": "The annotation @WebFilter must define the attribute \\u0027urlPatterns\\u0027, \\u0027servletNames\\u0027 or \\u0027value\\u0027." | ||
| } | ||
| ], | ||
| "data": { | ||
| "participantId": "io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.CompleteFilterAnnotationQuickFix", | ||
| "documentUri": "unused", | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 12 | ||
| } | ||
| }, | ||
| "extendedData": { | ||
| "annotation": "jakarta.servlet.annotation.WebFilter", | ||
| "attribute": "value", | ||
| "diagnosticCode": "CompleteWebFilterAttributes" | ||
| }, | ||
| "resourceOperationSupported": true, | ||
| "commandConfigurationUpdateSupported": false | ||
| } | ||
| } | ||
| ] | ||
| """, | ||
| true, // simulateCancellation = true | ||
| "Add the `servletNames` attribute to @WebFilter", | ||
| "Add the `urlPatterns` attribute to @WebFilter", | ||
| "Add the `value` attribute to @WebFilter" | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,6 +173,7 @@ public abstract class InvalidWebFilter implements Filter { | |
| } | ||
| ]""" | ||
| , | ||
| false, // simulateCancellation = false | ||
|
||
| "Add the `servletNames` attribute to @WebFilter", | ||
| "Add the `urlPatterns` attribute to @WebFilter", | ||
| "Add the `value` attribute to @WebFilter"); | ||
|
|
||
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.
To show in action the cancel support easily, I suggest that you remove this classe and you do test in the same WebFilterQuickFixTest.
This class could define a private method like
assertCodeActionss(boolen simulateCancellation , @NotNull String... expectedActions) (which will call
and after that you could define 2 tests methods:
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.
@angelozerr I’ve made the modification as suggested, with a small change — since expectedActions is included in the request, I had to add that argument for both tests. Thanks!
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.
Please do my suggestion to fix tests