Skip to content

Commit

Permalink
fix:PR-3 Final fix from recent upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ipv1337 committed Oct 4, 2023
1 parent 20b6ff5 commit 63e6591
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 94 deletions.
10 changes: 0 additions & 10 deletions projects/java/hello_springboot_app/src/main/java/hello/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> response = template.getForEntity(base.toString(), String.class);
// assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
// }
// }
73 changes: 37 additions & 36 deletions projects/java/rs_springboot_app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;

import com.bazel.demo.IntentionalDupedClass;

@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 63e6591

Please sign in to comment.