Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.rviewer.skeletons;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RviewerSkeletonApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RviewerSkeletonApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.rviewer.skeletons.domain.responses;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class PongResponse {
|
||||
|
||||
private String message;
|
||||
private int number;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.rviewer.skeletons.domain.services;
|
||||
|
||||
import com.rviewer.skeletons.domain.responses.PongResponse;
|
||||
import com.rviewer.skeletons.domain.services.persistence.DatabaseConnector;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PongService {
|
||||
|
||||
@Autowired
|
||||
DatabaseConnector postgresConnector;
|
||||
|
||||
public PongResponse getPong() {
|
||||
return new PongResponse("pong", postgresConnector.getConnectionStatus());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.rviewer.skeletons.domain.services.persistence;
|
||||
|
||||
public interface DatabaseConnector {
|
||||
|
||||
public int getConnectionStatus();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.rviewer.skeletons.infrastructure.controllers;
|
||||
|
||||
import com.rviewer.skeletons.domain.services.PongService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
public class PingController {
|
||||
|
||||
@Autowired
|
||||
private PongService pongService;
|
||||
|
||||
@GetMapping("/ping")
|
||||
public ResponseEntity getPing() {
|
||||
return ResponseEntity.ok(pongService.getPong());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.rviewer.skeletons.infrastructure.persistence;
|
||||
|
||||
import com.rviewer.skeletons.domain.services.persistence.DatabaseConnector;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PostgresConnector implements DatabaseConnector {
|
||||
|
||||
@Autowired
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public int getConnectionStatus() {
|
||||
return jdbcTemplate.queryForObject("SELECT 1+1", Integer.class);
|
||||
}
|
||||
|
||||
}
|
||||
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
server.port=8080
|
||||
application.title=Java skeleton
|
||||
application.version=1.0.0
|
||||
|
||||
spring.datasource.initialization-mode=always
|
||||
spring.datasource.username = rv_user
|
||||
spring.datasource.password = rv_password
|
||||
spring.datasource.driverClassName = org.postgresql.Driver
|
||||
spring.datasource.url = jdbc:postgresql://postgres-skeleton-db:5432/postgres_rv_database
|
||||
8
src/main/resources/banner.txt
Normal file
8
src/main/resources/banner.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
,------. ,--.
|
||||
| .--. ' ,--. ,--. `--' ,---. ,--. ,--. ,---. ,--.--.
|
||||
| '--'.' \ `' / ,--. | .-. : | |.'.| | | .-. : | .--'
|
||||
| |\ \ \ / | | \ --. | .'. | \ --. | |
|
||||
`--' '--' `--' `--' `----' '--' '--' `----' `--'
|
||||
|
||||
${application.title} - v${application.version}
|
||||
Powered by Rviewer
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.rviewer.skeletons.infrastructure.controllers;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class PingControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
public void getPing_success() throws Exception {
|
||||
mockMvc
|
||||
.perform(get("/ping"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPing_returnsPong() throws Exception {
|
||||
mockMvc
|
||||
.perform(get("/ping"))
|
||||
.andExpect(content().string(containsString("pong")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.rviewer.skeletons.infrastructure.persistence;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SpringBootTest
|
||||
public class PostgresConnectorTest {
|
||||
|
||||
@Mock
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@Autowired
|
||||
private PostgresConnector postgresConnector;
|
||||
|
||||
@Test
|
||||
public void getConnectionStatus_shouldReturn2() {
|
||||
when(jdbcTemplate.queryForObject("SELECT 1+1", Integer.class)).thenReturn(2);
|
||||
assertEquals(2, postgresConnector.getConnectionStatus());
|
||||
}
|
||||
}
|
||||
9
src/test/resources/application.properties
Normal file
9
src/test/resources/application.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
server.port=8080
|
||||
application.title=Java skeleton
|
||||
application.version=1.0.0
|
||||
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.datasource.url=jdbc:h2:mem:testdb
|
||||
spring.datasource.username=user
|
||||
spring.datasource.password=password
|
||||
8
src/test/resources/banner.txt
Normal file
8
src/test/resources/banner.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
,------. ,--.
|
||||
| .--. ' ,--. ,--. `--' ,---. ,--. ,--. ,---. ,--.--.
|
||||
| '--'.' \ `' / ,--. | .-. : | |.'.| | | .-. : | .--'
|
||||
| |\ \ \ / | | \ --. | .'. | \ --. | |
|
||||
`--' '--' `--' `--' `----' '--' '--' `----' `--'
|
||||
|
||||
${application.title} - v${application.version}
|
||||
Powered by Rviewer
|
||||
Reference in New Issue
Block a user