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

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.

主站蜘蛛池模板: 麻城市| 三江| 安新县| 永吉县| 措美县| 东平县| 邮箱| 措勤县| 阜南县| 镇巴县| 宁阳县| 津南区| 浦城县| 梁河县| 乌海市| 汉寿县| 法库县| 富源县| 嘉善县| 兖州市| 福海县| 原平市| 江都市| 寿宁县| 盐城市| 宁武县| 巴马| 天峻县| 专栏| 伊通| 华阴市| 洪洞县| 张掖市| 若尔盖县| 工布江达县| 中阳县| 城步| 中山市| 桐庐县| 五峰| 漯河市|