|
| 1 | +package com.reajason.javaweb.integration.jetty; |
| 2 | + |
| 3 | +import com.reajason.javaweb.integration.TestCasesProvider; |
| 4 | +import com.reajason.javaweb.memshell.Packers; |
| 5 | +import com.reajason.javaweb.memshell.Server; |
| 6 | +import com.reajason.javaweb.memshell.ShellTool; |
| 7 | +import com.reajason.javaweb.memshell.ShellType; |
| 8 | +import lombok.extern.slf4j.Slf4j; |
| 9 | +import net.bytebuddy.jar.asm.Opcodes; |
| 10 | +import org.junit.jupiter.api.AfterAll; |
| 11 | +import org.junit.jupiter.params.ParameterizedTest; |
| 12 | +import org.junit.jupiter.params.provider.Arguments; |
| 13 | +import org.junit.jupiter.params.provider.MethodSource; |
| 14 | +import org.testcontainers.containers.DockerComposeContainer; |
| 15 | +import org.testcontainers.junit.jupiter.Container; |
| 16 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import java.util.List; |
| 20 | +import java.util.stream.Stream; |
| 21 | + |
| 22 | +import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; |
| 23 | +import static com.reajason.javaweb.integration.ShellAssertionTool.testShellInjectAssertOk; |
| 24 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author ReaJason |
| 28 | + * @since 2024/12/7 |
| 29 | + */ |
| 30 | +@Slf4j |
| 31 | +@Testcontainers |
| 32 | +public class Jetty12ee10ContainerTest { |
| 33 | + public static final String imageName = "jetty:12.0-jre21-ee10"; |
| 34 | + public static final String serviceName = "jetty1221ee10"; |
| 35 | + |
| 36 | + @Container |
| 37 | + public static final DockerComposeContainer<?> compose = |
| 38 | + new DockerComposeContainer<>(new File("docker-compose/jetty/docker-compose-12-jre21-ee10.yaml")) |
| 39 | + .withExposedService(serviceName, 8080); |
| 40 | + |
| 41 | + static Stream<Arguments> casesProvider() { |
| 42 | + Server server = Server.Jetty; |
| 43 | + List<String> supportedShellTypes = List.of( |
| 44 | + ShellType.JAKARTA_SERVLET, |
| 45 | + ShellType.JAKARTA_FILTER, |
| 46 | + ShellType.JAKARTA_LISTENER |
| 47 | + ); |
| 48 | + List<Packers> testPackers = List.of(Packers.Base64); |
| 49 | + return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, |
| 50 | + null, List.of(ShellTool.AntSword, ShellTool.NeoreGeorg) // AntSword not supported Jakarta |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + @AfterAll |
| 55 | + static void tearDown() { |
| 56 | + String logs = compose.getContainerByServiceName(serviceName).get().getLogs(); |
| 57 | + assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); |
| 58 | + } |
| 59 | + |
| 60 | + public static String getUrl() { |
| 61 | + String host = compose.getServiceHost(serviceName, 8080); |
| 62 | + int port = compose.getServicePort(serviceName, 8080); |
| 63 | + String url = "http://" + host + ":" + port + "/app"; |
| 64 | + log.info("container started, app url is : {}", url); |
| 65 | + return url; |
| 66 | + } |
| 67 | + |
| 68 | + @ParameterizedTest(name = "{0}|{1}{2}|{3}") |
| 69 | + @MethodSource("casesProvider") |
| 70 | + void test(String imageName, String shellType, ShellTool shellTool, Packers packer) { |
| 71 | + testShellInjectAssertOk(getUrl(), Server.Jetty, shellType, shellTool, Opcodes.V21, packer, null); |
| 72 | + } |
| 73 | +} |
0 commit comments