Skip to content

Commit

Permalink
Some unit tests pass now
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoozhoo committed Sep 25, 2024
1 parent ec1097b commit d172feb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package ca.zhoozhoo.springcloud.rooms.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;

import io.r2dbc.spi.ConnectionFactory;

@Configuration
@EnableR2dbcRepositories(basePackages = "ca.zhoozhoo.springcloud.rooms")
public class R2dbcConfig {

// @Bean(value = "r2dbcEntityTemplate")
// public R2dbcEntityTemplate getR2dbcEntityTemplate(ConnectionFactory connectionFactory) {
// return new R2dbcEntityTemplate(connectionFactory);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import reactor.util.annotation.NonNull;

@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Room {

@Id
@Column("ROOM_ID")
private long id;
private Long id;

@NonNull
private String name;

@NonNull
private String roomNumber;

@NonNull
private String bedInfo;
}
28 changes: 0 additions & 28 deletions spring-cloud-room-service/src/main/resources/data.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ca.zhoozhoo.springcloud.rooms.repository;

import java.util.Arrays;
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 ca.zhoozhoo.springcloud.rooms.model.Room;
import reactor.test.StepVerifier;

@SpringBootTest
public class RoomRepositoryTest {

@Autowired
private RoomRepository roomRepository;

@Test
public void testFindAll() {
insertRooms();

roomRepository.findAll()
.as(StepVerifier::create)
.expectNextCount(4)
.verifyComplete();
}

@Test
public void testDeleteAll() {
insertRooms();

roomRepository.deleteAll()
.as(StepVerifier::create)
.expectNextCount(0)
.verifyComplete();
}

public void insertRooms() {
List<Room> rooms = Arrays.asList(new Room(null, "Room 1", "101", "King Bed"),
new Room(null, "Room 2", "102", "Queen Bed"),
new Room(null, "Room 3", "103", "Single Bed"),
new Room(null, "Room 4", "104", "Single Bed"));

roomRepository.saveAll(rooms).subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ spring:
config:
enabled: false
r2dbc:
url: "r2dbc:h2:mem:///testdb"
sql:
init:
schema-locations:
- classpath*:schema.sql
data-locations:
- classpath*:data.sql
url: "r2dbc:h2:mem:///test;DB_CLOSE_DELAY=-1"
name: "sa"
security:
oauth2:
resourceserver:
Expand Down

0 comments on commit d172feb

Please sign in to comment.