Skip to content

Commit e6c06ff

Browse files
committed
Make tweaks to the code base.
1 parent ca70d0e commit e6c06ff

File tree

9 files changed

+79
-89
lines changed

9 files changed

+79
-89
lines changed

1-reactive/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@
5757
<artifactId>reactor-test</artifactId>
5858
<scope>test</scope>
5959
</dependency>
60-
<dependency>
61-
<groupId>junit</groupId>
62-
<artifactId>junit</artifactId>
63-
<version>4.12</version>
64-
<scope>test</scope>
65-
</dependency>
66-
</dependencies>
60+
</dependencies>
6761
<!-- end::dep[] -->
6862

6963
<!-- Spring Boot Maven Plugin -->

2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package com.greglturnquist.hackingspringboot.reactive;
1818

19+
import reactor.core.publisher.Mono;
1920
import org.springframework.stereotype.Controller;
2021
import org.springframework.web.bind.annotation.GetMapping;
2122
import org.springframework.web.bind.annotation.ModelAttribute;
2223
import org.springframework.web.bind.annotation.PathVariable;
2324
import org.springframework.web.bind.annotation.PostMapping;
2425
import org.springframework.web.bind.annotation.RequestParam;
2526
import org.springframework.web.reactive.result.view.Rendering;
26-
import reactor.core.publisher.Mono;
2727

