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

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.

主站蜘蛛池模板: 南宫市| 苍南县| 兰溪市| 开阳县| 夏邑县| 松江区| 交城县| 阿勒泰市| 大关县| 亳州市| 阳曲县| 北海市| 海盐县| 邛崃市| 海门市| 赣榆县| 邵东县| 梅河口市| 修文县| 和硕县| 漳浦县| 精河县| 丰台区| 霍山县| 方城县| 新丰县| 澄城县| 佛学| 冀州市| 平泉县| 专栏| 寿阳县| 永吉县| 沽源县| 深泽县| 阿拉善左旗| 怀集县| 沙坪坝区| 蕲春县| 长乐市| 道孚县|