Skip to content

Commit

Permalink
Bonus also updated 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 7d9d008 commit 92859d1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions microservice-istio-bonus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.1.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -20,6 +20,11 @@
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -55,10 +60,6 @@
<artifactId>postgresql</artifactId>
<!-- scope>runtime</scope -->
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -81,7 +82,6 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.20</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ewolff.microservice.bonus.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 @@ -14,6 +14,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.thymeleaf.util.DateUtils;

import com.ewolff.microservice.bonus.Bonus;
import com.ewolff.microservice.bonus.BonusRepository;
Expand All @@ -28,7 +29,7 @@ public class BonusPoller {

private RestTemplate restTemplate = new RestTemplate();

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

private BonusService bonusService;

Expand All @@ -52,7 +53,7 @@ public void poll() {
public void pollInternal() {
HttpHeaders requestHeaders = new HttpHeaders();
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 +62,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())))) {
Bonus bonus = restTemplate
.getForEntity(entry.getLink(), Bonus.class).getBody();
log.trace("saving bonus {}", bonus.getId());
bonusService.calculateBonus(bonus);
}
}
if (response.getHeaders().getFirst("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.bonus.BonusRepository;
Expand All @@ -18,8 +18,8 @@ public BonusController(BonusRepository bonusRepository) {
this.bonusRepository = bonusRepository;
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ewolff.microservice.bonus.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.bonus.poller.BonusPoller;

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

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

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

@Autowired
private BonusRepository bonusRepository;
Expand All @@ -23,7 +23,7 @@ public class BonusServiceTest {
private BonusService bonusService;

@Test
public void ensureIdempotencySecondCallIgnored() {
void ensureIdempotencySecondCallIgnored() {
long countBefore = bonusRepository.count();
Bonus bonus = new Bonus(42L,
new Customer(23L, "Eberhard", "Wolff"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

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

@LocalServerPort
private int serverPort;

private RestTemplate restTemplate = new RestTemplate();

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

assertThat(body, containsString("<div"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public V4Pact createFragment(PactDslWithProvider builder) {
}

@Test
public void orderArePolled() {
void orderArePolled() {
long countBeforePoll = bonusRepository.count();
bonusPoller.pollInternal();
assertThat(bonusRepository.count(), is(greaterThan(countBeforePoll)));
Expand Down

0 comments on commit 92859d1

Please sign in to comment.