Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
public class MigrateAnnotatedServletsIntegrationTest extends IntegrationTestBaseClass {


Expand All @@ -31,6 +30,7 @@ protected String getTestSubDir() {
return "bootify-servlets";
}

@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
@Tag("integration")
@Test
void happyPath() {
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}

@Test
void recipeNBotApplicableWhenOnlyFilterExists() {
void shouldMigrateWebFilter() {
String pom = """
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
Expand All @@ -152,9 +152,19 @@ void recipeNBotApplicableWhenOnlyFilterExists() {
String servletFilterClass = """
package org.jboss.as.quickstarts.helloworld;
import javax.servlet.annotation.WebFilter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

@WebFilter("/")
public class MyFilter {
public class MyFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
}
""";

Expand All @@ -165,8 +175,16 @@ public class MyFilter {

scanProject();

assertRecipeNotApplicable(
assertApplicableRecipesContain(
"initialize-spring-boot-migration",
"migrate-annotated-servlets"
);

applyRecipe("initialize-spring-boot-migration");
applyRecipe("migrate-annotated-servlets");

String content = loadJavaFile("org.jboss.as.quickstarts.helloworld", "SpringBootApp");
assertThat(content).contains("@SpringBootApplication").withFailMessage(() -> "@SpringBootApplication annotation not found");
assertThat(content).contains("@ServletComponentScan").withFailMessage(() -> "@ServletComponentScan annotation not found");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- name: migrate-annotated-servlets
description: Allow Spring Boot to deploy servlets annotated with @WebServlet
description: Allow Spring Boot to deploy servlets and filters annotated with @WebServlet or @WebFilter
order: 70
condition:
description: Any class has import starting with javax.servlet
type: org.springframework.sbm.java.migration.conditions.HasTypeAnnotation
annotation: javax.servlet.annotation.WebServlet
description: Any class has import starting with javax.servlet.annotation
type: org.springframework.sbm.java.migration.conditions.HasImportStartingWith
value: javax.servlet.annotation
actions:
- type: org.springframework.sbm.build.migration.actions.AddDependencies
condition:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.examples.jee.web;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "The Filter", urlPatterns = {"/*"})
public class TheFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}

@Override
public void destroy() {
}
}