Compare commits
No commits in common. "ee6c6eda02e6bcb78ee1f5431414628452b0b9fd" and "ae7d965a6da8287ec263abd5f8c5b37d3f727926" have entirely different histories.
ee6c6eda02
...
ae7d965a6d
12 changed files with 0 additions and 221 deletions
21
pom.xml
21
pom.xml
|
@ -41,29 +41,8 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 3rd party -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Database -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hsqldb</groupId>
|
|
||||||
<artifactId>hsqldb</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Tests -->
|
<!-- Tests -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
|
|
@ -2,12 +2,8 @@ package eu.ztsh.wymiana;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableConfigurationProperties
|
|
||||||
@ConfigurationPropertiesScan
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.config;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import org.hsqldb.persist.HsqlProperties;
|
|
||||||
import org.hsqldb.server.Server;
|
|
||||||
import org.hsqldb.server.ServerAcl;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class DatabaseConfiguration {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create HSQL Database instance that is accessible from outside of application
|
|
||||||
*
|
|
||||||
* @return server instance
|
|
||||||
* @throws ServerAcl.AclFormatException when instantiating ServerAcl
|
|
||||||
* @throws IOException when instantiating ServerAcl
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Server hsqlServer(HsqlDbProperties properties) throws ServerAcl.AclFormatException, IOException {
|
|
||||||
var server = new Server();
|
|
||||||
var props = new HsqlProperties();
|
|
||||||
props.setProperty("server.database.0", String.format("mem:%s", properties.name()));
|
|
||||||
props.setProperty("server.dbname.0", properties.name());
|
|
||||||
props.setProperty("server.no_system_exit", true);
|
|
||||||
props.setProperty("server.port", properties.port());
|
|
||||||
server.setProperties(props);
|
|
||||||
server.start();
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* As we manually create database instance, we need also create datasource instance.
|
|
||||||
* HSQL instance is passed to force spring to create {@link Server} before pool.
|
|
||||||
*
|
|
||||||
* @param dataSourceProperties spring.datasource.* properties
|
|
||||||
* @return datasource instance
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public HikariDataSource hikariDataSource(DataSourceProperties dataSourceProperties, Server ignore) {
|
|
||||||
var config = new HikariConfig();
|
|
||||||
config.setJdbcUrl(dataSourceProperties.getUrl());
|
|
||||||
config.setUsername(dataSourceProperties.getUsername());
|
|
||||||
config.setPassword(dataSourceProperties.getPassword());
|
|
||||||
config.setDriverClassName(dataSourceProperties.getDriverClassName());
|
|
||||||
return new HikariDataSource(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
@ConfigurationProperties("hsqldb")
|
|
||||||
public record HsqlDbProperties(String name, int port) {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.entity;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "currency")
|
|
||||||
public class CurrencyEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
String pesel;
|
|
||||||
@Id
|
|
||||||
String symbol;
|
|
||||||
Double amount;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.entity;
|
|
||||||
|
|
||||||
import jakarta.persistence.CascadeType;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "user")
|
|
||||||
public class UserEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
String pesel;
|
|
||||||
String name;
|
|
||||||
String surname;
|
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pesel")
|
|
||||||
List<CurrencyEntity> currencies;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.repository;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.data.entity.UserEntity;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
public interface UserRepository extends CrudRepository<UserEntity, String> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package eu.ztsh.wymiana.model;
|
|
||||||
|
|
||||||
public record Currency(String symbol, double amount) {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package eu.ztsh.wymiana.model;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public record User(String name, String surname, String pesel, Map<String, Currency> currencies) {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
hsqldb:
|
|
||||||
name: db
|
|
||||||
port: 9090
|
|
||||||
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
username: sa
|
|
||||||
password:
|
|
||||||
url: jdbc:hsqldb:hsql://localhost:${hsqldb.port}/${hsqldb.name}
|
|
||||||
driver-class-name: org.hsqldb.jdbc.JDBCDriver
|
|
||||||
jpa:
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: create
|
|
0
src/test/java/.gitkeep
Normal file
0
src/test/java/.gitkeep
Normal file
|
@ -1,49 +0,0 @@
|
||||||
package eu.ztsh.wymiana.data.repository;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.data.entity.CurrencyEntity;
|
|
||||||
import eu.ztsh.wymiana.data.entity.UserEntity;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@ExtendWith(SpringExtension.class)
|
|
||||||
class UserRepositoryTest {
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserRepositoryTest(UserRepository userRepository) {
|
|
||||||
this.userRepository = userRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void prepareTest() {
|
|
||||||
userRepository.deleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
@DisplayName("Basic insert & get test")
|
|
||||||
void basicTest() {
|
|
||||||
var pesel = "00281018264";
|
|
||||||
var entity = new UserEntity(pesel, "Janina", "Kowalska",
|
|
||||||
List.of(new CurrencyEntity(pesel, "PLN", 20.10)));
|
|
||||||
userRepository.save(entity);
|
|
||||||
assertThat(userRepository.findById(pesel))
|
|
||||||
.isNotEmpty()
|
|
||||||
.get()
|
|
||||||
.usingRecursiveComparison()
|
|
||||||
.isEqualTo(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue