Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Update to spring 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hassler authored and nenaraab committed Apr 2, 2020
1 parent 459ddae commit b6cc7b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<http.proxyPort></http.proxyPort>
<logback.version>1.1.7</logback.version>
<sap.logging.version>2.1.1</sap.logging.version>
<spring.version>4.3.3.RELEASE</spring.version>
<spring.version>5.2.4.RELEASE</spring.version>
<httpclient.version>4.5.2</httpclient.version>
</properties>

Expand Down Expand Up @@ -71,14 +71,14 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
<version>2.10.2</version>
</dependency>

<!-- Actuator for adding management endpoints -->
<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.2.5.RELEASE</version>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>

<!-- Bean validation (@NotNull etc.) -->
Expand All @@ -98,18 +98,18 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
<version>1.2.1.RELEASE</version>
<version>2.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
<version>1.2.1.RELEASE</version>
<version>2.0.7.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
<version>2.2.4.RELEASE</version>
<exclusions>
<exclusion>
<!-- We need spring-core 4.2 or later, but spring-data includes 4.1.9 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<AdvertisementListDto> advertisements() {
@GetMapping("/pages/{pageId}") // not "public"
public ResponseEntity<AdvertisementListDto> advertisementsForPage(@PathVariable("pageId") int pageId) {

Page<Advertisement> page = adRepository.findAll(new PageRequest(pageId, DEFAULT_PAGE_SIZE));
Page<Advertisement> page = adRepository.findAll(PageRequest.of(pageId, DEFAULT_PAGE_SIZE));

return new ResponseEntity<AdvertisementListDto>(new AdvertisementListDto(page.getContent()),
buildLinkHeader(page, PATH_PAGES), HttpStatus.OK);
Expand All @@ -93,7 +93,7 @@ public AdvertisementDto advertisementById(@PathVariable("id") @Min(0) Long id) {
logger.info("demonstration of custom fields, part of message: {}",
CustomField.customField("example-key", "example-value"));
throwIfNonexisting(id);
AdvertisementDto ad = new AdvertisementDto(adRepository.findOne(id));
AdvertisementDto ad = new AdvertisementDto(adRepository.findById(id).get());
logger.info("returning: {}", ad);
return ad;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public void deleteAll() {
@ResponseStatus(NO_CONTENT)
public void deleteById(@PathVariable("id") Long id) {
throwIfNonexisting(id);
adRepository.delete(id);
adRepository.deleteById(id);
}

@PutMapping("/{id}")
Expand All @@ -140,7 +140,7 @@ public AdvertisementDto update(@PathVariable("id") long id, @RequestBody Adverti
throwIfNonexisting(id);
adRepository.save(updatedAd.toEntity());
logger.trace(TECHNICAL, "updated ad with version {}", updatedAd.metadata.version);
return new AdvertisementDto(adRepository.findOne(id)); // Note that EntityManager.merge might not update all
return new AdvertisementDto(adRepository.findById(id).get()); // Note that EntityManager.merge might not update all
// fields such as createdAt
}

Expand Down Expand Up @@ -170,7 +170,7 @@ private static void throwIfIdNotNull(final Long id) {
}

private void throwIfNonexisting(long id) {
if (!adRepository.exists(id)) {
if (!adRepository.existsById(id)) {
NotFoundException notFoundException = new NotFoundException(id + " not found");
logger.warn("request failed", notFoundException);
throw notFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.sap.bulletinboard.ads.config.EmbeddedDatabaseConfig;
import com.sap.bulletinboard.ads.controllers.AdvertisementDto;

import java.util.Optional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = EmbeddedDatabaseConfig.class)
public class AdvertisementRepositoryTest {
Expand Down Expand Up @@ -56,8 +58,9 @@ public void shouldSetCreatedTimestampOnFirstSaveOnly() throws InterruptedExcepti
entityUpdated.setCreatedAt(Advertisement.now());
repo.save(entityUpdated);

Advertisement entityAfterUpdate = repo.findOne(entity.getId());
assertThat(entityAfterUpdate.getCreatedAt(), is(timestampAfterCreation));
Optional<Advertisement> entityAfterUpdate = repo.findById(entity.getId());
assertThat(entityAfterUpdate.isPresent(), is(true));
assertThat(entityAfterUpdate.get().getCreatedAt(), is(timestampAfterCreation));
}

@Test
Expand Down

0 comments on commit b6cc7b0

Please sign in to comment.