Skip to content

Commit

Permalink
Upgrade spring-boot to version 3.4.0 and fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isbel8ai committed Dec 9, 2024
1 parent 7426625 commit ec32313
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand All @@ -23,6 +24,7 @@ public List<Product> getAllProducts() {
}

@Override
@Transactional
public Product createProduct(Product newProduct) {
try {
return productRepository.save(newProduct);
Expand All @@ -37,6 +39,7 @@ public Product getProduct(Long productId) {
}

@Override
@Transactional
public Product replaceProduct(Long productId, Product modifiedProduct) {
Product product = productRepository.findById(productId).orElseThrow(ElementNotFoundException::new);
product.setCode(modifiedProduct.getCode());
Expand All @@ -52,6 +55,7 @@ public Product replaceProduct(Long productId, Product modifiedProduct) {
}

@Override
@Transactional
public void deleteProduct(Long productId) {
productRepository.deleteById(productId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.i8ai.training.store.service.ShopService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand All @@ -15,13 +16,14 @@ public class ShopServiceImpl implements ShopService {
private final ShopRepository shopRepository;

@Override
public List<Shop> getAllShops() {
return shopRepository.findAll();
@Transactional
public Shop createShop(Shop newShop) {
return shopRepository.save(newShop);
}

@Override
public Shop createShop(Shop newShop) {
return shopRepository.save(newShop);
public List<Shop> getAllShops() {
return shopRepository.findAll();
}

@Override
Expand All @@ -30,6 +32,7 @@ public Shop getShop(Long shopId) {
}

@Override
@Transactional
public Shop replaceShop(Long shopId, Shop modifiedShop) {
Shop shop = shopRepository.findById(shopId).orElseThrow();
shop.setName(modifiedShop.getName());
Expand All @@ -39,6 +42,7 @@ public Shop replaceShop(Long shopId, Shop modifiedShop) {
}

@Override
@Transactional
public void deleteShop(Long shopId) {
shopRepository.deleteById(shopId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void setUp() {
@AfterEach
void tearDown() {
saleRepository.deleteAll();
offerRepository.deleteAll();
packRepository.deleteAll();
lotRepository.deleteAll();
productRepository.deleteAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ void tearDown() {

@Test
void testCreateProduct() throws Exception {
Product product = Product.builder()
.code(TestConstants.PRODUCT_A_CODE)
.name(TestConstants.PRODUCT_A_NAME)
.measureUnit(TestConstants.PRODUCT_A_MEASURE)
.build();
mockMvc.perform(post("/products")
.contentType(MediaType.APPLICATION_JSON)
.content(helper.asJsonString(TestConstants.PRODUCT_A)))
.content(helper.asJsonString(product)))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$").exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ class ShopControllerTest {

@Test
void testCreateShop() throws Exception {
Shop shop = Shop.builder()
.name(TestConstants.SHOP1_NAME)
.address(TestConstants.SHOP1_ADDRESS)
.build();
mockMvc.perform(post("/shops")
.contentType(MediaType.APPLICATION_JSON)
.content(helper.asJsonString(TestConstants.SHOP1)))
.content(helper.asJsonString(shop)))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$").exists());
Expand Down

0 comments on commit ec32313

Please sign in to comment.