-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathPersonControllerTest.java
More file actions
58 lines (50 loc) · 2.13 KB
/
PersonControllerTest.java
File metadata and controls
58 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.springframework.hateoas.reactive;
import org.junit.jupiter.api.Test;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.linkTo;
import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.methodOn;
class PersonControllerTest {
@Test
public void testLink() {
Mono<Link> link = linkTo(methodOn(PersonController.class).showAll()).withRel("people").toMono();
StepVerifier.create(link)
.expectNextMatches(l -> {
assertThat(l.getRel()).isEqualTo(LinkRelation.of("people"));
assertThat(l.getHref()).endsWith("/people");
return true;
})
.verifyComplete();
}
@Test
public void testLink2() {
var person = new PersonController.Person(1L);
// /people
var baseLink = linkTo(methodOn(PersonController.class).showAll());
// / 1
var link = baseLink.slash(person.id().toString()).withSelfRel().toMono();
StepVerifier.create(link)
.expectNextMatches(l -> {
assertThat(l.getRel()).isEqualTo(IanaLinkRelations.SELF);
assertThat(l.getHref()).endsWith("/people/1");
return true;
})
.verifyComplete();
}
@Test
public void testLink3() {
var link = linkTo(methodOn(PersonController.class).show(1L))
.withSelfRel().toMono();
StepVerifier.create(link)
.expectNextMatches(l -> {
assertThat(l.getRel()).isEqualTo(IanaLinkRelations.SELF);
assertThat(l.getHref()).endsWith("/people/1");
return true;
})
.verifyComplete();
}
}