官术网_书友最值得收藏!

Sample values in the repository

In order to use the repository, we will have to create a concrete class and fill in some values to test the GET operation. In the following method, we can do that:

package com.packtpub.reactive;
// import statements
public class UserRepositorySample implements UserRepository {
// initiate Users
private final Map<Integer, User> users = new HashMap<>();
// fill dummy values for testing
public UserRepositorySample() {
this.users.put(100, new User(100, "David"));
this.users.put(101, new User(101, "John"));
this.users.put(102, new User(102, "Kevin"));
}
}

In the preceding class, we just implemented UserRepository and filled in some sample values.

In order to simplify our code, we have used only application-based data storage, which means that once the application is restarted, our data will be reinitialized. In this case, we can't store any new data in our application. However, this will help us to focus on our main topics, such as Reactive and Spring 5, which are not related to persistence.

We can use this sample repository in the routing method:

public RouterFunction<ServerResponse> routingFunction() {
UserRepository repository = new UserRepositorySample();
UserHandler handler = new UserHandler(repository);
}

The preceding lines will insert dummy values in our repository. This will be enough for testing the GET operation.

主站蜘蛛池模板: 渭源县| 仁布县| 秦安县| 西宁市| 长乐市| 山阳县| 中阳县| 临邑县| 安化县| 华蓥市| 乌恰县| 阜城县| 潞城市| 襄汾县| 壶关县| 尼勒克县| 新安县| 金川县| 色达县| 东兴市| 大关县| 内黄县| 沈阳市| 汝城县| 灌云县| 伊吾县| 宣恩县| 镇平县| 武乡县| 凭祥市| 大邑县| 巨鹿县| 昌乐县| 镇坪县| 都昌县| 康乐县| 罗定市| 固安县| 青岛市| 呼图壁县| 马山县|