Initial commit

This commit is contained in:
rviewer-team
2022-06-16 10:17:10 +02:00
commit 6bd3921714
32 changed files with 1214 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -0,0 +1,6 @@
package com.rviewer.skeletons.domain.services.persistence;
public interface DatabaseConnector {
public int getConnectionStatus();
}

View File

@@ -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());
}
}

View File

@@ -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);
}
}

View 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

View File

@@ -0,0 +1,8 @@
,------. ,--.
| .--. ' ,--. ,--. `--' ,---. ,--. ,--. ,---. ,--.--.
| '--'.' \ `' / ,--. | .-. : | |.'.| | | .-. : | .--'
| |\ \ \ / | | \ --. | .'. | \ --. | |
`--' '--' `--' `--' `----' '--' '--' `----' `--'
${application.title} - v${application.version}
Powered by Rviewer

View File

@@ -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")));
}
}

View File

@@ -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());
}
}

View 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

View File

@@ -0,0 +1,8 @@
,------. ,--.
| .--. ' ,--. ,--. `--' ,---. ,--. ,--. ,---. ,--.--.
| '--'.' \ `' / ,--. | .-. : | |.'.| | | .-. : | .--'
| |\ \ \ / | | \ --. | .'. | \ --. | |
`--' '--' `--' `--' `----' '--' '--' `----' `--'
${application.title} - v${application.version}
Powered by Rviewer