Minor cleanup
This commit is contained in:
parent
3385b72fb5
commit
73e3e356fa
5 changed files with 56 additions and 47 deletions
19
.idea/misc.xml
generated
19
.idea/misc.xml
generated
|
@ -1,4 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0">
|
||||||
|
<entry_point TYPE="field" FQNAME="com.example.springboot.HelloControllerTest mvc" />
|
||||||
|
<entry_point TYPE="field" FQNAME="com.example.springboot.HelloControllerIT template" />
|
||||||
|
</entry_points>
|
||||||
|
<pattern value="com.example.springboot.Application" />
|
||||||
|
<pattern value="com.example.springboot.ApplicationBuild" />
|
||||||
|
<pattern value="com.example.springboot.Application" method="commandLineRunner" />
|
||||||
|
<pattern value="com.example.springboot.HelloControllerIT" method="getHello" />
|
||||||
|
<pattern value="com.example.springboot.HelloControllerTest" method="getHello" />
|
||||||
|
<pattern value="com.example.springboot.HelloController" />
|
||||||
|
<pattern value="com.example.springboot.HelloControllerIT" />
|
||||||
|
<pattern value="com.example.springboot.HelloControllerTest" />
|
||||||
|
<pattern value="com.example.springboot.HelloController" method="index" />
|
||||||
|
<pattern value="com.example.springboot.Application" method="main" />
|
||||||
|
<pattern value="com.example.springboot.ApplicationBuild" method="main" />
|
||||||
|
<pattern value="com.example.springboot.HelloControllerIT" method="main" />
|
||||||
|
</component>
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,33 +1,29 @@
|
||||||
package com.example.springboot;
|
package com.example.springboot;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Application {
|
public class Application {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@Bean
|
||||||
SpringApplication.run(Application.class, args);
|
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
||||||
}
|
return args -> {
|
||||||
|
System.out.println("Let's inspect the beans provided by Spring Boot:");
|
||||||
@Bean
|
|
||||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
|
||||||
return args -> {
|
|
||||||
|
|
||||||
System.out.println("Let's inspect the beans provided by Spring Boot:");
|
|
||||||
|
|
||||||
String[] beanNames = ctx.getBeanDefinitionNames();
|
|
||||||
Arrays.sort(beanNames);
|
|
||||||
for (String beanName : beanNames) {
|
|
||||||
System.out.println(beanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
String[] beanNames = ctx.getBeanDefinitionNames();
|
||||||
|
Arrays.sort(beanNames);
|
||||||
|
for (String beanName : beanNames) {
|
||||||
|
System.out.println(beanName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class HelloController {
|
public class HelloController {
|
||||||
|
@GetMapping("/")
|
||||||
@GetMapping("/")
|
public String index() {
|
||||||
public String index() {
|
return "Greetings from Spring Boot!";
|
||||||
return "Greetings from Spring Boot!";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.example.springboot;
|
package com.example.springboot;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
|
@ -11,17 +10,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class HelloControllerIT {
|
public class HelloControllerIT {
|
||||||
|
@Autowired
|
||||||
|
private TestRestTemplate template;
|
||||||
|
|
||||||
@Autowired
|
public static void main(String[] args) throws Exception {
|
||||||
private TestRestTemplate template;
|
new HelloControllerIT().getHello();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHello() throws Exception {
|
public void getHello() throws Exception {
|
||||||
ResponseEntity<String> response = template.getForEntity("/", String.class);
|
ResponseEntity<String> response = template.getForEntity("/", String.class);
|
||||||
assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!");
|
assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
new HelloControllerIT().getHello();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package com.example.springboot;
|
package com.example.springboot;
|
||||||
|
|
||||||
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.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
@ -13,17 +8,20 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class HelloControllerTest {
|
public class HelloControllerTest {
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mvc;
|
||||||
|
|
||||||
@Autowired
|
@Test
|
||||||
private MockMvc mvc;
|
public void getHello() throws Exception {
|
||||||
|
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
|
||||||
@Test
|
.andExpect(status().isOk())
|
||||||
public void getHello() throws Exception {
|
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
|
||||||
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
|
}
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue