H2 DB
- used for tests - no DB implenention for prod
This commit is contained in:
parent
198b49dd8f
commit
38f86076c2
20
build.gradle
20
build.gradle
@ -8,7 +8,7 @@ group = 'djmil'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
sourceCompatibility = '20'
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -18,8 +18,26 @@ repositories {
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
implementation 'org.springframework.data:spring-data-jdbc'
|
||||
testImplementation 'com.h2database:h2'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// This section causes useful test output to go to the terminal.
|
||||
test {
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed" //, "standardOut", "standardError"
|
||||
|
||||
showExceptions true
|
||||
exceptionFormat "full"
|
||||
showCauses true
|
||||
showStackTraces true
|
||||
|
||||
// Change to `true` for more verbose test output
|
||||
showStandardStreams = false
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package djmil.cashcard;
|
||||
|
||||
public record CashCard(Long id, Double amount) {
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
public record CashCard(@Id Long id, Double amount) {
|
||||
}
|
||||
|
@ -6,17 +6,26 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cashcards")
|
||||
public class CashCardController {
|
||||
|
||||
private CashCardRepository cashCardRepository;
|
||||
|
||||
public CashCardController(CashCardRepository cashCardRepository) {
|
||||
this.cashCardRepository = cashCardRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/{requestedId}")
|
||||
public ResponseEntity<CashCard> findById(@PathVariable Long requestedId) {
|
||||
if (requestedId.equals(99L)) {
|
||||
CashCard cashCard = new CashCard(99L, 123.45);
|
||||
return ResponseEntity.ok(cashCard);
|
||||
Optional<CashCard> cashCardOptional = cashCardRepository.findById(requestedId);
|
||||
|
||||
if (cashCardOptional.isPresent()) {
|
||||
return ResponseEntity.ok(cashCardOptional.get());
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
src/main/java/djmil/cashcard/CashCardRepository.java
Normal file
6
src/main/java/djmil/cashcard/CashCardRepository.java
Normal file
@ -0,0 +1,6 @@
|
||||
package djmil.cashcard;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface CashCardRepository extends CrudRepository<CashCard, Long> {
|
||||
}
|
1
src/test/resources/data.sql
Normal file
1
src/test/resources/data.sql
Normal file
@ -0,0 +1 @@
|
||||
INSERT INTO CASH_CARD(ID, AMOUNT) VALUES (99, 123.45);
|
5
src/test/resources/schema.sql
Normal file
5
src/test/resources/schema.sql
Normal file
@ -0,0 +1,5 @@
|
||||
CREATE TABLE cash_card
|
||||
(
|
||||
ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
AMOUNT NUMBER NOT NULL DEFAULT 0
|
||||
);
|
Loading…
Reference in New Issue
Block a user