From 3ef0ac42572f64ce9f99c112a43bcc350803ab97 Mon Sep 17 00:00:00 2001 From: Gilvan Ornelas Fernandes Filho Date: Sun, 20 Dec 2020 21:29:30 -0300 Subject: [PATCH 001/149] Clean architecture initial commit --- patterns/clean-architecture/pom.xml | 87 +++++++++++++++++++ .../CleanArchitectureApplication.java | 40 +++++++++ .../usercreation/CommonUser.java | 30 +++++++ .../usercreation/CommonUserFactory.java | 8 ++ .../usercreation/JpaUser.java | 21 +++++ .../usercreation/JpaUserRepository.java | 8 ++ .../cleanarchitecture/usercreation/User.java | 9 ++ .../usercreation/UserDataMapper.java | 53 +++++++++++ .../usercreation/UserDsRequestModel.java | 41 +++++++++ .../usercreation/UserFactory.java | 5 ++ .../usercreation/UserInputBoundary.java | 5 ++ .../usercreation/UserPresenter.java | 7 ++ .../usercreation/UserRegisterController.java | 20 +++++ .../usercreation/UserRegisterDsGateway.java | 7 ++ .../usercreation/UserRegisterInteractor.java | 35 ++++++++ .../usercreation/UserRequestModel.java | 33 +++++++ .../usercreation/UserResponseFormatter.java | 22 +++++ .../usercreation/UserResponseModel.java | 29 +++++++ .../src/main/resources/application.properties | 2 + .../UserResponseFormatterTests.java | 29 +++++++ .../usercreation/UserUnitTest.java | 15 ++++ 21 files changed, 506 insertions(+) create mode 100644 patterns/clean-architecture/pom.xml create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java create mode 100644 patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java create mode 100644 patterns/clean-architecture/src/main/resources/application.properties create mode 100644 patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java create mode 100644 patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java diff --git a/patterns/clean-architecture/pom.xml b/patterns/clean-architecture/pom.xml new file mode 100644 index 0000000000..6e7de78751 --- /dev/null +++ b/patterns/clean-architecture/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + clean-architecture + 1.0 + clean-architecture + Project for clean architecture in java + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + 1.8 + + + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.mockito + mockito-core + test + + + org.junit.platform + junit-platform-engine + + + org.junit.jupiter + junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.platform + junit-platform-runner + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java new file mode 100644 index 0000000000..ebac2bacf3 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/CleanArchitectureApplication.java @@ -0,0 +1,40 @@ +package com.baeldung.pattern.cleanarchitecture; + +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.core.type.filter.TypeFilter; + +@SpringBootApplication +public class CleanArchitectureApplication { + + public static void main(String[] args) { + SpringApplication.run(CleanArchitectureApplication.class); + } + + @Bean + BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext beanRegistry) { + return beanFactory -> { + genericApplicationContext((BeanDefinitionRegistry) ((AnnotationConfigServletWebServerApplicationContext) beanRegistry).getBeanFactory()); + }; + } + + void genericApplicationContext(BeanDefinitionRegistry beanRegistry) { + ClassPathBeanDefinitionScanner beanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanRegistry); + beanDefinitionScanner.addIncludeFilter(removeModelAndEntitiesFilter()); + beanDefinitionScanner.scan("com.baeldung.pattern.cleanarchitecture"); + } + + static TypeFilter removeModelAndEntitiesFilter() { + return (MetadataReader mr, MetadataReaderFactory mrf) -> !mr.getClassMetadata() + .getClassName() + .endsWith("Model"); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java new file mode 100644 index 0000000000..f7ba9dacc0 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java @@ -0,0 +1,30 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class CommonUser implements User { + + String name; + String password; + + CommonUser(String name, String password) { + this.name = name; + this.password = password; + } + + CommonUser() { + } + + @Override + public boolean passwordIsValid() { + return password == null || password.length() > 5; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getPassword() { + return password; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java new file mode 100644 index 0000000000..a2b851da94 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUserFactory.java @@ -0,0 +1,8 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class CommonUserFactory implements UserFactory { + @Override + public User create(String name, String password) { + return new CommonUser(name, password); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java new file mode 100644 index 0000000000..20751f282a --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUser.java @@ -0,0 +1,21 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class JpaUser implements UserRegisterDsGateway { + + final JpaUserRepository repository; + + JpaUser(JpaUserRepository repository) { + this.repository = repository; + } + + @Override + public boolean existsByName(String name) { + return repository.existsById(name); + } + + @Override + public void save(UserDsRequestModel requestModel) { + UserDataMapper accountDataMapper = new UserDataMapper(requestModel.getName(), requestModel.getPassword(), requestModel.getCreationTime()); + repository.save(accountDataMapper); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java new file mode 100644 index 0000000000..8565ed7965 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/JpaUserRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +interface JpaUserRepository extends JpaRepository { +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java new file mode 100644 index 0000000000..aab652f2a1 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/User.java @@ -0,0 +1,9 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface User { + boolean passwordIsValid(); + + String getName(); + + String getPassword(); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java new file mode 100644 index 0000000000..44112de8a9 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDataMapper.java @@ -0,0 +1,53 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "user") +class UserDataMapper { + + @Id + String name; + + String password; + + LocalDateTime creationTime; + + public UserDataMapper() { + } + + public UserDataMapper(String name, String password, LocalDateTime creationTime) { + super(); + this.name = name; + this.password = password; + this.creationTime = creationTime; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public LocalDateTime getCreationTime() { + return creationTime; + } + + public void setCreationTime(LocalDateTime creationTime) { + this.creationTime = creationTime; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java new file mode 100644 index 0000000000..aa0f0b56d1 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserDsRequestModel.java @@ -0,0 +1,41 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +class UserDsRequestModel { + + String name; + String password; + LocalDateTime creationTime; + + public UserDsRequestModel(String name, String password, LocalDateTime creationTime) { + this.name = name; + this.password = password; + this.creationTime = creationTime; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public LocalDateTime getCreationTime() { + return creationTime; + } + + public void setCreationTime(LocalDateTime creationTime) { + this.creationTime = creationTime; + } + +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java new file mode 100644 index 0000000000..1ff29709be --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserFactory.java @@ -0,0 +1,5 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserFactory { + User create(String name, String password); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java new file mode 100644 index 0000000000..e72c30f13c --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserInputBoundary.java @@ -0,0 +1,5 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +public interface UserInputBoundary { + UserResponseModel create(UserRequestModel requestModel); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java new file mode 100644 index 0000000000..45d202643e --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserPresenter.java @@ -0,0 +1,7 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserPresenter { + UserResponseModel prepareSuccessView(UserResponseModel user); + + UserResponseModel prepareFailView(String error); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java new file mode 100644 index 0000000000..039dc12910 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterController.java @@ -0,0 +1,20 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +class UserRegisterController { + + final UserInputBoundary userInput; + + UserRegisterController(UserInputBoundary accountGateway) { + this.userInput = accountGateway; + } + + @PostMapping("/user") + UserResponseModel create(@RequestBody UserRequestModel requestModel) { + return userInput.create(requestModel); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java new file mode 100644 index 0000000000..89c1b7e774 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterDsGateway.java @@ -0,0 +1,7 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +interface UserRegisterDsGateway { + boolean existsByName(String identifier); + + void save(UserDsRequestModel requestModel); +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java new file mode 100644 index 0000000000..5137593dc3 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRegisterInteractor.java @@ -0,0 +1,35 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; + +class UserRegisterInteractor implements UserInputBoundary { + + final UserRegisterDsGateway userDsGateway; + final UserPresenter userPresenter; + final UserFactory userFactory; + + UserRegisterInteractor(UserRegisterDsGateway userRegisterDfGateway, UserPresenter userPresenter, + UserFactory userFactory) { + this.userDsGateway = userRegisterDfGateway; + this.userPresenter = userPresenter; + this.userFactory = userFactory; + } + + @Override + public UserResponseModel create(UserRequestModel requestModel) { + if (userDsGateway.existsByName(requestModel.getName())) { + return userPresenter.prepareFailView("User already exists."); + } + User user = userFactory.create(requestModel.getName(), requestModel.getPassword()); + if (!user.passwordIsValid()) { + return userPresenter.prepareFailView("User password must have more than 5 characters."); + } + LocalDateTime now = LocalDateTime.now(); + UserDsRequestModel userDsModel = new UserDsRequestModel(user.getName(), user.getPassword(), now); + + userDsGateway.save(userDsModel); + + UserResponseModel accountResponseModel = new UserResponseModel(user.getName(), now.toString()); + return userPresenter.prepareSuccessView(accountResponseModel); + } +} \ No newline at end of file diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java new file mode 100644 index 0000000000..8317665c31 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserRequestModel.java @@ -0,0 +1,33 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +class UserRequestModel { + + String name; + String password; + + public UserRequestModel() { + super(); + } + + UserRequestModel(String name, String password) { + super(); + this.name = name; + this.password = password; + } + + String getName() { + return name; + } + + void setName(String name) { + this.name = name; + } + + String getPassword() { + return password; + } + + void setPassword(String password) { + this.password = password; + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java new file mode 100644 index 0000000000..4842d44e22 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatter.java @@ -0,0 +1,22 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +class UserResponseFormatter implements UserPresenter { + + @Override + public UserResponseModel prepareSuccessView(UserResponseModel response) { + LocalDateTime responseTime = LocalDateTime.parse(response.getCreationTime()); + response.setCreationTime(responseTime.format(DateTimeFormatter.ofPattern("hh:mm:ss"))); + return response; + } + + @Override + public UserResponseModel prepareFailView(String error) { + throw new ResponseStatusException(HttpStatus.CONFLICT, error); + } +} diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java new file mode 100644 index 0000000000..73a3d8fb10 --- /dev/null +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseModel.java @@ -0,0 +1,29 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +public class UserResponseModel { + + String login; + String creationTime; + + public UserResponseModel(String login, String creationTime) { + this.login = login; + this.creationTime = creationTime; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getCreationTime() { + return creationTime; + } + + public void setCreationTime(String creationTime) { + this.creationTime = creationTime; + } + +} diff --git a/patterns/clean-architecture/src/main/resources/application.properties b/patterns/clean-architecture/src/main/resources/application.properties new file mode 100644 index 0000000000..a5a02bb49d --- /dev/null +++ b/patterns/clean-architecture/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.error.include-message=always \ No newline at end of file diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java new file mode 100644 index 0000000000..f8ebde5f10 --- /dev/null +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java @@ -0,0 +1,29 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; +import org.springframework.web.server.ResponseStatusException; + +import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseFormatter; +import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseModel; + +class UserResponseFormatterTests { + + UserResponseFormatter userResponseFormatter = new UserResponseFormatter(); + + @Test + void givenDateAnd3HourTime_whenPrepareSuccessView_thenReturnOnly3HourTime() { + UserResponseModel modelResponse = new UserResponseModel("baeldung", "2020-12-20T03:00:00.000"); + UserResponseModel formattedResponse = userResponseFormatter.prepareSuccessView(modelResponse); + + assertThat(formattedResponse.getCreationTime()).isEqualTo("03:00:00"); + } + + @Test + void whenPrepareFailView_thenThrowHttpConflictException() { + assertThatThrownBy(() -> userResponseFormatter.prepareFailView("Invalid password")) + .isInstanceOf(ResponseStatusException.class); + } +} diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java new file mode 100644 index 0000000000..505ea47e3f --- /dev/null +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.pattern.cleanarchitecture.usercreation; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class UserUnitTest { + + @Test + void given123Password_whenPasswordIsNotValid_thenIsFalse() { + User user = new CommonUser("Baeldung", "123"); + + assertThat(user.passwordIsValid()).isFalse(); + } +} From c6e380d798ed362a754754a73f82a7553f66dd0d Mon Sep 17 00:00:00 2001 From: krzysztof Date: Wed, 23 Dec 2020 12:46:18 +0100 Subject: [PATCH 002/149] BAEL-4750 Java 12 New Features --- .../newfeatures/CompactNumbersUnitTest.java | 21 ++++++++++++ .../newfeatures/FileMismatchUnitTest.java | 32 +++++++++++++++++++ .../baeldung/newfeatures/StringUnitTest.java | 15 +++++++++ .../newfeatures/TeeingCollectorUnitTest.java | 18 +++++++++++ 4 files changed, 86 insertions(+) create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java create mode 100644 core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java new file mode 100644 index 0000000000..08a6d58d72 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java @@ -0,0 +1,21 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.text.NumberFormat; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +public class CompactNumbersUnitTest { + + @Test + public void givenNumber_thenCompactValues() { + NumberFormat likesShort = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT); + likesShort.setMaximumFractionDigits(2); + assertEquals("2.59K", likesShort.format(2592)); + NumberFormat likesLong = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG); + likesLong.setMaximumFractionDigits(2); + assertEquals("2.59 thousand", likesShort.format(2592)); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java new file mode 100644 index 0000000000..7f081fe399 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java @@ -0,0 +1,32 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.Assert.assertEquals; + +public class FileMismatchUnitTest { + + @Test + public void givenIdenticalFiles_thenShouldNotFindMismatch() throws IOException { + Path filePath1 = Files.createTempFile("file1", ".txt"); + Path filePath2 = Files.createTempFile("file2", ".txt"); + Files.writeString(filePath1, "Java 12 Article"); + Files.writeString(filePath2, "Java 12 Article"); + long mismatch = Files.mismatch(filePath1, filePath2); + assertEquals(-1, mismatch); + } + + @Test + public void givenDifferentFiles_thenShouldFindMismatch() throws IOException { + Path filePath3 = Files.createTempFile("file3", ".txt"); + Path filePath4 = Files.createTempFile("file4", ".txt"); + Files.writeString(filePath3, "Java 12 Article"); + Files.writeString(filePath4, "Java 12 Tutorial"); + long mismatch = Files.mismatch(filePath3, filePath4); + assertEquals(8, mismatch); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java new file mode 100644 index 0000000000..5ae51bd960 --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java @@ -0,0 +1,15 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class StringUnitTest { + + @Test + public void givenString_thenRevertValue() { + String text = "Baeldung"; + String transformed = text.transform(value -> new StringBuilder(value).reverse().toString()); + assertEquals("gnudleaB", transformed); + } +} diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java new file mode 100644 index 0000000000..90fc4eda5e --- /dev/null +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java @@ -0,0 +1,18 @@ +package java.com.baeldung.newfeatures; + +import org.junit.Test; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +public class TeeingCollectorUnitTest { + + @Test + public void givenSetOfNumbers_thenCalculateAverage() { + double mean = Stream.of(1, 2, 3, 4, 5) + .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); + assertEquals(3.0, mean); + } +} From c79e7d8cbdf130e36412289d1f6c24070617a142 Mon Sep 17 00:00:00 2001 From: krzysztof Date: Wed, 23 Dec 2020 12:48:07 +0100 Subject: [PATCH 003/149] BAEL-4750 Java 12 New Features --- .../java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java index 90fc4eda5e..30a5cb40a7 100644 --- a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java @@ -12,7 +12,7 @@ public class TeeingCollectorUnitTest { @Test public void givenSetOfNumbers_thenCalculateAverage() { double mean = Stream.of(1, 2, 3, 4, 5) - .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); + .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count)); assertEquals(3.0, mean); } } From 2d2a64acbe74fdb9da86e582362e6df28590db8c Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Fri, 25 Dec 2020 09:06:51 +0530 Subject: [PATCH 004/149] Added changes to show transaction roll back --- .../baeldung/spring/transaction/Course.java | 35 +++++++++++++++++ .../spring/transaction/CourseDao.java | 24 ++++++++++++ .../spring/transaction/CourseService.java | 38 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java new file mode 100644 index 0000000000..5add1e4a99 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/Course.java @@ -0,0 +1,35 @@ +package com.baeldung.spring.transaction; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "course") +public class Course implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "id") + private Long id; + + public Course() { + } + + public Course(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java new file mode 100644 index 0000000000..489784bb40 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.transaction; + +import java.sql.SQLException; + +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.stereotype.Repository; + +import com.baeldung.spring.hibernate.AbstractHibernateDao; + +@Repository +public class CourseDao extends AbstractHibernateDao { + public CourseDao() { + super(); + setClazz(Course.class); + } + + public Course createWithRuntimeException(final Course entity) { + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); + } + + public Course createWithCheckedException(final Course entity) throws SQLException { + throw new SQLException("Throwing exception for demoing Rollback!!!"); + } +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java new file mode 100644 index 0000000000..1478c5bd1d --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -0,0 +1,38 @@ +package com.baeldung.spring.transaction; + +import java.sql.SQLException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +@Service +public class CourseService { + + @Autowired + private CourseDao courseDao; + + @Transactional + public void createCourseDeclarativeWithRuntimeException(Course course) { + courseDao.createWithRuntimeException(course); + } + + @Transactional(rollbackFor = { SQLException.class }) + public void createCourseDeclarativeWithCheckedException(Course course) throws SQLException { + courseDao.createWithCheckedException(course); + } + + public void createCourseDefaultRatingProgramatic(Course course) { + try { + courseDao.createWithRuntimeException(course); + } catch (Exception e) { + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + } + + public Course findById(Long id) { + return courseDao.findOne(id); + } + +} From d44dacaa2b69659b1d257229650c2c7598c09761 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Sat, 26 Dec 2020 06:14:52 +0530 Subject: [PATCH 005/149] Removed unwanted method --- .../java/com/baeldung/spring/transaction/CourseService.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 1478c5bd1d..21f947a925 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -31,8 +31,4 @@ public class CourseService { } } - public Course findById(Long id) { - return courseDao.findOne(id); - } - } From d1af00c8c95be12b016fc0996600178e12c058d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 28 Dec 2020 14:51:36 +0100 Subject: [PATCH 006/149] JAVA-3545: Move spring-thymeleaf-3 into spring-web-modules --- pom.xml | 3 --- spring-web-modules/pom.xml | 1 + .../spring-thymeleaf-3}/README.md | 0 .../spring-thymeleaf-3}/pom.xml | 2 +- .../src/main/java/com/baeldung/thymeleaf/Application.java | 0 .../src/main/java/com/baeldung/thymeleaf/articles/Article.java | 0 .../com/baeldung/thymeleaf/articles/ArticlesController.java | 0 .../main/java/com/baeldung/thymeleaf/blog/BlogController.java | 0 .../src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java | 0 .../conditionalclasses/ConditionalClassesController.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java | 0 .../com/baeldung/thymeleaf/cssandjs/CssAndJsController.java | 0 .../baeldung/thymeleaf/currencies/CurrenciesController.java | 0 .../src/main/java/com/baeldung/thymeleaf/option/Student.java | 0 .../java/com/baeldung/thymeleaf/option/StudentController.java | 0 .../src/main/resources/static/js/cssandjs/actions.js | 0 .../src/main/resources/static/styles/cssandjs/main.css | 0 .../src/main/resources/templates/articles/articles-list.html | 0 .../src/main/resources/templates/blog/blog-new.html | 0 .../templates/conditionalclasses/conditionalclasses.html | 0 .../src/main/resources/templates/cssandjs/styledPage.html | 0 .../src/main/resources/templates/currencies/currencies.html | 0 .../src/main/resources/templates/option/studentForm.html | 0 .../com/baeldung/thymeleaf/ApplicationIntegrationTest.java | 0 .../thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java | 0 .../currencies/CurrenciesControllerIntegrationTest.java | 0 26 files changed, 2 insertions(+), 4 deletions(-) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/README.md (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/pom.xml (98%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/Application.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/Article.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/Student.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/java/com/baeldung/thymeleaf/option/StudentController.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/js/cssandjs/actions.js (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/static/styles/cssandjs/main.css (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/articles/articles-list.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/blog/blog-new.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/conditionalclasses/conditionalclasses.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/cssandjs/styledPage.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/currencies/currencies.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/main/resources/templates/option/studentForm.html (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java (100%) rename {spring-thymeleaf-3 => spring-web-modules/spring-thymeleaf-3}/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java (100%) diff --git a/pom.xml b/pom.xml index f66433c612..14565fe87d 100644 --- a/pom.xml +++ b/pom.xml @@ -694,7 +694,6 @@ spring-swagger-codegen spring-threads - spring-thymeleaf-3 spring-vault spring-vertx @@ -1164,8 +1163,6 @@ spring-static-resources spring-swagger-codegen - spring-thymeleaf-3 - spring-vault spring-vertx diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 910af6a1bc..c5d9b33dd1 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-thymeleaf spring-thymeleaf-2 + spring-thymeleaf-3 diff --git a/spring-thymeleaf-3/README.md b/spring-web-modules/spring-thymeleaf-3/README.md similarity index 100% rename from spring-thymeleaf-3/README.md rename to spring-web-modules/spring-thymeleaf-3/README.md diff --git a/spring-thymeleaf-3/pom.xml b/spring-web-modules/spring-thymeleaf-3/pom.xml similarity index 98% rename from spring-thymeleaf-3/pom.xml rename to spring-web-modules/spring-thymeleaf-3/pom.xml index 7c58115d11..6dd1267e8a 100644 --- a/spring-thymeleaf-3/pom.xml +++ b/spring-web-modules/spring-thymeleaf-3/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/Article.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/articles/ArticlesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/conditionalclasses/ConditionalClassesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/currencies/CurrenciesController.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/Student.java diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java similarity index 100% rename from spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java rename to spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/option/StudentController.java diff --git a/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js diff --git a/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css b/spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css similarity index 100% rename from spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css diff --git a/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/articles/articles-list.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/conditionalclasses/conditionalclasses.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/currencies/currencies.html diff --git a/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html similarity index 100% rename from spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html rename to spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/option/studentForm.html diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java b/spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java similarity index 100% rename from spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java rename to spring-web-modules/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/currencies/CurrenciesControllerIntegrationTest.java From 05c7fa926932fae40dc04c6d049775694ea5e033 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:36:14 +0530 Subject: [PATCH 007/149] JAVA-3524: Moved spring-mvc-forms-thymeleaf inside spring-web-modules --- .../spring-mvc-forms-thymeleaf}/README.md | 0 .../spring-mvc-forms-thymeleaf}/pom.xml | 2 +- .../src/main/java/com/baeldung/listbindingexample/Book.java | 0 .../main/java/com/baeldung/listbindingexample/BookService.java | 0 .../java/com/baeldung/listbindingexample/BooksCreationDto.java | 0 .../src/main/java/com/baeldung/listbindingexample/Config.java | 0 .../com/baeldung/listbindingexample/InMemoryBookService.java | 0 .../com/baeldung/listbindingexample/ListBindingApplication.java | 0 .../baeldung/listbindingexample/MultipleBooksController.java | 0 .../src/main/java/com/baeldung/sessionattrs/Config.java | 0 .../java/com/baeldung/sessionattrs/SessionAttrsApplication.java | 0 .../baeldung/sessionattrs/TodoControllerWithScopedProxy.java | 0 .../sessionattrs/TodoControllerWithSessionAttributes.java | 0 .../src/main/java/com/baeldung/sessionattrs/TodoItem.java | 0 .../src/main/java/com/baeldung/sessionattrs/TodoList.java | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-forms-thymeleaf}/src/main/resources/logback.xml | 0 .../src/main/resources/templates/books/allBooks.html | 0 .../src/main/resources/templates/books/createBooksForm.html | 0 .../src/main/resources/templates/books/editBooksForm.html | 0 .../src/main/resources/templates/books/index.html | 0 .../src/main/resources/templates/sessionattrs/index.html | 0 .../main/resources/templates/sessionattrs/scopedproxyform.html | 0 .../main/resources/templates/sessionattrs/scopedproxytodos.html | 0 .../resources/templates/sessionattrs/sessionattributesform.html | 0 .../templates/sessionattrs/sessionattributestodos.html | 0 .../com}/baeldung/listbindingexample/SpringContextTest.java | 0 .../sessionattrs/SessionAttrsApplicationIntegrationTest.java | 0 .../test/java/com}/baeldung/sessionattrs/SpringContextTest.java | 0 .../src/test/java/com/baeldung/sessionattrs/TestConfig.java | 0 .../TodoControllerWithScopedProxyIntegrationTest.java | 0 .../TodoControllerWithSessionAttributesIntegrationTest.java | 0 32 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/README.md (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/pom.xml (96%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/Book.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/BookService.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/Config.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/Config.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoItem.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/java/com/baeldung/sessionattrs/TodoList.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/application.properties (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/logback.xml (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/allBooks.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/createBooksForm.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/editBooksForm.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/books/index.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/index.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/scopedproxyform.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/scopedproxytodos.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/sessionattributesform.html (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/main/resources/templates/sessionattrs/sessionattributestodos.html (100%) rename {spring-mvc-forms-thymeleaf/src/test/java/org => spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com}/baeldung/listbindingexample/SpringContextTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java (100%) rename {spring-mvc-forms-thymeleaf/src/test/java/org => spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com}/baeldung/sessionattrs/SpringContextTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TestConfig.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java (100%) rename {spring-mvc-forms-thymeleaf => spring-web-modules/spring-mvc-forms-thymeleaf}/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java (100%) diff --git a/spring-mvc-forms-thymeleaf/README.md b/spring-web-modules/spring-mvc-forms-thymeleaf/README.md similarity index 100% rename from spring-mvc-forms-thymeleaf/README.md rename to spring-web-modules/spring-mvc-forms-thymeleaf/README.md diff --git a/spring-mvc-forms-thymeleaf/pom.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml similarity index 96% rename from spring-mvc-forms-thymeleaf/pom.xml rename to spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml index 2aed7f70ad..641f64b93c 100644 --- a/spring-mvc-forms-thymeleaf/pom.xml +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/Config.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/SessionAttrsApplication.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxy.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoItem.java diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/application.properties b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/application.properties similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/application.properties diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/logback.xml diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/index.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxyform.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/scopedproxytodos.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributesform.html diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html similarity index 100% rename from spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/main/resources/templates/sessionattrs/sessionattributestodos.html diff --git a/spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/listbindingexample/SpringContextTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/listbindingexample/SpringContextTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/listbindingexample/SpringContextTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/listbindingexample/SpringContextTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SessionAttrsApplicationIntegrationTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/sessionattrs/SpringContextTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SpringContextTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/org/baeldung/sessionattrs/SpringContextTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/SpringContextTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TestConfig.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithScopedProxyIntegrationTest.java diff --git a/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java similarity index 100% rename from spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java rename to spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributesIntegrationTest.java From bcfbe6102ca657416983f90559194089eddc1412 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:37:05 +0530 Subject: [PATCH 008/149] JAVA-3524: Added module to new parent's pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 910af6a1bc..730647d9e2 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-forms-thymeleaf spring-thymeleaf spring-thymeleaf-2 From 1e89df8bcfddb6107f68f76949395c1b22750bec Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 11:38:10 +0530 Subject: [PATCH 009/149] JAVA-3524: removed module spring-mvc-forms-thymeleaf from main pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index f66433c612..7db1c5bc54 100644 --- a/pom.xml +++ b/pom.xml @@ -658,7 +658,6 @@ spring-mobile spring-mockito - spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 @@ -1130,7 +1129,6 @@ spring-mobile spring-mockito - spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-java-2 From 9b1abb07fbafaadcb5151dedb1f7b435eff9841e Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Tue, 29 Dec 2020 11:02:52 +0200 Subject: [PATCH 010/149] BAEL-4472- Binary Semaphore vs a ReentrantLock - Unit test added --- ...inarySemaphoreVsReentrantLockUnitTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java new file mode 100644 index 0000000000..f456e82f39 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.binarysemaphorereentrantlock; + +import static org.junit.Assert.assertEquals; +import java.util.concurrent.Semaphore; +import java.util.concurrent.locks.ReentrantLock; + +import org.junit.Test; + +public class BinarySemaphoreVsReentrantLockUnitTest { + + @Test + public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { + Semaphore binarySemaphore = new Semaphore(1); + try { + binarySemaphore.acquire(); + assertEquals(0, binarySemaphore.availablePermits()); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + binarySemaphore.release(); + assertEquals(1, binarySemaphore.availablePermits()); + } + } + + @Test + public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + + @Test + public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + reentrantLock.lock(); + assertEquals(2, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + +} From d84de4ccdfc9c65bd0de800ea956ff86dbb25ed6 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 29 Dec 2020 14:43:19 +0100 Subject: [PATCH 011/149] JAVA-3533: Move spring-rest-http-2 into spring-web-modules --- pom.xml | 1 - spring-web-modules/pom.xml | 1 + .../spring-rest-http-2}/README.md | 0 .../spring-rest-http-2}/pom.xml | 2 +- .../src/main/java/com/baeldung/SpringBootRest2Application.java | 0 .../com/baeldung/swaggerui/disable/config/SwaggerConfig.java | 0 .../swaggerui/disable/controllers/VersionController.java | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/README.md (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/pom.xml (95%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/SpringBootRest2Application.java (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java (100%) rename {spring-rest-http-2 => spring-web-modules/spring-rest-http-2}/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java (100%) diff --git a/pom.xml b/pom.xml index f8e84c09e1..520343431b 100644 --- a/pom.xml +++ b/pom.xml @@ -673,7 +673,6 @@ spring-reactor spring-remoting spring-rest-angular - spring-rest-http-2 spring-rest-query-language spring-rest-shell spring-rest-simple diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 3dea8fc36e..2b1dfc367a 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,7 @@ spring-mvc-crash spring-mvc-forms-jsp spring-rest-http + spring-rest-http-2 spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 diff --git a/spring-rest-http-2/README.md b/spring-web-modules/spring-rest-http-2/README.md similarity index 100% rename from spring-rest-http-2/README.md rename to spring-web-modules/spring-rest-http-2/README.md diff --git a/spring-rest-http-2/pom.xml b/spring-web-modules/spring-rest-http-2/pom.xml similarity index 95% rename from spring-rest-http-2/pom.xml rename to spring-web-modules/spring-rest-http-2/pom.xml index 8678d7243d..6aa8be365c 100644 --- a/spring-rest-http-2/pom.xml +++ b/spring-web-modules/spring-rest-http-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/SpringBootRest2Application.java diff --git a/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/config/SwaggerConfig.java diff --git a/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java similarity index 100% rename from spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java rename to spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/swaggerui/disable/controllers/VersionController.java From 11dae9ea5a1a1d941a969f843b03a2e817d7e522 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:44:00 +0530 Subject: [PATCH 012/149] JAVA-3526: Moved spring-mvc-java inside spring-web-modules --- .../spring-mvc-java}/.gitignore | 0 .../spring-mvc-java}/README.md | 2 +- .../spring-mvc-java}/persons.xls | Bin .../spring-mvc-java}/persons.xlsx | Bin .../spring-mvc-java}/pom.xml | 2 +- .../java/com/baeldung/SpringMVCApplication.java | 0 .../main/java/com/baeldung/accessparamsjs/App.java | 0 .../com/baeldung/accessparamsjs/Controller.java | 0 .../main/java/com/baeldung/cache/BookService.java | 0 .../java/com/baeldung/cache/CustomKeyGenerator.java | 0 .../java/com/baeldung/excel/ExcelPOIHelper.java | 0 .../src/main/java/com/baeldung/excel/MyCell.java | 0 .../java/com/baeldung/filters/EmptyParamFilter.java | 0 .../java/com/baeldung/listeners/AppListener.java | 0 .../com/baeldung/listeners/RequestListener.java | 0 .../src/main/java/com/baeldung/model/Article.java | 0 .../src/main/java/com/baeldung/model/Book.java | 0 .../java/com/baeldung/model/FormDataWithFile.java | 0 .../src/main/java/com/baeldung/model/Greeting.java | 0 .../src/main/java/com/baeldung/model/User.java | 0 .../java/com/baeldung/servlets/CounterServlet.java | 0 .../com/baeldung/servlets/UppercaseServlet.java | 0 .../spring/web/config/ApplicationCacheConfig.java | 0 .../spring/web/config/MainWebAppInitializer.java | 0 .../com/baeldung/spring/web/config/WebConfig.java | 0 .../src/main/java/com/baeldung/web/BeanA.java | 0 .../src/main/java/com/baeldung/web/BeanB.java | 0 .../baeldung/web/controller/ExcelController.java | 0 .../web/controller/FileUploadController.java | 0 .../baeldung/web/controller/GreetController.java | 0 .../baeldung/web/controller/ImageController.java | 0 .../MultipartFileUploadStubController.java | 0 .../baeldung/web/controller/SampleController.java | 0 .../com/baeldung/web/controller/UserController.java | 0 .../web/controller/message/MessageController.java | 0 .../optionalpathvars/ArticleViewerController.java | 0 .../ArticleViewerWithMapParamController.java | 0 .../ArticleViewerWithOptionalParamController.java | 0 ...rticleViewerWithRequiredAttributeController.java | 0 ...ticleViewerWithTwoSeparateMethodsController.java | 0 .../src/main/resources/annotations.properties | 0 .../src/main/resources/annotations.xml | 0 .../src/main/resources/application.properties | 0 .../spring-mvc-java}/src/main/resources/logback.xml | 0 .../src/main/resources/messages_en.properties | 0 .../src/main/resources/mvc-configuration.xml | 0 .../main/resources/templates/thymeleaf/index.html | 0 .../main/webapp/WEB-INF/images/image-example.jpg | Bin .../src/main/webapp/WEB-INF/jsp/index.jsp | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/templates/footer.html | 0 .../src/main/webapp/WEB-INF/templates/hello.html | 0 .../src/main/webapp/WEB-INF/templates/index.html | 0 .../src/main/webapp/WEB-INF/templates/message.html | 0 .../src/main/webapp/WEB-INF/view/excel.jsp | 0 .../src/main/webapp/WEB-INF/view/fileUploadForm.jsp | 0 .../src/main/webapp/WEB-INF/view/fileUploadView.jsp | 0 .../src/main/webapp/WEB-INF/view/index.jsp | 0 .../src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/web_old.xml | 0 .../spring-mvc-java}/src/main/webapp/js/jquery.js | 0 .../src/main/webapp/js/script-async-jquery.js | 0 .../src/main/webapp/js/script-async.js | 0 .../spring-mvc-java}/src/main/webapp/js/script.js | 0 .../baeldung/accessparamsjs/ControllerUnitTest.java | 0 .../baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java | 0 .../htmlunit/HtmlUnitAndSpringLiveTest.java | 0 .../htmlunit/HtmlUnitWebScrapingLiveTest.java | 0 .../test/java/com/baeldung/htmlunit/TestConfig.java | 0 .../controller/GreetControllerIntegrationTest.java | 0 .../GreetControllerRealIntegrationTest.java | 0 .../web/controller/GreetControllerUnitTest.java | 0 .../test/java/com/baeldung/web/controller/README.md | 0 .../ArticleViewerControllerIntegrationTest.java | 0 ...rControllerWithOptionalParamIntegrationTest.java | 0 ...trollerWithRequiredAttributeIntegrationTest.java | 0 .../ArticleViewerWithMapParamIntegrationTest.java | 0 ...ViewerWithTwoSeparateMethodsIntegrationTest.java | 0 .../spring-mvc-java}/src/test/resources/.gitignore | 0 .../src/test/resources/logback-test.xml | 0 80 files changed, 2 insertions(+), 2 deletions(-) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/.gitignore (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/README.md (92%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/persons.xls (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/persons.xlsx (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/pom.xml (99%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/SpringMVCApplication.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/accessparamsjs/App.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/accessparamsjs/Controller.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/cache/BookService.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/cache/CustomKeyGenerator.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/excel/ExcelPOIHelper.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/excel/MyCell.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/filters/EmptyParamFilter.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/listeners/AppListener.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/listeners/RequestListener.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Article.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Book.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/FormDataWithFile.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/Greeting.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/model/User.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/servlets/CounterServlet.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/servlets/UppercaseServlet.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/spring/web/config/WebConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/BeanA.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/BeanB.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/ExcelController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/FileUploadController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/GreetController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/ImageController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/SampleController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/UserController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/message/MessageController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/annotations.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/annotations.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/application.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/logback.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/messages_en.properties (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/mvc-configuration.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/resources/templates/thymeleaf/index.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/images/image-example.jpg (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/jsp/index.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/footer.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/hello.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/index.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/templates/message.html (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/excel.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/fileUploadForm.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/fileUploadView.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/index.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/WEB-INF/web_old.xml (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/jquery.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script-async-jquery.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script-async.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/main/webapp/js/script.js (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/htmlunit/TestConfig.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/README.md (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/resources/.gitignore (100%) rename {spring-mvc-java => spring-web-modules/spring-mvc-java}/src/test/resources/logback-test.xml (100%) diff --git a/spring-mvc-java/.gitignore b/spring-web-modules/spring-mvc-java/.gitignore similarity index 100% rename from spring-mvc-java/.gitignore rename to spring-web-modules/spring-mvc-java/.gitignore diff --git a/spring-mvc-java/README.md b/spring-web-modules/spring-mvc-java/README.md similarity index 92% rename from spring-mvc-java/README.md rename to spring-web-modules/spring-mvc-java/README.md index 877d92901a..afd1aea3bf 100644 --- a/spring-mvc-java/README.md +++ b/spring-web-modules/spring-mvc-java/README.md @@ -4,7 +4,7 @@ This module contains articles about Spring MVC with Java configuration ### The Course -The "REST With Spring" Classes: http://bit.ly/restwithspring +The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring) diff --git a/spring-mvc-java/persons.xls b/spring-web-modules/spring-mvc-java/persons.xls similarity index 100% rename from spring-mvc-java/persons.xls rename to spring-web-modules/spring-mvc-java/persons.xls diff --git a/spring-mvc-java/persons.xlsx b/spring-web-modules/spring-mvc-java/persons.xlsx similarity index 100% rename from spring-mvc-java/persons.xlsx rename to spring-web-modules/spring-mvc-java/persons.xlsx diff --git a/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml similarity index 99% rename from spring-mvc-java/pom.xml rename to spring-web-modules/spring-mvc-java/pom.xml index a45e9c8521..179ac0fb54 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/App.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/accessparamsjs/Controller.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Article.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Article.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Article.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Article.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Book.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Book.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Book.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Book.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/FormDataWithFile.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/Greeting.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/User.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/User.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/model/User.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/model/User.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/FileUploadController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/GreetController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ImageController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/MultipartFileUploadStubController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/UserController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/message/MessageController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithOptionalParamController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithRequiredAttributeController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java similarity index 100% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java diff --git a/spring-mvc-java/src/main/resources/annotations.properties b/spring-web-modules/spring-mvc-java/src/main/resources/annotations.properties similarity index 100% rename from spring-mvc-java/src/main/resources/annotations.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/annotations.properties diff --git a/spring-mvc-java/src/main/resources/annotations.xml b/spring-web-modules/spring-mvc-java/src/main/resources/annotations.xml similarity index 100% rename from spring-mvc-java/src/main/resources/annotations.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/annotations.xml diff --git a/spring-mvc-java/src/main/resources/application.properties b/spring-web-modules/spring-mvc-java/src/main/resources/application.properties similarity index 100% rename from spring-mvc-java/src/main/resources/application.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/application.properties diff --git a/spring-mvc-java/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-java/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-java/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/logback.xml diff --git a/spring-mvc-java/src/main/resources/messages_en.properties b/spring-web-modules/spring-mvc-java/src/main/resources/messages_en.properties similarity index 100% rename from spring-mvc-java/src/main/resources/messages_en.properties rename to spring-web-modules/spring-mvc-java/src/main/resources/messages_en.properties diff --git a/spring-mvc-java/src/main/resources/mvc-configuration.xml b/spring-web-modules/spring-mvc-java/src/main/resources/mvc-configuration.xml similarity index 100% rename from spring-mvc-java/src/main/resources/mvc-configuration.xml rename to spring-web-modules/spring-mvc-java/src/main/resources/mvc-configuration.xml diff --git a/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html b/spring-web-modules/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html similarity index 100% rename from spring-mvc-java/src/main/resources/templates/thymeleaf/index.html rename to spring-web-modules/spring-mvc-java/src/main/resources/templates/thymeleaf/index.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/images/image-example.jpg diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/footer.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/hello.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/index.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/templates/message.html diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/excel.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadForm.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/fileUploadView.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/index.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml b/spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml rename to spring-web-modules/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml diff --git a/spring-mvc-java/src/main/webapp/js/jquery.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/jquery.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/jquery.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/jquery.js diff --git a/spring-mvc-java/src/main/webapp/js/script-async-jquery.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async-jquery.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script-async-jquery.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async-jquery.js diff --git a/spring-mvc-java/src/main/webapp/js/script-async.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script-async.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script-async.js diff --git a/spring-mvc-java/src/main/webapp/js/script.js b/spring-web-modules/spring-mvc-java/src/main/webapp/js/script.js similarity index 100% rename from spring-mvc-java/src/main/webapp/js/script.js rename to spring-web-modules/spring-mvc-java/src/main/webapp/js/script.js diff --git a/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerUnitTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java similarity index 100% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java rename to spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java diff --git a/spring-mvc-java/src/test/resources/.gitignore b/spring-web-modules/spring-mvc-java/src/test/resources/.gitignore similarity index 100% rename from spring-mvc-java/src/test/resources/.gitignore rename to spring-web-modules/spring-mvc-java/src/test/resources/.gitignore diff --git a/spring-mvc-java/src/test/resources/logback-test.xml b/spring-web-modules/spring-mvc-java/src/test/resources/logback-test.xml similarity index 100% rename from spring-mvc-java/src/test/resources/logback-test.xml rename to spring-web-modules/spring-mvc-java/src/test/resources/logback-test.xml From 81b21f361c772f7cddf2460b80409a405ea25aac Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:44:51 +0530 Subject: [PATCH 013/149] JAVA-3525: Moved spring-mvc-java-2 inside spring-web-modules --- .../spring-mvc-java-2}/.gitignore | 0 .../spring-mvc-java-2}/README.md | 0 .../spring-mvc-java-2}/pom.xml | 2 +- .../main/java/com/baeldung/cache/CacheControlController.java | 0 .../src/main/java/com/baeldung/cache/CacheWebConfig.java | 0 .../src/main/java/com/baeldung/datetime/DateTimeConfig.java | 0 .../src/main/java/com/baeldung/datetime/DateTimeController.java | 0 .../main/java/com/baeldung/matrix/config/MatrixWebConfig.java | 0 .../java/com/baeldung/matrix/controller/CompanyController.java | 0 .../java/com/baeldung/matrix/controller/EmployeeController.java | 0 .../src/main/java/com/baeldung/matrix/model/Company.java | 0 .../src/main/java/com/baeldung/matrix/model/Employee.java | 0 .../multiparttesting/MultipartPostRequestController.java | 0 .../CustomWebMvcConfigurationSupport.java | 0 .../com/baeldung/pathvariable.dottruncated/SiteController.java | 0 .../baeldung/pathvariable/PathVariableAnnotationController.java | 0 .../spring-mvc-java-2}/src/main/resources/targetFile.tmp | 0 .../spring-mvc-java-2}/src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/companyHome.jsp | 0 .../src/main/webapp/WEB-INF/view/companyView.jsp | 0 .../src/main/webapp/WEB-INF/view/employeeHome.jsp | 0 .../src/main/webapp/WEB-INF/view/employeeView.jsp | 0 .../spring-mvc-java-2}/src/main/webapp/WEB-INF/web.xml | 0 .../spring-mvc-java-2}/src/main/webapp/resources/hello.css | 0 .../baeldung/cache/CacheControlControllerIntegrationTest.java | 0 .../java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java | 0 .../java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java | 0 .../baeldung/multipart/file/ConvertMultipartFileUnitTest.java | 0 .../MultipartPostRequestControllerUnitTest.java | 0 29 files changed, 1 insertion(+), 1 deletion(-) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/.gitignore (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/README.md (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/pom.xml (97%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/cache/CacheControlController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/cache/CacheWebConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/datetime/DateTimeConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/datetime/DateTimeController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/controller/CompanyController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/controller/EmployeeController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/model/Company.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/matrix/model/Employee.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/resources/targetFile.tmp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/companyHome.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/companyView.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/employeeHome.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/view/employeeView.jsp (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/main/webapp/resources/hello.css (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java (100%) rename {spring-mvc-java-2 => spring-web-modules/spring-mvc-java-2}/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java (100%) diff --git a/spring-mvc-java-2/.gitignore b/spring-web-modules/spring-mvc-java-2/.gitignore similarity index 100% rename from spring-mvc-java-2/.gitignore rename to spring-web-modules/spring-mvc-java-2/.gitignore diff --git a/spring-mvc-java-2/README.md b/spring-web-modules/spring-mvc-java-2/README.md similarity index 100% rename from spring-mvc-java-2/README.md rename to spring-web-modules/spring-mvc-java-2/README.md diff --git a/spring-mvc-java-2/pom.xml b/spring-web-modules/spring-mvc-java-2/pom.xml similarity index 97% rename from spring-mvc-java-2/pom.xml rename to spring-web-modules/spring-mvc-java-2/pom.xml index 533a24771a..8a025defac 100644 --- a/spring-mvc-java-2/pom.xml +++ b/spring-web-modules/spring-mvc-java-2/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/config/MatrixWebConfig.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/CompanyController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/controller/EmployeeController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Company.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/matrix/model/Employee.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/multiparttesting/MultipartPostRequestController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/CustomWebMvcConfigurationSupport.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable.dottruncated/SiteController.java diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java similarity index 100% rename from spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java diff --git a/spring-mvc-java-2/src/main/resources/targetFile.tmp b/spring-web-modules/spring-mvc-java-2/src/main/resources/targetFile.tmp similarity index 100% rename from spring-mvc-java-2/src/main/resources/targetFile.tmp rename to spring-web-modules/spring-mvc-java-2/src/main/resources/targetFile.tmp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyHome.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/companyView.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeHome.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/view/employeeView.jsp diff --git a/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-java-2/src/main/webapp/resources/hello.css b/spring-web-modules/spring-mvc-java-2/src/main/webapp/resources/hello.css similarity index 100% rename from spring-mvc-java-2/src/main/webapp/resources/hello.css rename to spring-web-modules/spring-mvc-java-2/src/main/webapp/resources/hello.css diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeMvcIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/matrix/EmployeeNoMvcIntegrationTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multipart/file/ConvertMultipartFileUnitTest.java diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java similarity index 100% rename from spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java From 824fd5496f94c2bae686ec94c183a043cb64481e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:46:11 +0530 Subject: [PATCH 014/149] Added module to new parent's pom --- spring-web-modules/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 730647d9e2..b41033bc30 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -21,6 +21,8 @@ spring-mvc-crash spring-mvc-forms-jsp spring-mvc-forms-thymeleaf + spring-mvc-java + spring-mvc-java-2 spring-thymeleaf spring-thymeleaf-2 From 4eec2e35a290fe470351cc733d4718ccdd2b0590 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 29 Dec 2020 23:46:47 +0530 Subject: [PATCH 015/149] Removed modules from main pom --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7db1c5bc54..e6cb9fd686 100644 --- a/pom.xml +++ b/pom.xml @@ -658,9 +658,6 @@ spring-mobile spring-mockito - spring-mvc-java - spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow @@ -1129,9 +1126,6 @@ spring-mobile spring-mockito - spring-mvc-java - spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow From c99f74a6a1b316a15bc68bfb4477afdf829ba4bd Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 12:14:14 +0100 Subject: [PATCH 016/149] JAVA-3535 Move spring rest query language module --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-rest-query-language}/.gitignore | 0 .../spring-rest-query-language}/README.md | 0 .../spring-rest-query-language}/pom.xml | 2 +- .../dao/GenericSpecificationsBuilder.java | 200 +++++----- .../baeldung/persistence/dao/IUserDAO.java | 0 .../persistence/dao/MyUserPredicate.java | 0 .../dao/MyUserPredicatesBuilder.java | 0 .../persistence/dao/MyUserRepository.java | 0 .../com/baeldung/persistence/dao/UserDAO.java | 0 .../persistence/dao/UserRepository.java | 0 .../dao/UserSearchQueryCriteriaConsumer.java | 0 .../persistence/dao/UserSpecification.java | 0 .../dao/UserSpecificationsBuilder.java | 140 +++---- .../dao/rsql/CustomRsqlVisitor.java | 0 .../dao/rsql/GenericRsqlSpecBuilder.java | 0 .../dao/rsql/GenericRsqlSpecification.java | 0 .../dao/rsql/RsqlSearchOperation.java | 0 .../baeldung/persistence/model/MyUser.java | 0 .../com/baeldung/persistence/model/User.java | 0 .../com/baeldung/persistence/model/User_.java | 0 .../java/com/baeldung/spring/Application.java | 0 .../baeldung/spring/PersistenceConfig.java | 0 .../java/com/baeldung/spring/WebConfig.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/UserController.java | 342 ++++++++--------- .../RestResponseEntityExceptionHandler.java | 0 .../MyResourceNotFoundException.java | 0 .../com/baeldung/web/util/CriteriaParser.java | 0 .../com/baeldung/web/util/SearchCriteria.java | 0 .../baeldung/web/util/SearchOperation.java | 72 ++-- .../baeldung/web/util/SpecSearchCriteria.java | 164 ++++---- .../src/main/resources/application.properties | 0 .../src/main/resources/data.sql | 0 .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../JPACriteriaQueryIntegrationTest.java | 0 .../query/JPAQuerydslIntegrationTest.java | 0 .../JPASpecificationIntegrationTest.java | 360 +++++++++--------- .../query/JPASpecificationLiveTest.java | 294 +++++++------- .../query/RsqlIntegrationTest.java | 0 .../java/com/baeldung/web/MyUserLiveTest.java | 0 .../src/test/resources/.gitignore | 0 50 files changed, 788 insertions(+), 789 deletions(-) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/.gitignore (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/README.md (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/pom.xml (99%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/IUserDAO.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserDAO.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserRepository.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSpecification.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/MyUser.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/persistence/model/User_.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/spring/WebConfig.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/controller/HomeController.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/controller/UserController.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/CriteriaParser.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SearchCriteria.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SearchOperation.java (96%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java (96%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/application.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/data.sql (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/logback.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/persistence-h2.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/persistence-mysql.properties (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java (97%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/java/com/baeldung/web/MyUserLiveTest.java (100%) rename {spring-rest-query-language => spring-web-modules/spring-rest-query-language}/src/test/resources/.gitignore (100%) diff --git a/pom.xml b/pom.xml index 79bf7d72b7..88b0a4e23d 100644 --- a/pom.xml +++ b/pom.xml @@ -674,7 +674,6 @@ spring-reactor spring-remoting spring-rest-http-2 - spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate @@ -1141,7 +1140,6 @@ spring-reactor spring-remoting - spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index ce0524f957..19ec1c2a74 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-rest-angular spring-rest-http + spring-rest-query-language spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-query-language/.gitignore b/spring-web-modules/spring-rest-query-language/.gitignore similarity index 100% rename from spring-rest-query-language/.gitignore rename to spring-web-modules/spring-rest-query-language/.gitignore diff --git a/spring-rest-query-language/README.md b/spring-web-modules/spring-rest-query-language/README.md similarity index 100% rename from spring-rest-query-language/README.md rename to spring-web-modules/spring-rest-query-language/README.md diff --git a/spring-rest-query-language/pom.xml b/spring-web-modules/spring-rest-query-language/pom.xml similarity index 99% rename from spring-rest-query-language/pom.xml rename to spring-web-modules/spring-rest-query-language/pom.xml index 4458aa0580..5e7ca023dd 100644 --- a/spring-rest-query-language/pom.xml +++ b/spring-web-modules/spring-rest-query-language/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java index 75fb4456c4..b6623e8885 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/GenericSpecificationsBuilder.java @@ -1,100 +1,100 @@ -package com.baeldung.persistence.dao; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.springframework.data.jpa.domain.Specification; - -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -public class GenericSpecificationsBuilder { - - private final List params; - - public GenericSpecificationsBuilder() { - this.params = new ArrayList<>(); - } - - public final GenericSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { - return with(null, key, operation, value, prefix, suffix); - } - - public final GenericSpecificationsBuilder with(final String precedenceIndicator, final String key, final String operation, final Object value, final String prefix, final String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) // the operation may be complex operation - { - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - params.add(new SpecSearchCriteria(precedenceIndicator, key, op, value)); - } - return this; - } - - public Specification build(Function> converter) { - - if (params.size() == 0) { - return null; - } - - final List> specs = params.stream() - .map(converter) - .collect(Collectors.toCollection(ArrayList::new)); - - Specification result = specs.get(0); - - for (int idx = 1; idx < specs.size(); idx++) { - result = params.get(idx) - .isOrPredicate() - ? Specification.where(result) - .or(specs.get(idx)) - : Specification.where(result) - .and(specs.get(idx)); - } - - return result; - } - - public Specification build(Deque postFixedExprStack, Function> converter) { - - Deque> specStack = new LinkedList<>(); - - Collections.reverse((List) postFixedExprStack); - - while (!postFixedExprStack.isEmpty()) { - Object mayBeOperand = postFixedExprStack.pop(); - - if (!(mayBeOperand instanceof String)) { - specStack.push(converter.apply((SpecSearchCriteria) mayBeOperand)); - } else { - Specification operand1 = specStack.pop(); - Specification operand2 = specStack.pop(); - if (mayBeOperand.equals(SearchOperation.AND_OPERATOR)) - specStack.push(Specification.where(operand1) - .and(operand2)); - else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR)) - specStack.push(Specification.where(operand1) - .or(operand2)); - } - - } - return specStack.pop(); - - } - -} +package com.baeldung.persistence.dao; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.springframework.data.jpa.domain.Specification; + +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +public class GenericSpecificationsBuilder { + + private final List params; + + public GenericSpecificationsBuilder() { + this.params = new ArrayList<>(); + } + + public final GenericSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { + return with(null, key, operation, value, prefix, suffix); + } + + public final GenericSpecificationsBuilder with(final String precedenceIndicator, final String key, final String operation, final Object value, final String prefix, final String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) // the operation may be complex operation + { + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + params.add(new SpecSearchCriteria(precedenceIndicator, key, op, value)); + } + return this; + } + + public Specification build(Function> converter) { + + if (params.size() == 0) { + return null; + } + + final List> specs = params.stream() + .map(converter) + .collect(Collectors.toCollection(ArrayList::new)); + + Specification result = specs.get(0); + + for (int idx = 1; idx < specs.size(); idx++) { + result = params.get(idx) + .isOrPredicate() + ? Specification.where(result) + .or(specs.get(idx)) + : Specification.where(result) + .and(specs.get(idx)); + } + + return result; + } + + public Specification build(Deque postFixedExprStack, Function> converter) { + + Deque> specStack = new LinkedList<>(); + + Collections.reverse((List) postFixedExprStack); + + while (!postFixedExprStack.isEmpty()) { + Object mayBeOperand = postFixedExprStack.pop(); + + if (!(mayBeOperand instanceof String)) { + specStack.push(converter.apply((SpecSearchCriteria) mayBeOperand)); + } else { + Specification operand1 = specStack.pop(); + Specification operand2 = specStack.pop(); + if (mayBeOperand.equals(SearchOperation.AND_OPERATOR)) + specStack.push(Specification.where(operand1) + .and(operand2)); + else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR)) + specStack.push(Specification.where(operand1) + .or(operand2)); + } + + } + return specStack.pop(); + + } + +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/IUserDAO.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicate.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserPredicatesBuilder.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/MyUserRepository.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserDAO.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserRepository.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSearchQueryCriteriaConsumer.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecification.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java index 72d7274226..eac1562294 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/UserSpecificationsBuilder.java @@ -1,70 +1,70 @@ -package com.baeldung.persistence.dao; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.data.jpa.domain.Specification; - -import com.baeldung.persistence.model.User; -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -public final class UserSpecificationsBuilder { - - private final List params; - - public UserSpecificationsBuilder() { - params = new ArrayList<>(); - } - - // API - - public final UserSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { - return with(null, key, operation, value, prefix, suffix); - } - - public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) { // the operation may be complex operation - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - params.add(new SpecSearchCriteria(orPredicate, key, op, value)); - } - return this; - } - - public Specification build() { - if (params.size() == 0) - return null; - - Specification result = new UserSpecification(params.get(0)); - - for (int i = 1; i < params.size(); i++) { - result = params.get(i).isOrPredicate() - ? Specification.where(result).or(new UserSpecification(params.get(i))) - : Specification.where(result).and(new UserSpecification(params.get(i))); - } - - return result; - } - - public final UserSpecificationsBuilder with(UserSpecification spec) { - params.add(spec.getCriteria()); - return this; - } - - public final UserSpecificationsBuilder with(SpecSearchCriteria criteria) { - params.add(criteria); - return this; - } -} +package com.baeldung.persistence.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.data.jpa.domain.Specification; + +import com.baeldung.persistence.model.User; +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +public final class UserSpecificationsBuilder { + + private final List params; + + public UserSpecificationsBuilder() { + params = new ArrayList<>(); + } + + // API + + public final UserSpecificationsBuilder with(final String key, final String operation, final Object value, final String prefix, final String suffix) { + return with(null, key, operation, value, prefix, suffix); + } + + public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) { // the operation may be complex operation + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + params.add(new SpecSearchCriteria(orPredicate, key, op, value)); + } + return this; + } + + public Specification build() { + if (params.size() == 0) + return null; + + Specification result = new UserSpecification(params.get(0)); + + for (int i = 1; i < params.size(); i++) { + result = params.get(i).isOrPredicate() + ? Specification.where(result).or(new UserSpecification(params.get(i))) + : Specification.where(result).and(new UserSpecification(params.get(i))); + } + + return result; + } + + public final UserSpecificationsBuilder with(UserSpecification spec) { + params.add(spec.getCriteria()); + return this; + } + + public final UserSpecificationsBuilder with(SpecSearchCriteria criteria) { + params.add(criteria); + return this; + } +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/dao/rsql/RsqlSearchOperation.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/MyUser.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/persistence/model/User_.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/spring/WebConfig.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/HomeController.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java similarity index 97% rename from spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java index 54e8618b27..73a97f84ae 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/controller/UserController.java @@ -1,171 +1,171 @@ -package com.baeldung.web.controller; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.querydsl.binding.QuerydslPredicate; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -import com.baeldung.persistence.dao.GenericSpecificationsBuilder; -import com.baeldung.persistence.dao.IUserDAO; -import com.baeldung.persistence.dao.MyUserPredicatesBuilder; -import com.baeldung.persistence.dao.MyUserRepository; -import com.baeldung.persistence.dao.UserRepository; -import com.baeldung.persistence.dao.UserSpecification; -import com.baeldung.persistence.dao.UserSpecificationsBuilder; -import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor; -import com.baeldung.persistence.model.MyUser; -import com.baeldung.persistence.model.User; -import com.baeldung.web.util.CriteriaParser; -import com.baeldung.web.util.SearchCriteria; -import com.baeldung.web.util.SearchOperation; -import com.google.common.base.Joiner; -import com.google.common.base.Preconditions; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; - -import cz.jirutka.rsql.parser.RSQLParser; -import cz.jirutka.rsql.parser.ast.Node; - -//@EnableSpringDataWebSupport -@Controller -@RequestMapping(value = "/auth/") -public class UserController { - - @Autowired - private IUserDAO service; - - @Autowired - private UserRepository dao; - - @Autowired - private MyUserRepository myUserRepository; - - public UserController() { - super(); - } - - // API - READ - - @RequestMapping(method = RequestMethod.GET, value = "/users") - @ResponseBody - public List search(@RequestParam(value = "search", required = false) String search) { - List params = new ArrayList(); - if (search != null) { - Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); - } - } - return service.searchUser(params); - } - - @RequestMapping(method = RequestMethod.GET, value = "/users/spec") - @ResponseBody - public List findAllBySpecification(@RequestParam(value = "search") String search) { - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - String operationSetExper = Joiner.on("|") - .join(SearchOperation.SIMPLE_OPERATION_SET); - Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); - } - - Specification spec = builder.build(); - return dao.findAll(spec); - } - - @GetMapping(value = "/users/espec") - @ResponseBody - public List findAllByOrPredicate(@RequestParam(value = "search") String search) { - Specification spec = resolveSpecification(search); - return dao.findAll(spec); - } - - @GetMapping(value = "/users/spec/adv") - @ResponseBody - public List findAllByAdvPredicate(@RequestParam(value = "search") String search) { - Specification spec = resolveSpecificationFromInfixExpr(search); - return dao.findAll(spec); - } - - protected Specification resolveSpecificationFromInfixExpr(String searchParameters) { - CriteriaParser parser = new CriteriaParser(); - GenericSpecificationsBuilder specBuilder = new GenericSpecificationsBuilder<>(); - return specBuilder.build(parser.parse(searchParameters), UserSpecification::new); - } - - protected Specification resolveSpecification(String searchParameters) { - - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - String operationSetExper = Joiner.on("|") - .join(SearchOperation.SIMPLE_OPERATION_SET); - Pattern pattern = Pattern.compile("(\\p{Punct}?)(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); - Matcher matcher = pattern.matcher(searchParameters + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(5), matcher.group(4), matcher.group(6)); - } - return builder.build(); - } - - @RequestMapping(method = RequestMethod.GET, value = "/myusers") - @ResponseBody - public Iterable findAllByQuerydsl(@RequestParam(value = "search") String search) { - MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); - if (search != null) { - Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); - } - } - BooleanExpression exp = builder.build(); - return myUserRepository.findAll(exp); - } - - @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") - @ResponseBody - public List findAllByRsql(@RequestParam(value = "search") String search) { - Node rootNode = new RSQLParser().parse(search); - Specification spec = rootNode.accept(new CustomRsqlVisitor()); - return dao.findAll(spec); - } - - @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") - @ResponseBody - public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) { - return myUserRepository.findAll(predicate); - } - - // API - WRITE - - @RequestMapping(method = RequestMethod.POST, value = "/users") - @ResponseStatus(HttpStatus.CREATED) - public void create(@RequestBody User resource) { - Preconditions.checkNotNull(resource); - dao.save(resource); - } - - @RequestMapping(method = RequestMethod.POST, value = "/myusers") - @ResponseStatus(HttpStatus.CREATED) - public void addMyUser(@RequestBody MyUser resource) { - Preconditions.checkNotNull(resource); - myUserRepository.save(resource); - - } - -} +package com.baeldung.web.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.querydsl.binding.QuerydslPredicate; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import com.baeldung.persistence.dao.GenericSpecificationsBuilder; +import com.baeldung.persistence.dao.IUserDAO; +import com.baeldung.persistence.dao.MyUserPredicatesBuilder; +import com.baeldung.persistence.dao.MyUserRepository; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.dao.UserSpecification; +import com.baeldung.persistence.dao.UserSpecificationsBuilder; +import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor; +import com.baeldung.persistence.model.MyUser; +import com.baeldung.persistence.model.User; +import com.baeldung.web.util.CriteriaParser; +import com.baeldung.web.util.SearchCriteria; +import com.baeldung.web.util.SearchOperation; +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.BooleanExpression; + +import cz.jirutka.rsql.parser.RSQLParser; +import cz.jirutka.rsql.parser.ast.Node; + +//@EnableSpringDataWebSupport +@Controller +@RequestMapping(value = "/auth/") +public class UserController { + + @Autowired + private IUserDAO service; + + @Autowired + private UserRepository dao; + + @Autowired + private MyUserRepository myUserRepository; + + public UserController() { + super(); + } + + // API - READ + + @RequestMapping(method = RequestMethod.GET, value = "/users") + @ResponseBody + public List search(@RequestParam(value = "search", required = false) String search) { + List params = new ArrayList(); + if (search != null) { + Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); + } + } + return service.searchUser(params); + } + + @RequestMapping(method = RequestMethod.GET, value = "/users/spec") + @ResponseBody + public List findAllBySpecification(@RequestParam(value = "search") String search) { + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + String operationSetExper = Joiner.on("|") + .join(SearchOperation.SIMPLE_OPERATION_SET); + Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); + } + + Specification spec = builder.build(); + return dao.findAll(spec); + } + + @GetMapping(value = "/users/espec") + @ResponseBody + public List findAllByOrPredicate(@RequestParam(value = "search") String search) { + Specification spec = resolveSpecification(search); + return dao.findAll(spec); + } + + @GetMapping(value = "/users/spec/adv") + @ResponseBody + public List findAllByAdvPredicate(@RequestParam(value = "search") String search) { + Specification spec = resolveSpecificationFromInfixExpr(search); + return dao.findAll(spec); + } + + protected Specification resolveSpecificationFromInfixExpr(String searchParameters) { + CriteriaParser parser = new CriteriaParser(); + GenericSpecificationsBuilder specBuilder = new GenericSpecificationsBuilder<>(); + return specBuilder.build(parser.parse(searchParameters), UserSpecification::new); + } + + protected Specification resolveSpecification(String searchParameters) { + + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + String operationSetExper = Joiner.on("|") + .join(SearchOperation.SIMPLE_OPERATION_SET); + Pattern pattern = Pattern.compile("(\\p{Punct}?)(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); + Matcher matcher = pattern.matcher(searchParameters + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(5), matcher.group(4), matcher.group(6)); + } + return builder.build(); + } + + @RequestMapping(method = RequestMethod.GET, value = "/myusers") + @ResponseBody + public Iterable findAllByQuerydsl(@RequestParam(value = "search") String search) { + MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); + if (search != null) { + Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); + } + } + BooleanExpression exp = builder.build(); + return myUserRepository.findAll(exp); + } + + @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") + @ResponseBody + public List findAllByRsql(@RequestParam(value = "search") String search) { + Node rootNode = new RSQLParser().parse(search); + Specification spec = rootNode.accept(new CustomRsqlVisitor()); + return dao.findAll(spec); + } + + @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") + @ResponseBody + public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) { + return myUserRepository.findAll(predicate); + } + + // API - WRITE + + @RequestMapping(method = RequestMethod.POST, value = "/users") + @ResponseStatus(HttpStatus.CREATED) + public void create(@RequestBody User resource) { + Preconditions.checkNotNull(resource); + dao.save(resource); + } + + @RequestMapping(method = RequestMethod.POST, value = "/myusers") + @ResponseStatus(HttpStatus.CREATED) + public void addMyUser(@RequestBody MyUser resource) { + Preconditions.checkNotNull(resource); + myUserRepository.save(resource); + + } + +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/CriteriaParser.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java similarity index 100% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchCriteria.java diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java similarity index 96% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java index acc9e0c0a8..86ad9ad749 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SearchOperation.java @@ -1,36 +1,36 @@ -package com.baeldung.web.util; - -public enum SearchOperation { - EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS; - - public static final String[] SIMPLE_OPERATION_SET = { ":", "!", ">", "<", "~" }; - - public static final String OR_PREDICATE_FLAG = "'"; - - public static final String ZERO_OR_MORE_REGEX = "*"; - - public static final String OR_OPERATOR = "OR"; - - public static final String AND_OPERATOR = "AND"; - - public static final String LEFT_PARANTHESIS = "("; - - public static final String RIGHT_PARANTHESIS = ")"; - - public static SearchOperation getSimpleOperation(final char input) { - switch (input) { - case ':': - return EQUALITY; - case '!': - return NEGATION; - case '>': - return GREATER_THAN; - case '<': - return LESS_THAN; - case '~': - return LIKE; - default: - return null; - } - } -} +package com.baeldung.web.util; + +public enum SearchOperation { + EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS; + + public static final String[] SIMPLE_OPERATION_SET = { ":", "!", ">", "<", "~" }; + + public static final String OR_PREDICATE_FLAG = "'"; + + public static final String ZERO_OR_MORE_REGEX = "*"; + + public static final String OR_OPERATOR = "OR"; + + public static final String AND_OPERATOR = "AND"; + + public static final String LEFT_PARANTHESIS = "("; + + public static final String RIGHT_PARANTHESIS = ")"; + + public static SearchOperation getSimpleOperation(final char input) { + switch (input) { + case ':': + return EQUALITY; + case '!': + return NEGATION; + case '>': + return GREATER_THAN; + case '<': + return LESS_THAN; + case '~': + return LIKE; + default: + return null; + } + } +} diff --git a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java similarity index 96% rename from spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java rename to spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java index 73b690673b..22b55c78fb 100644 --- a/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java +++ b/spring-web-modules/spring-rest-query-language/src/main/java/com/baeldung/web/util/SpecSearchCriteria.java @@ -1,82 +1,82 @@ -package com.baeldung.web.util; - -public class SpecSearchCriteria { - - private String key; - private SearchOperation operation; - private Object value; - private boolean orPredicate; - - public SpecSearchCriteria() { - - } - - public SpecSearchCriteria(final String key, final SearchOperation operation, final Object value) { - super(); - this.key = key; - this.operation = operation; - this.value = value; - } - - public SpecSearchCriteria(final String orPredicate, final String key, final SearchOperation operation, final Object value) { - super(); - this.orPredicate = orPredicate != null && orPredicate.equals(SearchOperation.OR_PREDICATE_FLAG); - this.key = key; - this.operation = operation; - this.value = value; - } - - public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); - if (op != null) { - if (op == SearchOperation.EQUALITY) { // the operation may be complex operation - final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); - - if (startWithAsterisk && endWithAsterisk) { - op = SearchOperation.CONTAINS; - } else if (startWithAsterisk) { - op = SearchOperation.ENDS_WITH; - } else if (endWithAsterisk) { - op = SearchOperation.STARTS_WITH; - } - } - } - this.key = key; - this.operation = op; - this.value = value; - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public SearchOperation getOperation() { - return operation; - } - - public void setOperation(final SearchOperation operation) { - this.operation = operation; - } - - public Object getValue() { - return value; - } - - public void setValue(final Object value) { - this.value = value; - } - - public boolean isOrPredicate() { - return orPredicate; - } - - public void setOrPredicate(boolean orPredicate) { - this.orPredicate = orPredicate; - } - -} +package com.baeldung.web.util; + +public class SpecSearchCriteria { + + private String key; + private SearchOperation operation; + private Object value; + private boolean orPredicate; + + public SpecSearchCriteria() { + + } + + public SpecSearchCriteria(final String key, final SearchOperation operation, final Object value) { + super(); + this.key = key; + this.operation = operation; + this.value = value; + } + + public SpecSearchCriteria(final String orPredicate, final String key, final SearchOperation operation, final Object value) { + super(); + this.orPredicate = orPredicate != null && orPredicate.equals(SearchOperation.OR_PREDICATE_FLAG); + this.key = key; + this.operation = operation; + this.value = value; + } + + public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) { + SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + if (op != null) { + if (op == SearchOperation.EQUALITY) { // the operation may be complex operation + final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX); + + if (startWithAsterisk && endWithAsterisk) { + op = SearchOperation.CONTAINS; + } else if (startWithAsterisk) { + op = SearchOperation.ENDS_WITH; + } else if (endWithAsterisk) { + op = SearchOperation.STARTS_WITH; + } + } + } + this.key = key; + this.operation = op; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public SearchOperation getOperation() { + return operation; + } + + public void setOperation(final SearchOperation operation) { + this.operation = operation; + } + + public Object getValue() { + return value; + } + + public void setValue(final Object value) { + this.value = value; + } + + public boolean isOrPredicate() { + return orPredicate; + } + + public void setOrPredicate(boolean orPredicate) { + this.orPredicate = orPredicate; + } + +} diff --git a/spring-rest-query-language/src/main/resources/application.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/application.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/application.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/application.properties diff --git a/spring-rest-query-language/src/main/resources/data.sql b/spring-web-modules/spring-rest-query-language/src/main/resources/data.sql similarity index 100% rename from spring-rest-query-language/src/main/resources/data.sql rename to spring-web-modules/spring-rest-query-language/src/main/resources/data.sql diff --git a/spring-rest-query-language/src/main/resources/logback.xml b/spring-web-modules/spring-rest-query-language/src/main/resources/logback.xml similarity index 100% rename from spring-rest-query-language/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-query-language/src/main/resources/logback.xml diff --git a/spring-rest-query-language/src/main/resources/persistence-h2.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/persistence-h2.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/persistence-h2.properties diff --git a/spring-rest-query-language/src/main/resources/persistence-mysql.properties b/spring-web-modules/spring-rest-query-language/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-rest-query-language/src/main/resources/persistence-mysql.properties rename to spring-web-modules/spring-rest-query-language/src/main/resources/persistence-mysql.properties diff --git a/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml b/spring-web-modules/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml rename to spring-web-modules/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-query-language/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPAQuerydslIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java similarity index 97% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java index 707426769e..f6fff10506 100644 --- a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java +++ b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationIntegrationTest.java @@ -1,180 +1,180 @@ -package com.baeldung.persistence.query; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.persistence.dao.GenericSpecificationsBuilder; -import com.baeldung.persistence.dao.UserRepository; -import com.baeldung.persistence.dao.UserSpecification; -import com.baeldung.persistence.dao.UserSpecificationsBuilder; -import com.baeldung.persistence.model.User; -import com.baeldung.spring.PersistenceConfig; -import com.baeldung.web.util.CriteriaParser; -import com.baeldung.web.util.SearchOperation; -import com.baeldung.web.util.SpecSearchCriteria; - -import java.util.List; -import java.util.function.Function; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIn.isIn; -import static org.hamcrest.core.IsNot.not; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { PersistenceConfig.class }) -@Transactional -@Rollback -public class JPASpecificationIntegrationTest { - - @Autowired - private UserRepository repository; - - private User userJohn; - - private User userTom; - - private User userPercy; - - @Before - public void init() { - userJohn = new User(); - userJohn.setFirstName("john"); - userJohn.setLastName("doe"); - userJohn.setEmail("john@doe.com"); - userJohn.setAge(22); - repository.save(userJohn); - - userTom = new User(); - userTom.setFirstName("tom"); - userTom.setLastName("doe"); - userTom.setEmail("tom@doe.com"); - userTom.setAge(26); - repository.save(userTom); - - userPercy = new User(); - userPercy.setFirstName("percy"); - userPercy.setLastName("blackney"); - userPercy.setEmail("percy@blackney.com"); - userPercy.setAge(30); - repository.save(userPercy); - } - - @Test - public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john")); - final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe")); - final List results = repository.findAll(Specification - .where(spec) - .and(spec1)); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { - UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - - SpecSearchCriteria spec = new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"); - SpecSearchCriteria spec1 = new SpecSearchCriteria("'","lastName", SearchOperation.EQUALITY, "doe"); - - List results = repository.findAll(builder - .with(spec) - .with(spec1) - .build()); - - assertThat(results, hasSize(2)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, isIn(results)); - } - - @Test - public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() { - GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); - Function> converter = UserSpecification::new; - - CriteriaParser parser=new CriteriaParser(); - List results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter)); - - assertThat(results, hasSize(1)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstOrLastNameGenericBuilder_whenGettingListOfUsers_thenCorrect() { - GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); - Function> converter = UserSpecification::new; - - builder.with("firstName", ":", "john", null, null); - builder.with("'", "lastName", ":", "doe", null, null); - - List results = repository.findAll(builder.build(converter)); - - assertThat(results, hasSize(2)); - assertThat(userJohn, isIn(results)); - assertThat(userTom, isIn(results)); - } - - @Test - public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john")); - final List results = repository.findAll(Specification.where(spec)); - - assertThat(userTom, isIn(results)); - assertThat(userJohn, not(isIn(results))); - } - - @Test - public void givenMinAge_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25")); - final List results = repository.findAll(Specification.where(spec)); - assertThat(userTom, isIn(results)); - assertThat(userJohn, not(isIn(results))); - } - - @Test - public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo")); - final List results = repository.findAll(spec); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.ENDS_WITH, "n")); - final List results = repository.findAll(spec); - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.CONTAINS, "oh")); - final List results = repository.findAll(spec); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } - - @Test - public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20")); - final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25")); - final List results = repository.findAll(Specification - .where(spec) - .and(spec1)); - - assertThat(userJohn, isIn(results)); - assertThat(userTom, not(isIn(results))); - } -} +package com.baeldung.persistence.query; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.persistence.dao.GenericSpecificationsBuilder; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.dao.UserSpecification; +import com.baeldung.persistence.dao.UserSpecificationsBuilder; +import com.baeldung.persistence.model.User; +import com.baeldung.spring.PersistenceConfig; +import com.baeldung.web.util.CriteriaParser; +import com.baeldung.web.util.SearchOperation; +import com.baeldung.web.util.SpecSearchCriteria; + +import java.util.List; +import java.util.function.Function; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.hamcrest.collection.IsIn.isIn; +import static org.hamcrest.core.IsNot.not; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }) +@Transactional +@Rollback +public class JPASpecificationIntegrationTest { + + @Autowired + private UserRepository repository; + + private User userJohn; + + private User userTom; + + private User userPercy; + + @Before + public void init() { + userJohn = new User(); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); + userJohn.setEmail("john@doe.com"); + userJohn.setAge(22); + repository.save(userJohn); + + userTom = new User(); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); + userTom.setEmail("tom@doe.com"); + userTom.setAge(26); + repository.save(userTom); + + userPercy = new User(); + userPercy.setFirstName("percy"); + userPercy.setLastName("blackney"); + userPercy.setEmail("percy@blackney.com"); + userPercy.setAge(30); + repository.save(userPercy); + } + + @Test + public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john")); + final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe")); + final List results = repository.findAll(Specification + .where(spec) + .and(spec1)); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { + UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + + SpecSearchCriteria spec = new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"); + SpecSearchCriteria spec1 = new SpecSearchCriteria("'","lastName", SearchOperation.EQUALITY, "doe"); + + List results = repository.findAll(builder + .with(spec) + .with(spec1) + .build()); + + assertThat(results, hasSize(2)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, isIn(results)); + } + + @Test + public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() { + GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); + Function> converter = UserSpecification::new; + + CriteriaParser parser=new CriteriaParser(); + List results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter)); + + assertThat(results, hasSize(1)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstOrLastNameGenericBuilder_whenGettingListOfUsers_thenCorrect() { + GenericSpecificationsBuilder builder = new GenericSpecificationsBuilder<>(); + Function> converter = UserSpecification::new; + + builder.with("firstName", ":", "john", null, null); + builder.with("'", "lastName", ":", "doe", null, null); + + List results = repository.findAll(builder.build(converter)); + + assertThat(results, hasSize(2)); + assertThat(userJohn, isIn(results)); + assertThat(userTom, isIn(results)); + } + + @Test + public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john")); + final List results = repository.findAll(Specification.where(spec)); + + assertThat(userTom, isIn(results)); + assertThat(userJohn, not(isIn(results))); + } + + @Test + public void givenMinAge_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25")); + final List results = repository.findAll(Specification.where(spec)); + assertThat(userTom, isIn(results)); + assertThat(userJohn, not(isIn(results))); + } + + @Test + public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo")); + final List results = repository.findAll(spec); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.ENDS_WITH, "n")); + final List results = repository.findAll(spec); + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.CONTAINS, "oh")); + final List results = repository.findAll(spec); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } + + @Test + public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20")); + final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25")); + final List results = repository.findAll(Specification + .where(spec) + .and(spec1)); + + assertThat(userJohn, isIn(results)); + assertThat(userTom, not(isIn(results))); + } +} diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java similarity index 97% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java index ad6a4259e7..d1fded3f10 100644 --- a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java +++ b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/JPASpecificationLiveTest.java @@ -1,147 +1,147 @@ -package com.baeldung.persistence.query; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import io.restassured.RestAssured; -import io.restassured.response.Response; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.test.context.ActiveProfiles; - -import com.baeldung.persistence.model.User; - -//@RunWith(SpringJUnit4ClassRunner.class) -//@ContextConfiguration(classes = { ConfigTest.class, -// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) -@ActiveProfiles("test") -public class JPASpecificationLiveTest { - - // @Autowired - // private UserRepository repository; - - private User userJohn; - - private User userTom; - - private final String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec?search="; - - @Before - public void init() { - userJohn = new User(); - userJohn.setFirstName("john"); - userJohn.setLastName("doe"); - userJohn.setEmail("john@doe.com"); - userJohn.setAge(22); - // repository.save(userJohn); - - userTom = new User(); - userTom.setFirstName("tom"); - userTom.setLastName("doe"); - userTom.setEmail("tom@doe.com"); - userTom.setAge(26); - // repository.save(userTom); - } - - private final String EURL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/espec?search="; - - @Test - public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); - final String result = response.body() - .asString(); - assertTrue(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName!john"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userTom.getEmail())); - assertFalse(result.contains(userJohn.getEmail())); - } - - @Test - public void givenMinAge_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "age>25"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userTom.getEmail())); - assertFalse(result.contains(userJohn.getEmail())); - } - - @Test - public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:jo*"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - @Test - public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { - final Response response = RestAssured.get(URL_PREFIX + "age>20,age<25"); - final String result = response.body() - .asString(); - - assertTrue(result.contains(userJohn.getEmail())); - assertFalse(result.contains(userTom.getEmail())); - } - - private final String ADV_URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec/adv?search="; - - @Test - public void givenFirstOrLastName_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = RestAssured.get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); - final String result = response.body() - .asString(); - assertTrue(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - - @Test - public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); - final String result = response.body() - .asString(); - assertFalse(result.contains(userJohn.getEmail())); - assertTrue(result.contains(userTom.getEmail())); - } - -} +package com.baeldung.persistence.query; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import io.restassured.RestAssured; +import io.restassured.response.Response; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.persistence.model.User; + +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration(classes = { ConfigTest.class, +// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +@ActiveProfiles("test") +public class JPASpecificationLiveTest { + + // @Autowired + // private UserRepository repository; + + private User userJohn; + + private User userTom; + + private final String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec?search="; + + @Before + public void init() { + userJohn = new User(); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); + userJohn.setEmail("john@doe.com"); + userJohn.setAge(22); + // repository.save(userJohn); + + userTom = new User(); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); + userTom.setEmail("tom@doe.com"); + userTom.setAge(26); + // repository.save(userTom); + } + + private final String EURL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/espec?search="; + + @Test + public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); + final String result = response.body() + .asString(); + assertTrue(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName!john"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userTom.getEmail())); + assertFalse(result.contains(userJohn.getEmail())); + } + + @Test + public void givenMinAge_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "age>25"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userTom.getEmail())); + assertFalse(result.contains(userJohn.getEmail())); + } + + @Test + public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:jo*"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + @Test + public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { + final Response response = RestAssured.get(URL_PREFIX + "age>20,age<25"); + final String result = response.body() + .asString(); + + assertTrue(result.contains(userJohn.getEmail())); + assertFalse(result.contains(userTom.getEmail())); + } + + private final String ADV_URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec/adv?search="; + + @Test + public void givenFirstOrLastName_whenGettingAdvListOfUsers_thenCorrect() { + final Response response = RestAssured.get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); + final String result = response.body() + .asString(); + assertTrue(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + + @Test + public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { + final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); + final String result = response.body() + .asString(); + assertFalse(result.contains(userJohn.getEmail())); + assertTrue(result.contains(userTom.getEmail())); + } + +} diff --git a/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/persistence/query/RsqlIntegrationTest.java diff --git a/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java b/spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java similarity index 100% rename from spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java rename to spring-web-modules/spring-rest-query-language/src/test/java/com/baeldung/web/MyUserLiveTest.java diff --git a/spring-rest-query-language/src/test/resources/.gitignore b/spring-web-modules/spring-rest-query-language/src/test/resources/.gitignore similarity index 100% rename from spring-rest-query-language/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-query-language/src/test/resources/.gitignore From 6a0313b4db0deecd005308fd39bc2aeb3b91702b Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 12:34:37 +0100 Subject: [PATCH 017/149] JAVA-3528 Move spring-mvc-velocity module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-mvc-velocity}/README.md | 0 .../spring-mvc-velocity}/pom.xml | 2 +- .../com/baeldung/mvc/velocity/controller/MainController.java | 0 .../main/java/com/baeldung/mvc/velocity/domain/Tutorial.java | 0 .../com/baeldung/mvc/velocity/service/ITutorialsService.java | 0 .../com/baeldung/mvc/velocity/service/TutorialsService.java | 0 .../mvc/velocity/spring/config/MainWebAppInitializer.java | 0 .../java/com/baeldung/mvc/velocity/spring/config/WebConfig.java | 0 .../spring-mvc-velocity}/src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/fragments/footer.vm | 0 .../src/main/webapp/WEB-INF/fragments/header.vm | 0 .../src/main/webapp/WEB-INF/layouts/layout.vm | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/spring-context.xml | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/views/index.vm | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/views/list.vm | 0 .../spring-mvc-velocity}/src/main/webapp/WEB-INF/web_old.xml | 0 .../mvc/velocity/test/DataContentControllerIntegrationTest.java | 0 .../java/com/baeldung/mvc/velocity/test/config/TestConfig.java | 0 .../src/test/java/org/baeldung/SpringContextTest.java | 0 .../spring-mvc-velocity}/src/test/resources/mvc-servlet.xml | 0 23 files changed, 2 insertions(+), 3 deletions(-) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/README.md (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/pom.xml (98%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/resources/logback.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/fragments/footer.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/fragments/header.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/layouts/layout.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/spring-context.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/views/index.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/views/list.vm (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/main/webapp/WEB-INF/web_old.xml (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/java/org/baeldung/SpringContextTest.java (100%) rename {spring-mvc-velocity => spring-web-modules/spring-mvc-velocity}/src/test/resources/mvc-servlet.xml (100%) diff --git a/pom.xml b/pom.xml index 79bf7d72b7..228b068fab 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-mvc-java spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow spring-mvc-xml @@ -1131,7 +1130,6 @@ spring-mvc-java spring-mvc-java-2 - spring-mvc-velocity spring-mvc-views spring-mvc-webflow spring-mvc-xml diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index ce0524f957..382ed99603 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -20,6 +20,7 @@ spring-mvc-basics-4 spring-mvc-crash spring-mvc-forms-jsp + spring-mvc-velocity spring-rest-angular spring-rest-http spring-resttemplate-2 diff --git a/spring-mvc-velocity/README.md b/spring-web-modules/spring-mvc-velocity/README.md similarity index 100% rename from spring-mvc-velocity/README.md rename to spring-web-modules/spring-mvc-velocity/README.md diff --git a/spring-mvc-velocity/pom.xml b/spring-web-modules/spring-mvc-velocity/pom.xml similarity index 98% rename from spring-mvc-velocity/pom.xml rename to spring-web-modules/spring-mvc-velocity/pom.xml index 2269f05fa4..05016962a5 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-web-modules/spring-mvc-velocity/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-4 0.0.1-SNAPSHOT - ../parent-spring-4 + ../../parent-spring-4 diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/controller/MainController.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/domain/Tutorial.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/TutorialsService.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/MainWebAppInitializer.java diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java b/spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java similarity index 100% rename from spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java rename to spring-web-modules/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/spring/config/WebConfig.java diff --git a/spring-mvc-velocity/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-velocity/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-velocity/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-velocity/src/main/resources/logback.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/footer.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/fragments/header.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/layouts/layout.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/spring-context.xml diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/index.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/views/list.vm diff --git a/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml b/spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml rename to spring-web-modules/spring-mvc-velocity/src/main/webapp/WEB-INF/web_old.xml diff --git a/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java b/spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java similarity index 100% rename from spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/DataContentControllerIntegrationTest.java diff --git a/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java b/spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java similarity index 100% rename from spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/com/baeldung/mvc/velocity/test/config/TestConfig.java diff --git a/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java similarity index 100% rename from spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-velocity/src/test/java/org/baeldung/SpringContextTest.java diff --git a/spring-mvc-velocity/src/test/resources/mvc-servlet.xml b/spring-web-modules/spring-mvc-velocity/src/test/resources/mvc-servlet.xml similarity index 100% rename from spring-mvc-velocity/src/test/resources/mvc-servlet.xml rename to spring-web-modules/spring-mvc-velocity/src/test/resources/mvc-servlet.xml From ad461edca2298ebe3e7d93b14480958404b157b5 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 21:46:25 +0100 Subject: [PATCH 018/149] JAVA-2824 Fix tests in Java 9 and above modules --- .../java9/process/OutputStreamExample.java | 3 +-- .../process/ProcessUnderstandingUnitTest.java | 19 ++++++++++++++++++- .../screenshot/ScreenshotUnitTest.java | 5 +++-- .../baeldung/time/LocalDateTimeUnitTest.java | 9 --------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java index 37378f9d6c..fc6d907bfd 100644 --- a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java +++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java @@ -6,8 +6,7 @@ import java.util.logging.Logger; public class OutputStreamExample { public static void main(String[] args) { - Logger log = Logger.getLogger(OutputStreamExample.class.getName()); - log.log(Level.INFO, Integer.toString(sum(1,2))); + System.out.println(sum(1,2)); } public static int sum(int a, int b) { diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java index c8932efb4f..69b65852cc 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java @@ -5,10 +5,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.*; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.lang.String; -import java.util.Optional; import java.util.concurrent.TimeUnit; import java.lang.Integer; @@ -88,4 +88,21 @@ class ProcessUnderstandingUnitTest { .filter(ph -> (ph.pid() > 10000 && ph.pid() < 50000)) .count()) > 0); } + + @Test + public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException { + + Runtime.getRuntime() + .exec("javac -cp src src/main/java/com/baeldung/java9/process/OutputStreamExample.java" + .replace("/", File.separator)); + + Process process = Runtime.getRuntime() + .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample" + .replace("/", File.separator)); + + BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream())); + int value = Integer.parseInt(output.readLine()); + + assertEquals(3, value); + } } diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java index ac358b4e71..bf271ef2cc 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java @@ -9,11 +9,13 @@ import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.jupiter.api.Disabled; import static org.junit.Assert.assertTrue; +@Ignore public class ScreenshotUnitTest { @Test @@ -43,7 +45,6 @@ public class ScreenshotUnitTest { // This methods needs a component as a parameter and can only be run from an application with a GUI @Test - @Disabled public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { Rectangle componentRect = component.getBounds(); BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java index 1611a3002f..52dc9ba1c6 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java @@ -18,15 +18,6 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic; @PrepareForTest({ LocalDateTime.class }) public class LocalDateTimeUnitTest { - @Test - public void givenLocalDateTimeMock_whenNow_thenGetFixedLocalDateTime() { - Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC")); - String dateTimeExpected = "2014-12-22T10:15:30"; - LocalDateTime now = LocalDateTime.now(clock); - - assertThat(now).isEqualTo(dateTimeExpected); - } - @Test public void givenFixedClock_whenNow_thenGetFixedLocalDateTime() { Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC")); From de5f9940dd5d4226b16b10afae3d16a21ba1e670 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:26:14 +0100 Subject: [PATCH 019/149] JAVA-3531 Move spring-mvc-xml module --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-mvc-xml}/.gitignore | 0 .../spring-mvc-xml}/README.md | 0 .../spring-mvc-xml}/pom.xml | 0 .../java/com/baeldung/jsp/ExampleOne.java | 0 .../java/com/baeldung/jsp/ExampleThree.java | 0 .../com/baeldung/spring/ClientWebConfig.java | 0 .../baeldung/spring/ClientWebConfigJava.java | 0 .../ConstraintViolationExceptionHandler.java | 0 .../spring/controller/ErrorController.java | 0 .../controller/GeoIPTestController.java | 0 .../spring/controller/GreetingController.java | 0 .../spring/controller/HelloController.java | 0 .../controller/HelloGuestController.java | 0 .../controller/HelloWorldController.java | 0 .../spring/controller/ImageController.java | 122 +++++++++--------- .../spring/controller/PersonController.java | 0 ...stAndPathVariableValidationController.java | 0 .../spring/controller/WelcomeController.java | 0 .../java/com/baeldung/spring/form/GeoIP.java | 0 .../java/com/baeldung/spring/form/Person.java | 0 .../RawDBDemoGeoIPLocationService.java | 0 .../spring/validator/PersonValidator.java | 42 +++--- .../contentManagementWebMvcConfig.xml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/messages.properties | 2 +- .../src/main/resources/webMvcConfig.xml | 0 .../src/main/webapp/GeoIpTest.jsp | 0 .../WEB-INF/crash/commands/message.groovy | 0 .../WEB-INF/crash/commands/message2.java | 0 .../webapp/WEB-INF/crash/crash.properties | 0 .../webapp/WEB-INF/crash/telnet.properties | 0 .../webapp/WEB-INF/images/image-example.jpg | Bin .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/error.jsp | 0 .../main/webapp/WEB-INF/view/errorPage.jsp | 0 .../src/main/webapp/WEB-INF/view/greeting.jsp | 0 .../src/main/webapp/WEB-INF/view/hello.jsp | 0 .../main/webapp/WEB-INF/view/helloworld.jsp | 0 .../webapp/WEB-INF/view/image-download.jsp | 0 .../main/webapp/WEB-INF/view/personForm.jsp | 0 .../main/webapp/WEB-INF/view/personView.jsp | 0 .../src/main/webapp/WEB-INF/view/sample.jsp | 0 .../src/main/webapp/WEB-INF/view/welcome.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../spring-mvc-xml}/src/main/webapp/index.jsp | 0 .../src/main/webapp/jsp/ExampleThree.jsp | 0 .../src/main/webapp/jsp/ExampleTwo.jsp | 0 .../src/main/webapp/jsp/index.jsp | 0 .../src/main/webapp/spring-handler-index.jsp | 0 .../baeldung/geoip/GeoIpIntegrationTest.java | 0 ...leValidationControllerIntegrationTest.java | 0 .../java/org/baeldung/SpringContextTest.java | 2 +- 54 files changed, 85 insertions(+), 86 deletions(-) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/.gitignore (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/README.md (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/pom.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/jsp/ExampleOne.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/jsp/ExampleThree.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/ClientWebConfig.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/ClientWebConfigJava.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ErrorController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/GreetingController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloGuestController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/HelloWorldController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/ImageController.java (97%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/PersonController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/controller/WelcomeController.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/form/GeoIP.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/form/Person.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/java/com/baeldung/spring/validator/PersonValidator.java (96%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/contentManagementWebMvcConfig.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/logback.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/messages.properties (98%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/resources/webMvcConfig.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/GeoIpTest.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/commands/message.groovy (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/commands/message2.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/crash.properties (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/crash/telnet.properties (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/images/image-example.jpg (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/error.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/errorPage.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/greeting.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/hello.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/helloworld.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/image-download.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/personForm.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/personView.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/sample.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/view/welcome.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/ExampleThree.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/ExampleTwo.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/jsp/index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/main/webapp/spring-handler-index.jsp (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java (100%) rename {spring-mvc-xml => spring-web-modules/spring-mvc-xml}/src/test/java/org/baeldung/SpringContextTest.java (96%) diff --git a/pom.xml b/pom.xml index 67fa58293b..352d61660d 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-xml spring-protobuf spring-quartz @@ -1130,7 +1129,6 @@ spring-mvc-java-2 spring-mvc-velocity - spring-mvc-xml spring-protobuf spring-quartz diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c28ffbeab8..d9e7e8012d 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -22,6 +22,7 @@ spring-mvc-forms-jsp spring-mvc-views spring-mvc-webflow + spring-mvc-xml spring-rest-angular spring-rest-http spring-resttemplate-2 diff --git a/spring-mvc-xml/.gitignore b/spring-web-modules/spring-mvc-xml/.gitignore similarity index 100% rename from spring-mvc-xml/.gitignore rename to spring-web-modules/spring-mvc-xml/.gitignore diff --git a/spring-mvc-xml/README.md b/spring-web-modules/spring-mvc-xml/README.md similarity index 100% rename from spring-mvc-xml/README.md rename to spring-web-modules/spring-mvc-xml/README.md diff --git a/spring-mvc-xml/pom.xml b/spring-web-modules/spring-mvc-xml/pom.xml similarity index 100% rename from spring-mvc-xml/pom.xml rename to spring-web-modules/spring-mvc-xml/pom.xml diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfig.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/ClientWebConfigJava.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GreetingController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloGuestController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/HelloWorldController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java similarity index 97% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java index fc46c07e06..c02e76d4c0 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java +++ b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java @@ -1,61 +1,61 @@ -package com.baeldung.spring.controller; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.*; -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.ResponseBody; -import org.springframework.web.context.support.ServletContextResource; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; - -@Controller -public class ImageController { - - @Autowired - private ServletContext servletContext; - - @RequestMapping(value = "/image-view", method = RequestMethod.GET) - public String imageView() throws IOException { - return "image-download"; - } - - @RequestMapping(value = "/image-manual-response", method = RequestMethod.GET) - public void getImageAsByteArray(HttpServletResponse response) throws IOException { - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - response.setContentType(MediaType.IMAGE_JPEG_VALUE); - IOUtils.copy(in, response.getOutputStream()); - } - - @RequestMapping(value = "/image-byte-array", method = RequestMethod.GET) - @ResponseBody - public byte[] getImageAsByteArray() throws IOException { - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - return IOUtils.toByteArray(in); - } - - @RequestMapping(value = "/image-response-entity", method = RequestMethod.GET) - public ResponseEntity getImageAsResponseEntity() throws IOException { - ResponseEntity responseEntity; - final HttpHeaders headers = new HttpHeaders(); - final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); - byte[] media = IOUtils.toByteArray(in); - headers.setCacheControl(CacheControl.noCache().getHeaderValue()); - responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK); - return responseEntity; - } - - @RequestMapping(value = "/image-resource", method = RequestMethod.GET) - @ResponseBody - public ResponseEntity getImageAsResource() { - final HttpHeaders headers = new HttpHeaders(); - Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg"); - return new ResponseEntity<>(resource, headers, HttpStatus.OK); - } -} +package com.baeldung.spring.controller; + +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.*; +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.ResponseBody; +import org.springframework.web.context.support.ServletContextResource; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; + +@Controller +public class ImageController { + + @Autowired + private ServletContext servletContext; + + @RequestMapping(value = "/image-view", method = RequestMethod.GET) + public String imageView() throws IOException { + return "image-download"; + } + + @RequestMapping(value = "/image-manual-response", method = RequestMethod.GET) + public void getImageAsByteArray(HttpServletResponse response) throws IOException { + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + response.setContentType(MediaType.IMAGE_JPEG_VALUE); + IOUtils.copy(in, response.getOutputStream()); + } + + @RequestMapping(value = "/image-byte-array", method = RequestMethod.GET) + @ResponseBody + public byte[] getImageAsByteArray() throws IOException { + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + return IOUtils.toByteArray(in); + } + + @RequestMapping(value = "/image-response-entity", method = RequestMethod.GET) + public ResponseEntity getImageAsResponseEntity() throws IOException { + ResponseEntity responseEntity; + final HttpHeaders headers = new HttpHeaders(); + final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg"); + byte[] media = IOUtils.toByteArray(in); + headers.setCacheControl(CacheControl.noCache().getHeaderValue()); + responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK); + return responseEntity; + } + + @RequestMapping(value = "/image-resource", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getImageAsResource() { + final HttpHeaders headers = new HttpHeaders(); + Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg"); + return new ResponseEntity<>(resource, headers, HttpStatus.OK); + } +} diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/PersonController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/RequestAndPathVariableValidationController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/WelcomeController.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/form/Person.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java similarity index 100% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java similarity index 96% rename from spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java rename to spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java index f7625bacd9..cda756cdfc 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java +++ b/spring-web-modules/spring-mvc-xml/src/main/java/com/baeldung/spring/validator/PersonValidator.java @@ -1,22 +1,22 @@ -package com.baeldung.spring.validator; - -import com.baeldung.spring.form.Person; -import org.springframework.stereotype.Component; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -@Component -public class PersonValidator implements Validator { - - @Override - public boolean supports(final Class calzz) { - return Person.class.isAssignableFrom(calzz); - } - - @Override - public void validate(final Object obj, final Errors errors) { - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name"); - } +package com.baeldung.spring.validator; + +import com.baeldung.spring.form.Person; +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +@Component +public class PersonValidator implements Validator { + + @Override + public boolean supports(final Class calzz) { + return Person.class.isAssignableFrom(calzz); + } + + @Override + public void validate(final Object obj, final Errors errors) { + + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name"); + } } \ No newline at end of file diff --git a/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml diff --git a/spring-mvc-xml/src/main/resources/logback.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/logback.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/logback.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/logback.xml diff --git a/spring-mvc-xml/src/main/resources/messages.properties b/spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties similarity index 98% rename from spring-mvc-xml/src/main/resources/messages.properties rename to spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties index 2a3cccf76c..8d886c8449 100644 --- a/spring-mvc-xml/src/main/resources/messages.properties +++ b/spring-web-modules/spring-mvc-xml/src/main/resources/messages.properties @@ -1,2 +1,2 @@ -required.name = Name is required! +required.name = Name is required! NotEmpty.person.password = Password is required! \ No newline at end of file diff --git a/spring-mvc-xml/src/main/resources/webMvcConfig.xml b/spring-web-modules/spring-mvc-xml/src/main/resources/webMvcConfig.xml similarity index 100% rename from spring-mvc-xml/src/main/resources/webMvcConfig.xml rename to spring-web-modules/spring-mvc-xml/src/main/resources/webMvcConfig.xml diff --git a/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/GeoIpTest.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/GeoIpTest.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message.groovy diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/commands/message2.java diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/crash.properties diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/crash/telnet.properties diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/images/image-example.jpg diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/error.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/errorPage.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/greeting.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/hello.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/helloworld.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/image-download.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personForm.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/personView.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/sample.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/view/welcome.jsp diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-mvc-xml/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml diff --git a/spring-mvc-xml/src/main/webapp/index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/index.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleThree.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/ExampleTwo.jsp diff --git a/spring-mvc-xml/src/main/webapp/jsp/index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/jsp/index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/jsp/index.jsp diff --git a/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp b/spring-web-modules/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp similarity index 100% rename from spring-mvc-xml/src/main/webapp/spring-handler-index.jsp rename to spring-web-modules/spring-mvc-xml/src/main/webapp/spring-handler-index.jsp diff --git a/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java similarity index 100% rename from spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java diff --git a/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java similarity index 100% rename from spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/spring/controller/RequestAndPathVariableValidationControllerIntegrationTest.java diff --git a/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java similarity index 96% rename from spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java index 62e34859ee..27dcb83bd4 100644 --- a/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package org.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 8f843980820d537980a124367424386efb169b8f Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:37:42 +0100 Subject: [PATCH 020/149] JAVA-3531 Move spring-mvc-xml module (correct package for test) --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-web-modules/spring-mvc-xml/src/test/java/{org => com}/baeldung/SpringContextTest.java (96%) diff --git a/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java similarity index 96% rename from spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java rename to spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java index 27dcb83bd4..62e34859ee 100644 --- a/spring-web-modules/spring-mvc-xml/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-mvc-xml/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 08435be1909f31bef139b724ba0790dde736df55 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 30 Dec 2020 22:57:22 +0100 Subject: [PATCH 021/149] JAVA-3536 Move spring-rest-shell module --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-shell}/README.md | 0 .../spring-rest-shell}/pom.xml | 2 +- .../src/main/java/com/baeldung/Application.java | 0 .../src/main/java/com/baeldung/acticle/Article.java | 0 .../src/main/java/com/baeldung/acticle/ArticleRepository.java | 0 .../spring-rest-shell}/src/main/resources/logback.xml | 0 8 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/README.md (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/pom.xml (96%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/Application.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/acticle/Article.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/java/com/baeldung/acticle/ArticleRepository.java (100%) rename {spring-rest-shell => spring-web-modules/spring-rest-shell}/src/main/resources/logback.xml (100%) diff --git a/pom.xml b/pom.xml index 67fa58293b..44a87ecd3c 100644 --- a/pom.xml +++ b/pom.xml @@ -673,7 +673,6 @@ spring-remoting spring-rest-http-2 spring-rest-query-language - spring-rest-shell spring-rest-simple spring-resttemplate spring-rest-testing @@ -1138,7 +1137,6 @@ spring-reactor spring-remoting spring-rest-query-language - spring-rest-shell spring-rest-simple spring-resttemplate spring-rest-testing diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index c28ffbeab8..9fb40a1ed3 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -24,6 +24,7 @@ spring-mvc-webflow spring-rest-angular spring-rest-http + spring-rest-shell spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-shell/README.md b/spring-web-modules/spring-rest-shell/README.md similarity index 100% rename from spring-rest-shell/README.md rename to spring-web-modules/spring-rest-shell/README.md diff --git a/spring-rest-shell/pom.xml b/spring-web-modules/spring-rest-shell/pom.xml similarity index 96% rename from spring-rest-shell/pom.xml rename to spring-web-modules/spring-rest-shell/pom.xml index 1148a5c093..f5792fd6ca 100644 --- a/spring-rest-shell/pom.xml +++ b/spring-web-modules/spring-rest-shell/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-shell/src/main/java/com/baeldung/Application.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/Application.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/Application.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/Application.java diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java b/spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java similarity index 100% rename from spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java rename to spring-web-modules/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java diff --git a/spring-rest-shell/src/main/resources/logback.xml b/spring-web-modules/spring-rest-shell/src/main/resources/logback.xml similarity index 100% rename from spring-rest-shell/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-shell/src/main/resources/logback.xml From 90562c22a4c8a37db5f0c0189559c424eb8f9285 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 31 Dec 2020 10:46:33 +0100 Subject: [PATCH 022/149] JAVA-4130: Fix README.md for Using JaVers for Data Model Auditing in Spring Data --- spring-boot-modules/spring-boot-data/README.md | 1 + .../src/main/java/com/baeldung/javers/README.md | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md diff --git a/spring-boot-modules/spring-boot-data/README.md b/spring-boot-modules/spring-boot-data/README.md index da22b62128..f72864e6d9 100644 --- a/spring-boot-modules/spring-boot-data/README.md +++ b/spring-boot-modules/spring-boot-data/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring Boot with Spring Data - [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) - [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent) - [Guide To Running Logic on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) +- [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit) diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md deleted file mode 100644 index 4f8dd4abff..0000000000 --- a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/javers/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles - -- [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit) From 47ada8bdcad728c5e86450916af1e3bf72584c4c Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:19:30 +0100 Subject: [PATCH 023/149] JAVA-3498 Fix integration test in spring-cloud-zuul --- ...=> GreetingControllerIntegrationTest.java} | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) rename spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/{GreetingControllerManualTest.java => GreetingControllerIntegrationTest.java} (72%) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java similarity index 72% rename from spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java rename to spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index 4d3cede534..62e57992cb 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerManualTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -5,14 +5,17 @@ import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateL import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_REMAINING; import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_REMAINING_QUOTA; import static com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.RateLimitConstants.HEADER_RESET; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static java.lang.Integer.parseInt; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import java.util.concurrent.TimeUnit; + +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +29,7 @@ import org.springframework.test.context.junit4.SpringRunner; @AutoConfigureTestDatabase @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class GreetingControllerManualTest { +public class GreetingControllerIntegrationTest { private static final String SIMPLE_GREETING = "/greeting/simple"; private static final String ADVANCED_GREETING = "/greeting/advanced"; @@ -44,11 +47,15 @@ public class GreetingControllerManualTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - assertEquals(limit, "5"); - assertEquals(remaining, "4"); - assertEquals(reset, "60000"); + Assert.assertEquals("5", limit); + Assert.assertEquals(remaining, "4", remaining); + Assert.assertNotNull(reset); + Assert.assertThat( + parseInt(reset), + is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000))) + ); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); } @Test @@ -57,7 +64,7 @@ public class GreetingControllerManualTest { HttpHeaders headers = response.getHeaders(); String key = "rate-limit-application_serviceAdvanced_127.0.0.1"; assertHeaders(headers, key, false, false); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); for (int i = 0; i < 2; i++) { response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); @@ -68,18 +75,18 @@ public class GreetingControllerManualTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - assertEquals(limit, "1"); - assertEquals(remaining, "0"); - assertNotEquals(reset, "2000"); + Assert.assertEquals(limit, "1"); + Assert.assertEquals(remaining, "0"); + Assert.assertNotEquals(reset, "2000"); - assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); + Assert.assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); TimeUnit.SECONDS.sleep(2); response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); headers = response.getHeaders(); assertHeaders(headers, key, false, false); - assertEquals(OK, response.getStatusCode()); + Assert.assertEquals(OK, response.getStatusCode()); } private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) { @@ -91,22 +98,22 @@ public class GreetingControllerManualTest { if (nullable) { if (quotaHeaders) { - assertNull(quota); - assertNull(remainingQuota); + Assert.assertNull(quota); + Assert.assertNull(remainingQuota); } else { - assertNull(limit); - assertNull(remaining); + Assert.assertNull(limit); + Assert.assertNull(remaining); } - assertNull(reset); + Assert.assertNull(reset); } else { if (quotaHeaders) { - assertNotNull(quota); - assertNotNull(remainingQuota); + Assert.assertNotNull(quota); + Assert.assertNotNull(remainingQuota); } else { - assertNotNull(limit); - assertNotNull(remaining); + Assert.assertNotNull(limit); + Assert.assertNotNull(remaining); } - assertNotNull(reset); + Assert.assertNotNull(reset); } } } From bef161cc5df86f6cbd6e08dc9f43a6211196204c Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:22:01 +0100 Subject: [PATCH 024/149] JAVA-3498 Fix integration test in spring-cloud-zuul (fix imports) --- .../GreetingControllerIntegrationTest.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index 62e57992cb..a234bc8972 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -10,6 +10,9 @@ import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; @@ -47,15 +50,15 @@ public class GreetingControllerIntegrationTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - Assert.assertEquals("5", limit); - Assert.assertEquals(remaining, "4", remaining); - Assert.assertNotNull(reset); - Assert.assertThat( + assertEquals("5", limit); + assertEquals(remaining, "4", remaining); + assertNotNull(reset); + assertThat( parseInt(reset), is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000))) ); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); } @Test @@ -64,7 +67,7 @@ public class GreetingControllerIntegrationTest { HttpHeaders headers = response.getHeaders(); String key = "rate-limit-application_serviceAdvanced_127.0.0.1"; assertHeaders(headers, key, false, false); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); for (int i = 0; i < 2; i++) { response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); @@ -75,18 +78,18 @@ public class GreetingControllerIntegrationTest { String remaining = headers.getFirst(HEADER_REMAINING + key); String reset = headers.getFirst(HEADER_RESET + key); - Assert.assertEquals(limit, "1"); - Assert.assertEquals(remaining, "0"); + assertEquals(limit, "1"); + assertEquals(remaining, "0"); Assert.assertNotEquals(reset, "2000"); - Assert.assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); + assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); TimeUnit.SECONDS.sleep(2); response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class); headers = response.getHeaders(); assertHeaders(headers, key, false, false); - Assert.assertEquals(OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode()); } private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) { @@ -107,13 +110,13 @@ public class GreetingControllerIntegrationTest { Assert.assertNull(reset); } else { if (quotaHeaders) { - Assert.assertNotNull(quota); - Assert.assertNotNull(remainingQuota); + assertNotNull(quota); + assertNotNull(remainingQuota); } else { - Assert.assertNotNull(limit); - Assert.assertNotNull(remaining); + assertNotNull(limit); + assertNotNull(remaining); } - Assert.assertNotNull(reset); + assertNotNull(reset); } } } From cb7c9406eed01e9f44d2dd2573443841e2ef7208 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 31 Dec 2020 12:24:17 +0100 Subject: [PATCH 025/149] JAVA-3498 Fix integration test in spring-cloud-zuul (fix imports - 2) --- .../GreetingControllerIntegrationTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java index a234bc8972..7fdc723305 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/GreetingControllerIntegrationTest.java @@ -11,14 +11,15 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import java.util.concurrent.TimeUnit; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -80,7 +81,7 @@ public class GreetingControllerIntegrationTest { assertEquals(limit, "1"); assertEquals(remaining, "0"); - Assert.assertNotEquals(reset, "2000"); + assertNotEquals(reset, "2000"); assertEquals(TOO_MANY_REQUESTS, response.getStatusCode()); @@ -101,13 +102,13 @@ public class GreetingControllerIntegrationTest { if (nullable) { if (quotaHeaders) { - Assert.assertNull(quota); - Assert.assertNull(remainingQuota); + assertNull(quota); + assertNull(remainingQuota); } else { - Assert.assertNull(limit); - Assert.assertNull(remaining); + assertNull(limit); + assertNull(remaining); } - Assert.assertNull(reset); + assertNull(reset); } else { if (quotaHeaders) { assertNotNull(quota); From 926f273a2d94ff36005f9ba82af6c9c64b9e94eb Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 2 Jan 2021 12:08:15 +0100 Subject: [PATCH 026/149] Feature/bael 4749 java 11 features (#10308) * BAEL-4749: Added examples for Java 11 * BAEL-4749: Refactor test examples * BAEL-4749: Refactor test examples 2 * BAEL-4749: Fix PR comments * BAEL-4749: Update nestmates examples * BAEL-4749: Use method reference in Predicate.not example * BAEL-4749: Use String::isBlank in Predicate.not example * BAEL-4749: Two space indents when continuing a line * BAEL-4749: Two space indents when continuing a line (2) --- core-java-modules/core-java-11-2/pom.xml | 25 ++++++++ .../java/com/baeldung/features/MainClass.java | 17 ++++++ .../features/HttpClientIntegrationTest.java | 54 ++++++++++++++++ .../features/JavaElevenFeaturesUnitTest.java | 61 +++++++++++++++++++ .../features/NestedClassesUnitTest.java | 37 +++++++++++ 5 files changed, 194 insertions(+) create mode 100644 core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java create mode 100644 core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml index e2b129ae00..b92963a5c8 100644 --- a/core-java-modules/core-java-11-2/pom.xml +++ b/core-java-modules/core-java-11-2/pom.xml @@ -28,6 +28,29 @@ ${assertj.version} test + + org.mock-server + mockserver-junit-jupiter + ${mockserver.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + @@ -48,7 +71,9 @@ 11 11 29.0-jre + 5.7.0 3.17.2 + 5.11.1 diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java new file mode 100644 index 0000000000..b00c56fcd7 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java @@ -0,0 +1,17 @@ +package com.baeldung.features; + +public class MainClass { + + private static boolean mainPrivateMethod() { + return true; + } + + public static class NestedClass { + + boolean nestedPublicMethod() { + return mainPrivateMethod(); + } + + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java new file mode 100644 index 0000000000..1d49f5dbd1 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java @@ -0,0 +1,54 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.model.HttpStatusCode; +import org.mockserver.socket.PortFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; + +class HttpClientIntegrationTest { + + private static ClientAndServer mockServer; + private static int port; + + @BeforeAll + static void startServer() { + port = PortFactory.findFreePort(); + mockServer = startClientAndServer(port); + mockServer.when(new org.mockserver.model.HttpRequest().withMethod("GET")) + .respond(new org.mockserver.model.HttpResponse() + .withStatusCode(HttpStatusCode.OK_200.code()) + .withBody("Hello from the server!")); + } + + @AfterAll + static void stopServer() { + mockServer.stop(); + } + + @Test + void givenSampleHttpRequest_whenRequestIsSent_thenServerResponseIsReceived() throws IOException, InterruptedException { + HttpClient httpClient = HttpClient.newBuilder() + .version(HttpClient.Version.HTTP_2) + .connectTimeout(Duration.ofSeconds(20)) + .build(); + HttpRequest httpRequest = HttpRequest.newBuilder() + .GET() + .uri(URI.create("http://localhost:" + port)) + .build(); + HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); + assertThat(httpResponse.body()).isEqualTo("Hello from the server!"); + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java new file mode 100644 index 0000000000..61ce9c7c13 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class JavaElevenFeaturesUnitTest { + + @Test + void givenMultilineString_whenExtractingNonBlankStrippedLines_thenLinesAreReturned() { + String multilineString = "Baeldung helps \n \n developers \n explore Java."; + List lines = multilineString.lines() + .filter(line -> !line.isBlank()) + .map(String::strip) + .collect(Collectors.toList()); + assertThat(lines).containsExactly("Baeldung helps", "developers", "explore Java."); + } + + @Test + void givenTemporaryFile_whenReadingStringContent_thenContentIsReturned(@TempDir Path tempDir) throws IOException { + Path filePath = Files.writeString(Files.createTempFile(tempDir, "demo", ".txt"), "Sample text"); + String fileContent = Files.readString(filePath); + assertThat(fileContent).isEqualTo("Sample text"); + } + + @Test + void givenSampleList_whenConvertingToArray_thenItemsRemainUnchanged() { + List sampleList = Arrays.asList("Java", "Kotlin"); + String[] sampleArray = sampleList.toArray(String[]::new); + assertThat(sampleArray).containsExactly("Java", "Kotlin"); + } + + @Test + void givenSampleList_whenConvertingToUppercaseString_thenUppercaseIsReturned() { + List sampleList = Arrays.asList("Java", "Kotlin"); + String resultString = sampleList.stream() + .map((@Nonnull var x) -> x.toUpperCase()) + .collect(Collectors.joining(", ")); + assertThat(resultString).isEqualTo("JAVA, KOTLIN"); + } + + @Test + void givenSampleList_whenExtractingNonBlankValues_thenOnlyNonBlanksAreReturned() { + List sampleList = Arrays.asList("Java", "\n \n", "Kotlin", " "); + List withoutBlanks = sampleList.stream() + .filter(Predicate.not(String::isBlank)) + .collect(Collectors.toList()); + assertThat(withoutBlanks).containsExactly("Java", "Kotlin"); + } + +} diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java new file mode 100644 index 0000000000..902ad9c6f8 --- /dev/null +++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.features; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class NestedClassesUnitTest { + + @Test + public void giveNestedClass_whenCallingMainClassPrivateMethod_thenNoExceptionIsThrown() { + MainClass.NestedClass nestedInstance = new MainClass.NestedClass(); + assertThat(nestedInstance.nestedPublicMethod()).isTrue(); + } + + @Test + public void giveNestedClass_whenCheckingNestmate_thenNestedClassIsReturned() { + assertThat(MainClass.class.isNestmateOf(MainClass.NestedClass.class)).isTrue(); + } + + @Test + public void giveNestedClass_whenCheckingNestHost_thenMainClassIsReturned() { + assertThat(MainClass.NestedClass.class.getNestHost()).isEqualTo(MainClass.class); + } + + @Test + public void giveNestedClass_whenCheckingNestMembers_thenNestMembersAreReturned() { + Set nestedMembers = Arrays.stream(MainClass.NestedClass.class.getNestMembers()) + .map(Class::getName) + .collect(Collectors.toSet()); + assertThat(nestedMembers).contains(MainClass.class.getName(), MainClass.NestedClass.class.getName()); + } + +} From f210b5ae2967688b38879b0165adf59c44cee49e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 3 Jan 2021 00:11:41 +0530 Subject: [PATCH 027/149] JAVA-4166: Fix test in spring-5-reactive --- .../com/baeldung/functional/FunctionalWebApplication.java | 7 ++++--- .../FunctionalWebApplicationIntegrationTest.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java index 1f40798ada..b89f74ad92 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java @@ -3,7 +3,7 @@ package com.baeldung.functional; import static org.springframework.web.reactive.function.BodyInserters.fromObject; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RequestPredicates.path; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import static org.springframework.web.reactive.function.server.RouterFunctions.route; import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; import static org.springframework.web.reactive.function.server.ServerResponse.ok; @@ -18,6 +18,7 @@ import org.apache.catalina.startup.Tomcat; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.server.WebServer; import org.springframework.core.io.ClassPathResource; +import org.springframework.http.MediaType; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; import org.springframework.web.reactive.function.server.RouterFunction; @@ -37,14 +38,14 @@ public class FunctionalWebApplication { private RouterFunction routingFunction() { FormHandler formHandler = new FormHandler(); - RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) + RouterFunction restfulRouter = route(GET("/actor"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/actor"), serverRequest -> serverRequest.bodyToMono(Actor.class) .doOnNext(actors::add) .then(ok().build())); return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) .andRoute(POST("/upload"), formHandler::handleUpload) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) - .andNest(path("/actor"), restfulRouter) + .andNest(accept(MediaType.APPLICATION_JSON), restfulRouter) .filter((request, next) -> { System.out.println("Before handler invocation: " + request.path()); return next.handle(request); diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java index 38496d3500..5c0b4f69d0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java @@ -103,7 +103,6 @@ public class FunctionalWebApplicationIntegrationTest { .isEqualTo(String.valueOf(resource.contentLength())); } - @Ignore("We get 404 after Spring Boot 2.4 upgrade. We need to solve it in a new task.") @Test public void givenActors_whenAddActor_thenAdded() throws Exception { client.get() From 71bbdb7fede51f7b275eac1b4fe6c13a6aea8901 Mon Sep 17 00:00:00 2001 From: Tapan Avasthi Date: Sat, 2 Jan 2021 04:03:44 +0530 Subject: [PATCH 028/149] Use shouldNotFilter to exclude URLs for a Filter Jira ticket: http://jira.baeldung.com/browse/BAEL-4703 The existing article uses an out-dated way is used to excluded filtering for certain urls, instead shouldNotFilter should be used. --- .../filter/HeaderValidatorFilter.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java index 2af90badae..d6c1777326 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java @@ -11,20 +11,23 @@ import java.io.IOException; @Order(1) public class HeaderValidatorFilter extends OncePerRequestFilter { - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException { - String path = request.getRequestURI(); - if ("/health".equals(path)) { - filterChain.doFilter(request, response); - return; - } - String countryCode = request.getHeader("X-Country-Code"); - if (!"US".equals(countryCode)) { - response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale"); - return; - } - - filterChain.doFilter(request, response); - } -} \ No newline at end of file + @Override + protected void doFilterInternal(HttpServletRequest request, + HttpServletResponse response, + FilterChain filterChain) + throws ServletException, + IOException { + String countryCode = request.getHeader("X-Country-Code"); + if (!"US".equals(countryCode)) { + response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale"); + return; + } + filterChain.doFilter(request, response); + } + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { + String path = request.getRequestURI(); + return "/health".equals(path); + } +} From 1a2bd7348762bf5b1b505d8c78fd3fb41665e4bf Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Thu, 31 Dec 2020 23:20:27 +0100 Subject: [PATCH 029/149] [BAEL-2547] jackson deserialization class-casting exception --- .../baeldung/jackson/tocollection/Book.java | 70 ++++++++++ .../tocollection/JsonToCollectionUtil.java | 24 ++++ .../resources/to-java-collection/books.json | 13 ++ .../resources/to-java-collection/books.xml | 17 +++ .../DeserializeToJavaCollectionUnitTest.java | 130 ++++++++++++++++++ .../JsonToCollectionUtilUnitTest.java | 51 +++++++ 6 files changed, 305 insertions(+) create mode 100644 jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java create mode 100644 jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java create mode 100644 jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json create mode 100644 jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml create mode 100644 jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java create mode 100644 jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java diff --git a/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java new file mode 100644 index 0000000000..e9cb1343e9 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/Book.java @@ -0,0 +1,70 @@ +package com.baeldung.jackson.tocollection; + + +import java.util.Objects; + +public class Book { + private Integer bookId; + private String title; + private String author; + + public Book() {} + + public Book(Integer bookId, String title, String author) { + this.bookId = bookId; + this.title = title; + this.author = author; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Book)) { + return false; + } + + Book book = (Book) o; + + if (!Objects.equals(bookId, book.bookId)) { + return false; + } + if (!Objects.equals(title, book.title)) { + return false; + } + return Objects.equals(author, book.author); + } + + @Override + public int hashCode() { + int result = bookId != null ? bookId.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + result = 31 * result + (author != null ? author.hashCode() : 0); + return result; + } + + public Integer getBookId() { + return bookId; + } + + public void setBookId(Integer bookId) { + this.bookId = bookId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} diff --git a/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java new file mode 100644 index 0000000000..83e2de2c3b --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/java/com/baeldung/jackson/tocollection/JsonToCollectionUtil.java @@ -0,0 +1,24 @@ +package com.baeldung.jackson.tocollection; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class JsonToCollectionUtil { + + private JsonToCollectionUtil(){} + + public static List jsonArrayToList(String json, Class elementClass) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, elementClass); + return objectMapper.readValue(json, listType); + } + + public static List jsonArrayToList2(String json, Class elementClass) throws IOException { + return new ObjectMapper().readValue(json, new TypeReference>() {}); + } +} diff --git a/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json new file mode 100644 index 0000000000..6daf426736 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.json @@ -0,0 +1,13 @@ +[ { + "bookId" : 1, + "title" : "A Song of Ice and Fire", + "author" : "George R. R. Martin" +}, { + "bookId" : 2, + "title" : "The Hitchhiker's Guide to the Galaxy", + "author" : "Douglas Adams" +}, { + "bookId" : 3, + "title" : "Hackers And Painters", + "author" : "Paul Graham" +} ] diff --git a/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml new file mode 100644 index 0000000000..b2f951315b --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/main/resources/to-java-collection/books.xml @@ -0,0 +1,17 @@ + + + 1 + A Song of Ice and Fire + George R. R. Martin + + + 2 + The Hitchhiker's Guide to the Galaxy + Douglas Adams + + + 3 + Hackers And Painters + Paul Graham + + diff --git a/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java new file mode 100644 index 0000000000..8ddcc2d69a --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/DeserializeToJavaCollectionUnitTest.java @@ -0,0 +1,130 @@ +package com.baeldung.jackson.tocollection; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +public class DeserializeToJavaCollectionUnitTest { + private ObjectMapper objectMapper; + private XmlMapper xmlMapper; + private List expectedBookList; + + + @BeforeEach + void setup() { + objectMapper = new ObjectMapper(); + xmlMapper = new XmlMapper(); + expectedBookList = Lists.newArrayList( + new Book(1, "A Song of Ice and Fire", "George R. R. Martin"), + new Book(2, "The Hitchhiker's Guide to the Galaxy", "Douglas Adams"), + new Book(3, "Hackers And Painters", "Paul Graham")); + } + + private String readFile(String path) { + try (Scanner scanner = new Scanner(getClass().getResourceAsStream(path), "UTF-8")) { + return scanner.useDelimiter("\\A").next(); + } + } + + /*==================== + * JSON tests + *==================== + */ + @Test + void givenJsonString_whenDeserializingToList_thenThrowingClassCastException() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = objectMapper.readValue(jsonString, ArrayList.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + + @Test + void givenJsonString_whenDeserializingWithTypeReference_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = objectMapper.readValue(jsonString, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithJavaType_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class); + List bookList = objectMapper.readValue(jsonString, listType); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithConvertValueAndTypeReference_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + JsonNode jsonNode = objectMapper.readTree(jsonString); + List bookList = objectMapper.convertValue(jsonNode, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenDeserializingWithConvertValueAndJavaType_thenGetExpectedList() throws JsonProcessingException { + String jsonString = readFile("/to-java-collection/books.json"); + JsonNode jsonNode = objectMapper.readTree(jsonString); + List bookList = objectMapper.convertValue(jsonNode, objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class)); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + /*==================== + * XML tests + *==================== + */ + @Test + void givenXml_whenDeserializingToList_thenThrowingClassCastException() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List bookList = xmlMapper.readValue(xml, ArrayList.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + + @Test + void givenXml_whenDeserializingWithTypeReference_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List bookList = xmlMapper.readValue(xml, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenXml_whenDeserializingWithConvertValueAndTypeReference_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List node = xmlMapper.readValue(xml, List.class); + List bookList = xmlMapper.convertValue(node, new TypeReference>() {}); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenXml_whenDeserializingWithConvertValueAndJavaType_thenGetExpectedList() throws JsonProcessingException { + String xml = readFile("/to-java-collection/books.xml"); + List node = xmlMapper.readValue(xml, List.class); + List bookList = xmlMapper.convertValue(node, objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Book.class)); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } +} diff --git a/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java new file mode 100644 index 0000000000..a08e48e069 --- /dev/null +++ b/jackson-modules/jackson-conversions-2/src/test/java/com/baeldung/jackson/tocollection/JsonToCollectionUtilUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.jackson.tocollection; + +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; +import java.util.Scanner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +class JsonToCollectionUtilUnitTest { + + private List expectedBookList; + + + @BeforeEach + void setup() { + expectedBookList = Lists.newArrayList( + new Book(1, "A Song of Ice and Fire", "George R. R. Martin"), + new Book(2, "The Hitchhiker's Guide to the Galaxy", "Douglas Adams"), + new Book(3, "Hackers And Painters", "Paul Graham")); + } + + private String readFile(String path) { + try (Scanner scanner = new Scanner(getClass().getResourceAsStream(path), "UTF-8")) { + return scanner.useDelimiter("\\A").next(); + } + } + + @Test + void givenJsonString_whenCalljsonArrayToList_thenGetExpectedList() throws IOException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = JsonToCollectionUtil.jsonArrayToList(jsonString, Book.class); + assertThat(bookList.get(0)).isInstanceOf(Book.class); + assertThat(bookList).isEqualTo(expectedBookList); + } + + @Test + void givenJsonString_whenCalljsonArrayToList2_thenGetException() throws IOException { + String jsonString = readFile("/to-java-collection/books.json"); + List bookList = JsonToCollectionUtil.jsonArrayToList2(jsonString, Book.class); + assertThat(bookList).size().isEqualTo(3); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> bookList.get(0).getBookId()) + .withMessageMatching(".*java.util.LinkedHashMap cannot be cast to .*com.baeldung.jackson.tocollection.Book.*"); + } + +} From 5d9cb02da9070e9742a172877d0220d841a559f8 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 3 Jan 2021 16:36:16 -0300 Subject: [PATCH 030/149] fixed error updating deprecated isEmpty method --- .../properties/reloading/configs/ReloadablePropertySource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java index 5d4e170226..e63dc1eb54 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/reloading/configs/ReloadablePropertySource.java @@ -15,7 +15,7 @@ public class ReloadablePropertySource extends PropertySource { } public ReloadablePropertySource(String name, String path) { - super(StringUtils.hasText(name) ? path : name); + super(!StringUtils.hasText(name) ? path : name); try { this.propertiesConfiguration = new PropertiesConfiguration(path); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); From bbdcf57afb63dda1b6e020ba22c5d1a780ef1c92 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Tue, 29 Dec 2020 11:02:52 +0200 Subject: [PATCH 031/149] BAEL-4472- Binary Semaphore vs a ReentrantLock - new module added --- .../core-java-concurrency-advanced-4/pom.xml | 47 +++++++++++++++ ...inarySemaphoreVsReentrantLockUnitTest.java | 58 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 3 files changed, 106 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/pom.xml create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-4/pom.xml b/core-java-modules/core-java-concurrency-advanced-4/pom.xml new file mode 100644 index 0000000000..eb9ed3adc1 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + core-java-concurrency-advanced-4 + 0.1.0-SNAPSHOT + core-java-concurrency-advanced-4 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + + + core-java-concurrency-advanced-4 + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + src/main/resources + true + + + + + + 1.8 + 1.8 + + + diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java new file mode 100644 index 0000000000..f456e82f39 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.binarysemaphorereentrantlock; + +import static org.junit.Assert.assertEquals; +import java.util.concurrent.Semaphore; +import java.util.concurrent.locks.ReentrantLock; + +import org.junit.Test; + +public class BinarySemaphoreVsReentrantLockUnitTest { + + @Test + public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { + Semaphore binarySemaphore = new Semaphore(1); + try { + binarySemaphore.acquire(); + assertEquals(0, binarySemaphore.availablePermits()); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + binarySemaphore.release(); + assertEquals(1, binarySemaphore.availablePermits()); + } + } + + @Test + public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + + @Test + public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { + ReentrantLock reentrantLock = new ReentrantLock(); + try { + reentrantLock.lock(); + reentrantLock.lock(); + assertEquals(2, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + } finally { + reentrantLock.unlock(); + assertEquals(1, reentrantLock.getHoldCount()); + assertEquals(true, reentrantLock.isLocked()); + + reentrantLock.unlock(); + assertEquals(0, reentrantLock.getHoldCount()); + assertEquals(false, reentrantLock.isLocked()); + } + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 0a9e818156..00ed22c3bd 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -47,6 +47,7 @@ core-java-concurrency-advanced core-java-concurrency-advanced-2 core-java-concurrency-advanced-3 + core-java-concurrency-advanced-4 core-java-concurrency-basic core-java-concurrency-basic-2 core-java-concurrency-collections From 1b4e5782ec11316b254c8faec298dc66d433dfdc Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 4 Jan 2021 09:05:55 +0530 Subject: [PATCH 032/149] BAEL-4624: Review comments --- .../com/baeldung/spring/transaction/CourseDao.java | 11 ----------- .../baeldung/spring/transaction/CourseService.java | 10 +++++++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java index 489784bb40..adf138ba67 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseDao.java @@ -1,8 +1,5 @@ package com.baeldung.spring.transaction; -import java.sql.SQLException; - -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Repository; import com.baeldung.spring.hibernate.AbstractHibernateDao; @@ -13,12 +10,4 @@ public class CourseDao extends AbstractHibernateDao { super(); setClazz(Course.class); } - - public Course createWithRuntimeException(final Course entity) { - throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); - } - - public Course createWithCheckedException(final Course entity) throws SQLException { - throw new SQLException("Throwing exception for demoing Rollback!!!"); - } } diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 21f947a925..400c7d4843 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -3,6 +3,7 @@ package com.baeldung.spring.transaction; import java.sql.SQLException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; @@ -15,17 +16,20 @@ public class CourseService { @Transactional public void createCourseDeclarativeWithRuntimeException(Course course) { - courseDao.createWithRuntimeException(course); + courseDao.create(course); + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); } @Transactional(rollbackFor = { SQLException.class }) public void createCourseDeclarativeWithCheckedException(Course course) throws SQLException { - courseDao.createWithCheckedException(course); + courseDao.create(course); + throw new SQLException("Throwing exception for demoing Rollback!!!"); } public void createCourseDefaultRatingProgramatic(Course course) { try { - courseDao.createWithRuntimeException(course); + courseDao.create(course); + throw new DataIntegrityViolationException("Throwing exception for demoing Rollback!!!"); } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } From 68d3abae10124c5d5d2b103252be20d54d209cdb Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 10:50:19 +0100 Subject: [PATCH 033/149] JAVA-3537: Move spring-rest-simple into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-rest-simple}/README.md | 0 .../spring-rest-simple}/pom.xml | 2 +- .../src/main/java/com/baeldung/Application.java | 0 .../java/com/baeldung/apachefileupload/UploadController.java | 0 .../src/main/java/com/baeldung/config/MvcConfig.java | 0 .../com/baeldung/config/converter/KryoHttpMessageConverter.java | 0 .../src/main/java/com/baeldung/repository/BookRepository.java | 0 .../java/com/baeldung/web/controller/ApiExceptionHandler.java | 0 .../main/java/com/baeldung/web/controller/BookController.java | 0 .../main/java/com/baeldung/web/controller/FooController.java | 0 .../src/main/java/com/baeldung/web/dto/Bazz.java | 0 .../src/main/java/com/baeldung/web/dto/Book.java | 0 .../src/main/java/com/baeldung/web/dto/Foo.java | 0 .../src/main/java/com/baeldung/web/dto/FooProtos.java | 0 .../src/main/java/com/baeldung/web/error/ApiErrorResponse.java | 0 .../main/java/com/baeldung/web/error/BookNotFoundException.java | 0 .../src/main/java/com/baeldung/web/util/LinkUtil.java | 0 .../src/main/resources/application.properties | 0 .../spring-rest-simple}/src/main/resources/logback.xml | 0 .../spring-rest-simple}/src/main/webapp/WEB-INF/company.html | 0 .../src/main/webapp/WEB-INF/spring-views.xml | 0 .../src/main/webapp/WEB-INF/spring-web-config.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../java/com/baeldung/repository/BookRepositoryUnitTest.java | 0 .../baeldung/web/controller/BookControllerIntegrationTest.java | 0 .../java/com/baeldung/web/controller/mediatypes/TestConfig.java | 0 .../test/java/com/baeldung/web/test/RequestMappingLiveTest.java | 0 .../java/com/baeldung/web/test/RestTemplateBasicLiveTest.java | 0 .../baeldung/web/test/SpringHttpMessageConvertersLiveTest.java | 0 .../com/baeldung/web/test/TestRestTemplateBasicLiveTest.java | 0 .../src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java | 0 .../spring-rest-simple}/src/test/resources/.gitignore | 0 34 files changed, 2 insertions(+), 3 deletions(-) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/README.md (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/pom.xml (99%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/Application.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/apachefileupload/UploadController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/config/MvcConfig.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/repository/BookRepository.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/BookController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Bazz.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Book.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/Foo.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/dto/FooProtos.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/error/ApiErrorResponse.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/error/BookNotFoundException.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/java/com/baeldung/web/util/LinkUtil.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/resources/application.properties (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/resources/logback.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/company.html (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/spring-views.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/main/webapp/WEB-INF/spring-web-config.xml (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java (100%) rename {spring-rest-simple => spring-web-modules/spring-rest-simple}/src/test/resources/.gitignore (100%) diff --git a/pom.xml b/pom.xml index 16de220d8c..208a0f5d87 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-reactor spring-remoting - spring-rest-simple spring-resttemplate spring-rest-testing spring-roo @@ -1119,7 +1118,6 @@ spring-reactor spring-remoting - spring-rest-simple spring-resttemplate spring-rest-testing spring-roo diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index d2d8b5d816..6252a6360f 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -32,6 +32,7 @@ spring-rest-http-2 spring-rest-query-language spring-rest-shell + spring-rest-simple spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-simple/README.md b/spring-web-modules/spring-rest-simple/README.md similarity index 100% rename from spring-rest-simple/README.md rename to spring-web-modules/spring-rest-simple/README.md diff --git a/spring-rest-simple/pom.xml b/spring-web-modules/spring-rest-simple/pom.xml similarity index 99% rename from spring-rest-simple/pom.xml rename to spring-web-modules/spring-rest-simple/pom.xml index 291053c87f..37a0b99de2 100644 --- a/spring-rest-simple/pom.xml +++ b/spring-web-modules/spring-rest-simple/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-simple/src/main/java/com/baeldung/Application.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/Application.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/Application.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/Application.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/apachefileupload/UploadController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/config/converter/KryoHttpMessageConverter.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/repository/BookRepository.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/ApiExceptionHandler.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/BookController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Bazz.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Book.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/Foo.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/dto/FooProtos.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/ApiErrorResponse.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/error/BookNotFoundException.java diff --git a/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java b/spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java similarity index 100% rename from spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java rename to spring-web-modules/spring-rest-simple/src/main/java/com/baeldung/web/util/LinkUtil.java diff --git a/spring-rest-simple/src/main/resources/application.properties b/spring-web-modules/spring-rest-simple/src/main/resources/application.properties similarity index 100% rename from spring-rest-simple/src/main/resources/application.properties rename to spring-web-modules/spring-rest-simple/src/main/resources/application.properties diff --git a/spring-rest-simple/src/main/resources/logback.xml b/spring-web-modules/spring-rest-simple/src/main/resources/logback.xml similarity index 100% rename from spring-rest-simple/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-simple/src/main/resources/logback.xml diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/company.html b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/company.html similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/company.html rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/company.html diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-views.xml diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml b/spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml similarity index 100% rename from spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml rename to spring-web-modules/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml diff --git a/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/repository/BookRepositoryUnitTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/BookControllerIntegrationTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RequestMappingLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/RestTemplateBasicLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/SpringHttpMessageConvertersLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/test/TestRestTemplateBasicLiveTest.java diff --git a/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java b/spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java similarity index 100% rename from spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java rename to spring-web-modules/spring-rest-simple/src/test/java/com/baeldung/web/util/HTTPLinkHeaderUtil.java diff --git a/spring-rest-simple/src/test/resources/.gitignore b/spring-web-modules/spring-rest-simple/src/test/resources/.gitignore similarity index 100% rename from spring-rest-simple/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-simple/src/test/resources/.gitignore From f49df277d4e40d46034cd4a047fdaaf39f853556 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 12:29:07 +0100 Subject: [PATCH 034/149] JAVA-3586: Upgrade commons-lang3 to 3.11 in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 16de220d8c..41274250cd 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ 2.21.0 2.5 2.6 - 3.5 + 3.11 1.4 3.0.0 3.1.0 From 3cb1b8536f89fc90ff9bd9dd38f59185c67b979b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 12:50:24 +0100 Subject: [PATCH 035/149] JAVA-3586: Use commons-lang3.version property --- core-java-modules/core-java-15/pom.xml | 3 +-- core-java-modules/core-java-9/pom.xml | 2 +- core-java-modules/core-java-collections-3/pom.xml | 2 +- java-numbers-3/pom.xml | 3 +-- java-numbers-4/pom.xml | 3 +-- jhipster/jhipster-microservice/car-app/pom.xml | 3 +-- jhipster/jhipster-microservice/dealer-app/pom.xml | 3 +-- jhipster/jhipster-microservice/gateway-app/pom.xml | 3 +-- jhipster/jhipster-monolithic/pom.xml | 3 +-- maven-modules/versions-maven-plugin/pom.xml | 3 +-- persistence-modules/hibernate-annotations/pom.xml | 3 +-- quarkus/pom.xml | 2 +- 12 files changed, 12 insertions(+), 21 deletions(-) diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index df8aeafca9..3b0d324d10 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -20,7 +20,7 @@ org.apache.commons commons-lang3 - ${apache-commons-lang3.version} + ${commons-lang3.version} org.assertj @@ -68,7 +68,6 @@ 15 - 3.11 3.17.2 3.8.1 3.0.0-M3 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index d7894934b1..05dc8ba5eb 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -47,7 +47,7 @@ org.apache.commons commons-lang3 - 3.11 + ${commons-lang3.version} commons-io diff --git a/core-java-modules/core-java-collections-3/pom.xml b/core-java-modules/core-java-collections-3/pom.xml index a9a05f5092..602fcf60f4 100644 --- a/core-java-modules/core-java-collections-3/pom.xml +++ b/core-java-modules/core-java-collections-3/pom.xml @@ -35,7 +35,7 @@ org.apache.commons commons-lang3 - 3.10 + ${commons-lang3.version} diff --git a/java-numbers-3/pom.xml b/java-numbers-3/pom.xml index 495618885a..62225a898f 100644 --- a/java-numbers-3/pom.xml +++ b/java-numbers-3/pom.xml @@ -27,7 +27,7 @@ org.apache.commons commons-lang3 - ${commons.version} + ${commons-lang3.version} test @@ -51,7 +51,6 @@ 2.6.0 0.10.2 - 3.9 3.6.1 diff --git a/java-numbers-4/pom.xml b/java-numbers-4/pom.xml index e1722fb039..f4b0e23bd7 100644 --- a/java-numbers-4/pom.xml +++ b/java-numbers-4/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-lang3 - ${commons.version} + ${commons-lang3.version} test @@ -45,7 +45,6 @@ 0.10.2 - 3.9 3.6.1 diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml index c53ea8358e..603d53299c 100644 --- a/jhipster/jhipster-microservice/car-app/pom.xml +++ b/jhipster/jhipster-microservice/car-app/pom.xml @@ -22,7 +22,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.2 5.2.8.Final @@ -267,7 +266,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml index a0bcc73e31..0e492d3d13 100644 --- a/jhipster/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster/jhipster-microservice/dealer-app/pom.xml @@ -21,7 +21,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.2 5.2.8.Final @@ -266,7 +265,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml index c6dcbb3f3e..c5e7364f57 100644 --- a/jhipster/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster/jhipster-microservice/gateway-app/pom.xml @@ -23,7 +23,6 @@ 3.6.0 1.10 2.5 - 3.5 0.4.13 1.3 1.2 @@ -299,7 +298,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index 04f790faf5..103f48424f 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -171,7 +171,7 @@ org.apache.commons commons-lang3 - ${commons-lang.version} + ${commons-lang3.version} org.assertj @@ -888,7 +888,6 @@ 3.6.2 2.0.0 2.5 - 3.5 0.4.13 1.3 2.2.1 diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 3a9134ff40..3c6f2eeb3e 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} @@ -74,7 +74,6 @@ 2.3 2.7 1.9.1 - 3.0 4.0 diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 5367921f31..368eee2115 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -30,7 +30,7 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} @@ -67,7 +67,6 @@ 2.1.7.RELEASE 5.4.7.Final 1.4.200 - 3.8.1 0.9 diff --git a/quarkus/pom.xml b/quarkus/pom.xml index 7fdf1557fb..9c14afca3c 100644 --- a/quarkus/pom.xml +++ b/quarkus/pom.xml @@ -48,7 +48,7 @@ org.apache.commons commons-lang3 - 3.9 + ${commons-lang3.version} org.projectlombok From 5f78600cf7df8efd88c4f0e64c33d2d8437ed43b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 13:33:47 +0100 Subject: [PATCH 036/149] JAVA-3586: Fix versions-maven-plugin pom.xml --- maven-modules/versions-maven-plugin/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 3c6f2eeb3e..ff49811430 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.apache.commons commons-lang3 - ${commons-lang3.version} + ${commons.lang3.version} @@ -75,6 +75,7 @@ 2.7 1.9.1 4.0 + 3.11 \ No newline at end of file From 7dc8fdba7eaab562793c96c3c52888669b824d04 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 16:27:21 +0100 Subject: [PATCH 037/149] JAVA-3538: Move spring-rest-testing into spring-web-modules --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-rest-testing}/.gitignore | 0 .../spring-rest-testing}/README.md | 0 .../spring-rest-testing}/pom.xml | 2 +- .../ExceptionTestingApplication.java | 48 +++---- .../controller/ExceptionController.java | 62 ++++----- .../exception/BadArgumentsException.java | 26 ++-- .../exception/InternalException.java | 26 ++-- .../exception/ResourceNotFoundException.java | 26 ++-- .../com/baeldung/persistence/IOperations.java | 0 .../com/baeldung/persistence/dao/IFooDao.java | 0 .../com/baeldung/persistence/model/Foo.java | 0 .../com/baeldung/persistence/model/User.java | 0 .../persistence/service/IFooService.java | 0 .../service/common/AbstractService.java | 0 .../persistence/service/impl/FooService.java | 0 .../java/com/baeldung/spring/Application.java | 0 .../baeldung/spring/PersistenceConfig.java | 0 .../java/com/baeldung/spring/WebConfig.java | 0 .../web/controller/FooController.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/RootController.java | 0 .../MyResourceNotFoundException.java | 0 .../web/metric/ActuatorMetricService.java | 0 .../metric/CustomActuatorMetricService.java | 0 .../web/metric/IActuatorMetricService.java | 0 .../metric/ICustomActuatorMetricService.java | 0 .../baeldung/web/metric/IMetricService.java | 0 .../com/baeldung/web/metric/MetricFilter.java | 0 .../baeldung/web/metric/MetricService.java | 0 .../baeldung/web/util/RestPreconditions.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/graph.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/Consts.java | 0 .../SpringContextIntegrationTest.java | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../ExceptionControllerUnitTest.java | 130 +++++++++--------- .../persistence/PersistenceTestSuite.java | 0 ...ractServicePersistenceIntegrationTest.java | 0 .../FooServicePersistenceIntegrationTest.java | 0 .../test/java/com/baeldung/util/IDUtil.java | 0 .../src/test/resources/.gitignore | 0 .../spring-rest-testing}/src/testFile | 0 51 files changed, 161 insertions(+), 162 deletions(-) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/README.md (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/pom.xml (99%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java (96%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/IOperations.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/dao/IFooDao.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/Foo.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/model/User.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/IFooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/common/AbstractService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/persistence/service/impl/FooService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/Application.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/spring/WebConfig.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/HomeController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/controller/RootController.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/IMetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricFilter.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/metric/MetricService.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/java/com/baeldung/web/util/RestPreconditions.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/application.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/logback.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-h2.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/persistence-mysql.properties (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/graph.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/Consts.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java (97%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/java/com/baeldung/util/IDUtil.java (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/test/resources/.gitignore (100%) rename {spring-rest-testing => spring-web-modules/spring-rest-testing}/src/testFile (100%) diff --git a/pom.xml b/pom.xml index 208a0f5d87..d27d7350b3 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling @@ -1119,7 +1118,6 @@ spring-reactor spring-remoting spring-resttemplate - spring-rest-testing spring-roo spring-scheduling diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 6252a6360f..640c7c3660 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -33,6 +33,7 @@ spring-rest-query-language spring-rest-shell spring-rest-simple + spring-rest-testing spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-rest-testing/.gitignore b/spring-web-modules/spring-rest-testing/.gitignore similarity index 100% rename from spring-rest-testing/.gitignore rename to spring-web-modules/spring-rest-testing/.gitignore diff --git a/spring-rest-testing/README.md b/spring-web-modules/spring-rest-testing/README.md similarity index 100% rename from spring-rest-testing/README.md rename to spring-web-modules/spring-rest-testing/README.md diff --git a/spring-rest-testing/pom.xml b/spring-web-modules/spring-rest-testing/pom.xml similarity index 99% rename from spring-rest-testing/pom.xml rename to spring-web-modules/spring-rest-testing/pom.xml index 0e947260f4..fea8d25e4d 100644 --- a/spring-rest-testing/pom.xml +++ b/spring-web-modules/spring-rest-testing/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java index facc300dfa..b6e62b7295 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/ExceptionTestingApplication.java @@ -1,25 +1,25 @@ -package com.baeldung.exceptiontesting; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * Main Application Class - uses Spring Boot. Just run this as a normal Java - * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) - * - */ -@EnableScheduling -@EnableAutoConfiguration -@ComponentScan("com.baeldung.exceptiontesting") -@SpringBootApplication -public class ExceptionTestingApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(ExceptionTestingApplication.class, args); - } - +package com.baeldung.exceptiontesting; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * Main Application Class - uses Spring Boot. Just run this as a normal Java + * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) + * + */ +@EnableScheduling +@EnableAutoConfiguration +@ComponentScan("com.baeldung.exceptiontesting") +@SpringBootApplication +public class ExceptionTestingApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(ExceptionTestingApplication.class, args); + } + } \ No newline at end of file diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java similarity index 97% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java index 0f458b5f10..6d98337e40 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/controller/ExceptionController.java @@ -1,31 +1,31 @@ -package com.baeldung.exceptiontesting.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -@RestController -public class ExceptionController { - - @GetMapping("/exception/{exception_id}") - public void getSpecificException(@PathVariable("exception_id") String pException) { - if("not_found".equals(pException)) { - throw new ResourceNotFoundException("resource not found"); - } - else if("bad_arguments".equals(pException)) { - throw new BadArgumentsException("bad arguments"); - } - else { - throw new InternalException("internal error"); - } - } - - @GetMapping("/exception/throw") - public void getException() throws Exception { - throw new Exception("error"); - } -} +package com.baeldung.exceptiontesting.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +@RestController +public class ExceptionController { + + @GetMapping("/exception/{exception_id}") + public void getSpecificException(@PathVariable("exception_id") String pException) { + if("not_found".equals(pException)) { + throw new ResourceNotFoundException("resource not found"); + } + else if("bad_arguments".equals(pException)) { + throw new BadArgumentsException("bad arguments"); + } + else { + throw new InternalException("internal error"); + } + } + + @GetMapping("/exception/throw") + public void getException() throws Exception { + throw new Exception("error"); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java index 1eb1e6a3c9..1f0e1c1ddb 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/BadArgumentsException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadArgumentsException extends RuntimeException { - - public BadArgumentsException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadArgumentsException extends RuntimeException { + + public BadArgumentsException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java index 8e9f0f60f3..854d6a57f0 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/InternalException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) -public class InternalException extends RuntimeException { - - public InternalException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) +public class InternalException extends RuntimeException { + + public InternalException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java similarity index 96% rename from spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java index 469d5af96f..6d6e6ef712 100644 --- a/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java +++ b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/exceptiontesting/exception/ResourceNotFoundException.java @@ -1,13 +1,13 @@ -package com.baeldung.exceptiontesting.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@SuppressWarnings("serial") -@ResponseStatus(HttpStatus.NOT_FOUND) -public class ResourceNotFoundException extends RuntimeException { - - public ResourceNotFoundException(String message) { - super(message); - } -} +package com.baeldung.exceptiontesting.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@SuppressWarnings("serial") +@ResponseStatus(HttpStatus.NOT_FOUND) +public class ResourceNotFoundException extends RuntimeException { + + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/IOperations.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/dao/IFooDao.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/Foo.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/model/User.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/IFooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/common/AbstractService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/persistence/service/impl/FooService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/Application.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/Application.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/spring/WebConfig.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/HomeController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/controller/RootController.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/CustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/ICustomActuatorMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/IMetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricFilter.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/metric/MetricService.java diff --git a/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java b/spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java similarity index 100% rename from spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java rename to spring-web-modules/spring-rest-testing/src/main/java/com/baeldung/web/util/RestPreconditions.java diff --git a/spring-rest-testing/src/main/resources/application.properties b/spring-web-modules/spring-rest-testing/src/main/resources/application.properties similarity index 100% rename from spring-rest-testing/src/main/resources/application.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/application.properties diff --git a/spring-rest-testing/src/main/resources/logback.xml b/spring-web-modules/spring-rest-testing/src/main/resources/logback.xml similarity index 100% rename from spring-rest-testing/src/main/resources/logback.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/logback.xml diff --git a/spring-rest-testing/src/main/resources/persistence-h2.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-h2.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-h2.properties diff --git a/spring-rest-testing/src/main/resources/persistence-mysql.properties b/spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-rest-testing/src/main/resources/persistence-mysql.properties rename to spring-web-modules/spring-rest-testing/src/main/resources/persistence-mysql.properties diff --git a/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml b/spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml rename to spring-web-modules/spring-rest-testing/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/graph.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-rest-testing/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-testing/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-rest-testing/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-testing/src/test/java/com/baeldung/Consts.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/Consts.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/Consts.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java similarity index 97% rename from spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java index d624efcdd0..8e1eaad977 100644 --- a/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java +++ b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/exceptiontesting/controller/ExceptionControllerUnitTest.java @@ -1,65 +1,65 @@ -package com.baeldung.exceptiontesting.controller; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -import com.baeldung.exceptiontesting.controller.ExceptionController; -import com.baeldung.exceptiontesting.exception.BadArgumentsException; -import com.baeldung.exceptiontesting.exception.InternalException; -import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@RunWith(SpringRunner.class) -@WebMvcTest(ExceptionController.class) -public class ExceptionControllerUnitTest{ - - @Autowired - private MockMvc mvc; - - @Test - public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { - String exceptionParam = "not_found"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) - .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); - } - - @Test - public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { - String exceptionParam = "bad_arguments"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) - .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); - } - - @Test - public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { - String exceptionParam = "dummy"; - - mvc.perform(get("/exception/{exception_id}", exceptionParam) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) - .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); - } - - @Test(expected = Exception.class) - public void whenGetException_thenInternalServerError() throws Exception { - mvc.perform(get("/exception/throw") - .contentType(MediaType.APPLICATION_JSON)); - } -} +package com.baeldung.exceptiontesting.controller; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.exceptiontesting.controller.ExceptionController; +import com.baeldung.exceptiontesting.exception.BadArgumentsException; +import com.baeldung.exceptiontesting.exception.InternalException; +import com.baeldung.exceptiontesting.exception.ResourceNotFoundException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringRunner.class) +@WebMvcTest(ExceptionController.class) +public class ExceptionControllerUnitTest{ + + @Autowired + private MockMvc mvc; + + @Test + public void givenNotFound_whenGetSpecificException_thenNotFoundCode() throws Exception { + String exceptionParam = "not_found"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof ResourceNotFoundException)) + .andExpect(result -> assertEquals("resource not found", result.getResolvedException().getMessage())); + } + + @Test + public void givenBadArguments_whenGetSpecificException_thenBadRequest() throws Exception { + String exceptionParam = "bad_arguments"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof BadArgumentsException)) + .andExpect(result -> assertEquals("bad arguments", result.getResolvedException().getMessage())); + } + + @Test + public void givenOther_whenGetSpecificException_thenInternalServerError() throws Exception { + String exceptionParam = "dummy"; + + mvc.perform(get("/exception/{exception_id}", exceptionParam) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof InternalException)) + .andExpect(result -> assertEquals("internal error", result.getResolvedException().getMessage())); + } + + @Test(expected = Exception.class) + public void whenGetException_thenInternalServerError() throws Exception { + mvc.perform(get("/exception/throw") + .contentType(MediaType.APPLICATION_JSON)); + } +} diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/PersistenceTestSuite.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java diff --git a/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java b/spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java similarity index 100% rename from spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java rename to spring-web-modules/spring-rest-testing/src/test/java/com/baeldung/util/IDUtil.java diff --git a/spring-rest-testing/src/test/resources/.gitignore b/spring-web-modules/spring-rest-testing/src/test/resources/.gitignore similarity index 100% rename from spring-rest-testing/src/test/resources/.gitignore rename to spring-web-modules/spring-rest-testing/src/test/resources/.gitignore diff --git a/spring-rest-testing/src/testFile b/spring-web-modules/spring-rest-testing/src/testFile similarity index 100% rename from spring-rest-testing/src/testFile rename to spring-web-modules/spring-rest-testing/src/testFile From 6daa38007c206871ad2d1af496ab390a8322e84c Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Tue, 5 Jan 2021 01:32:23 +0800 Subject: [PATCH 038/149] [BAEL-4601] How to convert a Hibernate proxy to a real entity object * Adds Domain Models * Adds Integration Tests --- .../hibernateunproxy/CreditCardPayment.java | 20 +++++ .../jpa/hibernateunproxy/Payment.java | 47 ++++++++++++ .../jpa/hibernateunproxy/PaymentReceipt.java | 53 +++++++++++++ .../jpa/hibernateunproxy/WebUser.java | 42 +++++++++++ .../main/resources/META-INF/persistence.xml | 20 +++++ .../HibernateProxyIntegrationTest.java | 75 +++++++++++++++++++ 6 files changed, 257 insertions(+) create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java new file mode 100644 index 0000000000..6eb41f7ccc --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/CreditCardPayment.java @@ -0,0 +1,20 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import java.math.BigDecimal; + +@Entity +public class CreditCardPayment extends Payment { + + private String cardNumber; + + CreditCardPayment(BigDecimal amount, WebUser webUser, String cardNumber) { + this.amount = amount; + this.webUser = webUser; + this.cardNumber = cardNumber; + } + + protected CreditCardPayment() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java new file mode 100644 index 0000000000..9e70da5f65 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/Payment.java @@ -0,0 +1,47 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; +import java.math.BigDecimal; +import java.util.Objects; + +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Payment { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + protected WebUser webUser; + + protected BigDecimal amount; + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Payment payment = (Payment) o; + + return Objects.equals(id, payment.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected Payment() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java new file mode 100644 index 0000000000..530839eef4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/PaymentReceipt.java @@ -0,0 +1,53 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import java.util.Objects; +import java.util.UUID; + +@Entity +public class PaymentReceipt { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + private Payment payment; + + private String transactionNumber; + + PaymentReceipt(Payment payment) { + this.payment = payment; + this.transactionNumber = UUID.randomUUID().toString(); + } + + public Payment getPayment() { + return payment; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + PaymentReceipt that = (PaymentReceipt) o; + + return Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected PaymentReceipt() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java new file mode 100644 index 0000000000..d3f82bacd4 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/hibernateunproxy/WebUser.java @@ -0,0 +1,42 @@ +package com.baeldung.jpa.hibernateunproxy; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Objects; + +@Entity +public class WebUser { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + WebUser(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + WebUser webUser = (WebUser) o; + + return Objects.equals(id, webUser.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + protected WebUser() { + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml index f428fea07b..19ecae8491 100644 --- a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -77,4 +77,24 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.hibernateunproxy.Payment + com.baeldung.jpa.hibernateunproxy.CreditCardPayment + com.baeldung.jpa.hibernateunproxy.PaymentReceipt + com.baeldung.jpa.hibernateunproxy.WebUser + true + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java new file mode 100644 index 0000000000..a831639f5d --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.jpa.hibernateunproxy; + +import org.hibernate.Hibernate; +import org.hibernate.proxy.HibernateProxy; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class HibernateProxyIntegrationTest { + + private static EntityManager entityManager; + + @BeforeAll + public static void setup() { + EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-hibernate-unproxy"); + entityManager = factory.createEntityManager(); + populateH2DB(); + } + + @Test + public void givenPaymentReceipt_whenAccessingPayment_thenVerifyType() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + Assert.assertEquals(true, paymentReceipt.getPayment() instanceof HibernateProxy); + } + + @Test + public void givenWebUserProxy_whenCreatingPayment_thenExecuteSingleStatement() { + entityManager.getTransaction().begin(); + + WebUser webUser = entityManager.getReference(WebUser.class, 1L); + Payment payment = new CreditCardPayment(new BigDecimal(100), webUser, "CN-1234"); + entityManager.persist(payment); + + entityManager.getTransaction().commit(); + Assert.assertEquals(true, webUser instanceof HibernateProxy); + } + + @Test + public void givenPaymentReceipt_whenCastingPaymentToConcreteClass_thenThrowClassCastException() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + assertThrows(ClassCastException.class, () -> { + CreditCardPayment creditCardPayment = (CreditCardPayment) paymentReceipt.getPayment(); + }); + } + + @Test + public void givenPaymentReceipt_whenPaymentIsUnproxied_thenReturnRealEntityObject() { + PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); + Assert.assertEquals(true, Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); + } + + private static void populateH2DB() { + entityManager.getTransaction().begin(); + + WebUser webUser = new WebUser("name"); + entityManager.persist(webUser); + + Payment payment = new CreditCardPayment(new BigDecimal(100), webUser, "CN-1234"); + entityManager.persist(payment); + + PaymentReceipt receipt = new PaymentReceipt(payment); + entityManager.persist(receipt); + + entityManager.getTransaction().commit(); + entityManager.clear(); + } + +} From d8c26b6adb3e9a0a147276832a2b7523b4f7ca34 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 4 Jan 2021 23:01:41 +0100 Subject: [PATCH 039/149] JAVA-3586: Get rid of the overriden commons-lang3.version property --- blade/pom.xml | 1 - .../core-java-arrays-operations-advanced/pom.xml | 2 -- core-java-modules/core-java-arrays-operations-basic/pom.xml | 4 ---- core-java-modules/core-java-arrays-sorting/pom.xml | 4 ---- core-java-modules/core-java-collections-list/pom.xml | 1 - core-java-modules/core-java-lang-2/pom.xml | 1 - core-java-modules/core-java-string-algorithms-2/pom.xml | 1 - core-java-modules/core-java-string-algorithms-3/pom.xml | 1 - core-java-modules/core-java-string-algorithms/pom.xml | 1 - core-java-modules/core-java-string-operations-2/pom.xml | 1 - core-java-modules/core-java-string-operations/pom.xml | 1 - json-2/pom.xml | 1 - libraries-apache-commons/pom.xml | 1 - maven-modules/versions-maven-plugin/original/pom.xml | 1 - persistence-modules/hibernate-annotations/pom.xml | 1 - persistence-modules/hibernate-mapping/pom.xml | 1 - spring-web-modules/spring-mvc-java/pom.xml | 1 - xml/pom.xml | 1 - 18 files changed, 25 deletions(-) diff --git a/blade/pom.xml b/blade/pom.xml index 178d1afb52..458ec40051 100644 --- a/blade/pom.xml +++ b/blade/pom.xml @@ -154,7 +154,6 @@ 2.0.14.RELEASE 4.2.1 - 3.8.1 1.18.4 4.5.6 4.5.6 diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml index d73fdcee28..c7ea09c616 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -29,8 +29,6 @@ - 3.9 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-basic/pom.xml b/core-java-modules/core-java-arrays-operations-basic/pom.xml index 64856d9b39..dcee6547a0 100644 --- a/core-java-modules/core-java-arrays-operations-basic/pom.xml +++ b/core-java-modules/core-java-arrays-operations-basic/pom.xml @@ -68,11 +68,7 @@ 3.2.0 - - 3.9 - 1.19 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-sorting/pom.xml b/core-java-modules/core-java-arrays-sorting/pom.xml index 9b307870a1..9b900c3de6 100644 --- a/core-java-modules/core-java-arrays-sorting/pom.xml +++ b/core-java-modules/core-java-arrays-sorting/pom.xml @@ -76,12 +76,8 @@ 3.2.0 - - 3.9 28.2-jre - 1.19 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml index 509f58ea61..76ca66fe70 100644 --- a/core-java-modules/core-java-collections-list/pom.xml +++ b/core-java-modules/core-java-collections-list/pom.xml @@ -36,7 +36,6 @@ 4.1 - 3.8.1 3.11.1 diff --git a/core-java-modules/core-java-lang-2/pom.xml b/core-java-modules/core-java-lang-2/pom.xml index 5f2d4ec901..d395e8efb1 100644 --- a/core-java-modules/core-java-lang-2/pom.xml +++ b/core-java-modules/core-java-lang-2/pom.xml @@ -69,7 +69,6 @@ 1.19 3.12.2 1.9.4 - 3.10 29.0-jre diff --git a/core-java-modules/core-java-string-algorithms-2/pom.xml b/core-java-modules/core-java-string-algorithms-2/pom.xml index a635cd8022..2a84cebb4c 100644 --- a/core-java-modules/core-java-string-algorithms-2/pom.xml +++ b/core-java-modules/core-java-string-algorithms-2/pom.xml @@ -61,7 +61,6 @@ - 3.8.1 3.6.1 1.2 diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index 2725ba84c6..610956588e 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -59,7 +59,6 @@ - 3.8.1 3.6.1 28.1-jre diff --git a/core-java-modules/core-java-string-algorithms/pom.xml b/core-java-modules/core-java-string-algorithms/pom.xml index 85879d74e2..6ba9ae7bb3 100644 --- a/core-java-modules/core-java-string-algorithms/pom.xml +++ b/core-java-modules/core-java-string-algorithms/pom.xml @@ -65,7 +65,6 @@ - 3.8.1 27.0.1-jre 0.4.0 3.6.1 diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index db32bf97a1..5865d9a776 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -112,7 +112,6 @@ 3.6.1 2.0.0.Final - 3.8.1 28.2-jre 6.0.2.Final 3.0.0 diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index c5791e929e..9632988392 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -60,7 +60,6 @@ - 3.9 3.6.1 1.10 diff --git a/json-2/pom.xml b/json-2/pom.xml index 0bdede3b1a..e27d1c83f6 100644 --- a/json-2/pom.xml +++ b/json-2/pom.xml @@ -114,7 +114,6 @@ 0.9.23 3.11.1 1.9.2 - 3.9 diff --git a/libraries-apache-commons/pom.xml b/libraries-apache-commons/pom.xml index 74adddabcf..08dddac880 100644 --- a/libraries-apache-commons/pom.xml +++ b/libraries-apache-commons/pom.xml @@ -65,7 +65,6 @@ - 3.6 1.1 1.9.3 1.2 diff --git a/maven-modules/versions-maven-plugin/original/pom.xml b/maven-modules/versions-maven-plugin/original/pom.xml index f705dae5c5..c36a5913c2 100644 --- a/maven-modules/versions-maven-plugin/original/pom.xml +++ b/maven-modules/versions-maven-plugin/original/pom.xml @@ -74,7 +74,6 @@ 1.15 2.3 4.0 - 3.0 1.9.1 2.7 diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 368eee2115..230de2e17e 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -62,7 +62,6 @@ 5.4.7.Final 1.4.200 - 3.8.1 true 2.1.7.RELEASE 5.4.7.Final diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 4eabc5d298..155eefa526 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -71,7 +71,6 @@ 3.0.1-b11 1.0.3 1.3 - 3.9 2.6 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 179ac0fb54..ec302eed57 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -234,7 +234,6 @@ 19.0 - 3.5 1.3.2 2.5 1.4 diff --git a/xml/pom.xml b/xml/pom.xml index 8b2df41af6..cbad5b37f0 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -379,7 +379,6 @@ 2.3.29 0.9.6 - 3.5 2.4 1.8 From f361ccc834363018a7d5f924e21c88b3ab0a0105 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 5 Jan 2021 14:10:30 +0100 Subject: [PATCH 040/149] JAVA-3540: Move spring-resttemplate into spring-web-modules --- pom.xml | 2 -- spring-web-modules/pom.xml | 1 + .../spring-resttemplate}/.gitignore | 0 .../spring-resttemplate}/README.md | 0 .../spring-resttemplate}/pom.xml | 2 +- .../baeldung/responseheaders/ResponseHeadersApplication.java | 0 .../controllers/FilterResponseHeaderController.java | 0 .../responseheaders/controllers/ResponseHeaderController.java | 0 .../responseheaders/filter/AddResponseHeaderFilter.java | 0 .../resttemplate/RestTemplateConfigurationApplication.java | 0 .../configuration/CustomClientHttpRequestInterceptor.java | 0 .../configuration/CustomRestTemplateCustomizer.java | 0 .../com/baeldung/resttemplate/configuration/FooController.java | 0 .../baeldung/resttemplate/configuration/HelloController.java | 0 .../com/baeldung/resttemplate/configuration/SpringConfig.java | 0 .../com/baeldung/resttemplate/lists/EmployeeApplication.java | 0 .../com/baeldung/resttemplate/lists/client/EmployeeClient.java | 0 .../resttemplate/lists/controller/EmployeeResource.java | 0 .../main/java/com/baeldung/resttemplate/lists/dto/Employee.java | 0 .../java/com/baeldung/resttemplate/lists/dto/EmployeeList.java | 0 .../baeldung/resttemplate/lists/service/EmployeeService.java | 0 .../src/main/java/com/baeldung/resttemplate/web/dto/Foo.java | 0 .../baeldung/resttemplate/web/exception/NotFoundException.java | 0 .../web/handler/RestTemplateResponseErrorHandler.java | 0 .../src/main/java/com/baeldung/resttemplate/web/model/Bar.java | 0 .../main/java/com/baeldung/resttemplate/web/model/Employee.java | 0 .../baeldung/resttemplate/web/service/BarConsumerService.java | 0 .../com/baeldung/resttemplate/web/service/EmployeeService.java | 0 .../java/com/baeldung/sampleapp/config/MainApplication.java | 0 .../java/com/baeldung/sampleapp/config/RestClientConfig.java | 0 .../src/main/java/com/baeldung/sampleapp/config/WebConfig.java | 0 .../interceptors/RestTemplateHeaderModifierInterceptor.java | 0 .../baeldung/sampleapp/repository/HeavyResourceRepository.java | 0 .../sampleapp/web/controller/BarMappingExamplesController.java | 0 .../baeldung/sampleapp/web/controller/CompanyController.java | 0 .../sampleapp/web/controller/DeferredResultController.java | 0 .../sampleapp/web/controller/HeavyResourceController.java | 0 .../com/baeldung/sampleapp/web/controller/ItemController.java | 0 .../com/baeldung/sampleapp/web/controller/MyFooController.java | 0 .../com/baeldung/sampleapp/web/controller/PactController.java | 0 .../baeldung/sampleapp/web/controller/SimplePostController.java | 0 .../sampleapp/web/controller/redirect/RedirectController.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Company.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Foo.java | 0 .../main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java | 0 .../baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java | 0 .../sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Item.java | 0 .../main/java/com/baeldung/sampleapp/web/dto/ItemManager.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java | 0 .../src/main/java/com/baeldung/sampleapp/web/dto/Views.java | 0 .../sampleapp/web/exception/ResourceNotFoundException.java | 0 .../src/main/java/com/baeldung/transfer/LoginForm.java | 0 .../java/com/baeldung/web/upload/app/UploadApplication.java | 0 .../baeldung/web/upload/client/MultipartFileUploadClient.java | 0 .../com/baeldung/web/upload/controller/FileServerResource.java | 0 .../src/main/resources/application.properties | 0 .../spring-resttemplate}/src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../src/test/java/com/baeldung/SpringTestConfig.java | 0 .../src/test/java/com/baeldung/client/Consts.java | 0 .../java/com/baeldung/client/TestRestTemplateBasicLiveTest.java | 0 .../src/test/java/com/baeldung/pact/PactProviderLiveTest.java | 0 .../baeldung/resttemplate/LargeFileDownloadIntegrationTest.java | 0 .../com/baeldung/resttemplate/RestTemplateBasicLiveTest.java | 0 .../java/com/baeldung/resttemplate/RestTemplateLiveTest.java | 0 .../controller/redirect/RedirectControllerIntegrationTest.java | 0 .../RestTemplateResponseErrorHandlerIntegrationTest.java | 0 .../service/EmployeeServiceMockRestServiceServerUnitTest.java | 0 .../java/com/baeldung/web/service/EmployeeServiceUnitTest.java | 0 .../spring-resttemplate}/src/test/resources/.gitignore | 0 .../spring-resttemplate}/src/test/resources/logback-test.xml | 0 72 files changed, 2 insertions(+), 3 deletions(-) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/.gitignore (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/README.md (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/pom.xml (99%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/FooController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/model/Bar.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/model/Employee.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/MainApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/config/WebConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Company.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Item.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/dto/Views.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/transfer/LoginForm.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/app/UploadApplication.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/resources/application.properties (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/main/resources/logback.xml (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/SpringTestConfig.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/client/Consts.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/pact/PactProviderLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/resources/.gitignore (100%) rename {spring-resttemplate => spring-web-modules/spring-resttemplate}/src/test/resources/logback-test.xml (100%) diff --git a/pom.xml b/pom.xml index d27d7350b3..464134b572 100644 --- a/pom.xml +++ b/pom.xml @@ -663,7 +663,6 @@ spring-reactor spring-remoting - spring-resttemplate spring-roo spring-scheduling @@ -1117,7 +1116,6 @@ spring-reactor spring-remoting - spring-resttemplate spring-roo spring-scheduling diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 640c7c3660..e00ae3e899 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -34,6 +34,7 @@ spring-rest-shell spring-rest-simple spring-rest-testing + spring-resttemplate spring-resttemplate-2 spring-thymeleaf spring-thymeleaf-2 diff --git a/spring-resttemplate/.gitignore b/spring-web-modules/spring-resttemplate/.gitignore similarity index 100% rename from spring-resttemplate/.gitignore rename to spring-web-modules/spring-resttemplate/.gitignore diff --git a/spring-resttemplate/README.md b/spring-web-modules/spring-resttemplate/README.md similarity index 100% rename from spring-resttemplate/README.md rename to spring-web-modules/spring-resttemplate/README.md diff --git a/spring-resttemplate/pom.xml b/spring-web-modules/spring-resttemplate/pom.xml similarity index 99% rename from spring-resttemplate/pom.xml rename to spring-web-modules/spring-resttemplate/pom.xml index 05660f5210..c0f266fd62 100644 --- a/spring-resttemplate/pom.xml +++ b/spring-web-modules/spring-resttemplate/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/ResponseHeadersApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/FilterResponseHeaderController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/controllers/ResponseHeaderController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/responseheaders/filter/AddResponseHeaderFilter.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/MainApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/RestClientConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/config/WebConfig.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/interceptors/RestTemplateHeaderModifierInterceptor.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/repository/HeavyResourceRepository.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/BarMappingExamplesController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/CompanyController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/DeferredResultController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/HeavyResourceController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/ItemController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/PactController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/redirect/RedirectController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Company.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResource.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressOnly.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/HeavyResourceAddressPartialUpdate.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Item.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/ItemManager.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/PactDto.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/Views.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/exception/ResourceNotFoundException.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/transfer/LoginForm.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java rename to spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java diff --git a/spring-resttemplate/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate/src/main/resources/application.properties similarity index 100% rename from spring-resttemplate/src/main/resources/application.properties rename to spring-web-modules/spring-resttemplate/src/main/resources/application.properties diff --git a/spring-resttemplate/src/main/resources/logback.xml b/spring-web-modules/spring-resttemplate/src/main/resources/logback.xml similarity index 100% rename from spring-resttemplate/src/main/resources/logback.xml rename to spring-web-modules/spring-resttemplate/src/main/resources/logback.xml diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/client/Consts.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/pact/PactProviderLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java rename to spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java diff --git a/spring-resttemplate/src/test/resources/.gitignore b/spring-web-modules/spring-resttemplate/src/test/resources/.gitignore similarity index 100% rename from spring-resttemplate/src/test/resources/.gitignore rename to spring-web-modules/spring-resttemplate/src/test/resources/.gitignore diff --git a/spring-resttemplate/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate/src/test/resources/logback-test.xml similarity index 100% rename from spring-resttemplate/src/test/resources/logback-test.xml rename to spring-web-modules/spring-resttemplate/src/test/resources/logback-test.xml From 3bf9bf40948c308eeaaed1e9dc5943d37bfe98c8 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Tue, 5 Jan 2021 20:17:31 +0530 Subject: [PATCH 041/149] Added no roll back example --- .../java/com/baeldung/spring/transaction/CourseService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java index 400c7d4843..05e3f32cee 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/spring/transaction/CourseService.java @@ -35,4 +35,10 @@ public class CourseService { } } + @Transactional(noRollbackFor = { SQLException.class }) + public void createCourseDeclarativeWithNoRollBack(Course course) throws SQLException { + courseDao.create(course); + throw new SQLException("Throwing exception for demoing Rollback!!!"); + } + } From af51e73604d96e45b75d2b076d9d0f14a1f125e8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 5 Jan 2021 23:00:14 +0530 Subject: [PATCH 042/149] JAVA-4011: Moved 1 article from spring-5-security to spring-boot-security --- .../src/main/java/com/baeldung/securityprofile/Application.java | 0 .../java/com/baeldung/securityprofile/ApplicationNoSecurity.java | 0 .../java/com/baeldung/securityprofile/ApplicationSecurity.java | 0 .../java/com/baeldung/securityprofile/EmployeeController.java | 0 .../securityprofile/EmployeeControllerNoSecurityUnitTest.java | 0 .../com/baeldung/securityprofile/EmployeeControllerUnitTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/Application.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/main/java/com/baeldung/securityprofile/EmployeeController.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java (100%) rename {spring-security-modules/spring-5-security => spring-boot-modules/spring-boot-security}/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java (100%) diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/Application.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/Application.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java diff --git a/spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java similarity index 100% rename from spring-security-modules/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java rename to spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java diff --git a/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java similarity index 100% rename from spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java rename to spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java diff --git a/spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java similarity index 100% rename from spring-security-modules/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java rename to spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java From 5fcec971af06230b6fd077f417b0ae30e4a901d8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 5 Jan 2021 23:01:01 +0530 Subject: [PATCH 043/149] JAVA-4011: README changes --- spring-boot-modules/spring-boot-security/README.md | 2 ++ spring-security-modules/spring-5-security/README.md | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-security/README.md b/spring-boot-modules/spring-boot-security/README.md index 7229ba0f4a..2c9d37eac0 100644 --- a/spring-boot-modules/spring-boot-security/README.md +++ b/spring-boot-modules/spring-boot-security/README.md @@ -8,6 +8,8 @@ This module contains articles about Spring Boot Security - [Spring Security for Spring Boot Integration Tests](https://www.baeldung.com/spring-security-integration-tests) - [Introduction to Spring Security Taglibs](https://www.baeldung.com/spring-security-taglibs) - [Guide to @CurrentSecurityContext in Spring Security](https://www.baeldung.com/spring-currentsecuritycontext) +- [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) + ### Spring Boot Security Auto-Configuration diff --git a/spring-security-modules/spring-5-security/README.md b/spring-security-modules/spring-5-security/README.md index 6847d4bf5c..1917d347fb 100644 --- a/spring-security-modules/spring-5-security/README.md +++ b/spring-security-modules/spring-5-security/README.md @@ -9,6 +9,5 @@ This module contains articles about Spring Security 5 - [New Password Storage In Spring Security 5](https://www.baeldung.com/spring-security-5-password-storage) - [Default Password Encoder in Spring Security 5](https://www.baeldung.com/spring-security-5-default-password-encoder) - [Guide to the AuthenticationManagerResolver in Spring Security](https://www.baeldung.com/spring-security-authenticationmanagerresolver) -- [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) - [Manual Logout With Spring Security](https://www.baeldung.com/spring-security-manual-logout) - [How to Disable Spring Security Logout Redirects](https://www.baeldung.com/spring-security-disable-logout-redirects) From bfa1d207dfc8d7271a4e48e070e4d6714e2f8d9b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:03:21 +0800 Subject: [PATCH 044/149] Update README.md --- core-java-modules/core-java-char/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md index 71f8e943aa..fd79da15ab 100644 --- a/core-java-modules/core-java-char/README.md +++ b/core-java-modules/core-java-char/README.md @@ -3,4 +3,4 @@ This module contains articles about Java Character Class ### Relevant Articles: -- Character#isAlphabetic vs Character#isLetter +- [Character#isAlphabetic vs Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic) From 6ba3be6c81535b1e8976beae5a98dfac3de9da12 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:21:03 +0800 Subject: [PATCH 045/149] Update README.md --- spring-boot-modules/spring-boot-artifacts-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-artifacts-2/README.md b/spring-boot-modules/spring-boot-artifacts-2/README.md index 80e3d95d14..35f9cfab32 100644 --- a/spring-boot-modules/spring-boot-artifacts-2/README.md +++ b/spring-boot-modules/spring-boot-artifacts-2/README.md @@ -4,4 +4,4 @@ This module contains articles about configuring the Spring Boot build process 2. ### Relevant Articles: -TBD \ No newline at end of file +- [Difference Between spring-boot:repackage and Maven package](https://www.baeldung.com/spring-boot-repackage-vs-mvn-package) From cc6a351836ee0f29467b45348f4e9aaa521a4076 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:23:20 +0800 Subject: [PATCH 046/149] Update README.md --- core-java-modules/core-java-11-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-11-2/README.md b/core-java-modules/core-java-11-2/README.md index 834f310fce..c87936b07d 100644 --- a/core-java-modules/core-java-11-2/README.md +++ b/core-java-modules/core-java-11-2/README.md @@ -6,3 +6,4 @@ This module contains articles about Java 11 core features - [Guide to Java 8 Optional](https://www.baeldung.com/java-optional) - [Guide to Java Reflection](http://www.baeldung.com/java-reflection) - [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors) +- [New Features in Java 11](https://www.baeldung.com/java-11-new-features) From eedd1fd70bfab9a73417c099afc0d7f5d4db4cef Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:25:50 +0800 Subject: [PATCH 047/149] Update README.md --- core-java-modules/core-java-12/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-12/README.md b/core-java-modules/core-java-12/README.md index 6c603e4dea..c28df26c6f 100644 --- a/core-java-modules/core-java-12/README.md +++ b/core-java-modules/core-java-12/README.md @@ -2,3 +2,4 @@ - [String API Updates in Java 12](https://www.baeldung.com/java12-string-api) +- [Java 12 New Features](https://www.baeldung.com/java-12-new-features) From 108522e190261b1795fd55b9beb3c94b81af84fd Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 6 Jan 2021 11:16:55 +0100 Subject: [PATCH 048/149] JAVA-3541: Move spring-5-mvc into spring-web-modules --- pom.xml | 2 - spring-web-modules/pom.xml | 1 + .../spring-5-mvc}/.gitignore | 0 .../spring-5-mvc}/README.md | 0 .../spring-5-mvc}/pom.xml | 3 +- .../src/main/java/com/baeldung/Constants.java | 0 .../java/com/baeldung/Spring5Application.java | 0 .../com/baeldung/html/HtmlApplication.java | 0 .../com/baeldung/html/HtmlController.java | 0 .../java/com/baeldung/idc/Application.java | 0 .../src/main/java/com/baeldung/idc/Book.java | 0 .../java/com/baeldung/idc/BookController.java | 0 .../java/com/baeldung/idc/BookOperations.java | 0 .../java/com/baeldung/idc/BookRepository.java | 0 .../src/main/java/com/baeldung/model/Foo.java | 0 .../baeldung/persistence/DataSetupBean.java | 0 .../baeldung/persistence/FooRepository.java | 0 .../java/com/baeldung/web/FooController.java | 130 +++++++++--------- .../web/ResponseBodyEmitterController.java | 0 .../baeldung/web/SseEmitterController.java | 0 .../web/StreamingResponseBodyController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/jsp/index.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/LiveTest.java | 0 .../Spring5ApplicationIntegrationTest.java | 0 .../com/baeldung/html/HtmlControllerTest.java | 0 28 files changed, 67 insertions(+), 69 deletions(-) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/.gitignore (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/README.md (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/pom.xml (97%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/Constants.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/Spring5Application.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/html/HtmlApplication.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/html/HtmlController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/Application.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/Book.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookOperations.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/idc/BookRepository.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/model/Foo.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/persistence/DataSetupBean.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/persistence/FooRepository.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/FooController.java (97%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/SseEmitterController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/java/com/baeldung/web/StreamingResponseBodyController.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/resources/application.properties (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/resources/logback.xml (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/webapp/WEB-INF/jsp/index.jsp (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/LiveTest.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java (100%) rename {spring-5-mvc => spring-web-modules/spring-5-mvc}/src/test/java/com/baeldung/html/HtmlControllerTest.java (100%) diff --git a/pom.xml b/pom.xml index 464134b572..3eca22c173 100644 --- a/pom.xml +++ b/pom.xml @@ -601,7 +601,6 @@ spring-5 spring-5-data-reactive - spring-5-mvc spring-5-reactive spring-5-reactive-2 spring-5-reactive-client @@ -1055,7 +1054,6 @@ spring-5 spring-5-data-reactive - spring-5-mvc spring-5-reactive spring-5-reactive-2 spring-5-reactive-client diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index e00ae3e899..cc2ffcf762 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -14,6 +14,7 @@ + spring-5-mvc spring-mvc-basics spring-mvc-basics-2 spring-mvc-basics-3 diff --git a/spring-5-mvc/.gitignore b/spring-web-modules/spring-5-mvc/.gitignore similarity index 100% rename from spring-5-mvc/.gitignore rename to spring-web-modules/spring-5-mvc/.gitignore diff --git a/spring-5-mvc/README.md b/spring-web-modules/spring-5-mvc/README.md similarity index 100% rename from spring-5-mvc/README.md rename to spring-web-modules/spring-5-mvc/README.md diff --git a/spring-5-mvc/pom.xml b/spring-web-modules/spring-5-mvc/pom.xml similarity index 97% rename from spring-5-mvc/pom.xml rename to spring-web-modules/spring-5-mvc/pom.xml index 39fcd22824..ddcce8207b 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-web-modules/spring-5-mvc/pom.xml @@ -12,8 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 - + ../../parent-boot-2 diff --git a/spring-5-mvc/src/main/java/com/baeldung/Constants.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Constants.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/Constants.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Constants.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/Spring5Application.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlApplication.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/html/HtmlController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/Application.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Application.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/Book.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/Book.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookOperations.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/model/Foo.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/DataSetupBean.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/persistence/FooRepository.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java similarity index 97% rename from spring-5-mvc/src/main/java/com/baeldung/web/FooController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java index 137864cddd..8d8e03bbaf 100644 --- a/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java @@ -1,66 +1,66 @@ -package com.baeldung.web; - -import java.util.List; - -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; - -import com.baeldung.model.Foo; -import com.baeldung.persistence.FooRepository; - -@RestController -public class FooController { - - @Autowired - private FooRepository repo; - - // API - read - - @GetMapping("/foos/{id}") - @Validated - public Foo findById(@PathVariable @Min(0) final long id) { - return repo.findById(id).orElse(null); - } - - @GetMapping("/foos") - public List findAll() { - return repo.findAll(); - } - - @GetMapping( value="/foos", params = { "page", "size" }) - @Validated - public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { - return repo.findAll(PageRequest.of(page, size)).getContent(); - } - - // API - write - - @PutMapping("/foos/{id}") - @ResponseStatus(HttpStatus.OK) - public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { - return foo; - } - - @PostMapping("/foos") - @ResponseStatus(HttpStatus.CREATED) - public void create( @RequestBody final Foo foo) { - if (null == foo || null == foo.getName()) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required"); - } - repo.save(foo); - } +package com.baeldung.web; + +import java.util.List; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.HttpStatus; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +import com.baeldung.model.Foo; +import com.baeldung.persistence.FooRepository; + +@RestController +public class FooController { + + @Autowired + private FooRepository repo; + + // API - read + + @GetMapping("/foos/{id}") + @Validated + public Foo findById(@PathVariable @Min(0) final long id) { + return repo.findById(id).orElse(null); + } + + @GetMapping("/foos") + public List findAll() { + return repo.findAll(); + } + + @GetMapping( value="/foos", params = { "page", "size" }) + @Validated + public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { + return repo.findAll(PageRequest.of(page, size)).getContent(); + } + + // API - write + + @PutMapping("/foos/{id}") + @ResponseStatus(HttpStatus.OK) + public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { + return foo; + } + + @PostMapping("/foos") + @ResponseStatus(HttpStatus.CREATED) + public void create( @RequestBody final Foo foo) { + if (null == foo || null == foo.getName()) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required"); + } + repo.save(foo); + } } \ No newline at end of file diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java diff --git a/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java similarity index 100% rename from spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java rename to spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java diff --git a/spring-5-mvc/src/main/resources/application.properties b/spring-web-modules/spring-5-mvc/src/main/resources/application.properties similarity index 100% rename from spring-5-mvc/src/main/resources/application.properties rename to spring-web-modules/spring-5-mvc/src/main/resources/application.properties diff --git a/spring-5-mvc/src/main/resources/logback.xml b/spring-web-modules/spring-5-mvc/src/main/resources/logback.xml similarity index 100% rename from spring-5-mvc/src/main/resources/logback.xml rename to spring-web-modules/spring-5-mvc/src/main/resources/logback.xml diff --git a/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp rename to spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/spring-5-mvc/src/main/webapp/WEB-INF/web.xml b/spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-5-mvc/src/main/webapp/WEB-INF/web.xml rename to spring-web-modules/spring-5-mvc/src/main/webapp/WEB-INF/web.xml diff --git a/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/LiveTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java diff --git a/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java diff --git a/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java similarity index 100% rename from spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java rename to spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/html/HtmlControllerTest.java From 83664977f035d37e14f4a075330fa2fb71d66216 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 6 Jan 2021 11:48:27 -0300 Subject: [PATCH 049/149] Updated deprecated ConfigFileApplicationContextInitializer usage, now using ConfigDataApplicationContextInitializer --- .../properties/yamllist/YamlComplexListsUnitTest.java | 4 ++-- .../baeldung/properties/yamllist/YamlSimpleListUnitTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java index 6dc5d61d09..ce9ec38551 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlComplexListsUnitTest.java @@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.baeldung.properties.yamllist.pojo.ApplicationProps; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ApplicationProps.class) class YamlComplexListsUnitTest { diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java index 475a73c7d7..5315c7b9bc 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/yamllist/YamlSimpleListUnitTest.java @@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.baeldung.properties.yamllist.pojo.ApplicationProps; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ApplicationProps.class) class YamlSimpleListUnitTest { From 1112f95497583488dbdf9f13f9feb38a401be2ad Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 6 Jan 2021 11:49:12 -0300 Subject: [PATCH 050/149] updated deprecated Assert. method usage. This is not related to this 2.4.0 boot update --- .../value/defaults/ValuesWithDefaultsApp.java | 14 +++++++------- .../properties/lists/ListsPropertiesUnitTest.java | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java index 72fa0e03c0..2a2b535be7 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java +++ b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java @@ -51,21 +51,21 @@ public class ValuesWithDefaultsApp { @PostConstruct public void afterInitialize() { // strings - Assert.isTrue(stringWithDefaultValue.equals("my default value")); - Assert.isTrue(stringWithBlankDefaultValue.equals("")); + Assert.isTrue(stringWithDefaultValue.equals("my default value"), "unexpected value for stringWithDefaultValue"); + Assert.isTrue(stringWithBlankDefaultValue.equals(""), "unexpected value for stringWithBlankDefaultValue"); // other primitives - Assert.isTrue(booleanWithDefaultValue); - Assert.isTrue(intWithDefaultValue == 42); + Assert.isTrue(booleanWithDefaultValue, "unexpected value for booleanWithDefaultValue"); + Assert.isTrue(intWithDefaultValue == 42, "unexpected value for intWithDefaultValue"); // arrays List stringListValues = Arrays.asList("one", "two", "three"); - Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues)); + Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults"); List intListValues = Arrays.asList(1, 2, 3); - Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues)); + Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults"); // SpEL - Assert.isTrue(spelWithDefaultValue.equals("my default system property value")); + Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java index 60ba4cc108..1abb643d75 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SpringListPropertiesApplication.class) @@ -47,7 +48,7 @@ public class ListsPropertiesUnitTest { @Test public void whenContextIsInitialized_thenInjectedArrayContainsExpectedValues() { - assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); + assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); } @Test @@ -82,7 +83,7 @@ public class ListsPropertiesUnitTest { String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); - assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); + assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStrings); } } From 567e9109038dcdd0bc2536c3d4f24c7622d74120 Mon Sep 17 00:00:00 2001 From: MeenaGawande <45625809+MeenaGawande@users.noreply.github.com> Date: Wed, 6 Jan 2021 23:36:07 +0530 Subject: [PATCH 051/149] [BAEL-4720] Java File.separator vs File.pathSeparator (#10330) * [BAEL-4720] Java File.separator vs File.pathSeparator Removed src code and modified junit tests * [BAEL-4720] Java File.separator vs File.pathSeparator Code formatting: Removed extra spaces in the code * [BAEL-4720] Java File.separator vs File.pathSeparator Added more junit tests * [BAEL-4720] Java File.separator vs File.pathSeparator Added new module core-java-io4 and moved the code from core-java-io3 module. Co-authored-by: MeenaGawande --- core-java-modules/core-java-io-4/.gitignore | 2 + core-java-modules/core-java-io-4/README.md | 8 +++ core-java-modules/core-java-io-4/pom.xml | 52 +++++++++++++++ .../FilePathSeparatorUnitTest.java | 63 +++++++++++++++++++ .../fileseparator/FileSeparatorUnitTest.java | 63 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 6 files changed, 189 insertions(+) create mode 100644 core-java-modules/core-java-io-4/.gitignore create mode 100644 core-java-modules/core-java-io-4/README.md create mode 100644 core-java-modules/core-java-io-4/pom.xml create mode 100644 core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java create mode 100644 core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java diff --git a/core-java-modules/core-java-io-4/.gitignore b/core-java-modules/core-java-io-4/.gitignore new file mode 100644 index 0000000000..0c0cd871c5 --- /dev/null +++ b/core-java-modules/core-java-io-4/.gitignore @@ -0,0 +1,2 @@ +test-link* +0.* \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md new file mode 100644 index 0000000000..7cc38bb9fe --- /dev/null +++ b/core-java-modules/core-java-io-4/README.md @@ -0,0 +1,8 @@ +## Core Java IO + +This module contains articles about core Java input and output (IO) + +### Relevant Articles: + +- [Java File Separator vs File Path Separator] +- [[<-- Prev]](/core-java-modules/core-java-io-3) diff --git a/core-java-modules/core-java-io-4/pom.xml b/core-java-modules/core-java-io-4/pom.xml new file mode 100644 index 0000000000..ee31b35ba9 --- /dev/null +++ b/core-java-modules/core-java-io-4/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + core-java-io-4 + 0.1.0-SNAPSHOT + core-java-io-4 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + + commons-io + commons-io + ${commons-io.version} + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + + + + 3.6.1 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java new file mode 100644 index 0000000000..959aae8aff --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.fileseparator; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.util.StringJoiner; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; + +public class FilePathSeparatorUnitTest { + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenCheckPathSeparator_thenResultIsAsExpectedOnWindows() throws IOException { + assertEquals(";", File.pathSeparator); + assertEquals(';', File.pathSeparatorChar); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenCheckPathSeparator_thenResultIsAsExpected() throws IOException { + assertEquals(":", File.pathSeparator); + assertEquals(':', File.pathSeparatorChar); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildPathUsingString_thenResultIsAsExpectedOnWindows() throws IOException { + String[] pathNames = { "path1", "path2", "path3" }; + String path = String.join(File.pathSeparator, pathNames); + assertEquals("path1;path2;path3",path); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildPathUsingString_thenResultIsAsExpected() throws IOException { + String[] pathNames = { "path1", "path2", "path3" }; + String path = String.join(File.pathSeparator, pathNames); + assertEquals("path1:path2:path3", path); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenbuildPathUsingStringJoiner_thenResultIsAsExpectedOnWindows() throws IOException { + assertEquals("path1;path2", buildPathUsingStringJoiner("path1", "path2")); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenbuildPathUsingStringJoiner_thenResultIsAsExpected() throws IOException { + assertEquals("path1:path2", buildPathUsingStringJoiner("path1", "path2")); + } + + private String buildPathUsingStringJoiner(String path1, String path2) { + StringJoiner joiner = new StringJoiner(File.pathSeparator); + joiner.add(path1); + joiner.add(path2); + return joiner.toString(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java new file mode 100644 index 0000000000..f908dcc9bb --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.fileseparator; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; + +public class FileSeparatorUnitTest { + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenCheckFileSeparator_thenCorrectOnWindows() { + assertEquals("\\", File.separator); + assertEquals('\\', File.separatorChar); + + String fileSeparator = FileSystems.getDefault().getSeparator(); + assertEquals("\\",fileSeparator); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenCheckFileSeparator_thenCorrect() { + assertEquals("/", File.separator); + assertEquals('/', File.separatorChar); + + String fileSeparator = FileSystems.getDefault().getSeparator(); + assertEquals("/",fileSeparator); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildFilePathUsingPathsClass_thenCorrectOnWindows() { + Path path = Paths.get("dir1", "dir2"); + assertEquals("dir1\\dir2", path.toString()); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildFilePathUsingPathsClass_thenCorrect() { + Path path = Paths.get("dir1", "dir2"); + assertEquals("dir1/dir2", path.toString()); + } + + @Test + @EnabledOnOs(OS.WINDOWS) + public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpectedOnWindows() { + File file = new File("file1", "file2"); + assertEquals("file1\\file2", file.toString()); + } + + @Test + @EnabledOnOs({ OS.LINUX, OS.MAC }) + public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpected() { + File file = new File("file1", "file2"); + assertEquals("file1/file2", file.toString()); + } +} \ No newline at end of file diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 0a9e818156..711d1e03b9 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -67,6 +67,7 @@ core-java-io core-java-io-2 core-java-io-3 + core-java-io-4 core-java-io-apis core-java-io-conversions core-java-io-conversions-2 From e136bfb7dfea608c1dac957170c6bad5f77924d1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 7 Jan 2021 11:06:50 +0530 Subject: [PATCH 052/149] JAVA-4214: Fix issue with geodb repo --- persistence-modules/hibernate-annotations/pom.xml | 14 -------------- persistence-modules/hibernate-queries/pom.xml | 14 -------------- persistence-modules/hibernate5/pom.xml | 14 -------------- 3 files changed, 42 deletions(-) diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 230de2e17e..d3b786d6c8 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -44,21 +44,8 @@ hibernate-spatial ${hibernate-core.version} - - org.opengeo - geodb - ${geodb.version} - - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 5.4.7.Final 1.4.200 @@ -66,7 +53,6 @@ 2.1.7.RELEASE 5.4.7.Final 1.4.200 - 0.9 diff --git a/persistence-modules/hibernate-queries/pom.xml b/persistence-modules/hibernate-queries/pom.xml index 06f7f42088..4374c833c2 100644 --- a/persistence-modules/hibernate-queries/pom.xml +++ b/persistence-modules/hibernate-queries/pom.xml @@ -35,11 +35,6 @@ hibernate-spatial ${hibernate.version} - - org.opengeo - geodb - ${geodb.version} - mysql mysql-connector-java @@ -62,19 +57,10 @@ - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 6.0.6 2.2.3 3.8.0 - 0.9 1.21 diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index 7f04abc09f..3feffc98fd 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -35,11 +35,6 @@ hibernate-spatial ${hibernate.version} - - org.opengeo - geodb - ${geodb.version} - mysql mysql-connector-java @@ -68,21 +63,12 @@ - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - 5.4.12.Final 6.0.6 2.2.3 3.8.0 1.21 - 0.9 From 28d61c77efda4b80321c233a4d0bcb2b352fe585 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 7 Jan 2021 16:30:52 +0200 Subject: [PATCH 053/149] move main class to graphql package --- spring-boot-modules/spring-boot-libraries/pom.xml | 2 +- .../java/com/baeldung/{demo => graphql}/DemoApplication.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/{demo => graphql}/DemoApplication.java (96%) diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index cec035cf93..c96a881573 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -239,7 +239,7 @@ - com.baeldung.intro.App + com.baeldung.graphql.DemoApplication 8.5.11 2.4.1.Final 1.9.0 diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java similarity index 96% rename from spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java index e30ee6104d..1fd93af3b7 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/demo/DemoApplication.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/DemoApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.demo; +package com.baeldung.graphql; import com.baeldung.graphql.GraphqlConfiguration; import org.springframework.boot.SpringApplication; From 75aa478d80aa0f249351ac0dec0731773059604a Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 20:26:18 +0100 Subject: [PATCH 054/149] JAVA-3585: Upgrade commons-io in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 09cba54b87..e4a2632bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -1375,7 +1375,7 @@ 1.19 1.6.0 2.21.0 - 2.5 + 2.8.0 2.6 3.11 1.4 From ba5343cab27965460f29ec889fa1a03a30d2cb78 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 20:42:57 +0100 Subject: [PATCH 055/149] JAVA-3585: Use common commons-io.version property in all child modules --- aws-lambda/lambda/pom.xml | 1 - core-java-modules/core-java-9/pom.xml | 2 +- jhipster/jhipster-microservice/car-app/pom.xml | 1 - jhipster/jhipster-microservice/dealer-app/pom.xml | 1 - jhipster/jhipster-microservice/gateway-app/pom.xml | 1 - jhipster/jhipster-monolithic/pom.xml | 1 - libraries-6/pom.xml | 3 +-- libraries-data/pom.xml | 3 +-- parent-java/pom.xml | 3 +-- persistence-modules/hibernate-mapping/pom.xml | 1 - spring-boot-modules/pom.xml | 1 - spring-boot-modules/spring-boot-mvc-3/pom.xml | 4 ---- spring-core/pom.xml | 3 +-- spring-di/pom.xml | 3 +-- spring-web-modules/spring-mvc-java/pom.xml | 1 - xml/pom.xml | 1 - 16 files changed, 6 insertions(+), 24 deletions(-) diff --git a/aws-lambda/lambda/pom.xml b/aws-lambda/lambda/pom.xml index 2d903aabc5..1f446e04c0 100644 --- a/aws-lambda/lambda/pom.xml +++ b/aws-lambda/lambda/pom.xml @@ -89,7 +89,6 @@ 1.1.1 - 2.5 1.3.0 1.2.0 2.8.2 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index 05dc8ba5eb..001faf88cb 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -52,7 +52,7 @@ commons-io commons-io - 2.7 + ${commons-io.version} diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml index 603d53299c..477192438f 100644 --- a/jhipster/jhipster-microservice/car-app/pom.xml +++ b/jhipster/jhipster-microservice/car-app/pom.xml @@ -21,7 +21,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.2 5.2.8.Final diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml index 0e492d3d13..59df7d3b69 100644 --- a/jhipster/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster/jhipster-microservice/dealer-app/pom.xml @@ -20,7 +20,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.2 5.2.8.Final diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml index c5e7364f57..a50c2bbdd1 100644 --- a/jhipster/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster/jhipster-microservice/gateway-app/pom.xml @@ -22,7 +22,6 @@ 2.0.0 3.6.0 1.10 - 2.5 0.4.13 1.3 1.2 diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index 103f48424f..97f2b85b2f 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -887,7 +887,6 @@ -Djava.security.egd=file:/dev/./urandom -Xmx256m 3.6.2 2.0.0 - 2.5 0.4.13 1.3 2.2.1 diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index 0f129c27c9..caaebbb922 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -94,7 +94,7 @@ commons-io commons-io - ${commonsio.version} + ${commons-io.version} test @@ -157,7 +157,6 @@ 1.15 3.6 3.6.2 - 2.6 RELEASE 3.0 1.8.1 diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 95d771ce4e..5adb490e96 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -80,7 +80,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} provided @@ -165,7 +165,6 @@ 2.3 1.2 - 2.1 3.0.1 1.2.2 1.0.0 diff --git a/parent-java/pom.xml b/parent-java/pom.xml index d251adcdd3..9170f45bbe 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -27,7 +27,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} org.openjdk.jmh @@ -43,7 +43,6 @@ 29.0-jre - 2.6 1.19 2.3.7 2.2 diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 155eefa526..ebc854a621 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -71,7 +71,6 @@ 3.0.1-b11 1.0.3 1.3 - 2.6 diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index c562d522e2..ee088c357a 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -116,6 +116,5 @@ 5.6.2 - 2.6 diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml index 1290b0432f..5a5d4c3cd8 100644 --- a/spring-boot-modules/spring-boot-mvc-3/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -37,8 +37,4 @@ - - 2.7 - - diff --git a/spring-core/pom.xml b/spring-core/pom.xml index eb25bcd517..7d83fc198c 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -65,7 +65,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} @@ -86,7 +86,6 @@ 1.4.4.RELEASE 1 20.0 - 2.5 1.5.2.RELEASE 1.10.19 3.12.2 diff --git a/spring-di/pom.xml b/spring-di/pom.xml index 48cdf60673..df0b685ae2 100644 --- a/spring-di/pom.xml +++ b/spring-di/pom.xml @@ -83,7 +83,7 @@ commons-io commons-io - ${commons.io.version} + ${commons-io.version} org.aspectj @@ -159,7 +159,6 @@ 1.4.4.RELEASE 1 20.0 - 2.5 1.5.2.RELEASE 1.10.19 3.12.2 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index ec302eed57..474bbb2a06 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -235,7 +235,6 @@ 19.0 1.3.2 - 2.5 1.4 2.2.0 diff --git a/xml/pom.xml b/xml/pom.xml index cbad5b37f0..837f918b46 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -364,7 +364,6 @@ 1.2.0 2.0.6 1.6.2 - 2.5 4.1 1.2.4.5 2.3.1 From d25080b689972a08a53d82891af20e98cec45d5e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 7 Jan 2021 23:14:19 +0100 Subject: [PATCH 056/149] JAVA-4217: Update batch dependencies --- spring-batch-2/pom.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-batch-2/pom.xml b/spring-batch-2/pom.xml index 54df6d43e8..183ad610f3 100644 --- a/spring-batch-2/pom.xml +++ b/spring-batch-2/pom.xml @@ -20,7 +20,6 @@ org.springframework.boot spring-boot-starter-batch - 2.3.6.RELEASE org.hsqldb @@ -31,7 +30,6 @@ org.springframework.boot spring-boot-starter-test - ${spring.boot.batch.version} test @@ -43,14 +41,13 @@ org.springframework.batch spring-batch-test - ${spring.batch.test.version} + ${spring.batch.version} test - 2.3.6.RELEASE - 4.2.4.RELEASE + 4.3.0 2.5.1 From 51189b8d4058b637fd9ce1091fe4ea8b120e6158 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 8 Jan 2021 18:22:46 +0530 Subject: [PATCH 057/149] JAVA-4216: Fix issue in jnosql-artemis project --- persistence-modules/jnosql/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/jnosql/pom.xml b/persistence-modules/jnosql/pom.xml index fb7ac72b05..81c62ee562 100644 --- a/persistence-modules/jnosql/pom.xml +++ b/persistence-modules/jnosql/pom.xml @@ -21,7 +21,7 @@ - 0.0.5 + 0.0.6 From 989216338f7b2ee7b00a5672dd60cfa11a4b64cd Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 8 Jan 2021 19:56:04 +0100 Subject: [PATCH 058/149] JAVA-3588: Upgrade commons-fileupload in the main pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4a2632bf4..2d1850bb79 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ 2.3.1 1.2 2.11.1 - 1.3 + 1.4 1.2.0 5.2.0 0.3.1 From d450e4a2f81748ada5b89fd8cc5a8a976d35d095 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 8 Jan 2021 20:01:27 +0100 Subject: [PATCH 059/149] JAVA-3588: Use common commons-fileupload.version property in all child modules --- javax-servlets/pom.xml | 1 - spring-security-modules/spring-security-web-rest/pom.xml | 2 -- spring-web-modules/spring-mvc-basics-2/pom.xml | 1 - spring-web-modules/spring-mvc-forms-jsp/pom.xml | 3 +-- spring-web-modules/spring-mvc-java/pom.xml | 2 -- spring-web-modules/spring-rest-simple/pom.xml | 1 - 6 files changed, 1 insertion(+), 9 deletions(-) diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index 5fc9fef24a..700b823a6e 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -59,7 +59,6 @@ 4.5.3 2.8.2 3.9.1 - 1.3.3 4.0.1 diff --git a/spring-security-modules/spring-security-web-rest/pom.xml b/spring-security-modules/spring-security-web-rest/pom.xml index d2468152da..2330243aa6 100644 --- a/spring-security-modules/spring-security-web-rest/pom.xml +++ b/spring-security-modules/spring-security-web-rest/pom.xml @@ -168,7 +168,6 @@ ${springfox-swagger.version} - commons-fileupload commons-fileupload @@ -271,7 +270,6 @@ 26.0-jre - 1.3.2 2.9.0 diff --git a/spring-web-modules/spring-mvc-basics-2/pom.xml b/spring-web-modules/spring-mvc-basics-2/pom.xml index e16b54b2c8..0b4515994b 100644 --- a/spring-web-modules/spring-mvc-basics-2/pom.xml +++ b/spring-web-modules/spring-mvc-basics-2/pom.xml @@ -168,7 +168,6 @@ 4.0.0 6.0.10.Final enter-location-of-server - 1.3.2 3.0.11.RELEASE 2.4.12 2.3.27-incubating diff --git a/spring-web-modules/spring-mvc-forms-jsp/pom.xml b/spring-web-modules/spring-mvc-forms-jsp/pom.xml index aba16236da..0ca23bd6cb 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/pom.xml +++ b/spring-web-modules/spring-mvc-forms-jsp/pom.xml @@ -54,7 +54,7 @@ commons-fileupload commons-fileupload - ${fileupload.version} + ${commons-fileupload.version} com.fasterxml.jackson.core @@ -98,7 +98,6 @@ 6.0.10.Final - 1.3.3 5.2.5.Final 6.0.6 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 474bbb2a06..1324511215 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -234,8 +234,6 @@ 19.0 - 1.3.2 - 1.4 2.2.0 diff --git a/spring-web-modules/spring-rest-simple/pom.xml b/spring-web-modules/spring-rest-simple/pom.xml index 37a0b99de2..b9d5100fbf 100644 --- a/spring-web-modules/spring-rest-simple/pom.xml +++ b/spring-web-modules/spring-rest-simple/pom.xml @@ -314,7 +314,6 @@ - 1.3.3 4.0.0 1.4 3.1.0 From 195f4aab7bf8dd5147d1d538cad41504056cf70d Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 8 Jan 2021 18:14:01 -0300 Subject: [PATCH 060/149] cleaned up boot version override in spring-boot-properties, since the parent-boot-2 module has been updated --- spring-boot-modules/spring-boot-properties/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index 0260a4a72e..40668f47fd 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -141,7 +141,6 @@ @ com.baeldung.yaml.MyApplication - 2.4.0 From dfe902f0a68ccb9071165130d06319c01cf3eb02 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 12:59:21 +0530 Subject: [PATCH 061/149] JAVA-3542: Moved spring-jooq inside persistence-modules --- {spring-jooq => persistence-modules/spring-jooq}/.gitignore | 0 {spring-jooq => persistence-modules/spring-jooq}/README.md | 0 {spring-jooq => persistence-modules/spring-jooq}/pom.xml | 2 +- .../spring-jooq}/src/main/resources/application.properties | 0 .../spring-jooq}/src/main/resources/intro_config.properties | 0 .../spring-jooq}/src/main/resources/intro_schema.sql | 0 .../spring-jooq}/src/main/resources/logback.xml | 0 .../com/baeldung/jooq/introduction/ExceptionTranslator.java | 0 .../jooq/introduction/PersistenceContextIntegrationTest.java | 0 .../com/baeldung/jooq/introduction/QueryIntegrationTest.java | 0 .../src/test/java/com/baeldung/jooq/springboot/Application.java | 0 .../java/com/baeldung/jooq/springboot/InitialConfiguration.java | 0 .../com/baeldung/jooq/springboot/SpringBootIntegrationTest.java | 0 .../spring-jooq}/src/test/resources/application.properties | 0 14 files changed, 1 insertion(+), 1 deletion(-) rename {spring-jooq => persistence-modules/spring-jooq}/.gitignore (100%) rename {spring-jooq => persistence-modules/spring-jooq}/README.md (100%) rename {spring-jooq => persistence-modules/spring-jooq}/pom.xml (99%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/application.properties (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/intro_config.properties (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/intro_schema.sql (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/main/resources/logback.xml (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/Application.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java (100%) rename {spring-jooq => persistence-modules/spring-jooq}/src/test/resources/application.properties (100%) diff --git a/spring-jooq/.gitignore b/persistence-modules/spring-jooq/.gitignore similarity index 100% rename from spring-jooq/.gitignore rename to persistence-modules/spring-jooq/.gitignore diff --git a/spring-jooq/README.md b/persistence-modules/spring-jooq/README.md similarity index 100% rename from spring-jooq/README.md rename to persistence-modules/spring-jooq/README.md diff --git a/spring-jooq/pom.xml b/persistence-modules/spring-jooq/pom.xml similarity index 99% rename from spring-jooq/pom.xml rename to persistence-modules/spring-jooq/pom.xml index 550d49b5b2..6b3d565175 100644 --- a/spring-jooq/pom.xml +++ b/persistence-modules/spring-jooq/pom.xml @@ -9,7 +9,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/spring-jooq/src/main/resources/application.properties b/persistence-modules/spring-jooq/src/main/resources/application.properties similarity index 100% rename from spring-jooq/src/main/resources/application.properties rename to persistence-modules/spring-jooq/src/main/resources/application.properties diff --git a/spring-jooq/src/main/resources/intro_config.properties b/persistence-modules/spring-jooq/src/main/resources/intro_config.properties similarity index 100% rename from spring-jooq/src/main/resources/intro_config.properties rename to persistence-modules/spring-jooq/src/main/resources/intro_config.properties diff --git a/spring-jooq/src/main/resources/intro_schema.sql b/persistence-modules/spring-jooq/src/main/resources/intro_schema.sql similarity index 100% rename from spring-jooq/src/main/resources/intro_schema.sql rename to persistence-modules/spring-jooq/src/main/resources/intro_schema.sql diff --git a/spring-jooq/src/main/resources/logback.xml b/persistence-modules/spring-jooq/src/main/resources/logback.xml similarity index 100% rename from spring-jooq/src/main/resources/logback.xml rename to persistence-modules/spring-jooq/src/main/resources/logback.xml diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/ExceptionTranslator.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/PersistenceContextIntegrationTest.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/introduction/QueryIntegrationTest.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/Application.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/InitialConfiguration.java diff --git a/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java b/persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java similarity index 100% rename from spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java rename to persistence-modules/spring-jooq/src/test/java/com/baeldung/jooq/springboot/SpringBootIntegrationTest.java diff --git a/spring-jooq/src/test/resources/application.properties b/persistence-modules/spring-jooq/src/test/resources/application.properties similarity index 100% rename from spring-jooq/src/test/resources/application.properties rename to persistence-modules/spring-jooq/src/test/resources/application.properties From 3dbc22182ff3220becfb321b351bea10ea3556c7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 13:00:07 +0530 Subject: [PATCH 062/149] JAVA-3542: Added module to new parent's pom --- persistence-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index c7905a178d..8789a8473b 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -86,6 +86,7 @@ spring-jpa spring-jpa-2 spring-jdbc + spring-jooq spring-persistence-simple From 1f70c884377d18195ae838aa8d8579ffefa4ac80 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 9 Jan 2021 13:01:08 +0530 Subject: [PATCH 063/149] JAVA-3542: Removed module from main pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index e4a2632bf4..e923c3711c 100644 --- a/pom.xml +++ b/pom.xml @@ -650,7 +650,6 @@ spring-jersey spring-jinq spring-jms - spring-jooq spring-kafka spring-katharsis @@ -1101,7 +1100,6 @@ spring-jersey spring-jinq spring-jms - spring-jooq spring-kafka spring-katharsis From df31e606c3d8486dfb99a0be50491e74097b2810 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 9 Jan 2021 15:55:24 +0000 Subject: [PATCH 064/149] BAEL-4748 implement UserConsumerService with webClient and write UnitTests --- .../webclient/json/UserConsumerService.java | 16 ++++ .../json/UserConsumerServiceImpl.java | 90 +++++++++++++++++++ .../webclient/json/model/Address.java | 29 ++++++ .../baeldung/webclient/json/model/User.java | 30 +++++++ .../json/UserConsumerServiceImplUnitTest.java | 74 +++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java new file mode 100644 index 0000000000..9afc207ff2 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java @@ -0,0 +1,16 @@ +package com.baeldung.webclient.json; + +import java.util.List; + +public interface UserConsumerService { + + List processUserDataFromObjectArray(); + + List processUserDataFromUserArray(); + + List processUserDataFromUserList(); + + List processNestedUserDataFromUserArray(); + + List processNestedUserDataFromUserList(); +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java new file mode 100644 index 0000000000..30cd4a5617 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java @@ -0,0 +1,90 @@ +package com.baeldung.webclient.json; + +import com.baeldung.webclient.json.model.Address; +import com.baeldung.webclient.json.model.User; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class UserConsumerServiceImpl implements UserConsumerService { + + private final WebClient webClient; + private static final ObjectMapper mapper = new ObjectMapper(); + + public UserConsumerServiceImpl(WebClient webClient) { + this.webClient = webClient; + } + @Override + public List processUserDataFromObjectArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Object[].class).log(); + Object[] objects = response.block(); + return Arrays.stream(objects) + .map(object -> mapper.convertValue(object, User.class)) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserArray() { + Mono response = + webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(User[].class).log(); + + User[] userArray = response.block(); + return Arrays.stream(userArray) + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processUserDataFromUserList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + List userList = response.block(); + + return userList.stream() + .map(User::getName) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(User[].class).log(); + User[] userArray = response.block(); + + return Arrays.stream(userArray) + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } + + @Override + public List processNestedUserDataFromUserList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + + List userList = response.block(); + return userList.stream() + .flatMap(user -> user.getAddressList().stream()) + .map(Address::getPostCode) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java new file mode 100644 index 0000000000..cc4323b72b --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java @@ -0,0 +1,29 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Address { + private final String addressLine1; + private final String addressLine2; + private final String town; + private final String postCode; + + @JsonCreator + public Address( + @JsonProperty("addressLine1") String addressLine1, + @JsonProperty("addressLine2") String addressLine2, + @JsonProperty("town") String town, + @JsonProperty("postCode") String postCode) { + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.town = town; + this.postCode = postCode; + } + public String getPostCode() { + return postCode; + } +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java new file mode 100644 index 0000000000..6ed359f9db --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java @@ -0,0 +1,30 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User { + private final int id; + private final String name; + private final List
addressList; + + @JsonCreator + public User( + @JsonProperty("id") int id, + @JsonProperty("name") String name, + @JsonProperty("addressList") List
addressList) { + this.id = id; + this.name = name; + this.addressList = addressList; + } + + public String getName() { + return name; + } + + public List
getAddressList() { return addressList; } +} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java new file mode 100644 index 0000000000..151554efde --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.webclient.json; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +public class UserConsumerServiceImplUnitTest { + + private static String USER_JSON = "[{\"id\":1,\"name\":\"user1\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user1_address1_postCode\"}," + + "{\"addressLine1\":\"address2_addressLine1\",\"addressLine2\":\"address2_addressLine2\",\"town\":\"address2_town\",\"postCode\":\"user1_address2_postCode\"}]}," + + "{\"id\":2,\"name\":\"user2\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user2_address1_postCode\"}]}]"; + + private static String BASE_URL = "http://localhost:8080"; + + WebClient webClientMock = WebClient.builder() + .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) + .header("content-type", "application/json") + .body(USER_JSON) + .build())) + .build(); + + private final UserConsumerService tested = new UserConsumerServiceImpl(webClientMock); + + @Test + void when_processUserDataFromObjectArray_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromObjectArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processUserDataFromUserArray_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromUserArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processUserDataFromUserList_then_OK() { + List expected = Arrays.asList("user1", "user2"); + List actual = tested.processUserDataFromUserList(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processNestedUserDataFromUserArray_then_OK() { + List expected = Arrays.asList( + "user1_address1_postCode", + "user1_address2_postCode", + "user2_address1_postCode"); + + List actual = tested.processNestedUserDataFromUserArray(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); + } + + @Test + void when_processNestedUserDataFromUserList_then_OK() { + List expected = Arrays.asList( + "user1_address1_postCode", + "user1_address2_postCode", + "user2_address1_postCode"); + + List actual = tested.processNestedUserDataFromUserList(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); + } +} \ No newline at end of file From adfede63ba31352ca99e0631330a5e9856646096 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Sat, 9 Jan 2021 21:18:07 +0200 Subject: [PATCH 065/149] BAEL-4472 - old file removed --- ...inarySemaphoreVsReentrantLockUnitTest.java | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java deleted file mode 100644 index f456e82f39..0000000000 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.binarysemaphorereentrantlock; - -import static org.junit.Assert.assertEquals; -import java.util.concurrent.Semaphore; -import java.util.concurrent.locks.ReentrantLock; - -import org.junit.Test; - -public class BinarySemaphoreVsReentrantLockUnitTest { - - @Test - public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException { - Semaphore binarySemaphore = new Semaphore(1); - try { - binarySemaphore.acquire(); - assertEquals(0, binarySemaphore.availablePermits()); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - binarySemaphore.release(); - assertEquals(1, binarySemaphore.availablePermits()); - } - } - - @Test - public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException { - ReentrantLock reentrantLock = new ReentrantLock(); - try { - reentrantLock.lock(); - assertEquals(1, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - } finally { - reentrantLock.unlock(); - assertEquals(0, reentrantLock.getHoldCount()); - assertEquals(false, reentrantLock.isLocked()); - } - } - - @Test - public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException { - ReentrantLock reentrantLock = new ReentrantLock(); - try { - reentrantLock.lock(); - reentrantLock.lock(); - assertEquals(2, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - } finally { - reentrantLock.unlock(); - assertEquals(1, reentrantLock.getHoldCount()); - assertEquals(true, reentrantLock.isLocked()); - - reentrantLock.unlock(); - assertEquals(0, reentrantLock.getHoldCount()); - assertEquals(false, reentrantLock.isLocked()); - } - } - -} From 5e26ff97d9e41166fdd59c6192278838e9785d80 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 9 Jan 2021 23:09:00 -0300 Subject: [PATCH 066/149] removed starter-test vintage engine exclusion, not needed since Boot 2.4.0 --- spring-boot-modules/spring-boot-properties-3/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml index 44e2ef52ac..809fd6e2d4 100644 --- a/spring-boot-modules/spring-boot-properties-3/pom.xml +++ b/spring-boot-modules/spring-boot-properties-3/pom.xml @@ -26,12 +26,6 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.vintage - junit-vintage-engine - - org.springframework.boot From c0955b04f7c91c22d669bec3a212f58959f18def Mon Sep 17 00:00:00 2001 From: wolkenschieber Date: Sun, 10 Jan 2021 14:03:17 +0100 Subject: [PATCH 067/149] Update packages to match declaration --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-angular/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-ctx-fluent/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-jasypt/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-logging-log4j2/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) rename spring-boot-modules/spring-boot-vue/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-angular/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-angular/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-jasypt/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-jasypt/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-logging-log4j2/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-vue/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-vue/src/test/java/com/baeldung/SpringContextTest.java From 4af05b2230e35453f39a6708b9f2bef5a17580a6 Mon Sep 17 00:00:00 2001 From: wolkenschieber Date: Sun, 10 Jan 2021 15:04:09 +0100 Subject: [PATCH 068/149] Update packages to match declaration --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/SpringContextTest.java From 7347c8fe16d7d26de2f01e24c9869450209341ba Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 9 Jan 2021 23:10:12 -0300 Subject: [PATCH 069/149] added example for multidocument properties files --- .../src/main/resources/application.properties | 6 ++++- ...documentPropertiesFileIntegrationTest.java | 22 +++++++++++++++++ ...documentPropertiesFileIntegrationTest.java | 24 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index eace1f0e46..bf89182d8a 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -8,4 +8,8 @@ spring.datasource.url=jdbc:h2:dev spring.datasource.username=SA spring.datasource.password=password app.name=MyApp -app.description=${app.name} is a Spring Boot application \ No newline at end of file +app.description=${app.name} is a Spring Boot application +bael.property=defaultValue +#--- +spring.config.activate.on-profile=prod +bael.property=prodValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..61c76aef84 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,22 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +public class DefaultMultidocumentPropertiesFileIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Test + public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("defaultValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..39bc2da3ba --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,24 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("prod") +public class ProdMultidocumentPropertiesFileIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("prodValue"); + } +} From 0de32373657be04f4d28ed50bc558a263fd0cb00 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 11 Jan 2021 14:23:27 -0300 Subject: [PATCH 070/149] improved and updated spring-boot-yaml-vs-properties article code --- ...ation-multidocument-integration.properties | 4 +++ .../src/main/resources/application.properties | 12 +++++++- .../src/main/resources/application.yml | 20 ++++++------- ...ultMultidocumentFilesIntegrationTest.java} | 6 +++- .../DevMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ ...tionMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ ...rodMultidocumentFilesIntegrationTest.java} | 8 ++++-- ...gingMultidocumentFilesIntegrationTest.java | 28 +++++++++++++++++++ 8 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties rename spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/{DefaultMultidocumentPropertiesFileIntegrationTest.java => DefaultMultidocumentFilesIntegrationTest.java} (77%) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java rename spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/{ProdMultidocumentPropertiesFileIntegrationTest.java => ProdMultidocumentFilesIntegrationTest.java} (76%) create mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties new file mode 100644 index 0000000000..c4eeba2589 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties @@ -0,0 +1,4 @@ +spring.datasource.password: 'password' +spring.datasource.url: jdbc:mysql://localhost:3306/db_integration +spring.datasource.username: user +bael.property=integrationValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index bf89182d8a..c2bb5deb45 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -9,7 +9,17 @@ spring.datasource.username=SA spring.datasource.password=password app.name=MyApp app.description=${app.name} is a Spring Boot application +logging.file.name=myapplication.log bael.property=defaultValue #--- -spring.config.activate.on-profile=prod +spring.config.activate.on-profile=multidocument-dev +spring.datasource.password=password +spring.datasource.url=jdbc:h2:dev +spring.datasource.username=SA +bael.property=devValue +#--- +spring.config.activate.on-profile=multidocument-prod +spring.datasource.password=password +spring.datasource.url=jdbc:h2:prod +spring.datasource.username=prodUser bael.property=prodValue \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index 00baeade9c..33aabb2459 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -1,17 +1,17 @@ -logging: - file: - name: myapplication.log -spring: - datasource: - password: 'password' - url: jdbc:h2:dev - username: SA +bael: + root-level-property: defaultRootLevelValue --- spring: + config: + activate: + on-profile: multidocument-staging datasource: password: 'password' - url: jdbc:mysql://localhost:3306/db_production - username: user + url: jdbc:h2:staging + username: SA +bael: + property: stagingValue +--- application: servers: - ip: '127.0.0.1' diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java similarity index 77% rename from spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java index 61c76aef84..af1f7f705f 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentPropertiesFileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DefaultMultidocumentFilesIntegrationTest.java @@ -10,13 +10,17 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import com.baeldung.boot.properties.DemoApplication; @SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) -public class DefaultMultidocumentPropertiesFileIntegrationTest { +public class DefaultMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; @Test public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("defaultValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..54188595c0 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/DevMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-dev") +public class DevMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("devValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..f7968f51ad --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-integration") +public class IntegrationMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("integrationValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java similarity index 76% rename from spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java index 39bc2da3ba..9270995da0 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentPropertiesFileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/ProdMultidocumentFilesIntegrationTest.java @@ -11,14 +11,18 @@ import org.springframework.test.context.ActiveProfiles; import com.baeldung.boot.properties.DemoApplication; @SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) -@ActiveProfiles("prod") -public class ProdMultidocumentPropertiesFileIntegrationTest { +@ActiveProfiles("multidocument-prod") +public class ProdMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; @Test public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("prodValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java new file mode 100644 index 0000000000..8040c93ee0 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/StagingMultidocumentFilesIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.boot.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.boot.properties.DemoApplication; + +@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK) +@ActiveProfiles("multidocument-staging") +public class StagingMultidocumentFilesIntegrationTest { + + @Value("${bael.property}") + private String baelCustomProperty; + + @Value("${bael.root-level-property}") + private String baelRootProperty; + + @Test + public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { + assertThat(baelCustomProperty).isEqualTo("stagingValue"); + assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); + } +} From 93e15677438aeebf523d40bdbb003e237261c764 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:12:12 +0530 Subject: [PATCH 071/149] JAVA-4013: Moved 1 article to spring-boot-data-2 --- spring-boot-modules/spring-boot-data-2/pom.xml | 9 +++++++++ .../hikari/ApplicationWithHikariConnectionPool.java | 0 .../java/com/baeldung/hikari/HikariIntegrationTest.java | 0 3 files changed, 9 insertions(+) rename {spring-5 => spring-boot-modules/spring-boot-data-2}/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java (100%) rename {spring-5 => spring-boot-modules/spring-boot-data-2}/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java (100%) diff --git a/spring-boot-modules/spring-boot-data-2/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml index 199a204500..fb0d5f2053 100644 --- a/spring-boot-modules/spring-boot-data-2/pom.xml +++ b/spring-boot-modules/spring-boot-data-2/pom.xml @@ -16,6 +16,15 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java similarity index 100% rename from spring-5/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/ApplicationWithHikariConnectionPool.java diff --git a/spring-5/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java similarity index 100% rename from spring-5/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/hikari/HikariIntegrationTest.java From 6052fd6bc85e12d1ddfe9d2b9e7054d307074858 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:14:11 +0530 Subject: [PATCH 072/149] JAVA-4013: Moved 2 articles to spring-testing-2 --- spring-5/pom.xml | 13 +------------ testing-modules/spring-testing-2/pom.xml | 17 +++++++++++++++++ .../Spring5JUnit4ConcurrentIntegrationTest.java | 2 +- .../com/baeldung/enabledif}/EnabledOnJava8.java | 2 +- ...Spring5EnabledAnnotationIntegrationTest.java | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) rename {spring-5/src/test/java/com/baeldung => testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent}/Spring5JUnit4ConcurrentIntegrationTest.java (98%) rename {spring-5/src/test/java/com/baeldung/jupiter => testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif}/EnabledOnJava8.java (93%) rename {spring-5/src/test/java/com/baeldung/jupiter => testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif}/Spring5EnabledAnnotationIntegrationTest.java (97%) diff --git a/spring-5/pom.xml b/spring-5/pom.xml index eadfb5e512..e368bcacba 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -133,18 +133,7 @@ - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - methods - true - - + diff --git a/testing-modules/spring-testing-2/pom.xml b/testing-modules/spring-testing-2/pom.xml index 807b84c676..4686a20202 100644 --- a/testing-modules/spring-testing-2/pom.xml +++ b/testing-modules/spring-testing-2/pom.xml @@ -54,8 +54,25 @@ + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + methods + true + + + + 1.12.2 + 2.21.0 \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java similarity index 98% rename from spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java index 7e494465b2..8a0947ba44 100644 --- a/spring-5/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/concurrent/Spring5JUnit4ConcurrentIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.concurrent; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java similarity index 93% rename from spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java index c6d3b7ff10..01bdc176e0 100644 --- a/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/EnabledOnJava8.java @@ -1,4 +1,4 @@ -package com.baeldung.jupiter; +package com.baeldung.enabledif; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java similarity index 97% rename from spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java rename to testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java index 35363e0ea3..b6ccb2204b 100644 --- a/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationIntegrationTest.java +++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/enabledif/Spring5EnabledAnnotationIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.jupiter; +package com.baeldung.enabledif; import static org.junit.jupiter.api.Assertions.assertTrue; From 013902b25364fe5044361f2b536b8af5c2b6557a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 12 Jan 2021 19:14:50 +0530 Subject: [PATCH 073/149] JAVA-4013: README changes --- spring-5/README.md | 3 --- spring-boot-modules/spring-boot-data-2/README.md | 1 + testing-modules/spring-testing-2/README.md | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-5/README.md b/spring-5/README.md index cef0fedb4f..cce18bedf8 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -4,13 +4,10 @@ This module contains articles about Spring 5 ### Relevant Articles -- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) - [Spring 5 Functional Bean Registration](https://www.baeldung.com/spring-5-functional-beans) - [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](https://www.baeldung.com/spring-5-junit-config) -- [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) - [Introduction to Spring REST Docs](https://www.baeldung.com/spring-rest-docs) - [Spring ResponseStatusException](https://www.baeldung.com/spring-response-status-exception) - [Spring Assert Statements](https://www.baeldung.com/spring-assert) -- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) - [Difference between \ vs \](https://www.baeldung.com/spring-contextannotation-contextcomponentscan) - [Finding the Spring Version](https://www.baeldung.com/spring-find-version) diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md index d5020ce354..c21ce02a2e 100644 --- a/spring-boot-modules/spring-boot-data-2/README.md +++ b/spring-boot-modules/spring-boot-data-2/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper) +- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) diff --git a/testing-modules/spring-testing-2/README.md b/testing-modules/spring-testing-2/README.md index 702a02ff27..16b47adeac 100644 --- a/testing-modules/spring-testing-2/README.md +++ b/testing-modules/spring-testing-2/README.md @@ -1,3 +1,5 @@ ## Relevant Articles: - [Guide to @DynamicPropertySource in Spring](https://www.baeldung.com/spring-dynamicpropertysource) +- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests) +- [Spring 5 Testing with @EnabledIf Annotation](https://www.baeldung.com/spring-5-enabledIf) From 1a0655a189734d2d9b50611acf2987d69a2e02f7 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 13 Jan 2021 10:26:38 -0300 Subject: [PATCH 074/149] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests These are potential issues, since the dependency is included in the root pom --- testing-modules/spring-testing/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index 9fe0fd8895..9e0c986bb2 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -39,6 +39,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + org.springframework spring-core From 1ed7c56596a3f29f55b79b85c1a88e7279a2f2bc Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 13 Jan 2021 11:28:41 -0300 Subject: [PATCH 075/149] changes related to spring-boot-modules/spring-boot-testing boot 2.4.0 upgrade --- spring-boot-modules/spring-boot-testing/pom.xml | 11 +++++++++++ .../BindingYMLPropertiesUnitTest.java | 4 ++-- .../execution/LoadSpringContextIntegrationTest.java | 4 ++-- .../src/test/resources/application.yml | 8 ++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index 5bf626f165..50a1ace2fa 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -51,6 +51,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java index 5543f5e9e8..99c128997e 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java @@ -7,13 +7,13 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(value = ServerConfig.class) @ActiveProfiles("test") public class BindingYMLPropertiesUnitTest { diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java index 6698094550..483c67b7a2 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -19,7 +19,7 @@ import static org.mockito.Mockito.verify; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class }, - initializers = ConfigFileApplicationContextInitializer.class) + initializers = ConfigDataApplicationContextInitializer.class) public class LoadSpringContextIntegrationTest { @SpyBean TaskService taskService; diff --git a/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml b/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml index 1b46b0f1ff..056b5baffc 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml +++ b/spring-boot-modules/spring-boot-testing/src/test/resources/application.yml @@ -1,5 +1,7 @@ spring: - profiles: test + config: + activate: + on-profile: test server: address: ip: 192.168.0.4 @@ -7,7 +9,9 @@ server: imgs: /etc/test/imgs --- spring: - profiles: dev + config: + activate: + on-profile: dev server: address: ip: 192.168.0.5 From 3af803eb73f0ea9b3e643c66f6cba20fc8d52dd2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:11:46 +0800 Subject: [PATCH 076/149] Update README.md --- core-java-modules/core-java-io-4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md index 7cc38bb9fe..c837e2bffc 100644 --- a/core-java-modules/core-java-io-4/README.md +++ b/core-java-modules/core-java-io-4/README.md @@ -4,5 +4,5 @@ This module contains articles about core Java input and output (IO) ### Relevant Articles: -- [Java File Separator vs File Path Separator] +- [Java File Separator vs File Path Separator](https://www.baeldung.com/java-file-vs-file-path-separator) - [[<-- Prev]](/core-java-modules/core-java-io-3) From 974f0f34273b65f08a5f64fd08ebf68133d54383 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:13:45 +0800 Subject: [PATCH 077/149] Update README.md --- jackson-modules/jackson-conversions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson-modules/jackson-conversions-2/README.md b/jackson-modules/jackson-conversions-2/README.md index 71c5578525..9986fe75b5 100644 --- a/jackson-modules/jackson-conversions-2/README.md +++ b/jackson-modules/jackson-conversions-2/README.md @@ -9,4 +9,5 @@ This module contains articles about Jackson conversions. - [Converting JSON to CSV in Java](https://www.baeldung.com/java-converting-json-to-csv) - [How to Process YAML with Jackson](https://www.baeldung.com/jackson-yaml) - [Jackson Streaming API](https://www.baeldung.com/jackson-streaming-api) +- [Jackson: java.util.LinkedHashMap cannot be cast to X](https://www.baeldung.com/jackson-linkedhashmap-cannot-be-cast) - More articles: [[<-- prev]](../jackson-conversions) From 5d14cdd74619575db8617f54ec0dc682ea2961a4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 00:15:43 +0800 Subject: [PATCH 078/149] Create README.md --- core-java-modules/core-java-concurrency-advanced-4/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/README.md diff --git a/core-java-modules/core-java-concurrency-advanced-4/README.md b/core-java-modules/core-java-concurrency-advanced-4/README.md new file mode 100644 index 0000000000..98f2894515 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Binary Semaphore vs Reentrant Lock](https://www.baeldung.com/java-binary-semaphore-vs-reentrant-lock) From eddab4c557548bce7c83bcdacf8800eb0f6c7e64 Mon Sep 17 00:00:00 2001 From: Emmanuel Yasa Date: Thu, 14 Jan 2021 01:36:35 +0800 Subject: [PATCH 079/149] [BAEL-4601] Revision: Simplifies assertions --- .../jpa/hibernateunproxy/HibernateProxyIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java index a831639f5d..717745bb13 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/hibernateunproxy/HibernateProxyIntegrationTest.java @@ -27,7 +27,7 @@ public class HibernateProxyIntegrationTest { @Test public void givenPaymentReceipt_whenAccessingPayment_thenVerifyType() { PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); - Assert.assertEquals(true, paymentReceipt.getPayment() instanceof HibernateProxy); + Assert.assertTrue(paymentReceipt.getPayment() instanceof HibernateProxy); } @Test @@ -39,7 +39,7 @@ public class HibernateProxyIntegrationTest { entityManager.persist(payment); entityManager.getTransaction().commit(); - Assert.assertEquals(true, webUser instanceof HibernateProxy); + Assert.assertTrue(webUser instanceof HibernateProxy); } @Test @@ -53,7 +53,7 @@ public class HibernateProxyIntegrationTest { @Test public void givenPaymentReceipt_whenPaymentIsUnproxied_thenReturnRealEntityObject() { PaymentReceipt paymentReceipt = entityManager.find(PaymentReceipt.class, 3L); - Assert.assertEquals(true, Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); + Assert.assertTrue(Hibernate.unproxy(paymentReceipt.getPayment()) instanceof CreditCardPayment); } private static void populateH2DB() { From 0785727da410d21dcf1b67660d84210583a93dd9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 14 Jan 2021 13:45:12 +0800 Subject: [PATCH 080/149] Create README.md --- guest/core-kotlin/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 guest/core-kotlin/README.md diff --git a/guest/core-kotlin/README.md b/guest/core-kotlin/README.md new file mode 100644 index 0000000000..c211773f27 --- /dev/null +++ b/guest/core-kotlin/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Kotlin vs Java](https://www.baeldung.com/kotlin/kotlin-vs-java) From 7e51af38d962b0f26f630bc0db1527778a7c4f87 Mon Sep 17 00:00:00 2001 From: CHANDRAKANT Kumar Date: Thu, 14 Jan 2021 15:18:33 +0530 Subject: [PATCH 081/149] Corrected the name of unit test to mark them as manual. --- ....java => MyCounterJCStressManualTest.java} | 8 ++- ...> MyCounterMultithreadedTCManualTest.java} | 12 ++-- .../concurrent/MyCounterSimpleManualTest.java | 63 +++++++++++++++++++ .../concurrent/MyCounterSimpleUnitTest.java | 60 ------------------ .../MyCounterTempusFugitManualTest.java | 41 ++++++++++++ .../MyCounterTempusFugitUnitTest.java | 37 ----------- .../MyCounterThreadWeaverManualTest.java | 48 ++++++++++++++ .../MyCounterThreadWeaverUnitTest.java | 44 ------------- 8 files changed, 167 insertions(+), 146 deletions(-) rename core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/{MyCounterJCStressUnitTest.java => MyCounterJCStressManualTest.java} (74%) rename core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/{MyCounterMultithreadedTCUnitTest.java => MyCounterMultithreadedTCManualTest.java} (59%) create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java create mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java delete mode 100644 core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java similarity index 74% rename from core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java rename to core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java index 6c76505347..0e6b41d1e9 100644 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressUnitTest.java +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterJCStressManualTest.java @@ -10,11 +10,17 @@ import org.openjdk.jcstress.annotations.Outcome; import org.openjdk.jcstress.annotations.State; import org.openjdk.jcstress.infra.results.I_Result; +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ @JCStressTest @Outcome(id = "1", expect = ACCEPTABLE_INTERESTING, desc = "One update lost.") @Outcome(id = "2", expect = ACCEPTABLE, desc = "Both updates.") @State -public class MyCounterJCStressUnitTest { +public class MyCounterJCStressManualTest { private MyCounter counter; diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java similarity index 59% rename from core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java rename to core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java index 8a0bedf6c2..985e316635 100644 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCUnitTest.java +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterMultithreadedTCManualTest.java @@ -1,12 +1,17 @@ package com.baeldung.concurrent; -import org.junit.Ignore; import org.junit.Test; import edu.umd.cs.mtc.MultithreadedTestCase; import edu.umd.cs.mtc.TestFramework; -public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase { +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterMultithreadedTCManualTest extends MultithreadedTestCase { private MyCounter counter; @@ -29,9 +34,8 @@ public class MyCounterMultithreadedTCUnitTest extends MultithreadedTestCase { assertEquals(2, counter.getCount()); } - @Ignore @Test public void testCounter() throws Throwable { - TestFramework.runManyTimes(new MyCounterMultithreadedTCUnitTest(), 1000); + TestFramework.runManyTimes(new MyCounterMultithreadedTCManualTest(), 1000); } } diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java new file mode 100644 index 0000000000..cba30da34b --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleManualTest.java @@ -0,0 +1,63 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.junit.Test; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterSimpleManualTest { + + @Test + public void testCounter() { + MyCounter counter = new MyCounter(); + for (int i = 0; i < 500; i++) + counter.increment(); + assertEquals(500, counter.getCount()); + } + + @Test + public void testCounterWithConcurrency() throws InterruptedException { + int numberOfThreads = 100; + ExecutorService service = Executors.newFixedThreadPool(10); + CountDownLatch latch = new CountDownLatch(numberOfThreads); + MyCounter counter = new MyCounter(); + for (int i = 0; i < numberOfThreads; i++) { + service.execute(() -> { + counter.increment(); + latch.countDown(); + }); + } + latch.await(); + assertEquals(numberOfThreads, counter.getCount()); + } + + @Test + public void testSummationWithConcurrencyAndWait() throws InterruptedException { + int numberOfThreads = 2; + ExecutorService service = Executors.newFixedThreadPool(10); + CountDownLatch latch = new CountDownLatch(numberOfThreads); + MyCounter counter = new MyCounter(); + for (int i = 0; i < numberOfThreads; i++) { + service.submit(() -> { + try { + counter.incrementWithWait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + latch.countDown(); + }); + } + latch.await(); + assertEquals(numberOfThreads, counter.getCount()); + } + +} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java deleted file mode 100644 index 9a405e7e24..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterSimpleUnitTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.junit.Ignore; -import org.junit.Test; - -public class MyCounterSimpleUnitTest { - - @Test - public void testCounter() { - MyCounter counter = new MyCounter(); - for (int i = 0; i < 500; i++) - counter.increment(); - assertEquals(500, counter.getCount()); - } - - @Ignore - @Test - public void testCounterWithConcurrency() throws InterruptedException { - int numberOfThreads = 100; - ExecutorService service = Executors.newFixedThreadPool(10); - CountDownLatch latch = new CountDownLatch(numberOfThreads); - MyCounter counter = new MyCounter(); - for (int i = 0; i < numberOfThreads; i++) { - service.execute(() -> { - counter.increment(); - latch.countDown(); - }); - } - latch.await(); - assertEquals(numberOfThreads, counter.getCount()); - } - - @Ignore - @Test - public void testSummationWithConcurrencyAndWait() throws InterruptedException { - int numberOfThreads = 2; - ExecutorService service = Executors.newFixedThreadPool(10); - CountDownLatch latch = new CountDownLatch(numberOfThreads); - MyCounter counter = new MyCounter(); - for (int i = 0; i < numberOfThreads; i++) { - service.submit(() -> { - try { - counter.incrementWithWait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - latch.countDown(); - }); - } - latch.await(); - assertEquals(numberOfThreads, counter.getCount()); - } - -} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java new file mode 100644 index 0000000000..a4ac643f7e --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitManualTest.java @@ -0,0 +1,41 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import org.junit.AfterClass; +import org.junit.Rule; +import org.junit.Test; + +import com.google.code.tempusfugit.concurrency.ConcurrentRule; +import com.google.code.tempusfugit.concurrency.RepeatingRule; +import com.google.code.tempusfugit.concurrency.annotations.Concurrent; +import com.google.code.tempusfugit.concurrency.annotations.Repeating; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterTempusFugitManualTest { + + @Rule + public ConcurrentRule concurrently = new ConcurrentRule(); + @Rule + public RepeatingRule rule = new RepeatingRule(); + + private static MyCounter counter = new MyCounter(); + + @Test + @Concurrent(count = 2) + @Repeating(repetition = 10) + public void runsMultipleTimes() { + counter.increment(); + } + + @AfterClass + public static void annotatedTestRunsMultipleTimes() throws InterruptedException { + assertEquals(counter.getCount(), 20); + } + +} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java deleted file mode 100644 index 36a2031e78..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterTempusFugitUnitTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - -import com.google.code.tempusfugit.concurrency.ConcurrentRule; -import com.google.code.tempusfugit.concurrency.RepeatingRule; -import com.google.code.tempusfugit.concurrency.annotations.Concurrent; -import com.google.code.tempusfugit.concurrency.annotations.Repeating; - -public class MyCounterTempusFugitUnitTest { - - @Rule - public ConcurrentRule concurrently = new ConcurrentRule(); - @Rule - public RepeatingRule rule = new RepeatingRule(); - - private static MyCounter counter = new MyCounter(); - - @Ignore - @Test - @Concurrent(count = 2) - @Repeating(repetition = 10) - public void runsMultipleTimes() { - counter.increment(); - } - - @AfterClass - public static void annotatedTestRunsMultipleTimes() throws InterruptedException { - assertEquals(counter.getCount(), 20); - } - -} diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java new file mode 100644 index 0000000000..2acfc4ee71 --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverManualTest.java @@ -0,0 +1,48 @@ +package com.baeldung.concurrent; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.google.testing.threadtester.AnnotatedTestRunner; +import com.google.testing.threadtester.ThreadedAfter; +import com.google.testing.threadtester.ThreadedBefore; +import com.google.testing.threadtester.ThreadedMain; +import com.google.testing.threadtester.ThreadedSecondary; + +/** + * This is defined as a manual test because it tries to simulate the race conditions + * in a concurrent program that is poorly designed and hence may fail nondeterministically. + * This will help the CI jobs to ignore these tests and a developer to run them manually. + * + */ +public class MyCounterThreadWeaverManualTest { + + private MyCounter counter; + + @ThreadedBefore + public void before() { + counter = new MyCounter(); + } + + @ThreadedMain + public void mainThread() { + counter.increment(); + } + + @ThreadedSecondary + public void secondThread() { + counter.increment(); + } + + @ThreadedAfter + public void after() { + assertEquals(2, counter.getCount()); + } + + @Test + public void testCounter() { + new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java deleted file mode 100644 index e65a963584..0000000000 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/MyCounterThreadWeaverUnitTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.concurrent; - -import static org.junit.Assert.assertEquals; - -import org.junit.Ignore; -import org.junit.Test; - -import com.google.testing.threadtester.AnnotatedTestRunner; -import com.google.testing.threadtester.ThreadedAfter; -import com.google.testing.threadtester.ThreadedBefore; -import com.google.testing.threadtester.ThreadedMain; -import com.google.testing.threadtester.ThreadedSecondary; - -public class MyCounterThreadWeaverUnitTest { - - private MyCounter counter; - - @ThreadedBefore - public void before() { - counter = new MyCounter(); - } - - @ThreadedMain - public void mainThread() { - counter.increment(); - } - - @ThreadedSecondary - public void secondThread() { - counter.increment(); - } - - @ThreadedAfter - public void after() { - assertEquals(2, counter.getCount()); - } - - @Ignore - @Test - public void testCounter() { - new AnnotatedTestRunner().runTests(this.getClass(), MyCounter.class); - } - -} \ No newline at end of file From 1c5185b54940c2089fc7a558f2bb614e3d256217 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 14 Jan 2021 11:43:32 -0300 Subject: [PATCH 082/149] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests --- spring-boot-modules/spring-boot-environment/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index d34bbd18c0..e3a8186cbf 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -33,6 +33,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + org.springframework.boot From 52db422b6c303b1b9018a85d842981ff427eece4 Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Fri, 15 Jan 2021 04:34:00 +0530 Subject: [PATCH 083/149] BAEL-4695 - Evaluating a Math Expression in Java (#10345) * Added code for checking if a class is abstract or not. * Renamed test name as per review comments. * BAEL-4695 - Added code to evaluate math expressions. * BAEL-4695 - Added test case for math function. * BAEL-4695 Added consistent examples and entry in parent pom. * BAEL-4695 - Added more examples --- .../core-java-lang-math-3/pom.xml | 35 +++++++ .../EvalauteMathExpressionsUnitTest.java | 91 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 3 files changed, 127 insertions(+) create mode 100644 core-java-modules/core-java-lang-math-3/pom.xml create mode 100644 core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java diff --git a/core-java-modules/core-java-lang-math-3/pom.xml b/core-java-modules/core-java-lang-math-3/pom.xml new file mode 100644 index 0000000000..27c2372ab6 --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + core-java-lang-math-3 + 0.0.1-SNAPSHOT + core-java-lang-math-3 + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + net.objecthunter + exp4j + 0.4.8 + + + + com.fathzer + javaluator + 3.0.3 + + + + + + + + + diff --git a/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java new file mode 100644 index 0000000000..a251e8d545 --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/math/evaluate/EvalauteMathExpressionsUnitTest.java @@ -0,0 +1,91 @@ +package com.baeldung.math.evaluate; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.fathzer.soft.javaluator.DoubleEvaluator; +import com.fathzer.soft.javaluator.StaticVariableSet; + +import net.objecthunter.exp4j.Expression; +import net.objecthunter.exp4j.ExpressionBuilder; + +public class EvalauteMathExpressionsUnitTest { + + @Test + public void givenSimpleExpression_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("3+2").build(); + double result = expression.evaluate(); + Assertions.assertEquals(5, result); + } + + @Test + public void givenTwoVariables_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("3x+2y").variables("x", "y") + .build() + .setVariable("x", 2) + .setVariable("y", 3); + double result = expression.evaluate(); + Assertions.assertEquals(12, result); + } + + @Test + public void givenMathFunctions_whenCallEvaluateMethod_thenSuccess() { + Expression expression = new ExpressionBuilder("sin(x)*sin(x)+cos(x)*cos(x)").variables("x") + .build() + .setVariable("x", 0.5); + double result = expression.evaluate(); + Assertions.assertEquals(1, result); + } + + @Test + public void givenExpression_whenCallEvaluateMethod_thenSuccess() { + String expression = "3+2"; + DoubleEvaluator eval = new DoubleEvaluator(); + Double result = eval.evaluate(expression); + Assertions.assertEquals(5, result); + } + + @Test + public void givenVariables_whenCallEvaluateMethod_thenSuccess() { + String expression = "3*x+2*y"; + DoubleEvaluator eval = new DoubleEvaluator(); + StaticVariableSet variables = new StaticVariableSet(); + variables.set("x", 2.0); + variables.set("y", 3.0); + Double result = eval.evaluate(expression, variables); + Assertions.assertEquals(12, result); + } + + @Test + public void givenMathFunction_whenCallEvaluateMethod_thenSuccess() { + String expression = "sin(x)*sin(x)+cos(x)*cos(x)"; + DoubleEvaluator eval = new DoubleEvaluator(); + StaticVariableSet variables = new StaticVariableSet(); + variables.set("x", 0.5); + Double result = eval.evaluate(expression, variables); + Assertions.assertEquals(1, result); + } + + @Test + public void givenJavaScriptingApiAndSimpleExpression_whenCallEvalMethod_thenSuccess() throws ScriptException { + ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); + ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript"); + String expression = "3+2"; + Integer result = (Integer) scriptEngine.eval(expression); + Assertions.assertEquals(5, result); + } + + @Test + public void givenJavaScriptingApi_whenCallEvalMethod_thenSuccess() throws ScriptException { + ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); + ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript"); + String expression = "x=2; y=3; 3*x+2*y;"; + Double result = (Double) scriptEngine.eval(expression); + Assertions.assertEquals(12, result); + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 140d5efe3b..2d342c4216 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -84,6 +84,7 @@ core-java-lang-3 core-java-lang-math core-java-lang-math-2 + core-java-lang-math-3 core-java-lang-oop-constructors core-java-lang-oop-patterns core-java-lang-oop-generics From e54423ce83c48abda00ca295eb1d29ef6501a28e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:15:41 +0530 Subject: [PATCH 084/149] JAVA-4010: Added new module and moved 3 articles to it --- .../spring-resttemplate-3/.gitignore | 12 ++ .../spring-resttemplate-3/README.md | 11 ++ .../spring-resttemplate-3/pom.xml | 29 +++++ .../lists/EmployeeApplication.java | 16 +++ .../lists/client/EmployeeClient.java | 120 ++++++++++++++++++ .../lists/controller/EmployeeResource.java | 46 +++++++ .../resttemplate/lists/dto/Employee.java | 40 ++++++ .../resttemplate/lists/dto/EmployeeList.java | 29 +++++ .../lists/service/EmployeeService.java | 25 ++++ .../web/upload/app/UploadApplication.java | 17 +++ .../client/MultipartFileUploadClient.java | 61 +++++++++ .../upload/controller/FileServerResource.java | 43 +++++++ .../src/main/resources/application.properties | 2 + .../src/main/resources/logback.xml | 23 ++++ .../java/com/baeldung/SpringContextTest.java | 15 +++ .../LargeFileDownloadIntegrationTest.java | 105 +++++++++++++++ .../src/test/resources/.gitignore | 13 ++ .../src/test/resources/logback-test.xml | 23 ++++ 18 files changed, 630 insertions(+) create mode 100644 spring-web-modules/spring-resttemplate-3/.gitignore create mode 100644 spring-web-modules/spring-resttemplate-3/README.md create mode 100644 spring-web-modules/spring-resttemplate-3/pom.xml create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties create mode 100644 spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore create mode 100644 spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml diff --git a/spring-web-modules/spring-resttemplate-3/.gitignore b/spring-web-modules/spring-resttemplate-3/.gitignore new file mode 100644 index 0000000000..8f98975dc9 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/.gitignore @@ -0,0 +1,12 @@ +*.class + +#folders# +/target +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/README.md b/spring-web-modules/spring-resttemplate-3/README.md new file mode 100644 index 0000000000..6a00d226db --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/README.md @@ -0,0 +1,11 @@ +## Spring RestTemplate + +This module contains articles about Spring RestTemplate + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles: +- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload) +- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list) +- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/pom.xml b/spring-web-modules/spring-resttemplate-3/pom.xml new file mode 100644 index 0000000000..b1c26e002f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + spring-resttemplate-3 + 0.1-SNAPSHOT + spring-resttemplate-3 + war + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + + diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java new file mode 100644 index 0000000000..1967d4f2aa --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.resttemplate.lists; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Sample application used to demonstrate working with Lists and RestTemplate. + */ +@SpringBootApplication +public class EmployeeApplication +{ + public static void main(String[] args) + { + SpringApplication.run(EmployeeApplication.class, args); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java new file mode 100644 index 0000000000..49e375f9cc --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java @@ -0,0 +1,120 @@ +package com.baeldung.resttemplate.lists.client; + +import com.baeldung.resttemplate.lists.dto.Employee; +import com.baeldung.resttemplate.lists.dto.EmployeeList; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Arrays.asList; + +/** + * Application that shows how to use Lists with RestTemplate. + */ +public class EmployeeClient { + public static void main(String[] args) { + EmployeeClient employeeClient = new EmployeeClient(); + + System.out.println("Calling GET for entity using arrays"); + employeeClient.getForEntityEmployeesAsArray(); + + System.out.println("Calling GET using ParameterizedTypeReference"); + employeeClient.getAllEmployeesUsingParameterizedTypeReference(); + + System.out.println("Calling GET using wrapper class"); + employeeClient.getAllEmployeesUsingWrapperClass(); + + System.out.println("Calling POST using normal lists"); + employeeClient.createEmployeesUsingLists(); + + System.out.println("Calling POST using wrapper class"); + employeeClient.createEmployeesUsingWrapperClass(); + } + + public EmployeeClient() { + + } + + public Employee[] getForEntityEmployeesAsArray() { + + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity response = + restTemplate.getForEntity( + "http://localhost:8082/spring-rest/employees/", + Employee[].class); + + Employee[] employees = response.getBody(); + + assert employees != null; + asList(employees).forEach(System.out::println); + + return employees; + + } + + + public List getAllEmployeesUsingParameterizedTypeReference() { + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity> response = + restTemplate.exchange( + "http://localhost:8082/spring-rest/employees/", + HttpMethod.GET, + null, + new ParameterizedTypeReference>() { + }); + + List employees = response.getBody(); + + assert employees != null; + employees.forEach(System.out::println); + + return employees; + } + + public List getAllEmployeesUsingWrapperClass() { + RestTemplate restTemplate = new RestTemplate(); + + EmployeeList response = + restTemplate.getForObject( + "http://localhost:8082/spring-rest/employees/v2", + EmployeeList.class); + + List employees = response.getEmployees(); + + employees.forEach(System.out::println); + + return employees; + } + + public void createEmployeesUsingLists() { + RestTemplate restTemplate = new RestTemplate(); + + List newEmployees = new ArrayList<>(); + newEmployees.add(new Employee(3, "Intern")); + newEmployees.add(new Employee(4, "CEO")); + + restTemplate.postForObject( + "http://localhost:8082/spring-rest/employees/", + newEmployees, + ResponseEntity.class); + } + + public void createEmployeesUsingWrapperClass() { + RestTemplate restTemplate = new RestTemplate(); + + List newEmployees = new ArrayList<>(); + newEmployees.add(new Employee(3, "Intern")); + newEmployees.add(new Employee(4, "CEO")); + + restTemplate.postForObject( + "http://localhost:8082/spring-rest/employees/v2/", + new EmployeeList(newEmployees), + ResponseEntity.class); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java new file mode 100644 index 0000000000..8a4d510f63 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java @@ -0,0 +1,46 @@ +package com.baeldung.resttemplate.lists.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.resttemplate.lists.dto.Employee; +import com.baeldung.resttemplate.lists.dto.EmployeeList; +import com.baeldung.resttemplate.lists.service.EmployeeService; + +import java.util.List; + +@RestController +@RequestMapping("/employees") +public class EmployeeResource +{ + @Autowired + private EmployeeService employeeService; + + @RequestMapping(method = RequestMethod.GET, path = "/") + public List getEmployees() + { + return employeeService.getAllEmployees(); + } + + @RequestMapping(method = RequestMethod.GET, path = "/v2") + public EmployeeList getEmployeesUsingWrapperClass() + { + List employees = employeeService.getAllEmployees(); + return new EmployeeList(employees); + } + + @RequestMapping(method = RequestMethod.POST, path = "/") + public void addEmployees(@RequestBody List employees) + { + employeeService.addEmployees(employees); + } + + @RequestMapping(method = RequestMethod.POST, path = "/v2") + public void addEmployeesUsingWrapperClass(@RequestBody EmployeeList employeeWrapper) + { + employeeService.addEmployees(employeeWrapper.getEmployees()); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java new file mode 100644 index 0000000000..0754c13c5b --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java @@ -0,0 +1,40 @@ +package com.baeldung.resttemplate.lists.dto; + +public class Employee { + + public long id; + public String title; + + public Employee() + { + + } + + public Employee(long id, String title) + { + this.id = id; + this.title = title; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public String toString() + { + return "Employee #" + id + "[" + title + "]"; + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java new file mode 100644 index 0000000000..eeabbfe450 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java @@ -0,0 +1,29 @@ +package com.baeldung.resttemplate.lists.dto; + +import java.util.ArrayList; +import java.util.List; + +public class EmployeeList +{ + public List employees; + + public EmployeeList() + { + employees = new ArrayList<>(); + } + + public EmployeeList(List employees) + { + this.employees = employees; + } + + public void setEmployees(List employees) + { + this.employees = employees; + } + + public List getEmployees() + { + return employees; + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java new file mode 100644 index 0000000000..8a1773483a --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java @@ -0,0 +1,25 @@ +package com.baeldung.resttemplate.lists.service; + +import org.springframework.stereotype.Service; + +import com.baeldung.resttemplate.lists.dto.Employee; + +import java.util.ArrayList; +import java.util.List; + +@Service("EmployeeListService") +public class EmployeeService +{ + public List getAllEmployees() + { + List employees = new ArrayList<>(); + employees.add(new Employee(1, "Manager")); + employees.add(new Employee(2, "Java Developer")); + return employees; + } + + public void addEmployees(List employees) + { + employees.forEach(e -> System.out.println("Adding new employee " + e)); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java new file mode 100644 index 0000000000..f3b1c0dc6f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/app/UploadApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.web.upload.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; + +@EnableAutoConfiguration +@ComponentScan("com.baeldung.web.upload") +@SpringBootApplication +public class UploadApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(UploadApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java new file mode 100644 index 0000000000..547aec17a0 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java @@ -0,0 +1,61 @@ +package com.baeldung.web.upload.client; + +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class MultipartFileUploadClient { + + public static void main(String[] args) throws IOException { + uploadSingleFile(); + uploadMultipleFile(); + } + + private static void uploadSingleFile() throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("file", getTestFile()); + + + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + String serverUrl = "http://localhost:8082/spring-rest/fileserver/singlefileupload/"; + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); + System.out.println("Response code: " + response.getStatusCode()); + } + + private static void uploadMultipleFile() throws IOException { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("files", getTestFile()); + body.add("files", getTestFile()); + body.add("files", getTestFile()); + + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + String serverUrl = "http://localhost:8082/spring-rest/fileserver/multiplefileupload/"; + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); + System.out.println("Response code: " + response.getStatusCode()); + } + + public static Resource getTestFile() throws IOException { + Path testFile = Files.createTempFile("test-file", ".txt"); + System.out.println("Creating and Uploading Test File: " + testFile); + Files.write(testFile, "Hello World !!, This is a test file.".getBytes()); + return new FileSystemResource(testFile.toFile()); + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java new file mode 100644 index 0000000000..3863a8f20d --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java @@ -0,0 +1,43 @@ +package com.baeldung.web.upload.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +@RestController +@RequestMapping("/fileserver") +public class FileServerResource { + + @RequestMapping(path = "/singlefileupload/", method = RequestMethod.POST) + public ResponseEntity processFile(@RequestParam("file") MultipartFile file) throws IOException { + + byte[] bytes = file.getBytes(); + + System.out.println("File Name: " + file.getOriginalFilename()); + System.out.println("File Content Type: " + file.getContentType()); + System.out.println("File Content:\n" + new String(bytes)); + + return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); + } + + @RequestMapping(path = "/multiplefileupload/", method = RequestMethod.POST) + public ResponseEntity processFile(@RequestParam("files") List files) throws IOException { + + for (MultipartFile file : files) { + byte[] bytes = file.getBytes(); + + System.out.println("File Name: " + file.getOriginalFilename()); + System.out.println("File Content Type: " + file.getContentType()); + System.out.println("File Content:\n" + new String(bytes)); + } + + return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties new file mode 100644 index 0000000000..1a26e3ad99 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8082 +server.servlet.context-path=/spring-rest \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml b/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml new file mode 100644 index 0000000000..9f48d36486 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/resources/logback.xml @@ -0,0 +1,23 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..26972a0aca --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,15 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { com.baeldung.web.upload.app.UploadApplication.class, }) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java new file mode 100644 index 0000000000..d8fc58319f --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/largefile/LargeFileDownloadIntegrationTest.java @@ -0,0 +1,105 @@ +package com.baeldung.largefile; + +import java.io.File; +import java.io.FileOutputStream; + +import org.assertj.core.api.Assertions; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.util.StreamUtils; +import org.springframework.web.client.RestTemplate; + +public class LargeFileDownloadIntegrationTest { + + static String FILE_URL = "http://ovh.net/files/1Mio.dat"; + + RestTemplate restTemplate; + + @Before + public void setUp() { + restTemplate = new RestTemplate(); + } + + @Test + public void givenResumableUrl_whenUrlCalledByHeadOption_thenExpectHeadersAvailable() { + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + Assertions + .assertThat(headers.get("Accept-Ranges")) + .contains("bytes"); + Assertions + .assertThat(headers.getContentLength()) + .isGreaterThan(0); + } + + @Test + public void givenResumableUrl_whenDownloadCompletely_thenExpectCorrectFileSize() { + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + long contentLength = headers.getContentLength(); + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, null, clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + Assertions + .assertThat(file.length()) + .isEqualTo(contentLength); + } + + @Test + public void givenResumableUrl_whenDownloadRange_thenExpectFileSizeEqualOrLessThanRange() { + int range = 10; + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + Assertions + .assertThat(file.length()) + .isLessThanOrEqualTo(range); + } + + @Test + public void givenResumableUrl_whenPauseDownloadAndResume_thenExpectCorrectFileSize() { + + int range = 10; + + HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); + long contentLength = headers.getContentLength(); + + File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { + File ret = File.createTempFile("download", "tmp"); + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); + return ret; + }); + + Assert.assertNotNull(file); + + Assertions + .assertThat(file.length()) + .isLessThanOrEqualTo(range); + + restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest + .getHeaders() + .set("Range", String.format("bytes=%d-%d", file.length(), contentLength)), clientHttpResponse -> { + StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(file, true)); + return file; + }); + + Assertions + .assertThat(file.length()) + .isEqualTo(contentLength); + + } + +} diff --git a/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore b/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..9f48d36486 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/resources/logback-test.xml @@ -0,0 +1,23 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + \ No newline at end of file From 2931dcbeb495abfac95cfbb28eaa2f1a97d69a28 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:16:39 +0530 Subject: [PATCH 085/149] JAVA-4010: Moved 3 articles from this module --- .../spring-resttemplate/README.md | 3 - .../lists/EmployeeApplication.java | 16 --- .../lists/client/EmployeeClient.java | 120 ------------------ .../lists/controller/EmployeeResource.java | 46 ------- .../resttemplate/lists/dto/Employee.java | 40 ------ .../resttemplate/lists/dto/EmployeeList.java | 29 ----- .../lists/service/EmployeeService.java | 25 ---- .../web/upload/app/UploadApplication.java | 17 --- .../client/MultipartFileUploadClient.java | 61 --------- .../upload/controller/FileServerResource.java | 43 ------- .../java/com/baeldung/SpringContextTest.java | 6 +- .../LargeFileDownloadIntegrationTest.java | 109 ---------------- 12 files changed, 2 insertions(+), 513 deletions(-) delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java delete mode 100644 spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java delete mode 100644 spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java diff --git a/spring-web-modules/spring-resttemplate/README.md b/spring-web-modules/spring-resttemplate/README.md index 952f35e90b..e8c240d86b 100644 --- a/spring-web-modules/spring-resttemplate/README.md +++ b/spring-web-modules/spring-resttemplate/README.md @@ -11,10 +11,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RestTemplate Error Handling](https://www.baeldung.com/spring-rest-template-error-handling) - [Configure a RestTemplate with RestTemplateBuilder](https://www.baeldung.com/spring-rest-template-builder) - [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) -- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) - [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor) -- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload) -- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list) - [HTTP PUT vs HTTP PATCH in a REST API](https://www.baeldung.com/http-put-patch-difference-spring) ### NOTE: diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java deleted file mode 100644 index 1967d4f2aa..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.resttemplate.lists; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Sample application used to demonstrate working with Lists and RestTemplate. - */ -@SpringBootApplication -public class EmployeeApplication -{ - public static void main(String[] args) - { - SpringApplication.run(EmployeeApplication.class, args); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java deleted file mode 100644 index 49e375f9cc..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.baeldung.resttemplate.lists.client; - -import com.baeldung.resttemplate.lists.dto.Employee; -import com.baeldung.resttemplate.lists.dto.EmployeeList; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import java.util.ArrayList; -import java.util.List; - -import static java.util.Arrays.asList; - -/** - * Application that shows how to use Lists with RestTemplate. - */ -public class EmployeeClient { - public static void main(String[] args) { - EmployeeClient employeeClient = new EmployeeClient(); - - System.out.println("Calling GET for entity using arrays"); - employeeClient.getForEntityEmployeesAsArray(); - - System.out.println("Calling GET using ParameterizedTypeReference"); - employeeClient.getAllEmployeesUsingParameterizedTypeReference(); - - System.out.println("Calling GET using wrapper class"); - employeeClient.getAllEmployeesUsingWrapperClass(); - - System.out.println("Calling POST using normal lists"); - employeeClient.createEmployeesUsingLists(); - - System.out.println("Calling POST using wrapper class"); - employeeClient.createEmployeesUsingWrapperClass(); - } - - public EmployeeClient() { - - } - - public Employee[] getForEntityEmployeesAsArray() { - - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity response = - restTemplate.getForEntity( - "http://localhost:8082/spring-rest/employees/", - Employee[].class); - - Employee[] employees = response.getBody(); - - assert employees != null; - asList(employees).forEach(System.out::println); - - return employees; - - } - - - public List getAllEmployeesUsingParameterizedTypeReference() { - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity> response = - restTemplate.exchange( - "http://localhost:8082/spring-rest/employees/", - HttpMethod.GET, - null, - new ParameterizedTypeReference>() { - }); - - List employees = response.getBody(); - - assert employees != null; - employees.forEach(System.out::println); - - return employees; - } - - public List getAllEmployeesUsingWrapperClass() { - RestTemplate restTemplate = new RestTemplate(); - - EmployeeList response = - restTemplate.getForObject( - "http://localhost:8082/spring-rest/employees/v2", - EmployeeList.class); - - List employees = response.getEmployees(); - - employees.forEach(System.out::println); - - return employees; - } - - public void createEmployeesUsingLists() { - RestTemplate restTemplate = new RestTemplate(); - - List newEmployees = new ArrayList<>(); - newEmployees.add(new Employee(3, "Intern")); - newEmployees.add(new Employee(4, "CEO")); - - restTemplate.postForObject( - "http://localhost:8082/spring-rest/employees/", - newEmployees, - ResponseEntity.class); - } - - public void createEmployeesUsingWrapperClass() { - RestTemplate restTemplate = new RestTemplate(); - - List newEmployees = new ArrayList<>(); - newEmployees.add(new Employee(3, "Intern")); - newEmployees.add(new Employee(4, "CEO")); - - restTemplate.postForObject( - "http://localhost:8082/spring-rest/employees/v2/", - new EmployeeList(newEmployees), - ResponseEntity.class); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java deleted file mode 100644 index 8a4d510f63..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.resttemplate.lists.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.resttemplate.lists.dto.Employee; -import com.baeldung.resttemplate.lists.dto.EmployeeList; -import com.baeldung.resttemplate.lists.service.EmployeeService; - -import java.util.List; - -@RestController -@RequestMapping("/employees") -public class EmployeeResource -{ - @Autowired - private EmployeeService employeeService; - - @RequestMapping(method = RequestMethod.GET, path = "/") - public List getEmployees() - { - return employeeService.getAllEmployees(); - } - - @RequestMapping(method = RequestMethod.GET, path = "/v2") - public EmployeeList getEmployeesUsingWrapperClass() - { - List employees = employeeService.getAllEmployees(); - return new EmployeeList(employees); - } - - @RequestMapping(method = RequestMethod.POST, path = "/") - public void addEmployees(@RequestBody List employees) - { - employeeService.addEmployees(employees); - } - - @RequestMapping(method = RequestMethod.POST, path = "/v2") - public void addEmployeesUsingWrapperClass(@RequestBody EmployeeList employeeWrapper) - { - employeeService.addEmployees(employeeWrapper.getEmployees()); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java deleted file mode 100644 index 0754c13c5b..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.resttemplate.lists.dto; - -public class Employee { - - public long id; - public String title; - - public Employee() - { - - } - - public Employee(long id, String title) - { - this.id = id; - this.title = title; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString() - { - return "Employee #" + id + "[" + title + "]"; - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java deleted file mode 100644 index eeabbfe450..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.resttemplate.lists.dto; - -import java.util.ArrayList; -import java.util.List; - -public class EmployeeList -{ - public List employees; - - public EmployeeList() - { - employees = new ArrayList<>(); - } - - public EmployeeList(List employees) - { - this.employees = employees; - } - - public void setEmployees(List employees) - { - this.employees = employees; - } - - public List getEmployees() - { - return employees; - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java deleted file mode 100644 index 8a1773483a..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.resttemplate.lists.service; - -import org.springframework.stereotype.Service; - -import com.baeldung.resttemplate.lists.dto.Employee; - -import java.util.ArrayList; -import java.util.List; - -@Service("EmployeeListService") -public class EmployeeService -{ - public List getAllEmployees() - { - List employees = new ArrayList<>(); - employees.add(new Employee(1, "Manager")); - employees.add(new Employee(2, "Java Developer")); - return employees; - } - - public void addEmployees(List employees) - { - employees.forEach(e -> System.out.println("Adding new employee " + e)); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java deleted file mode 100644 index f3b1c0dc6f..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/app/UploadApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.web.upload.app; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.ComponentScan; - -@EnableAutoConfiguration -@ComponentScan("com.baeldung.web.upload") -@SpringBootApplication -public class UploadApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(UploadApplication.class, args); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java deleted file mode 100644 index 547aec17a0..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/client/MultipartFileUploadClient.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.web.upload.client; - -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class MultipartFileUploadClient { - - public static void main(String[] args) throws IOException { - uploadSingleFile(); - uploadMultipleFile(); - } - - private static void uploadSingleFile() throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - - MultiValueMap body = new LinkedMultiValueMap<>(); - body.add("file", getTestFile()); - - - HttpEntity> requestEntity = new HttpEntity<>(body, headers); - String serverUrl = "http://localhost:8082/spring-rest/fileserver/singlefileupload/"; - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); - System.out.println("Response code: " + response.getStatusCode()); - } - - private static void uploadMultipleFile() throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); - - MultiValueMap body = new LinkedMultiValueMap<>(); - body.add("files", getTestFile()); - body.add("files", getTestFile()); - body.add("files", getTestFile()); - - HttpEntity> requestEntity = new HttpEntity<>(body, headers); - String serverUrl = "http://localhost:8082/spring-rest/fileserver/multiplefileupload/"; - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.postForEntity(serverUrl, requestEntity, String.class); - System.out.println("Response code: " + response.getStatusCode()); - } - - public static Resource getTestFile() throws IOException { - Path testFile = Files.createTempFile("test-file", ".txt"); - System.out.println("Creating and Uploading Test File: " + testFile); - Files.write(testFile, "Hello World !!, This is a test file.".getBytes()); - return new FileSystemResource(testFile.toFile()); - } -} diff --git a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java b/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java deleted file mode 100644 index 3863a8f20d..0000000000 --- a/spring-web-modules/spring-resttemplate/src/main/java/com/baeldung/web/upload/controller/FileServerResource.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.web.upload.controller; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.List; - -@RestController -@RequestMapping("/fileserver") -public class FileServerResource { - - @RequestMapping(path = "/singlefileupload/", method = RequestMethod.POST) - public ResponseEntity processFile(@RequestParam("file") MultipartFile file) throws IOException { - - byte[] bytes = file.getBytes(); - - System.out.println("File Name: " + file.getOriginalFilename()); - System.out.println("File Content Type: " + file.getContentType()); - System.out.println("File Content:\n" + new String(bytes)); - - return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); - } - - @RequestMapping(path = "/multiplefileupload/", method = RequestMethod.POST) - public ResponseEntity processFile(@RequestParam("files") List files) throws IOException { - - for (MultipartFile file : files) { - byte[] bytes = file.getBytes(); - - System.out.println("File Name: " + file.getOriginalFilename()); - System.out.println("File Content Type: " + file.getContentType()); - System.out.println("File Content:\n" + new String(bytes)); - } - - return (new ResponseEntity<>("Successful", null, HttpStatus.OK)); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java index 43901cf37f..dc176f5322 100644 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java @@ -8,12 +8,10 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.responseheaders.ResponseHeadersApplication; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { ResponseHeadersApplication.class, - com.baeldung.web.upload.app.UploadApplication.class, - }) +@SpringBootTest(classes = { ResponseHeadersApplication.class }) public class SpringContextTest { @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { + public void whenSpringContextIsBootstrapped_thenNoExceptions() { } } diff --git a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java b/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java deleted file mode 100644 index eb5d01d06f..0000000000 --- a/spring-web-modules/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.resttemplate; - -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.util.StreamUtils; -import org.springframework.web.client.RestTemplate; - -import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.List; - -public class LargeFileDownloadIntegrationTest { - - static String FILE_URL = "http://ovh.net/files/1Mio.dat"; - - RestTemplate restTemplate; - - @Before - public void setUp() { - restTemplate = new RestTemplate(); - } - - @Test - public void givenResumableUrl_whenUrlCalledByHeadOption_thenExpectHeadersAvailable() { - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - Assertions - .assertThat(headers.get("Accept-Ranges")) - .contains("bytes"); - Assertions - .assertThat(headers.getContentLength()) - .isGreaterThan(0); - } - - @Test - public void givenResumableUrl_whenDownloadCompletely_thenExpectCorrectFileSize() { - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - long contentLength = headers.getContentLength(); - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, null, clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - Assertions - .assertThat(file.length()) - .isEqualTo(contentLength); - } - - @Test - public void givenResumableUrl_whenDownloadRange_thenExpectFileSizeEqualOrLessThanRange() { - int range = 10; - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - Assertions - .assertThat(file.length()) - .isLessThanOrEqualTo(range); - } - - @Test - public void givenResumableUrl_whenPauseDownloadAndResume_thenExpectCorrectFileSize() { - - int range = 10; - - HttpHeaders headers = restTemplate.headForHeaders(FILE_URL); - long contentLength = headers.getContentLength(); - - File file = restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=0-%d", range - 1)), clientHttpResponse -> { - File ret = File.createTempFile("download", "tmp"); - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(ret)); - return ret; - }); - - Assert.assertNotNull(file); - - Assertions - .assertThat(file.length()) - .isLessThanOrEqualTo(range); - - restTemplate.execute(FILE_URL, HttpMethod.GET, clientHttpRequest -> clientHttpRequest - .getHeaders() - .set("Range", String.format("bytes=%d-%d", file.length(), contentLength)), clientHttpResponse -> { - StreamUtils.copy(clientHttpResponse.getBody(), new FileOutputStream(file, true)); - return file; - }); - - Assertions - .assertThat(file.length()) - .isEqualTo(contentLength); - - } - -} From a0e7e3bf8005102b12167382e92988c93802b115 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 15 Jan 2021 23:17:03 +0530 Subject: [PATCH 086/149] JAVA-4010: Added new module to parent pom --- spring-web-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index cc2ffcf762..37ee84da25 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -37,6 +37,7 @@ spring-rest-testing spring-resttemplate spring-resttemplate-2 + spring-resttemplate-3 spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 From 6b462cd6c69679fedd58fe58e15df788a7e9faa2 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 15 Jan 2021 16:00:03 -0300 Subject: [PATCH 087/149] Improved spring-properties-file-outside-jar with new 2.4.0 feature --- .../additional.properties | 1 + .../spring-boot-environment/pom.xml | 21 +++++++++++++----- .../src/main/resources/application.properties | 5 +++-- ...ertyImportExternalFileIntegrationTest.java | 22 +++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 spring-boot-modules/spring-boot-environment/additional.properties create mode 100644 spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-environment/additional.properties b/spring-boot-modules/spring-boot-environment/additional.properties new file mode 100644 index 0000000000..676536efa5 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/additional.properties @@ -0,0 +1 @@ +bael.property1=value1 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index e3a8186cbf..a3aab63a2d 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -88,7 +89,6 @@ org.springframework.cloud spring-cloud-context - ${springcloud.version} @@ -99,6 +99,18 @@ + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud-version} + pom + import + + + + ${project.artifactId} @@ -153,9 +165,8 @@ 2.2 18.0 3.1.7 - 2.0.2.RELEASE 4.5.8 - 2.3.3.RELEASE + 2020.0.0 diff --git a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties index 27b7915cff..3d6f37230c 100644 --- a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties @@ -2,6 +2,7 @@ management.endpoints.web.exposure.include=* management.metrics.enable.root=true management.metrics.enable.jvm=true management.endpoint.restart.enabled=true -spring.datasource.jmx-enabled=false +spring.datasource.tomcat.jmx-enabled=false spring.main.allow-bean-definition-overriding=true -management.endpoint.shutdown.enabled=true \ No newline at end of file +management.endpoint.shutdown.enabled=true +spring.config.import=file:./additional.properties,optional:file:/Users/home/config/jdbc.properties \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java new file mode 100644 index 0000000000..04f5445639 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java @@ -0,0 +1,22 @@ +package com.baeldung.properties; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ApplicationPropertyImportExternalFileIntegrationTest { + + @Value("${bael.property1}") + String baelProperty; + + @Test + public void whenExternalisedPropertiesLoadedUsinApplicationProperties_thenReadValues() throws IOException { + assertEquals(baelProperty, "value1"); + } + +} From dce6c4fe126268493f334b278bd282856ab7bf05 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Fri, 15 Jan 2021 17:21:00 -0600 Subject: [PATCH 088/149] BAEL-4695: create and update README files (#10425) --- core-java-modules/core-java-lang-math-2/README.md | 2 +- core-java-modules/core-java-lang-math-3/README.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-lang-math-3/README.md diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md index a98ff863ac..5e1dc5af0e 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -14,4 +14,4 @@ - [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) - [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) - [Largest Power of 2 That Is Less Than the Given Number with Java](https://www.baeldung.com/java-largest-power-of-2-less-than-number) -- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math)[[Next -->]](/core-java-modules/core-java-lang-math-3) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md new file mode 100644 index 0000000000..9eee021f8f --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -0,0 +1,8 @@ +========= + +## Core Java 8 Cookbooks and Examples - Part 3 + +### Relevant articles: + +- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) From 77b00187def78bd518b51b2ba1603d49cdd76d08 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 16 Jan 2021 16:27:02 +0200 Subject: [PATCH 089/149] fix channel type, callback --- webrtc/src/main/resources/static/client.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webrtc/src/main/resources/static/client.js b/webrtc/src/main/resources/static/client.js index 059dc84bcb..9b3de9ef6d 100644 --- a/webrtc/src/main/resources/static/client.js +++ b/webrtc/src/main/resources/static/client.js @@ -38,11 +38,7 @@ var input = document.getElementById("messageInput"); function initialize() { var configuration = null; - peerConnection = new RTCPeerConnection(configuration, { - optional : [ { - RtpDataChannels : true - } ] - }); + peerConnection = new RTCPeerConnection(configuration); // Setup ice handling peerConnection.onicecandidate = function(event) { @@ -71,6 +67,11 @@ function initialize() { dataChannel.onclose = function() { console.log("data channel is closed"); }; + + peerConnection.ondatachannel = function (event) { + dataChannel = event.channel; + }; + } function createOffer() { From 72ca7fde484f8645078a0031e4bcf1a5db5587da Mon Sep 17 00:00:00 2001 From: Gilvan Ornelas Fernandes Filho Date: Sat, 16 Jan 2021 11:36:20 -0300 Subject: [PATCH 090/149] Fixing valid password condition --- .../pattern/cleanarchitecture/usercreation/CommonUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java index f7ba9dacc0..c4f105fad5 100644 --- a/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java +++ b/patterns/clean-architecture/src/main/java/com/baeldung/pattern/cleanarchitecture/usercreation/CommonUser.java @@ -15,7 +15,7 @@ class CommonUser implements User { @Override public boolean passwordIsValid() { - return password == null || password.length() > 5; + return password != null && password.length() > 5; } @Override From 82b5316bc444fe0032563b7d0511a4e90fff65cb Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 16 Jan 2021 12:20:54 -0300 Subject: [PATCH 091/149] fixed properties files notation --- .../application-multidocument-integration.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties index c4eeba2589..f3bac4c614 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application-multidocument-integration.properties @@ -1,4 +1,4 @@ -spring.datasource.password: 'password' -spring.datasource.url: jdbc:mysql://localhost:3306/db_integration -spring.datasource.username: user +spring.datasource.password=password +spring.datasource.url=jdbc:mysql://localhost:3306/db_integration +spring.datasource.username=user bael.property=integrationValue \ No newline at end of file From b9c81b0cedbcaa40ecb9978d3072a1f7939299ec Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sun, 17 Jan 2021 11:39:53 +0100 Subject: [PATCH 092/149] BAEL-4756 - Mockito MockSettings (#10423) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings Co-authored-by: Jonathan Cook --- .../mockito/mocksettings/AbstractCoffee.java | 15 +++++ .../mockito/mocksettings/SimpleService.java | 10 ++++ .../mocksettings/SpecialInterface.java | 5 ++ .../mocksettings/MockSettingsUnitTest.java | 56 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java new file mode 100644 index 0000000000..99fd686951 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/AbstractCoffee.java @@ -0,0 +1,15 @@ +package com.baeldung.mockito.mocksettings; + +public abstract class AbstractCoffee { + + protected String name; + + protected AbstractCoffee(String name) { + this.name = name; + } + + protected String getName() { + return name; + } + +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java new file mode 100644 index 0000000000..034517acbf --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SimpleService.java @@ -0,0 +1,10 @@ +package com.baeldung.mockito.mocksettings; + +public class SimpleService { + + public SimpleService(SpecialInterface special) { + Runnable runnable = (Runnable) special; + runnable.run(); + } + +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java new file mode 100644 index 0000000000..e5f88247d6 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/mocksettings/SpecialInterface.java @@ -0,0 +1,5 @@ +package com.baeldung.mockito.mocksettings; + +public interface SpecialInterface { + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java new file mode 100644 index 0000000000..596baf1954 --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.mockito.mocksettings; + +import static org.mockito.Answers.RETURNS_SMART_NULLS; +import static org.junit.Assert.assertEquals; +import static org.mockito.Answers.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.exceptions.verification.SmartNullPointerException; +import org.mockito.junit.MockitoJUnitRunner; + +import com.baeldung.mockito.fluentapi.Pizza; +import com.baeldung.mockito.fluentapi.PizzaService; + +@RunWith(MockitoJUnitRunner.class) +public class MockSettingsUnitTest { + + @Test(expected = SmartNullPointerException.class) + public void whenServiceMockedWithSmartNulls_thenExceptionHasExtraInfo() { + PizzaService service = mock(PizzaService.class, withSettings().defaultAnswer(RETURNS_SMART_NULLS)); + Pizza pizza = service.orderHouseSpecial(); + pizza.getSize(); + } + + @Test + public void whenServiceMockedWithNameAndVerboseLogging_thenLogsMethodInvocations() { + PizzaService service = mock(PizzaService.class, withSettings().name("pizzaServiceMock") + .verboseLogging()); + + Pizza pizza = mock(Pizza.class); + when(service.orderHouseSpecial()).thenReturn(pizza); + + service.orderHouseSpecial(); + + verify(service).orderHouseSpecial(); + } + + @Test + public void whenServiceMockedWithExtraInterfaces_thenConstructorSuccess() { + SpecialInterface specialMock = mock(SpecialInterface.class, withSettings().extraInterfaces(Runnable.class)); + new SimpleService(specialMock); + } + + @Test + public void whenMockSetupWithConstructor_thenConstructorIsInvoked() { + AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("expresso") + .defaultAnswer(CALLS_REAL_METHODS)); + + assertEquals("Coffee name: ", "expresso", coffeeSpy.getName()); + } + +} From 1b127b9b00b1cb9bc25e606c2f74a107b3bb0d6b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 18 Jan 2021 12:55:30 -0300 Subject: [PATCH 093/149] removed Sprng Boot version override, upgraded cloud version and added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests --- spring-cloud/spring-cloud-config/client/pom.xml | 15 +++++++++++++-- spring-cloud/spring-cloud-config/pom.xml | 3 +-- spring-cloud/spring-cloud-config/server/pom.xml | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-config/client/pom.xml b/spring-cloud/spring-cloud-config/client/pom.xml index 805a50bfdb..2400520d2b 100644 --- a/spring-cloud/spring-cloud-config/client/pom.xml +++ b/spring-cloud/spring-cloud-config/client/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 client client @@ -26,6 +26,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + diff --git a/spring-cloud/spring-cloud-config/pom.xml b/spring-cloud/spring-cloud-config/pom.xml index 5db18a7245..bfe17044e0 100644 --- a/spring-cloud/spring-cloud-config/pom.xml +++ b/spring-cloud/spring-cloud-config/pom.xml @@ -33,8 +33,7 @@ - Hoxton.SR4 - 2.3.3.RELEASE + 2020.0.0 diff --git a/spring-cloud/spring-cloud-config/server/pom.xml b/spring-cloud/spring-cloud-config/server/pom.xml index e32a473cd6..f0f1e43612 100644 --- a/spring-cloud/spring-cloud-config/server/pom.xml +++ b/spring-cloud/spring-cloud-config/server/pom.xml @@ -1,11 +1,11 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 server server - + com.baeldung.spring.cloud spring-cloud-config @@ -30,6 +30,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + From b33fd1ee9c03cac4c3a5f919babc9728f2a38c2b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 18 Jan 2021 15:50:55 -0300 Subject: [PATCH 094/149] Added additional scenario to reflect scenario mentioned in spring-feature-flags (even though the article does not point to any module in the codebase) --- .../src/main/resources/application.properties | 4 ++++ .../src/main/resources/application.yml | 3 +++ .../IntegrationMultidocumentFilesIntegrationTest.java | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties index c2bb5deb45..a079837942 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.properties @@ -11,6 +11,7 @@ app.name=MyApp app.description=${app.name} is a Spring Boot application logging.file.name=myapplication.log bael.property=defaultValue +bael.otherProperty=defaultOtherValue #--- spring.config.activate.on-profile=multidocument-dev spring.datasource.password=password @@ -18,6 +19,9 @@ spring.datasource.url=jdbc:h2:dev spring.datasource.username=SA bael.property=devValue #--- +spring.config.activate.on-profile=multidocument-integration-extension +bael.otherProperty=integrationExtensionOtherValue +#--- spring.config.activate.on-profile=multidocument-prod spring.datasource.password=password spring.datasource.url=jdbc:h2:prod diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index 33aabb2459..da398f5beb 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -2,6 +2,9 @@ bael: root-level-property: defaultRootLevelValue --- spring: + profiles: + group: + multidocument-integration: multidocument-integration-extension config: activate: on-profile: multidocument-staging diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java index f7968f51ad..e0727154d0 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/multidocument/IntegrationMultidocumentFilesIntegrationTest.java @@ -17,12 +17,16 @@ public class IntegrationMultidocumentFilesIntegrationTest { @Value("${bael.property}") private String baelCustomProperty; + @Value("${bael.otherProperty}") + private String baelCustomOtherProperty; + @Value("${bael.root-level-property}") private String baelRootProperty; @Test public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() { assertThat(baelCustomProperty).isEqualTo("integrationValue"); + assertThat(baelCustomOtherProperty).isEqualTo("integrationExtensionOtherValue"); assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue"); } } From caadfb7a911bdba043de472d9c30843a57d0d781 Mon Sep 17 00:00:00 2001 From: Bruno Fontana Date: Tue, 19 Jan 2021 08:58:58 -0300 Subject: [PATCH 095/149] Adding clean-architecture to parent POM. Fixing UserResponseFormatter test name. --- ...seFormatterTests.java => UserResponseFormatterUnitTest.java} | 2 +- patterns/pom.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/{UserResponseFormatterTests.java => UserResponseFormatterUnitTest.java} (96%) diff --git a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java similarity index 96% rename from patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java rename to patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java index f8ebde5f10..e394cbbf94 100644 --- a/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterTests.java +++ b/patterns/clean-architecture/src/test/java/com/baeldung/pattern/cleanarchitecture/usercreation/UserResponseFormatterUnitTest.java @@ -9,7 +9,7 @@ import org.springframework.web.server.ResponseStatusException; import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseFormatter; import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseModel; -class UserResponseFormatterTests { +class UserResponseFormatterUnitTest { UserResponseFormatter userResponseFormatter = new UserResponseFormatter(); diff --git a/patterns/pom.xml b/patterns/pom.xml index a179d75ffe..112eecb606 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -24,6 +24,7 @@ hexagonal-architecture intercepting-filter solid + clean-architecture From 8f428d768807b78be053957082e053aacfe04b26 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 19 Jan 2021 12:22:02 -0300 Subject: [PATCH 096/149] fix extra test configuration properties error --- .../src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index da398f5beb..10570bb738 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -1,10 +1,11 @@ bael: root-level-property: defaultRootLevelValue ---- spring: profiles: group: multidocument-integration: multidocument-integration-extension +--- +spring: config: activate: on-profile: multidocument-staging From 42ca93dbbf17207d806cbcd2a9fc35429bfca406 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 19 Jan 2021 15:44:33 -0300 Subject: [PATCH 097/149] added junit-vintage-engine dependency to avoid issues with existing JUnit4 tests for spring-boot module --- spring-boot-modules/spring-boot/pom.xml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot/pom.xml b/spring-boot-modules/spring-boot/pom.xml index c1f1ea3072..9023ae92f3 100644 --- a/spring-boot-modules/spring-boot/pom.xml +++ b/spring-boot-modules/spring-boot/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -58,6 +58,17 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + io.dropwizard.metrics From 98cce29a737a390516a024404dab9ea8a7e9ca32 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:39:59 +0800 Subject: [PATCH 098/149] Update README.md --- java-collections-maps-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-collections-maps-3/README.md b/java-collections-maps-3/README.md index 4da8547824..39ac8575fa 100644 --- a/java-collections-maps-3/README.md +++ b/java-collections-maps-3/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Java Map With Case-Insensitive Keys](https://www.baeldung.com/java-map-with-case-insensitive-keys) +- [Using a Byte Array as Map Key in Java](https://www.baeldung.com/java-map-key-byte-array) From 1e16299ac522244bccbb84557c612ed8d316dbef Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:42:24 +0800 Subject: [PATCH 099/149] Update README.md --- java-numbers-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-4/README.md b/java-numbers-4/README.md index 7db25b283c..cdd53692e0 100644 --- a/java-numbers-4/README.md +++ b/java-numbers-4/README.md @@ -2,3 +2,4 @@ - [Probability in Java](https://www.baeldung.com/java-probability) - [Understanding the & 0xff Value in Java](https://www.baeldung.com/java-and-0xff) +- [Determine if an Integer’s Square Root Is an Integer in Java](https://www.baeldung.com/java-find-if-square-root-is-integer) From 093fb533fa14d317f95b9a966442132d8d0b4378 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:44:10 +0800 Subject: [PATCH 100/149] Update README.md --- core-java-modules/core-java-lang-math-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md index 9eee021f8f..dda3013407 100644 --- a/core-java-modules/core-java-lang-math-3/README.md +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -5,4 +5,5 @@ ### Relevant articles: - [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) +- [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) From f7f017037f4f0a7be3583721d9f171b0b0b33a27 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:46:34 +0800 Subject: [PATCH 101/149] Update README.md --- persistence-modules/java-jpa-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md index 1949207364..9c9e040825 100644 --- a/persistence-modules/java-jpa-3/README.md +++ b/persistence-modules/java-jpa-3/README.md @@ -9,3 +9,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [Defining Indexes in JPA](https://www.baeldung.com/jpa-indexes) - [JPA CascadeType.REMOVE vs orphanRemoval](https://www.baeldung.com/jpa-cascade-remove-vs-orphanremoval) - [A Guide to MultipleBagFetchException in Hibernate](https://www.baeldung.com/java-hibernate-multiplebagfetchexception) +- [How to Convert a Hibernate Proxy to a Real Entity Object](https://www.baeldung.com/hibernate-proxy-to-real-entity-object) From c3f92c8b3846e571ff3ded44692fd8fb1b5b0cb7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:50:15 +0800 Subject: [PATCH 102/149] Create README.md --- patterns/clean-architecture/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 patterns/clean-architecture/README.md diff --git a/patterns/clean-architecture/README.md b/patterns/clean-architecture/README.md new file mode 100644 index 0000000000..aad8608447 --- /dev/null +++ b/patterns/clean-architecture/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Clean Architecture with Spring Boot](https://www.baeldung.com/spring-boot-clean-architecture) From 59e4bd98114616735188ffcb3171bcecb8c8e4be Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 20 Jan 2021 12:37:10 -0300 Subject: [PATCH 103/149] updated deprecation: HandlerInterceptorAdapter class -> HandlerInterceptor interface --- .../baeldung/loginredirect/LoginPageInterceptor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java index aa93201f37..f08b824369 100644 --- a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java +++ b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java @@ -1,16 +1,16 @@ package com.baeldung.loginredirect; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.http.HttpStatus; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.util.UrlPathHelper; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -class LoginPageInterceptor extends HandlerInterceptorAdapter { +class LoginPageInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { From c5a57eb06572f3baa619eea20ae666d96a7d3b69 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:31:35 +0530 Subject: [PATCH 104/149] JAVA-4012: Moved 1 article to spring-boot-persistence-mongodb --- .../src/main/resources/mongoConfig.xml | 31 ++++++++++++++++++ .../src/main/resources/test.png | Bin .../com/baeldung/gridfs/GridFSLiveTest.java | 0 .../src/main/resources/mongoConfig.xml | 5 --- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml rename persistence-modules/{spring-data-mongodb => spring-boot-persistence-mongodb}/src/main/resources/test.png (100%) rename persistence-modules/{spring-data-mongodb => spring-boot-persistence-mongodb}/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java (100%) diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml new file mode 100644 index 0000000000..c5b9068de3 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/mongoConfig.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-mongodb/src/main/resources/test.png b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/test.png similarity index 100% rename from persistence-modules/spring-data-mongodb/src/main/resources/test.png rename to persistence-modules/spring-boot-persistence-mongodb/src/main/resources/test.png diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java similarity index 100% rename from persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java rename to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java diff --git a/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml b/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml index 074a203b1a..5067bec78e 100644 --- a/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml +++ b/persistence-modules/spring-data-mongodb/src/main/resources/mongoConfig.xml @@ -14,11 +14,6 @@ - - - - - From 52c492f679220b77ec0488da155e766b40b165e1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:32:54 +0530 Subject: [PATCH 105/149] JAVA-4012: README changes --- persistence-modules/spring-boot-persistence-mongodb/README.md | 1 + persistence-modules/spring-data-mongodb/README.md | 2 -- persistence-modules/spring-jpa/README.md | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-mongodb/README.md b/persistence-modules/spring-boot-persistence-mongodb/README.md index f277ef66ca..aade8eb1c0 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/README.md +++ b/persistence-modules/spring-boot-persistence-mongodb/README.md @@ -3,3 +3,4 @@ - [Auto-Generated Field for MongoDB using Spring Boot](https://www.baeldung.com/spring-boot-mongodb-auto-generated-field) - [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb) - [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file) +- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index 381bf83fa8..0be8c57036 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -7,10 +7,8 @@ - [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) - [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) -- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) - [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) -- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) - [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index f60609e0de..937890cd13 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -7,6 +7,7 @@ - [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database) - [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source) - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - More articles: [[next -->]](/spring-jpa-2) ### Eclipse Config From a679b1997864a78543c1fdc4522a3743f0b448f1 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 20 Jan 2021 22:39:36 +0530 Subject: [PATCH 106/149] JAVA-4012: removed entry for article --- persistence-modules/spring-data-jpa-annotations/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-annotations/README.md b/persistence-modules/spring-data-jpa-annotations/README.md index 5f1c8dbc27..1ee579cf6c 100644 --- a/persistence-modules/spring-data-jpa-annotations/README.md +++ b/persistence-modules/spring-data-jpa-annotations/README.md @@ -4,7 +4,6 @@ This module contains articles about annotations used in Spring Data JPA ### Relevant articles -- [Spring Data Annotations](https://www.baeldung.com/spring-data-annotations) - [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) - [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable) - [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) From 5b1e5979782cbf0d6b468adcb01ef370df43a09a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 11:47:41 -0300 Subject: [PATCH 107/149] Updated deprecated BodyInserters.fromObject method, in favor of BodyInserters.fromValue --- .../com/baeldung/web/reactive/client/WebClientController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index a719259328..09134701e9 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -38,7 +38,7 @@ public class WebClientController { // request header specification WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromObject("data")); + WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); // inserters BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters @@ -49,7 +49,7 @@ public class WebClientController { map.add("key2", "value2"); // BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromObject("body"); + BodyInserter inserter3 = BodyInserters.fromValue("body"); // responses WebClient.ResponseSpec response1 = uri1.body(inserter3) From 14506a542df37ff132f307a35eeb91dfeba7dd66 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 11:50:55 -0300 Subject: [PATCH 108/149] removed unused reactor-spring version property --- spring-5-reactive/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 3b7383f726..60c8b90e16 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -149,7 +149,6 @@ - 1.0.1.RELEASE 1.1.3 1.0 1.0 From 52d458c05f5c1dd2eec3bb6aca1b2b0f9d362de7 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 12:43:26 -0300 Subject: [PATCH 109/149] formatted WebClientController class --- .../reactive/client/WebClientController.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 09134701e9..7c0dc1cff7 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -1,8 +1,17 @@ package com.baeldung.web.reactive.client; +import java.net.URI; +import java.nio.charset.Charset; +import java.time.ZonedDateTime; +import java.util.Collections; + import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; -import org.springframework.http.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -10,12 +19,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; -import java.net.URI; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.Collections; +import reactor.core.publisher.Mono; @RestController public class WebClientController { @@ -41,8 +46,7 @@ public class WebClientController { WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters - .fromPublisher(Subscriber::onComplete, String.class); + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "value1"); From dd60782928c438d33d05c07889eba964c3f62318 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 12:44:06 -0300 Subject: [PATCH 110/149] Added timeout WebClient configuration, as in article --- .../reactive/client/WebClientController.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 7c0dc1cff7..3132a4173d 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,6 +4,7 @@ import java.net.URI; import java.nio.charset.Charset; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; @@ -12,6 +13,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -20,7 +22,12 @@ import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import io.netty.channel.ChannelOption; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClient; +import reactor.netty.tcp.TcpClient; @RestController public class WebClientController { @@ -75,6 +82,19 @@ public class WebClientController { return WebClient.create("http://localhost:8081"); } + private WebClient createWebClientConfiguringTimeout() { + TcpClient tcpClient = TcpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) + .doOnConnected(connection -> { + connection.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)); + connection.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)); + }); + + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient))) + .build(); + } + private WebClient createWebClientWithServerURLAndDefaultValues() { return WebClient.builder() .baseUrl("http://localhost:8081") From 1f7e0f06b6d8286f8a053ad38a385ef41bd55bec Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 14:25:30 -0300 Subject: [PATCH 111/149] updated timeout logic due to deprecation --- .../web/reactive/client/WebClientController.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 3132a4173d..66f787eda3 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -27,7 +27,6 @@ import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; -import reactor.netty.tcp.TcpClient; @RestController public class WebClientController { @@ -83,15 +82,13 @@ public class WebClientController { } private WebClient createWebClientConfiguringTimeout() { - TcpClient tcpClient = TcpClient.create() + HttpClient httpClient = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(connection -> { - connection.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)); - connection.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)); - }); + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient))) + .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); } From e6ab521b6127a9949515da3ad47aac66e8963cf9 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Thu, 21 Jan 2021 14:57:06 -0300 Subject: [PATCH 112/149] added LinkedMultiValueMap usage for inserter declaration, as in article --- .../com/baeldung/web/reactive/client/WebClientController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 66f787eda3..34de13bc28 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -13,8 +13,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -58,7 +60,7 @@ public class WebClientController { map.add("key1", "value1"); map.add("key2", "value2"); - // BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); + BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); BodyInserter inserter3 = BodyInserters.fromValue("body"); // responses From d90c7fed48fd86207471f821305ec8bbc109df54 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Fri, 22 Jan 2021 08:53:02 +0100 Subject: [PATCH 113/149] =?UTF-8?q?BAEL-4644:=20Small=20test=20to=20check?= =?UTF-8?q?=20Java=20JIT=20compiler=20performances=20vs=20C++=20=E2=80=A6?= =?UTF-8?q?=20(#10412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-4644: Small test to check Java JIT compiler performances vs C++ and JS * BAEL-4644: Remove CSV with performance test results * Revert "BAEL-4644: Remove CSV with performance test results" This reverts commit a69c9667 --- .../src/main/external/Fibonacci.cpp | 19 ++++ .../src/main/external/Fibonacci.js | 14 +++ .../performancetests/jit/Fibonacci.java | 20 ++++ .../FibonacciPerformancesResults.csv | 103 ++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 performance-tests/src/main/external/Fibonacci.cpp create mode 100644 performance-tests/src/main/external/Fibonacci.js create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java create mode 100644 performance-tests/src/main/resources/FibonacciPerformancesResults.csv diff --git a/performance-tests/src/main/external/Fibonacci.cpp b/performance-tests/src/main/external/Fibonacci.cpp new file mode 100644 index 0000000000..d23603c2ea --- /dev/null +++ b/performance-tests/src/main/external/Fibonacci.cpp @@ -0,0 +1,19 @@ +#include +#include + +using namespace std; + +int fibonacci(int n) { + if (n <= 1) + return n; + return fibonacci(n - 1) + fibonacci(n - 2); +} + +int main() { + for (int i = 0; i < 100; i++) { + auto startTime = chrono::high_resolution_clock::now().time_since_epoch(); + int result = fibonacci(12); + auto totalTime = chrono::high_resolution_clock::now().time_since_epoch() - startTime; + cout << totalTime << "\n"; + } +} \ No newline at end of file diff --git a/performance-tests/src/main/external/Fibonacci.js b/performance-tests/src/main/external/Fibonacci.js new file mode 100644 index 0000000000..ba41bf3ab9 --- /dev/null +++ b/performance-tests/src/main/external/Fibonacci.js @@ -0,0 +1,14 @@ +function fibonacci(index) { + if (index <= 1) + return index; + return fibonacci(index-1) + fibonacci(index-2); +} + +for (var i=0; i<100; i++) { + var startTime = process.hrtime.bigint(); + var result = fibonacci(12); + var totalTime = process.hrtime.bigint() - startTime; + console.log(totalTime); +} + + \ No newline at end of file diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java b/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java new file mode 100644 index 0000000000..c980093128 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/jit/Fibonacci.java @@ -0,0 +1,20 @@ +package com.baeldung.performancetests.jit; + +public class Fibonacci { + + public static void main(String[] args) { + for (int i=0; i<100; i++) { + long startTime = System.nanoTime(); + int result = fibonacci(12); + long totalTime = System.nanoTime() - startTime; + System.out.println(totalTime); + } + } + + private static int fibonacci(int index) { + if (index <= 1) + return index; + return fibonacci(index-1) + fibonacci(index-2); + } + +} diff --git a/performance-tests/src/main/resources/FibonacciPerformancesResults.csv b/performance-tests/src/main/resources/FibonacciPerformancesResults.csv new file mode 100644 index 0000000000..01a1f3dd90 --- /dev/null +++ b/performance-tests/src/main/resources/FibonacciPerformancesResults.csv @@ -0,0 +1,103 @@ +Runs;Java using JIT;Java without JIT;C++ without O2;C++ with O2;JavaScript +1;21900;10572;8684;2643;35115 +2;60790;10572;8306;2643;20389 +3;1888;24543;7551;2265;20390 +4;4153;25675;8307;2265;19256 +5;1888;26053;8307;2265;19257 +6;5664;25675;8307;1887;35115 +7;1510;25676;29829;2266;20012 +8;1510;26053;7929;2643;35493 +9;1511;23787;7929;1888;40023 +10;3776;26431;26053;3776;20012 +11;1510;25676;7929;2265;35115 +12;1510;10195;7552;3775;19256 +13;17746;10572;7552;1888;40024 +14;26431;10194;7552;2265;19257 +15;1133;10195;8685;2265;18501 +16;1133;10572;7929;2265;18879 +17;1133;10572;7929;1888;53995 +18;756;10195;7929;1888;35115 +19;1133;10195;7930;2266;19634 +20;756;10573;7552;2266;37003 +21;1133;9817;7552;1888;35115 +22;1133;10194;7930;2266;32472 +23;1133;10195;7929;2266;18879 +24;755;10195;8307;3776;19257 +25;755;10195;7551;1888;34738 +26;1510;10194;7551;2265;18501 +27;3776;10194;7929;2266;33227 +28;1888;37758;9440;1888;19634 +29;1133;10573;8306;1888;32472 +30;1133;26430;7929;2265;32849 +31;1133;24165;8306;4153;32850 +32;755;24166;7929;2643;18879 +33;1133;10572;24920;4153;32850 +34;755;23788;10194;2643;19257 +35;756;23788;12837;4154;18501 +36;755;11328;8307;2643;33227 +37;1132;29829;8307;7174;1000211 +38;755;36625;8307;4531;39646 +39;1133;10950;7929;2643;34360 +40;1133;10950;7929;4531;3021 +41;1133;10573;7929;2643;2643 +42;755;29829;15104;2643;2643 +43;755;29829;13971;2643;3398 +44;1133;10950;8685;5664;3021 +45;1133;10950;9817;3020;3398 +46;1133;10950;8684;3776;3020 +47;1888;30962;7930;3020;3021 +48;1132;10950;8307;2643;3399 +49;1133;29451;7929;2265;2266 +50;1133;29452;8307;23033;2265 +51;755;10950;7929;2643;2266 +52;755;10950;7930;2643;2643 +53;755;11327;7929;4908;2265 +54;755;11328;7929;2265;2643 +55;1133;10572;7929;18879;16236 +56;756;36248;7929;2643;2643 +57;755;10572;7929;2265;2643 +58;755;10950;9818;2644;2643 +59;1132;10950;7929;2266;2643 +60;20012;30206;7929;2266;3021 +61;1133;30206;7929;2266;16613 +62;1511;30206;7552;2266;2643 +63;3021;30207;8307;1888;2643 +64;1510;10950;7929;1888;2266 +65;1510;30207;7929;2266;2644 +66;1888;30207;8307;2265;2643 +67;1511;29829;7929;2266;2643 +68;1888;10950;7930;2265;2266 +69;1510;29829;7929;21145;3020 +70;1511;29829;7929;1888;16613 +71;1510;30206;7929;2643;2265 +72;1510;10950;7929;2266;2644 +73;1888;10573;24921;18124;2266 +74;1888;10573;9062;6797;2644 +75;1888;10950;7929;2265;2643 +76;1133;10950;7929;2266;2644 +77;1133;29829;12460;2266;3020 +78;755;11328;8307;2643;2266 +79;755;11327;8684;2266;2643 +80;1133;30206;8307;2266;2643 +81;1133;29829;7929;2266;2266 +82;1888;30206;7929;2266;16236 +83;1510;11327;8307;2266;16613 +84;1888;11327;7929;2265;2643 +85;1133;10573;8307;6042;2266 +86;1133;10950;7929;2643;2266 +87;1133;10950;9817;2265;2265 +88;755;10950;24165;2643;2643 +89;755;11328;7929;3399;2643 +90;755;10950;8307;4909;3020 +91;755;10572;7552;23787;3020 +92;1133;10572;7929;2643;3021 +93;1132;10572;8307;2643;2643 +94;1132;10950;7551;2266;3398 +95;755;10950;23788;2265;2644 +96;755;10573;7551;1888;2265 +97;755;29829;12460;2266;2643 +98;1132;30207;7929;2266;2265 +99;1133;30206;7929;2265;2266 +100;755;10572;7929;2265;2643 +;;;;; +;;;;; From 10318d1145c2d2a87ec3e5d718aa8122c2609a9a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 10:29:15 -0300 Subject: [PATCH 114/149] updated inserter3 as in article --- .../com/baeldung/web/reactive/client/WebClientController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 34de13bc28..70919d8a2e 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -61,7 +61,8 @@ public class WebClientController { map.add("key2", "value2"); BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue("body"); + BodyInserter inserter3 = BodyInserters.fromValue(new Object()); + BodyInserter inserter4 = BodyInserters.fromValue("body"); // responses WebClient.ResponseSpec response1 = uri1.body(inserter3) From 814369e38cf68f9e3ff428c92bca3f044520bcf2 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 10:49:47 -0300 Subject: [PATCH 115/149] added exchange and retrieve examples as in teh article, updated due to deprecation --- .../baeldung/web/reactive/client/WebClientController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 70919d8a2e..de4f20a13f 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -72,8 +72,12 @@ public class WebClientController { .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()) .retrieve(); - WebClient.ResponseSpec response2 = requestSpec2.retrieve(); - + String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + String response3 = uri2.retrieve() + .bodyToMono(String.class) + .block(); + WebClient.ResponseSpec response4 = requestSpec2.retrieve(); } private WebClient createWebClient() { From 1b78d4be310efbb6dbaacac028b2e14305738e60 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 12:33:54 -0300 Subject: [PATCH 116/149] fixed and improved WebClient integration test --- .../reactive/client/WebClientApplication.java | 13 +++++ .../reactive/client/WebClientController.java | 7 ++- .../client/WebTestClientIntegrationTest.java | 54 ++++++++++++++++--- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java new file mode 100644 index 0000000000..f104ad30f1 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.web.reactive.client; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebClientApplication{ + + public static void main(String[] args) { + SpringApplication.run(WebClientApplication.class, args); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index de4f20a13f..2d42e848b2 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,6 +4,8 @@ import java.net.URI; import java.nio.charset.Charset; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; @@ -35,7 +37,10 @@ public class WebClientController { @ResponseStatus(HttpStatus.OK) @GetMapping("/resource") - public void getResource() { + public Map getResource() { + Map response = new HashMap<>(); + response.put("field", "value"); + return response; } public void demonstrateWebClient() { diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java index 2e37f2ffbd..07a4c81c91 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientIntegrationTest.java @@ -1,11 +1,11 @@ package com.baeldung.web.client; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ApplicationContext; import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; @@ -13,18 +13,23 @@ import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.WebHandler; -import com.baeldung.reactive.Spring5ReactiveApplication; +import com.baeldung.web.reactive.client.WebClientApplication; +import com.baeldung.web.reactive.client.WebClientController; import reactor.core.publisher.Mono; -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5ReactiveApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@WithMockUser +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class WebTestClientIntegrationTest { @LocalServerPort private int port; + @Autowired + private ApplicationContext context; + + @Autowired + private WebClientController controller; + private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(RequestPredicates.GET("/resource"), request -> ServerResponse.ok() .build()); private final WebHandler WEB_HANDLER = exchange -> Mono.empty(); @@ -49,6 +54,7 @@ public class WebTestClientIntegrationTest { } @Test + @WithMockUser public void testWebTestClientWithServerURL() { WebTestClient.bindToServer() .baseUrl("http://localhost:" + port) @@ -58,7 +64,39 @@ public class WebTestClientIntegrationTest { .exchange() .expectStatus() .isOk() - .expectBody(); + .expectBody() + .jsonPath("field") + .isEqualTo("value"); + ; + } + + @Test + @WithMockUser + public void testWebTestClientWithApplicationContext() { + WebTestClient.bindToApplicationContext(context) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .jsonPath("field") + .isEqualTo("value"); + } + + @Test + public void testWebTestClientWithController() { + WebTestClient.bindToController(controller) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .jsonPath("field") + .isEqualTo("value"); } } From 30f0c13ef637377122af55df319774d31c66ce53 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Fri, 22 Jan 2021 12:48:34 -0300 Subject: [PATCH 117/149] added context test for new WebClientApplication --- .../com/baeldung/web/client/SpringContextTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java new file mode 100644 index 0000000000..8d2ca41451 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/SpringContextTest.java @@ -0,0 +1,14 @@ +package com.baeldung.web.client; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import com.baeldung.web.reactive.client.WebClientApplication; + +@SpringBootTest(classes = WebClientApplication.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} From 0c5441380750ef523d88d39469af1102d4e2d711 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Fri, 22 Jan 2021 19:56:18 +0100 Subject: [PATCH 118/149] BAEL-2517 --- .../core-java-lang-oop-generics/pom.xml | 28 ++++++++++++ .../UncheckedConversion.java | 45 +++++++++++++++++++ .../UncheckedConversionUnitTest.java | 39 ++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java create mode 100644 core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-generics/pom.xml b/core-java-modules/core-java-lang-oop-generics/pom.xml index 65a0aeac59..1a538edac9 100644 --- a/core-java-modules/core-java-lang-oop-generics/pom.xml +++ b/core-java-modules/core-java-lang-oop-generics/pom.xml @@ -13,4 +13,32 @@ core-java-lang-oop-generics jar + + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java b/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java new file mode 100644 index 0000000000..9ad4a92077 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-generics/src/main/java/com/baeldung/uncheckedconversion/UncheckedConversion.java @@ -0,0 +1,45 @@ +package com.baeldung.uncheckedconversion; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +public class UncheckedConversion { + public static List getRawList() { + List result = new ArrayList(); + result.add("I am the 1st String."); + result.add("I am the 2nd String."); + result.add("I am the 3rd String."); + return result; + } + + public static List getRawListWithMixedTypes() { + List result = new ArrayList(); + result.add("I am the 1st String."); + result.add("I am the 2nd String."); + result.add("I am the 3rd String."); + result.add(new Date()); + return result; + } + + public static List castList(Class clazz, Collection rawCollection) { + List result = new ArrayList<>(rawCollection.size()); + for (Object o : rawCollection) { + try { + result.add(clazz.cast(o)); + } catch (ClassCastException e) { + // log the exception or other error handling + } + } + return result; + } + + public static List castList2(Class clazz, Collection rawCollection) throws ClassCastException { + List result = new ArrayList<>(rawCollection.size()); + for (Object o : rawCollection) { + result.add(clazz.cast(o)); + } + return result; + } +} diff --git a/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java b/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java new file mode 100644 index 0000000000..37b9a878d3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-generics/src/test/java/com/baeldung/uncheckedconversion/UncheckedConversionUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.uncheckedconversion; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class UncheckedConversionUnitTest { + + @Test + public void givenRawList_whenAssignToTypedList_shouldHaveCompilerWarning() { + List fromRawList = UncheckedConversion.getRawList(); + Assert.assertEquals(3, fromRawList.size()); + Assert.assertEquals("I am the 1st String.", fromRawList.get(0)); + } + + @Test(expected = ClassCastException.class) + public void givenRawList_whenListHasMixedType_shouldThrowClassCastException() { + List fromRawList = UncheckedConversion.getRawListWithMixedTypes(); + Assert.assertEquals(4, fromRawList.size()); + Assert.assertFalse(fromRawList.get(3).endsWith("String.")); + } + + @Test + public void givenRawList_whenAssignToTypedListAfterCallingCastList_shouldOnlyHaveElementsWithExpectedType() { + List rawList = UncheckedConversion.getRawListWithMixedTypes(); + List strList = UncheckedConversion.castList(String.class, rawList); + Assert.assertEquals(4, rawList.size()); + Assert.assertEquals("One element with the wrong type has been filtered out.", 3, strList.size()); + Assert.assertTrue(strList.stream().allMatch(el -> el.endsWith("String."))); + } + + @Test(expected = ClassCastException.class) + public void givenRawListWithWrongType_whenAssignToTypedListAfterCallingCastList2_shouldThrowException() { + List rawList = UncheckedConversion.getRawListWithMixedTypes(); + UncheckedConversion.castList2(String.class, rawList); + } + +} From 9144660a72defa218e1d0fbc64c98a592c323b28 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sat, 23 Jan 2021 07:08:50 +0100 Subject: [PATCH 119/149] BAEL-4756 - Mockito MockSettings - fix spelling (#10438) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings * BAEL-4756 - Mockito MockSettings - fix spelling Co-authored-by: Jonathan Cook --- .../baeldung/mockito/mocksettings/MockSettingsUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java index 596baf1954..907abc3d76 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/mocksettings/MockSettingsUnitTest.java @@ -47,10 +47,10 @@ public class MockSettingsUnitTest { @Test public void whenMockSetupWithConstructor_thenConstructorIsInvoked() { - AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("expresso") + AbstractCoffee coffeeSpy = mock(AbstractCoffee.class, withSettings().useConstructor("espresso") .defaultAnswer(CALLS_REAL_METHODS)); - assertEquals("Coffee name: ", "expresso", coffeeSpy.getName()); + assertEquals("Coffee name: ", "espresso", coffeeSpy.getName()); } } From 70a0e0de969efdcb8da019e01a1ca122b47cb6e1 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 11:19:30 +0000 Subject: [PATCH 120/149] BAEL-4748 change user to reader and address to favouriteBooks --- .../webclient/json/ReaderConsumerService.java | 16 ++++ .../json/ReaderConsumerServiceImpl.java | 90 +++++++++++++++++++ .../webclient/json/UserConsumerService.java | 16 ---- .../json/UserConsumerServiceImpl.java | 90 ------------------- .../webclient/json/model/Address.java | 29 ------ .../baeldung/webclient/json/model/Book.java | 22 +++++ .../baeldung/webclient/json/model/Reader.java | 0 .../baeldung/webclient/json/model/User.java | 30 ------- .../ReaderConsumerServiceImplUnitTest.java | 77 ++++++++++++++++ .../json/UserConsumerServiceImplUnitTest.java | 74 --------------- 10 files changed, 205 insertions(+), 239 deletions(-) create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java create mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java delete mode 100644 spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java delete mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java new file mode 100644 index 0000000000..b0bc71d2ed --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java @@ -0,0 +1,16 @@ +package com.baeldung.webclient.json; + +import java.util.List; + +public interface ReaderConsumerService { + + List processReaderDataFromObjectArray(); + + List processReaderDataFromReaderArray(); + + List processReaderDataFromReaderList(); + + List processNestedReaderDataFromReaderArray(); + + List processNestedReaderDataFromReaderList(); +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java new file mode 100644 index 0000000000..d1800a7f65 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java @@ -0,0 +1,90 @@ +package com.baeldung.webclient.json; + +import com.baeldung.webclient.json.model.Book; +import com.baeldung.webclient.json.model.Reader; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ReaderConsumerServiceImpl implements ReaderConsumerService { + + private final WebClient webClient; + private static final ObjectMapper mapper = new ObjectMapper(); + + public ReaderConsumerServiceImpl(WebClient webClient) { + this.webClient = webClient; + } + @Override + public List processReaderDataFromObjectArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Object[].class).log(); + Object[] objects = response.block(); + return Arrays.stream(objects) + .map(object -> mapper.convertValue(object, Reader.class)) + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processReaderDataFromReaderArray() { + Mono response = + webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Reader[].class).log(); + + Reader[] readers = response.block(); + return Arrays.stream(readers) + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processReaderDataFromReaderList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + List readers = response.block(); + + return readers.stream() + .map(Reader::getName) + .collect(Collectors.toList()); + } + + @Override + public List processNestedReaderDataFromReaderArray() { + Mono response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(Reader[].class).log(); + Reader[] readers = response.block(); + + return Arrays.stream(readers) + .flatMap(reader -> reader.getFavouriteBooks().stream()) + .map(Book::getAuthor) + .collect(Collectors.toList()); + } + + @Override + public List processNestedReaderDataFromReaderList() { + Mono> response = webClient.get() + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() {}); + + List readers = response.block(); + return readers.stream() + .flatMap(reader -> reader.getFavouriteBooks().stream()) + .map(Book::getAuthor) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java deleted file mode 100644 index 9afc207ff2..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.webclient.json; - -import java.util.List; - -public interface UserConsumerService { - - List processUserDataFromObjectArray(); - - List processUserDataFromUserArray(); - - List processUserDataFromUserList(); - - List processNestedUserDataFromUserArray(); - - List processNestedUserDataFromUserList(); -} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java deleted file mode 100644 index 30cd4a5617..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/UserConsumerServiceImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung.webclient.json; - -import com.baeldung.webclient.json.model.Address; -import com.baeldung.webclient.json.model.User; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.MediaType; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class UserConsumerServiceImpl implements UserConsumerService { - - private final WebClient webClient; - private static final ObjectMapper mapper = new ObjectMapper(); - - public UserConsumerServiceImpl(WebClient webClient) { - this.webClient = webClient; - } - @Override - public List processUserDataFromObjectArray() { - Mono response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(Object[].class).log(); - Object[] objects = response.block(); - return Arrays.stream(objects) - .map(object -> mapper.convertValue(object, User.class)) - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processUserDataFromUserArray() { - Mono response = - webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(User[].class).log(); - - User[] userArray = response.block(); - return Arrays.stream(userArray) - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processUserDataFromUserList() { - Mono> response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(new ParameterizedTypeReference>() {}); - List userList = response.block(); - - return userList.stream() - .map(User::getName) - .collect(Collectors.toList()); - } - - @Override - public List processNestedUserDataFromUserArray() { - Mono response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(User[].class).log(); - User[] userArray = response.block(); - - return Arrays.stream(userArray) - .flatMap(user -> user.getAddressList().stream()) - .map(Address::getPostCode) - .collect(Collectors.toList()); - } - - @Override - public List processNestedUserDataFromUserList() { - Mono> response = webClient.get() - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(new ParameterizedTypeReference>() {}); - - List userList = response.block(); - return userList.stream() - .flatMap(user -> user.getAddressList().stream()) - .map(Address::getPostCode) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java deleted file mode 100644 index cc4323b72b..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Address.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.webclient.json.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Address { - private final String addressLine1; - private final String addressLine2; - private final String town; - private final String postCode; - - @JsonCreator - public Address( - @JsonProperty("addressLine1") String addressLine1, - @JsonProperty("addressLine2") String addressLine2, - @JsonProperty("town") String town, - @JsonProperty("postCode") String postCode) { - this.addressLine1 = addressLine1; - this.addressLine2 = addressLine2; - this.town = town; - this.postCode = postCode; - } - public String getPostCode() { - return postCode; - } -} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java new file mode 100644 index 0000000000..cb3fb258d4 --- /dev/null +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java @@ -0,0 +1,22 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Book { + private final String author; + private final String title; + + @JsonCreator + public Book( + @JsonProperty("author") String author, + @JsonProperty("title") String title) { + this.author = author; + this.title = title; + } + public String getAuthor() { + return this.author; + } +} diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java deleted file mode 100644 index 6ed359f9db..0000000000 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/User.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.webclient.json.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class User { - private final int id; - private final String name; - private final List
addressList; - - @JsonCreator - public User( - @JsonProperty("id") int id, - @JsonProperty("name") String name, - @JsonProperty("addressList") List
addressList) { - this.id = id; - this.name = name; - this.addressList = addressList; - } - - public String getName() { - return name; - } - - public List
getAddressList() { return addressList; } -} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java new file mode 100644 index 0000000000..92f7bf4f3f --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -0,0 +1,77 @@ +package com.baeldung.webclient.json; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +public class ReaderConsumerServiceImplUnitTest { + + private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBooks\":[{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + + "{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"}]}," + + "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; + + private static String BASE_URL = "http://localhost:8080"; + + WebClient webClientMock = WebClient.builder() + .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) + .header("content-type", "application/json") + .body(READER_JSON) + .build())) + .build(); + + private final ReaderConsumerService tested = new ReaderConsumerServiceImpl(webClientMock); + + @Test + void when_processReaderDataFromObjectArray_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromObjectArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processReaderDataFromReaderArray_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromReaderArray(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processReaderDataFromReaderList_then_OK() { + List expected = Arrays.asList("reader1", "reader2"); + List actual = tested.processReaderDataFromReaderList(); + assertThat(actual, contains(expected.get(0), expected.get(1))); + } + + @Test + void when_processNestedReaderDataFromReaderArray_then_OK() { + List expected = Arrays.asList( + "Milan Kundera", + "Charles Dickens", + "J.R.R. Tolkien", + "Douglas Adams"); + + List actual = tested.processNestedReaderDataFromReaderArray(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + } + + @Test + void when_processNestedReaderDataFromReaderList_then_OK() { + List expected = Arrays.asList( + "Milan Kundera", + "Charles Dickens", + "J.R.R. Tolkien", + "Douglas Adams"); + + List actual = tested.processNestedReaderDataFromReaderList(); + assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + } +} \ No newline at end of file diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java deleted file mode 100644 index 151554efde..0000000000 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/UserConsumerServiceImplUnitTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.webclient.json; - -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; -import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; - -public class UserConsumerServiceImplUnitTest { - - private static String USER_JSON = "[{\"id\":1,\"name\":\"user1\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user1_address1_postCode\"}," + - "{\"addressLine1\":\"address2_addressLine1\",\"addressLine2\":\"address2_addressLine2\",\"town\":\"address2_town\",\"postCode\":\"user1_address2_postCode\"}]}," + - "{\"id\":2,\"name\":\"user2\",\"addressList\":[{\"addressLine1\":\"address1_addressLine1\",\"addressLine2\":\"address1_addressLine2\",\"town\":\"address1_town\",\"postCode\":\"user2_address1_postCode\"}]}]"; - - private static String BASE_URL = "http://localhost:8080"; - - WebClient webClientMock = WebClient.builder() - .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) - .header("content-type", "application/json") - .body(USER_JSON) - .build())) - .build(); - - private final UserConsumerService tested = new UserConsumerServiceImpl(webClientMock); - - @Test - void when_processUserDataFromObjectArray_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromObjectArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processUserDataFromUserArray_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromUserArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processUserDataFromUserList_then_OK() { - List expected = Arrays.asList("user1", "user2"); - List actual = tested.processUserDataFromUserList(); - assertThat(actual, contains(expected.get(0), expected.get(1))); - } - - @Test - void when_processNestedUserDataFromUserArray_then_OK() { - List expected = Arrays.asList( - "user1_address1_postCode", - "user1_address2_postCode", - "user2_address1_postCode"); - - List actual = tested.processNestedUserDataFromUserArray(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); - } - - @Test - void when_processNestedUserDataFromUserList_then_OK() { - List expected = Arrays.asList( - "user1_address1_postCode", - "user1_address2_postCode", - "user2_address1_postCode"); - - List actual = tested.processNestedUserDataFromUserList(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2))); - } -} \ No newline at end of file From a0425afd1b8710216221e0c16ba4a473f1cac373 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 11:25:11 +0000 Subject: [PATCH 121/149] MASH-4748 fix Reader object and url with WebClient --- .../baeldung/webclient/json/model/Reader.java | 30 +++++++++++++++++++ .../ReaderConsumerServiceImplUnitTest.java | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java index e69de29bb2..9fc480c3df 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java @@ -0,0 +1,30 @@ +package com.baeldung.webclient.json.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Reader { + private final int id; + private final String name; + private final List favouriteBooks; + + @JsonCreator + public Reader( + @JsonProperty("id") int id, + @JsonProperty("name") String name, + @JsonProperty("favouriteBooks") List favoriteBooks) { + this.id = id; + this.name = name; + this.favouriteBooks = favoriteBooks; + } + + public String getName() { + return name; + } + + public List getFavouriteBooks() { return favouriteBooks; } +} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java index 92f7bf4f3f..065f1dc11a 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -19,9 +19,9 @@ public class ReaderConsumerServiceImplUnitTest { "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; - private static String BASE_URL = "http://localhost:8080"; + private static String BASE_URL = "http://localhost:8080/readers"; - WebClient webClientMock = WebClient.builder() + WebClient webClientMock = WebClient.builder().baseUrl(BASE_URL) .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) .header("content-type", "application/json") .body(READER_JSON) From c3741487d89705dc28eac515330d9e4adb301c1f Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 23 Jan 2021 12:56:18 +0000 Subject: [PATCH 122/149] BAEL-4748 update examples with favouriteBook --- .../webclient/json/ReaderConsumerService.java | 8 ++-- .../json/ReaderConsumerServiceImpl.java | 16 ++++---- .../baeldung/webclient/json/model/Reader.java | 15 ++++--- .../ReaderConsumerServiceImplUnitTest.java | 41 ++++++++++++------- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java index b0bc71d2ed..17676b3f33 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java @@ -1,14 +1,16 @@ package com.baeldung.webclient.json; +import com.baeldung.webclient.json.model.Book; + import java.util.List; public interface ReaderConsumerService { - List processReaderDataFromObjectArray(); + List processReaderDataFromObjectArray(); - List processReaderDataFromReaderArray(); + List processReaderDataFromReaderArray(); - List processReaderDataFromReaderList(); + List processReaderDataFromReaderList(); List processNestedReaderDataFromReaderArray(); diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java index d1800a7f65..8f1a4c019a 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java @@ -21,7 +21,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { this.webClient = webClient; } @Override - public List processReaderDataFromObjectArray() { + public List processReaderDataFromObjectArray() { Mono response = webClient.get() .accept(MediaType.APPLICATION_JSON) .retrieve() @@ -29,12 +29,12 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Object[] objects = response.block(); return Arrays.stream(objects) .map(object -> mapper.convertValue(object, Reader.class)) - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @Override - public List processReaderDataFromReaderArray() { + public List processReaderDataFromReaderArray() { Mono response = webClient.get() .accept(MediaType.APPLICATION_JSON) @@ -43,12 +43,12 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Reader[] readers = response.block(); return Arrays.stream(readers) - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @Override - public List processReaderDataFromReaderList() { + public List processReaderDataFromReaderList() { Mono> response = webClient.get() .accept(MediaType.APPLICATION_JSON) .retrieve() @@ -56,7 +56,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { List readers = response.block(); return readers.stream() - .map(Reader::getName) + .map(Reader::getFavouriteBook) .collect(Collectors.toList()); } @@ -69,7 +69,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { Reader[] readers = response.block(); return Arrays.stream(readers) - .flatMap(reader -> reader.getFavouriteBooks().stream()) + .flatMap(reader -> reader.getBooksRead().stream()) .map(Book::getAuthor) .collect(Collectors.toList()); } @@ -83,7 +83,7 @@ public class ReaderConsumerServiceImpl implements ReaderConsumerService { List readers = response.block(); return readers.stream() - .flatMap(reader -> reader.getFavouriteBooks().stream()) + .flatMap(reader -> reader.getBooksRead().stream()) .map(Book::getAuthor) .collect(Collectors.toList()); } diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java index 9fc480c3df..7d02853ea1 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java @@ -10,21 +10,24 @@ import java.util.List; public class Reader { private final int id; private final String name; - private final List favouriteBooks; + private final Book favouriteBook; + private final List booksRead; @JsonCreator public Reader( @JsonProperty("id") int id, @JsonProperty("name") String name, - @JsonProperty("favouriteBooks") List favoriteBooks) { + @JsonProperty("favouriteBook") Book favouriteBook, + @JsonProperty("booksRead") List booksRead) { this.id = id; this.name = name; - this.favouriteBooks = favoriteBooks; + this.favouriteBook = favouriteBook; + this.booksRead =booksRead; } - public String getName() { - return name; + public Book getFavouriteBook() { + return favouriteBook; } - public List getFavouriteBooks() { return favouriteBooks; } + public List getBooksRead() { return booksRead; } } diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java index 065f1dc11a..51f0a5c1bb 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.webclient.json; +import com.baeldung.webclient.json.model.Book; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.ClientResponse; @@ -10,13 +11,16 @@ import java.util.Arrays; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasProperty; public class ReaderConsumerServiceImplUnitTest { - private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBooks\":[{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + - "{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"}]}," + - "{\"id\":2,\"name\":\"reader2\",\"favouriteBooks\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + + private static String READER_JSON = "[{\"id\":1,\"name\":\"reader1\",\"favouriteBook\":{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}," + + "\"booksRead\":[{\"author\":\"Charles Dickens\",\"title\":\"Oliver Twist\"},{\"author\":\"Milan Kundera\",\"title\":\"The Unbearable Lightness of Being\"}]}," + + "{\"id\":2,\"name\":\"reader2\",\"favouriteBook\":{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}," + + "\"booksRead\":[{\"author\":\"J.R.R. Tolkien\",\"title\":\"Lord of the Rings\"}, " + "{\"author\":\"Douglas Adams\",\"title\":\"The Hitchhiker\'s Guide to the Galaxy\"}]}]"; private static String BASE_URL = "http://localhost:8080/readers"; @@ -32,23 +36,30 @@ public class ReaderConsumerServiceImplUnitTest { @Test void when_processReaderDataFromObjectArray_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromObjectArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromObjectArray(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); } @Test void when_processReaderDataFromReaderArray_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromReaderArray(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromReaderArray(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); } @Test void when_processReaderDataFromReaderList_then_OK() { - List expected = Arrays.asList("reader1", "reader2"); - List actual = tested.processReaderDataFromReaderList(); - assertThat(actual, contains(expected.get(0), expected.get(1))); + String expectedAuthor1 = "Milan Kundera"; + String expectedAuthor2 = "Douglas Adams"; + List actual = tested.processReaderDataFromReaderList(); + assertThat(actual, hasItems(hasProperty("author", is(expectedAuthor1)), + hasProperty("author", is(expectedAuthor2)))); + } @Test @@ -60,7 +71,7 @@ public class ReaderConsumerServiceImplUnitTest { "Douglas Adams"); List actual = tested.processNestedReaderDataFromReaderArray(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + assertThat(actual, hasItems(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); } @Test @@ -72,6 +83,6 @@ public class ReaderConsumerServiceImplUnitTest { "Douglas Adams"); List actual = tested.processNestedReaderDataFromReaderList(); - assertThat(actual, contains(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); + assertThat(actual, hasItems(expected.get(0), expected.get(1), expected.get(2), expected.get(3))); } } \ No newline at end of file From 0de9172dc6035454d7b923d5cf40aef327544e83 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 11:36:58 -0300 Subject: [PATCH 123/149] Moved spring-5-webclient example code to new test class, to verify everything is working as expected --- .../reactive/client/WebClientController.java | 95 --------------- .../web/client/WebClientIntegrationTest.java | 110 ++++++++++++++++++ 2 files changed, 110 insertions(+), 95 deletions(-) create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 2d42e848b2..765cd561d8 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -1,36 +1,12 @@ package com.baeldung.web.reactive.client; -import java.net.URI; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.TimeUnit; -import org.reactivestreams.Publisher; -import org.reactivestreams.Subscriber; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ReactiveHttpOutputMessage; -import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.BodyInserter; -import org.springframework.web.reactive.function.BodyInserters; -import org.springframework.web.reactive.function.client.WebClient; - -import io.netty.channel.ChannelOption; -import io.netty.handler.timeout.ReadTimeoutHandler; -import io.netty.handler.timeout.WriteTimeoutHandler; -import reactor.core.publisher.Mono; -import reactor.netty.http.client.HttpClient; @RestController public class WebClientController { @@ -42,75 +18,4 @@ public class WebClientController { response.put("field", "value"); return response; } - - public void demonstrateWebClient() { - // request - WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); - - // request body specifications - WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) - .uri("/resource"); - WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() - .uri(URI.create("/resource")); - - // request header specification - WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); - - // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - - LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add("key1", "value1"); - map.add("key2", "value2"); - - BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue(new Object()); - BodyInserter inserter4 = BodyInserters.fromValue("body"); - - // responses - WebClient.ResponseSpec response1 = uri1.body(inserter3) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .acceptCharset(Charset.forName("UTF-8")) - .ifNoneMatch("*") - .ifModifiedSince(ZonedDateTime.now()) - .retrieve(); - String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) - .block(); - String response3 = uri2.retrieve() - .bodyToMono(String.class) - .block(); - WebClient.ResponseSpec response4 = requestSpec2.retrieve(); - } - - private WebClient createWebClient() { - return WebClient.create(); - } - - private WebClient createWebClientWithServerURL() { - return WebClient.create("http://localhost:8081"); - } - - private WebClient createWebClientConfiguringTimeout() { - HttpClient httpClient = HttpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) - .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); - - return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(httpClient)) - .build(); - } - - private WebClient createWebClientWithServerURLAndDefaultValues() { - return WebClient.builder() - .baseUrl("http://localhost:8081") - .defaultCookie("cookieKey", "cookieValue") - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) - .build(); - } - } diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java new file mode 100644 index 0000000000..df873c618d --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -0,0 +1,110 @@ +package com.baeldung.web.client; + +import java.net.URI; +import java.nio.charset.Charset; +import java.time.ZonedDateTime; +import java.util.Collections; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; +import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ReactiveHttpOutputMessage; +import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.reactive.function.BodyInserter; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; + +import com.baeldung.web.reactive.client.WebClientApplication; + +import io.netty.channel.ChannelOption; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; +import reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClient; + +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class WebClientIntegrationTest { + + @LocalServerPort + private int port; + + @Test + public void demonstrateWebClient() { + // request + WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); + WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); + + // request body specifications + WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) + .uri("/resource"); + WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() + .uri(URI.create("/resource")); + + // request header specification + WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); + WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); + + // inserters + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + + LinkedMultiValueMap map = new LinkedMultiValueMap<>(); + map.add("key1", "value1"); + map.add("key2", "value2"); + + BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); + BodyInserter inserter3 = BodyInserters.fromValue(new Object()); + BodyInserter inserter4 = BodyInserters.fromValue("body"); + + // responses + WebClient.ResponseSpec response1 = uri1.body(inserter3) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + .acceptCharset(Charset.forName("UTF-8")) + .ifNoneMatch("*") + .ifModifiedSince(ZonedDateTime.now()) + .retrieve(); + String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + String response3 = uri2.retrieve() + .bodyToMono(String.class) + .block(); + WebClient.ResponseSpec response4 = requestSpec2.retrieve(); + } + + private WebClient createWebClient() { + return WebClient.create(); + } + + private WebClient createWebClientWithServerURL() { + return WebClient.create("http://localhost:8081"); + } + + private WebClient createWebClientConfiguringTimeout() { + HttpClient httpClient = HttpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); + + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(httpClient)) + .build(); + } + + private WebClient createWebClientWithServerURLAndDefaultValues() { + return WebClient.builder() + .baseUrl("http://localhost:8081") + .defaultCookie("cookieKey", "cookieValue") + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) + .build(); + } +} From 3e5a1f3e50c4d18ee4e7a7be34c8aa9821aa31c8 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 12:40:28 -0300 Subject: [PATCH 124/149] added endpoints to test functionality properly --- .../web/reactive/client/WebClientController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 765cd561d8..2dfcd7533b 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -4,7 +4,11 @@ import java.util.HashMap; import java.util.Map; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -18,4 +22,14 @@ public class WebClientController { response.put("field", "value"); return response; } + + @PostMapping("/resource") + public String postResource(@RequestBody String bodyString) { + return "processed-" + bodyString; + } + + @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public String handleFormUpload(@RequestPart("key1") String value1, @RequestPart("key2") String value2) { + return "processed-" + value1 + value2; + } } From 725465b0b6e42202a5f66498773ced8b00ec5355 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sat, 23 Jan 2021 12:41:13 -0300 Subject: [PATCH 125/149] disabled security for WebClient codebase application --- .../baeldung/web/reactive/client/WebClientApplication.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java index f104ad30f1..aa9b81de4f 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientApplication.java @@ -2,9 +2,10 @@ package com.baeldung.web.reactive.client; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; -@SpringBootApplication -public class WebClientApplication{ +@SpringBootApplication(exclude = { ReactiveSecurityAutoConfiguration.class }) +public class WebClientApplication { public static void main(String[] args) { SpringApplication.run(WebClientApplication.class, args); From 0fe15633887f0e47baf0c8118269e39a7448c8f7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 24 Jan 2021 23:40:00 +0530 Subject: [PATCH 126/149] JAVA-4012: Moved 1 article from spring-data-mongodb to spring-boot-persistence-mongodb --- .../spring-boot-persistence-mongodb/README.md | 2 + .../zoneddatetime/config/MongoConfig.java | 53 +++++++++++++++++++ .../converter/ZonedDateTimeReadConverter.java | 2 +- .../ZonedDateTimeWriteConverter.java | 2 +- .../baeldung/zoneddatetime}/model/Action.java | 2 +- .../repository/ActionRepository.java | 5 +- .../ActionRepositoryLiveTest.java | 8 +-- .../spring-data-mongodb/README.md | 5 +- .../java/com/baeldung/config/MongoConfig.java | 5 -- 9 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java rename persistence-modules/{spring-data-mongodb/src/main/java => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/converter/ZonedDateTimeReadConverter.java (88%) rename persistence-modules/{spring-data-mongodb/src/main/java => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/converter/ZonedDateTimeWriteConverter.java (87%) rename persistence-modules/{spring-data-mongodb/src/main/java/com/baeldung => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/model/Action.java (96%) rename persistence-modules/{spring-data-mongodb/src/main/java/com/baeldung => spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime}/repository/ActionRepository.java (60%) rename persistence-modules/{spring-data-mongodb/src/test/java/com/baeldung/repository => spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime}/ActionRepositoryLiveTest.java (87%) diff --git a/persistence-modules/spring-boot-persistence-mongodb/README.md b/persistence-modules/spring-boot-persistence-mongodb/README.md index aade8eb1c0..97241ad464 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/README.md +++ b/persistence-modules/spring-boot-persistence-mongodb/README.md @@ -4,3 +4,5 @@ - [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb) - [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file) - [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) +- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) + diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java new file mode 100644 index 0000000000..3cfefa099c --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java @@ -0,0 +1,53 @@ +package com.baeldung.zoneddatetime.config; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; +import org.springframework.data.mongodb.core.convert.MongoCustomConversions; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; + +import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter; +import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; + +@Configuration +@EnableMongoRepositories(basePackages = { "com.baeldung" }) +public class MongoConfig extends AbstractMongoClientConfiguration { + + private final List> converters = new ArrayList>(); + + @Override + protected String getDatabaseName() { + return "test"; + } + + @Override + public MongoClient mongoClient() { + final ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/test"); + final MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return MongoClients.create(mongoClientSettings); + } + + @Override + public Collection getMappingBasePackages() { + return Collections.singleton("com.baeldung"); + } + + @Override + public MongoCustomConversions customConversions() { + converters.add(new ZonedDateTimeReadConverter()); + converters.add(new ZonedDateTimeWriteConverter()); + return new MongoCustomConversions(converters); + } + +} diff --git a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java similarity index 88% rename from persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java index a2d847957b..f4a4c2d040 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeReadConverter.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java @@ -1,4 +1,4 @@ -package converter; +package com.baeldung.zoneddatetime.converter; import org.springframework.core.convert.converter.Converter; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java similarity index 87% rename from persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java index e13ac2d130..2244a1460a 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/converter/ZonedDateTimeWriteConverter.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java @@ -1,4 +1,4 @@ -package converter; +package com.baeldung.zoneddatetime.converter; import org.springframework.core.convert.converter.Converter; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java similarity index 96% rename from persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java index aa480dbdf7..06202fe465 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/model/Action.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.zoneddatetime.model; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java similarity index 60% rename from persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java index bdca490fe6..e214c4b3c4 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/repository/ActionRepository.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java @@ -1,6 +1,7 @@ -package com.baeldung.repository; +package com.baeldung.zoneddatetime.repository; -import com.baeldung.model.Action; import org.springframework.data.mongodb.repository.MongoRepository; +import com.baeldung.zoneddatetime.model.Action; + public interface ActionRepository extends MongoRepository { } \ No newline at end of file diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java similarity index 87% rename from persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java rename to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java index 79648f1a20..3a241418ca 100644 --- a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/repository/ActionRepositoryLiveTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java @@ -1,7 +1,5 @@ -package com.baeldung.repository; +package com.baeldung.zoneddatetime; -import com.baeldung.config.MongoConfig; -import com.baeldung.model.Action; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -12,6 +10,10 @@ import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.baeldung.zoneddatetime.config.MongoConfig; +import com.baeldung.zoneddatetime.model.Action; +import com.baeldung.zoneddatetime.repository.ActionRepository; + import java.time.ZoneOffset; import java.time.ZonedDateTime; diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index 0be8c57036..acc978c68e 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -9,9 +9,8 @@ - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) - [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) -- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) -- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) - +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) +- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions) ## Spring Data MongoDB Live Testing diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 8036bbbca2..3819558e8b 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java +++ b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -25,9 +25,6 @@ import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; -import converter.ZonedDateTimeReadConverter; -import converter.ZonedDateTimeWriteConverter; - @Configuration @EnableMongoRepositories(basePackages = "com.baeldung.repository") public class MongoConfig extends AbstractMongoClientConfiguration { @@ -69,8 +66,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { @Override public MongoCustomConversions customConversions() { converters.add(new UserWriterConverter()); - converters.add(new ZonedDateTimeReadConverter()); - converters.add(new ZonedDateTimeWriteConverter()); return new MongoCustomConversions(converters); } From 992a33fe7dd6f2c766df2ddee288243a2c2e7a16 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 24 Jan 2021 23:46:39 +0530 Subject: [PATCH 127/149] JAVA-4012: clean-up --- .../main/java/com/baeldung/config/MongoConfig.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java index 3819558e8b..90b1268133 100644 --- a/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java +++ b/persistence-modules/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java @@ -5,16 +5,13 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.data.mongodb.MongoDatabaseFactory; import org.springframework.data.mongodb.MongoTransactionManager; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; -import org.springframework.data.mongodb.core.convert.MappingMongoConverter; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; -import org.springframework.data.mongodb.gridfs.GridFsTemplate; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import com.baeldung.converter.UserWriterConverter; @@ -31,9 +28,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { private final List> converters = new ArrayList>(); - @Autowired - private MappingMongoConverter mongoConverter; - @Override protected String getDatabaseName() { return "test"; @@ -69,11 +63,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration { return new MongoCustomConversions(converters); } - @Bean - public GridFsTemplate gridFsTemplate() throws Exception { - return new GridFsTemplate(mongoDbFactory(), mongoConverter); - } - @Bean MongoTransactionManager transactionManager(MongoDatabaseFactory dbFactory) { return new MongoTransactionManager(dbFactory); From 2bc7dbc70868ac34ac8d3e7edb8113338fa991d4 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 24 Jan 2021 15:18:29 -0300 Subject: [PATCH 128/149] added and ordered tests in WebClientIntegrationTest to match article - test not passing (reusing specs) --- .../web/client/WebClientIntegrationTest.java | 82 +++++++++++++------ 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index df873c618d..837ea679d2 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,7 +1,7 @@ package com.baeldung.web.client; import java.net.URI; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -22,6 +23,10 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; +import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; +import org.springframework.web.reactive.function.client.WebClient.UriSpec; import com.baeldung.web.reactive.client.WebClientApplication; @@ -31,7 +36,7 @@ import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; -@SpringBootTest(classes = WebClientApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class WebClientIntegrationTest { @LocalServerPort @@ -40,44 +45,73 @@ public class WebClientIntegrationTest { @Test public void demonstrateWebClient() { // request - WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); + UriSpec requestPost1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); + UriSpec requestPost2 = createWebClientWithServerURLAndDefaultValues().post(); + UriSpec requestGet = createWebClientWithServerURLAndDefaultValues().get(); // request body specifications - WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) - .uri("/resource"); - WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() - .uri(URI.create("/resource")); + RequestBodySpec bodySpecPost = requestPost1.uri("/resource"); + RequestBodySpec bodySpecPostMultipart = requestPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + .build()); + RequestBodySpec bodySpecOverridenBaseUri = requestPost2.uri(URI.create("/resource")); // request header specification - WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromValue("data")); + String bodyValue = "bodyValue"; + RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); + RequestHeadersSpec headerSpecPost2 = bodySpecPost.body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); - // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + // request header specification using inserters + BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add("key1", "value1"); - map.add("key2", "value2"); + map.add("key1", "multipartValue1"); + map.add("key2", "multipartValue2"); - BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromValue(new Object()); - BodyInserter inserter4 = BodyInserters.fromValue("body"); + BodyInserter, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(map); + BodyInserter inserterObject = BodyInserters.fromValue(new Object()); + BodyInserter inserterString = BodyInserters.fromValue(bodyValue); + + RequestHeadersSpec headerSpecInserterCompleteSuscriber = bodySpecPost.body(inserterCompleteSuscriber); + RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); + RequestHeadersSpec headerSpecInserterObject = bodySpecPost.body(inserterObject); + RequestHeadersSpec headerSpecInserterString = bodySpecPost.body(inserterString); // responses - WebClient.ResponseSpec response1 = uri1.body(inserter3) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + ResponseSpec responsePostObject = headerSpecInserterObject.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .acceptCharset(Charset.forName("UTF-8")) + .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()) .retrieve(); - String response2 = uri1.exchangeToMono(response -> response.bodyToMono(String.class)) + String responsePostString = headerSpecInserterString.exchangeToMono(response -> response.bodyToMono(String.class)) .block(); - String response3 = uri2.retrieve() + String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + .retrieve() .bodyToMono(String.class) .block(); - WebClient.ResponseSpec response4 = requestSpec2.retrieve(); + String responsePostCompleteSubsciber = headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithBody1 = headerSpecPost1.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithBody3 = headerSpecPost2.retrieve() + .bodyToMono(String.class) + .block(); + String responseGet = headerSpecGet.retrieve() + .bodyToMono(String.class) + .block(); + String responsePostWithNoBody = bodySpecPost.retrieve() + .bodyToMono(String.class) + .block(); + try { + bodySpecOverridenBaseUri.retrieve() + .bodyToMono(String.class) + .block(); + } catch (Exception ex) { + System.out.println(ex.getClass()); + } } private WebClient createWebClient() { @@ -101,7 +135,7 @@ public class WebClientIntegrationTest { private WebClient createWebClientWithServerURLAndDefaultValues() { return WebClient.builder() - .baseUrl("http://localhost:8081") + .baseUrl("http://localhost:" + port) .defaultCookie("cookieKey", "cookieValue") .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) From 84737e1056097486bdce4f7b6bc65cfafd930065 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Sun, 24 Jan 2021 17:41:34 -0300 Subject: [PATCH 129/149] added Foo for post Object scenario, removed Subscriber::onComplete scenario, fixed some other errors in examples --- .../com/baeldung/web/reactive/client/Foo.java | 20 +++ .../reactive/client/WebClientController.java | 7 +- .../web/client/WebClientIntegrationTest.java | 141 +++++++++++------- 3 files changed, 116 insertions(+), 52 deletions(-) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java new file mode 100644 index 0000000000..1fc4834cfa --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java @@ -0,0 +1,20 @@ +package com.baeldung.web.reactive.client; + +public class Foo { + + private String name; + + public Foo(String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 2dfcd7533b..4c7941ac35 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -28,8 +28,13 @@ public class WebClientController { return "processed-" + bodyString; } + @PostMapping("/resource-foo") + public String postResource(@RequestBody Foo bodyFoo) { + return "processedFoo-" + bodyFoo.getName(); + } + @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public String handleFormUpload(@RequestPart("key1") String value1, @RequestPart("key2") String value2) { - return "processed-" + value1 + value2; + return "processed-" + value1 + "-" + value2; } } diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 837ea679d2..b49aff9575 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,9 +1,13 @@ package com.baeldung.web.client; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.Collections; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; @@ -12,6 +16,7 @@ import org.reactivestreams.Subscriber; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; @@ -24,13 +29,17 @@ import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; +import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; import org.springframework.web.reactive.function.client.WebClient.UriSpec; +import org.springframework.web.reactive.function.client.WebClientRequestException; +import com.baeldung.web.reactive.client.Foo; import com.baeldung.web.reactive.client.WebClientApplication; import io.netty.channel.ChannelOption; +import io.netty.channel.ConnectTimeoutException; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; @@ -43,27 +52,37 @@ public class WebClientIntegrationTest { private int port; @Test - public void demonstrateWebClient() { - // request - UriSpec requestPost1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - UriSpec requestPost2 = createWebClientWithServerURLAndDefaultValues().post(); - UriSpec requestGet = createWebClientWithServerURLAndDefaultValues().get(); + public void givenDifferentScenarios_whenRequestsSent_thenObtainExpectedResponses() { + // WebClient + WebClient client1 = WebClient.create(); + WebClient client2 = WebClient.create("http://localhost:" + port); + WebClient client3 = WebClient.builder() + .baseUrl("http://localhost:" + port) + .defaultCookie("cookieKey", "cookieValue") + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) + .build(); + + // request specification + UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); + UriSpec uriSpecPost2 = client2.post(); + UriSpec requestGet = client3.get(); + + // uri specification + RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); + RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + .build()); + RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri(URI.create("/resource-foo")); // request body specifications - RequestBodySpec bodySpecPost = requestPost1.uri("/resource"); - RequestBodySpec bodySpecPostMultipart = requestPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") - .build()); - RequestBodySpec bodySpecOverridenBaseUri = requestPost2.uri(URI.create("/resource")); - - // request header specification String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headerSpecPost2 = bodySpecPost.body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(BodyInserters.fromValue(new Foo("fooName"))); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); - // request header specification using inserters - BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - + // request body specifications - using inserters LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "multipartValue1"); map.add("key2", "multipartValue2"); @@ -72,73 +91,93 @@ public class WebClientIntegrationTest { BodyInserter inserterObject = BodyInserters.fromValue(new Object()); BodyInserter inserterString = BodyInserters.fromValue(bodyValue); - RequestHeadersSpec headerSpecInserterCompleteSuscriber = bodySpecPost.body(inserterCompleteSuscriber); RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headerSpecInserterObject = bodySpecPost.body(inserterObject); - RequestHeadersSpec headerSpecInserterString = bodySpecPost.body(inserterString); + RequestHeadersSpec headerSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); + RequestHeadersSpec headerSpecInserterString = createDefaultPostResourceRequest().body(inserterString); - // responses - ResponseSpec responsePostObject = headerSpecInserterObject.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + // request header specification + RequestHeadersSpec headerSpecInserterStringWithHeaders = headerSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") - .ifModifiedSince(ZonedDateTime.now()) - .retrieve(); - String responsePostString = headerSpecInserterString.exchangeToMono(response -> response.bodyToMono(String.class)) + .ifModifiedSince(ZonedDateTime.now()); + + // request + ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); + String responsePostString = responseSpecPostString.bodyToMono(String.class) .block(); String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() .bodyToMono(String.class) .block(); - String responsePostCompleteSubsciber = headerSpecInserterCompleteSuscriber.retrieve() - .bodyToMono(String.class) - .block(); String responsePostWithBody1 = headerSpecPost1.retrieve() .bodyToMono(String.class) .block(); String responsePostWithBody3 = headerSpecPost2.retrieve() .bodyToMono(String.class) .block(); - String responseGet = headerSpecGet.retrieve() + String responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class) .block(); + ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { + }; + Map responseGet = headerSpecGet.retrieve() + .bodyToMono(ref) + .block(); String responsePostWithNoBody = bodySpecPost.retrieve() .bodyToMono(String.class) .block(); - try { + + // response assertions + assertThat(responsePostString).isEqualTo("processed-bodyValue"); + assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); + assertThat(responsePostWithBody1).isEqualTo("processed-"); + assertThat(responsePostWithBody3).isEqualTo("processed-"); + assertThat(responseGet).containsEntry("field", "value"); + assertThat(responsePostWithNoBody).isEqualTo("processed-"); + assertThat(responsePostFoo).isEqualTo("processed-fooName"); + + assertThrows(WebClientRequestException.class, () -> { + String responsePostObject = headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) + .block(); + }); + assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) .block(); - } catch (Exception ex) { - System.out.println(ex.getClass()); - } + }); + } - private WebClient createWebClient() { - return WebClient.create(); - } - - private WebClient createWebClientWithServerURL() { - return WebClient.create("http://localhost:8081"); - } - - private WebClient createWebClientConfiguringTimeout() { + @Test + public void givenWebClientWithTimeoutConfigurations_whenRequestUsingWronglyConfiguredPublisher_thenObtainTimeout() { HttpClient httpClient = HttpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) - .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS)) - .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))); + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) + .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(1000, TimeUnit.MILLISECONDS)) + .addHandlerLast(new WriteTimeoutHandler(1000, TimeUnit.MILLISECONDS))); - return WebClient.builder() + WebClient timeoutClient = WebClient.builder() .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); + + BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() + .uri("/resource") + .body(inserterCompleteSuscriber); + WebClientRequestException exception = assertThrows(WebClientRequestException.class, () -> { + headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class) + .block(); + }); + assertThat(exception.getCause()).isInstanceOf(ConnectTimeoutException.class); } - private WebClient createWebClientWithServerURLAndDefaultValues() { - return WebClient.builder() - .baseUrl("http://localhost:" + port) - .defaultCookie("cookieKey", "cookieValue") - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) - .build(); + private RequestBodyUriSpec createDefaultPostRequest() { + return WebClient.create("http://localhost:" + port) + .post(); + } + + private RequestBodySpec createDefaultPostResourceRequest() { + return createDefaultPostRequest().uri("/resource"); } } From 431442e3cab7bd575b1f136f362517aecab0d279 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Mon, 25 Jan 2021 12:29:01 +0200 Subject: [PATCH 130/149] BAEL-4499 - Synchronization bad practice and solution example --- .../AnimalBadPractice.java | 35 +++++++++++++ .../AnimalSolution.java | 42 +++++++++++++++ .../SynchronizationBadPracticeExample.java | 51 +++++++++++++++++++ .../SynchronizationSolutionExample.java | 30 +++++++++++ 4 files changed, 158 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java create mode 100644 core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java new file mode 100644 index 0000000000..ca6b7db765 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java @@ -0,0 +1,35 @@ +package com.baeldung.synchronizationbadpractices; + +public class AnimalBadPractice { + + private String name; + private String owner; + + public String getName() { + return name; + } + + public String getOwner() { + return owner; + } + + public synchronized void setName(String name) { + this.name = name; + } + + public void setOwner(String owner) { + synchronized(this) { + this.owner = owner; + } + } + + public AnimalBadPractice() { + + } + + public AnimalBadPractice(String name, String owner) { + this.name = name; + this.owner = owner; + } + +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java new file mode 100644 index 0000000000..b49cfa05d4 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java @@ -0,0 +1,42 @@ +package com.baeldung.synchronizationbadpractices; + +public class AnimalSolution { + + private final Object objLock1 = new Object(); + private final Object objLock2 = new Object(); + + private String name; + private String owner; + + public String getName() { + return name; + } + + public String getOwner() { + return owner; + } + + + public void setName(String name) { + synchronized(objLock1) { + this.name = name; + } + } + + public void setOwner(String owner) { + synchronized(objLock2) { + this.owner = owner; + } + } + + public AnimalSolution() { + + } + + public AnimalSolution(String name, String owner) { + this.name = name; + this.owner = owner; + } + + +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java new file mode 100644 index 0000000000..84d2e1cbb6 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java @@ -0,0 +1,51 @@ +package com.baeldung.synchronizationbadpractices; + +public class SynchronizationBadPracticeExample { + + public void stringBadPractice1() { + String stringLock = "LOCK_STRING"; + synchronized (stringLock) { + // ... + } + } + + private final String stringLock = "LOCK_STRING"; + public void stringBadPractice2() { + synchronized (stringLock) { + // ... + } + } + + private final String internedStringLock = new String("LOCK_STRING").intern(); + public void stringBadPractice3() { + synchronized (internedStringLock) { + // ... + } + } + + private final Boolean booleanLock = Boolean.FALSE; + public void booleanBadPractice() { + synchronized (booleanLock) { + // ... + } + } + + private int count = 0; + private final Integer intLock = count; + public void boxedPrimitiveBadPractice() { + synchronized (intLock) { + count++; + // ... + } + } + + public void classBadPractice() throws InterruptedException { + AnimalBadPractice animalObj = new AnimalBadPractice("Tommy", "John"); + synchronized(animalObj) { + while (true) { + Thread.sleep(Integer.MAX_VALUE); + } + } + } + +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java new file mode 100644 index 0000000000..a3ab8a2cee --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java @@ -0,0 +1,30 @@ +package com.baeldung.synchronizationbadpractices; + +public class SynchronizationSolutionExample { + + private final String stringLock = new String("LOCK_STRING"); + public void stringSolution() { + synchronized (stringLock) { + // ... + } + } + + private int count = 0; + private final Integer intLock = new Integer(count); + public void boxedPrimitiveSolution() { + synchronized(intLock) { + count++; + // ... + } + } + + private static int staticCount = 0; + private static final Object staticObjLock = new Object(); + public void staticVariableSolution() { + synchronized(staticObjLock) { + staticCount++; + // ... + } + } + +} From cfe47f772a434eb3b1c462144c9a2301e3418cf4 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:37:12 -0300 Subject: [PATCH 131/149] fixed rest of tests --- .../com/baeldung/web/reactive/client/Foo.java | 4 ++++ .../reactive/client/WebClientController.java | 10 ++++---- .../web/client/WebClientIntegrationTest.java | 24 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java index 1fc4834cfa..c6e3678832 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/Foo.java @@ -4,6 +4,10 @@ public class Foo { private String name; + public Foo() { + super(); + } + public Foo(String name) { super(); this.name = name; diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 4c7941ac35..1a91001807 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + @RestController public class WebClientController { @@ -24,13 +26,13 @@ public class WebClientController { } @PostMapping("/resource") - public String postResource(@RequestBody String bodyString) { - return "processed-" + bodyString; + public Mono postStringResource(@RequestBody Mono bodyString) { + return bodyString.map(body -> "processed-" + body); } @PostMapping("/resource-foo") - public String postResource(@RequestBody Foo bodyFoo) { - return "processedFoo-" + bodyFoo.getName(); + public Mono postFooResource(@RequestBody Mono bodyFoo) { + return bodyFoo.map(foo -> "processedFoo-" + foo.getName()); } @PostMapping(value = "/resource-multipart", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index b49aff9575..04a4031c62 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -17,8 +17,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.codec.CodecException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.client.reactive.ClientHttpRequest; @@ -72,8 +74,8 @@ public class WebClientIntegrationTest { RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") .build()); + RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); - RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri(URI.create("/resource-foo")); // request body specifications String bodyValue = "bodyValue"; @@ -124,23 +126,27 @@ public class WebClientIntegrationTest { Map responseGet = headerSpecGet.retrieve() .bodyToMono(ref) .block(); - String responsePostWithNoBody = bodySpecPost.retrieve() - .bodyToMono(String.class) + Map responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + return responseHandler.bodyToMono(ref); + }) .block(); // response assertions assertThat(responsePostString).isEqualTo("processed-bodyValue"); assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); - assertThat(responsePostWithBody1).isEqualTo("processed-"); - assertThat(responsePostWithBody3).isEqualTo("processed-"); + assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); + assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); assertThat(responseGet).containsEntry("field", "value"); - assertThat(responsePostWithNoBody).isEqualTo("processed-"); - assertThat(responsePostFoo).isEqualTo("processed-fooName"); + assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); + assertThat(responsePostWithNoBody).containsEntry("error", "Bad Request"); - assertThrows(WebClientRequestException.class, () -> { - String responsePostObject = headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) + // assert sending plain `new Object()` as request body + assertThrows(CodecException.class, () -> { + headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) .block(); }); + // assert sending request overriding base uri assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) From 0cda08a95e6326c4e5dfec76c54e2a865974b1d5 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:41:57 -0300 Subject: [PATCH 132/149] replaced existing scenario to use an alternative body method --- .../java/com/baeldung/web/client/WebClientIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 04a4031c62..34627b00ed 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -81,7 +81,7 @@ public class WebClientIntegrationTest { String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(BodyInserters.fromValue(new Foo("fooName"))); + RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); // request body specifications - using inserters From a37812ce04cb20c7a1a76deabbe15137c6fb5c26 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 11:44:44 -0300 Subject: [PATCH 133/149] added additional scenario using bodyValue method --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 34627b00ed..032d62b04d 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -81,6 +81,7 @@ public class WebClientIntegrationTest { String bodyValue = "bodyValue"; RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headerSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); @@ -115,6 +116,9 @@ public class WebClientIntegrationTest { String responsePostWithBody1 = headerSpecPost1.retrieve() .bodyToMono(String.class) .block(); + String responsePostWithBody2 = headerSpecPost2.retrieve() + .bodyToMono(String.class) + .block(); String responsePostWithBody3 = headerSpecPost2.retrieve() .bodyToMono(String.class) .block(); @@ -136,6 +140,7 @@ public class WebClientIntegrationTest { assertThat(responsePostString).isEqualTo("processed-bodyValue"); assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); + assertThat(responsePostWithBody2).isEqualTo("processed-bodyValue"); assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); assertThat(responseGet).containsEntry("field", "value"); assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); From 615322468ecf4093d2e96c453b6c389dac7e9e5c Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Mon, 25 Jan 2021 12:26:37 -0300 Subject: [PATCH 134/149] made tests assertions non-blocking --- spring-5-reactive/pom.xml | 11 ++- .../web/client/WebClientIntegrationTest.java | 68 ++++++++++--------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 60c8b90e16..40791faaaf 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 spring-5-reactive 0.0.1-SNAPSHOT @@ -73,6 +74,12 @@ spring-security-test test + + io.projectreactor + reactor-test + test + + diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 032d62b04d..01de550a9c 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -46,6 +46,7 @@ import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; +import reactor.test.StepVerifier; @SpringBootTest(classes = WebClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class WebClientIntegrationTest { @@ -107,44 +108,46 @@ public class WebClientIntegrationTest { // request ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); - String responsePostString = responseSpecPostString.bodyToMono(String.class) - .block(); - String responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + Mono responsePostString = responseSpecPostString.bodyToMono(String.class); + Mono responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody1 = headerSpecPost1.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody2 = headerSpecPost2.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostWithBody3 = headerSpecPost2.retrieve() - .bodyToMono(String.class) - .block(); - String responsePostFoo = headerSpecFooPost.retrieve() - .bodyToMono(String.class) - .block(); + .bodyToMono(String.class); + Mono responsePostWithBody1 = headerSpecPost1.retrieve() + .bodyToMono(String.class); + Mono responsePostWithBody2 = headerSpecPost2.retrieve() + .bodyToMono(String.class); + Mono responsePostWithBody3 = headerSpecPost2.retrieve() + .bodyToMono(String.class); + Mono responsePostFoo = headerSpecFooPost.retrieve() + .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - Map responseGet = headerSpecGet.retrieve() - .bodyToMono(ref) - .block(); - Map responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + Mono> responseGet = headerSpecGet.retrieve() + .bodyToMono(ref); + Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); return responseHandler.bodyToMono(ref); - }) - .block(); + }); // response assertions - assertThat(responsePostString).isEqualTo("processed-bodyValue"); - assertThat(responsePostMultipart).isEqualTo("processed-multipartValue1-multipartValue2"); - assertThat(responsePostWithBody1).isEqualTo("processed-bodyValue"); - assertThat(responsePostWithBody2).isEqualTo("processed-bodyValue"); - assertThat(responsePostWithBody3).isEqualTo("processed-bodyValue"); - assertThat(responseGet).containsEntry("field", "value"); - assertThat(responsePostFoo).isEqualTo("processedFoo-fooName"); - assertThat(responsePostWithNoBody).containsEntry("error", "Bad Request"); + StepVerifier.create(responsePostString) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostMultipart) + .expectNext("processed-multipartValue1-multipartValue2"); + StepVerifier.create(responsePostWithBody1) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostWithBody2) + .expectNext("processed-bodyValue"); + StepVerifier.create(responsePostWithBody3) + .expectNext("processed-bodyValue"); + StepVerifier.create(responseGet) + .expectNextMatches(nextMap -> nextMap.get("field") + .equals("value")); + StepVerifier.create(responsePostFoo) + .expectNext("processedFoo-fooName"); + StepVerifier.create(responsePostWithNoBody) + .expectNextMatches(nextMap -> nextMap.get("error") + .equals("Bad Request")); // assert sending plain `new Object()` as request body assertThrows(CodecException.class, () -> { @@ -152,11 +155,12 @@ public class WebClientIntegrationTest { .block(); }); // assert sending request overriding base uri - assertThrows(WebClientRequestException.class, () -> { + Exception exception = assertThrows(WebClientRequestException.class, () -> { bodySpecOverridenBaseUri.retrieve() .bodyToMono(String.class) .block(); }); + assertThat(exception.getMessage()).contains("Connection refused"); } From e8569d56b0eb251b49baf091ecaf3dc792f74bca Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Tue, 26 Jan 2021 04:09:58 +0500 Subject: [PATCH 135/149] add file for constantpool (#10442) * Create ConstantPool.java add file for constantpool * update the module with most relevant update the module with most relevant --- .../main/java/com/baeldung/constantpool/ConstantPool.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java new file mode 100644 index 0000000000..b9aea05272 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java @@ -0,0 +1,8 @@ +package com.baeldung.constantpool; + +public class ConstantPool { + + public void sayHello() { + System.out.println("Hello World"); + } +} From b018825dc40e2b0a2d0e242bcf88ed4d6253a488 Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Tue, 26 Jan 2021 20:36:04 +0530 Subject: [PATCH 136/149] BAEL-4710 - Hiding endpoints using @Hidden (#10431) * Added code for checking if a class is abstract or not. * Renamed test name as per review comments. * BAEL-4695 - Added code to evaluate math expressions. * BAEL-4695 - Added test case for math function. * BAEL-4695 Added consistent examples and entry in parent pom. * BAEL-4695 - Added more examples * BAEL-4710 - Hiding endpoints using @Hidden --- .../controller/RegularRestController.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java new file mode 100644 index 0000000000..f3135229d6 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/springdoc/controller/RegularRestController.java @@ -0,0 +1,31 @@ +package com.baeldung.springdoc.controller; + +import java.time.LocalDate; +import java.time.LocalTime; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Hidden; + +@Hidden +@RestController +public class RegularRestController { + + @Hidden + @GetMapping("/getAuthor") + public String getAuthor() { + return "Umang Budhwar"; + } + + @GetMapping("/getDate") + public LocalDate getDate() { + return LocalDate.now(); + } + + @GetMapping("/getTime") + public LocalTime getTime() { + return LocalTime.now(); + } + +} From 609c4db4fba6764034ea94394ed4ec8c4413a3c5 Mon Sep 17 00:00:00 2001 From: Yavuz Tas <12643010+yavuztas@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:10:30 +0100 Subject: [PATCH 137/149] BAEL-3828 Where Should @Service Annotation Be Kept? (#10430) * BAEL-3828 add code samples and tests for the article * BAEL-3828 fix maven test folder structure and test executions * BAEL-3828 fix indentation in continuation lines --- .../annotations/service/AuthApplication.java | 22 ++++++++ .../AbstractAuthenticationService.java | 12 +++++ .../InMemoryAuthenticationService.java | 14 +++++ .../concretes/LdapAuthenticationService.java | 14 +++++ .../interfaces/AuthenticationService.java | 10 ++++ .../EmployeeApplicationUnitTest.java} | 2 +- .../service/AuthApplicationUnitTest.java | 51 +++++++++++++++++++ .../AbstractsAnnotatedTestConfiguration.java | 10 ++++ ...reteClassesAnnotatedTestConfiguration.java | 10 ++++ .../InterfacesAnnotatedTestConfiguration.java | 10 ++++ 10 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java rename spring-boot-modules/spring-boot-annotations/src/{main/test/com.baeldung.annotations/EmployeeApplicationTest.java => test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java} (96%) create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java new file mode 100644 index 0000000000..fa5770b08e --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/AuthApplication.java @@ -0,0 +1,22 @@ +package com.baeldung.annotations.service; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AuthApplication { + + @Autowired + private AuthenticationService inMemoryAuthService; + + @Autowired + private AbstractAuthenticationService ldapAuthService; + + public static void main(String[] args) { + SpringApplication.run(AuthApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java new file mode 100644 index 0000000000..47fac229f7 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/abstracts/AbstractAuthenticationService.java @@ -0,0 +1,12 @@ +package com.baeldung.annotations.service.abstracts; + +import org.springframework.stereotype.Service; + +@Service +public abstract class AbstractAuthenticationService { + + public boolean authenticate(String username, String password) { + return false; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java new file mode 100644 index 0000000000..8f80cb8593 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/InMemoryAuthenticationService.java @@ -0,0 +1,14 @@ +package com.baeldung.annotations.service.concretes; + +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.springframework.stereotype.Service; + +@Service +public class InMemoryAuthenticationService implements AuthenticationService { + + @Override + public boolean authenticate(String username, String password) { + return false; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java new file mode 100644 index 0000000000..af93ea13be --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/concretes/LdapAuthenticationService.java @@ -0,0 +1,14 @@ +package com.baeldung.annotations.service.concretes; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import org.springframework.stereotype.Service; + +@Service +public class LdapAuthenticationService extends AbstractAuthenticationService { + + @Override + public boolean authenticate(String username, String password) { + return true; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java new file mode 100644 index 0000000000..0537343266 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/service/interfaces/AuthenticationService.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.interfaces; + +import org.springframework.stereotype.Service; + +@Service +public interface AuthenticationService { + + boolean authenticate(String username, String password); + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java similarity index 96% rename from spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java rename to spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java index 66700cf781..8dfc743f3d 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/EmployeeApplicationUnitTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertAll; -public class EmployeeApplicationTest { +public class EmployeeApplicationUnitTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withUserConfiguration(EmployeeApplication.class); diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java new file mode 100644 index 0000000000..ecbf1b38e5 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/AuthApplicationUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.annotations.service; + +import com.baeldung.annotations.service.abstracts.AbstractAuthenticationService; +import com.baeldung.annotations.service.config.AbstractsAnnotatedTestConfiguration; +import com.baeldung.annotations.service.config.ConcreteClassesAnnotatedTestConfiguration; +import com.baeldung.annotations.service.config.InterfacesAnnotatedTestConfiguration; +import com.baeldung.annotations.service.interfaces.AuthenticationService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +public class AuthApplicationUnitTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + + @Test + void whenOnlyInterfacesAnnotated_noSuchBeanDefinitionExceptionThrown() { + contextRunner + .withUserConfiguration(InterfacesAnnotatedTestConfiguration.class) + .run(context -> { + Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> { + context.getBean(AuthenticationService.class); + }); + }); + } + + @Test + void whenOnlyAbstractClassesAnnotated_noSuchBeanDefinitionExceptionThrown() { + contextRunner + .withUserConfiguration(AbstractsAnnotatedTestConfiguration.class) + .run(context -> { + Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> { + context.getBean(AbstractAuthenticationService.class); + }); + }); + } + + @Test + void whenConcreteClassesAnnotated_noExceptionThrown() { + contextRunner + .withUserConfiguration(ConcreteClassesAnnotatedTestConfiguration.class) + .run(context -> { + AuthenticationService inMemoryAuthService = context.getBean(AuthenticationService.class); + AbstractAuthenticationService ldapAuthService = context.getBean(AbstractAuthenticationService.class); + + Assertions.assertNotNull(inMemoryAuthService); + Assertions.assertNotNull(ldapAuthService); + }); + } +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..4c52401a06 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/AbstractsAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.abstracts") +public class AbstractsAnnotatedTestConfiguration { + +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..baf7fb970c --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/ConcreteClassesAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.concretes") +public class ConcreteClassesAnnotatedTestConfiguration { + +} diff --git a/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java new file mode 100644 index 0000000000..94659902a1 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/test/java/com.baeldung.annotations/service/config/InterfacesAnnotatedTestConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.annotations.service.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.ComponentScan; + +@TestConfiguration +@ComponentScan("com.baeldung.annotations.service.interfaces") +public class InterfacesAnnotatedTestConfiguration { + +} From 384b89d3ea78c39568fadf8e6a051f670952e398 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 12:57:49 -0300 Subject: [PATCH 138/149] added response timeout to timeout configuration --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 01de550a9c..f54d8a6c3d 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.ZonedDateTime; import java.util.Collections; import java.util.Map; @@ -116,7 +117,7 @@ public class WebClientIntegrationTest { .bodyToMono(String.class); Mono responsePostWithBody2 = headerSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost2.retrieve() + Mono responsePostWithBody3 = headerSpecPost3.retrieve() .bodyToMono(String.class); Mono responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class); @@ -168,6 +169,7 @@ public class WebClientIntegrationTest { public void givenWebClientWithTimeoutConfigurations_whenRequestUsingWronglyConfiguredPublisher_thenObtainTimeout() { HttpClient httpClient = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) + .responseTimeout(Duration.ofMillis(1000)) .doOnConnected(conn -> conn.addHandlerLast(new ReadTimeoutHandler(1000, TimeUnit.MILLISECONDS)) .addHandlerLast(new WriteTimeoutHandler(1000, TimeUnit.MILLISECONDS))); From f8ca77bc71323ac704fb138db497e05b4bd11562 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 16:05:31 -0300 Subject: [PATCH 139/149] fixed and improved reactive tests not getting verified --- .../web/client/WebClientIntegrationTest.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index f54d8a6c3d..cbf11766e1 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -1,7 +1,6 @@ package com.baeldung.web.client; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -42,7 +41,6 @@ import com.baeldung.web.reactive.client.Foo; import com.baeldung.web.reactive.client.WebClientApplication; import io.netty.channel.ChannelOption; -import io.netty.channel.ConnectTimeoutException; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import reactor.core.publisher.Mono; @@ -129,40 +127,45 @@ public class WebClientIntegrationTest { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); return responseHandler.bodyToMono(ref); }); + Mono responsePostOverridenBaseUri = bodySpecOverridenBaseUri.retrieve() + .bodyToMono(String.class); // response assertions StepVerifier.create(responsePostString) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostMultipart) - .expectNext("processed-multipartValue1-multipartValue2"); + .expectNext("processed-multipartValue1-multipartValue2") + .verifyComplete(); StepVerifier.create(responsePostWithBody1) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostWithBody2) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responsePostWithBody3) - .expectNext("processed-bodyValue"); + .expectNext("processed-bodyValue") + .verifyComplete(); StepVerifier.create(responseGet) .expectNextMatches(nextMap -> nextMap.get("field") - .equals("value")); + .equals("value")) + .verifyComplete(); StepVerifier.create(responsePostFoo) - .expectNext("processedFoo-fooName"); + .expectNext("processedFoo-fooName") + .verifyComplete(); StepVerifier.create(responsePostWithNoBody) .expectNextMatches(nextMap -> nextMap.get("error") - .equals("Bad Request")); - - // assert sending plain `new Object()` as request body - assertThrows(CodecException.class, () -> { - headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class)) - .block(); - }); + .equals("Bad Request")) + .verifyComplete(); // assert sending request overriding base uri - Exception exception = assertThrows(WebClientRequestException.class, () -> { - bodySpecOverridenBaseUri.retrieve() - .bodyToMono(String.class) - .block(); - }); - assertThat(exception.getMessage()).contains("Connection refused"); - + StepVerifier.create(responsePostOverridenBaseUri) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + // assert error plain `new Object()` as request body + StepVerifier.create(headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) + .expectError(CodecException.class) + .verify(); } @Test @@ -181,12 +184,11 @@ public class WebClientIntegrationTest { RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() .uri("/resource") .body(inserterCompleteSuscriber); - WebClientRequestException exception = assertThrows(WebClientRequestException.class, () -> { - headerSpecInserterCompleteSuscriber.retrieve() - .bodyToMono(String.class) - .block(); - }); - assertThat(exception.getCause()).isInstanceOf(ConnectTimeoutException.class); + + StepVerifier.create(headerSpecInserterCompleteSuscriber.retrieve() + .bodyToMono(String.class)) + .expectTimeout(Duration.ofMillis(2000)) + .verify(); } private RequestBodyUriSpec createDefaultPostRequest() { From d87cd065aa9ecb87dd080cce8b9b4dc14203a341 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 16:31:14 -0300 Subject: [PATCH 140/149] cleaned WebClient. definition for spec, for consistency and simplicity --- .../com/baeldung/web/client/WebClientIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index cbf11766e1..c8a306c4bc 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -66,8 +66,8 @@ public class WebClientIntegrationTest { .build(); // request specification - UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); - UriSpec uriSpecPost2 = client2.post(); + UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); + UriSpec uriSpecPost2 = client2.post(); UriSpec requestGet = client3.get(); // uri specification From 32f35285754fc004ad48e08a645dc2759b0b851a Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 17:41:44 -0300 Subject: [PATCH 141/149] added more common exchangeToMono example for article --- .../web/client/WebClientIntegrationTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index c8a306c4bc..9116ff3e63 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -115,8 +115,18 @@ public class WebClientIntegrationTest { .bodyToMono(String.class); Mono responsePostWithBody2 = headerSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost3.retrieve() - .bodyToMono(String.class); + Mono responsePostWithBody3 = headerSpecPost3.exchangeToMono(response -> { + if (response.statusCode() + .equals(HttpStatus.OK)) { + return response.bodyToMono(String.class); + } else if (response.statusCode() + .is4xxClientError()) { + return Mono.just("Error response"); + } else { + return response.createException() + .flatMap(Mono::error); + } + }); Mono responsePostFoo = headerSpecFooPost.retrieve() .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { From 0f668a63b91dadf4a9e5dc479a38f1d8c954a33b Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 17:53:48 -0300 Subject: [PATCH 142/149] renamed headersSpec to match article --- .../web/client/WebClientIntegrationTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 9116ff3e63..49edf422b0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -79,11 +79,11 @@ public class WebClientIntegrationTest { // request body specifications String bodyValue = "bodyValue"; - RequestHeadersSpec headerSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headerSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headerSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); - RequestHeadersSpec headerSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); - RequestHeadersSpec headerSpecGet = requestGet.uri("/resource"); + RequestHeadersSpec headersSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); + RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); + RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); + RequestHeadersSpec headersSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); + RequestHeadersSpec headersSpecGet = requestGet.uri("/resource"); // request body specifications - using inserters LinkedMultiValueMap map = new LinkedMultiValueMap<>(); @@ -94,28 +94,28 @@ public class WebClientIntegrationTest { BodyInserter inserterObject = BodyInserters.fromValue(new Object()); BodyInserter inserterString = BodyInserters.fromValue(bodyValue); - RequestHeadersSpec headerSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headerSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); - RequestHeadersSpec headerSpecInserterString = createDefaultPostResourceRequest().body(inserterString); + RequestHeadersSpec headersSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); + RequestHeadersSpec headersSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); + RequestHeadersSpec headersSpecInserterString = createDefaultPostResourceRequest().body(inserterString); // request header specification - RequestHeadersSpec headerSpecInserterStringWithHeaders = headerSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + RequestHeadersSpec headersSpecInserterStringWithHeaders = headersSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()); // request - ResponseSpec responseSpecPostString = headerSpecInserterStringWithHeaders.retrieve(); + ResponseSpec responseSpecPostString = headersSpecInserterStringWithHeaders.retrieve(); Mono responsePostString = responseSpecPostString.bodyToMono(String.class); - Mono responsePostMultipart = headerSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + Mono responsePostMultipart = headersSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .retrieve() .bodyToMono(String.class); - Mono responsePostWithBody1 = headerSpecPost1.retrieve() + Mono responsePostWithBody1 = headersSpecPost1.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody2 = headerSpecPost2.retrieve() + Mono responsePostWithBody2 = headersSpecPost2.retrieve() .bodyToMono(String.class); - Mono responsePostWithBody3 = headerSpecPost3.exchangeToMono(response -> { + Mono responsePostWithBody3 = headersSpecPost3.exchangeToMono(response -> { if (response.statusCode() .equals(HttpStatus.OK)) { return response.bodyToMono(String.class); @@ -127,11 +127,11 @@ public class WebClientIntegrationTest { .flatMap(Mono::error); } }); - Mono responsePostFoo = headerSpecFooPost.retrieve() + Mono responsePostFoo = headersSpecFooPost.retrieve() .bodyToMono(String.class); ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - Mono> responseGet = headerSpecGet.retrieve() + Mono> responseGet = headersSpecGet.retrieve() .bodyToMono(ref); Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -173,7 +173,7 @@ public class WebClientIntegrationTest { .contains("Connection refused")) .verify(); // assert error plain `new Object()` as request body - StepVerifier.create(headerSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) + StepVerifier.create(headersSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) .expectError(CodecException.class) .verify(); } @@ -191,11 +191,11 @@ public class WebClientIntegrationTest { .build(); BodyInserter, ReactiveHttpOutputMessage> inserterCompleteSuscriber = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); - RequestHeadersSpec headerSpecInserterCompleteSuscriber = timeoutClient.post() + RequestHeadersSpec headersSpecInserterCompleteSuscriber = timeoutClient.post() .uri("/resource") .body(inserterCompleteSuscriber); - StepVerifier.create(headerSpecInserterCompleteSuscriber.retrieve() + StepVerifier.create(headersSpecInserterCompleteSuscriber.retrieve() .bodyToMono(String.class)) .expectTimeout(Duration.ofMillis(2000)) .verify(); From c477f22f27fbe4c3900fa5e5ea79223e9dc255b6 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Tue, 26 Jan 2021 18:17:17 -0300 Subject: [PATCH 143/149] modified url override example, to use the client3 (the one defining the baseUrl) --- .../java/com/baeldung/web/client/WebClientIntegrationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index 49edf422b0..eddbf74868 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -75,7 +75,8 @@ public class WebClientIntegrationTest { RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") .build()); RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); - RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec bodySpecOverridenBaseUri = client3.post() + .uri(URI.create("/resource")); // request body specifications String bodyValue = "bodyValue"; From 047dfdef258719a8c91bde81329075f2dc5dc589 Mon Sep 17 00:00:00 2001 From: Gerardo Roza Date: Wed, 27 Jan 2021 12:28:41 -0300 Subject: [PATCH 144/149] split integration test into different test scenarios, one for each step in the webclient process --- .../web/client/WebClientIntegrationTest.java | 266 +++++++++++++----- 1 file changed, 192 insertions(+), 74 deletions(-) diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java index eddbf74868..39adf0b5c0 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebClientIntegrationTest.java @@ -33,8 +33,8 @@ import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec; import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; -import org.springframework.web.reactive.function.client.WebClient.UriSpec; import org.springframework.web.reactive.function.client.WebClientRequestException; import com.baeldung.web.reactive.client.Foo; @@ -53,9 +53,13 @@ public class WebClientIntegrationTest { @LocalServerPort private int port; + private static final String BODY_VALUE = "bodyValue"; + private static final ParameterizedTypeReference> MAP_RESPONSE_REF = new ParameterizedTypeReference>() { + }; + @Test - public void givenDifferentScenarios_whenRequestsSent_thenObtainExpectedResponses() { - // WebClient + public void givenDifferentWebClientCreationMethods_whenUsed_thenObtainExpectedResponse() { + // WebClient creation WebClient client1 = WebClient.create(); WebClient client2 = WebClient.create("http://localhost:" + port); WebClient client3 = WebClient.builder() @@ -65,58 +69,149 @@ public class WebClientIntegrationTest { .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) .build(); - // request specification - UriSpec uriSpecPost1 = client1.method(HttpMethod.POST); - UriSpec uriSpecPost2 = client2.post(); - UriSpec requestGet = client3.get(); + // response assertions + StepVerifier.create(retrieveResponse(client1.post() + .uri("http://localhost:" + port + "/resource"))) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(client2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(client3)) + .expectNext("processed-bodyValue") + .verifyComplete(); + // assert response without specifying URI + StepVerifier.create(retrieveResponse(client1)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + } + @Test + public void givenDifferentMethodSpecifications_whenUsed_thenObtainExpectedResponse() { + // request specification + RequestBodyUriSpec uriSpecPost1 = createDefaultClient().method(HttpMethod.POST); + RequestBodyUriSpec uriSpecPost2 = createDefaultClient().post(); + RequestHeadersUriSpec requestGet = createDefaultClient().get(); + + // response assertions + StepVerifier.create(retrieveResponse(uriSpecPost1)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(uriSpecPost2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveGetResponse(requestGet)) + .expectNextMatches(nextMap -> nextMap.get("field") + .equals("value")) + .verifyComplete(); + } + + @Test + public void givenDifferentUriSpecifications_whenUsed_thenObtainExpectedResponse() { // uri specification - RequestBodySpec bodySpecPost = uriSpecPost1.uri("http://localhost:" + port + "/resource"); - RequestBodySpec bodySpecPostMultipart = uriSpecPost2.uri(uriBuilder -> uriBuilder.pathSegment("resource-multipart") + RequestBodySpec bodySpecUsingString = createDefaultPostRequest().uri("/resource"); + RequestBodySpec bodySpecUsingUriBuilder = createDefaultPostRequest().uri(uriBuilder -> uriBuilder.pathSegment("resource") .build()); - RequestBodySpec fooBodySpecPost = createDefaultPostRequest().uri("/resource-foo"); - RequestBodySpec bodySpecOverridenBaseUri = client3.post() + RequestBodySpec bodySpecusingURI = createDefaultPostRequest().uri(URI.create("http://localhost:" + port + "/resource")); + RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + RequestBodySpec bodySpecOverridenBaseUri2 = WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .post() .uri(URI.create("/resource")); - // request body specifications - String bodyValue = "bodyValue"; - RequestHeadersSpec headersSpecPost1 = bodySpecPost.body(BodyInserters.fromPublisher(Mono.just(bodyValue), String.class)); - RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(bodyValue)); - RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(bodyValue); - RequestHeadersSpec headersSpecFooPost = fooBodySpecPost.body(Mono.just(new Foo("fooName")), Foo.class); - RequestHeadersSpec headersSpecGet = requestGet.uri("/resource"); + // response assertions + StepVerifier.create(retrieveResponse(bodySpecUsingString)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(bodySpecUsingUriBuilder)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(bodySpecusingURI)) + .expectNext("processed-bodyValue") + .verifyComplete(); + // assert sending request overriding base URI + StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri2)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + } - // request body specifications - using inserters + @Test + public void givenDifferentBodySpecifications_whenUsed_thenObtainExpectedResponse() { + // request body specifications + RequestHeadersSpec headersSpecPost1 = createDefaultPostResourceRequest().body(BodyInserters.fromPublisher(Mono.just(BODY_VALUE), String.class)); + RequestHeadersSpec headersSpecPost2 = createDefaultPostResourceRequest().body(BodyInserters.fromValue(BODY_VALUE)); + RequestHeadersSpec headersSpecPost3 = createDefaultPostResourceRequest().bodyValue(BODY_VALUE); + RequestHeadersSpec headersSpecFooPost = createDefaultPostRequest().uri("/resource-foo") + .body(Mono.just(new Foo("fooName")), Foo.class); + BodyInserter inserterPlainObject = BodyInserters.fromValue(new Object()); + RequestHeadersSpec headersSpecPlainObject = createDefaultPostResourceRequest().body(inserterPlainObject); + + // request body specifications - using other inserter method (multipart request) LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "multipartValue1"); map.add("key2", "multipartValue2"); - BodyInserter, ClientHttpRequest> inserterMultipart = BodyInserters.fromMultipartData(map); - BodyInserter inserterObject = BodyInserters.fromValue(new Object()); - BodyInserter inserterString = BodyInserters.fromValue(bodyValue); + RequestHeadersSpec headersSpecInserterMultipart = createDefaultPostRequest().uri("/resource-multipart") + .body(inserterMultipart); - RequestHeadersSpec headersSpecInserterMultipart = bodySpecPostMultipart.body(inserterMultipart); - RequestHeadersSpec headersSpecInserterObject = createDefaultPostResourceRequest().body(inserterObject); - RequestHeadersSpec headersSpecInserterString = createDefaultPostResourceRequest().body(inserterString); + // response assertions + StepVerifier.create(retrieveResponse(headersSpecPost1)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecPost2)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecPost3)) + .expectNext("processed-bodyValue") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecFooPost)) + .expectNext("processedFoo-fooName") + .verifyComplete(); + StepVerifier.create(retrieveResponse(headersSpecInserterMultipart)) + .expectNext("processed-multipartValue1-multipartValue2") + .verifyComplete(); + // assert error plain `new Object()` as request body + StepVerifier.create(retrieveResponse(headersSpecPlainObject)) + .expectError(CodecException.class) + .verify(); + // assert response for request with no body + Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { + assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + return responseHandler.bodyToMono(MAP_RESPONSE_REF); + }); + StepVerifier.create(responsePostWithNoBody) + .expectNextMatches(nextMap -> nextMap.get("error") + .equals("Bad Request")) + .verifyComplete(); + } + @Test + public void givenPostSpecifications_whenHeadersAdded_thenObtainExpectedResponse() { // request header specification - RequestHeadersSpec headersSpecInserterStringWithHeaders = headersSpecInserterString.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + RequestHeadersSpec headersSpecInserterStringWithHeaders = createDefaultPostResourceRequestResponse().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .acceptCharset(StandardCharsets.UTF_8) .ifNoneMatch("*") .ifModifiedSince(ZonedDateTime.now()); - // request - ResponseSpec responseSpecPostString = headersSpecInserterStringWithHeaders.retrieve(); + // response assertions + StepVerifier.create(retrieveResponse(headersSpecInserterStringWithHeaders)) + .expectNext("processed-bodyValue") + .verifyComplete(); + } + + @Test + public void givenDifferentResponseSpecifications_whenUsed_thenObtainExpectedResponse() { + ResponseSpec responseSpecPostString = createDefaultPostResourceRequestResponse().retrieve(); Mono responsePostString = responseSpecPostString.bodyToMono(String.class); - Mono responsePostMultipart = headersSpecInserterMultipart.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) - .retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody1 = headersSpecPost1.retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody2 = headersSpecPost2.retrieve() - .bodyToMono(String.class); - Mono responsePostWithBody3 = headersSpecPost3.exchangeToMono(response -> { + Mono responsePostString2 = createDefaultPostResourceRequestResponse().exchangeToMono(response -> { if (response.statusCode() .equals(HttpStatus.OK)) { return response.bodyToMono(String.class); @@ -128,55 +223,37 @@ public class WebClientIntegrationTest { .flatMap(Mono::error); } }); - Mono responsePostFoo = headersSpecFooPost.retrieve() - .bodyToMono(String.class); - ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { - }; - Mono> responseGet = headersSpecGet.retrieve() - .bodyToMono(ref); - Mono> responsePostWithNoBody = createDefaultPostResourceRequest().exchangeToMono(responseHandler -> { - assertThat(responseHandler.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST); - return responseHandler.bodyToMono(ref); + Mono responsePostNoBody = createDefaultPostResourceRequest().exchangeToMono(response -> { + if (response.statusCode() + .equals(HttpStatus.OK)) { + return response.bodyToMono(String.class); + } else if (response.statusCode() + .is4xxClientError()) { + return Mono.just("Error response"); + } else { + return response.createException() + .flatMap(Mono::error); + } }); - Mono responsePostOverridenBaseUri = bodySpecOverridenBaseUri.retrieve() - .bodyToMono(String.class); + Mono> responseGet = createDefaultClient().get() + .uri("/resource") + .retrieve() + .bodyToMono(MAP_RESPONSE_REF); // response assertions StepVerifier.create(responsePostString) .expectNext("processed-bodyValue") .verifyComplete(); - StepVerifier.create(responsePostMultipart) - .expectNext("processed-multipartValue1-multipartValue2") - .verifyComplete(); - StepVerifier.create(responsePostWithBody1) + StepVerifier.create(responsePostString2) .expectNext("processed-bodyValue") .verifyComplete(); - StepVerifier.create(responsePostWithBody2) - .expectNext("processed-bodyValue") - .verifyComplete(); - StepVerifier.create(responsePostWithBody3) - .expectNext("processed-bodyValue") + StepVerifier.create(responsePostNoBody) + .expectNext("Error response") .verifyComplete(); StepVerifier.create(responseGet) .expectNextMatches(nextMap -> nextMap.get("field") .equals("value")) .verifyComplete(); - StepVerifier.create(responsePostFoo) - .expectNext("processedFoo-fooName") - .verifyComplete(); - StepVerifier.create(responsePostWithNoBody) - .expectNextMatches(nextMap -> nextMap.get("error") - .equals("Bad Request")) - .verifyComplete(); - // assert sending request overriding base uri - StepVerifier.create(responsePostOverridenBaseUri) - .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() - .contains("Connection refused")) - .verify(); - // assert error plain `new Object()` as request body - StepVerifier.create(headersSpecInserterObject.exchangeToMono(response -> response.bodyToMono(String.class))) - .expectError(CodecException.class) - .verify(); } @Test @@ -202,12 +279,53 @@ public class WebClientIntegrationTest { .verify(); } + // helper methods to create default instances + private WebClient createDefaultClient() { + return WebClient.create("http://localhost:" + port); + } + private RequestBodyUriSpec createDefaultPostRequest() { - return WebClient.create("http://localhost:" + port) - .post(); + return createDefaultClient().post(); } private RequestBodySpec createDefaultPostResourceRequest() { return createDefaultPostRequest().uri("/resource"); } + + private RequestHeadersSpec createDefaultPostResourceRequestResponse() { + return createDefaultPostResourceRequest().bodyValue(BODY_VALUE); + } + + // helper methods to retrieve a response based on different steps of the process (specs) + private Mono retrieveResponse(WebClient client) { + return client.post() + .uri("/resource") + .bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono retrieveResponse(RequestBodyUriSpec spec) { + return spec.uri("/resource") + .bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono> retrieveGetResponse(RequestHeadersUriSpec spec) { + return spec.uri("/resource") + .retrieve() + .bodyToMono(MAP_RESPONSE_REF); + } + + private Mono retrieveResponse(RequestBodySpec spec) { + return spec.bodyValue(BODY_VALUE) + .retrieve() + .bodyToMono(String.class); + } + + private Mono retrieveResponse(RequestHeadersSpec spec) { + return spec.retrieve() + .bodyToMono(String.class); + } } From b6570de6379a1818164aa401ddce8c12f787306c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:11:32 +0800 Subject: [PATCH 145/149] Update README.md --- testing-modules/mockito-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index c7b62182b5..4bd2ff9759 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -9,3 +9,4 @@ - [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) - [Using Mockito ArgumentCaptor](https://www.baeldung.com/mockito-argumentcaptor) - [Difference Between when() and doXxx() Methods in Mockito](https://www.baeldung.com/java-mockito-when-vs-do) +- [Overview of Mockito MockSettings](https://www.baeldung.com/mockito-mocksettings) From fe2aab7fb9ccfbd53c54f4e867111f187d357ed4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:21:00 +0800 Subject: [PATCH 146/149] Update README.md --- spring-web-modules/spring-rest-http-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-web-modules/spring-rest-http-2/README.md b/spring-web-modules/spring-rest-http-2/README.md index 97cdc2d068..b5358f888f 100644 --- a/spring-web-modules/spring-rest-http-2/README.md +++ b/spring-web-modules/spring-rest-http-2/README.md @@ -8,3 +8,4 @@ The "REST With Spring 2" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [How to Turn Off Swagger-ui in Production](https://www.baeldung.com/swagger-ui-turn-off-in-production) +- [Setting a Request Timeout for a Spring REST API](https://www.baeldung.com/spring-rest-timeout) From 7634f6a6bd281294188f5056f048477659d3bfd2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:23:32 +0800 Subject: [PATCH 147/149] Update README.md --- performance-tests/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/performance-tests/README.md b/performance-tests/README.md index 27c0363010..09bf6dba1f 100644 --- a/performance-tests/README.md +++ b/performance-tests/README.md @@ -6,6 +6,7 @@ This module contains articles about performance testing. - [Performance of Java Mapping Frameworks](https://www.baeldung.com/java-performance-mapping-frameworks) - [Performance Effects of Exceptions in Java](https://www.baeldung.com/java-exceptions-performance) +- [Is Java a Compiled or Interpreted Language?](https://www.baeldung.com/java-compiled-interpreted) ### Running From a65de428fd776ed6fd10849b172ca2001834fdce Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:26:15 +0800 Subject: [PATCH 148/149] Update README.md --- spring-boot-modules/spring-boot-annotations/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-annotations/README.md b/spring-boot-modules/spring-boot-annotations/README.md index 6ead94de86..1b2bca435c 100644 --- a/spring-boot-modules/spring-boot-annotations/README.md +++ b/spring-boot-modules/spring-boot-annotations/README.md @@ -10,3 +10,4 @@ This module contains articles about Spring Boot annotations - [Spring Core Annotations](https://www.baeldung.com/spring-core-annotations) - [Spring Bean Annotations](https://www.baeldung.com/spring-bean-annotations) - [Difference Between @ComponentScan and @EnableAutoConfiguration in Spring Boot](https://www.baeldung.com/spring-componentscan-vs-enableautoconfiguration) +- [Where Should the Spring @Service Annotation Be Kept?](https://www.baeldung.com/spring-service-annotation-placement) From d11f1163abe40a87787fed5c6d0e31ee26357adf Mon Sep 17 00:00:00 2001 From: dvyshd <34768329+dvyshd@users.noreply.github.com> Date: Thu, 28 Jan 2021 23:53:49 +0000 Subject: [PATCH 149/149] BAEL-4719 - Using the Map.Entry Java Class (#10428) * BAEL-4719 Using the Map.Entry Java Class * BAEL-4719 Using the Map.Entry Java Class * BAEL-4719 Change description * BAEL-4719 Feedback from first draft --- .../java/com/baeldung/map/entry/Book.java | 35 +++++++++++++++++++ .../map/entry/MapEntryEfficiencyExample.java | 34 ++++++++++++++++++ .../map/entry/MapEntryTupleExample.java | 25 +++++++++++++ .../baeldung/map/entry/MapEntryUnitTest.java | 33 +++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java create mode 100644 java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java create mode 100644 java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java new file mode 100644 index 0000000000..7e47e22908 --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/Book.java @@ -0,0 +1,35 @@ +package com.baeldung.map.entry; + +public class Book { + private String title; + private String author; + + public Book(String title, String author) { + this.title = title; + this.author = author; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + @Override + public String toString() { + return "Book{" + + "title='" + title + '\'' + + ", author='" + author + '\'' + + '}'; + } +} diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java new file mode 100644 index 0000000000..d64bcb38df --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryEfficiencyExample.java @@ -0,0 +1,34 @@ +package com.baeldung.map.entry; + +import java.util.HashMap; +import java.util.Map; + +public class MapEntryEfficiencyExample { + + public static void main(String[] args) { + MapEntryEfficiencyExample mapEntryEfficiencyExample = new MapEntryEfficiencyExample(); + Map map = new HashMap<>(); + + map.put("Robert C. Martin", "Clean Code"); + map.put("Joshua Bloch", "Effective Java"); + + System.out.println("Iterating Using Map.KeySet - 2 operations"); + mapEntryEfficiencyExample.usingKeySet(map); + + System.out.println("Iterating Using Map.Entry - 1 operation"); + mapEntryEfficiencyExample.usingEntrySet(map); + + } + + public void usingKeySet(Map bookMap) { + for (String key : bookMap.keySet()) { + System.out.println("key: " + key + " value: " + bookMap.get(key)); + } + } + + public void usingEntrySet(Map bookMap) { + for (Map.Entry book: bookMap.entrySet()) { + System.out.println("key: " + book.getKey() + " value: " + book.getValue()); + } + } +} diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java new file mode 100644 index 0000000000..edcbd263fe --- /dev/null +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/entry/MapEntryTupleExample.java @@ -0,0 +1,25 @@ +package com.baeldung.map.entry; + +import java.util.*; + +public class MapEntryTupleExample { + + public static void main(String[] args) { + Map.Entry tuple1; + Map.Entry tuple2; + Map.Entry tuple3; + + tuple1 = new AbstractMap.SimpleEntry<>("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch")); + tuple2 = new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin")); + tuple3 = new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin")); + + List> orderedTuples = new ArrayList<>(); + orderedTuples.add(tuple1); + orderedTuples.add(tuple2); + orderedTuples.add(tuple3); + + for (Map.Entry tuple : orderedTuples) { + System.out.println("key: " + tuple.getKey() + " value: " + tuple.getValue()); + } + } +} diff --git a/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java b/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java new file mode 100644 index 0000000000..7340558023 --- /dev/null +++ b/java-collections-maps-3/src/test/java/com/baeldung/map/entry/MapEntryUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.map.entry; + +import org.junit.Test; + +import java.util.*; + +import static org.junit.Assert.assertEquals; + +public class MapEntryUnitTest { + + @Test + public void givenSimpleEntryList_whenAddDuplicateKey_thenDoesNotOverwriteExistingKey() { + List> orderedTuples = new ArrayList<>(); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch"))); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin"))); + orderedTuples.add(new AbstractMap.SimpleEntry<>("9780132350884", new Book("Clean Code", "Robert C Martin"))); + + assertEquals(3, orderedTuples.size()); + assertEquals("9780134685991", orderedTuples.get(0).getKey()); + assertEquals("9780132350884", orderedTuples.get(1).getKey()); + assertEquals("9780132350884", orderedTuples.get(2).getKey()); + } + + @Test + public void givenRegularMap_whenAddDuplicateKey_thenOverwritesExistingKey() { + Map entries = new HashMap<>(); + entries.put("9780134685991", new Book("Effective Java 3d Edition", "Joshua Bloch")); + entries.put("9780132350884", new Book("Clean Code", "Robert C Martin")); + entries.put("9780132350884", new Book("Clean Code", "Robert C Martin")); + + assertEquals(2, entries.size()); + } +}