Skip to content

Commit

Permalink
Update to Spring Boot 3.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ewolff committed Oct 23, 2023
1 parent b48b7d8 commit 7d9d008
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 107 deletions.
9 changes: 5 additions & 4 deletions microservice-istio-demo/microservice-istio-invoicing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ewolff.microservice.invoicing.poller;

import java.time.ZonedDateTime;
import java.util.Date;

import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -27,7 +27,7 @@ public class InvoicePoller {

private RestTemplate restTemplate = new RestTemplate();

private Date lastModified = null;
private ZonedDateTime lastModified = null;

private boolean pollingActivated;

Expand All @@ -52,7 +52,7 @@ public void pollInternal() {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set(HttpHeaders.ACCEPT, "*/*");
if (lastModified != null) {
requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified));
requestHeaders.setZonedDateTime(HttpHeaders.IF_MODIFIED_SINCE, lastModified);
}
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
ResponseEntity<OrderFeed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, OrderFeed.class);
Expand All @@ -61,15 +61,15 @@ public void pollInternal() {
log.trace("data has been modified");
OrderFeed feed = response.getBody();
for (OrderFeedEntry entry : feed.getOrders()) {
if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
if ((lastModified == null) || (entry.getUpdated().after(Date.from(lastModified.toInstant())))) {
Invoice invoice = restTemplate
.getForEntity(entry.getLink(), Invoice.class).getBody();
log.trace("saving invoice {}", invoice.getId());
invoiceService.generateInvoice(invoice);
}
}
if (response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED) != null) {
lastModified = DateUtils.parseDate(response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED));
lastModified = response.getHeaders().getFirstZonedDateTime(HttpHeaders.LAST_MODIFIED);
log.trace("Last-Modified header {}", lastModified);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ewolff.microservice.invoicing.InvoiceRepository;
Expand All @@ -18,8 +18,8 @@ public InvoiceController(InvoiceRepository invoiceRepository) {
this.invoiceRepository = invoiceRepository;
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView invoice(@PathVariable("id") long id) {
@GetMapping(value = "/{id}", produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView invoice(@PathVariable long id) {
return new ModelAndView("invoice", "invoice", invoiceRepository.findById(id).get());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ewolff.microservice.invoicing.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.PostMapping;

import com.ewolff.microservice.invoicing.poller.InvoicePoller;

Expand All @@ -15,7 +14,7 @@ public PollController(InvoicePoller poller) {
this.poller = poller;
}

@RequestMapping(value = "/poll", method = RequestMethod.POST)
@PostMapping("/poll")
public String poll() {
poller.poll();
return "success";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

@SpringBootTest(classes = InvoiceTestApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class InvoiceWebIntegrationTest {
class InvoiceWebIntegrationTest {

@LocalServerPort
private int serverPort;

private RestTemplate restTemplate = new RestTemplate();

@Test
public void isHTMLReturned() {
void isHTMLReturned() {
String body = getForMediaType(String.class, MediaType.TEXT_HTML, shippingURL());

assertThat(body, containsString("<div"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@SpringBootTest(classes = InvoiceTestApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class InvoicingServiceTest {
class InvoicingServiceTest {

@Autowired
private InvoiceRepository invoiceRepository;
Expand All @@ -24,7 +24,7 @@ public class InvoicingServiceTest {
private InvoiceService invoiceService;

@Test
public void ensureIdempotencySecondCallIgnored() {
void ensureIdempotencySecondCallIgnored() {
long countBefore = invoiceRepository.count();
Invoice invoice = new Invoice(42,
new Customer(23, "Eberhard", "Wolff", "eberhard.wolff@innoq.com"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public V4Pact createFragment(PactDslWithProvider builder) {
}

@Test
public void orderArePolled() {
void orderArePolled() {
long countBeforePoll = invoiceRepository.count();
invoicePoller.pollInternal();
assertThat(invoiceRepository.count(), is(greaterThan(countBeforePoll)));
Expand Down
10 changes: 5 additions & 5 deletions microservice-istio-demo/microservice-istio-order/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -63,10 +68,5 @@
<version>4.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ewolff.microservice.order.customer.CustomerRepository;
Expand Down Expand Up @@ -38,15 +40,15 @@ public ModelAndView orderList() {
return new ModelAndView("orderlist", "orders", orderRepository.findAll());
}

@RequestMapping(value = "/form.html", method = RequestMethod.GET)
@GetMapping("/form.html")
public ModelAndView form() {
ModelAndView modelAndView = new ModelAndView("orderForm", "order", new Order());
modelAndView.addObject("items", itemRepository.findAll(Sort.unsorted()));
modelAndView.addObject("customers", customerRepository.findAll(Sort.unsorted()));
return modelAndView;
}

@RequestMapping(value = "/line", method = RequestMethod.POST)
@PostMapping("/line")
public ModelAndView addLine(Order order) {
order.addLine(0, itemRepository.findAll(Sort.unsorted()).iterator().next());
ModelAndView modelAndView = new ModelAndView("orderForm", "order", order);
Expand All @@ -55,13 +57,13 @@ public ModelAndView addLine(Order order) {
return modelAndView;
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView get(@PathVariable("id") long id) {
@GetMapping("/{id}")
public ModelAndView get(@PathVariable long id) {
return new ModelAndView("order", "order", orderRepository.findById(id).get());
}

@RequestMapping(value = "/order/{id}", method = RequestMethod.GET)
public ResponseEntity<Order> getJSON(@PathVariable("id") long id) {
@GetMapping("/order/{id}")
public ResponseEntity<Order> getJSON(@PathVariable long id) {
Optional<Order> response = orderRepository.findById(id);
if (response.isEmpty()) {
return new ResponseEntity<Order>(HttpStatus.NOT_FOUND);
Expand All @@ -70,19 +72,19 @@ public ResponseEntity<Order> getJSON(@PathVariable("id") long id) {
}
}

@RequestMapping(value = "/full-{id}", method = RequestMethod.GET)
public ModelAndView full(@PathVariable("id") long id) {
@GetMapping("/full-{id}")
public ModelAndView full(@PathVariable long id) {
return new ModelAndView("order-full", "order", orderRepository.findById(id).get());
}

@RequestMapping(value = "/", method = RequestMethod.POST)
@PostMapping("/")
public ModelAndView post(Order order) {
order = orderService.order(order);
return new ModelAndView("success");
}

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable("id") long id) {
@DeleteMapping("/{id}")
public ModelAndView delete(@PathVariable long id) {
orderRepository.deleteById(id);

return new ModelAndView("success");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public OrderRestController(OrderRepository orderRepository) {
}

private String baseUrl(HttpServletRequest request) {
return String.format("%s://%s:%d%s/", request.getScheme(), request.getServerName(), request.getServerPort(),
request.getContextPath());
return "%s://%s:%d%s/".formatted(request.getScheme(), request.getServerName(), request.getServerPort(),
request.getContextPath());
}

@RequestMapping(value = "/feed", produces = "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import org.springframework.test.context.ActiveProfiles;

import com.ewolff.microservice.order.customer.CustomerRepository;
import com.ewolff.microservice.order.customer.CustomerTestDataGenerator;

@SpringBootTest(classes = OrderApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class CustomerTestDataGeneratorTest {
import com.ewolff.microservice.order.customer.CustomerTestDataGenerator;

@SpringBootTest(classes = OrderApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
class CustomerTestDataGeneratorTest {

@Autowired
private CustomerRepository customerRepository;

@Autowired
private CustomerTestDataGenerator customerTestDataGenerator;

@Test
public void assureTestDataGeneratedOnce() {
private CustomerTestDataGenerator customerTestDataGenerator;

@Test
void assureTestDataGeneratedOnce() {
assertEquals(1, customerRepository.findByName("Wolff").size());
customerTestDataGenerator.generateTestData();
assertEquals(1, customerRepository.findByName("Wolff").size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Date;
import java.time.ZonedDateTime;

import org.apache.http.client.utils.DateUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -27,7 +26,7 @@

@SpringBootTest(classes = OrderApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class FeedClientTest {
class FeedClientTest {

@LocalServerPort
private long serverPort;
Expand All @@ -41,20 +40,20 @@ public class FeedClientTest {
private RestTemplate restTemplate = new RestTemplate();

@Test
public void feedReturnsBasicInformation() {
void feedReturnsBasicInformation() {
OrderFeed feed = retrieveFeed();
assertNotNull(feed.getUpdated());
}

@Test
public void requestWithLastModifiedReturns304() {
void requestWithLastModifiedReturns304() {
ResponseEntity<OrderFeed> response = restTemplate.exchange(feedUrl(), HttpMethod.GET, new HttpEntity(null),
OrderFeed.class);

Date lastModified = DateUtils.parseDate(response.getHeaders().getFirst("Last-Modified"));
ZonedDateTime lastModified = response.getHeaders().getFirstZonedDateTime("Last-Modified");

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified));
requestHeaders.setZonedDateTime("If-Modified-Since", lastModified);
HttpEntity requestEntity = new HttpEntity(requestHeaders);

response = restTemplate.exchange(feedUrl(), HttpMethod.GET, requestEntity, OrderFeed.class);
Expand All @@ -63,7 +62,7 @@ public void requestWithLastModifiedReturns304() {
}

@Test
public void feedReturnsNewlyCreatedOrder() {
void feedReturnsNewlyCreatedOrder() {
Order order = new Order();
order.setCustomer(customerRepository.findAll(Sort.unsorted()).iterator().next());
orderRepository.save(order);
Expand All @@ -82,7 +81,7 @@ private OrderFeed retrieveFeed() {
}

private String feedUrl() {
return String.format("http://localhost:%d/feed", serverPort);
return "http://localhost:%d/feed".formatted(serverPort);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import org.springframework.test.context.ActiveProfiles;

import com.ewolff.microservice.order.item.ItemRepository;
import com.ewolff.microservice.order.item.ItemTestDataGenerator;

@SpringBootTest(classes = OrderApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class ItemTestDataGeneratorTest {
import com.ewolff.microservice.order.item.ItemTestDataGenerator;

@SpringBootTest(classes = OrderApp.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
class ItemTestDataGeneratorTest {

@Autowired
private ItemRepository itemRepository;

@Autowired
private ItemTestDataGenerator itemTestDataGenerator;

@Test
public void assureTestDataGeneratedOnce() {
private ItemTestDataGenerator itemTestDataGenerator;

@Test
void assureTestDataGeneratedOnce() {
assertEquals(1, itemRepository.findByName("iPod").size());
itemTestDataGenerator.generateTestData();
assertEquals(1, itemRepository.findByName("iPod").size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ewolff.microservice.order;

import javax.annotation.PostConstruct;

import jakarta.annotation.PostConstruct;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Sort;
Expand Down
Loading

0 comments on commit 7d9d008

Please sign in to comment.