load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "JUNIT5_DEPS", "java_binary", "java_library", "java_test_suite")
load("//java:version.bzl", "TOOLS_JAVA_VERSION")
load("//java/private:selenium_test.bzl", "BROWSERS")

filegroup(
    name = "keystore",
    srcs = [
        "webserver/keystore",
    ],
    visibility = [
        "//dotnet/test:__subpackages__",
    ],
)

java_library(
    name = "environment",
    testonly = True,
    srcs = glob(
        [
            "*.java",
            "webserver/*.java",
        ],
        exclude = [
            "**/*Test.java",
            "**/*TestBase.java",
        ],
    ),
    data = [
        "webserver/keystore",
        "//common/extensions",
        "//common/src/web",
        "//javascript/atoms",
        "//javascript/atoms:deps",
        "//third_party/closure/goog",
        "//third_party/js/sizzle",
        "@com_google_javascript_closure_library",
    ],
    javacopts = [
        "--release",
        TOOLS_JAVA_VERSION,
    ],
    visibility = [
        "//java/test:__subpackages__",
        "//javascript:__subpackages__",
    ],
    deps = [
        "//java/src/org/openqa/selenium:core",
        "//java/src/org/openqa/selenium/grid/config",
        "//java/src/org/openqa/selenium/grid/security",
        "//java/src/org/openqa/selenium/grid/server",
        "//java/src/org/openqa/selenium/grid/web",
        "//java/src/org/openqa/selenium/json",
        "//java/src/org/openqa/selenium/netty/server",
        "//java/src/org/openqa/selenium/remote",
        "//java/src/org/openqa/selenium/remote/http",
        "//java/test/org/openqa/selenium/build",
        artifact("com.google.guava:guava"),
        artifact("dev.failsafe:failsafe"),
        artifact("org.assertj:assertj-core"),
    ],
)

java_binary(
    name = "appserver",
    testonly = True,
    main_class = "org.openqa.selenium.environment.webserver.NettyAppServer",
    visibility = [
        "//:__pkg__",
        "//dotnet/test:__subpackages__",
    ],
    runtime_deps = [
        ":environment",
    ],
)

java_binary(
    name = "jre-server",
    testonly = True,
    main_class = "org.openqa.selenium.environment.webserver.JreAppServer",
    visibility = [
        "//dotnet/test:__subpackages__",
    ],
    runtime_deps = [
        ":environment",
    ],
)

java_library(
    name = "test-base",
    testonly = True,
    srcs = ["webserver/AppServerTestBase.java"],
    deps = [
        ":environment",
        "//java/src/org/openqa/selenium:core",
        "//java/src/org/openqa/selenium/remote/http",
        "//java/src/org/openqa/selenium/support",
        "//java/test/org/openqa/selenium/testing/drivers",
        artifact("org.junit.jupiter:junit-jupiter-api"),
    ] + JUNIT5_DEPS,
)

firefox = BROWSERS["firefox"]

java_test_suite(
    name = "LargeTests",
    size = "large",
    srcs = glob(["**/*Test.java"]),
    data = firefox["data"],
    jvm_flags = firefox["jvm_flags"],
    tags = [
        "firefox",
        "selenium-remote",
    ] + firefox["tags"],
    deps = [
        ":environment",
        ":test-base",
        artifact("org.junit.jupiter:junit-jupiter-api"),
    ] + firefox["deps"] + JUNIT5_DEPS,
)
