Merge pull request #14305 from Eredisse/master

BAEL-6024 - Guide to YugabyteDB
This commit is contained in:
Vini 2023-07-07 15:14:50 +02:00 committed by GitHub
commit 2546a2e218
5 changed files with 132 additions and 89 deletions

View File

@ -20,10 +20,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>

View File

@ -18,27 +18,24 @@ public class User {
@Column
private String name;
Long getId() {
public Long getId() {
return id;
}
void setId(Long id) {
public void setId(Long id) {
this.id = id;
}
String getName() {
public String getName() {
return name;
}
void setName(String name) {
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
'}';
return "User{" + "id=" + id + ", name='" + name + '\'' + '}';
}
}

View File

@ -0,0 +1,13 @@
version: '3'
services:
yugabytedb:
image: yugabytedb/yugabyte:latest
container_name: yugabyte
user: root
ports:
- '5433:5433'
- '7000:7000'
- '9000:9000'
command: ["bin/yugabyted", "start", "--daemon=false"]

View File

@ -0,0 +1,37 @@
package com.baeldung;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:application.properties")
public class YugabyteDBLiveTest {
@Autowired
private UserRepository userRepository;
@Test
void givenTwoUsers_whenPersistUsingJPARepository_thenUserAreSaved() {
User user1 = new User();
user1.setName("Alex");
User user2 = new User();
user2.setName("John");
userRepository.save(user1);
userRepository.save(user2);
List<User> allUsers = userRepository.findAll();
assertEquals(2, allUsers.size());
}
}