2828
/**
2929
* @author Greg Turnquist

3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,45 @@
3131
@Controller
3232
public class HomeController {
3333

34-
private InventoryService inventoryService;
34+
private InventoryService inventoryService;
3535

36-
public HomeController(InventoryService inventoryService) {
37-
this.inventoryService = inventoryService;
38-
}
39-
// end::1[]
36+
public HomeController(InventoryService inventoryService) {
37+
this.inventoryService = inventoryService;
38+
}
39+
// end::1[]
4040

41-
// tag::2[]
42-
@GetMapping
43-
Mono<Rendering> home() { // <1>
44-
return Mono.just(Rendering.view("home.html") // <2>
45-
.modelAttribute("items", this.inventoryService.getInventory()) // <3>
46-
.modelAttribute("cart", this.inventoryService.getCart("My Cart") // <4>
47-
.defaultIfEmpty(new Cart("My Cart")))
48-
.build());
49-
}
50-
// end::2[]
41+
@GetMapping
42+
Mono<Rendering> home() {
43+
// tag::2[]
44+
return Mono.just(Rendering.view("home.html") //
45+
.modelAttribute("items", this.inventoryService.getInventory()) //
46+
.modelAttribute("cart", this.inventoryService.getCart("My Cart") //
47+
.defaultIfEmpty(new Cart("My Cart")))
48+
.build());
49+
// end::2[]
50+
}
5151

52-
@GetMapping("/add/{id}")
53-
Mono<String> addToCart(@PathVariable String id) {
54-
return this.inventoryService.addItemToCart("My Cart", id)
55-
.then(Mono.just("redirect:/"));
56-
}
52+
@GetMapping("/add/{id}")
53+
Mono<String> addToCart(@PathVariable String id) {
54+
return this.inventoryService.addItemToCart("My Cart", id)
55+
.then(Mono.just("redirect:/"));
56+
}
5757

58-
@GetMapping("/remove/{id}")
59-
Mono<String> removeFromCart(@PathVariable String id) {
60-
return this.inventoryService.removeOneFromCart("My Cart", id)
61-
.then(Mono.just("redirect:/"));
62-
}
58+
@GetMapping("/remove/{id}")
59+
Mono<String> removeFromCart(@PathVariable String id) {
60+
return this.inventoryService.removeOneFromCart("My Cart", id)
61+
.then(Mono.just("redirect:/"));
62+
}
6363

64-
@PostMapping
65-
Mono<String> createItem(@ModelAttribute Item newItem) {
66-
return this.inventoryService.saveItem(newItem) //
67-
.then(Mono.just("redirect:/"));
68-
}
64+
@PostMapping
65+
Mono<String> createItem(@ModelAttribute Item newItem) {
66+
return this.inventoryService.saveItem(newItem) //
67+
.then(Mono.just("redirect:/"));
68+
}
6969

70-
@GetMapping("/delete/{id}")
71-
Mono<String> deleteItem(@PathVariable String id) {
72-
return this.inventoryService.deleteItem(id) //
73-
.then(Mono.just("redirect:/"));
74-
}
70+
@GetMapping("/delete/{id}")
71+
Mono<String> deleteItem(@PathVariable String id) {
72+
return this.inventoryService.deleteItem(id) //
73+
.then(Mono.just("redirect:/"));
74+
}
7575
}

6-reactive/pom.xml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,31 @@
125125
<!-- end::restdocs-build[] -->
126126

127127
<!-- tag::restdocs-package[] -->
128-
<!--<plugin>-->
129-
<!--<artifactId>maven-resources-plugin</artifactId>-->
130-
<!--<version>2.7</version>-->
131-
<!--<executions>-->
132-
<!--<execution>-->
133-
<!--<id>copy-resources</id>-->
134-
<!--<phase>prepare-package</phase>-->
135-
<!--<goals>-->
136-
<!--<goal>copy-resources</goal>-->
137-
<!--</goals>-->
138-
<!--<configuration>-->
139-
<!--<outputDirectory>-->
140-
<!--${project.build.outputDirectory}/static/docs-->
141-
<!--</outputDirectory>-->
142-
<!--<resources>-->
143-
<!--<resource>-->
144-
<!--<directory>-->
145-
<!--${project.build.directory}/generated-docs-->
146-
<!--</directory>-->
147-
<!--</resource>-->
148-
<!--</resources>-->
149-
<!--</configuration>-->
150-
<!--</execution>-->
151-
<!--</executions>-->
152-
<!--</plugin>-->
128+
<plugin>
129+
<artifactId>maven-resources-plugin</artifactId>
130+
<version>2.7</version>
131+
<executions>
132+
<execution>
133+
<id>copy-resources</id>
134+
<phase>prepare-package</phase>
135+
<goals>
136+
<goal>copy-resources</goal>
137+
</goals>
138+
<configuration>
139+
<outputDirectory>
140+
${project.build.outputDirectory}/static/docs
141+
</outputDirectory>
142+
<resources>
143+
<resource>
144+
<directory>
145+
${project.build.directory}/generated-docs
146+
</directory>
147+
</resource>
148+
</resources>
149+
</configuration>
150+
</execution>
151+
</executions>
152+
</plugin>
153153
<!-- end::restdocs-package[] -->
154154

155155
</plugins>

6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/AffordancesItemController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.hateoas.IanaLinkRelations;
3030
import org.springframework.hateoas.Link;
3131
import org.springframework.hateoas.Links;
32+
import org.springframework.hateoas.MediaTypes;
3233
import org.springframework.hateoas.RepresentationModel;
3334
import org.springframework.hateoas.mediatype.alps.Alps;
3435
import org.springframework.hateoas.mediatype.alps.Type;
@@ -136,7 +137,7 @@ public Mono<ResponseEntity<?>> updateItem(@RequestBody Mono<EntityModel<Item>> i
136137
// end::update-item[]
137138

138139
// tag::profile[]
139-
@GetMapping(value = "/affordances/items/profile"/*, produces = MediaTypes.ALPS_JSON_VALUE*/)
140+
@GetMapping(value = "/affordances/items/profile"/, produces = MediaTypes.ALPS_JSON_VALUE)
140141
public Alps profile() {
141142
return alps() //
142143
.descriptor(Collections.singletonList(descriptor() //

6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HypermediaItemController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.hateoas.IanaLinkRelations;
3030
import org.springframework.hateoas.Link;
3131
import org.springframework.hateoas.Links;
32+
import org.springframework.hateoas.MediaTypes;
3233
import org.springframework.hateoas.RepresentationModel;
3334
import org.springframework.hateoas.mediatype.alps.Alps;
3435
import org.springframework.hateoas.mediatype.alps.Type;
@@ -65,7 +66,8 @@ Mono<RepresentationModel<?>> root() {
6566
Mono<Link> itemsAggregateLink = linkTo(controller.findAll()).withRel(IanaLinkRelations.ITEM) //
6667
.toMono();
6768

68-
return selfLink.zipWith(itemsAggregateLink).map(links -> Links.of(links.getT1(), links.getT2()))
69+
return selfLink.zipWith(itemsAggregateLink) //
70+
.map(links -> Links.of(links.getT1(), links.getT2())) //
6971
.map(links -> new RepresentationModel<>(links.toList()));
7072
}
7173
// end::root[]
@@ -103,7 +105,8 @@ Mono<EntityModel<Item>> findOne(@PathVariable String id) {
103105
// end::find-one[]
104106

105107
// tag::find-affordance[]
106-
@GetMapping("/hypermedia/items/{id}/affordances") // <1>
108+
@GetMapping("/hypermedia/items/{id}/affordances")
109+
// <1>
107110
Mono<EntityModel<Item>> findOneWithAffordances(@PathVariable String id) {
108111
HypermediaItemController controller = methodOn(HypermediaItemController.class);
109112

@@ -151,7 +154,7 @@ public Mono<ResponseEntity<?>> updateItem(@RequestBody Mono<EntityModel<Item>> i
151154
// end::update-item[]
152155

153156
// tag::profile[]
154-
@GetMapping(value = "/hypermedia/items/profile"/*, produces = MediaTypes.ALPS_JSON_VALUE*/)
157+
@GetMapping(value = "/hypermedia/items/profile", produces = MediaTypes.ALPS_JSON_VALUE)
155158
public Alps profile() {
156159
return alps() //
157160
.descriptor(Collections.singletonList(descriptor() //

6-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/ApiItemControllerDocumentationTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
2727
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
2828
import org.springframework.boot.test.mock.mockito.MockBean;
29-
import org.springframework.hateoas.MediaTypes;
3029
import org.springframework.test.web.reactive.server.WebTestClient;
3130

32-
import com.greglturnquist.hackingspringboot.reactive.ApiItemController;
33-
import com.greglturnquist.hackingspringboot.reactive.InventoryService;
34-
import com.greglturnquist.hackingspringboot.reactive.Item;
35-
import com.greglturnquist.hackingspringboot.reactive.ItemRepository;
36-
3731
/**
3832
* @author Greg Turnquist
3933
*/
@@ -69,12 +63,10 @@ void postNewItem() {
6963
when(repository.save(any())) //
7064
.thenReturn(Mono.just(new Item("1", "Alf alarm clock", "nothing important", 19.99)));
7165

72-
// TODO: Remove `content-type` pending https://github.com/spring-projects/spring-hateoas/issues/1047
7366
this.webTestClient.post().uri("/api/items") // <1>
74-
.contentType(MediaTypes.HAL_JSON) // <2>
75-
.bodyValue(new Item("Alf alarm clock", "nothing important", 19.99)) // <3>
67+
.bodyValue(new Item("Alf alarm clock", "nothing important", 19.99)) // <2>
7668
.exchange() //
77-
.expectStatus().isCreated() // <4>
69+
.expectStatus().isCreated() // <3>
7870
.expectBody() //
7971
.consumeWith(document("post-new-item", preprocessResponse(prettyPrint()))); //
8072
}

6-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/HypermediaItemControllerDocumentationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
2121
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*;
2222

23-
import org.junit.jupiter.api.Test;
2423
import reactor.core.publisher.Flux;
2524
import reactor.core.publisher.Mono;
25+
26+
import org.junit.jupiter.api.Test;
2627
import org.springframework.beans.factory.annotation.Autowired;
2728
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
2829
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
@@ -74,7 +75,7 @@ void postNewItem() {
7475
// tag::test3[]
7576
@Test
7677
void findOneItem() {
77-
when(repository.findById("item-1")) // <1>
78+
when(repository.findById("item-1")) //
7879
.thenReturn(Mono.just(new Item("item-1", "Alf alarm clock", "nothing I really need", 19.99)));
7980

8081
this.webTestClient.get().uri("/hypermedia/items/item-1") //
@@ -84,14 +85,13 @@ void findOneItem() {
8485
.consumeWith(document("findOne-hypermedia", //
8586
preprocessResponse(prettyPrint()), //
8687
links(linkWithRel("self").description("Canonical link to this `Item`"),
87-
linkWithRel("item").description("Link back to the aggregate root")))); // <2>
88+
linkWithRel("item").description("Link back to the aggregate root")))); //
8889
}
8990
// end::test3[]
9091

9192
@Test
9293
void findProfile() {
9394
this.webTestClient.get().uri("/hypermedia/items/profile") //
94-
// .accept(MediaTypes.ALPS_JSON) //
9595
.exchange() //
9696
.expectStatus().isOk() //
9797
.expectBody() //

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737

3838
<modules>
3939
<module>1-reactive</module>
40-
<module>1-classic</module>
40+
<!-- <module>1-classic</module>-->
4141
<module>2-reactive</module>
4242
<module>2b-reactive</module>
43-
<module>2-classic</module>
43+
<!-- <module>2-classic</module>-->
4444
<module>3-reactive</module>
45-
<module>3-classic</module>
45+
<!-- <module>3-classic</module>-->
4646
<module>4-reactive</module>
4747
<!-- <module>4-classic</module>-->
4848
<module>5-reactive</module>

0 commit comments

Comments
 (0)