feat: support bypassJdkModule and Jakarta

This commit is contained in:
ReaJason
2024-11-29 02:02:04 +08:00
parent d0dcc8d56f
commit b6ce6581a0
40 changed files with 1167 additions and 686 deletions
@@ -0,0 +1,59 @@
package godzilla;
import com.reajason.javaweb.config.GodzillaShellConfig;
import com.reajason.javaweb.godzilla.GodzillaManager;
import lombok.SneakyThrows;
import okhttp3.*;
import org.junit.jupiter.api.Assertions;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author ReaJason
* @since 2024/11/28
*/
public interface BaseGodzillaTest {
OkHttpClient client = new OkHttpClient();
@SneakyThrows
default void verifyContainerResponse(String url) {
Request request = new Request.Builder()
.url(url).build();
try (Response response = client.newCall(request).execute()) {
Assertions.assertEquals(200, response.code());
}
}
@SneakyThrows
default void uploadJspFileToServer(String uploadUrl, String filename, String fileContent) {
MediaType mediaType = MediaType.parse("text/plain");
RequestBody fileRequestBody = RequestBody.create(fileContent, mediaType);
MultipartBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", filename, fileRequestBody)
.build();
Request request = new Request.Builder()
.url(uploadUrl).post(requestBody)
.build();
try (Response response = client.newCall(request).execute()) {
Assertions.assertEquals(200, response.code());
}
}
default void testGodzillaIsOk(String entrypoint, GodzillaShellConfig shellConfig) {
try (GodzillaManager godzillaManager = GodzillaManager.builder()
.entrypoint(entrypoint)
.pass(shellConfig.getPass())
.key(shellConfig.getKey())
.header(shellConfig.getHeaderName(), shellConfig.getHeaderValue()).build()) {
assertTrue(godzillaManager.start());
assertTrue(godzillaManager.test());
} catch (IOException e) {
e.printStackTrace();
}
}
}