Skip to content

Commit

Permalink
Upgrade to Spring Boot 3.4.0 (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
arey authored Dec 28, 2024
1 parent 1b45065 commit cf41db1
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 48 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-rest</artifactId>
<version>3.2.1</version>
<version>3.4.0</version>

<description>REST version of the Spring Petclinic sample application</description>
<url>https://spring-petclinic.github.io/</url>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from Maven repository -->
</parent>

<properties>
<!-- Third-party libraries -->
<spring-data-jdbc.version>1.2.1.RELEASE</spring-data-jdbc.version>
<springdoc-openapi-ui.version>2.6.0</springdoc-openapi-ui.version>
<springdoc-openapi-ui.version>2.7.0</springdoc-openapi-ui.version>
<jackson-databind-nullable.version>0.2.6</jackson-databind-nullable.version>
<mapstruct.version>1.6.3</mapstruct.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Pet extends NamedEntity {
@Column(name = "birth_date", columnDefinition = "DATE")
private LocalDate birthDate;

@ManyToOne
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "type_id")
private PetType type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public ResponseEntity<PetDto> addPetToOwner(Integer ownerId, PetFieldsDto petFie
Owner owner = new Owner();
owner.setId(ownerId);
pet.setOwner(owner);
pet.getType().setName(null);
this.clinicService.savePet(pet);
PetDto petDto = petMapper.toPetDto(pet);
headers.setLocation(UriComponentsBuilder.newInstance().path("/api/pets/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public VetRestController(ClinicService clinicService, VetMapper vetMapper, Speci
@PreAuthorize("hasRole(@roles.VET_ADMIN)")
@Override
public ResponseEntity<List<VetDto>> listVets() {
List<VetDto> vets = new ArrayList<>();
vets.addAll(vetMapper.toVetDtos(this.clinicService.findAllVets()));
List<VetDto> vets = new ArrayList<>(vetMapper.toVetDtos(this.clinicService.findAllVets()));
if (vets.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public Pet findPetById(int id) throws DataAccessException {
@Override
@Transactional
public void savePet(Pet pet) throws DataAccessException {
pet.setType(findPetTypeById(pet.getType().getId()));
petRepository.save(pet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.samples.petclinic.mapper.OwnerMapper;
import org.springframework.samples.petclinic.mapper.PetMapper;
Expand All @@ -38,6 +37,7 @@
import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
Expand Down Expand Up @@ -75,7 +75,7 @@ class OwnerRestControllerTests {
@Autowired
private VisitMapper visitMapper;

@MockBean
@MockitoBean
private ClinicService clinicService;

private MockMvc mockMvc;
Expand Down Expand Up @@ -189,7 +189,7 @@ void testGetOwnersListSuccess() throws Exception {
void testGetOwnersListNotFound() throws Exception {
owners.clear();
given(this.clinicService.findOwnerByLastName("0")).willReturn(ownerMapper.toOwners(owners));
this.mockMvc.perform(get("/api/owners/?lastName=0")
this.mockMvc.perform(get("/api/owners?lastName=0")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand All @@ -200,7 +200,7 @@ void testGetAllOwnersSuccess() throws Exception {
owners.remove(0);
owners.remove(1);
given(this.clinicService.findAllOwners()).willReturn(ownerMapper.toOwners(owners));
this.mockMvc.perform(get("/api/owners/")
this.mockMvc.perform(get("/api/owners")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
Expand All @@ -215,7 +215,7 @@ void testGetAllOwnersSuccess() throws Exception {
void testGetAllOwnersNotFound() throws Exception {
owners.clear();
given(this.clinicService.findAllOwners()).willReturn(ownerMapper.toOwners(owners));
this.mockMvc.perform(get("/api/owners/")
this.mockMvc.perform(get("/api/owners")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand All @@ -229,7 +229,7 @@ void testCreateOwnerSuccess() throws Exception {
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
this.mockMvc.perform(post("/api/owners/")
this.mockMvc.perform(post("/api/owners")
.content(newOwnerAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated());
}
Expand All @@ -244,7 +244,7 @@ void testCreateOwnerError() throws Exception {
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto);
this.mockMvc.perform(post("/api/owners/")
this.mockMvc.perform(post("/api/owners")
.content(newOwnerAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());
}
Expand Down Expand Up @@ -359,7 +359,7 @@ void testCreatePetSuccess() throws Exception {
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String newPetAsJSON = mapper.writeValueAsString(newPet);
System.err.println("--> newPetAsJSON=" + newPetAsJSON);
this.mockMvc.perform(post("/api/owners/1/pets/")
this.mockMvc.perform(post("/api/owners/1/pets")
.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated());
}
Expand All @@ -375,7 +375,7 @@ void testCreatePetError() throws Exception {
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
String newPetAsJSON = mapper.writeValueAsString(newPet);
this.mockMvc.perform(post("/api/owners/1/pets/")
this.mockMvc.perform(post("/api/owners/1/pets")
.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest()).andDo(MockMvcResultHandlers.print());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.samples.petclinic.mapper.PetMapper;
Expand All @@ -36,6 +35,7 @@
import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand Down Expand Up @@ -63,7 +63,7 @@
@WebAppConfiguration
class PetRestControllerTests {

@MockBean
@MockitoBean
protected ClinicService clinicService;
@Autowired
private PetRestController petRestController;
Expand Down Expand Up @@ -132,7 +132,7 @@ void testGetAllPetsSuccess() throws Exception {
System.err.println(pets);
when(this.clinicService.findAllPets()).thenReturn(pets);
//given(this.clinicService.findAllPets()).willReturn(petMapper.toPets(pets));
this.mockMvc.perform(get("/api/pets/")
this.mockMvc.perform(get("/api/pets")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
Expand All @@ -147,7 +147,7 @@ void testGetAllPetsSuccess() throws Exception {
void testGetAllPetsNotFound() throws Exception {
pets.clear();
given(this.clinicService.findAllPets()).willReturn(petMapper.toPets(pets));
this.mockMvc.perform(get("/api/pets/")
this.mockMvc.perform(get("/api/pets")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.samples.petclinic.mapper.PetTypeMapper;
import org.springframework.samples.petclinic.model.PetType;
Expand All @@ -30,6 +29,7 @@
import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand Down Expand Up @@ -58,7 +58,7 @@ class PetTypeRestControllerTests {
@Autowired
private PetTypeMapper petTypeMapper;

@MockBean
@MockitoBean
private ClinicService clinicService;

private MockMvc mockMvc;
Expand Down Expand Up @@ -132,7 +132,7 @@ void testGetAllPetTypesSuccessAsOwnerAdmin() throws Exception {
petTypes.remove(0);
petTypes.remove(1);
given(this.clinicService.findAllPetTypes()).willReturn(petTypes);
this.mockMvc.perform(get("/api/pettypes/")
this.mockMvc.perform(get("/api/pettypes")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
Expand All @@ -148,7 +148,7 @@ void testGetAllPetTypesSuccessAsVetAdmin() throws Exception {
petTypes.remove(0);
petTypes.remove(1);
given(this.clinicService.findAllPetTypes()).willReturn(petTypes);
this.mockMvc.perform(get("/api/pettypes/")
this.mockMvc.perform(get("/api/pettypes")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
Expand All @@ -163,7 +163,7 @@ void testGetAllPetTypesSuccessAsVetAdmin() throws Exception {
void testGetAllPetTypesNotFound() throws Exception {
petTypes.clear();
given(this.clinicService.findAllPetTypes()).willReturn(petTypes);
this.mockMvc.perform(get("/api/pettypes/")
this.mockMvc.perform(get("/api/pettypes")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand All @@ -175,7 +175,7 @@ void testCreatePetTypeSuccess() throws Exception {
newPetType.setId(null);
ObjectMapper mapper = new ObjectMapper();
String newPetTypeAsJSON = mapper.writeValueAsString(petTypeMapper.toPetTypeFieldsDto(newPetType));
this.mockMvc.perform(post("/api/pettypes/")
this.mockMvc.perform(post("/api/pettypes")
.content(newPetTypeAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated());
}
Expand All @@ -188,7 +188,7 @@ void testCreatePetTypeError() throws Exception {
newPetType.setName(null);
ObjectMapper mapper = new ObjectMapper();
String newPetTypeAsJSON = mapper.writeValueAsString(petTypeMapper.toPetTypeDto(newPetType));
this.mockMvc.perform(post("/api/pettypes/")
this.mockMvc.perform(post("/api/pettypes")
.content(newPetTypeAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.samples.petclinic.mapper.SpecialtyMapper;
import org.springframework.samples.petclinic.model.Specialty;
import org.springframework.samples.petclinic.rest.advice.ExceptionControllerAdvice;
import org.springframework.samples.petclinic.rest.controller.SpecialtyRestController;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand Down Expand Up @@ -58,7 +57,7 @@ class SpecialtyRestControllerTests {
@Autowired
private SpecialtyMapper specialtyMapper;

@MockBean
@MockitoBean
private ClinicService clinicService;

private MockMvc mockMvc;
Expand Down Expand Up @@ -115,7 +114,7 @@ void testGetSpecialtyNotFound() throws Exception {
void testGetAllSpecialtysSuccess() throws Exception {
specialties.remove(0);
given(this.clinicService.findAllSpecialties()).willReturn(specialties);
this.mockMvc.perform(get("/api/specialties/")
this.mockMvc.perform(get("/api/specialties")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
Expand All @@ -130,7 +129,7 @@ void testGetAllSpecialtysSuccess() throws Exception {
void testGetAllSpecialtysNotFound() throws Exception {
specialties.clear();
given(this.clinicService.findAllSpecialties()).willReturn(specialties);
this.mockMvc.perform(get("/api/specialties/")
this.mockMvc.perform(get("/api/specialties")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand All @@ -142,7 +141,7 @@ void testCreateSpecialtySuccess() throws Exception {
newSpecialty.setId(999);
ObjectMapper mapper = new ObjectMapper();
String newSpecialtyAsJSON = mapper.writeValueAsString(specialtyMapper.toSpecialtyDto(newSpecialty));
this.mockMvc.perform(post("/api/specialties/")
this.mockMvc.perform(post("/api/specialties")
.content(newSpecialtyAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated());
}
Expand All @@ -155,7 +154,7 @@ void testCreateSpecialtyError() throws Exception {
newSpecialty.setName(null);
ObjectMapper mapper = new ObjectMapper();
String newSpecialtyAsJSON = mapper.writeValueAsString(specialtyMapper.toSpecialtyDto(newSpecialty));
this.mockMvc.perform(post("/api/specialties/")
this.mockMvc.perform(post("/api/specialties")
.content(newSpecialtyAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void testCreateUserSuccess() throws Exception {
user.addRole("OWNER_ADMIN");
ObjectMapper mapper = new ObjectMapper();
String newVetAsJSON = mapper.writeValueAsString(userMapper.toUserDto(user));
this.mockMvc.perform(post("/api/users/")
this.mockMvc.perform(post("/api/users")
.content(newVetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated());
}
Expand All @@ -68,7 +68,7 @@ void testCreateUserError() throws Exception {
user.setEnabled(true);
ObjectMapper mapper = new ObjectMapper();
String newVetAsJSON = mapper.writeValueAsString(userMapper.toUserDto(user));
this.mockMvc.perform(post("/api/users/")
this.mockMvc.perform(post("/api/users")
.content(newVetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());
}
Expand Down
Loading

0 comments on commit cf41db1

Please sign in to comment.