Skip to content

Commit

Permalink
fix:PR-2 Fixed hello_springboot_app tests after recent upgrade (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipv1337 committed Oct 4, 2023
1 parent 6a2e22e commit 20b6ff5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ java_test(
# "@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",
"@maven_springboot//:org_springframework_boot_spring_boot_starter_web",
"@maven_springboot//:org_springframework_spring_beans",
"@maven_springboot//:org_springframework_spring_test",
"@maven_springboot//:org_springframework_spring_web",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
package hello;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.equalTo;

import java.net.URL;
import org.junit.Before;
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.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;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerIT {

@Test
public void contextLoads() {
}
@Autowired private MockMvc mvc;

@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}

// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Expand All @@ -46,18 +59,3 @@ public void contextLoads() {
// assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
// }
// }

// @RunWith(SpringRunner.class)
// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// public class HelloControllerIT {

// @Test
// void exampleTest(@Autowired WebTestClient webClient) {
// webClient
// .get().uri("/")
// .exchange()
// .expectStatus().isOk()
// .expectBody(String.class).isEqualTo("Greetings from Spring Boot!");
// }

// }
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package hello;

import static org.hamcrest.Matchers.equalTo;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

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;
Expand All @@ -14,26 +16,17 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {

@Test
public void contextLoads() {
}
@Autowired private MockMvc mvc;

@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}

// @RunWith(SpringRunner.class)
// @SpringBootTest
// @AutoConfigureMockMvc
// public class HelloControllerTest {

// @Autowired private MockMvc mvc;

// @Test
// public void getHello() throws Exception {
// mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk())
// .andExpect(content().string(equalTo("Greetings from Spring Boot!")));
// }
// }

0 comments on commit 20b6ff5

Please sign in to comment.