diff --git a/projects/java/hello_springboot_app/src/main/java/hello/BUILD.bazel b/projects/java/hello_springboot_app/src/main/java/hello/BUILD.bazel index 8fb3ee0..14103dd 100644 --- a/projects/java/hello_springboot_app/src/main/java/hello/BUILD.bazel +++ b/projects/java/hello_springboot_app/src/main/java/hello/BUILD.bazel @@ -41,16 +41,6 @@ java_library( deps = springboot_deps + lib_deps, ) -# See: https://docs.bazel.build/versions/master/be/java.html#java_binary -# java_binary( -# name = "app", -# main_class = "hello.Application", -# visibility = ["//visibility:public"], -# runtime_deps = [ -# ":lib", -# ], -# ) - # Build the app as a Spring Boot executable jar springboot( name = "app", diff --git a/projects/java/hello_springboot_app/src/test/java/hello/BUILD.bazel b/projects/java/hello_springboot_app/src/test/java/hello/BUILD.bazel index 3a177a8..a2a9e79 100644 --- a/projects/java/hello_springboot_app/src/test/java/hello/BUILD.bazel +++ b/projects/java/hello_springboot_app/src/test/java/hello/BUILD.bazel @@ -5,7 +5,6 @@ java_test( deps = [ "//projects/java/hello_springboot_app/src/main/java/hello:lib", "@maven_springboot//:org_hamcrest_hamcrest", - # "@maven_springboot//:org_hamcrest_hamcrest_library", "@maven_springboot//:org_springframework_boot_spring_boot_test", "@maven_springboot//:org_springframework_boot_spring_boot_test_autoconfigure", "@maven_springboot//:org_springframework_boot_spring_boot_starter_web", @@ -23,7 +22,6 @@ java_test( deps = [ "//projects/java/hello_springboot_app/src/main/java/hello:lib", "@maven_springboot//:org_hamcrest_hamcrest", - # "@maven_springboot//:org_hamcrest_hamcrest_library", "@maven_springboot//:org_springframework_boot_spring_boot", "@maven_springboot//:org_springframework_boot_spring_boot_test", "@maven_springboot//:org_springframework_boot_spring_boot_test_autoconfigure", diff --git a/projects/java/hello_springboot_app/src/test/java/hello/HelloControllerIT.java b/projects/java/hello_springboot_app/src/test/java/hello/HelloControllerIT.java index fb0a7da..daac359 100644 --- a/projects/java/hello_springboot_app/src/test/java/hello/HelloControllerIT.java +++ b/projects/java/hello_springboot_app/src/test/java/hello/HelloControllerIT.java @@ -5,18 +5,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// import java.net.URL; - -// import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -// import org.springframework.boot.test.web.client.TestRestTemplate; -// import org.springframework.boot.test.web.server.LocalServerPort; -// import org.springframework.http.ResponseEntity; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -36,26 +30,3 @@ public void getHello() throws Exception { .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); } } - -// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -// public class HelloControllerIT { - -// @LocalServerPort -// private int port; - -// private URL base; - -// @Autowired -// private TestRestTemplate template; - -// @Before -// public void setUp() throws Exception { -// this.base = new URL("http://localhost:" + port + "/"); -// } - -// @Test -// public void getHello() throws Exception { -// ResponseEntity response = template.getForEntity(base.toString(), String.class); -// assertThat(response.getBody(), equalTo("Greetings from Spring Boot!")); -// } -// } diff --git a/projects/java/rs_springboot_app/BUILD.bazel b/projects/java/rs_springboot_app/BUILD.bazel index f9bff02..e6a255a 100644 --- a/projects/java/rs_springboot_app/BUILD.bazel +++ b/projects/java/rs_springboot_app/BUILD.bazel @@ -22,28 +22,29 @@ lib_deps = [ # create our deps list for Spring Boot springboot_deps = [ # "@rules_spring//springboot/import_bundles:springboot_required_deps", - # "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_jetty", - # "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_web", - # "@maven_springboot_v2//:org_springframework_boot_spring_boot_loader_tools", - # "@maven_springboot_v2//:org_springframework_spring_webmvc", + # "@maven_springboot//:org_springframework_boot_spring_boot_starter_jetty", + # "@maven_springboot//:org_springframework_boot_spring_boot_starter_web", + # "@maven_springboot//:org_springframework_boot_spring_boot_loader_tools", + # "@maven_springboot//:org_springframework_spring_webmvc", "@maven_pojo//:javax_annotation_javax_annotation_api", - "@maven_springboot_v2//:org_springframework_boot_spring_boot", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_actuator", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_actuator_autoconfigure", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_autoconfigure", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_loader", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_loader_tools", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_logging", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_jetty", - # "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_web", - # "@maven_springboot_v2//:org_springframework_boot_spring_boot_starter_parent", - "@maven_springboot_v2//:org_springframework_spring_aop", - "@maven_springboot_v2//:org_springframework_spring_beans", - "@maven_springboot_v2//:org_springframework_spring_context", - "@maven_springboot_v2//:org_springframework_spring_core", - "@maven_springboot_v2//:org_springframework_spring_expression", - "@maven_springboot_v2//:org_springframework_spring_web", + "@maven_springboot//:org_springframework_boot_spring_boot", + "@maven_springboot//:org_springframework_boot_spring_boot_actuator", + "@maven_springboot//:org_springframework_boot_spring_boot_actuator_autoconfigure", + "@maven_springboot//:org_springframework_boot_spring_boot_autoconfigure", + "@maven_springboot//:org_springframework_boot_spring_boot_loader", + "@maven_springboot//:org_springframework_boot_spring_boot_loader_tools", + "@maven_springboot//:org_springframework_boot_spring_boot_starter", + "@maven_springboot//:org_springframework_boot_spring_boot_starter_logging", + # "@maven_springboot//:org_springframework_boot_spring_boot_starter_jetty", + "@maven_springboot//:org_springframework_boot_spring_boot_starter_web", + # "@maven_springboot//:org_springframework_boot_spring_boot_starter_parent", + "@maven_springboot//:org_springframework_spring_aop", + "@maven_springboot//:org_springframework_spring_beans", + "@maven_springboot//:org_springframework_spring_context", + "@maven_springboot//:org_springframework_spring_core", + "@maven_springboot//:org_springframework_spring_expression", + "@maven_springboot//:org_springframework_spring_web", + # "@maven_springboot//:org_springframework_spring_webmvc", # bring in same dep again as above, but through a different maven_install # rule: the springboot rule does not package duplicate deps, first one wins @@ -71,6 +72,21 @@ java_test( timeout = "short", ) +springboottest_deps = [ + "@maven_springboot//:org_springframework_spring_beans", + "@maven_springboot//:org_springframework_boot_spring_boot_test", + "@maven_springboot//:org_springframework_spring_test", +] + +java_test( + name = "SampleRestFuncTest", + srcs = ["src/test/java/com/sample/SampleRestFuncTest.java"], + test_class = "com.sample.SampleRestFuncTest", + resources = glob(["src/test/resources/**"]), + deps = [ ":demoapp_lib" ] + test_deps + springboottest_deps, + timeout = "short", +) + # Build the app as a Spring Boot executable jar springboot( name = "demoapp", @@ -110,18 +126,3 @@ springboot( # these addins will be copied into the root of the generated springboot jar addins = [":info.txt", ":author.txt"], ) - -springboottest_deps = [ - "@maven_springboot_v2//:org_springframework_spring_beans", - "@maven_springboot_v2//:org_springframework_boot_spring_boot_test", - "@maven_springboot_v2//:org_springframework_spring_test", -] - -java_test( - name = "SampleRestFuncTest", - srcs = ["src/test/java/com/sample/SampleRestFuncTest.java"], - test_class = "com.sample.SampleRestFuncTest", - resources = glob(["src/test/resources/**"]), - deps = [ ":demoapp_lib" ] + test_deps + springboottest_deps, - timeout = "short", -) diff --git a/projects/java/rs_springboot_app/src/main/java/com/sample/SampleMain.java b/projects/java/rs_springboot_app/src/main/java/com/sample/SampleMain.java index e5c17ee..fb6e639 100644 --- a/projects/java/rs_springboot_app/src/main/java/com/sample/SampleMain.java +++ b/projects/java/rs_springboot_app/src/main/java/com/sample/SampleMain.java @@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.SpringApplication; + import com.bazel.demo.IntentionalDupedClass; @SpringBootApplication diff --git a/projects/java/rs_springboot_app/src/test/java/com/sample/SampleRestFuncTest.java b/projects/java/rs_springboot_app/src/test/java/com/sample/SampleRestFuncTest.java index 05df8bc..a9de9ba 100644 --- a/projects/java/rs_springboot_app/src/test/java/com/sample/SampleRestFuncTest.java +++ b/projects/java/rs_springboot_app/src/test/java/com/sample/SampleRestFuncTest.java @@ -19,25 +19,16 @@ * This test class starts the Spring Boot application. Because the Spring context is * created, you can autowire spring beans into the test. */ -// @RunWith(SpringRunner.class) -// @SpringBootTest(classes = SampleMain.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -// @TestPropertySource(locations = {"classpath:/test.properties"}) -// public class SampleRestFuncTest { - -// // @Autowired -// private SampleRest sampleRest; - -// @Test -// public void apiTest() { -// assertEquals("Hello!", sampleRest.hello()); -// } -// } - -@SpringBootTest +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SampleMain.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestPropertySource(locations = {"classpath:/test.properties"}) public class SampleRestFuncTest { + @Autowired + private SampleRest sampleRest; + @Test - public void contextLoads() { + public void apiTest() { + assertEquals("Hello!", sampleRest.hello()); } - }