Skip to content

Commit 26cbe29

Browse files
committed
Changes for proofreading.
1 parent 5ee5e7c commit 26cbe29

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

6-reactive/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<properties>
2121
<java.version>1.8</java.version>
2222
<auto-service.version>1.0-rc5</auto-service.version>
23-
<spring-hateoas.version>1.1.0.BUILD-SNAPSHOT</spring-hateoas.version>
2423
</properties>
2524

2625
<dependencies>

9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Mono<Rendering> home(Authentication auth) { // <1>
4444
return Mono.just(Rendering.view("home.html") //
4545
.modelAttribute("items", this.inventoryService.getInventory()) //
4646
.modelAttribute("cart", this.inventoryService.getCart(cartName(auth)) // <2>
47-
.defaultIfEmpty(new Cart(cartName(auth)))) // <3>
48-
.modelAttribute("auth", auth) // <4>
47+
.defaultIfEmpty(new Cart(cartName(auth)))) //
48+
.modelAttribute("auth", auth) // <3>
4949
.build());
5050
}
5151
// end::user-cart[]

9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/ApiItemController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Mono<CollectionModel<EntityModel<Item>>> findAll(Authentication auth) {
105105
.flatMap(links -> this.repository.findAll() //
106106
.flatMap(item -> findOne(item.getId(), auth)) //
107107
.collectList() //
108-
.map(entityModels -> new CollectionModel<>(entityModels, links)));
108+
.map(entityModels -> CollectionModel.of(entityModels, links)));
109109
}
110110
// end::find-all[]
111111

@@ -117,14 +117,15 @@ Mono<EntityModel<Item>> findOne(@PathVariable String id, Authentication auth) {
117117
Mono<Link> selfLink = linkTo(controller.findOne(id, auth)).withSelfRel() //
118118
.toMono();
119119

120-
Mono<Link> aggregateLink = linkTo(controller.findAll(auth)).withRel(IanaLinkRelations.ITEM) //
121-
.toMono();
120+
Mono<Link> aggregateLink = linkTo(controller.findAll(auth)) //
121+
.withRel(IanaLinkRelations.ITEM).toMono();
122122

123123
Mono<Links> allLinks; // <1>
124124

125125
if (auth.getAuthorities().contains(ROLE_INVENTORY)) { // <2>
126-
allLinks = Mono.zip(selfLink, aggregateLink, //
127-
linkTo(controller.deleteItem(id)).withRel("delete").toMono()) //
126+
Mono<Link> deleteLink = linkTo(controller.deleteItem(id)).withRel("delete") //
127+
.toMono();
128+
allLinks = Mono.zip(selfLink, aggregateLink, deleteLink) //
128129
.map(links -> Links.of(links.getT1(), links.getT2(), links.getT3()));
129130
} else { // <3>
130131
allLinks = Mono.zip(selfLink, aggregateLink) //
@@ -133,7 +134,7 @@ Mono<EntityModel<Item>> findOne(@PathVariable String id, Authentication auth) {
133134

134135
return allLinks // <4>
135136
.flatMap(links -> this.repository.findById(id) //
136-
.map(item -> new EntityModel<>(item, links)));
137+
.map(item -> EntityModel.of(item, links)));
137138
}
138139

139140
// end::find-one[]

9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Mono<Rendering> home(Authentication auth) { // <1>
4040
return Mono.just(Rendering.view("home.html") //
4141
.modelAttribute("items", this.inventoryService.getInventory()) //
4242
.modelAttribute("cart", this.inventoryService.getCart(cartName(auth)) // <2>
43-
.defaultIfEmpty(new Cart(cartName(auth)))) // <3>
44-
.modelAttribute("auth", auth) // <4>
43+
.defaultIfEmpty(new Cart(cartName(auth)))) //
44+
.modelAttribute("auth", auth) // <3>
4545
.build());
4646
}
4747
// end::user-cart[]

9-reactive-method-security/src/test/java/com/greglturnquist/hackingspringboot/reactive/ApiItemControllerTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
package com.greglturnquist.hackingspringboot.reactive;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType.*;
1920

21+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
22+
import org.springframework.hateoas.config.EnableHypermediaSupport;
23+
import org.springframework.hateoas.config.HypermediaWebTestClientConfigurer;
2024
import reactor.test.StepVerifier;
2125

2226
import org.junit.jupiter.api.BeforeEach;
@@ -38,23 +42,21 @@
3842
/**
3943
* @author Greg Turnquist
4044
*/
41-
@SpringBootTest
45+
// tag::register[]
46+
@SpringBootTest()
47+
@EnableHypermediaSupport(type = HAL) // <1>
4248
@AutoConfigureWebTestClient
4349
public class ApiItemControllerTest {
4450

45-
@Autowired WebTestClient webTestClient;
51+
@Autowired WebTestClient webTestClient; // <2>
4652

4753
@Autowired ItemRepository repository;
4854

49-
@Autowired WebClientConfigurer webClientConfigurer;
55+
@Autowired HypermediaWebTestClientConfigurer webClientConfigurer; // <3>
5056

51-
// tag::register[]
52-
@BeforeEach // <1>
57+
@BeforeEach
5358
void setUp() {
54-
this.webTestClient = this.webTestClient //
55-
.mutate() //
56-
.exchangeStrategies(this.webClientConfigurer.hypermediaExchangeStrategies()) // <2>
57-
.build();
59+
this.webTestClient = this.webTestClient.mutateWith(webClientConfigurer); // <4>
5860
}
5961
// end::register[]
6062

@@ -178,7 +180,7 @@ void navigateToItemWithoutInventoryAuthority() {
178180
@Test
179181
@WithMockUser(username = "alice", roles = { "INVENTORY" })
180182
void navigateToItemWithInventoryAuthority() {
181-
183+
182184
// Navigate to the root URI of the API.
183185
RepresentationModel<?> root = this.webTestClient.get().uri("/api") //
184186
.exchange() //

9-reactive-oauth/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ spring:
44
client:
55
registration:
66
google:
7-
client-id: 76769467445-cg244gaa3heg88hphvlsfbkehj96opeh.apps.googleusercontent.com
7+
client-id: 1234redacted5678opeh.apps.googleusercontent.com
88
client-secret: ovj6b_va5fEB-EWEcE3FGOK6

9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/User.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
// tag::code[]
2727
public class User {
2828

29-
private @Id String id;
29+
private @Id String id; // <1>
3030
private String name;
3131
private String password;
3232
private List<String> roles;
3333

34-
private User() {} // <1>
34+
private User() {} // <2>
3535

36-
public User(String id, String name, String password, List<String> roles) { // <2>
36+
public User(String id, String name, String password, List<String> roles) { // <3>
3737
this.id = id;
3838
this.name = name;
3939
this.password = password;
4040
this.roles = roles;
4141
}
4242

43-
public User(String name, String password, List<String> roles) { // <3>
43+
public User(String name, String password, List<String> roles) { // <4>
4444
this.name = name;
4545
this.password = password;
4646
this.roles = roles;

9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/UserRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
public interface UserRepository extends CrudRepository<User, String> {
2626

2727
Mono<User> findByName(String name);
28+
2829
}
2930
// end::code[]

0 commit comments

Comments
 (0)