Archived
Initial Gradle commit with test properties, development properties, logging properties, lombok properties, and travis properties, and example Spring Boot classes and integration and unit tests
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package hello;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(final ApplicationContext ctx) {
|
||||
return args -> {
|
||||
|
||||
LOG.info("Beans provided by Spring Boot:");
|
||||
|
||||
final String[] beanNames = ctx.getBeanDefinitionNames();
|
||||
Arrays.sort(beanNames);
|
||||
for (final String beanName : beanNames) {
|
||||
LOG.info(beanName);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hello;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HelloController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "Greetings from Spring Boot!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: atusa
|
||||
Date: 2/1/19
|
||||
Time: 8:03 PM
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>$Title$</title>
|
||||
</head>
|
||||
<body>
|
||||
$END$
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class HelloControllerTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals(3, 3);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package integrationTest;
|
||||
|
||||
import hello.Application;
|
||||
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.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
|
||||
public class HelloControllerIntegrationTest {
|
||||
@LocalServerPort private int port;
|
||||
private URL base;
|
||||
@Autowired private TestRestTemplate testRestTemplate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.base = new URL("http://localhost:" + port + "/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() {
|
||||
final ResponseEntity<String> response = testRestTemplate.getForEntity(base.toString(),
|
||||
String.class);
|
||||
assertEquals("Greetings from Spring Boot!", response.getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
test.base.url=http://localhost:
|
||||
Reference in New Issue
Block a user