diff --git a/batch-boot-jpa-sample/pom.xml b/batch-boot-jpa-sample/pom.xml
index 74a870249..48b284b34 100644
--- a/batch-boot-jpa-sample/pom.xml
+++ b/batch-boot-jpa-sample/pom.xml
@@ -242,10 +242,9 @@
${spotless.version}
-
- 1.25.2
-
-
+
+ 2.50.0
+
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java
index 67845c9e9..3494347d9 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java
@@ -6,7 +6,8 @@
@ConfigurationProperties("application")
public class ApplicationProperties {
- @NestedConfigurationProperty private Cors cors = new Cors();
+ @NestedConfigurationProperty
+ private Cors cors = new Cors();
public Cors getCors() {
return cors;
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java
index 8d149949b..e71c28849 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java
@@ -48,18 +48,17 @@ Job allCustomersJob(
JpaPagingItemReader jpaPagingItemReader,
JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
- Step step =
- new StepBuilder("all-customers-step", jobRepository)
- .allowStartIfComplete(true)
- .chunk(10, transactionManager)
- .reader(jpaPagingItemReader)
- .processor(getCustomerCustomerDTOItemProcessor())
- .writer(getCustomerDTOItemWriter())
- .faultTolerant() // tell to spring batch that this step can face errors
- .skip(Exception.class) // skip all Exception
- .noSkip(ConstraintViolationException.class) // but do not skip this one
- .skipLimit(20) // the number of times you want to skip Exception.class
- .build();
+ Step step = new StepBuilder("all-customers-step", jobRepository)
+ .allowStartIfComplete(true)
+ .chunk(10, transactionManager)
+ .reader(jpaPagingItemReader)
+ .processor(getCustomerCustomerDTOItemProcessor())
+ .writer(getCustomerDTOItemWriter())
+ .faultTolerant() // tell to spring batch that this step can face errors
+ .skip(Exception.class) // skip all Exception
+ .noSkip(ConstraintViolationException.class) // but do not skip this one
+ .skipLimit(20) // the number of times you want to skip Exception.class
+ .build();
return new JobBuilder("all-customers-job", jobRepository)
.start(step)
@@ -76,8 +75,7 @@ private ItemWriter getCustomerDTOItemWriter() {
}
private ItemProcessor getCustomerCustomerDTOItemProcessor() {
- return customer ->
- new CustomerDTO(customer.getName(), customer.getAddress(), customer.getGender());
+ return customer -> new CustomerDTO(customer.getName(), customer.getAddress(), customer.getGender());
}
@Bean
@@ -91,8 +89,7 @@ JpaPagingItemReader jpaPagingItemReader(
return new JpaPagingItemReaderBuilder()
.name("jpaPagingItemReader")
.entityManagerFactory(entityManagerFactory)
- .queryString(
- "SELECT c FROM Customer c WHERE c.id BETWEEN :minId AND :maxId ORDER BY c.id")
+ .queryString("SELECT c FROM Customer c WHERE c.id BETWEEN :minId AND :maxId ORDER BY c.id")
.parameterValues(parameterValuesMap)
.pageSize(10)
.build();
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/GlobalExceptionHandler.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/GlobalExceptionHandler.java
index 9e1b3758e..c1ad17874 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/GlobalExceptionHandler.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/GlobalExceptionHandler.java
@@ -22,23 +22,19 @@ class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
ProblemDetail onException(MethodArgumentNotValidException methodArgumentNotValidException) {
ProblemDetail problemDetail =
- ProblemDetail.forStatusAndDetail(
- HttpStatusCode.valueOf(400), "Invalid request content.");
+ ProblemDetail.forStatusAndDetail(HttpStatusCode.valueOf(400), "Invalid request content.");
problemDetail.setTitle("Constraint Violation");
- List validationErrorsList =
- methodArgumentNotValidException.getAllErrors().stream()
- .map(
- objectError -> {
- FieldError fieldError = (FieldError) objectError;
- return new ApiValidationError(
- fieldError.getObjectName(),
- fieldError.getField(),
- fieldError.getRejectedValue(),
- Objects.requireNonNull(
- fieldError.getDefaultMessage(), ""));
- })
- .sorted(Comparator.comparing(ApiValidationError::field))
- .toList();
+ List validationErrorsList = methodArgumentNotValidException.getAllErrors().stream()
+ .map(objectError -> {
+ FieldError fieldError = (FieldError) objectError;
+ return new ApiValidationError(
+ fieldError.getObjectName(),
+ fieldError.getField(),
+ fieldError.getRejectedValue(),
+ Objects.requireNonNull(fieldError.getDefaultMessage(), ""));
+ })
+ .sorted(Comparator.comparing(ApiValidationError::field))
+ .toList();
problemDetail.setProperty("violations", validationErrorsList);
return problemDetail;
}
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java
index c7a9ec70d..f17f68cdc 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java
@@ -24,13 +24,11 @@ class Initializer implements CommandLineRunner {
@Override
public void run(String... args) {
log.info("Running Initializer.....");
- List customerList =
- Instancio.ofList(Customer.class)
- .size(1000)
- .ignore(field(Customer.class, "id"))
- .generate(
- field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
- .create();
+ List customerList = Instancio.ofList(Customer.class)
+ .size(1000)
+ .ignore(field(Customer.class, "id"))
+ .generate(field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
+ .create();
log.info("Saving Customers of size :{}", customerList.size());
customerList = customerRepository.saveAll(customerList);
log.info("Inserted customers of size :{}", customerList.size());
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/SwaggerConfig.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/SwaggerConfig.java
index 83908c1ba..eb10e5524 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/SwaggerConfig.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/SwaggerConfig.java
@@ -6,7 +6,5 @@
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
-@OpenAPIDefinition(
- info = @Info(title = "batch-boot-jpa", version = "v1"),
- servers = @Server(url = "/"))
+@OpenAPIDefinition(info = @Info(title = "batch-boot-jpa", version = "v1"), servers = @Server(url = "/"))
class SwaggerConfig {}
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java
index 3e8f32750..7d20d5af3 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java
@@ -19,8 +19,7 @@ public class Customer {
private Long id;
@Column(nullable = false)
- @NotEmpty(message = "Name cannot be empty")
- private String name;
+ @NotEmpty(message = "Name cannot be empty") private String name;
private String address;
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java
index bae14cf18..6bbda32c7 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java
@@ -23,12 +23,10 @@ public CustomerService(CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
}
- public PagedResult findAllCustomers(
- int pageNo, int pageSize, String sortBy, String sortDir) {
- Sort sort =
- sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
- ? Sort.by(sortBy).ascending()
- : Sort.by(sortBy).descending();
+ public PagedResult findAllCustomers(int pageNo, int pageSize, String sortBy, String sortDir) {
+ Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
+ ? Sort.by(sortBy).ascending()
+ : Sort.by(sortBy).descending();
// create Pageable instance
Pageable pageable = PageRequest.of(pageNo, pageSize, sort);
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java
index 69b28b12d..8e018110f 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java
@@ -11,7 +11,6 @@ public final class AppConstants {
public static final String DEFAULT_SORT_DIRECTION = "asc";
private AppConstants() {
- throw new UnsupportedOperationException(
- "This is a utility class and cannot be instantiated");
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/CustomerController.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/CustomerController.java
index 9bed924d3..41d9dc916 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/CustomerController.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/CustomerController.java
@@ -30,23 +30,17 @@ class CustomerController {
@GetMapping
PagedResult getAllCustomers(
- @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false)
- int pageNo,
- @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false)
- int pageSize,
- @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false)
- String sortBy,
- @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_DIRECTION, required = false)
- String sortDir) {
+ @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) int pageNo,
+ @RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) int pageSize,
+ @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) String sortBy,
+ @RequestParam(defaultValue = AppConstants.DEFAULT_SORT_DIRECTION, required = false) String sortDir) {
return customerService.findAllCustomers(pageNo, pageSize, sortBy, sortDir);
}
@GetMapping("/{id}")
ResponseEntity getCustomerById(@PathVariable Long id) {
- return customerService
- .findCustomerById(id)
- .map(ResponseEntity::ok)
- .orElseGet(() -> ResponseEntity.notFound().build());
+ return customerService.findCustomerById(id).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound()
+ .build());
}
@PostMapping
@@ -59,11 +53,10 @@ Customer createCustomer(@RequestBody @Validated Customer customer) {
ResponseEntity updateCustomer(@PathVariable Long id, @RequestBody Customer customer) {
return customerService
.findCustomerById(id)
- .map(
- customerObj -> {
- customer.setId(id);
- return ResponseEntity.ok(customerService.saveCustomer(customer));
- })
+ .map(customerObj -> {
+ customer.setId(id);
+ return ResponseEntity.ok(customerService.saveCustomer(customer));
+ })
.orElseGet(() -> ResponseEntity.notFound().build());
}
@@ -71,11 +64,10 @@ ResponseEntity updateCustomer(@PathVariable Long id, @RequestBody Cust
ResponseEntity deleteCustomer(@PathVariable Long id) {
return customerService
.findCustomerById(id)
- .map(
- customer -> {
- customerService.deleteCustomerById(id);
- return ResponseEntity.ok(customer);
- })
+ .map(customer -> {
+ customerService.deleteCustomerById(id);
+ return ResponseEntity.ok(customer);
+ })
.orElseGet(() -> ResponseEntity.notFound().build());
}
}
diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/JobInvokerController.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/JobInvokerController.java
index 86caa0840..da61fc003 100644
--- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/JobInvokerController.java
+++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/web/controllers/JobInvokerController.java
@@ -27,14 +27,12 @@ class JobInvokerController {
}
@GetMapping("/customers")
- String allCustomersJobHandle(@RequestParam Long minId, @RequestParam Long maxId)
- throws Exception {
-
- JobParameters jobParameters =
- new JobParametersBuilder()
- .addLong("minId", minId)
- .addLong("maxId", maxId)
- .toJobParameters();
+ String allCustomersJobHandle(@RequestParam Long minId, @RequestParam Long maxId) throws Exception {
+
+ JobParameters jobParameters = new JobParametersBuilder()
+ .addLong("minId", minId)
+ .addLong("maxId", maxId)
+ .toJobParameters();
JobExecution jobExecution = this.jobLauncher.run(this.allCustomersJob, jobParameters);
return "Batch job has been invoked as " + jobExecution.getJobId();
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/TestBatchApplication.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/TestBatchApplication.java
index 25f98a5d2..aa97ef3fa 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/TestBatchApplication.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/TestBatchApplication.java
@@ -6,6 +6,8 @@
public class TestBatchApplication {
public static void main(String[] args) {
- SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
+ SpringApplication.from(BatchApplication::main)
+ .with(ContainersConfig.class)
+ .run(args);
}
}
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/batch/SpringBatchIntegrationTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/batch/SpringBatchIntegrationTest.java
index cb34358dc..c3632ff79 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/batch/SpringBatchIntegrationTest.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/batch/SpringBatchIntegrationTest.java
@@ -21,11 +21,14 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
class SpringBatchIntegrationTest extends AbstractIntegrationTest {
- @Autowired private JobLauncherTestUtils jobLauncherTestUtils;
+ @Autowired
+ private JobLauncherTestUtils jobLauncherTestUtils;
- @Autowired private JobRepositoryTestUtils jobRepositoryTestUtils;
+ @Autowired
+ private JobRepositoryTestUtils jobRepositoryTestUtils;
- @Autowired private Job jobUnderTest;
+ @Autowired
+ private Job jobUnderTest;
@BeforeEach
void setup() {
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java
index 474a6c5d2..431e154fd 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java
@@ -18,9 +18,12 @@
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {
- @Autowired protected MockMvc mockMvc;
+ @Autowired
+ protected MockMvc mockMvc;
- @Autowired protected MockMvcTester mockMvcTester;
+ @Autowired
+ protected MockMvcTester mockMvcTester;
- @Autowired protected ObjectMapper objectMapper;
+ @Autowired
+ protected ObjectMapper objectMapper;
}
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/repository/SchemaValidationTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/repository/SchemaValidationTest.java
index 6edc759ad..2c2ac22a4 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/repository/SchemaValidationTest.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/repository/SchemaValidationTest.java
@@ -16,7 +16,8 @@
@AutoConfigureTestDatabase
class SchemaValidationTest {
- @Autowired private DataSource dataSource;
+ @Autowired
+ private DataSource dataSource;
@Test
void contextLoads() {
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/services/CustomerServiceTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/services/CustomerServiceTest.java
index fcc57fdbf..66803933e 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/services/CustomerServiceTest.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/services/CustomerServiceTest.java
@@ -25,9 +25,11 @@
@ExtendWith(MockitoExtension.class)
class CustomerServiceTest {
- @Mock private CustomerRepository customerRepository;
+ @Mock
+ private CustomerRepository customerRepository;
- @InjectMocks private CustomerService customerService;
+ @InjectMocks
+ private CustomerService customerService;
@Test
void findAllCustomers() {
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java
index fd0b6c982..32bc7293f 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java
@@ -24,7 +24,8 @@
class CustomerControllerIT extends AbstractIntegrationTest {
- @Autowired private CustomerRepository customerRepository;
+ @Autowired
+ private CustomerRepository customerRepository;
private List customerList = null;
@@ -32,13 +33,11 @@ class CustomerControllerIT extends AbstractIntegrationTest {
void setUp() {
customerRepository.deleteAllInBatch();
- customerList =
- Instancio.ofList(Customer.class)
- .size(3)
- .ignore(field(Customer.class, "id"))
- .generate(
- field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
- .create();
+ customerList = Instancio.ofList(Customer.class)
+ .size(3)
+ .ignore(field(Customer.class, "id"))
+ .generate(field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
+ .create();
customerList = customerRepository.saveAll(customerList);
}
@@ -75,10 +74,9 @@ void shouldCreateNewCustomer() throws Exception {
Customer customer = Instancio.create(Customer.class);
customer.setId(null);
this.mockMvc
- .perform(
- post("/api/customers")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(post("/api/customers")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id", notNullValue()))
.andExpect(jsonPath("$.name", is(customer.getName())));
@@ -89,10 +87,9 @@ void shouldReturn400WhenCreateNewCustomerWithoutName() throws Exception {
Customer customer = new Customer(null, null, null, null);
this.mockMvc
- .perform(
- post("/api/customers")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(post("/api/customers")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isBadRequest())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(jsonPath("$.type", is("about:blank")))
@@ -112,10 +109,9 @@ void shouldUpdateCustomer() throws Exception {
customer.setName("Updated Customer");
this.mockMvc
- .perform(
- put("/api/customers/{id}", customer.getId())
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(put("/api/customers/{id}", customer.getId())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(customer.getId()), Long.class))
.andExpect(jsonPath("$.name", is("Updated Customer")));
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerTest.java
index 4b4120632..c63a33629 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerTest.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerTest.java
@@ -37,11 +37,14 @@
@ActiveProfiles(PROFILE_TEST)
class CustomerControllerTest {
- @Autowired private MockMvc mockMvc;
+ @Autowired
+ private MockMvc mockMvc;
- @MockitoBean private CustomerService customerService;
+ @MockitoBean
+ private CustomerService customerService;
- @Autowired private ObjectMapper objectMapper;
+ @Autowired
+ private ObjectMapper objectMapper;
private List customerList;
@@ -87,22 +90,18 @@ void shouldReturn404WhenFetchingNonExistingCustomer() throws Exception {
Long customerId = 1L;
given(customerService.findCustomerById(customerId)).willReturn(Optional.empty());
- this.mockMvc
- .perform(get("/api/customers/{id}", customerId))
- .andExpect(status().isNotFound());
+ this.mockMvc.perform(get("/api/customers/{id}", customerId)).andExpect(status().isNotFound());
}
@Test
void shouldCreateNewCustomer() throws Exception {
- given(customerService.saveCustomer(any(Customer.class)))
- .willAnswer((invocation) -> invocation.getArgument(0));
+ given(customerService.saveCustomer(any(Customer.class))).willAnswer((invocation) -> invocation.getArgument(0));
Customer customer = Instancio.create(Customer.class);
this.mockMvc
- .perform(
- post("/api/customers")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(post("/api/customers")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id", notNullValue()))
.andExpect(jsonPath("$.name", is(customer.getName())));
@@ -113,10 +112,9 @@ void shouldReturn400WhenCreateNewCustomerWithoutText() throws Exception {
Customer customer = new Customer(null, null, null, null);
this.mockMvc
- .perform(
- post("/api/customers")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(post("/api/customers")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isBadRequest())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(jsonPath("$.type", is("about:blank")))
@@ -137,14 +135,12 @@ void shouldUpdateCustomer() throws Exception {
customer.setId(customerId);
customer.setName("Updated Name");
given(customerService.findCustomerById(customerId)).willReturn(Optional.of(customer));
- given(customerService.saveCustomer(any(Customer.class)))
- .willAnswer((invocation) -> invocation.getArgument(0));
+ given(customerService.saveCustomer(any(Customer.class))).willAnswer((invocation) -> invocation.getArgument(0));
this.mockMvc
- .perform(
- put("/api/customers/{id}", customer.getId())
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(put("/api/customers/{id}", customer.getId())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name", is("Updated Name")));
}
@@ -156,10 +152,9 @@ void shouldReturn404WhenUpdatingNonExistingCustomer() throws Exception {
Customer customer = Instancio.create(Customer.class);
this.mockMvc
- .perform(
- put("/api/customers/{id}", customerId)
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(customer)))
+ .perform(put("/api/customers/{id}", customerId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(customer)))
.andExpect(status().isNotFound());
}
@@ -182,8 +177,6 @@ void shouldReturn404WhenDeletingNonExistingCustomer() throws Exception {
Long customerId = 1L;
given(customerService.findCustomerById(customerId)).willReturn(Optional.empty());
- this.mockMvc
- .perform(delete("/api/customers/{id}", customerId))
- .andExpect(status().isNotFound());
+ this.mockMvc.perform(delete("/api/customers/{id}", customerId)).andExpect(status().isNotFound());
}
}
diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java
index 4c9242e9f..c125b7a63 100644
--- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java
+++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java
@@ -21,10 +21,6 @@ void shouldInvokeAllCustomersJob() {
@Test
void shouldReturnBadRequestForMissingParameters() {
- mockMvcTester
- .get()
- .uri("/api/job/customers")
- .assertThat()
- .hasStatus(HttpStatus.BAD_REQUEST);
+ mockMvcTester.get().uri("/api/job/customers").assertThat().hasStatus(HttpStatus.BAD_REQUEST);
}
}
diff --git a/httpClients/boot-restclient/pom.xml b/httpClients/boot-restclient/pom.xml
index c7b9e2798..8cf48d47f 100644
--- a/httpClients/boot-restclient/pom.xml
+++ b/httpClients/boot-restclient/pom.xml
@@ -71,13 +71,12 @@
${spotless.version}
-
- 1.25.2
-
-
-
-
-
+
+ 2.50.0
+
+
+
+
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ApplicationProperties.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ApplicationProperties.java
index e8cc1c4ed..5d3bfbf20 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ApplicationProperties.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ApplicationProperties.java
@@ -13,10 +13,10 @@
@ConfigurationProperties("application")
public class ApplicationProperties {
- @NotBlank(message = "External Call URL cant be Blank")
- private String externalCallUrl;
+ @NotBlank(message = "External Call URL cant be Blank") private String externalCallUrl;
- @NestedConfigurationProperty private Cors cors = new Cors();
+ @NestedConfigurationProperty
+ private Cors cors = new Cors();
@Getter
@Setter
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ClientLoggerRequestInterceptor.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ClientLoggerRequestInterceptor.java
index 9ffc3bf9d..7548862ae 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ClientLoggerRequestInterceptor.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/ClientLoggerRequestInterceptor.java
@@ -22,42 +22,35 @@ public class ClientLoggerRequestInterceptor implements ClientHttpRequestIntercep
private static final Logger log = LoggerFactory.getLogger(ClientLoggerRequestInterceptor.class);
@Override
- public ClientHttpResponse intercept(
- HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
+ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
logRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
return logResponse(response);
}
- private BufferingClientHttpResponseWrapper logResponse(ClientHttpResponse response)
- throws IOException {
- log.info(
- "============================response begin==========================================");
+ private BufferingClientHttpResponseWrapper logResponse(ClientHttpResponse response) throws IOException {
+ log.info("============================response begin==========================================");
log.info("Status code : {}", response.getStatusCode());
log.info("Status text : {}", response.getStatusText());
logHeaders(response.getHeaders());
- String responseBody =
- StreamUtils.copyToString(response.getBody(), Charset.defaultCharset());
+ String responseBody = StreamUtils.copyToString(response.getBody(), Charset.defaultCharset());
log.info("Response body: {}", responseBody);
- log.info(
- "=======================response end=================================================");
+ log.info("=======================response end=================================================");
return new BufferingClientHttpResponseWrapper(response, responseBody);
}
private void logRequest(HttpRequest request, byte[] body) {
- log.info(
- "===========================request begin================================================");
+ log.info("===========================request begin================================================");
log.info("URI : {}", request.getURI());
log.info("Method : {}", request.getMethod());
logHeaders(request.getHeaders());
if (body.length > 0) {
log.info("Request body: {}", new String(body, StandardCharsets.UTF_8));
}
- log.info(
- "==========================request end================================================");
+ log.info("==========================request end================================================");
}
private void logHeaders(HttpHeaders headers) {
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/GlobalExceptionHandler.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/GlobalExceptionHandler.java
index 8f6a0977b..a01ecc260 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/GlobalExceptionHandler.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/GlobalExceptionHandler.java
@@ -22,22 +22,19 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
ProblemDetail onException(MethodArgumentNotValidException methodArgumentNotValidException) {
ProblemDetail problemDetail =
- ProblemDetail.forStatusAndDetail(
- HttpStatusCode.valueOf(400), "Invalid request content.");
+ ProblemDetail.forStatusAndDetail(HttpStatusCode.valueOf(400), "Invalid request content.");
problemDetail.setTitle("Constraint Violation");
- List validationErrorsList =
- methodArgumentNotValidException.getAllErrors().stream()
- .map(
- objectError -> {
- FieldError fieldError = (FieldError) objectError;
- return new ApiValidationError(
- fieldError.getObjectName(),
- fieldError.getField(),
- fieldError.getRejectedValue(),
- Objects.requireNonNull(fieldError.getDefaultMessage()));
- })
- .sorted(Comparator.comparing(ApiValidationError::field))
- .toList();
+ List validationErrorsList = methodArgumentNotValidException.getAllErrors().stream()
+ .map(objectError -> {
+ FieldError fieldError = (FieldError) objectError;
+ return new ApiValidationError(
+ fieldError.getObjectName(),
+ fieldError.getField(),
+ fieldError.getRejectedValue(),
+ Objects.requireNonNull(fieldError.getDefaultMessage()));
+ })
+ .sorted(Comparator.comparing(ApiValidationError::field))
+ .toList();
problemDetail.setProperty("violations", validationErrorsList);
return problemDetail;
}
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/RestClientConfiguration.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/RestClientConfiguration.java
index 3dea72f21..204c14076 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/RestClientConfiguration.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/RestClientConfiguration.java
@@ -24,17 +24,14 @@ RestClient restClient(RestClient.Builder restClientBuilder) {
RestClientCustomizer restClientCustomizer(
ApplicationProperties applicationProperties,
ClientLoggerRequestInterceptor clientLoggerRequestInterceptor) {
- DefaultUriBuilderFactory factory =
- new DefaultUriBuilderFactory(applicationProperties.getExternalCallUrl());
+ DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(applicationProperties.getExternalCallUrl());
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.URI_COMPONENT);
- return restClientBuilder ->
- restClientBuilder
- .uriBuilderFactory(factory)
- .defaultHeaders(
- httpHeaders -> {
- httpHeaders.setContentType(MediaType.APPLICATION_JSON);
- httpHeaders.setAccept(List.of(MediaType.APPLICATION_JSON));
- })
- .requestInterceptor(clientLoggerRequestInterceptor);
+ return restClientBuilder -> restClientBuilder
+ .uriBuilderFactory(factory)
+ .defaultHeaders(httpHeaders -> {
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+ httpHeaders.setAccept(List.of(MediaType.APPLICATION_JSON));
+ })
+ .requestInterceptor(clientLoggerRequestInterceptor);
}
}
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/SwaggerConfig.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/SwaggerConfig.java
index a0984b0a8..2675dec4a 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/SwaggerConfig.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/config/SwaggerConfig.java
@@ -6,7 +6,5 @@
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
-@OpenAPIDefinition(
- info = @Info(title = "rest-client", version = "v1"),
- servers = @Server(url = "/"))
+@OpenAPIDefinition(info = @Info(title = "rest-client", version = "v1"), servers = @Server(url = "/"))
public class SwaggerConfig {}
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/model/response/PostDto.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/model/response/PostDto.java
index 5109c4a21..08270ff67 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/model/response/PostDto.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/model/response/PostDto.java
@@ -2,8 +2,4 @@
import jakarta.validation.constraints.NotBlank;
-public record PostDto(
- Long userId,
- Long id,
- @NotBlank(message = "title can't be blank") String title,
- String body) {}
+public record PostDto(Long userId, Long id, @NotBlank(message = "title can't be blank") String title, String body) {}
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/HttpClientService.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/HttpClientService.java
index 803f4b7dd..88247d49c 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/HttpClientService.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/HttpClientService.java
@@ -30,9 +30,7 @@ public HttpClientService(RestClient restClient) {
}
T callAndFetchResponseForGetMethod(
- Function uriFunction,
- @Nullable Map headers,
- Class bodyType) {
+ Function uriFunction, @Nullable Map headers, Class bodyType) {
return callServer(uriFunction, HttpMethod.GET, headers, null, bodyType, null);
}
@@ -41,8 +39,7 @@ T callAndFetchResponseForGetMethod(
return callServer(uriFunction, HttpMethod.GET, null, null, null, bodyType);
}
- T callAndFetchResponseForPostMethod(
- Function uriFunction, Object body, Class bodyType) {
+ T callAndFetchResponseForPostMethod(Function uriFunction, Object body, Class bodyType) {
return callServer(uriFunction, HttpMethod.POST, null, body, bodyType, null);
}
@@ -55,8 +52,7 @@ String callAndFetchResponseForDeleteMethod(Function uriFunction
return callAndFetchResponseForDeleteMethod(uriFunction, String.class);
}
- T callAndFetchResponseForDeleteMethod(
- Function uriFunction, Class bodyType) {
+ T callAndFetchResponseForDeleteMethod(Function uriFunction, Class bodyType) {
return callServer(uriFunction, HttpMethod.DELETE, null, null, bodyType, null);
}
@@ -69,21 +65,15 @@ private T callServer(
ParameterizedTypeReference typeReferenceBodyType) {
RestClient.RequestBodySpec uri = restClient.method(httpMethod).uri(uriFunction);
if (!CollectionUtils.isEmpty(headers)) {
- uri.headers(
- httpHeader ->
- headers.keySet().forEach(key -> httpHeader.add(key, headers.get(key))));
+ uri.headers(httpHeader -> headers.keySet().forEach(key -> httpHeader.add(key, headers.get(key))));
}
if (body != null) {
uri.body(body);
}
- RestClient.ResponseSpec responseSpec =
- uri.retrieve()
- .onStatus(
- HttpStatusCode::is4xxClientError,
- (request, response) -> {
- throw new MyCustomClientException(
- response.getStatusCode(), response.getHeaders());
- });
+ RestClient.ResponseSpec responseSpec = uri.retrieve()
+ .onStatus(HttpStatusCode::is4xxClientError, (request, response) -> {
+ throw new MyCustomClientException(response.getStatusCode(), response.getHeaders());
+ });
if (bodyType != null) {
return responseSpec.body(bodyType);
} else {
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/PostService.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/PostService.java
index 6acc3cf0b..e1b32c994 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/PostService.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/services/PostService.java
@@ -18,16 +18,12 @@ public PostService(HttpClientService httpClientService) {
public List findAllPosts() {
return httpClientService.callAndFetchResponseForGetMethod(
- uriBuilder -> uriBuilder.path("/posts").build(),
- new ParameterizedTypeReference>() {});
+ uriBuilder -> uriBuilder.path("/posts").build(), new ParameterizedTypeReference>() {});
}
public Optional findPostById(Long id) {
- PostDto response =
- httpClientService.callAndFetchResponseForGetMethod(
- uriBuilder -> uriBuilder.path("/posts/{postId}").build(id),
- Map.of("apiKey", "123456"),
- PostDto.class);
+ PostDto response = httpClientService.callAndFetchResponseForGetMethod(
+ uriBuilder -> uriBuilder.path("/posts/{postId}").build(id), Map.of("apiKey", "123456"), PostDto.class);
return Optional.ofNullable(response);
}
@@ -37,11 +33,8 @@ public PostDto savePost(PostDto post) {
}
public Optional updatePostById(Long id, PostDto postDto) {
- PostDto response =
- httpClientService.callAndFetchResponseForPutMethod(
- uriBuilder -> uriBuilder.path("/posts/{postId}").build(id),
- postDto,
- PostDto.class);
+ PostDto response = httpClientService.callAndFetchResponseForPutMethod(
+ uriBuilder -> uriBuilder.path("/posts/{postId}").build(id), postDto, PostDto.class);
return Optional.ofNullable(response);
}
diff --git a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/web/controllers/PostController.java b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/web/controllers/PostController.java
index f324b50ac..afda8330f 100644
--- a/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/web/controllers/PostController.java
+++ b/httpClients/boot-restclient/src/main/java/com/example/restclient/bootrestclient/web/controllers/PostController.java
@@ -33,10 +33,8 @@ public List getAllPosts() {
@GetMapping("/{id}")
public ResponseEntity getPostById(@PathVariable Long id) {
- return postService
- .findPostById(id)
- .map(ResponseEntity::ok)
- .orElseGet(() -> ResponseEntity.notFound().build());
+ return postService.findPostById(id).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound()
+ .build());
}
@PostMapping
@@ -47,10 +45,8 @@ public PostDto createPost(@RequestBody @Validated PostDto post) {
@PutMapping("/{id}")
public ResponseEntity updatePost(@PathVariable Long id, @RequestBody PostDto post) {
- return postService
- .updatePostById(id, post)
- .map(ResponseEntity::ok)
- .orElseGet(() -> ResponseEntity.notFound().build());
+ return postService.updatePostById(id, post).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound()
+ .build());
}
@DeleteMapping("/{id}")
diff --git a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/BootRestClientApplicationTests.java b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/BootRestClientApplicationTests.java
index 6b74aa276..c6bdaf42d 100644
--- a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/BootRestClientApplicationTests.java
+++ b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/BootRestClientApplicationTests.java
@@ -26,15 +26,18 @@
@AutoConfigureMockMvc
class BootRestClientApplicationTests {
- @Autowired private MockMvc mockMvc;
+ @Autowired
+ private MockMvc mockMvc;
- @Autowired RestClient.Builder builder;
+ @Autowired
+ RestClient.Builder builder;
private MockRestServiceServer mockServer;
@BeforeEach
void setUp() {
- mockServer = MockRestServiceServer.bindTo(builder).ignoreExpectOrder(true).build();
+ mockServer =
+ MockRestServiceServer.bindTo(builder).ignoreExpectOrder(true).build();
}
@Test
@@ -56,13 +59,12 @@ void findPostById() throws Exception {
.andRespond(withSuccess(mockApiResponse, MediaType.APPLICATION_JSON));
// Perform the test
- String result =
- this.mockMvc
- .perform(get("/api/posts/{postId}", 1))
- .andExpect(status().isOk())
- .andReturn()
- .getResponse()
- .getContentAsString();
+ String result = this.mockMvc
+ .perform(get("/api/posts/{postId}", 1))
+ .andExpect(status().isOk())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
// Verify the result
assertThat(result).isEqualToIgnoringWhitespace(mockApiResponse);
@@ -100,16 +102,12 @@ void createPost() throws Exception {
.andRespond(withSuccess(mockApiResponse, MediaType.APPLICATION_JSON));
// Perform the test
- String result =
- this.mockMvc
- .perform(
- post("/api/posts")
- .content(mockApiRequest)
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isCreated())
- .andReturn()
- .getResponse()
- .getContentAsString();
+ String result = this.mockMvc
+ .perform(post("/api/posts").content(mockApiRequest).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isCreated())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
// Verify the result
assertThat(result).isEqualToIgnoringWhitespace(mockApiResponse);
diff --git a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/services/PostServiceTest.java b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/services/PostServiceTest.java
index a6c6a7cfd..cedde57a1 100644
--- a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/services/PostServiceTest.java
+++ b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/services/PostServiceTest.java
@@ -29,11 +29,14 @@
})
class PostServiceTest {
- @Autowired private MockRestServiceServer mockRestServiceServer;
+ @Autowired
+ private MockRestServiceServer mockRestServiceServer;
- @Autowired private ObjectMapper objectMapper;
+ @Autowired
+ private ObjectMapper objectMapper;
- @Autowired private PostService postService;
+ @Autowired
+ private PostService postService;
@Test
void findPostById() throws JsonProcessingException {
@@ -45,10 +48,7 @@ void findPostById() throws JsonProcessingException {
.andExpect(header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
.andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
.andExpect(header("apiKey", "123456"))
- .andRespond(
- withSuccess(
- objectMapper.writeValueAsString(postDto),
- MediaType.APPLICATION_JSON));
+ .andRespond(withSuccess(objectMapper.writeValueAsString(postDto), MediaType.APPLICATION_JSON));
Optional optionalPostDto = postService.findPostById(1L);
diff --git a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerIntTest.java b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerIntTest.java
index b6a97ad0f..b9fa2de4c 100644
--- a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerIntTest.java
+++ b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerIntTest.java
@@ -26,8 +26,11 @@
@AutoConfigureMockMvc
class PostControllerIntTest {
- @Autowired private MockMvc mockMvc;
- @Autowired private ObjectMapper objectMapper;
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private ObjectMapper objectMapper;
@Test
void shouldFindPostById() throws Exception {
@@ -36,11 +39,8 @@ void shouldFindPostById() throws Exception {
.perform(get("/api/posts/{id}", 1))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(1)))
- .andExpect(
- jsonPath(
- "$.title",
- is(
- "sunt aut facere repellat provident occaecati excepturi optio reprehenderit")))
+ .andExpect(jsonPath(
+ "$.title", is("sunt aut facere repellat provident occaecati excepturi optio reprehenderit")))
.andExpect(jsonPath("$.userId", is(1)))
.andExpect(
jsonPath(
@@ -53,10 +53,9 @@ void shouldFindPostById() throws Exception {
void shouldCreateNewPost() throws Exception {
PostDto postDto = new PostDto(1L, null, "First Title", "First Body");
this.mockMvc
- .perform(
- post("/api/posts")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(postDto)))
+ .perform(post("/api/posts")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(postDto)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id", notNullValue()))
.andExpect(jsonPath("$.title", is(postDto.title())))
@@ -69,15 +68,11 @@ void shouldReturn400WhenCreateNewPostWithoutTitle() throws Exception {
PostDto post = new PostDto(1L, null, null, "First Body");
this.mockMvc
- .perform(
- post("/api/posts")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(post)))
+ .perform(post("/api/posts")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(post)))
.andExpect(status().isBadRequest())
- .andExpect(
- header().string(
- HttpHeaders.CONTENT_TYPE,
- is(MediaType.APPLICATION_PROBLEM_JSON_VALUE)))
+ .andExpect(header().string(HttpHeaders.CONTENT_TYPE, is(MediaType.APPLICATION_PROBLEM_JSON_VALUE)))
.andExpect(jsonPath("$.type", is("about:blank")))
.andExpect(jsonPath("$.title", is("Constraint Violation")))
.andExpect(jsonPath("$.status", is(400)))
@@ -94,10 +89,9 @@ void shouldUpdatePost() throws Exception {
PostDto postDto = new PostDto(1L, 1L, "First Title", "First Body");
this.mockMvc
- .perform(
- put("/api/posts/{id}", postDto.id())
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(postDto)))
+ .perform(put("/api/posts/{id}", postDto.id())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(postDto)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(postDto.id()), Long.class))
.andExpect(jsonPath("$.title", is(postDto.title())))
@@ -108,13 +102,12 @@ void shouldUpdatePost() throws Exception {
@Test
void shouldDeletePost() throws Exception {
- String response =
- this.mockMvc
- .perform(delete("/api/posts/{id}", 50))
- .andExpect(status().isOk())
- .andReturn()
- .getResponse()
- .getContentAsString();
+ String response = this.mockMvc
+ .perform(delete("/api/posts/{id}", 50))
+ .andExpect(status().isOk())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
assertThat(response).isEqualTo("{}");
}
}
diff --git a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerTest.java b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerTest.java
index 23cd2bb21..73f5ad6b2 100644
--- a/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerTest.java
+++ b/httpClients/boot-restclient/src/test/java/com/example/restclient/bootrestclient/web/controllers/PostControllerTest.java
@@ -33,11 +33,14 @@
@ActiveProfiles(PROFILE_TEST)
class PostControllerTest {
- @Autowired private MockMvc mockMvc;
+ @Autowired
+ private MockMvc mockMvc;
- @MockitoBean private PostService postService;
+ @MockitoBean
+ private PostService postService;
- @Autowired private ObjectMapper objectMapper;
+ @Autowired
+ private ObjectMapper objectMapper;
private List postList;
@@ -81,15 +84,13 @@ void shouldReturn404WhenFetchingNonExistingPost() throws Exception {
@Test
void shouldCreateNewPost() throws Exception {
- given(postService.savePost(any(PostDto.class)))
- .willAnswer((invocation) -> invocation.getArgument(0));
+ given(postService.savePost(any(PostDto.class))).willAnswer((invocation) -> invocation.getArgument(0));
PostDto post = new PostDto(1L, 1L, "text 1", "First Body");
this.mockMvc
- .perform(
- post("/api/posts")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(post)))
+ .perform(post("/api/posts")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(post)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id", notNullValue()))
.andExpect(jsonPath("$.title", is(post.title())));
@@ -100,10 +101,9 @@ void shouldReturn400WhenCreateNewPostWithoutTitle() throws Exception {
PostDto post = new PostDto(null, null, null, null);
this.mockMvc
- .perform(
- post("/api/posts")
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(post)))
+ .perform(post("/api/posts")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(post)))
.andExpect(status().isBadRequest())
.andExpect(header().string("Content-Type", is("application/problem+json")))
.andExpect(jsonPath("$.type", is("about:blank")))
@@ -124,10 +124,9 @@ void shouldUpdatePost() throws Exception {
given(postService.updatePostById(postId, post)).willReturn(Optional.of(post));
this.mockMvc
- .perform(
- put("/api/posts/{id}", post.id())
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(post)))
+ .perform(put("/api/posts/{id}", post.id())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(post)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.title", is(post.title())));
}
@@ -139,10 +138,9 @@ void shouldReturn404WhenUpdatingNonExistingPost() throws Exception {
PostDto post = new PostDto(1L, postId, "Updated text", "First Body");
this.mockMvc
- .perform(
- put("/api/posts/{id}", postId)
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(post)))
+ .perform(put("/api/posts/{id}", postId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(post)))
.andExpect(status().isNotFound());
}
diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/entities/OrderItem.java b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/entities/OrderItem.java
index 999a9159f..53d483486 100644
--- a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/entities/OrderItem.java
+++ b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/entities/OrderItem.java
@@ -23,8 +23,7 @@ public class OrderItem {
private Long id;
@Column(nullable = false)
- @NotEmpty(message = "Text cannot be empty")
- private String text;
+ @NotEmpty(message = "Text cannot be empty") private String text;
@ManyToOne
@JoinColumn(name = "order_id")
diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/CustomerRequest.java b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/CustomerRequest.java
index c465cfaf8..f2f9e2de0 100644
--- a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/CustomerRequest.java
+++ b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/CustomerRequest.java
@@ -6,7 +6,5 @@
public record CustomerRequest(
@NotBlank(message = "FirstName must not be blank") String firstName,
String lastName,
- @Email(message = "Email value must be a well-formed email address")
- @NotBlank(message = "Email must not be blank")
- String email,
+ @Email(message = "Email value must be a well-formed email address") @NotBlank(message = "Email must not be blank") String email,
String phone) {}
diff --git a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/OrderRequest.java b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/OrderRequest.java
index 5022603b0..cab22b9ce 100644
--- a/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/OrderRequest.java
+++ b/jpa/boot-hibernate2ndlevelcache-sample/src/main/java/com/example/hibernatecache/model/request/OrderRequest.java
@@ -10,9 +10,7 @@
public record OrderRequest(
Long customerId,
@NotBlank(message = "Name cannot be blank") String name,
- @NotNull(message = "Price cannot be null") @DecimalMin(value = "0.01", message = "Value must be greater than or equal to 0.01")
- @DecimalMax(value = "10000.00", message = "Value must be less than or equal to 10000.00")
- @Digits(
+ @NotNull(message = "Price cannot be null") @DecimalMin(value = "0.01", message = "Value must be greater than or equal to 0.01") @DecimalMax(value = "10000.00", message = "Value must be less than or equal to 10000.00") @Digits(
integer = 3,
fraction = 2,
message = "Value must have at most 3 digits in integer part and 2 in fraction part")
diff --git a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/config/ApplicationProperties.java b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/config/ApplicationProperties.java
index 7454825de..1f23479b4 100644
--- a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/config/ApplicationProperties.java
+++ b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/config/ApplicationProperties.java
@@ -10,8 +10,7 @@
public class ApplicationProperties {
@NestedConfigurationProperty
- @Valid
- private Cors cors = new Cors();
+ @Valid private Cors cors = new Cors();
public Cors getCors() {
return cors;
diff --git a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/model/query/SearchCriteria.java b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/model/query/SearchCriteria.java
index e0821545d..3d40afdc0 100644
--- a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/model/query/SearchCriteria.java
+++ b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/model/query/SearchCriteria.java
@@ -21,12 +21,9 @@ public class SearchCriteria implements ISearchCriteria {
@NotNull(message = "Operator cannot be null") private QueryOperator queryOperator;
- @NotBlank(message = "Field name cannot be null or blank")
- private String field;
+ @NotBlank(message = "Field name cannot be null or blank") private String field;
- @NotNull(message = "Values list cannot be null") @Size(min = 1, message = "Values list cannot be empty")
- @Valid
- private List values;
+ @NotNull(message = "Values list cannot be null") @Size(min = 1, message = "Values list cannot be empty") @Valid private List values;
public SearchCriteria() {}
diff --git a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/web/controllers/AnimalController.java b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/web/controllers/AnimalController.java
index 49d355c3b..1060fa9ea 100644
--- a/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/web/controllers/AnimalController.java
+++ b/jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/web/controllers/AnimalController.java
@@ -63,13 +63,10 @@ PagedResult getAllAnimals(
public Window searchAnimals(
@Parameter(description = "Number of items per page (max 100)", in = ParameterIn.QUERY)
@RequestParam(defaultValue = "10")
- @Min(1)
- @Max(100)
- int pageSize,
+ @Min(1) @Max(100) int pageSize,
@Parameter(description = "Scroll ID for pagination", in = ParameterIn.QUERY) @RequestParam(required = false)
Long scrollId,
- @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true) @RequestBody @Valid
- SearchRequest searchRequest) {
+ @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true) @RequestBody @Valid SearchRequest searchRequest) {
return animalService.searchAnimals(searchRequest, pageSize, scrollId);
}