From 5c8a1373498a1eed20a14085863c63327fa8a3c9 Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Fri, 6 Oct 2023 17:48:47 +0530 Subject: [PATCH 001/107] JAVA-18764: Chnages made for applcation.yml file --- .../src/main/resources/application.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/security-modules/cas/cas-server/src/main/resources/application.yml b/security-modules/cas/cas-server/src/main/resources/application.yml index 0c4e4ffde2..0fd72c539d 100644 --- a/security-modules/cas/cas-server/src/main/resources/application.yml +++ b/security-modules/cas/cas-server/src/main/resources/application.yml @@ -8,3 +8,19 @@ server: spring: main: allow-bean-definition-overriding: true +cas: + authn: + accept: + users: + jdbc: + query[0]: + sql: SELECT * FROM users WHERE email = ? + url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC + dialect: org.hibernate.dialect.MySQLDialect + user: root + password: root1234 + ddlAuto: none + driverClass: com.mysql.cj.jdbc.Driver + fieldPassword: password + passwordEncoder: + type: NONE From c8bc9634d5ca7f92fe65193ff6ddec6b8682ebfd Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Mon, 9 Oct 2023 21:00:52 +0530 Subject: [PATCH 002/107] JAVA-18764: Update article "CAS SSO with Spring Security" --- security-modules/cas/cas-secured-app/pom.xml | 9 ++++ .../cassecuredapp/CasSecuredApplication.java | 11 ++++- .../cassecuredapp/MyUserDetailsService.java | 34 +++++++++++++++ .../cassecuredapp/UserRepository.java | 15 +++++++ .../com/baeldung/cassecuredapp/Users.java | 41 +++++++++++++++++++ .../src/main/resources/application.properties | 8 +++- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java create mode 100644 security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java create mode 100644 security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java diff --git a/security-modules/cas/cas-secured-app/pom.xml b/security-modules/cas/cas-secured-app/pom.xml index 6f1ec22cb5..6e1b878354 100644 --- a/security-modules/cas/cas-secured-app/pom.xml +++ b/security-modules/cas/cas-secured-app/pom.xml @@ -36,6 +36,15 @@ spring-boot-devtools runtime + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + org.springframework.boot spring-boot-starter-test diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java index 62da9cf725..9293a3e00f 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java @@ -6,6 +6,7 @@ import org.jasig.cas.client.validation.Cas30ServiceTicketValidator; import org.jasig.cas.client.validation.TicketValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -34,6 +35,7 @@ public class CasSecuredApplication { SpringApplication.run(CasSecuredApplication.class, args); } + @Bean public CasAuthenticationFilter casAuthenticationFilter( AuthenticationManager authenticationManager, @@ -58,6 +60,10 @@ public class CasSecuredApplication { return new Cas30ServiceTicketValidator("https://localhost:8443/cas"); } + @Bean + public MyUserDetailsService getUser(){ + return new MyUserDetailsService(); + } @Bean public CasAuthenticationProvider casAuthenticationProvider( TicketValidator ticketValidator, @@ -65,9 +71,10 @@ public class CasSecuredApplication { CasAuthenticationProvider provider = new CasAuthenticationProvider(); provider.setServiceProperties(serviceProperties); provider.setTicketValidator(ticketValidator); - provider.setUserDetailsService( + /* provider.setUserDetailsService( s -> new User("casuser", "Mellon", true, true, true, true, - AuthorityUtils.createAuthorityList("ROLE_ADMIN"))); + AuthorityUtils.createAuthorityList("ROLE_ADMIN")));*/ + provider.setUserDetailsService(getUser()); provider.setKey("CAS_PROVIDER_LOCALHOST_8900"); return provider; } diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java new file mode 100644 index 0000000000..35c83bfd75 --- /dev/null +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java @@ -0,0 +1,34 @@ +package com.baeldung.cassecuredapp; + +import java.util.Collections; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public class MyUserDetailsService implements UserDetailsService { + + @Autowired + private UserRepository userRepository; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + // Get the user from the database. + Users users = getUserFromDatabase(username); + + // Create a UserDetails object. + UserDetails userDetails = new User( + users.getEmail(), + users.getPassword(), + Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"))); + + return userDetails; + } + + private Users getUserFromDatabase(String username) { + return userRepository.findByEmail(username); + } +} diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java new file mode 100644 index 0000000000..366329a3fb --- /dev/null +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java @@ -0,0 +1,15 @@ +package com.baeldung.cassecuredapp; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends CrudRepository { + + Users findByEmail(@Param("email") String email); + +} diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java new file mode 100644 index 0000000000..4e775e80e3 --- /dev/null +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java @@ -0,0 +1,41 @@ +package com.baeldung.cassecuredapp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Users { + @Id + private Long id; + + @Column(nullable = false, unique = true) + private String email; + + private String password; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/security-modules/cas/cas-secured-app/src/main/resources/application.properties b/security-modules/cas/cas-secured-app/src/main/resources/application.properties index f8789997d5..fa13527982 100644 --- a/security-modules/cas/cas-secured-app/src/main/resources/application.properties +++ b/security-modules/cas/cas-secured-app/src/main/resources/application.properties @@ -1,2 +1,8 @@ server.port=8900 -spring.freemarker.suffix=.ftl \ No newline at end of file +spring.freemarker.suffix=.ftl + +spring.jpa.generate-ddl=false +spring.datasource.url= jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC +spring.datasource.username=root +spring.datasource.password=root1234 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file From 23124ab6f81536cb1a7e242d9caad1aead3fdf14 Mon Sep 17 00:00:00 2001 From: Vinay Mhatre <90505086+SamsterZero@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:26:22 +0530 Subject: [PATCH 003/107] To change default redirect Previously after logging in we used to get the desired index page, but the address bar still had the "/login" in the address bar, this code fixes that --- .../com/baeldung/customuserdetails/SecurityConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java index cfec910ce9..d438aefcdc 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java @@ -28,7 +28,7 @@ public class SecurityConfiguration { .formLogin() .loginPage("/login") .permitAll() - .successForwardUrl("/index") + .defaultSuccessUrl("/index") .and() .logout() .permitAll() From 1071a071706b8ed306153628d9610a91cf4de82a Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Thu, 19 Oct 2023 19:33:27 +0530 Subject: [PATCH 004/107] JAVA-18764: Changes made for updating the pkg --- .../cassecuredapp/CasSecuredApplication.java | 15 +++------------ .../baeldung/cassecuredapp/UserRepository.java | 15 --------------- .../CasUserDetailsService.java} | 18 ++++++++++-------- .../{Users.java => user/User.java} | 4 ++-- .../cassecuredapp/user/UserRepository.java | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java rename security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/{MyUserDetailsService.java => service/CasUserDetailsService.java} (63%) rename security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/{Users.java => user/User.java} (91%) create mode 100644 security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java index 9293a3e00f..84bbd2ace4 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java @@ -1,30 +1,21 @@ package com.baeldung.cassecuredapp; import org.jasig.cas.client.session.SingleSignOutFilter; -import org.jasig.cas.client.session.SingleSignOutHttpSessionListener; import org.jasig.cas.client.validation.Cas30ServiceTicketValidator; import org.jasig.cas.client.validation.TicketValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.context.event.EventListener; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.cas.ServiceProperties; import org.springframework.security.cas.authentication.CasAuthenticationProvider; -import org.springframework.security.cas.web.CasAuthenticationEntryPoint; import org.springframework.security.cas.web.CasAuthenticationFilter; -import org.springframework.security.core.authority.AuthorityUtils; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; import org.springframework.security.web.authentication.logout.LogoutFilter; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; -import javax.servlet.http.HttpSessionEvent; +import com.baeldung.cassecuredapp.service.CasUserDetailsService; @SpringBootApplication public class CasSecuredApplication { @@ -61,8 +52,8 @@ public class CasSecuredApplication { } @Bean - public MyUserDetailsService getUser(){ - return new MyUserDetailsService(); + public CasUserDetailsService getUser(){ + return new CasUserDetailsService(); } @Bean public CasAuthenticationProvider casAuthenticationProvider( diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java deleted file mode 100644 index 366329a3fb..0000000000 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.cassecuredapp; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -@Repository -public interface UserRepository extends CrudRepository { - - Users findByEmail(@Param("email") String email); - -} diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java similarity index 63% rename from security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java index 35c83bfd75..ac4fef1ff0 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/MyUserDetailsService.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java @@ -1,15 +1,17 @@ -package com.baeldung.cassecuredapp; +package com.baeldung.cassecuredapp.service; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -public class MyUserDetailsService implements UserDetailsService { +import com.baeldung.cassecuredapp.user.User; +import com.baeldung.cassecuredapp.user.UserRepository; + +public class CasUserDetailsService implements UserDetailsService { @Autowired private UserRepository userRepository; @@ -17,18 +19,18 @@ public class MyUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { // Get the user from the database. - Users users = getUserFromDatabase(username); + User user = getUserFromDatabase(username); // Create a UserDetails object. - UserDetails userDetails = new User( - users.getEmail(), - users.getPassword(), + UserDetails userDetails = new org.springframework.security.core.userdetails.User( + user.getEmail(), + user.getPassword(), Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"))); return userDetails; } - private Users getUserFromDatabase(String username) { + private User getUserFromDatabase(String username) { return userRepository.findByEmail(username); } } diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java similarity index 91% rename from security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java index 4e775e80e3..1dddc11458 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/Users.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java @@ -1,11 +1,11 @@ -package com.baeldung.cassecuredapp; +package com.baeldung.cassecuredapp.user; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @Entity -public class Users { +public class User { @Id private Long id; diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java new file mode 100644 index 0000000000..0481fabb06 --- /dev/null +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.cassecuredapp.user; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.cassecuredapp.user.User; + +@Repository +public interface UserRepository extends CrudRepository { + + User findByEmail(@Param("email") String email); + +} From 199df44c7f2978ed766273dd2bb17fce66ad0531 Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Mon, 23 Oct 2023 16:11:03 +0530 Subject: [PATCH 005/107] JAVA-18764: Changes made for updating the code --- .../cassecuredapp/CasSecuredApplication.java | 9 ++++++--- .../service/CasUserDetailsService.java | 13 +++++++------ .../cassecuredapp/user/{User.java => CasUser.java} | 2 +- .../baeldung/cassecuredapp/user/UserRepository.java | 6 ++---- .../src/main/resources/application.properties | 10 +++++----- 5 files changed, 21 insertions(+), 19 deletions(-) rename security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/{User.java => CasUser.java} (96%) diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java index 84bbd2ace4..f78d7a45d5 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java @@ -12,6 +12,8 @@ import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.cas.ServiceProperties; import org.springframework.security.cas.authentication.CasAuthenticationProvider; import org.springframework.security.cas.web.CasAuthenticationFilter; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.User; import org.springframework.security.web.authentication.logout.LogoutFilter; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; @@ -62,10 +64,11 @@ public class CasSecuredApplication { CasAuthenticationProvider provider = new CasAuthenticationProvider(); provider.setServiceProperties(serviceProperties); provider.setTicketValidator(ticketValidator); - /* provider.setUserDetailsService( + provider.setUserDetailsService( s -> new User("casuser", "Mellon", true, true, true, true, - AuthorityUtils.createAuthorityList("ROLE_ADMIN")));*/ - provider.setUserDetailsService(getUser()); + AuthorityUtils.createAuthorityList("ROLE_ADMIN"))); + //For Authentication with a Database-backed UserDetailsService + //provider.setUserDetailsService(getUser()); provider.setKey("CAS_PROVIDER_LOCALHOST_8900"); return provider; } diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java index ac4fef1ff0..801f5726b7 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/service/CasUserDetailsService.java @@ -4,11 +4,12 @@ import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.baeldung.cassecuredapp.user.User; +import com.baeldung.cassecuredapp.user.CasUser; import com.baeldung.cassecuredapp.user.UserRepository; public class CasUserDetailsService implements UserDetailsService { @@ -19,18 +20,18 @@ public class CasUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { // Get the user from the database. - User user = getUserFromDatabase(username); + CasUser casUser = getUserFromDatabase(username); // Create a UserDetails object. - UserDetails userDetails = new org.springframework.security.core.userdetails.User( - user.getEmail(), - user.getPassword(), + UserDetails userDetails = new User( + casUser.getEmail(), + casUser.getPassword(), Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"))); return userDetails; } - private User getUserFromDatabase(String username) { + private CasUser getUserFromDatabase(String username) { return userRepository.findByEmail(username); } } diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/CasUser.java similarity index 96% rename from security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/CasUser.java index 1dddc11458..2bf96d0994 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/User.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/CasUser.java @@ -5,7 +5,7 @@ import javax.persistence.Entity; import javax.persistence.Id; @Entity -public class User { +public class CasUser { @Id private Long id; diff --git a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java index 0481fabb06..623ccf2e38 100644 --- a/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java +++ b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/user/UserRepository.java @@ -4,11 +4,9 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import com.baeldung.cassecuredapp.user.User; - @Repository -public interface UserRepository extends CrudRepository { +public interface UserRepository extends CrudRepository { - User findByEmail(@Param("email") String email); + CasUser findByEmail(@Param("email") String email); } diff --git a/security-modules/cas/cas-secured-app/src/main/resources/application.properties b/security-modules/cas/cas-secured-app/src/main/resources/application.properties index fa13527982..5c93c67ff1 100644 --- a/security-modules/cas/cas-secured-app/src/main/resources/application.properties +++ b/security-modules/cas/cas-secured-app/src/main/resources/application.properties @@ -1,8 +1,8 @@ server.port=8900 spring.freemarker.suffix=.ftl -spring.jpa.generate-ddl=false -spring.datasource.url= jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC -spring.datasource.username=root -spring.datasource.password=root1234 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file +#spring.jpa.generate-ddl=false +#spring.datasource.url= jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC +#spring.datasource.username=root +#spring.datasource.password=root +#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file From d2cd902965cc8968628185b57f5f31e0de94724c Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Mon, 23 Oct 2023 16:12:35 +0530 Subject: [PATCH 006/107] JAVA-18764: Update article "CAS SSO with Spring Security" --- .../src/main/resources/application.yml | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/security-modules/cas/cas-server/src/main/resources/application.yml b/security-modules/cas/cas-server/src/main/resources/application.yml index 0fd72c539d..a49e86dd09 100644 --- a/security-modules/cas/cas-server/src/main/resources/application.yml +++ b/security-modules/cas/cas-server/src/main/resources/application.yml @@ -8,19 +8,19 @@ server: spring: main: allow-bean-definition-overriding: true -cas: - authn: - accept: - users: - jdbc: - query[0]: - sql: SELECT * FROM users WHERE email = ? - url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC - dialect: org.hibernate.dialect.MySQLDialect - user: root - password: root1234 - ddlAuto: none - driverClass: com.mysql.cj.jdbc.Driver - fieldPassword: password - passwordEncoder: - type: NONE +#cas: +# authn: +# accept: +# users: +# jdbc: +# query[0]: +# sql: SELECT * FROM users WHERE email = ? +# url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC +# dialect: org.hibernate.dialect.MySQLDialect +# user: root +# password: root +# ddlAuto: none +# driverClass: com.mysql.cj.jdbc.Driver +# fieldPassword: password +# passwordEncoder: +# type: NONE From bb9a96d9b36c5806a0ace5042d3f9df50e6c6673 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Fri, 27 Oct 2023 22:48:52 +0530 Subject: [PATCH 007/107] JAVA-26380 Change parent of spring-security-modules- Check build failures --- spring-security-modules/pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index ed8279c5f7..1b3db18b84 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -10,8 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 From dc6b248d9d31785226c255dc6f96495b2eb34e61 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 28 Oct 2023 12:26:06 +0530 Subject: [PATCH 008/107] JAVA-26280 Improve libraries-testing module build time --- libraries-testing/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-testing/pom.xml b/libraries-testing/pom.xml index 2c7f231fdc..8db9e4e5c5 100644 --- a/libraries-testing/pom.xml +++ b/libraries-testing/pom.xml @@ -213,7 +213,7 @@ 1.9.9 1.46.0 1.9.0 - 3.6.12 + 4.0.18 1.5.0 3.0.0 0.8.1 From 246d83d49d6790be372681ef3233ff567b02334b Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 28 Oct 2023 13:19:47 +0530 Subject: [PATCH 009/107] JAVA-26380 Update parent of child modules to use immediate parent --- spring-security-modules/spring-security-acl/pom.xml | 3 +-- spring-security-modules/spring-security-auth0/pom.xml | 3 +-- spring-security-modules/spring-security-azuread/pom.xml | 3 +-- spring-security-modules/spring-security-cognito/pom.xml | 3 +-- spring-security-modules/spring-security-core-2/pom.xml | 3 +-- spring-security-modules/spring-security-core/pom.xml | 3 +-- spring-security-modules/spring-security-ldap/pom.xml | 3 +-- spring-security-modules/spring-security-legacy-oidc/pom.xml | 3 +-- spring-security-modules/spring-security-oauth2-sso/pom.xml | 3 +-- spring-security-modules/spring-security-oauth2/pom.xml | 3 +-- spring-security-modules/spring-security-oidc/pom.xml | 3 +-- spring-security-modules/spring-security-okta/pom.xml | 3 +-- spring-security-modules/spring-security-opa/pom.xml | 3 +-- spring-security-modules/spring-security-pkce/pom.xml | 3 +-- spring-security-modules/spring-security-saml/pom.xml | 3 +-- spring-security-modules/spring-security-social-login/pom.xml | 3 +-- spring-security-modules/spring-security-web-angular/pom.xml | 3 +-- spring-security-modules/spring-security-web-boot-1/pom.xml | 3 +-- spring-security-modules/spring-security-web-boot-2/pom.xml | 3 +-- spring-security-modules/spring-security-web-boot-3/pom.xml | 3 +-- spring-security-modules/spring-security-web-boot-4/pom.xml | 3 +-- spring-security-modules/spring-security-web-boot-5/pom.xml | 3 +-- spring-security-modules/spring-security-web-login-2/pom.xml | 3 +-- spring-security-modules/spring-security-web-mvc/pom.xml | 3 +-- .../spring-security-web-rest-basic-auth/pom.xml | 3 +-- .../spring-security-web-rest-custom/pom.xml | 3 +-- spring-security-modules/spring-security-web-springdoc/pom.xml | 3 +-- spring-security-modules/spring-security-web-thymeleaf/pom.xml | 3 +-- spring-security-modules/spring-security-web-x509/pom.xml | 3 +-- 29 files changed, 29 insertions(+), 58 deletions(-) diff --git a/spring-security-modules/spring-security-acl/pom.xml b/spring-security-modules/spring-security-acl/pom.xml index 7facc1b14b..734b85800a 100644 --- a/spring-security-modules/spring-security-acl/pom.xml +++ b/spring-security-modules/spring-security-acl/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-auth0/pom.xml b/spring-security-modules/spring-security-auth0/pom.xml index 106a0db29f..8ee59eeac1 100644 --- a/spring-security-modules/spring-security-auth0/pom.xml +++ b/spring-security-modules/spring-security-auth0/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-azuread/pom.xml b/spring-security-modules/spring-security-azuread/pom.xml index c1fe08b47a..7e67a7e635 100644 --- a/spring-security-modules/spring-security-azuread/pom.xml +++ b/spring-security-modules/spring-security-azuread/pom.xml @@ -6,9 +6,8 @@ 4.0.0 com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 spring-security-azuread diff --git a/spring-security-modules/spring-security-cognito/pom.xml b/spring-security-modules/spring-security-cognito/pom.xml index 56754ddf99..2e359382a7 100644 --- a/spring-security-modules/spring-security-cognito/pom.xml +++ b/spring-security-modules/spring-security-cognito/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-core-2/pom.xml b/spring-security-modules/spring-security-core-2/pom.xml index 5d77098869..54aac0d9a7 100644 --- a/spring-security-modules/spring-security-core-2/pom.xml +++ b/spring-security-modules/spring-security-core-2/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-core/pom.xml b/spring-security-modules/spring-security-core/pom.xml index 03d7030057..2a18145ac0 100644 --- a/spring-security-modules/spring-security-core/pom.xml +++ b/spring-security-modules/spring-security-core/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-ldap/pom.xml b/spring-security-modules/spring-security-ldap/pom.xml index 471ffff4a1..9f4f3b4106 100644 --- a/spring-security-modules/spring-security-ldap/pom.xml +++ b/spring-security-modules/spring-security-ldap/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-legacy-oidc/pom.xml b/spring-security-modules/spring-security-legacy-oidc/pom.xml index e98486b0ff..55b6e780b2 100644 --- a/spring-security-modules/spring-security-legacy-oidc/pom.xml +++ b/spring-security-modules/spring-security-legacy-oidc/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-oauth2-sso/pom.xml b/spring-security-modules/spring-security-oauth2-sso/pom.xml index a87e4d7814..d8101d2313 100644 --- a/spring-security-modules/spring-security-oauth2-sso/pom.xml +++ b/spring-security-modules/spring-security-oauth2-sso/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-oauth2/pom.xml b/spring-security-modules/spring-security-oauth2/pom.xml index 1b30f6685d..977e2c16fd 100644 --- a/spring-security-modules/spring-security-oauth2/pom.xml +++ b/spring-security-modules/spring-security-oauth2/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-oidc/pom.xml b/spring-security-modules/spring-security-oidc/pom.xml index 70031b7396..c27c084ad7 100644 --- a/spring-security-modules/spring-security-oidc/pom.xml +++ b/spring-security-modules/spring-security-oidc/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-okta/pom.xml b/spring-security-modules/spring-security-okta/pom.xml index 98b8abedb4..5ae1241b18 100644 --- a/spring-security-modules/spring-security-okta/pom.xml +++ b/spring-security-modules/spring-security-okta/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-opa/pom.xml b/spring-security-modules/spring-security-opa/pom.xml index 72b0574253..a6240f6e69 100644 --- a/spring-security-modules/spring-security-opa/pom.xml +++ b/spring-security-modules/spring-security-opa/pom.xml @@ -7,9 +7,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-pkce/pom.xml b/spring-security-modules/spring-security-pkce/pom.xml index 5899b297b4..e0bd8eb90e 100644 --- a/spring-security-modules/spring-security-pkce/pom.xml +++ b/spring-security-modules/spring-security-pkce/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-saml/pom.xml b/spring-security-modules/spring-security-saml/pom.xml index 8a9b418374..8d7cce939f 100644 --- a/spring-security-modules/spring-security-saml/pom.xml +++ b/spring-security-modules/spring-security-saml/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-social-login/pom.xml b/spring-security-modules/spring-security-social-login/pom.xml index ddda4235be..5efa5b703c 100644 --- a/spring-security-modules/spring-security-social-login/pom.xml +++ b/spring-security-modules/spring-security-social-login/pom.xml @@ -9,9 +9,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-angular/pom.xml b/spring-security-modules/spring-security-web-angular/pom.xml index 2a745bc6cc..15dc4d007c 100644 --- a/spring-security-modules/spring-security-web-angular/pom.xml +++ b/spring-security-modules/spring-security-web-angular/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-boot-1/pom.xml b/spring-security-modules/spring-security-web-boot-1/pom.xml index fa0fd567fe..08adb700ec 100644 --- a/spring-security-modules/spring-security-web-boot-1/pom.xml +++ b/spring-security-modules/spring-security-web-boot-1/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-boot-2/pom.xml b/spring-security-modules/spring-security-web-boot-2/pom.xml index 3ba8726f51..2255f8b035 100644 --- a/spring-security-modules/spring-security-web-boot-2/pom.xml +++ b/spring-security-modules/spring-security-web-boot-2/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-boot-3/pom.xml b/spring-security-modules/spring-security-web-boot-3/pom.xml index 5229068dfa..0b71e89527 100644 --- a/spring-security-modules/spring-security-web-boot-3/pom.xml +++ b/spring-security-modules/spring-security-web-boot-3/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-boot-4/pom.xml b/spring-security-modules/spring-security-web-boot-4/pom.xml index ffbed0f8ab..b5bfc55a9f 100644 --- a/spring-security-modules/spring-security-web-boot-4/pom.xml +++ b/spring-security-modules/spring-security-web-boot-4/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-boot-5/pom.xml b/spring-security-modules/spring-security-web-boot-5/pom.xml index f4e2e3ad92..14b8d87f25 100644 --- a/spring-security-modules/spring-security-web-boot-5/pom.xml +++ b/spring-security-modules/spring-security-web-boot-5/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-login-2/pom.xml b/spring-security-modules/spring-security-web-login-2/pom.xml index 2d92a8567f..a44543a6ba 100644 --- a/spring-security-modules/spring-security-web-login-2/pom.xml +++ b/spring-security-modules/spring-security-web-login-2/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-mvc/pom.xml b/spring-security-modules/spring-security-web-mvc/pom.xml index 505826d1a2..10dd89f618 100644 --- a/spring-security-modules/spring-security-web-mvc/pom.xml +++ b/spring-security-modules/spring-security-web-mvc/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml b/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml index 3c842a8a54..9a3b21af92 100644 --- a/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml +++ b/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-rest-custom/pom.xml b/spring-security-modules/spring-security-web-rest-custom/pom.xml index dfd2f59aaf..2e55fe8b89 100644 --- a/spring-security-modules/spring-security-web-rest-custom/pom.xml +++ b/spring-security-modules/spring-security-web-rest-custom/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-springdoc/pom.xml b/spring-security-modules/spring-security-web-springdoc/pom.xml index 03e938f1c8..30102fd83d 100644 --- a/spring-security-modules/spring-security-web-springdoc/pom.xml +++ b/spring-security-modules/spring-security-web-springdoc/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-thymeleaf/pom.xml b/spring-security-modules/spring-security-web-thymeleaf/pom.xml index c13aa6a471..dd5f2d7c97 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/pom.xml +++ b/spring-security-modules/spring-security-web-thymeleaf/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-security-modules/spring-security-web-x509/pom.xml b/spring-security-modules/spring-security-web-x509/pom.xml index 5282ab7d83..ec0331fd53 100644 --- a/spring-security-modules/spring-security-web-x509/pom.xml +++ b/spring-security-modules/spring-security-web-x509/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + spring-security-modules 0.0.1-SNAPSHOT - ../../parent-boot-2 From 462ddc7f0260f44d0dbd56789f55c09ea9c5cd88 Mon Sep 17 00:00:00 2001 From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com> Date: Sat, 28 Oct 2023 21:11:08 +0530 Subject: [PATCH 010/107] BAEL-7145 Bill Pugh Singleton implementation --- .../baledung/billpugh/BillPughSingleton.java | 15 ++++++ .../billpugh/EagerLoadedSingleton.java | 11 +++++ .../billpugh/LazyLoadedSingleton.java | 15 ++++++ .../SynchronizedLazyLoadedSingleton.java | 15 ++++++ .../billpugh/BillPughSingletonUnitTest.java | 43 +++++++++++++++++ .../EagerLoadedSingletonUnitTest.java | 46 +++++++++++++++++++ .../billpugh/LazyLoadedSingletonUnitTest.java | 17 +++++++ ...nchronizedLazyLoadedSingletonUnitTest.java | 44 ++++++++++++++++++ 8 files changed, 206 insertions(+) create mode 100644 patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/BillPughSingleton.java create mode 100644 patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/EagerLoadedSingleton.java create mode 100644 patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/LazyLoadedSingleton.java create mode 100644 patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/SynchronizedLazyLoadedSingleton.java create mode 100644 patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java create mode 100644 patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/EagerLoadedSingletonUnitTest.java create mode 100644 patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/LazyLoadedSingletonUnitTest.java create mode 100644 patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/SynchronizedLazyLoadedSingletonUnitTest.java diff --git a/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/BillPughSingleton.java b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/BillPughSingleton.java new file mode 100644 index 0000000000..f558706a07 --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/BillPughSingleton.java @@ -0,0 +1,15 @@ +package com.baledung.billpugh; + +public class BillPughSingleton { + private BillPughSingleton() { + + } + + private static class SingletonHelper { + private static final BillPughSingleton BILL_PUGH_SINGLETON_INSTANCE = new BillPughSingleton(); + } + + public static BillPughSingleton getInstance() { + return SingletonHelper.BILL_PUGH_SINGLETON_INSTANCE; + } +} diff --git a/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/EagerLoadedSingleton.java b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/EagerLoadedSingleton.java new file mode 100644 index 0000000000..c0a535f2d5 --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/EagerLoadedSingleton.java @@ -0,0 +1,11 @@ +package com.baledung.billpugh; + +public class EagerLoadedSingleton { + private static final EagerLoadedSingleton EAGER_LOADED_SINGLETON = new EagerLoadedSingleton(); + private EagerLoadedSingleton() { + + } + public static EagerLoadedSingleton getInstance() { + return EAGER_LOADED_SINGLETON; + } +} diff --git a/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/LazyLoadedSingleton.java b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/LazyLoadedSingleton.java new file mode 100644 index 0000000000..b4967a58cd --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/LazyLoadedSingleton.java @@ -0,0 +1,15 @@ +package com.baledung.billpugh; + +public class LazyLoadedSingleton { + private static LazyLoadedSingleton lazyLoadedSingletonObj; + + private LazyLoadedSingleton() { + } + + public static LazyLoadedSingleton getInstance() { + if (null == lazyLoadedSingletonObj) { + lazyLoadedSingletonObj = new LazyLoadedSingleton(); + } + return lazyLoadedSingletonObj; + } +} diff --git a/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/SynchronizedLazyLoadedSingleton.java b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/SynchronizedLazyLoadedSingleton.java new file mode 100644 index 0000000000..fe3457e054 --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/main/java/com/baledung/billpugh/SynchronizedLazyLoadedSingleton.java @@ -0,0 +1,15 @@ +package com.baledung.billpugh; + +public class SynchronizedLazyLoadedSingleton { + private static SynchronizedLazyLoadedSingleton synchronizedLazyLoadedSingleton; + + private SynchronizedLazyLoadedSingleton() { + } + + public static synchronized SynchronizedLazyLoadedSingleton getInstance() { + if (null == synchronizedLazyLoadedSingleton) { + synchronizedLazyLoadedSingleton = new SynchronizedLazyLoadedSingleton(); + } + return synchronizedLazyLoadedSingleton; + } +} \ No newline at end of file diff --git a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java new file mode 100644 index 0000000000..b42d36229f --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java @@ -0,0 +1,43 @@ +package com.baledung.billpugh; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BillPughSingletonUnitTest { + Logger logger = LoggerFactory.getLogger(BillPughSingletonUnitTest.class); + @Test + void giveSynchronizedLazyLoadedImpl_whenCallgetInstance_thenReturnSingleton() { + Set setHoldingSingletonObj = new HashSet<>(); + List> futures = new ArrayList<>(); + + ExecutorService executorService = Executors.newFixedThreadPool(10); + Callable runnableTask = () -> { + logger.info("run called for:" + Thread.currentThread().getName()); + return BillPughSingleton.getInstance(); + }; + + int count = 0; + while(count < 10) { + futures.add(executorService.submit(runnableTask)); + count++; + } + futures.forEach(e -> { + try { + setHoldingSingletonObj.add(e.get()); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }); + executorService.shutdown(); + assertEquals(1, setHoldingSingletonObj.size()); + } +} diff --git a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/EagerLoadedSingletonUnitTest.java b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/EagerLoadedSingletonUnitTest.java new file mode 100644 index 0000000000..fd65ff6c5b --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/EagerLoadedSingletonUnitTest.java @@ -0,0 +1,46 @@ +package com.baledung.billpugh; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class EagerLoadedSingletonUnitTest { + + Logger logger = LoggerFactory.getLogger(EagerLoadedSingletonUnitTest.class); + + @Test + void giveEagerLoadedImpl_whenCallgetInstance_thenReturnSingleton() { + Set set = new HashSet<>(); + List> futures = new ArrayList<>(); + + ExecutorService executorService = Executors.newFixedThreadPool(10); + Callable runnableTask = () -> { + logger.info("run called for:" + Thread.currentThread().getName()); + return EagerLoadedSingleton.getInstance(); + }; + + int count = 0; + while(count < 10) { + futures.add(executorService.submit(runnableTask)); + count++; + } + futures.forEach(e -> { + try { + set.add(e.get()); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }); + executorService.shutdown(); + assertEquals(1, set.size()); + } + +} diff --git a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/LazyLoadedSingletonUnitTest.java b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/LazyLoadedSingletonUnitTest.java new file mode 100644 index 0000000000..0e0ea25779 --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/LazyLoadedSingletonUnitTest.java @@ -0,0 +1,17 @@ +package com.baledung.billpugh; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +public class LazyLoadedSingletonUnitTest { + + @Test + void givenLazyLoadedImpl_whenCallGetInstance_thenReturnSingleInstance() throws ClassNotFoundException { + Class bs = Class.forName("com.baledung.billpugh.LazyLoadedSingleton"); + assertThrows(IllegalAccessException.class, () -> bs.getDeclaredConstructor().newInstance()); + + LazyLoadedSingleton lazyLoadedSingletonObj1 = LazyLoadedSingleton.getInstance(); + LazyLoadedSingleton lazyLoadedSingletonObj2 = LazyLoadedSingleton.getInstance(); + assertEquals(lazyLoadedSingletonObj1.hashCode(), lazyLoadedSingletonObj2.hashCode()); + } +} diff --git a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/SynchronizedLazyLoadedSingletonUnitTest.java b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/SynchronizedLazyLoadedSingletonUnitTest.java new file mode 100644 index 0000000000..1f1636b458 --- /dev/null +++ b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/SynchronizedLazyLoadedSingletonUnitTest.java @@ -0,0 +1,44 @@ +package com.baledung.billpugh; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class SynchronizedLazyLoadedSingletonUnitTest { + Logger logger = LoggerFactory.getLogger(SynchronizedLazyLoadedSingletonUnitTest.class); + @Test + void giveSynchronizedLazyLoadedImpl_whenCallgetInstance_thenReturnSingleton() { + Set setHoldingSingletonObj = new HashSet<>(); + List> futures = new ArrayList<>(); + + ExecutorService executorService = Executors.newFixedThreadPool(10); + Callable runnableTask = () -> { + logger.info("run called for:" + Thread.currentThread().getName()); + return SynchronizedLazyLoadedSingleton.getInstance(); + }; + + int count = 0; + while(count < 10) { + futures.add(executorService.submit(runnableTask)); + count++; + } + futures.forEach(e -> { + try { + setHoldingSingletonObj.add(e.get()); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }); + executorService.shutdown(); + assertEquals(1, setHoldingSingletonObj.size()); + } + +} From 4596614dc9721bc246c587f35092c86330a92629 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Sun, 29 Oct 2023 01:42:22 +0530 Subject: [PATCH 011/107] Initial Commit --- .../core-java-persistence-3/pom.xml | 35 ++++++ .../ResultSetToMapUnitTest.java | 105 ++++++++++++++++++ persistence-modules/pom.xml | 1 + 3 files changed, 141 insertions(+) create mode 100644 persistence-modules/core-java-persistence-3/pom.xml create mode 100644 persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java diff --git a/persistence-modules/core-java-persistence-3/pom.xml b/persistence-modules/core-java-persistence-3/pom.xml new file mode 100644 index 0000000000..6868da27be --- /dev/null +++ b/persistence-modules/core-java-persistence-3/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + com.baeldung.core-java-persistence-3 + core-java-persistence-3 + core-java-persistence-3 + 0.1.0-SNAPSHOT + jar + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + org.springframework + spring-jdbc + ${spring-jdbc.version} + + + commons-dbutils + commons-dbutils + ${commons-dbutils.version} + + + + 2.1.214 + 5.3.29 + 1.8.1 + + \ No newline at end of file diff --git a/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java new file mode 100644 index 0000000000..b483cc04c9 --- /dev/null +++ b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java @@ -0,0 +1,105 @@ +package com.baeldung.resultsettomap; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.dbutils.QueryRunner; +import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ResultSetToMapUnitTest { + private static Connection connection = null; + private static final String JDBC_URL = "jdbc:h2:mem:testDatabase"; + private static final String USERNAME = "dbUser"; + private static final String PASSWORD = "dbPassword"; + + @Before + public void setup() throws Exception { + connection = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD); + initialDataSetup(); + } + + private void initialDataSetup() throws SQLException { + Statement statement = connection.createStatement(); + String sql = "CREATE TABLE EMPLOYEE (empId INTEGER not null, empName VARCHAR(50), empCity VARCHAR(50), PRIMARY KEY (empId))"; + statement.executeUpdate(sql); + List sqlQueryList = Arrays.asList("INSERT INTO EMPLOYEE VALUES (1, 'Steve','London')", "INSERT INTO EMPLOYEE VALUES (2, 'John','London')", "INSERT INTO EMPLOYEE VALUES (3, 'David', 'Sydney')", + "INSERT INTO EMPLOYEE VALUES (4, 'Kevin','London')", "INSERT INTO EMPLOYEE VALUES (5, 'Jade', 'Sydney')"); + for (String query : sqlQueryList) { + statement.executeUpdate(query); + } + } + + @Test + public void whenUsingNativeJava_thenConvertResultSetToMap() throws SQLException { + ResultSet resultSet = connection.prepareStatement("SELECT * FROM EMPLOYEE") + .executeQuery(); + Map> valueMap = new HashMap<>(); + + while (resultSet.next()) { + String empCity = resultSet.getString("empCity"); + String empName = resultSet.getString("empName"); + if (!valueMap.containsKey(empCity)) { + valueMap.putIfAbsent(empCity, new ArrayList<>()); + } + valueMap.get(empCity) + .add(empName); + } + assertEquals(3, valueMap.get("London") + .size()); + } + + @Test + public void whenUsingLambda_thenConvertResultSetToMap() throws SQLException { + ResultSet resultSet = connection.prepareStatement("SELECT * FROM EMPLOYEE") + .executeQuery(); + Map> valueMap = new HashMap<>(); + + while (resultSet.next()) { + String empCity = resultSet.getString("empCity"); + String empName = resultSet.getString("empName"); + valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()) + .add(empName); + } + assertEquals(3, valueMap.get("London") + .size()); + } + + @Test + public void whenUsingDbUtils_thenConvertResultSetToMap() throws SQLException { + + ResultSetHandler>> handler = new ResultSetHandler>>() { + public Map> handle(ResultSet resultSet) throws SQLException { + Map> result = new HashMap<>(); + while (resultSet.next()) { + String empCity = resultSet.getString("empCity"); + String empName = resultSet.getString("empName"); + result.computeIfAbsent(empCity, data -> new ArrayList<>()) + .add(empName); + } + return result; + } + }; + QueryRunner run = new QueryRunner(); + Map> valueMap = run.query(connection, "SELECT * FROM EMPLOYEE", handler); + assertEquals(3, valueMap.get("London") + .size()); + } + + @After + public void preDestroy() throws Exception { + connection.close(); + } +} diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index a99a180390..162894f1e0 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -21,6 +21,7 @@ blaze-persistence core-java-persistence core-java-persistence-2 + core-java-persistence-3 elasticsearch flyway flyway-repair From 6d2e874c264e67437078e9506e19dca6f0c181a9 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Sun, 29 Oct 2023 01:46:23 +0530 Subject: [PATCH 012/107] Updated Pom --- persistence-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 53e408c3a5..9c150a28d7 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -21,6 +21,7 @@ blaze-persistence core-java-persistence core-java-persistence-2 + core-java-persistence-3 couchbase elasticsearch flyway From 832584c68cdeadbb14cf17ee11ca215bfa4bfb40 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Tue, 31 Oct 2023 20:37:18 +0530 Subject: [PATCH 013/107] JAVA-26280 Improve libraries-testing module build time --- .../{SmurfsArchUnitTest.java => SmurfsArchManualTest.java} | 2 +- ...erStatusIntegrationTest.java => MemberStatusManualTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename libraries-testing/src/test/java/com/baeldung/archunit/smurfs/{SmurfsArchUnitTest.java => SmurfsArchManualTest.java} (98%) rename libraries-testing/src/test/java/com/baeldung/serenity/{MemberStatusIntegrationTest.java => MemberStatusManualTest.java} (98%) diff --git a/libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchUnitTest.java b/libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchManualTest.java similarity index 98% rename from libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchUnitTest.java rename to libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchManualTest.java index 9724c2bcae..7db104bd57 100644 --- a/libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchUnitTest.java +++ b/libraries-testing/src/test/java/com/baeldung/archunit/smurfs/SmurfsArchManualTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; -public class SmurfsArchUnitTest { +public class SmurfsArchManualTest { @Test public void givenPresentationLayerClasses_thenWrongCheckFails() { diff --git a/libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java b/libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusManualTest.java similarity index 98% rename from libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java rename to libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusManualTest.java index e95b63aa96..ec5346d27b 100644 --- a/libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java +++ b/libraries-testing/src/test/java/com/baeldung/serenity/MemberStatusManualTest.java @@ -14,7 +14,7 @@ import static com.baeldung.serenity.membership.MemberGrade.Gold; import static com.baeldung.serenity.membership.MemberGrade.Silver; @RunWith(SerenityRunner.class) -public class MemberStatusIntegrationTest { +public class MemberStatusManualTest { @Steps private MemberStatusSteps memberSteps; From 3fe81a3e075ae05044038788b23fa8729115f734 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 3 Nov 2023 03:49:06 +0530 Subject: [PATCH 014/107] Formatting changes --- .../core-java-persistence-3/pom.xml | 6 --- .../ResultSetToMapUnitTest.java | 44 ++++++++----------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/persistence-modules/core-java-persistence-3/pom.xml b/persistence-modules/core-java-persistence-3/pom.xml index 6868da27be..26ac2a5218 100644 --- a/persistence-modules/core-java-persistence-3/pom.xml +++ b/persistence-modules/core-java-persistence-3/pom.xml @@ -16,11 +16,6 @@ h2 ${h2.version} - - org.springframework - spring-jdbc - ${spring-jdbc.version} - commons-dbutils commons-dbutils @@ -29,7 +24,6 @@ 2.1.214 - 5.3.29 1.8.1 \ No newline at end of file diff --git a/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java index b483cc04c9..c8a6351804 100644 --- a/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java +++ b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java @@ -33,48 +33,43 @@ public class ResultSetToMapUnitTest { private void initialDataSetup() throws SQLException { Statement statement = connection.createStatement(); - String sql = "CREATE TABLE EMPLOYEE (empId INTEGER not null, empName VARCHAR(50), empCity VARCHAR(50), PRIMARY KEY (empId))"; - statement.executeUpdate(sql); - List sqlQueryList = Arrays.asList("INSERT INTO EMPLOYEE VALUES (1, 'Steve','London')", "INSERT INTO EMPLOYEE VALUES (2, 'John','London')", "INSERT INTO EMPLOYEE VALUES (3, 'David', 'Sydney')", - "INSERT INTO EMPLOYEE VALUES (4, 'Kevin','London')", "INSERT INTO EMPLOYEE VALUES (5, 'Jade', 'Sydney')"); + String ddlQuery = "CREATE TABLE employee (empId INTEGER not null, empName VARCHAR(50), empCity VARCHAR(50), PRIMARY KEY (empId))"; + statement.execute(ddlQuery); + List sqlQueryList = Arrays.asList("INSERT INTO employee VALUES (1, 'Steve','London')", "INSERT INTO employee VALUES (2, 'John','London')", "INSERT INTO employee VALUES (3, 'David', 'Sydney')", + "INSERT INTO employee VALUES (4, 'Kevin','London')", "INSERT INTO employee VALUES (5, 'Jade', 'Sydney')"); + for (String query : sqlQueryList) { - statement.executeUpdate(query); + statement.execute(query); } } @Test - public void whenUsingNativeJava_thenConvertResultSetToMap() throws SQLException { - ResultSet resultSet = connection.prepareStatement("SELECT * FROM EMPLOYEE") - .executeQuery(); + public void whenUsingContainsKey_thenConvertResultSetToMap() throws SQLException { + ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery(); Map> valueMap = new HashMap<>(); while (resultSet.next()) { String empCity = resultSet.getString("empCity"); String empName = resultSet.getString("empName"); if (!valueMap.containsKey(empCity)) { - valueMap.putIfAbsent(empCity, new ArrayList<>()); + valueMap.put(empCity, new ArrayList<>()); } - valueMap.get(empCity) - .add(empName); + valueMap.get(empCity).add(empName); } - assertEquals(3, valueMap.get("London") - .size()); + assertEquals(3, valueMap.get("London").size()); } @Test - public void whenUsingLambda_thenConvertResultSetToMap() throws SQLException { - ResultSet resultSet = connection.prepareStatement("SELECT * FROM EMPLOYEE") - .executeQuery(); + public void whenUsingComputeIfAbsent_thenConvertResultSetToMap() throws SQLException { + ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery(); Map> valueMap = new HashMap<>(); while (resultSet.next()) { String empCity = resultSet.getString("empCity"); String empName = resultSet.getString("empName"); - valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()) - .add(empName); + valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName); } - assertEquals(3, valueMap.get("London") - .size()); + assertEquals(3, valueMap.get("London").size()); } @Test @@ -86,16 +81,15 @@ public class ResultSetToMapUnitTest { while (resultSet.next()) { String empCity = resultSet.getString("empCity"); String empName = resultSet.getString("empName"); - result.computeIfAbsent(empCity, data -> new ArrayList<>()) - .add(empName); + result.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName); } return result; } }; + QueryRunner run = new QueryRunner(); - Map> valueMap = run.query(connection, "SELECT * FROM EMPLOYEE", handler); - assertEquals(3, valueMap.get("London") - .size()); + Map> valueMap = run.query(connection, "SELECT * FROM employee", handler); + assertEquals(3, valueMap.get("London").size()); } @After From 02e02f928f4ff4e4bad974b1e3e30e17b2fbc8ed Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Thu, 2 Nov 2023 17:47:02 -0600 Subject: [PATCH 015/107] [BAEL-7074] Synchronization for static data examples --- .../retry/RetryCompletableFuture.java | 2 +- .../threadpool/CustomCompletableFuture.java | 8 +- .../atomicinteger/Employee.java | 32 +++++++ .../synchronizestatic/none/Employee.java | 28 ++++++ .../reentrantlock/Employee.java | 44 +++++++++ .../synchronizedblock/Employee.java | 34 +++++++ .../synchronizedmethod/Employee.java | 27 ++++++ .../volatilekeyword/Employee.java | 29 ++++++ .../SychronizeStaticDataUnitTest.java | 89 +++++++++++++++++++ 9 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedmethod/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java index a3df6b3624..a46665559f 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java @@ -48,7 +48,7 @@ public class RetryCompletableFuture { CompletableFuture cf = CompletableFuture.supplyAsync(supplier); sleep(100); for (int i = 0; i < maxRetries; i++) { - cf = cf.exceptionallyAsync(__ -> supplier.get()); + //cf = cf.exceptionallyAsync(__ -> supplier.get()); } return cf; } diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java index 1f3997768e..473cc562ca 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java @@ -20,9 +20,9 @@ public class CustomCompletableFuture extends CompletableFuture { return future; } - @Override - public Executor defaultExecutor() { - return executor; - } +// @Override +// public Executor defaultExecutor() { +// return executor; +// } } \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java new file mode 100644 index 0000000000..845dd65ce6 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java @@ -0,0 +1,32 @@ +package com.baeldung.concurrent.synchronizestatic.atomicinteger; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Synchronizing static variable with AtomicInteger. + */ +public class Employee { + + private static final AtomicInteger count = new AtomicInteger(0); + + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + count.incrementAndGet(); + System.out.println("Count = " + count.get()); + } + + public static int getCount() { + return count.get(); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java new file mode 100644 index 0000000000..f050a68be4 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java @@ -0,0 +1,28 @@ +package com.baeldung.concurrent.synchronizestatic.none; + +/** + * No synchronization. + */ +public class Employee { + + static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + System.out.println("Count = " + ++count); + } + + public static Integer getCount() { + return count; + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java new file mode 100644 index 0000000000..2ac0b0d3f2 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java @@ -0,0 +1,44 @@ +package com.baeldung.concurrent.synchronizestatic.reentrantlock; + +import java.util.concurrent.locks.ReentrantLock; + +/** + * Synchronizing static variable with a Reenatrant Lock. + */ +public class Employee { + + private static final ReentrantLock lock = new ReentrantLock(); + + static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + lock.lock(); + try { + System.out.println("Count = " + ++count); + } + finally { + lock.unlock(); + } + } + + public static int getCount() { + lock.lock(); + try { + return count; + } + finally { + lock.unlock(); + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java new file mode 100644 index 0000000000..9c078e7abe --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java @@ -0,0 +1,34 @@ +package com.baeldung.concurrent.synchronizestatic.synchronizedblock; + +/** + * Synchronizing static variable with a synchronized block. + */ +public class Employee { + + private static final Object lock = new Object(); + + static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + synchronized(lock) { + System.out.println("Count = " + ++count); + } + } + + public static int getCount() { + synchronized(lock) { + return count; + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedmethod/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedmethod/Employee.java new file mode 100644 index 0000000000..f0a785c427 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedmethod/Employee.java @@ -0,0 +1,27 @@ +package com.baeldung.concurrent.synchronizestatic.synchronizedmethod; + +/** + * Synchronizing static variable with a synchronized method. + */ +public class Employee { + static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static synchronized void incrementCount() { + System.out.println("Count = " + ++count); + } + + public static synchronized int getCount() { + return count; + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java new file mode 100644 index 0000000000..f41b10e160 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java @@ -0,0 +1,29 @@ +package com.baeldung.concurrent.synchronizestatic.volatilekeyword; + +/** + * No synchronization. + */ +public class Employee +{ + + volatile static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + System.out.println("Count = " + ++count); + } + + public static Integer getCount() { + return count; + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java new file mode 100644 index 0000000000..d8d9a344f1 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java @@ -0,0 +1,89 @@ +package com.baeldung.concurrent.synchronizestatic; + +import org.junit.Test; + +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +public class SychronizeStaticDataUnitTest +{ + private final Executor pool = Executors.newFixedThreadPool(4); + + @Test + public void whenNotSynchronized_thenDataOutOfOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.none.Employee(finalI, "John", "Smith"); + }); + } + } + + @Test + public void whenVolatile_thenDataInOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.volatilekeyword.Employee(finalI, "John", "Smith"); + }); + } + } + + @Test + public void whenSynchronizedMethod_thenDataInOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.synchronizedmethod.Employee(finalI, "John", "Smith"); + }); + } + } + + @Test + public void whenSynchronizedBlock_thenDataInOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.synchronizedblock.Employee(finalI, "John", "Smith"); + }); + } + } + + @Test + public void whenAtomicInteger_thenDataInOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.atomicinteger.Employee(finalI, "John", "Smith"); + }); + } + } + + @Test + public void whenReentrantLock_thenDataInOrder() { + int numberToTest = 100; + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.reentrantlock.Employee(finalI, "John", "Smith"); + }); + } + } +} From 38f30e733fc9ecf70a79a90c65f2ed82947d05b4 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Thu, 2 Nov 2023 19:23:43 -0600 Subject: [PATCH 016/107] [BAEL-7074] Update tests --- .../atomicinteger/Employee.java | 1 - .../volatilekeyword/Employee.java | 29 ------------ .../SychronizeStaticDataUnitTest.java | 45 ++++++++----------- 3 files changed, 19 insertions(+), 56 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java index 845dd65ce6..9c3c9b987c 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java @@ -23,7 +23,6 @@ public class Employee { private static void incrementCount() { count.incrementAndGet(); - System.out.println("Count = " + count.get()); } public static int getCount() { diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java deleted file mode 100644 index f41b10e160..0000000000 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/volatilekeyword/Employee.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.concurrent.synchronizestatic.volatilekeyword; - -/** - * No synchronization. - */ -public class Employee -{ - - volatile static int count; - int id; - String name; - String title; - - public Employee(int id, String name, String title) - { - incrementCount(); - this.id = id; - this.name = name; - this.title = title; - } - - private static void incrementCount() { - System.out.println("Count = " + ++count); - } - - public static Integer getCount() { - return count; - } -} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java index d8d9a344f1..7e5dca9f2b 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java @@ -5,13 +5,22 @@ import org.junit.Test; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +/** + * The tests in this class show the output of creating multiple + * types of Employee classes in the synchronizedstatic + * package. When not synchronized the out will not be sequential; + * when it is synchronized the output will be in sequential. + */ public class SychronizeStaticDataUnitTest { private final Executor pool = Executors.newFixedThreadPool(4); + private final int numberToTest = 100; + @Test public void whenNotSynchronized_thenDataOutOfOrder() { - int numberToTest = 100; + + System.out.println("No synchronization"); for(int i = 0; i < numberToTest; i++) { int finalI = i; @@ -22,22 +31,10 @@ public class SychronizeStaticDataUnitTest } } - @Test - public void whenVolatile_thenDataInOrder() { - int numberToTest = 100; - - for(int i = 0; i < numberToTest; i++) { - int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.volatilekeyword.Employee(finalI, "John", "Smith"); - }); - } - } - @Test public void whenSynchronizedMethod_thenDataInOrder() { - int numberToTest = 100; + + System.out.println("Synchronization with synchronized method"); for(int i = 0; i < numberToTest; i++) { int finalI = i; @@ -50,7 +47,8 @@ public class SychronizeStaticDataUnitTest @Test public void whenSynchronizedBlock_thenDataInOrder() { - int numberToTest = 100; + + System.out.println("Synchronization with synchronized block"); for(int i = 0; i < numberToTest; i++) { int finalI = i; @@ -63,20 +61,15 @@ public class SychronizeStaticDataUnitTest @Test public void whenAtomicInteger_thenDataInOrder() { - int numberToTest = 100; - - for(int i = 0; i < numberToTest; i++) { - int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.atomicinteger.Employee(finalI, "John", "Smith"); - }); - } + // Not straight forward to test this because we cannot log/print + // and increment values in a synchronized fashion like other + // tests } @Test public void whenReentrantLock_thenDataInOrder() { - int numberToTest = 100; + + System.out.println("Synchronization with ReentrantLock"); for(int i = 0; i < numberToTest; i++) { int finalI = i; From 1aa2f849f49c5f14c25e07966e199593ca449e80 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 3 Nov 2023 13:10:24 -0600 Subject: [PATCH 017/107] Revert 2 changes unrelated to BAEL-7074 --- .../completablefuture/retry/RetryCompletableFuture.java | 2 +- .../threadpool/CustomCompletableFuture.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java index a46665559f..a3df6b3624 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/retry/RetryCompletableFuture.java @@ -48,7 +48,7 @@ public class RetryCompletableFuture { CompletableFuture cf = CompletableFuture.supplyAsync(supplier); sleep(100); for (int i = 0; i < maxRetries; i++) { - //cf = cf.exceptionallyAsync(__ -> supplier.get()); + cf = cf.exceptionallyAsync(__ -> supplier.get()); } return cf; } diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java index 473cc562ca..1f3997768e 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/completablefuture/threadpool/CustomCompletableFuture.java @@ -20,9 +20,9 @@ public class CustomCompletableFuture extends CompletableFuture { return future; } -// @Override -// public Executor defaultExecutor() { -// return executor; -// } + @Override + public Executor defaultExecutor() { + return executor; + } } \ No newline at end of file From 159461815d99562f7d8f1babe787c7f784145a92 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 3 Nov 2023 15:31:25 -0600 Subject: [PATCH 018/107] New example and unit test --- .../synchronizedclass/Employee.java | 32 +++++++++++++++++++ .../SychronizeStaticDataUnitTest.java | 16 +++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java new file mode 100644 index 0000000000..a69b633f3b --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java @@ -0,0 +1,32 @@ +package com.baeldung.concurrent.synchronizestatic.synchronizedclass; + +/** + * Synchronizing static variable with a synchronized block. + */ +public class Employee +{ + static int count; + int id; + String name; + String title; + + public Employee(int id, String name, String title) + { + incrementCount(); + this.id = id; + this.name = name; + this.title = title; + } + + private static void incrementCount() { + synchronized(Employee.class) { + System.out.println("Count = " + ++count); + } + } + + public static int getCount() { + synchronized(Employee.class) { + return count; + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java index 7e5dca9f2b..e633005c6f 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java @@ -45,10 +45,24 @@ public class SychronizeStaticDataUnitTest } } + @Test + public void whenSynchronizedClass_thenDataInOrder() { + + System.out.println("Synchronization with synchronized block on class"); + + for(int i = 0; i < numberToTest; i++) { + int finalI = i; + pool.execute(() -> + { + new com.baeldung.concurrent.synchronizestatic.synchronizedclass.Employee(finalI, "John", "Smith"); + }); + } + } + @Test public void whenSynchronizedBlock_thenDataInOrder() { - System.out.println("Synchronization with synchronized block"); + System.out.println("Synchronization with synchronized block on a private object"); for(int i = 0; i < numberToTest; i++) { int finalI = i; From 0f6149ef8cbbd7b60312b2726f7501dcdd85dc13 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Fri, 3 Nov 2023 23:31:49 +0200 Subject: [PATCH 019/107] [JAVA-26735] Upgraded gson library to 2.10.1 version --- aws-modules/aws-dynamodb/pom.xml | 2 +- aws-modules/aws-miscellaneous/pom.xml | 2 +- java-websocket/pom.xml | 2 +- json-modules/gson/pom.xml | 2 +- .../JsonObjectConversionsUnitTest.java | 31 ++++++++++++------- json-modules/json-arrays/pom.xml | 2 +- json-modules/json/pom.xml | 2 +- libraries-data-io/pom.xml | 2 +- libraries-data/pom.xml | 2 +- libraries-http-2/pom.xml | 2 +- libraries-http/pom.xml | 2 +- web-modules/javax-servlets/pom.xml | 2 +- web-modules/spark-java/pom.xml | 2 +- 13 files changed, 31 insertions(+), 24 deletions(-) diff --git a/aws-modules/aws-dynamodb/pom.xml b/aws-modules/aws-dynamodb/pom.xml index 37b88327f4..adce036733 100644 --- a/aws-modules/aws-dynamodb/pom.xml +++ b/aws-modules/aws-dynamodb/pom.xml @@ -79,7 +79,7 @@ - 2.8.0 + 2.10.1 1.21.1 3.1.1 diff --git a/aws-modules/aws-miscellaneous/pom.xml b/aws-modules/aws-miscellaneous/pom.xml index 4126256fb9..5fdd7fa04d 100644 --- a/aws-modules/aws-miscellaneous/pom.xml +++ b/aws-modules/aws-miscellaneous/pom.xml @@ -73,7 +73,7 @@ - 2.8.0 + 2.10.1 1.21.1 1.10.L001 0.9.4.0006L diff --git a/java-websocket/pom.xml b/java-websocket/pom.xml index d529b32022..fd97fd9db3 100644 --- a/java-websocket/pom.xml +++ b/java-websocket/pom.xml @@ -29,7 +29,7 @@ 1.1 - 2.8.0 + 2.10.1 \ No newline at end of file diff --git a/json-modules/gson/pom.xml b/json-modules/gson/pom.xml index ecfbaa7be4..ba968d9ae1 100644 --- a/json-modules/gson/pom.xml +++ b/json-modules/gson/pom.xml @@ -64,7 +64,7 @@ - 2.8.0 + 2.10.1 2.9.6 diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java index 9f07617969..18d9ccaf06 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java @@ -1,7 +1,9 @@ package com.baeldung.gson.conversion; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.google.gson.*; -import org.junit.Assert; import org.junit.jupiter.api.Test; public class JsonObjectConversionsUnitTest { @@ -10,24 +12,29 @@ public class JsonObjectConversionsUnitTest { void whenUsingJsonParser_thenConvertToJsonObject() throws Exception { // Example 1: Using JsonParser String json = "{ \"name\": \"Baeldung\", \"java\": true }"; - - JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); - - Assert.assertTrue(jsonObject.isJsonObject()); - Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung")); - Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true); + + JsonObject jsonObject = JsonParser.parseString(json) + .getAsJsonObject(); + + assertTrue(jsonObject.isJsonObject()); + assertEquals("Baeldung", jsonObject.get("name") + .getAsString()); + assertTrue(jsonObject.get("java") + .getAsBoolean()); } @Test void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception { // Example 2: Using fromJson String json = "{ \"name\": \"Baeldung\", \"java\": true }"; - + JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class); - - Assert.assertTrue(convertedObject.isJsonObject()); - Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung")); - Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true); + + assertTrue(convertedObject.isJsonObject()); + assertEquals("Baeldung", convertedObject.get("name") + .getAsString()); + assertTrue(convertedObject.get("java") + .getAsBoolean()); } } diff --git a/json-modules/json-arrays/pom.xml b/json-modules/json-arrays/pom.xml index 10c487fbda..ec492b49cc 100644 --- a/json-modules/json-arrays/pom.xml +++ b/json-modules/json-arrays/pom.xml @@ -38,7 +38,7 @@ 1.0 - 2.8.5 + 2.10.1 1.1.2 2.28.0 diff --git a/json-modules/json/pom.xml b/json-modules/json/pom.xml index 27c9262279..ba075be679 100644 --- a/json-modules/json/pom.xml +++ b/json-modules/json/pom.xml @@ -68,7 +68,7 @@ 1.0.72 1.0 1.0.1 - 2.8.5 + 2.10.1 1.1.2 2.28.0 diff --git a/libraries-data-io/pom.xml b/libraries-data-io/pom.xml index 2e126610d4..0a8afa02e2 100644 --- a/libraries-data-io/pom.xml +++ b/libraries-data-io/pom.xml @@ -106,7 +106,7 @@ v4-rev493-1.21.0 6.1.2 2.3.1 - 2.8.7 + 2.10.1 1.15 0.14.2 3.17.3 diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index a721e967d2..85ef01e704 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -210,7 +210,7 @@ 3.3.1 2.14.0 2.9.1 - 2.9.1 + 2.10.1 1.1.1 1.5.0 5.2.0 diff --git a/libraries-http-2/pom.xml b/libraries-http-2/pom.xml index fa3b6534db..c80c5729a7 100644 --- a/libraries-http-2/pom.xml +++ b/libraries-http-2/pom.xml @@ -110,7 +110,7 @@ 4.9.1 - 2.8.5 + 2.10.1 4.9.1 1.0.3 9.4.19.v20190610 diff --git a/libraries-http/pom.xml b/libraries-http/pom.xml index 18ba571f60..c726b56b5d 100644 --- a/libraries-http/pom.xml +++ b/libraries-http/pom.xml @@ -103,7 +103,7 @@ - 2.8.5 + 2.10.1 4.5.3 4.9.1 1.23.0 diff --git a/web-modules/javax-servlets/pom.xml b/web-modules/javax-servlets/pom.xml index 80a1e3af9f..406cfc05c1 100644 --- a/web-modules/javax-servlets/pom.xml +++ b/web-modules/javax-servlets/pom.xml @@ -49,7 +49,7 @@ 4.5.3 - 2.8.2 + 2.10.1 \ No newline at end of file diff --git a/web-modules/spark-java/pom.xml b/web-modules/spark-java/pom.xml index da09467212..e49be68319 100644 --- a/web-modules/spark-java/pom.xml +++ b/web-modules/spark-java/pom.xml @@ -30,7 +30,7 @@ 2.5.4 - 2.8.0 + 2.10.1 \ No newline at end of file From a324fc5c33993d3721f210c9e9079fb3233b4161 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Fri, 3 Nov 2023 23:52:59 +0200 Subject: [PATCH 020/107] [JAVA-26735] Replaced deprecated API JsonParser --- .../JsonObjectConversionsUnitTest.java | 2 ++ .../test/GsonDeserializationUnitTest.java | 8 ++--- .../gson/jsoncompare/JsonCompareUnitTest.java | 34 +++++++------------ .../serialization/GsonSerializeUnitTest.java | 3 +- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java index 18d9ccaf06..e1e5e48269 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/conversion/JsonObjectConversionsUnitTest.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.*; + +import org.junit.Assert; import org.junit.jupiter.api.Test; public class JsonObjectConversionsUnitTest { diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/deserialization/test/GsonDeserializationUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/deserialization/test/GsonDeserializationUnitTest.java index adc046ed8e..81d59cf364 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/deserialization/test/GsonDeserializationUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/deserialization/test/GsonDeserializationUnitTest.java @@ -3,8 +3,9 @@ package com.baeldung.gson.deserialization.test; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; + import java.lang.reflect.Type; import java.util.ArrayList; @@ -68,7 +69,7 @@ public class GsonDeserializationUnitTest { final GenericFoo targetObject = new Gson().fromJson(json, typeToken); - assertEquals(targetObject.theValue, new Integer(1)); + assertEquals(targetObject.theValue, Integer.valueOf(1)); } // tests - multiple elements @@ -98,8 +99,7 @@ public class GsonDeserializationUnitTest { @Test public void whenDeserializingJsonIntoElements_thenCorrect() { final String jsonSourceObject = "{\"valueInt\":7,\"valueString\":\"seven\"}"; - final JsonParser jParser = new JsonParser(); - final JsonElement jElement = jParser.parse(jsonSourceObject); + final JsonElement jElement = JsonParser.parseString(jsonSourceObject); final JsonObject jObject = jElement.getAsJsonObject(); final int intValue = jObject.get("valueInt").getAsInt(); final String stringValue = jObject.get("valueString").getAsString(); diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/jsoncompare/JsonCompareUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/jsoncompare/JsonCompareUnitTest.java index 84989a7411..4235eb426a 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/jsoncompare/JsonCompareUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/jsoncompare/JsonCompareUnitTest.java @@ -16,79 +16,71 @@ public class JsonCompareUnitTest { @Test public void givenIdenticalSimpleObjects_whenCompared_thenEqual() { - JsonParser parser = new JsonParser(); String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27 }}"; String string2 = "{\"customer\": {\"id\": \"44521\", \"fullName\": \"Emily Jenkins\",\"age\": 27}}"; - assertTrue(parser.parse(string1) - .isJsonObject()); - assertEquals(parser.parse(string1), parser.parse(string2)); + assertTrue(JsonParser.parseString(string1).isJsonObject()); + assertEquals(JsonParser.parseString(string1), JsonParser.parseString(string2)); } @Test public void givenSameObjectsInDifferentOrder_whenCompared_thenEqual() { - JsonParser parser = new JsonParser(); String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27 }}"; String string2 = "{\"customer\": {\"id\": \"44521\",\"age\": 27, \"fullName\": \"Emily Jenkins\" }}"; - JsonElement json1 = parser.parse(string1); - JsonElement json2 = parser.parse(string2); + JsonElement json1 = JsonParser.parseString(string1); + JsonElement json2 = JsonParser.parseString(string2); assertEquals(json1, json2); } @Test public void givenIdenticalArrays_whenCompared_thenEqual() { - JsonParser parser = new JsonParser(); String string1 = "[10, 20, 30]"; String string2 = "[10, 20, 30]"; - assertTrue(parser.parse(string1) + assertTrue(JsonParser.parseString(string1) .isJsonArray()); - assertEquals(parser.parse(string1), parser.parse(string2)); + assertEquals(JsonParser.parseString(string1), JsonParser.parseString(string2)); } @Test public void givenArraysInDifferentOrder_whenCompared_thenNotEqual() { - JsonParser parser = new JsonParser(); String string1 = "[20, 10, 30]"; String string2 = "[10, 20, 30]"; - assertNotEquals(parser.parse(string1), parser.parse(string2)); + assertNotEquals(JsonParser.parseString(string1), JsonParser.parseString(string2)); } @Test public void givenIdenticalNestedObjects_whenCompared_thenEqual() { - JsonParser parser = new JsonParser(); String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"fav_product\": \"Coke\", \"last_buy\": \"2012-04-23\"}}}"; String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"fav_product\": \"Coke\"}}}"; - JsonElement json1 = parser.parse(string1); - JsonElement json2 = parser.parse(string2); + JsonElement json1 = JsonParser.parseString(string1); + JsonElement json2 = JsonParser.parseString(string2); assertEquals(json1, json2); } @Test public void givenIdenticalNestedObjectsWithArray_whenCompared_thenEqual() { - JsonParser parser = new JsonParser(); String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}"; String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}"; - JsonElement json1 = parser.parse(string1); - JsonElement json2 = parser.parse(string2); + JsonElement json1 = JsonParser.parseString(string1); + JsonElement json2 = JsonParser.parseString(string2); assertEquals(json1, json2); } @Test public void givenNestedObjectsDifferentArrayOrder_whenCompared_thenNotEqual() { - JsonParser parser = new JsonParser(); String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}"; String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"eggs\", \"banana\"]}}}"; - JsonElement json1 = parser.parse(string1); - JsonElement json2 = parser.parse(string2); + JsonElement json1 = JsonParser.parseString(string1); + JsonElement json2 = JsonParser.parseString(string2); assertNotEquals(json1, json2); } diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/serialization/GsonSerializeUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/serialization/GsonSerializeUnitTest.java index 21d2bedd24..0d54cffbb4 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/serialization/GsonSerializeUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/serialization/GsonSerializeUnitTest.java @@ -41,8 +41,7 @@ public class GsonSerializeUnitTest { .serializeNulls() .disableHtmlEscaping() .create() - .toJson(new JsonParser() - .parse("{\"imdbId\":null,\"actors\":[{\"IMDB Code\":\"nm2199632\",\"Date Of Birth\":\"21-09-1982\",\"N° Film: \":3,\"filmography\":\"Apocalypto-Beatdown-Wind Walkers\"}]}")); + .toJson(JsonParser.parseString("{\"imdbId\":null,\"actors\":[{\"IMDB Code\":\"nm2199632\",\"Date Of Birth\":\"21-09-1982\",\"N° Film: \":3,\"filmography\":\"Apocalypto-Beatdown-Wind Walkers\"}]}")); Assert.assertEquals(gson.toJson(movieWithNullValue), expectedOutput); } } From 049770733ccef4e7e364c2cd6768f66b66e85e77 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 4 Nov 2023 12:24:35 +0530 Subject: [PATCH 021/107] JAVA-27176 Upgrade hibernate validator version in core-java-string-operations-2 module --- .../core-java-string-operations-2/pom.xml | 22 +++++-------------- .../SomeClassWithValidations.java | 2 +- .../emptystrings/EmptyStringsUnitTest.java | 8 +++---- 3 files changed, 10 insertions(+), 22 deletions(-) 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 902e8f09b4..383a3b4a40 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -14,11 +14,6 @@ - - javax.validation - validation-api - ${validation-api.version} - org.apache.commons commons-lang3 @@ -30,14 +25,9 @@ ${hibernate-validator.version} - javax.el - javax.el-api - ${javax.el-api.version} - - - org.glassfish.web - javax.el - ${javax.el.version} + org.glassfish.expressly + expressly + ${expressly.version} org.openjdk.jmh @@ -95,10 +85,8 @@ - 2.0.0.Final - 6.0.2.Final - 3.0.0 - 2.2.6 + 8.0.1.Final + 5.0.0 1.14 5.3.0 diff --git a/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/emptystrings/SomeClassWithValidations.java b/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/emptystrings/SomeClassWithValidations.java index 058d53ba82..abe311938a 100644 --- a/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/emptystrings/SomeClassWithValidations.java +++ b/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/emptystrings/SomeClassWithValidations.java @@ -1,6 +1,6 @@ package com.baeldung.emptystrings; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.Pattern; class SomeClassWithValidations { diff --git a/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/emptystrings/EmptyStringsUnitTest.java b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/emptystrings/EmptyStringsUnitTest.java index 9652e0e770..c756953c70 100644 --- a/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/emptystrings/EmptyStringsUnitTest.java +++ b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/emptystrings/EmptyStringsUnitTest.java @@ -5,10 +5,10 @@ import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.springframework.util.ObjectUtils; -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; import java.util.Set; import static org.hamcrest.Matchers.iterableWithSize; From 674f03a8fe8eee695e78aac18fe9cbe472f466e9 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 4 Nov 2023 12:43:56 +0530 Subject: [PATCH 022/107] JAVA-27177 Upgrade hibernate-validator version in atomikos module --- atomikos/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atomikos/pom.xml b/atomikos/pom.xml index cd798825d1..d2ef7c84b2 100644 --- a/atomikos/pom.xml +++ b/atomikos/pom.xml @@ -114,7 +114,7 @@ 1.1 1.0 2.0.1.Final - 6.1.2.Final + 8.0.1.Final 3.0.0 2.2.4 From 20361bec8ebc4b3f059b2ce9a98e2433e9622781 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 4 Nov 2023 12:59:59 +0530 Subject: [PATCH 023/107] JAVA-27178 Upgrade hibernate-validator in javaxval module --- javaxval/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javaxval/pom.xml b/javaxval/pom.xml index bececb2ea7..c4a30f915d 100644 --- a/javaxval/pom.xml +++ b/javaxval/pom.xml @@ -37,7 +37,7 @@ - 6.2.0.Final + 8.0.1.Final 3.0.4 From 885111ea75a8e4edb6b5fd82e94389effc8232ae Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 4 Nov 2023 13:13:28 +0530 Subject: [PATCH 024/107] JAVA-27177 Upragde hibernate validator- Remove dependencies no longer needed --- atomikos/pom.xml | 18 ------------------ .../atomikos/spring/jpa/Application.java | 8 ++++---- .../atomikos/spring/jpa/order/Order.java | 2 +- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/atomikos/pom.xml b/atomikos/pom.xml index d2ef7c84b2..2cbc106268 100644 --- a/atomikos/pom.xml +++ b/atomikos/pom.xml @@ -82,26 +82,11 @@ geronimo-jta_1.0.1B_spec ${geronimo.version} - - javax.validation - validation-api - ${validation-api.version} - org.hibernate.validator hibernate-validator ${hibernate-validator.version} - - javax.el - javax.el-api - ${javax.el-api.version} - - - org.glassfish.web - javax.el - ${javax.el.version} - @@ -113,10 +98,7 @@ 10.8.1.2 1.1 1.0 - 2.0.1.Final 8.0.1.Final - 3.0.0 - 2.2.4 \ No newline at end of file diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java b/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java index cf1fef2cd8..ad828bd2ca 100644 --- a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java +++ b/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java @@ -3,10 +3,10 @@ package com.baeldung.atomikos.spring.jpa; import java.util.Set; import java.util.UUID; -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java b/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java index 4b9ae2dd1d..3a580e6448 100644 --- a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java +++ b/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java @@ -3,7 +3,7 @@ package com.baeldung.atomikos.spring.jpa.order; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; -import javax.validation.constraints.Max; +import jakarta.validation.constraints.Max; @Entity @Table(name = "ORDERS") From 3ee56ca66ed6aebf9f2ba92e3eaafd4b474e089c Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sat, 4 Nov 2023 11:12:34 +0200 Subject: [PATCH 025/107] [JAVA-26735] Fixed test case --- .../primitives/PrimitiveValuesUnitTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/json-modules/gson/src/test/java/com/baeldung/gson/primitives/PrimitiveValuesUnitTest.java b/json-modules/gson/src/test/java/com/baeldung/gson/primitives/PrimitiveValuesUnitTest.java index e1241fa92a..00edcd426a 100644 --- a/json-modules/gson/src/test/java/com/baeldung/gson/primitives/PrimitiveValuesUnitTest.java +++ b/json-modules/gson/src/test/java/com/baeldung/gson/primitives/PrimitiveValuesUnitTest.java @@ -43,8 +43,8 @@ public class PrimitiveValuesUnitTest { gson.toJson(model); } - @Test(expected = IllegalArgumentException.class) public void - whenSerializingNaN_thenShouldRaiseAnException() { + @Test(expected = IllegalArgumentException.class) + public void whenSerializingNaN_thenShouldRaiseAnException() { FloatExample model = new FloatExample(); model.value = Float.NaN; @@ -52,7 +52,8 @@ public class PrimitiveValuesUnitTest { gson.toJson(model); } - @Test public void whenDeserializingFromJSON_thenShouldParseTheValueInTheString() { + @Test + public void whenDeserializingFromJSON_thenShouldParseTheValueInTheString() { String json = "{\"byteValue\": 17, \"shortValue\": 3, \"intValue\": 3, " + "\"longValue\": 3, \"floatValue\": 3.5" + ", \"doubleValue\": 3.5" + ", \"booleanValue\": true, \"charValue\": \"a\"}"; @@ -72,14 +73,16 @@ public class PrimitiveValuesUnitTest { // @formatter:on } - @Test public void whenDeserializingHighPrecissionNumberIntoFloat_thenShouldPerformRounding() { + @Test + public void whenDeserializingHighPrecissionNumberIntoFloat_thenShouldPerformRounding() { String json = "{\"value\": 12.123425589123456}"; Gson gson = new Gson(); FloatExample model = gson.fromJson(json, FloatExample.class); assertEquals(12.123426f, model.value, 0.000001); } - @Test public void whenDeserializingHighPrecissiongNumberIntoDouble_thenShouldPerformRounding() { + @Test + public void whenDeserializingHighPrecissiongNumberIntoDouble_thenShouldPerformRounding() { String json = "{\"value\": 12.123425589123556}"; Gson gson = new Gson(); DoubleExample model = gson.fromJson(json, DoubleExample.class); @@ -87,12 +90,12 @@ public class PrimitiveValuesUnitTest { } - @Test public void whenDeserializingValueThatOverflows_thenShouldOverflowSilently() { + @Test(expected = JsonSyntaxException.class) + public void whenDeserializingValueThatOverflows_thenShouldRaiseAnException() { Gson gson = new Gson(); String json = "{\"value\": \"300\"}"; ByteExample model = gson.fromJson(json, ByteExample.class); - assertEquals(44, model.value); } @Test public void whenDeserializingRealIntoByte_thenShouldRaiseAnException() { From dad8f5cf2b58a7fa83e430743488a44f8ac02576 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 5 Nov 2023 11:48:26 +0530 Subject: [PATCH 026/107] JAVA-27180 Upgrade hibernate-validator version in hibernate-mapping module --- persistence-modules/hibernate-mapping/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 1e3dc8be5f..0ce112b9e6 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -20,7 +20,7 @@ test - org.hibernate + org.hibernate.orm hibernate-core ${hibernate.version} @@ -36,7 +36,7 @@ - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -82,7 +82,7 @@ 2.1.214 6.1.7.Final 2.21.1 - 8.0.0.Final + 8.0.1.Final 3.0.1-b11 1.1 1.4.2 From a8af97e2eb5f534576447dddacc6ce8c79e206b5 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 5 Nov 2023 12:40:54 +0530 Subject: [PATCH 027/107] JAVA-27181 Update hibernate-validator version in jpa-hibarnate-cascade-type module --- .../jpa-hibernate-cascade-type/pom.xml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/persistence-modules/jpa-hibernate-cascade-type/pom.xml b/persistence-modules/jpa-hibernate-cascade-type/pom.xml index fd0ae117c7..90dd826a6e 100644 --- a/persistence-modules/jpa-hibernate-cascade-type/pom.xml +++ b/persistence-modules/jpa-hibernate-cascade-type/pom.xml @@ -24,27 +24,15 @@ - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} - - javax.el - javax.el-api - ${javax.el-api.version} - - - org.glassfish - javax.el - ${org.glassfish.javax.el.version} - 5.4.3.Final - 6.0.17.Final - 3.0.0 - 3.0.1-b11 + 8.0.1.Final \ No newline at end of file From 9e0b0945f7820d8e431b44c49f3a47a2d70be952 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 5 Nov 2023 13:05:01 +0530 Subject: [PATCH 028/107] JAVA-27182 Upgrade hibernate-validator version in spring-data-couchbase-2 module --- persistence-modules/spring-data-couchbase-2/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-data-couchbase-2/pom.xml b/persistence-modules/spring-data-couchbase-2/pom.xml index deb7d3b524..45462d477e 100644 --- a/persistence-modules/spring-data-couchbase-2/pom.xml +++ b/persistence-modules/spring-data-couchbase-2/pom.xml @@ -40,7 +40,7 @@ - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -71,7 +71,7 @@ 6.0.6 5.0.3 - 8.0.0.Final + 8.0.1.Final 2.12.2 From a575de93b1025cf723f87f98ebbbfe45bc2a6952 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 5 Nov 2023 13:36:30 +0530 Subject: [PATCH 029/107] JAVA-27183 Upgrade hibernate-validator version in spring-jpa module --- persistence-modules/spring-jpa/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-jpa/pom.xml b/persistence-modules/spring-jpa/pom.xml index c08e4f823a..10e44c0ce4 100644 --- a/persistence-modules/spring-jpa/pom.xml +++ b/persistence-modules/spring-jpa/pom.xml @@ -71,7 +71,7 @@ - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -122,7 +122,7 @@ 6.0.0 - 8.0.0.Final + 8.0.1.Final 2.0.2 2.1.214 5.0.0 From 790ec2b7fb71711ab9a8c793b6d101ac3e27cae8 Mon Sep 17 00:00:00 2001 From: timis1 Date: Sun, 5 Nov 2023 23:27:26 +0200 Subject: [PATCH 030/107] JAVA-27237 Review log statements for projects - Week 16 - 2023 (moved-13) (conti-1) --- .../test/resources/META-INF/persistence.xml | 2 +- .../src/test/resources/logback-test.xml | 2 +- .../src/test/resources/logback-test.xml | 2 ++ .../config/src/main/resources/logback.xml | 6 ++++++ .../src/main/resources/logback.xml | 18 +++++++++++++++++ .../src/main/resources/logback.xml | 20 +++++++++++++++++++ .../src/test/resources/logback-test.xml | 6 ++++++ 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml create mode 100644 spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-echo-demo/src/main/resources/logback.xml diff --git a/persistence-modules/deltaspike/src/test/resources/META-INF/persistence.xml b/persistence-modules/deltaspike/src/test/resources/META-INF/persistence.xml index ffcf20878c..60b415abd7 100644 --- a/persistence-modules/deltaspike/src/test/resources/META-INF/persistence.xml +++ b/persistence-modules/deltaspike/src/test/resources/META-INF/persistence.xml @@ -35,7 +35,7 @@ - + diff --git a/persistence-modules/deltaspike/src/test/resources/logback-test.xml b/persistence-modules/deltaspike/src/test/resources/logback-test.xml index bdc292924b..6a9aa37e7f 100644 --- a/persistence-modules/deltaspike/src/test/resources/logback-test.xml +++ b/persistence-modules/deltaspike/src/test/resources/logback-test.xml @@ -7,7 +7,7 @@ - + diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-basic-config/src/test/resources/logback-test.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-basic-config/src/test/resources/logback-test.xml index 8d4771e308..b9242f40a8 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-basic-config/src/test/resources/logback-test.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-basic-config/src/test/resources/logback-test.xml @@ -6,6 +6,8 @@ + + diff --git a/spring-cloud-modules/spring-cloud-bootstrap/config/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-bootstrap/config/src/main/resources/logback.xml index 7d900d8ea8..896eaf9c88 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/config/src/main/resources/logback.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/config/src/main/resources/logback.xml @@ -7,6 +7,12 @@ + + + + + + diff --git a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml new file mode 100644 index 0000000000..d944288ca4 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-echo-demo/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-echo-demo/src/main/resources/logback.xml new file mode 100644 index 0000000000..5f3e764e22 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-echo-demo/src/main/resources/logback.xml @@ -0,0 +1,20 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-jenkins-pipeline/src/test/resources/logback-test.xml b/spring-jenkins-pipeline/src/test/resources/logback-test.xml index b9242f40a8..69ab60701a 100644 --- a/spring-jenkins-pipeline/src/test/resources/logback-test.xml +++ b/spring-jenkins-pipeline/src/test/resources/logback-test.xml @@ -8,6 +8,12 @@ + + + + + + From dc667e03f3b9d4b94466459fbbaec99840d51f00 Mon Sep 17 00:00:00 2001 From: timis1 Date: Mon, 6 Nov 2023 13:58:00 +0200 Subject: [PATCH 031/107] JAVA-27237 Change the logging level to WARN (spring-integration) --- spring-integration/src/test/resources/logback-test.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-integration/src/test/resources/logback-test.xml b/spring-integration/src/test/resources/logback-test.xml index 98bfc86d71..352dc719df 100644 --- a/spring-integration/src/test/resources/logback-test.xml +++ b/spring-integration/src/test/resources/logback-test.xml @@ -9,7 +9,7 @@ - + From 03c615201fdad5e3bd54f7c701972bb248f7d2a7 Mon Sep 17 00:00:00 2001 From: Ulisses Lima Date: Mon, 6 Nov 2023 16:26:35 -0300 Subject: [PATCH 032/107] Update InterruptThread.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on a comment: Section 6 should be headlined with “Using System.exit()” since that’s what stops code execution, not the boolean variable (this is just a means to decide that execution should be stopped, like the negative array element in section 4. Also it’s unclear why we’d need the “if (isInterrupted())” statement in the while loop of the 8th section: how should isInterrupted() be true one line after we’ve checked in the while loop header that it’s false? Admittedly there’s a little chance that the interrupt status changed between these 2 lines, but this if statement would make much more sense somewhere in the business logic code where more time has passed since the evaluation of “while (!isInterrupted())”… and if that business code doesn’t have that complexity/length, one should omit this if statement altogether, since it creates more confusion than it helps for timely reaction on an interruption. --- .../main/java/com/baeldung/stopexecution/InterruptThread.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java index 7964ad9f52..7fcb6185cc 100644 --- a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java @@ -4,9 +4,7 @@ public class InterruptThread extends Thread { @Override public void run() { while (!isInterrupted()) { - if (isInterrupted()) { - break; - } + break; // business logic } } From 4ef6b9039f4e77075b6b199a5df9106da22f20ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Cardo=C5=9F?= <106325528+sodrac@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:47:45 +0200 Subject: [PATCH 033/107] BAEL-6874 update test code for article (#15155) * BAEL-6819 convert from int to Long in Java * BAEL-6819 update package name * BAEL-6874 test code for article * BAEL-6874 rename test class * BAEL-6874 update test code for article --- .../GenericNumbersComparatorUnitTest.java | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java index 37b971b5c5..0fcc0f3453 100644 --- a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java @@ -1,13 +1,12 @@ package com.baeldung.genericnumberscomparator; +import static org.assertj.core.api.Assertions.entry; import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Comparator; -import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.function.BiFunction; import java.util.function.BiPredicate; import java.util.function.Function; @@ -25,6 +24,7 @@ class GenericNumbersComparatorUnitTest { assertEquals(0, compareDouble(5, 5.0)); } + // we create a method that compares Integer, but this could also be done for other types e.g. Double, BigInteger public int compareTo(Integer int1, Integer int2) { return int1.compareTo(int2); } @@ -34,11 +34,10 @@ class GenericNumbersComparatorUnitTest { assertEquals(-1, compareTo(5, 7)); } - Map, BiFunction> comparisonMap = new HashMap<>(); + // for this example, we create a function that compares Integer, but this could also be done for other types e.g. Double, BigInteger + Map, BiFunction> comparisonMap = Map.ofEntries(entry(Integer.class, (num1, num2) -> ((Integer) num1).compareTo((Integer) num2))); public int compareUsingMap(Number num1, Number num2) { - comparisonMap.put(Integer.class, (a, b) -> ((Integer) num1).compareTo((Integer) num2)); - return comparisonMap.get(num1.getClass()) .apply(num1, num2); } @@ -70,24 +69,6 @@ class GenericNumbersComparatorUnitTest { assertEquals(-1, compareUsingReflection(5, 7)); } - interface NumberComparatorFactory { - Comparator getComparator(); - } - - class IntegerComparatorFactory implements NumberComparatorFactory { - @Override - public Comparator getComparator() { - return (num1, num2) -> ((Integer) num1).compareTo((Integer) num2); - } - } - - @Test - void givenNumbers_whenUseComparatorFactory_thenWillExecuteComparison() { - NumberComparatorFactory factory = new IntegerComparatorFactory(); - Comparator comparator = factory.getComparator(); - assertEquals(-1, comparator.compare(5, 7)); - } - Function toDouble = Number::doubleValue; BiPredicate isEqual = (num1, num2) -> toDouble.apply(num1) .equals(toDouble.apply(num2)); @@ -97,19 +78,6 @@ class GenericNumbersComparatorUnitTest { assertEquals(true, isEqual.test(5, 5.0)); } - private Number someNumber = 5; - private Number anotherNumber = 5.0; - - Optional optNum1 = Optional.ofNullable(someNumber); - Optional optNum2 = Optional.ofNullable(anotherNumber); - int comparisonResult = optNum1.flatMap(n1 -> optNum2.map(n2 -> Double.compare(n1.doubleValue(), n2.doubleValue()))) - .orElse(0); - - @Test - void givenNumbers_whenUseComparisonResult_thenWillExecuteComparison() { - assertEquals(0, comparisonResult); - } - private boolean someCondition = true; Function dynamicFunction = someCondition ? Number::doubleValue : Number::intValue; Comparator dynamicComparator = (num1, num2) -> ((Comparable) dynamicFunction.apply(num1)).compareTo(dynamicFunction.apply(num2)); From 9e995c1e417a8fc2a9d3339bc64adf7568746353 Mon Sep 17 00:00:00 2001 From: Mateusz Szablak Date: Mon, 6 Nov 2023 22:38:36 +0100 Subject: [PATCH 034/107] BAEL-6489 Time Conversions Using TimeUnit (#14390) --- .../TimeUnitConversionsUnitTest.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/timeunitconversions/TimeUnitConversionsUnitTest.java diff --git a/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/timeunitconversions/TimeUnitConversionsUnitTest.java b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/timeunitconversions/TimeUnitConversionsUnitTest.java new file mode 100644 index 0000000000..cbcbcd566b --- /dev/null +++ b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/timeunitconversions/TimeUnitConversionsUnitTest.java @@ -0,0 +1,105 @@ +package com.baeldung.timeunitconversions; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +class TimeUnitConversionsUnitTest { + + + @Test + void givenSeconds_whenConvertToMinutes_thenCorrect() { + int input = 60; + + long minutes = TimeUnit.MINUTES.convert(input, TimeUnit.SECONDS); + + assertThat(minutes).isEqualTo(1); + } + + @Test + void givenMinutes_whenConvertToSeconds_thenCorrect() { + int input = 1; + + long seconds = TimeUnit.SECONDS.convert(input, TimeUnit.MINUTES); + + assertThat(seconds).isEqualTo(60); + } + + @Test + void givenSeconds_whenToMinutes_thenCorrect() { + int input = 60; + + long minutes = TimeUnit.SECONDS.toMinutes(input); + + assertThat(minutes).isEqualTo(1); + } + + @Test + void givenMinutes_whenToSeconds_thenCorrect() { + int input = 1; + + long seconds = TimeUnit.MINUTES.toSeconds(input); + + assertThat(seconds).isEqualTo(60); + } + + @Test + void givenNegativeInput_whenToMinutes_thenCorrect() { + int input = -60; + + long minutes = TimeUnit.SECONDS.toMinutes(input); + assertThat(minutes).isEqualTo(-1); + } + + @Test + void givenNonTotalInput_whenToMinutes_thenCorrectTotalResultWithDecimalTruncate() { + long positiveUnder = TimeUnit.SECONDS.toMinutes(59); + long positiveAbove = TimeUnit.SECONDS.toMinutes(61); + + assertThat(positiveUnder).isEqualTo(0); + assertThat(positiveAbove).isEqualTo(1); + } + + @Test + void givenNonTotalNegativeInput_whenToMinutes_thenCorrectTotalResultWithDecimalTruncate() { + long negativeUnder = TimeUnit.SECONDS.toMinutes(-59); + long negativeAbove = TimeUnit.SECONDS.toMinutes(-61); + + assertThat(negativeUnder).isEqualTo(0); + assertThat(negativeAbove).isEqualTo(-1); + } + + @Test + void givenOverflowInput_whenToMillis_thenTruncatedToLimit() { + long maxMillis = TimeUnit.DAYS.toMillis(Long.MAX_VALUE); + long minMillis = TimeUnit.DAYS.toMillis(Long.MIN_VALUE); + + assertThat(maxMillis).isEqualTo(Long.MAX_VALUE); + assertThat(minMillis).isEqualTo(Long.MIN_VALUE); + } + + @Test + void givenInput_whenExtractFineTimeUnits_thenCorrect() { + long inputSeconds = 3672; + + long hours = TimeUnit.SECONDS.toHours(inputSeconds); + + long secondsRemainingAfterHours = inputSeconds - TimeUnit.HOURS.toSeconds(hours); + long minutes = TimeUnit.SECONDS.toMinutes(secondsRemainingAfterHours); + + long seconds = secondsRemainingAfterHours - TimeUnit.MINUTES.toSeconds(minutes); + + + assertThat(hours).isEqualTo(1); + assertThat(minutes).isEqualTo(1); + assertThat(seconds).isEqualTo(12); + + assertThat(inputSeconds).isEqualTo( + (hours * 60 * 60) + + (minutes * 60) + + (seconds) + ); + } +} From 14070ec048db08590402f87ebc4bd9b2065d23ec Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Tue, 7 Nov 2023 04:50:48 +0100 Subject: [PATCH 035/107] BAEL-6139: Added ThreadMonitorInfo (#15094) * BAEL-6139: Added ThreadMonitorInfo * BAEL-6139: Move ThreadMonitorInfo * BAEL-6139: Unsafe using park() and unpark(Thread) --- .../com/baeldung/park/ThreadMonitorInfo.java | 26 +++++++++ .../PreemptivePermitsBehaviorUnitTest.java | 27 +++++++++ ...atedPreemptivePermitsBehaviorUnitTest.java | 43 ++++++++++++++ .../ThreadInterruptedBehaviorUnitTest.java | 56 +++++++++++++++++++ .../park/TreadMonitorsBehaviorUnitTest.java | 51 +++++++++++++++++ 5 files changed, 203 insertions(+) create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/park/ThreadMonitorInfo.java create mode 100644 core-java-modules/core-java-sun/src/test/java/com/baeldung/park/PreemptivePermitsBehaviorUnitTest.java create mode 100644 core-java-modules/core-java-sun/src/test/java/com/baeldung/park/RepeatedPreemptivePermitsBehaviorUnitTest.java create mode 100644 core-java-modules/core-java-sun/src/test/java/com/baeldung/park/ThreadInterruptedBehaviorUnitTest.java create mode 100644 core-java-modules/core-java-sun/src/test/java/com/baeldung/park/TreadMonitorsBehaviorUnitTest.java diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/park/ThreadMonitorInfo.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/park/ThreadMonitorInfo.java new file mode 100644 index 0000000000..948fb48fcb --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/park/ThreadMonitorInfo.java @@ -0,0 +1,26 @@ +package com.baeldung.park; + +import java.util.concurrent.locks.LockSupport; + +public class ThreadMonitorInfo { + private static final Object MONITOR = new Object(); + public static void main(String[] args) throws InterruptedException { + final Thread waitingThread = new Thread(() -> { + try { + synchronized (MONITOR) { + MONITOR.wait(); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }, "Waiting Thread"); + + final Thread parkedThread = new Thread(LockSupport::park, "Parked Thread"); + + waitingThread.start(); + parkedThread.start(); + + waitingThread.join(); + parkedThread.join(); + } +} diff --git a/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/PreemptivePermitsBehaviorUnitTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/PreemptivePermitsBehaviorUnitTest.java new file mode 100644 index 0000000000..05bfa4ba0b --- /dev/null +++ b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/PreemptivePermitsBehaviorUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.park; + +import static org.junit.jupiter.api.Assertions.*; + +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.concurrent.locks.LockSupport; +import org.junit.jupiter.api.Test; + +class PreemptivePermitsBehaviorUnitTest { + + private final Thread parkedThread = new Thread() { + @Override + public void run() { + LockSupport.unpark(this); + LockSupport.park(); + } + }; + + @Test + void givenThreadWhenPreemptivePermitShouldNotPark() { + assertTimeoutPreemptively(Duration.of(1, ChronoUnit.SECONDS), () -> { + parkedThread.start(); + parkedThread.join(); + }); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/RepeatedPreemptivePermitsBehaviorUnitTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/RepeatedPreemptivePermitsBehaviorUnitTest.java new file mode 100644 index 0000000000..98be58e9d3 --- /dev/null +++ b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/RepeatedPreemptivePermitsBehaviorUnitTest.java @@ -0,0 +1,43 @@ +package com.baeldung.park; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.LockSupport; +import org.junit.jupiter.api.Test; + +class RepeatedPreemptivePermitsBehaviorUnitTest { + + private final Thread parkedThread = new Thread() { + @Override + public void run() { + LockSupport.unpark(this); + LockSupport.unpark(this); + LockSupport.park(); + LockSupport.park(); + } + }; + + @Test + void givenThreadWhenRepeatedPreemptivePermitShouldPark() { + Callable callable = () -> { + parkedThread.start(); + parkedThread.join(); + return true; + }; + + boolean result = false; + final Future future = Executors.newSingleThreadExecutor().submit(callable); + try { + result = future.get(1, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + // Expected the thread to be parked + } + assertFalse(result, "The thread should be parked"); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/ThreadInterruptedBehaviorUnitTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/ThreadInterruptedBehaviorUnitTest.java new file mode 100644 index 0000000000..da7b6ffbc9 --- /dev/null +++ b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/ThreadInterruptedBehaviorUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.park; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + +class ThreadInterruptedBehaviorUnitTest { + + @Test + @Timeout(3) + void givenParkedThreadWhenInterruptedShouldNotResetInterruptedFlag() throws InterruptedException { + final Thread thread = new Thread(LockSupport::park); + thread.start(); + thread.interrupt(); + assertTrue(thread.isInterrupted(), "The thread should have the interrupted flag"); + thread.join(); + } + + @Test + @Timeout(3) + void givenParkedThreadWhenNotInterruptedShouldNotHaveInterruptedFlag() throws InterruptedException { + final Thread thread = new Thread(LockSupport::park); + thread.start(); + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); + LockSupport.unpark(thread); + assertFalse(thread.isInterrupted(), "The thread shouldn't have the interrupted flag"); + thread.join(); + } + + @Test + @Timeout(3) + void givenWaitingThreadWhenNotInterruptedShouldNotHaveInterruptedFlag() throws InterruptedException { + + final Thread thread = new Thread() { + @Override + public void run() { + synchronized (this) { + try { + this.wait(); + } catch (InterruptedException e) { + // The thread was interrupted + } + } + } + }; + + thread.start(); + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); + thread.interrupt(); + thread.join(); + assertFalse(thread.isInterrupted(), "The thread shouldn't have the interrupted flag"); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/TreadMonitorsBehaviorUnitTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/TreadMonitorsBehaviorUnitTest.java new file mode 100644 index 0000000000..b14b674a19 --- /dev/null +++ b/core-java-modules/core-java-sun/src/test/java/com/baeldung/park/TreadMonitorsBehaviorUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.park; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; + +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.LockSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + + +class TreadMonitorsBehaviorUnitTest { + + @Test + @Timeout(3) + void giveThreadWhenNotifyWithoutAcquiringMonitorThrowsException() { + final Thread thread = new Thread() { + @Override + public void run() { + synchronized (this) { + try { + this.wait(); + } catch (InterruptedException e) { + // The thread was interrupted + } + } + } + }; + + assertThrows(IllegalMonitorStateException.class, () -> { + thread.start(); + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); + thread.notify(); + thread.join(); + }); + } + + @Test + @Timeout(3) + void giveThreadWhenUnparkWithoutAcquiringMonitor() { + final Thread thread = new Thread(LockSupport::park); + assertTimeoutPreemptively(Duration.of(2, ChronoUnit.SECONDS), () -> { + thread.start(); + LockSupport.unpark(thread); + }); + } +} From a7f39e4155917e732664262beaa686259add6321 Mon Sep 17 00:00:00 2001 From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:42:25 +0530 Subject: [PATCH 036/107] Spell mistake fix --- .../java/com/baledung/billpugh/BillPughSingletonUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java index b42d36229f..dcf2098b4b 100644 --- a/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java +++ b/patterns-modules/design-patterns-singleton/src/test/java/com/baledung/billpugh/BillPughSingletonUnitTest.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class BillPughSingletonUnitTest { Logger logger = LoggerFactory.getLogger(BillPughSingletonUnitTest.class); @Test - void giveSynchronizedLazyLoadedImpl_whenCallgetInstance_thenReturnSingleton() { + void givenSynchronizedLazyLoadedImpl_whenCallgetInstance_thenReturnSingleton() { Set setHoldingSingletonObj = new HashSet<>(); List> futures = new ArrayList<>(); From f1424a62ef6f8bab13fee10463435d895de9da33 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Tue, 7 Nov 2023 15:52:43 +0530 Subject: [PATCH 037/107] JAVA-26556: Changes made for Adding missed modules (#15105) /core-java-modules/core-java-numbers-conversions /core-java-modules/core-java-datetime-conversion /di-modules/avaje/persistence-modules/spring-boot-persistence-4 /spring-boot-modules/spring-boot-security-2 /spring-boot-modules/spring-boot-ssl-bundles /spring-boot-modules/spring-boot-telegram --- ...nversionsTest.java => FloatDoubleConversionsUnitTest.java} | 2 +- core-java-modules/pom.xml | 4 +++- di-modules/pom.xml | 1 + persistence-modules/pom.xml | 1 + spring-boot-modules/pom.xml | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) rename core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/{FloatDoubleConversionsTest.java => FloatDoubleConversionsUnitTest.java} (95%) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsUnitTest.java similarity index 95% rename from core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java rename to core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsUnitTest.java index 9da50276a9..2bddb6d8cd 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsUnitTest.java @@ -3,7 +3,7 @@ package com.baeldung.floatdoubleconversions; import org.junit.Assert; import org.junit.Test; -public class FloatDoubleConversionsTest { +public class FloatDoubleConversionsUnitTest { @Test public void whenDoubleType_thenFloatTypeSuccess(){ diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 79596d2067..f4bda010e8 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -32,6 +32,7 @@ + core-java-numbers-conversions core-java-9-improvements core-java-9-streams core-java-9 @@ -195,9 +196,10 @@ core-java-records core-java-9-jigsaw + core-java-collections-set core-java-date-operations-1 - + core-java-datetime-conversion core-java-httpclient java-native diff --git a/di-modules/pom.xml b/di-modules/pom.xml index e6c86d48e6..984180cb28 100644 --- a/di-modules/pom.xml +++ b/di-modules/pom.xml @@ -18,6 +18,7 @@ dagger flyway-cdi-extension guice + avaje \ No newline at end of file diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index eb4b212771..8726b7ad87 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -120,6 +120,7 @@ scylladb spring-data-cassandra-2 spring-data-jpa-repo-3 + spring-boot-persistence-4 diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 259a40dc38..433f23f4ba 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -68,6 +68,9 @@ spring-boot-runtime spring-boot-runtime-2 spring-boot-security + spring-boot-security-2 + spring-boot-ssl-bundles + spring-boot-telegram spring-boot-springdoc spring-boot-swagger spring-boot-swagger-2 From 19e70b20a485c7abf466a7fd29557ed31787d601 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Tue, 7 Nov 2023 15:58:16 +0530 Subject: [PATCH 038/107] =?UTF-8?q?JAVA-26498:=20Changes=20made=20for=20ad?= =?UTF-8?q?ding=20missed=20module=20core-java-collectio=E2=80=A6=20(#15071?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /core-java-modules/core-java-collections-conversions-2 /core-java-modules/core-java-collections-conversions-3 /core-java-modules/core-java-concurrency-advanced-5 --- core-java-modules/pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index f4bda010e8..a237fe0ed6 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -21,7 +21,9 @@ - + core-java-collections-conversions-2 + core-java-collections-conversions-3 + core-java-concurrency-advanced-5 From 63758605c922c7daa0a8fa3413091967ff2dae5d Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Tue, 7 Nov 2023 16:45:05 +0530 Subject: [PATCH 039/107] JAVA-26557: Changes made for Adding missed modules (#15121) /libraries-ai /spring-pulsar /maven-modules/versions-maven-plugin/original --- maven-modules/versions-maven-plugin/original/pom.xml | 5 ----- maven-modules/versions-maven-plugin/pom.xml | 11 +++++++++++ pom.xml | 3 +++ spring-pulsar/pom.xml | 5 +---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/maven-modules/versions-maven-plugin/original/pom.xml b/maven-modules/versions-maven-plugin/original/pom.xml index 2d81274611..6026dac9fe 100644 --- a/maven-modules/versions-maven-plugin/original/pom.xml +++ b/maven-modules/versions-maven-plugin/original/pom.xml @@ -18,11 +18,6 @@ commons-collections4 ${commons-collections4.version} - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - org.apache.commons commons-compress diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 9c837cefa0..ec1e0ceaba 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -7,6 +7,17 @@ versions-maven-plugin 0.0.1-SNAPSHOT versions-maven-plugin + pom + + + maven-modules + com.baeldung + 0.0.1-SNAPSHOT + + + + original + diff --git a/pom.xml b/pom.xml index 12a8f3dc1d..a16fabebc5 100644 --- a/pom.xml +++ b/pom.xml @@ -860,6 +860,7 @@ libraries-http libraries-http-2 libraries-io + libraries-ai libraries-primitive libraries-rpc libraries-server @@ -930,6 +931,7 @@ spring-kafka-2 libraries-llms + spring-pulsar @@ -1212,6 +1214,7 @@ spring-kafka-2 libraries-llms + spring-pulsar diff --git a/spring-pulsar/pom.xml b/spring-pulsar/pom.xml index 05debcab1c..a1c834f830 100644 --- a/spring-pulsar/pom.xml +++ b/spring-pulsar/pom.xml @@ -15,10 +15,6 @@ ../parent-boot-3 - - 17 - 0.2.0 - org.springframework.boot @@ -47,6 +43,7 @@ + 17 0.2.0 From 270acf62e46bc420a0517d756fa63b1742b904b2 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Tue, 7 Nov 2023 21:49:49 +0530 Subject: [PATCH 040/107] Formatter Changes --- .../ResultSetToMapUnitTest.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java index c8a6351804..e449beb83a 100644 --- a/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java +++ b/persistence-modules/core-java-persistence-3/src/test/java/com/baeldung/resultsettomap/ResultSetToMapUnitTest.java @@ -45,7 +45,8 @@ public class ResultSetToMapUnitTest { @Test public void whenUsingContainsKey_thenConvertResultSetToMap() throws SQLException { - ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery(); + ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee") + .executeQuery(); Map> valueMap = new HashMap<>(); while (resultSet.next()) { @@ -54,22 +55,27 @@ public class ResultSetToMapUnitTest { if (!valueMap.containsKey(empCity)) { valueMap.put(empCity, new ArrayList<>()); } - valueMap.get(empCity).add(empName); + valueMap.get(empCity) + .add(empName); } - assertEquals(3, valueMap.get("London").size()); + assertEquals(3, valueMap.get("London") + .size()); } @Test public void whenUsingComputeIfAbsent_thenConvertResultSetToMap() throws SQLException { - ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery(); + ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee") + .executeQuery(); Map> valueMap = new HashMap<>(); while (resultSet.next()) { String empCity = resultSet.getString("empCity"); String empName = resultSet.getString("empName"); - valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName); + valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()) + .add(empName); } - assertEquals(3, valueMap.get("London").size()); + assertEquals(3, valueMap.get("London") + .size()); } @Test @@ -81,15 +87,17 @@ public class ResultSetToMapUnitTest { while (resultSet.next()) { String empCity = resultSet.getString("empCity"); String empName = resultSet.getString("empName"); - result.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName); + result.computeIfAbsent(empCity, data -> new ArrayList<>()) + .add(empName); } return result; } }; - + QueryRunner run = new QueryRunner(); Map> valueMap = run.query(connection, "SELECT * FROM employee", handler); - assertEquals(3, valueMap.get("London").size()); + assertEquals(3, valueMap.get("London") + .size()); } @After From 362610ca587c741843e616d387f613acad3c1340 Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:21:46 +0100 Subject: [PATCH 041/107] BAEL-6776: Convert File to Byte Array in Java (#15123) --- .../FileToByteArrayUnitTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/filetofrombytearray/FileToByteArrayUnitTest.java diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/filetofrombytearray/FileToByteArrayUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/filetofrombytearray/FileToByteArrayUnitTest.java new file mode 100644 index 0000000000..1bbd958583 --- /dev/null +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/filetofrombytearray/FileToByteArrayUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.filetofrombytearray; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Test; + +class FileToByteArrayUnitTest { + + private static final String FILE_NAME = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "sample.txt"; + private final byte[] expectedByteArray = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 }; + + @Test + void givenFile_whenUsingFileInputStreamClass_thenConvert() throws IOException { + File myFile = new File(FILE_NAME); + byte[] byteArray = new byte[(int) myFile.length()]; + try (FileInputStream inputStream = new FileInputStream(myFile)) { + inputStream.read(byteArray); + } + + assertArrayEquals(expectedByteArray, byteArray); + } + + @Test + void givenFile_whenUsingNioApiFilesClass_thenConvert() throws IOException { + byte[] byteArray = Files.readAllBytes(Paths.get(FILE_NAME)); + + assertArrayEquals(expectedByteArray, byteArray); + } + + @Test + void givenFile_whenUsingApacheCommonsIOUtilsClass_thenConvert() throws IOException { + File myFile = new File(FILE_NAME); + byte[] byteArray = new byte[(int) myFile.length()]; + try (FileInputStream inputStream = new FileInputStream(myFile)) { + byteArray = IOUtils.toByteArray(inputStream); + } + + assertArrayEquals(expectedByteArray, byteArray); + } + + @Test + void givenFile_whenUsingApacheCommonsFileUtilsClass_thenConvert() throws IOException { + byte[] byteArray = FileUtils.readFileToByteArray(new File(FILE_NAME)); + + assertArrayEquals(expectedByteArray, byteArray); + } + + @Test + void givenFile_whenUsingGuavaFilesClass_thenConvert() throws IOException { + byte[] byteArray = com.google.common.io.Files.toByteArray(new File(FILE_NAME)); + + assertArrayEquals(expectedByteArray, byteArray); + } + +} From 9b28d7739aade6a5baad097206b655d4aa824025 Mon Sep 17 00:00:00 2001 From: Ehsan Sasanianno Date: Wed, 8 Nov 2023 10:26:53 +0100 Subject: [PATCH 042/107] java-26718: upgrade caffeine version to 3.x (#15138) --- libraries-5/pom.xml | 2 +- spring-5-webflux-2/pom.xml | 2 +- spring-boot-modules/spring-boot-libraries/pom.xml | 2 +- spring-boot-modules/spring-caching-2/pom.xml | 2 ++ spring-boot-modules/spring-caching/pom.xml | 2 ++ 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml index c98a66c094..a043b4bfa8 100644 --- a/libraries-5/pom.xml +++ b/libraries-5/pom.xml @@ -141,7 +141,7 @@ 2.5.11 0.8.1 3.0.14 - 2.5.5 + 3.1.8 3.0.2 4.5.1 1.0 diff --git a/spring-5-webflux-2/pom.xml b/spring-5-webflux-2/pom.xml index 68945138d4..34cbda6c18 100644 --- a/spring-5-webflux-2/pom.xml +++ b/spring-5-webflux-2/pom.xml @@ -100,7 +100,7 @@ 3.4.5 - 2.9.2 + 3.1.8 1.16.2 diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index d8ca53f013..b7b8ad17ad 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -228,7 +228,7 @@ 3.3.0 7.6.0 0.7.0 - 2.8.2 + 3.1.8 \ No newline at end of file diff --git a/spring-boot-modules/spring-caching-2/pom.xml b/spring-boot-modules/spring-caching-2/pom.xml index 2239256630..ee28ac5ed5 100644 --- a/spring-boot-modules/spring-caching-2/pom.xml +++ b/spring-boot-modules/spring-caching-2/pom.xml @@ -47,6 +47,7 @@ com.github.ben-manes.caffeine caffeine + ${caffeine.version} it.ozimov @@ -64,6 +65,7 @@ 0.7.3 + 3.1.8 \ No newline at end of file diff --git a/spring-boot-modules/spring-caching/pom.xml b/spring-boot-modules/spring-caching/pom.xml index c27ccf3348..f3d9488b89 100644 --- a/spring-boot-modules/spring-caching/pom.xml +++ b/spring-boot-modules/spring-caching/pom.xml @@ -51,6 +51,7 @@ com.github.ben-manes.caffeine caffeine + ${caffeine.version} com.h2database @@ -78,6 +79,7 @@ 3.5.2 + 3.1.8 \ No newline at end of file From c7e2dc2a6ec7a54633ec4f4c988a7d970e656e56 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:06:28 +0200 Subject: [PATCH 043/107] JAVA-27248 Align module names, folder names and artifact id - Week 44 - 2023 (conti-1) (#15147) Co-authored-by: timis1 --- .../core-java-conditionals/pom.xml | 2 +- core-java-modules/core-java-os-2/pom.xml | 4 ++-- di-modules/avaje/pom.xml | 17 ++++++++++------- spring-6-rsocket/pom.xml | 4 ++-- .../spring-boot-security-2/pom.xml | 2 +- .../spring-boot-ssl-bundles/pom.xml | 10 ++++++---- .../spring-reactive-2/pom.xml | 4 ++-- .../spring-reactive-3/pom.xml | 4 ++-- .../spring-reactive-data-couchbase/pom.xml | 2 +- .../spring-reactive-data/pom.xml | 2 +- 10 files changed, 28 insertions(+), 23 deletions(-) diff --git a/core-java-modules/core-java-conditionals/pom.xml b/core-java-modules/core-java-conditionals/pom.xml index 811f183e99..f2ad7df749 100644 --- a/core-java-modules/core-java-conditionals/pom.xml +++ b/core-java-modules/core-java-conditionals/pom.xml @@ -5,7 +5,7 @@ 4.0.0 core-java-conditionals 0.1.0-SNAPSHOT - core-java-compiler + core-java-conditionals jar diff --git a/core-java-modules/core-java-os-2/pom.xml b/core-java-modules/core-java-os-2/pom.xml index 53fdafa7d4..11b0585ae7 100644 --- a/core-java-modules/core-java-os-2/pom.xml +++ b/core-java-modules/core-java-os-2/pom.xml @@ -3,8 +3,8 @@ 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 - core-java-os - core-java-os + core-java-os-2 + core-java-os-2 jar diff --git a/di-modules/avaje/pom.xml b/di-modules/avaje/pom.xml index 49162c518e..03d3902d5f 100644 --- a/di-modules/avaje/pom.xml +++ b/di-modules/avaje/pom.xml @@ -3,14 +3,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung - inject-intro + avaje 0.0.1-SNAPSHOT - avaje-inject-intro - - 11 - 11 - 9.5 - + avaje + Avaje Inject Intro + io.avaje @@ -34,4 +31,10 @@ true + + + 11 + 11 + 9.5 + \ No newline at end of file diff --git a/spring-6-rsocket/pom.xml b/spring-6-rsocket/pom.xml index 5d15a605ae..0f9e63bc7e 100644 --- a/spring-6-rsocket/pom.xml +++ b/spring-6-rsocket/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.bealdung - rsocket + spring-6-rsocket 0.0.1-SNAPSHOT - rsocket + spring-6-rsocket com.baeldung diff --git a/spring-boot-modules/spring-boot-security-2/pom.xml b/spring-boot-modules/spring-boot-security-2/pom.xml index db094f33a6..dd8cab81de 100644 --- a/spring-boot-modules/spring-boot-security-2/pom.xml +++ b/spring-boot-modules/spring-boot-security-2/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-security-2 - spring-boot-security-1 + spring-boot-security-2 jar Spring Boot Security Auto-Configuration diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml index 4802e9ec58..770d8c2f01 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml +++ b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml @@ -3,16 +3,18 @@ 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 + spring-boot-ssl-bundles + spring-boot-ssl-bundles + Module for showing usage of SSL Bundles + jar + com.baeldung parent-boot-3 0.0.1-SNAPSHOT ../../parent-boot-3 - springbootsslbundles - spring-boot-ssl-bundles - jar - Module for showing usage of SSL Bundles + org.springframework.boot diff --git a/spring-reactive-modules/spring-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-2/pom.xml index 13970851cd..90c5300cc8 100644 --- a/spring-reactive-modules/spring-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-2/pom.xml @@ -5,9 +5,9 @@ 4.0.0 spring-reactive-2 0.0.1-SNAPSHOT - spring-5-reactive-2 + spring-reactive-2 jar - spring 5 sample project about new features + spring sample project about new features com.baeldung.spring.reactive diff --git a/spring-reactive-modules/spring-reactive-3/pom.xml b/spring-reactive-modules/spring-reactive-3/pom.xml index 96f23f1339..bf2cdbbf2d 100644 --- a/spring-reactive-modules/spring-reactive-3/pom.xml +++ b/spring-reactive-modules/spring-reactive-3/pom.xml @@ -5,9 +5,9 @@ 4.0.0 spring-reactive-3 0.0.1-SNAPSHOT - spring-5-reactive-3 + spring-reactive-3 jar - spring 5 sample project about new features + spring sample project about new features com.baeldung.spring.reactive diff --git a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml b/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml index 52b10f39d9..a7481d8aca 100644 --- a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml +++ b/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-reactive-data-couchbase - spring-data-couchbase + spring-reactive-data-couchbase jar diff --git a/spring-reactive-modules/spring-reactive-data/pom.xml b/spring-reactive-modules/spring-reactive-data/pom.xml index 03ea440b4f..a598315d5d 100644 --- a/spring-reactive-modules/spring-reactive-data/pom.xml +++ b/spring-reactive-modules/spring-reactive-data/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-reactive-data - spring-reactive-data-2 + spring-reactive-data jar From 7b6ba0e030db93e6faa5b84fe2fdd02a901a5f80 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Wed, 8 Nov 2023 15:54:10 +0530 Subject: [PATCH 044/107] JAVA-26729:Changes made for upgrade commons-validator to latest version (#15159) --- core-java-modules/core-java-datetime-string/pom.xml | 2 +- .../java/com/baeldung/formatinstant/FormatInstantUnitTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-datetime-string/pom.xml b/core-java-modules/core-java-datetime-string/pom.xml index a33114852c..292a38a5af 100644 --- a/core-java-modules/core-java-datetime-string/pom.xml +++ b/core-java-modules/core-java-datetime-string/pom.xml @@ -64,7 +64,7 @@ - 1.6 + 1.7 2.12.5 RELEASE 1.9 diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/formatinstant/FormatInstantUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/formatinstant/FormatInstantUnitTest.java index ef273e4b81..1466fece46 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/formatinstant/FormatInstantUnitTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/formatinstant/FormatInstantUnitTest.java @@ -6,6 +6,7 @@ import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.UnsupportedTemporalTypeException; +import java.util.TimeZone; import org.joda.time.format.DateTimeFormat; import org.junit.Test; @@ -17,7 +18,7 @@ public class FormatInstantUnitTest { @Test public void givenInstant_whenUsingDateTimeFormatter_thenFormat() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_FORMAT) - .withZone(ZoneId.systemDefault()); + .withZone(TimeZone.getTimeZone("UTC").toZoneId()); Instant instant = Instant.parse("2022-02-15T18:35:24.00Z"); String formattedInstant = formatter.format(instant); From 33fceb65a61e7f2f94586809d97911bc066031cb Mon Sep 17 00:00:00 2001 From: Michael Olayemi Date: Wed, 8 Nov 2023 14:16:19 +0100 Subject: [PATCH 045/107] Using CriteriaDefinition Utility in Hibernate (#15128) * Using CriteriaDefinition Utility in Hibernate * Using CriteriaDefinition Utility in Hibernate * Using CriteriaDefinition Utility in Hibernate * Using CriteriaDefinition Utility in Hibernate * Using CriteriaDefinition Utility in Hibernate --- persistence-modules/hibernate-queries/pom.xml | 2 +- .../criteria/util/HibernateUtil.java | 7 + .../CriteriaDefinitionApplicationView.java | 126 ++++++++++++++++++ .../LocalDateStringJavaDescriptor.java | 11 ++ ...nateCriteriaDefinitionIntegrationTest.java | 77 +++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/view/CriteriaDefinitionApplicationView.java create mode 100644 persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/criteria/HibernateCriteriaDefinitionIntegrationTest.java diff --git a/persistence-modules/hibernate-queries/pom.xml b/persistence-modules/hibernate-queries/pom.xml index bb60c7b83a..76f230a72d 100644 --- a/persistence-modules/hibernate-queries/pom.xml +++ b/persistence-modules/hibernate-queries/pom.xml @@ -99,7 +99,7 @@ 8.0.32 2.6.0 2.1.214 - 6.1.7.Final + 6.3.1.Final 1.17.6 diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/util/HibernateUtil.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/util/HibernateUtil.java index ff9ccb017b..f561a33f08 100644 --- a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/util/HibernateUtil.java +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/util/HibernateUtil.java @@ -16,4 +16,11 @@ public class HibernateUtil { return session; } + public static SessionFactory getHibernateSessionFactory() { + + final SessionFactory sessionFactory = new Configuration().configure("criteria.cfg.xml").buildSessionFactory(); + + return sessionFactory; + } + } diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/view/CriteriaDefinitionApplicationView.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/view/CriteriaDefinitionApplicationView.java new file mode 100644 index 0000000000..9f32aa06e3 --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteria/view/CriteriaDefinitionApplicationView.java @@ -0,0 +1,126 @@ +package com.baeldung.hibernate.criteria.view; + +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.query.criteria.CriteriaDefinition; +import org.hibernate.query.criteria.JpaRoot; + +import com.baeldung.hibernate.criteria.model.Item; +import com.baeldung.hibernate.criteria.util.HibernateUtil; + +public class CriteriaDefinitionApplicationView { + + public CriteriaDefinitionApplicationView() { + + } + + public String[] greaterThanCriteria() { + final Session session = HibernateUtil.getHibernateSession(); + final SessionFactory sessionFactory = HibernateUtil.getHibernateSessionFactory(); + + CriteriaDefinition query = new CriteriaDefinition<>(sessionFactory, Item.class) { + { + JpaRoot message = from(Item.class); + where(gt(message.get("itemPrice"), 1000)); + } + }; + + List items = session.createSelectionQuery(query).list(); + + final String greaterThanItems[] = new String[items.size()]; + for (int i = 0; i < items.size(); i++) { + greaterThanItems[i] = items.get(i).getItemName(); + } + + session.close(); + + return greaterThanItems; + } + + public String[] lessThanCriteria() { + final Session session = HibernateUtil.getHibernateSession(); + final SessionFactory sessionFactory = HibernateUtil.getHibernateSessionFactory(); + + CriteriaDefinition query = new CriteriaDefinition<>(sessionFactory, Item.class) { + { + JpaRoot message = from(Item.class); + where(lt(message.get("itemPrice"), 1000)); + } + }; + + List items = session.createSelectionQuery(query).list(); + final String lessThanItems[] = new String[items.size()]; + for (int i = 0; i < items.size(); i++) { + lessThanItems[i] = items.get(i).getItemName(); + } + + session.close(); + + return lessThanItems; + } + + public String[] likeCriteria() { + final Session session = HibernateUtil.getHibernateSession(); + final SessionFactory sessionFactory = HibernateUtil.getHibernateSessionFactory(); + + CriteriaDefinition query = new CriteriaDefinition<>(sessionFactory, Item.class) { + { + JpaRoot item = from(Item.class); + where(like(item.get("itemName"), "%chair%")); + } + }; + + List items = session.createSelectionQuery(query).list(); + + final String likeItems[] = new String[items.size()]; + for (int i = 0; i < items.size(); i++) { + likeItems[i] = items.get(i).getItemName(); + } + session.close(); + return likeItems; + } + + public String[] likeCaseCriteria() { + final Session session = HibernateUtil.getHibernateSession(); + final SessionFactory sessionFactory = HibernateUtil.getHibernateSessionFactory(); + + CriteriaDefinition query = new CriteriaDefinition<>(sessionFactory, Item.class) { + { + JpaRoot item = from(Item.class); + where(like(lower(item.get("itemName")), "%chair%")); + } + }; + + List items = session.createSelectionQuery(query).list(); + + final String likeItems[] = new String[items.size()]; + for (int i = 0; i < items.size(); i++) { + likeItems[i] = items.get(i).getItemName(); + } + session.close(); + return likeItems; + } + + public String[] betweenCriteria() { + final Session session = HibernateUtil.getHibernateSession(); + final SessionFactory sessionFactory = HibernateUtil.getHibernateSessionFactory(); + + CriteriaDefinition query = new CriteriaDefinition<>(sessionFactory, Item.class) { + { + JpaRoot item = from(Item.class); + where(between(item.get("itemPrice"), 100, 200)); + } + }; + + List items = session.createSelectionQuery(query).list(); + + final String betweenItems[] = new String[items.size()]; + for (int i = 0; i < items.size(); i++) { + betweenItems[i] = items.get(i).getItemName(); + } + session.close(); + return betweenItems; + } +} diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java index 58d8e8628a..e9c7548c7d 100644 --- a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java @@ -4,8 +4,13 @@ package com.baeldung.hibernate.customtypes; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import org.hibernate.dialect.Dialect; +import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation; +import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; +import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; +import org.hibernate.type.spi.TypeConfiguration; import io.hypersistence.utils.hibernate.type.array.internal.AbstractArrayTypeDescriptor; @@ -49,4 +54,10 @@ public class LocalDateStringJavaDescriptor extends AbstractArrayTypeDescriptor expectedLikeList = session.createQuery("From Item where itemName like '%chair%'").list(); + final String expectedLikeItems[] = new String[expectedLikeList.size()]; + for (int i = 0; i < expectedLikeList.size(); i++) { + expectedLikeItems[i] = expectedLikeList.get(i).getItemName(); + } + session.close(); + assertArrayEquals(expectedLikeItems, criteriaDefinition.likeCriteria()); + } + + @Test + public void givenHibernateSession_whenExecutingCaseSensitiveLikeCriteriaQuery_thenExpectMatchingItems() { + final Session session = HibernateUtil.getHibernateSession(); + final List expectedChairCaseList = session.createQuery("From Item where itemName like '%Chair%'").list(); + final String expectedChairCaseItems[] = new String[expectedChairCaseList.size()]; + for (int i = 0; i < expectedChairCaseList.size(); i++) { + expectedChairCaseItems[i] = expectedChairCaseList.get(i).getItemName(); + } + session.close(); + assertArrayEquals(expectedChairCaseItems, criteriaDefinition.likeCaseCriteria()); + } + + @Test + public void givenHibernateSession_whenExecutingGreaterThanCriteriaQuery_thenExpectMatchingItems() { + final Session session = HibernateUtil.getHibernateSession(); + final List expectedGreaterThanList = session.createQuery("From Item where itemPrice>1000").list(); + final String expectedGreaterThanItems[] = new String[expectedGreaterThanList.size()]; + for (int i = 0; i < expectedGreaterThanList.size(); i++) { + expectedGreaterThanItems[i] = expectedGreaterThanList.get(i).getItemName(); + } + session.close(); + assertArrayEquals(expectedGreaterThanItems, criteriaDefinition.greaterThanCriteria()); + } + + @Test + public void givenHibernateSession_whenExecutingLessThanCriteriaQuery_thenExpectMatchingItems() { + final Session session = HibernateUtil.getHibernateSession(); + final List expectedLessList = session.createQuery("From Item where itemPrice<1000").list(); + final String expectedLessThanItems[] = new String[expectedLessList.size()]; + for (int i = 0; i < expectedLessList.size(); i++) { + expectedLessThanItems[i] = expectedLessList.get(i).getItemName(); + } + session.close(); + assertArrayEquals(expectedLessThanItems, criteriaDefinition.lessThanCriteria()); + } + + @Test + public void givenHibernateSession_whenExecutingBetweenCriteriaQuery_thenExpectMatchingItems() { + final Session session = HibernateUtil.getHibernateSession(); + final List expectedBetweenList = session.createQuery("From Item where itemPrice between 100 and 200").list(); + final String expectedPriceBetweenItems[] = new String[expectedBetweenList.size()]; + for (int i = 0; i < expectedBetweenList.size(); i++) { + expectedPriceBetweenItems[i] = expectedBetweenList.get(i).getItemName(); + } + session.close(); + assertArrayEquals(expectedPriceBetweenItems, criteriaDefinition.betweenCriteria()); + } + + +} From 7e81d666c9a10ca2bd3128f73c538f1832b46854 Mon Sep 17 00:00:00 2001 From: MohamedHelmyKassab <137485958+MohamedHelmyKassab@users.noreply.github.com> Date: Thu, 9 Nov 2023 00:08:33 +0200 Subject: [PATCH 046/107] This commit related to BAEL-7103 (#15160) This commit aims to add a test class named "ConvertingHashSetToArrayUnitTest" that provides test methods to convert HashSet to an array. --- .../ConvertingHashSetToArrayUnitTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 core-java-modules/core-java-collections-5/toarraymethod/ConvertingHashSetToArrayUnitTest.java diff --git a/core-java-modules/core-java-collections-5/toarraymethod/ConvertingHashSetToArrayUnitTest.java b/core-java-modules/core-java-collections-5/toarraymethod/ConvertingHashSetToArrayUnitTest.java new file mode 100644 index 0000000000..420c1d25e6 --- /dev/null +++ b/core-java-modules/core-java-collections-5/toarraymethod/ConvertingHashSetToArrayUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.toarraymethod; + +import org.junit.Test; + +import java.util.HashSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ConvertingHashSetToArrayUnitTest { + + @Test + public void givenStringHashSet_whenConvertedToArray_thenArrayContainsStringElements() { + HashSet stringSet = new HashSet<>(); + stringSet.add("Apple"); + stringSet.add("Banana"); + stringSet.add("Cherry"); + + // Convert the HashSet of Strings to an array of Strings + String[] stringArray = stringSet.toArray(new String[0]); + + // Test that the array is of the correct length + assertEquals(3, stringArray.length); + + for (String str : stringArray) { + assertTrue(stringSet.contains(str)); + } + } + + @Test + public void givenIntegerHashSet_whenConvertedToArray_thenArrayContainsIntegerElements() { + HashSet integerSet = new HashSet<>(); + integerSet.add(5); + integerSet.add(10); + integerSet.add(15); + + // Convert the HashSet of Integers to an array of Integers + Integer[] integerArray = integerSet.toArray(new Integer[0]); + + // Test that the array is of the correct length + assertEquals(3, integerArray.length); + + for (Integer num : integerArray) { + assertTrue(integerSet.contains(num)); + } + + assertTrue(integerSet.contains(5)); + assertTrue(integerSet.contains(10)); + assertTrue(integerSet.contains(15)); + } +} From 5b596e0c49cea6914ba563d15d116303c40670c2 Mon Sep 17 00:00:00 2001 From: Alexander Molochko Date: Wed, 8 Nov 2023 18:05:37 -0700 Subject: [PATCH 047/107] BAEL-7012: Splitting Streams in Kafka (#15029) * BAEL-7012: Splitting Streams in Kafka * Move sources to the spring-kafka module * Move sources to the spring-kafka-2 module --- spring-kafka-2/pom.xml | 2 + .../kafka/kafkasplitting/IotSensorData.java | 31 ++++++++++ .../kafkasplitting/KafkaConsumerConfig.java | 43 +++++++++++++ .../KafkaIotConsumerService.java | 28 +++++++++ .../kafkasplitting/KafkaStreamsConfig.java | 62 +++++++++++++++++++ .../SpringBootKafkaStreamsSplittingApp.java | 12 ++++ .../src/main/resources/application.properties | 4 ++ 7 files changed, 182 insertions(+) create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/IotSensorData.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaConsumerConfig.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaIotConsumerService.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaStreamsConfig.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/SpringBootKafkaStreamsSplittingApp.java diff --git a/spring-kafka-2/pom.xml b/spring-kafka-2/pom.xml index 0bca20447d..fdf7da7438 100644 --- a/spring-kafka-2/pom.xml +++ b/spring-kafka-2/pom.xml @@ -65,6 +65,8 @@ 1.16.2 + 3.0.12 + 3.6.0 1.16.2 diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/IotSensorData.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/IotSensorData.java new file mode 100644 index 0000000000..350f6911f3 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/IotSensorData.java @@ -0,0 +1,31 @@ +package com.baeldung.spring.kafka.kafkasplitting; + +public class IotSensorData { + private String sensorType; + private String value; + private String sensorId; + + public String getSensorType() { + return sensorType; + } + + public void setSensorType(String sensorType) { + this.sensorType = sensorType; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getSensorId() { + return sensorId; + } + + public void setSensorId(String sensorId) { + this.sensorId = sensorId; + } +} diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaConsumerConfig.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaConsumerConfig.java new file mode 100644 index 0000000000..70640cb582 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaConsumerConfig.java @@ -0,0 +1,43 @@ +package com.baeldung.spring.kafka.kafkasplitting; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.config.KafkaListenerContainerFactory; +import org.springframework.kafka.core.ConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.kafka.listener.ConcurrentMessageListenerContainer; +import org.springframework.kafka.support.serializer.JsonDeserializer; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +class KafkaConsumerConfig { + + @Value("${spring.kafka.consumer.group-id}") + private String groupId; + @Value("${spring.kafka.bootstrap-servers}") + private String bootstrapServers; + + @Bean + public ConsumerFactory consumerFactory() { + Map props = new HashMap<>(); + props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); + props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId); + props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class); + + return new DefaultKafkaConsumerFactory<>(props, new StringDeserializer(), new JsonDeserializer<>(IotSensorData.class)); + } + + @Bean + KafkaListenerContainerFactory> kafkaListenerContainerFactory() { + ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory()); + return factory; + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaIotConsumerService.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaIotConsumerService.java new file mode 100644 index 0000000000..bbd0c549ab --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaIotConsumerService.java @@ -0,0 +1,28 @@ +package com.baeldung.spring.kafka.kafkasplitting; + +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Service; + +@Service +public class KafkaIotConsumerService { + + @KafkaListener(topics = "iot_sensor_data") + public void consumeIotData(IotSensorData item) { + System.out.println("Consumed Message in original \"iot_sensor_data\" topic :" + item.getSensorType()); + } + + @KafkaListener(topics = "iot_sensor_data_temp") + public void consumeIotTemperatureData(IotSensorData item) { + System.out.println("Consumed Temparature data :" + item.getValue()); + } + + @KafkaListener(topics = "iot_sensor_data_hum") + public void consumeIotHumidityData(IotSensorData item) { + System.out.println("Consumed Humidity data :" + item.getValue()); + } + + @KafkaListener(topics = "iot_sensor_data_move") + public void consumeIotMovementData(IotSensorData item) { + System.out.println("Consumed Movement data :" + item.getValue()); + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaStreamsConfig.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaStreamsConfig.java new file mode 100644 index 0000000000..c4eb1501fd --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/KafkaStreamsConfig.java @@ -0,0 +1,62 @@ +package com.baeldung.spring.kafka.kafkasplitting; + +import org.apache.kafka.common.serialization.Serde; +import org.apache.kafka.common.serialization.Serdes; +import org.apache.kafka.streams.StreamsBuilder; +import org.apache.kafka.streams.kstream.Branched; +import org.apache.kafka.streams.kstream.Consumed; +import org.apache.kafka.streams.kstream.KStream; +import org.apache.kafka.streams.processor.TopicNameExtractor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.annotation.EnableKafka; +import org.springframework.kafka.annotation.EnableKafkaStreams; +import org.springframework.kafka.support.KafkaStreamBrancher; +import org.springframework.kafka.support.serializer.JsonDeserializer; +import org.springframework.kafka.support.serializer.JsonSerializer; + +@Configuration +@EnableKafka +@EnableKafkaStreams +class KafkaStreamsConfig { + @Value("${kafka.topics.iot}") + private String iotTopicName; + + @Bean + public Serde iotSerde() { + return Serdes.serdeFrom(new JsonSerializer<>(), new JsonDeserializer<>(IotSensorData.class)); + } + + @Bean + public KStream iotStream(StreamsBuilder streamsBuilder) { + KStream stream = streamsBuilder.stream(iotTopicName, Consumed.with(Serdes.String(), iotSerde())); + stream.split() + .branch((key, value) -> value.getSensorType() != null, + Branched.withConsumer(ks -> ks.to((key, value, recordContext) -> String.format("%s_%s", iotTopicName, value.getSensorType())))) + .noDefaultBranch(); + return stream; + } + + @Bean + public KStream iotBrancher(StreamsBuilder streamsBuilder) { + KStream stream = streamsBuilder.stream(iotTopicName, Consumed.with(Serdes.String(), iotSerde())); + + new KafkaStreamBrancher() + .branch((key, value) -> "temp".equals(value.getSensorType()), (ks) -> ks.to(iotTopicName + "_temp")) + .branch((key, value) -> "move".equals(value.getSensorType()), (ks) -> ks.to(iotTopicName + "_move")) + .branch((key, value) -> "hum".equals(value.getSensorType()), (ks) -> ks.to(iotTopicName + "_hum")) + .defaultBranch(ks -> ks.to(String.format("%s_unknown", iotTopicName))) + .onTopOf(stream); + + return stream; + } + + @Bean + public KStream iotTopicExtractor(StreamsBuilder streamsBuilder) { + KStream stream = streamsBuilder.stream(iotTopicName, Consumed.with(Serdes.String(), iotSerde())); + TopicNameExtractor sensorTopicExtractor = (key, value, recordContext) -> String.format("%s_%s", iotTopicName, value.getSensorType()); + stream.to(sensorTopicExtractor); + return stream; + } +} diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/SpringBootKafkaStreamsSplittingApp.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/SpringBootKafkaStreamsSplittingApp.java new file mode 100644 index 0000000000..6101eeb13d --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/kafkasplitting/SpringBootKafkaStreamsSplittingApp.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.kafka.kafkasplitting; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootKafkaStreamsSplittingApp { + public static void main(String[] args) { + SpringApplication.run(SpringBootKafkaStreamsSplittingApp.class, args); + } + +} diff --git a/spring-kafka-2/src/main/resources/application.properties b/spring-kafka-2/src/main/resources/application.properties index ed844cadf8..9111491b58 100644 --- a/spring-kafka-2/src/main/resources/application.properties +++ b/spring-kafka-2/src/main/resources/application.properties @@ -19,4 +19,8 @@ kafka.backoff.max_failure=5 # multiple listeners properties multiple-listeners.books.topic.name=books +spring.kafka.streams.application-id=baeldung-streams +spring.kafka.consumer.group-id=baeldung-group +spring.kafka.streams.properties[default.key.serde]=org.apache.kafka.common.serialization.Serdes$StringSerde +kafka.topics.iot=iot_sensor_data From f33372e091a921a22e616f50e088820693130c79 Mon Sep 17 00:00:00 2001 From: hmdrz Date: Thu, 9 Nov 2023 11:21:54 +0330 Subject: [PATCH 048/107] #BAEL-7157: add one extra method --- .../test/java/com/baeldung/testsuite/ClassOneUnitTest.java | 4 ++++ .../com/baeldung/testsuite/subpackage/ClassTwoUnitTest.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/ClassOneUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/ClassOneUnitTest.java index 4ce092796e..cfb77c8d41 100644 --- a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/ClassOneUnitTest.java +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/ClassOneUnitTest.java @@ -10,4 +10,8 @@ public class ClassOneUnitTest { Assertions.assertTrue(true); } + @Test + public void whenFalse_thenFalse() { + Assertions.assertFalse(false); + } } diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/subpackage/ClassTwoUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/subpackage/ClassTwoUnitTest.java index bb63fcda63..be5b3380c7 100644 --- a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/subpackage/ClassTwoUnitTest.java +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/subpackage/ClassTwoUnitTest.java @@ -8,4 +8,9 @@ public class ClassTwoUnitTest { public void whenTrue_thenTrue() { Assertions.assertTrue(true); } + + @Test + public void whenFalse_thenFalse() { + Assertions.assertFalse(false); + } } From b6d28c44461e31609295637e87de8e7b463652fb Mon Sep 17 00:00:00 2001 From: hmdrz Date: Thu, 9 Nov 2023 11:22:14 +0330 Subject: [PATCH 049/107] #BAEL-7157: add main test suite --- .../testsuite/suites/JUnitSelectMethodsSuite.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/suites/JUnitSelectMethodsSuite.java diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/suites/JUnitSelectMethodsSuite.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/suites/JUnitSelectMethodsSuite.java new file mode 100644 index 0000000000..e0d17dc0e4 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/testsuite/suites/JUnitSelectMethodsSuite.java @@ -0,0 +1,14 @@ +package com.baeldung.testsuite.suites; + +import com.baeldung.testsuite.ClassOneUnitTest; +import org.junit.platform.suite.api.SelectMethod; +import org.junit.platform.suite.api.Suite; +import org.junit.platform.suite.api.SuiteDisplayName; + +@Suite +@SuiteDisplayName("My Test Suite") +@SelectMethod(type = ClassOneUnitTest.class, name = "whenFalse_thenFalse") +@SelectMethod("com.baeldung.testsuite.subpackage.ClassTwoUnitTest#whenFalse_thenFalse") +public class JUnitSelectMethodsSuite { + // runs ClassOneUnitTest and ClassTwoUnitTest +} \ No newline at end of file From 75a64be865bd573134dce88a48582e44ebca7e1a Mon Sep 17 00:00:00 2001 From: hmdrz Date: Thu, 9 Nov 2023 11:22:48 +0330 Subject: [PATCH 050/107] #BAEL-7157: upgrade dependency version and add extra dependencies --- testing-modules/junit-5-advanced/pom.xml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/testing-modules/junit-5-advanced/pom.xml b/testing-modules/junit-5-advanced/pom.xml index 3ae62eac2e..411f189638 100644 --- a/testing-modules/junit-5-advanced/pom.xml +++ b/testing-modules/junit-5-advanced/pom.xml @@ -45,7 +45,18 @@ ${junit-platform.version} test - + + org.junit.platform + junit-platform-launcher + ${junit-platform.version} + test + + + org.junit.platform + junit-platform-commons + ${junit-platform.version} + test + @@ -70,7 +81,7 @@ 1.49 3.24.2 - 1.9.2 + 1.10.1 3.0.0 From 781b7fde457d67c1549ec8f12d90c0dde15b6c05 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 9 Nov 2023 15:27:46 +0530 Subject: [PATCH 051/107] JAVA-27244: Changes made removing comment from modules that are added already (#15161) --- pom.xml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index a16fabebc5..ffd39b7ea2 100644 --- a/pom.xml +++ b/pom.xml @@ -362,7 +362,7 @@ web-modules/java-lite persistence-modules/deltaspike persistence-modules/hibernate-ogm - persistence-modules/spring-data-cassandra-reactive + persistence-modules/spring-data-cassandra-reactive java-nashorn jeromq spring-ejb-modules/ejb-beans @@ -533,7 +533,7 @@ web-modules/java-lite persistence-modules/deltaspike persistence-modules/hibernate-ogm - persistence-modules/spring-data-cassandra-reactive + persistence-modules/spring-data-cassandra-reactive java-nashorn jeromq spring-ejb-modules/ejb-beans @@ -854,7 +854,7 @@ libraries-apache-commons-2 libraries-apache-commons-collections libraries-apache-commons-io - libraries-data-2 + libraries-data-2 libraries-data-io libraries-files libraries-http @@ -929,7 +929,7 @@ gcp-firebase spring-di-4 spring-kafka-2 - + libraries-llms spring-pulsar @@ -1039,14 +1039,6 @@ core-java-modules gcp-firebase - - - - - - - - spring-aop spring-aop-2 custom-pmd @@ -1138,7 +1130,7 @@ libraries-apache-commons-2 libraries-apache-commons-collections libraries-apache-commons-io - libraries-data-2 + libraries-data-2 libraries-data-io libraries-files libraries-http @@ -1212,7 +1204,7 @@ spring-actuator spring-di-4 spring-kafka-2 - + libraries-llms spring-pulsar From 4145926d9421d1652383606066a2ee84cb398652 Mon Sep 17 00:00:00 2001 From: gaepi Date: Thu, 9 Nov 2023 11:55:32 +0100 Subject: [PATCH 052/107] JAVA-27245 - renamed modules. --- .../spring-cloud-bootstrap/README.md | 2 +- .../spring-cloud-bootstrap/pom.xml | 4 ++-- .../{svc-book => zipkin-log-svc-book}/pom.xml | 4 ++-- .../bootstrap/svcbook/BookServiceApplication.java | 0 .../cloud/bootstrap/svcbook/CookieConfig.java | 0 .../spring/cloud/bootstrap/svcbook/DataLoader.java | 0 .../cloud/bootstrap/svcbook/SecurityConfig.java | 0 .../cloud/bootstrap/svcbook/SessionConfig.java | 0 .../spring/cloud/bootstrap/svcbook/book/Book.java | 0 .../bootstrap/svcbook/book/BookController.java | 0 .../svcbook/book/BookNotFoundException.java | 0 .../bootstrap/svcbook/book/BookRepository.java | 0 .../cloud/bootstrap/svcbook/book/BookService.java | 0 .../src/main/resources/bootstrap.properties | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/SpringContextLiveTest.java | 0 .../src/test/resources/bootstrap.properties | 0 .../{svc-rating => zipkin-log-svc-rating}/pom.xml | 4 ++-- .../cloud/bootstrap/svcrating/CookieConfig.java | 0 .../cloud/bootstrap/svcrating/DataLoader.java | 0 .../svcrating/RatingServiceApplication.java | 0 .../cloud/bootstrap/svcrating/SecurityConfig.java | 0 .../cloud/bootstrap/svcrating/SessionConfig.java | 0 .../cloud/bootstrap/svcrating/rating/Rating.java | 0 .../svcrating/rating/RatingCacheRepository.java | 0 .../svcrating/rating/RatingController.java | 0 .../svcrating/rating/RatingNotFoundException.java | 0 .../svcrating/rating/RatingRepository.java | 0 .../bootstrap/svcrating/rating/RatingService.java | 0 .../src/main/resources/bootstrap.properties | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/SpringContextLiveTest.java | 0 .../src/test/resources/bootstrap.properties | 0 .../.gitignore | 0 .../Dockerfile | 2 +- .../pom.xml | 4 ++-- .../backend/KubernetesBackendApplication.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../test/java/com/baeldung/SpringContextTest.java | 0 .../.gitignore | 0 .../Dockerfile | 2 +- .../pom.xml | 4 ++-- .../frontend/KubernetesFrontendApplication.java | 2 +- .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../test/java/com/baeldung/SpringContextTest.java | 0 .../object-configurations/backend-deployment.yaml | 14 +++++++------- .../object-configurations/frontend-deployment.yaml | 14 +++++++------- .../kubernetes-minikube/pom.xml | 4 ++-- 50 files changed, 30 insertions(+), 30 deletions(-) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/pom.xml (97%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/CookieConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/DataLoader.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SessionConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/Book.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookController.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookNotFoundException.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookRepository.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookService.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/resources/bootstrap.properties (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/main/resources/logback.xml (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/test/java/com/baeldung/SpringContextLiveTest.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-book => zipkin-log-svc-book}/src/test/resources/bootstrap.properties (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/pom.xml (97%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/CookieConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/DataLoader.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SessionConfig.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/Rating.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingCacheRepository.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingController.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingNotFoundException.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingRepository.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingService.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/resources/bootstrap.properties (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/main/resources/logback.xml (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/test/java/com/baeldung/SpringContextLiveTest.java (100%) rename spring-cloud-modules/spring-cloud-bootstrap/{svc-rating => zipkin-log-svc-rating}/src/test/resources/bootstrap.properties (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/.gitignore (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/Dockerfile (62%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-backend}/pom.xml (92%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/src/main/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplication.java (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/src/main/resources/application.properties (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/src/main/resources/logback.xml (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-backend}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/.gitignore (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/Dockerfile (59%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-backend => minikube-demo-frontend}/pom.xml (92%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java (95%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/src/main/resources/application.properties (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/src/main/resources/logback.xml (100%) rename spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/{demo-frontend => minikube-demo-frontend}/src/test/java/com/baeldung/SpringContextTest.java (100%) diff --git a/spring-cloud-modules/spring-cloud-bootstrap/README.md b/spring-cloud-modules/spring-cloud-bootstrap/README.md index 252058be1f..661dd7c647 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/README.md +++ b/spring-cloud-modules/spring-cloud-bootstrap/README.md @@ -21,4 +21,4 @@ This module contains articles about bootstrapping Spring Cloud applications that - git commit -m "First commit" - start the config server - start the discovery server - - start all the other servers in any order (gateway, svc-book, svc-rating, zipkin) + - start all the other servers in any order (gateway, zipkin-log-svc-book, zipkin-log-svc-rating, zipkin) diff --git a/spring-cloud-modules/spring-cloud-bootstrap/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/pom.xml index f4d4073ef1..73b07c826f 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/pom.xml @@ -19,8 +19,8 @@ discovery gateway gateway-2 - svc-book - svc-rating + zipkin-log-svc-book + zipkin-log-svc-rating customer-service order-service diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/pom.xml similarity index 97% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/pom.xml rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/pom.xml index c973968a70..2a6196b92b 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung.spring.cloud - svc-book + zipkin-log-svc-book 1.0.0-SNAPSHOT - svc-book + zipkin-log-svc-book com.baeldung diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/CookieConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/CookieConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/CookieConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/CookieConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/DataLoader.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/DataLoader.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/DataLoader.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/DataLoader.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SecurityConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SessionConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SessionConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SessionConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/SessionConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/Book.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/Book.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/Book.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/Book.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookController.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookController.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookController.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookController.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookNotFoundException.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookNotFoundException.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookNotFoundException.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookNotFoundException.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookRepository.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookRepository.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookRepository.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookRepository.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookService.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookService.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookService.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/book/BookService.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/resources/bootstrap.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/resources/bootstrap.properties rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/resources/bootstrap.properties diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/resources/logback.xml similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/main/resources/logback.xml rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/main/resources/logback.xml diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/test/java/com/baeldung/SpringContextLiveTest.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/test/java/com/baeldung/SpringContextLiveTest.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/test/java/com/baeldung/SpringContextLiveTest.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/test/resources/bootstrap.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-book/src/test/resources/bootstrap.properties diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/pom.xml similarity index 97% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/pom.xml rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/pom.xml index 29ebb4c4bc..54572eeea2 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung.spring.cloud - svc-rating + zipkin-log-svc-rating 1.0.0-SNAPSHOT - svc-rating + zipkin-log-svc-rating com.baeldung diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/CookieConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/CookieConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/CookieConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/CookieConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/DataLoader.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/DataLoader.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/DataLoader.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/DataLoader.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SessionConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SessionConfig.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SessionConfig.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SessionConfig.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/Rating.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/Rating.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/Rating.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/Rating.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingCacheRepository.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingCacheRepository.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingCacheRepository.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingCacheRepository.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingController.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingController.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingController.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingController.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingNotFoundException.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingNotFoundException.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingNotFoundException.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingNotFoundException.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingRepository.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingRepository.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingRepository.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingRepository.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingService.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingService.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingService.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/rating/RatingService.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/resources/bootstrap.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/resources/bootstrap.properties rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/resources/bootstrap.properties diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/resources/logback.xml similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/main/resources/logback.xml rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/main/resources/logback.xml diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/test/java/com/baeldung/SpringContextLiveTest.java similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/test/java/com/baeldung/SpringContextLiveTest.java rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/test/java/com/baeldung/SpringContextLiveTest.java diff --git a/spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties b/spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/test/resources/bootstrap.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties rename to spring-cloud-modules/spring-cloud-bootstrap/zipkin-log-svc-rating/src/test/resources/bootstrap.properties diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/.gitignore b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/.gitignore similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/.gitignore rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/.gitignore diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/Dockerfile b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/Dockerfile similarity index 62% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/Dockerfile rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/Dockerfile index a0a9d57662..fad9c11a73 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/Dockerfile +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:8-jdk-alpine VOLUME /tmp -COPY target/demo-backend-1.0-SNAPSHOT.jar app.jar +COPY target/minikube-demo-backend-1.0-SNAPSHOT.jar app.jar ENV JAVA_OPTS="" ENTRYPOINT exec java -jar /app.jar --debug \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/pom.xml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/pom.xml similarity index 92% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/pom.xml rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/pom.xml index 85eb944b27..c08c6a5a9d 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/pom.xml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/pom.xml @@ -3,8 +3,8 @@ 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 - demo-frontend - demo-frontend + minikube-demo-backend + minikube-demo-backend com.baeldung.spring.cloud diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplication.java b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplication.java similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplication.java rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/java/com/baeldung/spring/cloud/kubernetes/backend/KubernetesBackendApplication.java diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/resources/application.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/resources/application.properties rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/resources/application.properties diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/resources/logback.xml similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/main/resources/logback.xml rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/main/resources/logback.xml diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/test/java/com/baeldung/SpringContextTest.java b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/src/test/java/com/baeldung/SpringContextTest.java rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-backend/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/.gitignore b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/.gitignore similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/.gitignore rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/.gitignore diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/Dockerfile b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/Dockerfile similarity index 59% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/Dockerfile rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/Dockerfile index 69adb03a17..207114b1b5 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/Dockerfile +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:8-jdk-alpine VOLUME /tmp -COPY target/demo-frontend-1.0-SNAPSHOT.jar app.jar +COPY target/minikube-demo-frontend-1.0-SNAPSHOT.jar app.jar ENV JAVA_OPTS="" ENTRYPOINT exec java -jar /app.jar \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/pom.xml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/pom.xml similarity index 92% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/pom.xml rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/pom.xml index 2b3f849145..8140807606 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-backend/pom.xml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/pom.xml @@ -3,8 +3,8 @@ 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 - demo-backend - demo-backend + minikube-demo-frontend + minikube-demo-frontend com.baeldung.spring.cloud diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java similarity index 95% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java index 635a79e8bb..d76fcdfd5d 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/java/com/baeldung/spring/cloud/kubernetes/frontend/KubernetesFrontendApplication.java @@ -22,7 +22,7 @@ public class KubernetesFrontendApplication { RestTemplate restTemplate = new RestTemplate(); String resourceUrl - = "http://demo-backend:8080"; + = "http://minikube-demo-backend:8080"; ResponseEntity response = restTemplate.getForEntity(resourceUrl, String.class); return "Message from backend is: " + response.getBody(); diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/resources/application.properties similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/resources/application.properties rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/resources/application.properties diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/resources/logback.xml similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/main/resources/logback.xml rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/main/resources/logback.xml diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/test/java/com/baeldung/SpringContextTest.java b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/demo-frontend/src/test/java/com/baeldung/SpringContextTest.java rename to spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/minikube-demo-frontend/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/backend-deployment.yaml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/backend-deployment.yaml index a7e26a6ec5..bcfa80cd7f 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/backend-deployment.yaml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/backend-deployment.yaml @@ -1,10 +1,10 @@ kind: Service apiVersion: v1 metadata: - name: demo-backend + name: minikube-demo-backend spec: selector: - app: demo-backend + app: minikube-demo-backend tier: backend ports: - protocol: TCP @@ -14,22 +14,22 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: - name: demo-backend + name: dminikube-demo-backend spec: selector: matchLabels: - app: demo-backend + app: minikube-demo-backend tier: backend replicas: 3 template: metadata: labels: - app: demo-backend + app: minikube-demo-backend tier: backend spec: containers: - - name: demo-backend - image: demo-backend:latest + - name: minikube-demo-backend + image: minikube-demo-backend:latest imagePullPolicy: Never ports: - containerPort: 8080 diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/frontend-deployment.yaml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/frontend-deployment.yaml index bf44dce21c..f96c7a1a9c 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/frontend-deployment.yaml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/object-configurations/frontend-deployment.yaml @@ -1,10 +1,10 @@ kind: Service apiVersion: v1 metadata: - name: demo-frontend + name: minikube-demo-frontend spec: selector: - app: demo-frontend + app: minikube-demo-frontend ports: - protocol: TCP port: 8081 @@ -14,20 +14,20 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: - name: demo-frontend + name: minikube-demo-frontend spec: selector: matchLabels: - app: demo-frontend + app: minikube-demo-frontend replicas: 3 template: metadata: labels: - app: demo-frontend + app: minikube-demo-frontend spec: containers: - - name: demo-frontend - image: demo-frontend:latest + - name: minikube-demo-frontend + image: minikube-demo-frontend:latest imagePullPolicy: Never ports: - containerPort: 8081 diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/pom.xml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/pom.xml index b778ee1b57..1c7456d007 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/pom.xml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-minikube/pom.xml @@ -14,8 +14,8 @@ - demo-backend - demo-frontend + minikube-demo-backend + minikube-demo-frontend \ No newline at end of file From d1685c42bd9f2692f16dd5f86f837d4c9714f051 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 9 Nov 2023 16:47:34 +0530 Subject: [PATCH 053/107] JAVA-26001_D_M: Fix formatting of POMs for modules D to M (#14958) --- google-auto-project/pom.xml | 1 - json-modules/json-2/pom.xml | 4 ++-- .../jacoco-coverage-services-example/pom.xml | 7 +++---- maven-modules/jacoco-coverage-aggregation/pom.xml | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/google-auto-project/pom.xml b/google-auto-project/pom.xml index 034fea5aad..175e0c20c6 100644 --- a/google-auto-project/pom.xml +++ b/google-auto-project/pom.xml @@ -8,7 +8,6 @@ google-auto-project pom - com.baeldung parent-modules diff --git a/json-modules/json-2/pom.xml b/json-modules/json-2/pom.xml index 6cca576fb1..b9a75e8aff 100644 --- a/json-modules/json-2/pom.xml +++ b/json-modules/json-2/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 json-2 0.0.1-SNAPSHOT diff --git a/maven-modules/jacoco-coverage-aggregation/jacoco-coverage-services-example/pom.xml b/maven-modules/jacoco-coverage-aggregation/jacoco-coverage-services-example/pom.xml index 2c06694b46..223689f8ff 100644 --- a/maven-modules/jacoco-coverage-aggregation/jacoco-coverage-services-example/pom.xml +++ b/maven-modules/jacoco-coverage-aggregation/jacoco-coverage-services-example/pom.xml @@ -13,8 +13,7 @@ jacoco-coverage-aggregation 1.0 - - + org.springframework @@ -28,7 +27,7 @@ test - + @@ -43,7 +42,7 @@ - + 5.9.2 6.0.11 diff --git a/maven-modules/jacoco-coverage-aggregation/pom.xml b/maven-modules/jacoco-coverage-aggregation/pom.xml index 70243973e8..6d1aab3c3d 100644 --- a/maven-modules/jacoco-coverage-aggregation/pom.xml +++ b/maven-modules/jacoco-coverage-aggregation/pom.xml @@ -21,7 +21,7 @@ jacoco-coverage-controllers-example jacoco-coverage-aggregate-report - + From 3fbd2eaab9561c4fa34d3b982c349e66c24de632 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 9 Nov 2023 16:48:02 +0530 Subject: [PATCH 054/107] JAVA-26001_Q_Z: Fix formatting of POMs for modules Q to Z (#14960) --- pom.xml | 4 +- spring-6-rsocket/pom.xml | 7 +- spring-aop-2/pom.xml | 94 +++++++++---------- .../spring-boot-3-testcontainers/pom.xml | 5 +- .../spring-boot-graalvm-docker/pom.xml | 61 ++++++------ .../spring-boot-jasypt/pom.xml | 3 +- .../spring-boot-ssl-bundles/pom.xml | 4 +- .../spring-boot-telegram/pom.xml | 4 +- .../spring-5-reactive/pom.xml | 0 .../spring-reactive-data-couchbase/pom.xml | 4 +- testing-modules/junit-5-basics-2/pom.xml | 9 +- 11 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 spring-reactive-modules/spring-5-reactive/pom.xml diff --git a/pom.xml b/pom.xml index ffd39b7ea2..bb5a0c9e7b 100644 --- a/pom.xml +++ b/pom.xml @@ -344,7 +344,7 @@ core-java-modules/core-java-security core-java-modules/core-java-lang core-java-modules/core-java-lang-math-3 - + core-java-modules/core-java-streams-2 @@ -517,7 +517,7 @@ core-java-modules/core-java-security core-java-modules/core-java-lang core-java-modules/core-java-lang-math-3 - + core-java-modules/core-java-streams-2 diff --git a/spring-6-rsocket/pom.xml b/spring-6-rsocket/pom.xml index 0f9e63bc7e..7f88df01e2 100644 --- a/spring-6-rsocket/pom.xml +++ b/spring-6-rsocket/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 com.bealdung spring-6-rsocket @@ -16,7 +16,6 @@ - org.springframework.boot spring-boot-starter-rsocket @@ -66,9 +65,11 @@ + 3.1.3 1.4.11 2.0.9 + diff --git a/spring-aop-2/pom.xml b/spring-aop-2/pom.xml index 206e1d7d7c..f1257369e0 100644 --- a/spring-aop-2/pom.xml +++ b/spring-aop-2/pom.xml @@ -74,54 +74,54 @@ - - compile-time-weaving + + compile-time-weaving - - - org.springframework - spring-aspects - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - com.baeldung.selfinvocation.CompileTimeWeavingIntegrationTest - - - - - org.codehaus.mojo - aspectj-maven-plugin - ${aspectj-plugin.version} - - ${java.version} - ${java.version} - ${java.version} - ignore - UTF-8 - - - org.springframework - spring-aspects - - - - - - - compile - - - - - - - + + + org.springframework + spring-aspects + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + com.baeldung.selfinvocation.CompileTimeWeavingIntegrationTest + + + + + org.codehaus.mojo + aspectj-maven-plugin + ${aspectj-plugin.version} + + ${java.version} + ${java.version} + ${java.version} + ignore + UTF-8 + + + org.springframework + spring-aspects + + + + + + + compile + + + + + + + load-time-weaving diff --git a/spring-boot-modules/spring-boot-3-testcontainers/pom.xml b/spring-boot-modules/spring-boot-3-testcontainers/pom.xml index 173fb8795c..d24da58742 100644 --- a/spring-boot-modules/spring-boot-3-testcontainers/pom.xml +++ b/spring-boot-modules/spring-boot-3-testcontainers/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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-3-testcontainers 0.0.1-SNAPSHOT @@ -16,7 +16,6 @@ - org.springframework.boot spring-boot-starter diff --git a/spring-boot-modules/spring-boot-graalvm-docker/pom.xml b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml index a3a1b148c2..253e8fceb6 100644 --- a/spring-boot-modules/spring-boot-graalvm-docker/pom.xml +++ b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml @@ -1,41 +1,44 @@ - + 4.0.0 - - - com.baeldung - parent-boot-3 - 0.0.1-SNAPSHOT - ../../parent-boot-3 - - com.baeldung spring-boot-graalvm-docker 1.0.0 spring-boot-graalvm-docker Spring Boot GrralVM with Docker + + + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 + + - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + - - - org.graalvm.buildtools - native-maven-plugin - - - org.springframework.boot - spring-boot-maven-plugin - - + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/spring-boot-modules/spring-boot-jasypt/pom.xml b/spring-boot-modules/spring-boot-jasypt/pom.xml index 70bbe35319..0f9ad72b64 100644 --- a/spring-boot-modules/spring-boot-jasypt/pom.xml +++ b/spring-boot-modules/spring-boot-jasypt/pom.xml @@ -27,7 +27,7 @@ com.github.ulisesbocchio - jasypt-spring-boot-starter + jasypt-spring-boot-starter ${jasypt.version} @@ -49,4 +49,5 @@ 3.0.5 + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml index 770d8c2f01..1f4e58f21f 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml +++ b/spring-boot-modules/spring-boot-ssl-bundles/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 spring-boot-ssl-bundles spring-boot-ssl-bundles diff --git a/spring-boot-modules/spring-boot-telegram/pom.xml b/spring-boot-modules/spring-boot-telegram/pom.xml index 67fdf197f8..9077e90400 100644 --- a/spring-boot-modules/spring-boot-telegram/pom.xml +++ b/spring-boot-modules/spring-boot-telegram/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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baelding spring-boot-telegram diff --git a/spring-reactive-modules/spring-5-reactive/pom.xml b/spring-reactive-modules/spring-5-reactive/pom.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml b/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml index a7481d8aca..2ac8ad19ac 100644 --- a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml +++ b/spring-reactive-modules/spring-reactive-data-couchbase/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 spring-reactive-data-couchbase spring-reactive-data-couchbase diff --git a/testing-modules/junit-5-basics-2/pom.xml b/testing-modules/junit-5-basics-2/pom.xml index 85b6c707fb..b430161380 100644 --- a/testing-modules/junit-5-basics-2/pom.xml +++ b/testing-modules/junit-5-basics-2/pom.xml @@ -1,16 +1,16 @@ + 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 + junit-5-basics-2 + com.baeldung parent-modules 1.0.0-SNAPSHOT - junit-5-basics-2 - commons-cli @@ -30,6 +30,7 @@ test + From bf5328c3970a508bbbb47257e5ea222363b27fa8 Mon Sep 17 00:00:00 2001 From: timis1 Date: Thu, 9 Nov 2023 14:39:49 +0200 Subject: [PATCH 055/107] JAVA-27237 Review log statements for projects | Week 44 | Manually Created (conti-1) --- .../src/main/resources/logback.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml index d944288ca4..1533b49c06 100644 --- a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml +++ b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/src/main/resources/logback.xml @@ -8,7 +8,9 @@ - + + + From 4cf46ce71908be7608b8a707feaca7e49f0213d3 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Thu, 9 Nov 2023 19:19:22 +0530 Subject: [PATCH 056/107] JAVA-27190 Upgrade hibernate validator version --- .../custom-validations-opeanpi-codegen/pom.xml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml index b57a014a8f..573b132467 100644 --- a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml @@ -27,15 +27,10 @@ test - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} - - javax.validation - validation-api - ${validation-api.version} - org.openapitools openapi-generator @@ -97,8 +92,7 @@ 3.0.0 2.17.1 1.7.0 - 6.0.10.Final - 2.0.1.Final + 8.0.1.Final 3.3.4 2.10.0.pr3 5.1.0 From 52197768be4b9d9bf325a46eee5de4fde180984a Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Thu, 9 Nov 2023 19:23:42 +0530 Subject: [PATCH 057/107] JAVA-27190 Remove code overriding parent-boot-version of hibernate-validator --- .../custom-validations-opeanpi-codegen/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml index 573b132467..95d3239b96 100644 --- a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml @@ -26,11 +26,6 @@ spring-boot-starter-test test - - org.hibernate.validator - hibernate-validator - ${hibernate-validator.version} - org.openapitools openapi-generator @@ -92,7 +87,6 @@ 3.0.0 2.17.1 1.7.0 - 8.0.1.Final 3.3.4 2.10.0.pr3 5.1.0 From 499ed4bbbd64a3e778a908f1a218df18cb974479 Mon Sep 17 00:00:00 2001 From: Paul Greer Date: Thu, 9 Nov 2023 21:52:12 +0000 Subject: [PATCH 058/107] BAEL-6943: Difference between String and StringBuffer in Java (#14815) * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Delete core-java-modules/core-java-lang-6/src/main/java/com/baeldung/intposneg directory * Delete core-java-modules/core-java-lang-6/src/test/java/com/baeldung/intposneg directory * Add files via upload * Delete core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/stringtoint/intposneg directory * Add files via upload * Add files via upload * Delete core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/intposneg directory * Delete core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/intposneg directory * Add files via upload * Add files via upload * Delete core-java-modules/core-java-lang-6/src/main/java/com/baeldung/diffstringstringbuffer directory * Delete core-java-modules/core-java-lang-6/src/test/java/com/baeldung/diffstringstringbuffer directory * Delete core-java-modules/core-java-string-apis-2/src/main/java/com/baeldung/diffstringstringbuffer directory * Delete core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer directory * Add files via upload * Add files via upload --- .../diffstringstringbuffer/MemoryAddress.java | 33 +++++++++++++++++++ .../StringBufferUnitTest.java | 18 ++++++++++ .../StringUnitTest.java | 29 ++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 core-java-modules/core-java-string-apis-2/src/main/java/com/baeldung/diffstringstringbuffer/MemoryAddress.java create mode 100644 core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringBufferUnitTest.java create mode 100644 core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringUnitTest.java diff --git a/core-java-modules/core-java-string-apis-2/src/main/java/com/baeldung/diffstringstringbuffer/MemoryAddress.java b/core-java-modules/core-java-string-apis-2/src/main/java/com/baeldung/diffstringstringbuffer/MemoryAddress.java new file mode 100644 index 0000000000..42a4d9d4b4 --- /dev/null +++ b/core-java-modules/core-java-string-apis-2/src/main/java/com/baeldung/diffstringstringbuffer/MemoryAddress.java @@ -0,0 +1,33 @@ +package com.baeldung.diffstringstringbuffer; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +public class MemoryAddress { + public long getMemoryAddress(Object object) { + Object[] arrayOfObject = new Object[]{object}; + Unsafe unsafe = null; + try { + Field field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe) field.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + assert unsafe != null; + long arrayBaseOffset = unsafe.arrayBaseOffset(Object[].class); + int addressSize = unsafe.addressSize(); + long objectAddress; + if (addressSize == 4) { + objectAddress = unsafe.getInt(arrayOfObject, arrayBaseOffset); + } else { + if (addressSize == 8) { + objectAddress = unsafe.getLong(arrayOfObject, arrayBaseOffset); + } else { + throw new Error("Error: Size not supported: " + addressSize); + } + } + return objectAddress; + } +} diff --git a/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringBufferUnitTest.java b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringBufferUnitTest.java new file mode 100644 index 0000000000..adbe69b65e --- /dev/null +++ b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringBufferUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.diffstringstringbuffer; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class StringBufferUnitTest { + @Test + void whenStringBufferVariableIsReassigned_thenVariableRetainsOriginalMemoryAddress() { + MemoryAddress memoryAddress = new MemoryAddress(); + StringBuffer stringBuffer = new StringBuffer("DownTown"); + long address1 = memoryAddress.getMemoryAddress(stringBuffer); + stringBuffer.insert(0, "Coder"); + assertEquals(stringBuffer.toString(), "CoderDownTown"); + long address2 = memoryAddress.getMemoryAddress(stringBuffer); + assertEquals(address1, address2); + } +} diff --git a/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringUnitTest.java b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringUnitTest.java new file mode 100644 index 0000000000..bf1fcfeaf1 --- /dev/null +++ b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/diffstringstringbuffer/StringUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.diffstringstringbuffer; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.Test; + +public class StringUnitTest { + @Test + void whenStringVariableIsReassigned_thenVariableGetsNewMemoryAddress() { + MemoryAddress memoryAddress = new MemoryAddress(); + String s1 = "DownTown"; + long address1 = memoryAddress.getMemoryAddress(s1); + s1 = "Coder"; + long address2 = memoryAddress.getMemoryAddress(s1); + assertNotEquals(address1, address2); + } + + @Test + void whenStringsAreIncludedInAStringBuffer_thenThoseStringsRemainImmutable() { + String s1 = "TopCat"; + StringBuffer stringBuffer = new StringBuffer("DownTown"); + stringBuffer.append(s1); + stringBuffer.reverse(); + assertNotEquals(s1, "taCpoT"); + stringBuffer.delete(0, 3); + assertEquals(s1, "TopCat"); + } +} From 0b0db24ebb0e028008722d698716e9d0a17452b8 Mon Sep 17 00:00:00 2001 From: psevestre Date: Thu, 9 Nov 2023 18:56:11 -0300 Subject: [PATCH 059/107] [BAEL-7044] Shared Memory Between Two JVMs (#15162) * [BAEL-4849] Article code * [BAEL-4968] Article code * [BAEL-4968] Article code * [BAEL-4968] Article code * [BAEL-4968] Remove extra comments * [BAEL-5258] Article Code * [BAEL-2765] PKCE Support for Secret Clients * [BAEL-5698] Article code * [BAEL-5698] Article code * [BAEL-5905] Initial code * [BAEL-5905] Article code * [BAEL-5905] Relocate article code to new module * [BAEL-6275] PostgreSQL NOTIFY/LISTEN * [BAEL-6275] Minor correction * BAEL-6138 * [BAEL-6138] WIP - LiveTest * [BAEL-6138] Tutorial Code * [BAEL-6138] Tutorial Code * [BAEL-6694] Article Code * [BAEL-7044] Tutorial code --------- Co-authored-by: Philippe Sevestre --- .../core-java-sun/shared-mem-test1.bat | 8 ++ .../core-java-sun/shared-mem-test2.bat | 10 ++ .../com/baeldung/sharedmem/ConsumerApp.java | 94 ++++++++++++++ .../sharedmem/ConsumerAppWithSpinLock.java | 119 ++++++++++++++++++ .../com/baeldung/sharedmem/ProducerApp.java | 89 +++++++++++++ .../sharedmem/ProducerAppWithSpinLock.java | 117 +++++++++++++++++ .../java/com/baeldung/sharedmem/SpinLock.java | 43 +++++++ 7 files changed, 480 insertions(+) create mode 100644 core-java-modules/core-java-sun/shared-mem-test1.bat create mode 100644 core-java-modules/core-java-sun/shared-mem-test2.bat create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerApp.java create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerAppWithSpinLock.java create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerApp.java create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerAppWithSpinLock.java create mode 100644 core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/SpinLock.java diff --git a/core-java-modules/core-java-sun/shared-mem-test1.bat b/core-java-modules/core-java-sun/shared-mem-test1.bat new file mode 100644 index 0000000000..148c51eb36 --- /dev/null +++ b/core-java-modules/core-java-sun/shared-mem-test1.bat @@ -0,0 +1,8 @@ +@rem This bat file starts the consumer and producer (more or less) at the same time +cd target\classes +rem start java --add-opens java.base/java.nio=ALL-UNNAMED com.baeldung.sharedmem.ProducerApp c:\lixo\sharedmem.bin 65536 +rem start java --add-opens java.base/java.nio=ALL-UNNAMED com.baeldung.sharedmem.ConsumerApp c:\lixo\sharedmem.bin 65536 +start %JAVA_HOME%\bin\java com.baeldung.sharedmem.ProducerApp c:\lixo\sharedmem.bin 65536 +start %JAVA_HOME%\bin\java com.baeldung.sharedmem.ConsumerApp c:\lixo\sharedmem.bin 65536 +cd .. +cd .. diff --git a/core-java-modules/core-java-sun/shared-mem-test2.bat b/core-java-modules/core-java-sun/shared-mem-test2.bat new file mode 100644 index 0000000000..7a7f8f7caa --- /dev/null +++ b/core-java-modules/core-java-sun/shared-mem-test2.bat @@ -0,0 +1,10 @@ +@rem This bat file starts the consumer and producer (more or less) at the same time +del target\sharedmem.bin +echo "" > target\sharedmem.bin +cd target\classes +rem start java --add-opens java.base/java.nio=ALL-UNNAMED com.baeldung.sharedmem.ProducerAppWithSpinLock ..\sharedmem.bin 65536 +rem start java --add-opens java.base/java.nio=ALL-UNNAMED com.baeldung.sharedmem.ConsumerAppWithSpinLock ..\sharedmem.bin 65536 +start %JAVA_HOME%\bin\java com.baeldung.sharedmem.ProducerAppWithSpinLock ..\sharedmem.bin 65536 +start %JAVA_HOME%\bin\java com.baeldung.sharedmem.ConsumerAppWithSpinLock ..\sharedmem.bin 65536 +cd .. +cd .. diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerApp.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerApp.java new file mode 100644 index 0000000000..1fbc02bee9 --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerApp.java @@ -0,0 +1,94 @@ +package com.baeldung.sharedmem; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Random; + +public class ConsumerApp { + + public static void main(String[] args) throws Exception { + + MessageDigest digest = MessageDigest.getInstance("SHA1"); + digest.digest(new byte[256]); + byte[] dummy = digest.digest(); + int hashLen = dummy.length; + + System.out.println("Starting consumer iterations..."); + + long size = Long.parseLong(args[1]); + MappedByteBuffer shm = createSharedMemory(args[0], size + hashLen); + long start = System.currentTimeMillis(); + long iterations = 0; + int capacity = shm.capacity(); + + long matchCount = 0; + long mismatchCount = 0; + byte[] expectedHash = new byte[hashLen]; + + while (System.currentTimeMillis() - start < 30_000) { + + for (int i = 0; i < capacity - hashLen; i++) { + byte value = shm.get(i); + digest.update(value); + } + + byte[] hash = digest.digest(); + shm.position(capacity-hashLen); + shm.get(expectedHash); + + if (Arrays.equals(hash, expectedHash)) { + matchCount++; + } else { + mismatchCount++; + } + + iterations++; + } + + System.out.printf("%d iterations run. matches=%d, mismatches=%d\n", iterations, matchCount, mismatchCount); + System.out.println("Press to exit"); + System.console() + .readLine(); + } + + private static MappedByteBuffer createSharedMemory(String path, long size) { + + try (FileChannel fc = (FileChannel) Files.newByteChannel( + new File(path).toPath(), + EnumSet.of( + StandardOpenOption.CREATE, + StandardOpenOption.SPARSE, + StandardOpenOption.WRITE, + StandardOpenOption.READ))) { + return fc.map(FileChannel.MapMode.READ_WRITE, 0, size); + + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } + + private static long getBufferAddress(MappedByteBuffer shm) { + try { + Class cls = shm.getClass(); + Method maddr = cls.getMethod("address"); + maddr.setAccessible(true); + Long addr = (Long) maddr.invoke(shm); + if (addr == null) { + throw new RuntimeException("Unable to retrieve buffer's address"); + } + return addr; + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerAppWithSpinLock.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerAppWithSpinLock.java new file mode 100644 index 0000000000..fa91edda40 --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ConsumerAppWithSpinLock.java @@ -0,0 +1,119 @@ +package com.baeldung.sharedmem; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Random; + +public class ConsumerAppWithSpinLock { + + public static void main(String[] args) { + try { + // Small wait to ensure the Producer gets the first round. Otherwise the hash will be invalid + Thread.sleep(1000); + run(args); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + System.console() + .printf("Press to continue"); + System.console() + .readLine(); + } + } + + private static void run(String args[]) throws Exception { + + MessageDigest digest = MessageDigest.getInstance("SHA1"); + digest.digest(new byte[256]); + byte[] dummy = digest.digest(); + int hashLen = dummy.length; + + long size = Long.parseLong(args[1]); + MappedByteBuffer shm = createSharedMemory(args[0], size + hashLen); + long addr = getBufferAddress(shm); + + System.out.printf("Buffer address: 0x%08x\n", addr); + + Random rnd = new Random(); + + long start = System.currentTimeMillis(); + long iterations = 0; + int capacity = shm.capacity(); + System.out.println("Starting consumer iterations..."); + + long matchCount = 0; + long mismatchCount = 0; + byte[] expectedHash = new byte[hashLen]; + SpinLock lock = new SpinLock(addr); + + while (System.currentTimeMillis() - start < 30_000) { + + if (!lock.tryLock(5_000)) { + throw new RuntimeException("Unable to acquire lock"); + } + + try { + for (int i = 4; i < capacity - hashLen; i++) { + byte value = shm.get(i); + digest.update(value); + } + + byte[] hash = digest.digest(); + shm.position(capacity-hashLen); + shm.get(expectedHash); + + if (Arrays.equals(hash, expectedHash)) { + matchCount++; + } else { + mismatchCount++; + } + + iterations++; + } finally { + lock.unlock(); + } + } + + System.out.printf("%d iteractions run. matches=%d, mismatches=%d\n", iterations, matchCount, mismatchCount); + } + + private static MappedByteBuffer createSharedMemory(String path, long size) { + + try (FileChannel fc = (FileChannel) Files.newByteChannel( + new File(path).toPath(), + EnumSet.of( + StandardOpenOption.CREATE, + StandardOpenOption.SPARSE, + StandardOpenOption.WRITE, + StandardOpenOption.READ))) { + return fc.map(FileChannel.MapMode.READ_WRITE, 0, size); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } + + private static long getBufferAddress(MappedByteBuffer shm) { + try { + Class cls = shm.getClass(); + Method maddr = cls.getMethod("address"); + maddr.setAccessible(true); + Long addr = (Long) maddr.invoke(shm); + if (addr == null) { + throw new RuntimeException("Unable to retrieve buffer's address"); + } + return addr; + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerApp.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerApp.java new file mode 100644 index 0000000000..ab7ca4d859 --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerApp.java @@ -0,0 +1,89 @@ +package com.baeldung.sharedmem; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.EnumSet; +import java.util.Random; + +public class ProducerApp { + + + public static void main(String[] args) throws Exception { + + MessageDigest digest = MessageDigest.getInstance("SHA1"); + digest.digest(new byte[256]); + byte[] dummy = digest.digest(); + int hashLen = dummy.length; + + + long size = Long.parseLong(args[1]); + MappedByteBuffer shm = createSharedMemory(args[0], size + hashLen); + + System.out.println("Starting producer iterations..."); + + long start = System.currentTimeMillis(); + long iterations = 0; + int capacity = shm.capacity(); + Random rnd = new Random(); + + while(System.currentTimeMillis() - start < 30000) { + + for (int i = 0; i < capacity - hashLen; i++) { + byte value = (byte) (rnd.nextInt(256) & 0x00ff); + digest.update(value); + shm.put(i, value); + } + + // Write hash at the end + byte[] hash = digest.digest(); + shm.position(capacity - hashLen); + shm.put(hash); + iterations++; + } + + System.out.printf("%d iterations run\n", iterations); + System.out.println("Press to exit"); + System.console().readLine(); + + } + + private static long getBufferAddress(MappedByteBuffer shm) { + try { + Class cls = shm.getClass(); + Method maddr = cls.getMethod("address"); + maddr.setAccessible(true); + Long addr = (Long) maddr.invoke(shm); + if ( addr == null ) { + throw new RuntimeException("Unable to retrieve buffer's address"); + } + return addr; + } + catch( NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + + private static MappedByteBuffer createSharedMemory(String path, long size) { + + try (FileChannel fc = (FileChannel)Files.newByteChannel(new File(path).toPath(), + EnumSet.of( + StandardOpenOption.CREATE, + StandardOpenOption.SPARSE, + StandardOpenOption.WRITE, + StandardOpenOption.READ))) { + + return fc.map(FileChannel.MapMode.READ_WRITE, 0, size); + } + catch( IOException ioe) { + throw new RuntimeException(ioe); + } + } + +} diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerAppWithSpinLock.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerAppWithSpinLock.java new file mode 100644 index 0000000000..619955eb2d --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/ProducerAppWithSpinLock.java @@ -0,0 +1,117 @@ +package com.baeldung.sharedmem; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.EnumSet; +import java.util.Random; + +public class ProducerAppWithSpinLock { + + public static void main(String[] args) { + try { + run(args); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + System.console() + .printf("Press to continue"); + System.console() + .readLine(); + } + } + + + public static void run(String[] args) throws Exception { + + MessageDigest digest = MessageDigest.getInstance("SHA1"); + digest.digest(new byte[256]); + byte[] dummy = digest.digest(); + int hashLen = dummy.length; + + + long size = Long.parseLong(args[1]); + MappedByteBuffer shm = createSharedMemory(args[0], size + hashLen); + + // Cleanup lock area + shm.putInt(0,0); + + long addr = getBufferAddress(shm); + System.out.printf("Buffer address: 0x%08x\n",addr); + Random rnd = new Random(); + + long start = System.currentTimeMillis(); + long iterations = 0; + int capacity = shm.capacity(); + System.out.println("Starting producer iterations..."); + SpinLock lock = new SpinLock(addr); + while(System.currentTimeMillis() - start < 30000) { + + if(!lock.tryLock(5000)) { + throw new RuntimeException("Unable to acquire lock"); + } + + try { + // Skip the first 4 bytes, as they're used by the lock + for (int i = 4; i < capacity - hashLen; i++) { + byte value = (byte) (rnd.nextInt(256) & 0x00ff); + digest.update(value); + shm.put(i, value); + } + + // Write hash at the end + byte[] hash = digest.digest(); + shm.position(capacity-hashLen); + shm.put(hash); + iterations++; + } + finally { + lock.unlock(); + } + } + + System.out.printf("%d iterations run\n", iterations); + + } + + private static long getBufferAddress(MappedByteBuffer shm) { + try { + Class cls = shm.getClass(); + Method maddr = cls.getMethod("address"); + maddr.setAccessible(true); + Long addr = (Long) maddr.invoke(shm); + if ( addr == null ) { + throw new RuntimeException("Unable to retrieve buffer's address"); + } + return addr; + } + catch( NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + + private static MappedByteBuffer createSharedMemory(String path, long size) { + + try (FileChannel fc = (FileChannel)Files.newByteChannel(new File(path).toPath(), + EnumSet.of( + StandardOpenOption.CREATE, + StandardOpenOption.SPARSE, + StandardOpenOption.WRITE, + StandardOpenOption.READ))) { + + return fc.map(FileChannel.MapMode.READ_WRITE, 0, size); + + } + catch( IOException ioe) { + throw new RuntimeException(ioe); + } + + } + +} diff --git a/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/SpinLock.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/SpinLock.java new file mode 100644 index 0000000000..145ac1e121 --- /dev/null +++ b/core-java-modules/core-java-sun/src/main/java/com/baeldung/sharedmem/SpinLock.java @@ -0,0 +1,43 @@ +package com.baeldung.sharedmem; + +//import sun.misc.Unsafe; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +public class SpinLock { + private static final Unsafe unsafe; + + static { + try { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + unsafe = (Unsafe) f.get(null); + } + catch(NoSuchFieldException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + + private final long addr; + + public SpinLock(long addr) { + this.addr = addr; + } + + public boolean tryLock(long maxWait) { + long deadline = System.currentTimeMillis() + maxWait; + while(System.currentTimeMillis() < deadline ) { + if ( unsafe.compareAndSwapInt(null,addr,0,1)) { + return true; + } + } + return false; + } + + public void unlock() { + unsafe.putInt(addr,0); + } + +} From 63679af8caa320ea547baa97a1d0c1e94fe69773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Cardo=C5=9F?= <106325528+sodrac@users.noreply.github.com> Date: Fri, 10 Nov 2023 00:01:10 +0200 Subject: [PATCH 060/107] BAEL-6874 update test code for article (#15164) * BAEL-6819 convert from int to Long in Java * BAEL-6819 update package name * BAEL-6874 test code for article * BAEL-6874 rename test class * BAEL-6874 update test code for article * BAEL-6874 update test code for article --- .../GenericNumbersComparatorUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java index 0fcc0f3453..0b0295c2db 100644 --- a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/genericnumberscomparator/GenericNumbersComparatorUnitTest.java @@ -78,7 +78,7 @@ class GenericNumbersComparatorUnitTest { assertEquals(true, isEqual.test(5, 5.0)); } - private boolean someCondition = true; + private boolean someCondition; Function dynamicFunction = someCondition ? Number::doubleValue : Number::intValue; Comparator dynamicComparator = (num1, num2) -> ((Comparable) dynamicFunction.apply(num1)).compareTo(dynamicFunction.apply(num2)); From 1f609d3aafe8149885b06db927912d10e01a0362 Mon Sep 17 00:00:00 2001 From: Dmytro Budym <46810751+dbudim@users.noreply.github.com> Date: Fri, 10 Nov 2023 04:08:28 +0100 Subject: [PATCH 061/107] =?UTF-8?q?Code=20examples=20for=20article:=20Swit?= =?UTF-8?q?ching=20Between=20Frames=20Using=20Selenium=20We=E2=80=A6=20(#1?= =?UTF-8?q?4973)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Code examples for article: Switching Between Frames Using Selenium WebDriver in Java * continuation indent 2 * moved to selenium-2 package --- .../selenium/iframe/IframeManualTest.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 testing-modules/selenium-2/src/test/java/com/baeldung/selenium/iframe/IframeManualTest.java diff --git a/testing-modules/selenium-2/src/test/java/com/baeldung/selenium/iframe/IframeManualTest.java b/testing-modules/selenium-2/src/test/java/com/baeldung/selenium/iframe/IframeManualTest.java new file mode 100644 index 0000000000..bc617a4777 --- /dev/null +++ b/testing-modules/selenium-2/src/test/java/com/baeldung/selenium/iframe/IframeManualTest.java @@ -0,0 +1,120 @@ +package com.baeldung.selenium.iframe; + +import io.github.bonigarcia.wdm.WebDriverManager; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.time.Duration; + + +public class IframeManualTest { + + private WebDriver driver; + private static final int TIMEOUT = 10; + + @BeforeMethod + public void init() { + WebDriverManager.chromedriver().setup(); + driver = new ChromeDriver(); + } + + @Test + public void whenSwitchToFrameUsingWebElement_thenSwitched() { + openDemoPage(); + WebElement iframeElement = driver.findElement(By.cssSelector("#myFrame2")); + + new WebDriverWait(driver, Duration.ofSeconds(10)) + .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(iframeElement)); + waitForTextInFrame(); + } + + @Test + public void whenSwitchToFrameUsingName_thenSwitched() { + openDemoPage(); + new WebDriverWait(driver, Duration.ofSeconds(10)) + .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frameName2")); + waitForTextInFrame(); + } + + @Test + public void whenSwitchToFrameUsingId_thenSwitched() { + openDemoPage(); + new WebDriverWait(driver, Duration.ofSeconds(10)) + .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("myFrame2")); + waitForTextInFrame(); + } + + @Test + public void whenSwitchToInnerFrameFromOuter_thenSwitched() { + openPageWithNestedFrames(); + switchToNestedFrame(); + waitForLinkInNestedFrame(); + } + + @Test + public void whenSwitchToParentFrame_thenSwitched() { + openPageWithNestedFrames(); + switchToNestedFrame(); + driver.switchTo().parentFrame(); + waitForTextInParentFrame(); + } + + @Test + public void whenSwitchToDefaultContent_thenSwitched() { + openPageWithNestedFrames(); + switchToNestedFrame(); + driver.switchTo().defaultContent(); + waitForElementInDefaultContent(); + } + + @AfterMethod + public void tearDown() { + driver.quit(); + } + + + private void openDemoPage() { + driver.get("https://seleniumbase.io/demo_page"); + new WebDriverWait(driver, Duration.ofSeconds(10)) + .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#myForm"))); + } + + private void openPageWithNestedFrames() { + driver.get("https://seleniumbase.io/w3schools/iframes"); + new WebDriverWait(driver, Duration.ofSeconds(10)) + .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#runbtn"))); + } + + private void switchToNestedFrame() { + driver.switchTo().frame("iframeResult"); + WebElement innerFrame = driver.findElement(By.cssSelector("[src='./demo_iframe.htm']")); + driver.switchTo().frame(innerFrame); + } + + private void waitForTextInFrame() { + new WebDriverWait(driver, Duration.ofSeconds(TIMEOUT)) + .until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h4"), "iFrame Text")); + } + + private void waitForLinkInNestedFrame() { + new WebDriverWait(driver, Duration.ofSeconds(TIMEOUT)) + .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[href='https://seleniumbase.io/w3schools/iframes.html']"))); + } + + private void waitForTextInParentFrame() { + new WebDriverWait(driver, Duration.ofSeconds(TIMEOUT)) + .until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h2"), "HTML Iframes (nested iframes)")); + } + + private void waitForElementInDefaultContent() { + new WebDriverWait(driver, Duration.ofSeconds(TIMEOUT)) + .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#runbtn"))); + } +} From 0ce0a647a112de2828e049762affbede65132b85 Mon Sep 17 00:00:00 2001 From: Ulisses Lima Date: Fri, 10 Nov 2023 04:10:03 -0300 Subject: [PATCH 062/107] MongoDbHashMapIntegrationTest - Changing to LiveTest (#15013) * changing to LiveTest Prevent integration tests from failing after spring boot upgrade. * Update MongoDbHashMapLiveTest.java Including docs. * Update MongoDbHashMapLiveTest.java removing instructions from atlas search. --- ...nTest.java => MongoDbHashMapLiveTest.java} | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) rename persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/{MongoDbHashMapIntegrationTest.java => MongoDbHashMapLiveTest.java} (76%) diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapLiveTest.java similarity index 76% rename from persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapIntegrationTest.java rename to persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapLiveTest.java index bbf425f277..29588df8a9 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/hashmap/MongoDbHashMapLiveTest.java @@ -13,21 +13,35 @@ import java.util.Map; import java.util.Set; import org.bson.Document; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; import com.mongodb.BasicDBObject; -@SpringBootTest +/** + * Steps to run locally: + * - Open embedded.properties and include: + * - spring.data.mongodb.uri= + * - spring.data.mongodb.database=sample_mflix + * + * Pre-requisites: + * - Following the steps to import the sample_mflix database + */ @DirtiesContext +@RunWith(SpringRunner.class) @TestPropertySource("/embedded.properties") -class MongoDbHashMapIntegrationTest { +@SpringBootTest(classes = SpringBootHashMapApplication.class) +class MongoDbHashMapLiveTest { + private static final String COLLECTION_NAME = "hashmap-test-collection"; private static final Map MAP = new HashMap<>(); private static final Set> MAP_SET = new HashSet<>(); @@ -52,17 +66,22 @@ class MongoDbHashMapIntegrationTest { MAP_SET.add(MAP); MAP_SET.add(otherMap); } + + @AfterEach + void destroy() { + mongo.dropCollection(COLLECTION_NAME); + } @Test void whenUsingMap_thenInsertSucceeds() { - Map saved = mongo.insert(MAP, "map-collection"); + Map saved = mongo.insert(MAP, COLLECTION_NAME); assertHasMongoId(saved); } @Test void whenMapSet_thenInsertSucceeds() { - Collection> saved = mongo.insert(MAP_SET, "map-set"); + Collection> saved = mongo.insert(MAP_SET, COLLECTION_NAME); saved.forEach(this::assertHasMongoId); assertEquals(2, saved.size()); @@ -72,7 +91,7 @@ class MongoDbHashMapIntegrationTest { void givenMap_whenDocumentConstructed_thenInsertSucceeds() { Document document = new Document(MAP); - Document saved = mongo.insert(document, "doc-collection"); + Document saved = mongo.insert(document, COLLECTION_NAME); assertHasMongoId(saved); } @@ -81,7 +100,7 @@ class MongoDbHashMapIntegrationTest { void givenMap_whenBasicDbObjectConstructed_thenInsertSucceeds() { BasicDBObject dbObject = new BasicDBObject(MAP); - BasicDBObject saved = mongo.insert(dbObject, "db-collection"); + BasicDBObject saved = mongo.insert(dbObject, COLLECTION_NAME); assertHasMongoId(saved); } @@ -114,7 +133,7 @@ class MongoDbHashMapIntegrationTest { set.add(document); }, Set::addAll); - Collection saved = mongo.insert(docs, "custom-set"); + Collection saved = mongo.insert(docs, COLLECTION_NAME); saved.forEach(this::assertHasMongoId); } } From ac0fa6ff7883a610297aa7eb5561536a5e0e079f Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:46:51 +0800 Subject: [PATCH 063/107] Update README.md [skip ci] --- core-java-modules/core-java-date-operations-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-date-operations-3/README.md b/core-java-modules/core-java-date-operations-3/README.md index 9d16d1f71c..48b68189fa 100644 --- a/core-java-modules/core-java-date-operations-3/README.md +++ b/core-java-modules/core-java-date-operations-3/README.md @@ -11,4 +11,5 @@ This module contains articles about date operations in Java. - [Getting Yesterday’s Date in Java](https://www.baeldung.com/java-find-yesterdays-date) - [How to Get the Start and End Dates of a Year Using Java](https://www.baeldung.com/java-date-year-start-end) - [Convert Between Java LocalDate and Epoch](https://www.baeldung.com/java-localdate-epoch) +- [Get First Date of Current Month in Java](https://www.baeldung.com/java-current-month-start-date) - [[<-- Prev]](/core-java-modules/core-java-date-operations-2) From 732c2255b294a38182581f016c31d524fa43f8eb Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:22:40 +0800 Subject: [PATCH 064/107] Update README.md [skip ci] --- spring-boot-modules/spring-boot-mvc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-mvc/README.md b/spring-boot-modules/spring-boot-mvc/README.md index f45feb6169..9257d6eba1 100644 --- a/spring-boot-modules/spring-boot-mvc/README.md +++ b/spring-boot-modules/spring-boot-mvc/README.md @@ -10,4 +10,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Using Spring ResponseEntity to Manipulate the HTTP Response](https://www.baeldung.com/spring-response-entity) - [The @ServletComponentScan Annotation in Spring Boot](https://www.baeldung.com/spring-servletcomponentscan) - [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization) +- [Localized Validation Messages in REST](https://www.baeldung.com/rest-localized-validation-messages) - More articles: [[next -->]](/spring-boot-modules/spring-boot-mvc-2) From 77c7186351207bedb51336cce9d47cb06a93c693 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:27:58 +0800 Subject: [PATCH 065/107] Update README.md [skip ci] --- spring-boot-modules/spring-boot-3-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-3-2/README.md b/spring-boot-modules/spring-boot-3-2/README.md index c176de2310..27f9281725 100644 --- a/spring-boot-modules/spring-boot-3-2/README.md +++ b/spring-boot-modules/spring-boot-3-2/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [Spring Boot 3.1’s ConnectionDetails Abstraction](https://www.baeldung.com/spring-boot-3-1-connectiondetails-abstraction) +- [@ConditionalOnThreading Annotation Spring](https://www.baeldung.com/spring-conditionalonthreading) From a2ad229e4e901972a6b8d7ca0b94b9f1837c4b3c Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:37:26 +0800 Subject: [PATCH 066/107] Update README.md [skip ci] --- core-java-modules/core-java-collections-maps-7/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md index 5599187cd8..84cc94ad3c 100644 --- a/core-java-modules/core-java-collections-maps-7/README.md +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [Difference Between putIfAbsent() and computeIfAbsent() in Java’s Map](https://www.baeldung.com/java-map-putifabsent-computeifabsent) - [How to Write Hashmap to CSV File](https://www.baeldung.com/java-write-hashmap-csv) +- [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair) From 9109481ecbcfcb4afc6b970debb02d3d2b5dbc9f Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:51:11 +0000 Subject: [PATCH 067/107] =?UTF-8?q?[JAVA-26045]=20Upgraded=20spring-boot-t?= =?UTF-8?q?esting=20module=20to=20spring-boot=203=20ver=E2=80=A6=20(#14990?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-boot-modules/spring-boot-testing/pom.xml | 13 +++++++++---- .../boot/configurationproperties/MailServer.java | 10 +++++----- .../configuration/RedisProperties.java | 2 +- .../java/com/baeldung/boot/testing/Employee.java | 12 ++++++------ .../src/main/resources/application.properties | 4 ++-- .../exclude/ExcludeAutoConfig1IntegrationTest.java | 2 +- .../exclude/ExcludeAutoConfig2IntegrationTest.java | 2 +- .../exclude/ExcludeAutoConfig3IntegrationTest.java | 2 +- .../exclude/ExcludeAutoConfig4IntegrationTest.java | 2 +- .../boot/autoconfig/AutoConfigIntegrationTest.java | 2 +- .../PropertyValidationUnitTest.java | 4 ++-- .../boot/embeddedRedis/TestRedisConfiguration.java | 4 ++-- .../src/test/resources/application.properties | 4 ++-- 13 files changed, 34 insertions(+), 29 deletions(-) diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index 257260fc3f..23277d11f3 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -9,9 +9,10 @@ This is simple boot application for demonstrating testing features. - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -67,6 +68,11 @@ ${embedded-redis.version} test + + io.rest-assured + rest-assured + test + @@ -122,7 +128,6 @@ 2.4-M1-groovy-4.0 3.0.0 0.7.2 - 2.5.0 2.17.1 diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java index e23b30759b..3f5ea64d24 100644 --- a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java @@ -2,11 +2,11 @@ package com.baeldung.boot.configurationproperties; import java.util.Map; -import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/embeddedRedis/configuration/RedisProperties.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/embeddedRedis/configuration/RedisProperties.java index 76f2e1bbfe..4e06548d79 100644 --- a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/embeddedRedis/configuration/RedisProperties.java +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/embeddedRedis/configuration/RedisProperties.java @@ -8,7 +8,7 @@ public class RedisProperties { private final int redisPort; private final String redisHost; - public RedisProperties(@Value("${spring.redis.port}") final int redisPort, @Value("${spring.redis.host}") final String redisHost) { + public RedisProperties(@Value("${spring.data.redis.port}") final int redisPort, @Value("${spring.data.redis.host}") final String redisHost) { this.redisPort = redisPort; this.redisHost = redisHost; } diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/testing/Employee.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/testing/Employee.java index 2921ecc609..cf68c45793 100644 --- a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/testing/Employee.java +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/boot/testing/Employee.java @@ -1,11 +1,11 @@ package com.baeldung.boot.testing; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.validation.constraints.Size; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.Size; import java.util.Date; @Entity diff --git a/spring-boot-modules/spring-boot-testing/src/main/resources/application.properties b/spring-boot-modules/spring-boot-testing/src/main/resources/application.properties index 70cae370a4..e3fe989efd 100644 --- a/spring-boot-modules/spring-boot-testing/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-testing/src/main/resources/application.properties @@ -1,6 +1,6 @@ # embedded redis -spring.redis.host= localhost -spring.redis.port= 6379 +spring.data.redis.host= localhost +spring.data.redis.port= 6379 # security spring.security.user.name=john diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig1IntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig1IntegrationTest.java index 2ca0c74901..a8a322df44 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig1IntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig1IntegrationTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import org.junit.runner.RunWith; 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.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig2IntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig2IntegrationTest.java index c0bd6570a1..6a9e157827 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig2IntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig2IntegrationTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import org.junit.runner.RunWith; 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.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig3IntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig3IntegrationTest.java index 1642d4b932..9d4d9759d6 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig3IntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig3IntegrationTest.java @@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; 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.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig4IntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig4IntegrationTest.java index 1aa453348b..f28929fbef 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig4IntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/autoconfig/exclude/ExcludeAutoConfig4IntegrationTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import org.junit.runner.RunWith; 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.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/autoconfig/AutoConfigIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/autoconfig/AutoConfigIntegrationTest.java index 44a02c0c80..447d174fb5 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/autoconfig/AutoConfigIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/autoconfig/AutoConfigIntegrationTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import org.junit.runner.RunWith; 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.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java index 939471dd67..5e70bcb45f 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java @@ -2,8 +2,8 @@ package com.baeldung.boot.configurationproperties; import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.validation.Validation; -import javax.validation.Validator; +import jakarta.validation.Validation; +import jakarta.validation.Validator; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java index c265d99c9b..10e5d56857 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java @@ -4,8 +4,8 @@ import com.baeldung.boot.embeddedRedis.configuration.RedisProperties; import org.springframework.boot.test.context.TestConfiguration; import redis.embedded.RedisServer; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; @TestConfiguration public class TestRedisConfiguration { diff --git a/spring-boot-modules/spring-boot-testing/src/test/resources/application.properties b/spring-boot-modules/spring-boot-testing/src/test/resources/application.properties index 1810c7b1eb..bc31991329 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/resources/application.properties +++ b/spring-boot-modules/spring-boot-testing/src/test/resources/application.properties @@ -1,6 +1,6 @@ #embedded redis -spring.redis.host= localhost -spring.redis.port= 6370 +spring.data.redis.host= localhost +spring.data.redis.port= 6370 # security spring.security.user.name=john spring.security.user.password=123 From 277001771c776c3f5c97d421339edf127ae4383e Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:06:56 +0800 Subject: [PATCH 068/107] Update README.md [skip ci] --- core-java-modules/core-java-jndi/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-jndi/README.md b/core-java-modules/core-java-jndi/README.md index 9c6f489841..cdb1b34ca9 100644 --- a/core-java-modules/core-java-jndi/README.md +++ b/core-java-modules/core-java-jndi/README.md @@ -4,3 +4,4 @@ - [Java Naming and Directory Interface Overview](https://www.baeldung.com/jndi) - [LDAP Authentication Using Pure Java](https://www.baeldung.com/java-ldap-auth) - [Testing LDAP Connections With Java](https://www.baeldung.com/java-test-ldap-connections) +- [JNDI – What Is java:comp/env?](https://www.baeldung.com/java-jndi-comp-env) From c7883a6d5cd680bcc39cb23cfc924bb23a7ad03e Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:10:20 +0800 Subject: [PATCH 069/107] Update README.md [skip ci] --- core-java-modules/core-java-documentation/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-documentation/README.md b/core-java-modules/core-java-documentation/README.md index 972e76c165..9fa48dc09e 100644 --- a/core-java-modules/core-java-documentation/README.md +++ b/core-java-modules/core-java-documentation/README.md @@ -4,3 +4,4 @@ - [Introduction to Javadoc](http://www.baeldung.com/javadoc) - [Code Snippets in Java API Documentation](https://www.baeldung.com/java-doc-code-snippets) +- [How to Document Generic Type Parameters in Javadoc](https://www.baeldung.com/java-javadoc-generic-type-parameters) From 2e330d6f34016e25e451e97df3cc190a6c52e565 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:12:41 +0800 Subject: [PATCH 070/107] Update README.md [skip ci] --- core-java-modules/core-java-records/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-records/README.md b/core-java-modules/core-java-records/README.md index 86d3579c76..7b4df6f15c 100644 --- a/core-java-modules/core-java-records/README.md +++ b/core-java-modules/core-java-records/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [Overriding hashCode() And equals() For Records](https://www.baeldung.com/java-override-hashcode-equals-records) +- [Optional as a Record Parameter in Java](https://www.baeldung.com/java-record-optional-param) From 4c87707c9057af9dc58a4443065a245c743c44e6 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:16:16 +0800 Subject: [PATCH 071/107] Update README.md [skip ci] --- core-java-modules/core-java-string-operations-7/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-operations-7/README.md b/core-java-modules/core-java-string-operations-7/README.md index 6c4fab384b..28e2dccd39 100644 --- a/core-java-modules/core-java-string-operations-7/README.md +++ b/core-java-modules/core-java-string-operations-7/README.md @@ -2,3 +2,4 @@ ### Relevant Articles: - [How to Center Text Output in Java](https://www.baeldung.com/java-center-text-output) - [Capitalize the First Letter of Each Word in a String](https://www.baeldung.com/java-string-initial-capital-letter-every-word) +- [Check if a String Contains Only Unicode Letters](https://www.baeldung.com/java-string-all-unicode-characters) From 7c1065b494a05299addb9f0ada8fdba786ac91e4 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:15:28 +0000 Subject: [PATCH 072/107] [JAVA-26439] Moved code related to "Guide to Stream.reduce()" to ebook module (#15170) --- .../streamreduce/application/Application.java | 62 ------------------- .../streamreduce/entities/Rating.java | 39 ------------ .../streamreduce/entities/Review.java | 28 --------- .../baeldung/streamreduce/entities/User.java | 30 --------- .../streamreduce/utilities/NumberUtils.java | 52 ---------------- .../streams/reduce/entities/User.java | 7 ++- .../reduce}/StreamReduceManualTest.java | 15 +++-- 7 files changed, 15 insertions(+), 218 deletions(-) delete mode 100644 core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java delete mode 100644 core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Rating.java delete mode 100644 core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Review.java delete mode 100644 core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java delete mode 100644 core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java rename core-java-modules/{core-java-8/src/test/java/com/baeldung/streamreduce/tests => core-java-streams-simple/src/test/java/com/baeldung/streams/reduce}/StreamReduceManualTest.java (95%) diff --git a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java deleted file mode 100644 index 00fc45ccae..0000000000 --- a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.baeldung.streamreduce.application; - -import com.baeldung.streamreduce.entities.User; -import com.baeldung.streamreduce.utilities.NumberUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Application { - - public static void main(String[] args) { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - int result1 = numbers.stream().reduce(0, (a, b) -> a + b); - System.out.println(result1); - - int result2 = numbers.stream().reduce(0, Integer::sum); - System.out.println(result2); - - List letters = Arrays.asList("a", "b", "c", "d", "e"); - String result3 = letters.stream().reduce("", (a, b) -> a + b); - System.out.println(result3); - - String result4 = letters.stream().reduce("", String::concat); - System.out.println(result4); - - String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase()); - System.out.println(result5); - - List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); - int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - System.out.println(result6); - - String result7 = letters.parallelStream().reduce("", String::concat); - System.out.println(result7); - - int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - System.out.println(result8); - - List userList = new ArrayList<>(); - for (int i = 0; i <= 1000000; i++) { - userList.add(new User("John" + i, i)); - } - - long t1 = System.currentTimeMillis(); - int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long t2 = System.currentTimeMillis(); - System.out.println(result9); - System.out.println("Sequential stream time: " + (t2 - t1) + "ms"); - - long t3 = System.currentTimeMillis(); - int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long t4 = System.currentTimeMillis(); - System.out.println(result10); - System.out.println("Parallel stream time: " + (t4 - t3) + "ms"); - - int result11 = NumberUtils.divideListElements(numbers, 1); - System.out.println(result11); - - int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0); - System.out.println(result12); - } -} diff --git a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Rating.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Rating.java deleted file mode 100644 index c4d0276256..0000000000 --- a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Rating.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.streamreduce.entities; - -import java.util.ArrayList; -import java.util.List; - -public class Rating { - - double points; - List reviews = new ArrayList<>(); - - public Rating() {} - - public void add(Review review) { - reviews.add(review); - computeRating(); - } - - private double computeRating() { - double totalPoints = reviews.stream().map(Review::getPoints).reduce(0, Integer::sum); - this.points = totalPoints / reviews.size(); - return this.points; - } - - public static Rating average(Rating r1, Rating r2) { - Rating combined = new Rating(); - combined.reviews = new ArrayList<>(r1.reviews); - combined.reviews.addAll(r2.reviews); - combined.computeRating(); - return combined; - } - - public double getPoints() { - return points; - } - - public List getReviews() { - return reviews; - } -} diff --git a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Review.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Review.java deleted file mode 100644 index 03cde8a9c8..0000000000 --- a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/Review.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.streamreduce.entities; - -public class Review { - - int points; - String review; - - public Review(int points, String review) { - this.points = points; - this.review = review; - } - - public int getPoints() { - return points; - } - - public void setPoints(int points) { - this.points = points; - } - - public String getReview() { - return review; - } - - public void setReview(String review) { - this.review = review; - } -} diff --git a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java deleted file mode 100644 index 20c12d7920..0000000000 --- a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.streamreduce.entities; - -public class User { - - private final String name; - private final int age; - private final Rating rating = new Rating(); - - public User(String name, int age) { - this.name = name; - this.age = age; - } - - public String getName() { - return name; - } - - public int getAge() { - return age; - } - - public Rating getRating() { - return rating; - } - - @Override - public String toString() { - return "User{" + "name=" + name + ", age=" + age + '}'; - } -} diff --git a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java deleted file mode 100644 index a2325cc701..0000000000 --- a/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.streamreduce.utilities; - -import java.util.List; -import java.util.function.BiFunction; -import java.util.logging.Level; -import java.util.logging.Logger; - -public abstract class NumberUtils { - - private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName()); - - public static int divideListElements(List values, Integer divider) { - return values.stream() - .reduce(0, (a, b) -> { - try { - return a / divider + b / divider; - } catch (ArithmeticException e) { - LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); - } - return 0; - }); - } - - public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) { - return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider)); - } - - public static int divideListElementsWithApplyFunctionMethod(List values, int divider) { - BiFunction division = (a, b) -> a / b; - return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider)); - } - - private static int divide(int value, int factor) { - int result = 0; - try { - result = value / factor; - } catch (ArithmeticException e) { - LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); - } - return result; - } - - private static int applyFunction(BiFunction function, int a, int b) { - try { - return function.apply(a, b); - } - catch(Exception e) { - LOGGER.log(Level.INFO, "Exception occurred!"); - } - return 0; - } -} diff --git a/core-java-modules/core-java-streams-simple/src/main/java/com/baeldung/streams/reduce/entities/User.java b/core-java-modules/core-java-streams-simple/src/main/java/com/baeldung/streams/reduce/entities/User.java index 610bd93b22..07c627005a 100644 --- a/core-java-modules/core-java-streams-simple/src/main/java/com/baeldung/streams/reduce/entities/User.java +++ b/core-java-modules/core-java-streams-simple/src/main/java/com/baeldung/streams/reduce/entities/User.java @@ -4,6 +4,7 @@ public class User { private final String name; private final int age; + private final Rating rating = new Rating(); public User(String name, int age) { this.name = name; @@ -17,7 +18,11 @@ public class User { public int getAge() { return age; } - + + public Rating getRating() { + return rating; + } + @Override public String toString() { return "User{" + "name=" + name + ", age=" + age + '}'; diff --git a/core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java b/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/reduce/StreamReduceManualTest.java similarity index 95% rename from core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java rename to core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/reduce/StreamReduceManualTest.java index 602bdd069e..2931384c94 100644 --- a/core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java +++ b/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/reduce/StreamReduceManualTest.java @@ -1,15 +1,18 @@ -package com.baeldung.streamreduce.tests; +package com.baeldung.streams.reduce; + +import static org.assertj.core.api.Assertions.assertThat; -import com.baeldung.streamreduce.entities.Rating; -import com.baeldung.streamreduce.entities.Review; -import com.baeldung.streamreduce.entities.User; -import com.baeldung.streamreduce.utilities.NumberUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; +import com.baeldung.streams.reduce.entities.Rating; +import com.baeldung.streams.reduce.entities.Review; +import com.baeldung.streams.reduce.entities.User; +import com.baeldung.streams.reduce.utilities.NumberUtils; + public class StreamReduceManualTest { @Test From 75828dbf491f828d41ba87e40461e0f566f38d62 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:29:30 +0800 Subject: [PATCH 073/107] Update README.md [skip ci] --- core-java-modules/core-java-collections-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-5/README.md b/core-java-modules/core-java-collections-5/README.md index 1939e5ca3f..4869158d2b 100644 --- a/core-java-modules/core-java-collections-5/README.md +++ b/core-java-modules/core-java-collections-5/README.md @@ -8,4 +8,5 @@ - [Difference Between Arrays.sort() and Collections.sort()](https://www.baeldung.com/java-arrays-collections-sort-methods) - [Skipping the First Iteration in Java](https://www.baeldung.com/java-skip-first-iteration) - [Remove Elements From a Queue Using Loop](https://www.baeldung.com/java-remove-elements-queue) +- [Intro to Vector Class in Java](https://www.baeldung.com/java-vector-guide) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-4) From 373a0cc89552d42db973e41bf75166643e360c0b Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:33:19 +0800 Subject: [PATCH 074/107] Update README.md [skip ci] --- reactor-core/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/reactor-core/README.md b/reactor-core/README.md index dccf1fa85c..96355ad703 100644 --- a/reactor-core/README.md +++ b/reactor-core/README.md @@ -13,3 +13,4 @@ This module contains articles about Reactor Core. - [Handling Exceptions in Project Reactor](https://www.baeldung.com/reactor-exceptions) - [Difference Between Flux.create and Flux.generate](https://www.baeldung.com/java-flux-create-generate) - [Difference Between Flux and Mono](https://www.baeldung.com/java-reactor-flux-vs-mono) +- [Working With MathFlux](https://www.baeldung.com/java-reactor-mathflux) From bb31624bb418edc1de9b99e67e25466d09a2b5f9 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:43:24 +0800 Subject: [PATCH 075/107] Update README.md [skip ci] --- core-java-modules/core-java-collections-maps-7/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md index 84cc94ad3c..2e1531050e 100644 --- a/core-java-modules/core-java-collections-maps-7/README.md +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -2,3 +2,4 @@ - [Difference Between putIfAbsent() and computeIfAbsent() in Java’s Map](https://www.baeldung.com/java-map-putifabsent-computeifabsent) - [How to Write Hashmap to CSV File](https://www.baeldung.com/java-write-hashmap-csv) - [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair) +- [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file) From 2c26effb6418f05b56dab0fc8c4a3d08714f2ea0 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:49:53 +0800 Subject: [PATCH 076/107] Update README.md [skip ci] --- core-java-modules/core-java-8-datetime-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-8-datetime-2/README.md b/core-java-modules/core-java-8-datetime-2/README.md index ac1e1ca81f..462a4be6f1 100644 --- a/core-java-modules/core-java-8-datetime-2/README.md +++ b/core-java-modules/core-java-8-datetime-2/README.md @@ -6,4 +6,5 @@ - [How Many Days Are There in a Particular Month of a Given Year?](https://www.baeldung.com/days-particular-month-given-year) - [Difference Between Instant and LocalDateTime](https://www.baeldung.com/java-instant-vs-localdatetime) - [Add Minutes to a Time String in Java](https://www.baeldung.com/java-string-time-add-mins) +- [Round the Date in Java](https://www.baeldung.com/java-round-the-date) - [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1) From d6638d328fd53d2ea1caddf767adbe461bf89416 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 07:57:45 +0800 Subject: [PATCH 077/107] Update README.md [skip ci] --- jersey/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jersey/README.md b/jersey/README.md index aa5a6a3b28..24e39f02a2 100644 --- a/jersey/README.md +++ b/jersey/README.md @@ -12,3 +12,4 @@ This module contains articles about Jersey. - [Add a Header to a Jersey SSE Client Request](https://www.baeldung.com/jersey-sse-client-request-headers) - [Exception Handling With Jersey](https://www.baeldung.com/java-exception-handling-jersey) - [@FormDataParam vs. @FormParam in Jersey](https://www.baeldung.com/jersey-formdataparam-vs-formparam) +- [Add a List as Query Parameter in Jersey](https://www.baeldung.com/java-jersey-list-query-param) From 4e5f7adc81c748340b02d24f351b24fb15284b9f Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:10:55 +0800 Subject: [PATCH 078/107] Update README.md [skip ci] --- core-java-modules/core-java-string-apis-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-apis-2/README.md b/core-java-modules/core-java-string-apis-2/README.md index 38bfb70ef1..57106b7151 100644 --- a/core-java-modules/core-java-string-apis-2/README.md +++ b/core-java-modules/core-java-string-apis-2/README.md @@ -6,4 +6,5 @@ This module contains articles about string APIs. - [Retain Only Digits and Decimal Separator in String](https://www.baeldung.com/java-string-retain-digits-decimal) - [Difference Between null and Empty String in Java](https://www.baeldung.com/java-string-null-vs-empty) - [Guide to Java String Pool](https://www.baeldung.com/java-string-pool) -- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting) \ No newline at end of file +- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting) +- [Compare StringBuilder Objects in Java](https://www.baeldung.com/java-stringbuilder-objects-comparison) From 3d8d1ad9044b88604fbb961290816ec675ce588d Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:16:39 +0800 Subject: [PATCH 079/107] Update README.md [skip ci] --- core-java-modules/core-java-streams-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-streams-5/README.md b/core-java-modules/core-java-streams-5/README.md index 629d52f0a9..82a13a1eb6 100644 --- a/core-java-modules/core-java-streams-5/README.md +++ b/core-java-modules/core-java-streams-5/README.md @@ -5,3 +5,4 @@ - [Streams vs. Loops in Java](https://www.baeldung.com/java-streams-vs-loops) - [Partition a Stream in Java](https://www.baeldung.com/java-partition-stream) - [Taking Every N-th Element from Finite and Infinite Streams in Java](https://www.baeldung.com/java-nth-element-finite-infinite-streams) +- [Modifying Objects Within Stream While Iterating](https://www.baeldung.com/java-stream-modify-objects-during-iteration) From c523d5b2019d1b7116c2182ff52da50c7825c486 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:21:22 +0800 Subject: [PATCH 080/107] Update README.md [skip ci] --- core-java-modules/core-java-streams-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-streams-5/README.md b/core-java-modules/core-java-streams-5/README.md index 82a13a1eb6..64bc4e6b7a 100644 --- a/core-java-modules/core-java-streams-5/README.md +++ b/core-java-modules/core-java-streams-5/README.md @@ -6,3 +6,4 @@ - [Partition a Stream in Java](https://www.baeldung.com/java-partition-stream) - [Taking Every N-th Element from Finite and Infinite Streams in Java](https://www.baeldung.com/java-nth-element-finite-infinite-streams) - [Modifying Objects Within Stream While Iterating](https://www.baeldung.com/java-stream-modify-objects-during-iteration) +- [Convert a Stream into a Map or Multimap in Java](https://www.baeldung.com/java-convert-stream-map-multimap) From 12fa2a39612a2c840d6262190e6e29767775ed2a Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:27:08 +0800 Subject: [PATCH 081/107] Update README.md [skip ci] --- core-java-modules/core-java-date-operations-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-date-operations-3/README.md b/core-java-modules/core-java-date-operations-3/README.md index 48b68189fa..d8c321deab 100644 --- a/core-java-modules/core-java-date-operations-3/README.md +++ b/core-java-modules/core-java-date-operations-3/README.md @@ -12,4 +12,5 @@ This module contains articles about date operations in Java. - [How to Get the Start and End Dates of a Year Using Java](https://www.baeldung.com/java-date-year-start-end) - [Convert Between Java LocalDate and Epoch](https://www.baeldung.com/java-localdate-epoch) - [Get First Date of Current Month in Java](https://www.baeldung.com/java-current-month-start-date) +- [Time Conversions Using TimeUnit](https://www.baeldung.com/java-timeunit-conversion) - [[<-- Prev]](/core-java-modules/core-java-date-operations-2) From a6bed1817696343168204da250d308b200be4279 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 11 Nov 2023 08:31:26 +0800 Subject: [PATCH 082/107] Update README.md [skip ci] --- core-java-modules/core-java-string-apis-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-apis-2/README.md b/core-java-modules/core-java-string-apis-2/README.md index 57106b7151..c0b313d3b3 100644 --- a/core-java-modules/core-java-string-apis-2/README.md +++ b/core-java-modules/core-java-string-apis-2/README.md @@ -8,3 +8,4 @@ This module contains articles about string APIs. - [Guide to Java String Pool](https://www.baeldung.com/java-string-pool) - [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting) - [Compare StringBuilder Objects in Java](https://www.baeldung.com/java-stringbuilder-objects-comparison) +- [Finding the N-th Occurrence of a Substring in a String in Java](https://www.baeldung.com/java-locate-nth-match-substring) From 4062f3a1193017941523176517a90b94fcd1f707 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:50:24 +0530 Subject: [PATCH 083/107] backlink updated --- spring-5-webflux-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-webflux-2/README.md b/spring-5-webflux-2/README.md index 1b01f519a4..a0fafd903e 100644 --- a/spring-5-webflux-2/README.md +++ b/spring-5-webflux-2/README.md @@ -6,4 +6,4 @@ This module contains articles about Spring 5 WebFlux - [Spring Webflux and @Cacheable Annotation](https://www.baeldung.com/spring-webflux-cacheable) - [Comparison Between Mono’s doOnNext() and doOnSuccess()](https://www.baeldung.com/mono-doonnext-doonsuccess) - [How to Access the First Element of a Flux](https://www.baeldung.com/java-flux-first-element) -- [Using zipWhen() with Mono](https://www.baeldung.com/java-mono-zipwhen) +- [Using zipWhen() With Mono](https://www.baeldung.com/java-mono-zipwhen) From 173dd4bac3d78e7897274cd1a8625cad251846ff Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:52:02 +0530 Subject: [PATCH 084/107] backlink updated --- persistence-modules/spring-data-jpa-query/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-query/README.md b/persistence-modules/spring-data-jpa-query/README.md index 27443c2026..27e7087592 100644 --- a/persistence-modules/spring-data-jpa-query/README.md +++ b/persistence-modules/spring-data-jpa-query/README.md @@ -5,7 +5,7 @@ This module contains articles about querying data using Spring Data JPA ### Relevant Articles: - [The Exists Query in Spring Data](https://www.baeldung.com/spring-data-exists-query) - [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions) -- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) +- [Limiting Query Results With JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) - [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting) - [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) - [JPA Join Types](https://www.baeldung.com/jpa-join-types) From b87609265da2f584dddb8eddfb830650c635655a Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sat, 11 Nov 2023 08:29:09 +0200 Subject: [PATCH 085/107] [JAVA-26709] Upgraded modelmapper to latest version --- .../pom.xml | 2 +- .../modelmapper/UsersListMappingUnitTest.java | 39 +++++++------------ libraries-6/pom.xml | 14 ++++--- parent-java/pom.xml | 2 +- performance-tests/pom.xml | 2 +- .../spring-boot-libraries/pom.xml | 2 +- spring-boot-rest/pom.xml | 2 +- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/core-java-modules/core-java-collections-conversions-2/pom.xml b/core-java-modules/core-java-collections-conversions-2/pom.xml index 7b7533fc39..da6b6a564a 100644 --- a/core-java-modules/core-java-collections-conversions-2/pom.xml +++ b/core-java-modules/core-java-collections-conversions-2/pom.xml @@ -44,6 +44,6 @@ 0.10.3 11 - 3.1.1 + 3.2.0 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/modelmapper/UsersListMappingUnitTest.java b/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/modelmapper/UsersListMappingUnitTest.java index a8a72b12f7..c71f655044 100644 --- a/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/modelmapper/UsersListMappingUnitTest.java +++ b/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/modelmapper/UsersListMappingUnitTest.java @@ -1,8 +1,9 @@ package com.baeldung.modelmapper; import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.modelmapper.ModelMapper; import org.modelmapper.TypeMap; import org.modelmapper.TypeToken; @@ -10,11 +11,10 @@ import org.modelmapper.TypeToken; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasProperty; -import static org.junit.Assert.assertThat; - /** * This class has test methods of mapping Integer to Character list, @@ -22,12 +22,12 @@ import static org.junit.Assert.assertThat; * * @author Sasa Milenkovic */ -public class UsersListMappingUnitTest { +class UsersListMappingUnitTest { private ModelMapper modelMapper; private List users; - @Before + @BeforeEach public void init() { modelMapper = new ModelMapper(); @@ -35,18 +35,16 @@ public class UsersListMappingUnitTest { TypeMap typeMap = modelMapper.createTypeMap(UserList.class, UserListDTO.class); typeMap.addMappings(mapper -> mapper.using(new UsersListConverter()) - .map(UserList::getUsers, UserListDTO::setUsernames)); + .map(UserList::getUsers, UserListDTO::setUsernames)); - users = new ArrayList(); + users = new ArrayList<>(); users.add(new User("b100", "user1", "user1@baeldung.com", "111-222", "USER")); users.add(new User("b101", "user2", "user2@baeldung.com", "111-333", "USER")); users.add(new User("b102", "user3", "user3@baeldung.com", "111-444", "ADMIN")); - } @Test - public void whenInteger_thenMapToCharacter() { - + void whenInteger_thenMapToCharacter() { List integers = new ArrayList(); integers.add(1); @@ -57,36 +55,27 @@ public class UsersListMappingUnitTest { }.getType()); assertThat(characters, hasItems('1', '2', '3')); - } @Test - public void givenUsersList_whenUseGenericType_thenMapToUserDTO() { - + void givenUsersList_whenUseGenericType_thenMapToUserDTO() { // Mapping lists using custom (generic) type mapping - List userDtoList = MapperUtil.mapList(users, UserDTO.class); - assertThat(userDtoList, Matchers.hasItem( - Matchers.both(hasProperty("userId", equalTo("b100"))) - .and(hasProperty("email", equalTo("user1@baeldung.com"))) - .and(hasProperty("username", equalTo("user1"))))); - - + assertThat(userDtoList, Matchers. hasItem(Matchers.both(hasProperty("userId", equalTo("b100"))) + .and(hasProperty("email", equalTo("user1@baeldung.com"))) + .and(hasProperty("username", equalTo("user1"))))); } @Test - public void givenUsersList_whenUseConverter_thenMapToUsernames() { - + void givenUsersList_whenUseConverter_thenMapToUsernames() { // Mapping lists using property mapping and converter - UserList userList = new UserList(); userList.setUsers(users); UserListDTO dtos = new UserListDTO(); modelMapper.map(userList, dtos); assertThat(dtos.getUsernames(), hasItems("user1", "user2", "user3")); - } } \ No newline at end of file diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index 139edab34f..9fa44d3a32 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -108,7 +108,7 @@ org.agrona agrona - 1.17.1 + ${agrona.version} @@ -126,7 +126,7 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 + ${exec-maven-plugin.version} generate-sources @@ -154,14 +154,14 @@ uk.co.real-logic sbe-tool - 1.27.0 + ${sbe-tool.version} org.codehaus.mojo build-helper-maven-plugin - 3.0.0 + ${build-helper-maven-plugin.version} add-source @@ -204,7 +204,11 @@ 3.0 1.8.1 8.12.9 - 2.4.4 + 3.2.0 + 1.17.1 + 1.6.0 + 1.27.0 + 3.0.0 \ No newline at end of file diff --git a/parent-java/pom.xml b/parent-java/pom.xml index b08925e040..03cafac55b 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -40,7 +40,7 @@ - 2.3.7 + 3.2.0 \ No newline at end of file diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 542a505b16..9f57a1a90c 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -152,7 +152,7 @@ 1.5.4 6.5.2 1.5.2.Final - 3.1.0 + 3.2.0 1.6.1.CR2 1.8 diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index b7b8ad17ad..ed9a414a60 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -219,7 +219,7 @@ 5.0.2 5.2.4 2.2.4 - 2.3.2 + 3.2.0 0.23.0 2.1.0 1.5-beta1 diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index db646899ad..71916900a4 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -162,7 +162,7 @@ com.baeldung.SpringBootRestApplication 1.4.11.1 - 3.1.0 + 3.2.0 3.3.0 2.3.7 From 62b0d3def765c37d9082415d5411980dff8d3493 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 11 Nov 2023 12:17:46 +0530 Subject: [PATCH 086/107] JAVA-27185 Upgrade hibernate validator in spring-cloud-gateway-2 --- spring-cloud-modules/spring-cloud-gateway-2/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-modules/spring-cloud-gateway-2/pom.xml b/spring-cloud-modules/spring-cloud-gateway-2/pom.xml index 22182e8c78..4228c72d37 100644 --- a/spring-cloud-modules/spring-cloud-gateway-2/pom.xml +++ b/spring-cloud-modules/spring-cloud-gateway-2/pom.xml @@ -57,7 +57,7 @@ test - org.hibernate + org.hibernate.validator hibernate-validator-cdi ${hibernate-validator.version} @@ -116,7 +116,7 @@ - 6.0.2.Final + 8.0.1.Final 0.7.2 9.19 From df9e040b765b8ac8e59e911d8ef170b1b8269682 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 11 Nov 2023 12:59:42 +0530 Subject: [PATCH 087/107] JAVA-27186 Upgrade hibernate validator version in spring-cloud-gateway --- spring-cloud-modules/spring-cloud-gateway/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-modules/spring-cloud-gateway/pom.xml b/spring-cloud-modules/spring-cloud-gateway/pom.xml index 76072a59ac..0287ab7588 100644 --- a/spring-cloud-modules/spring-cloud-gateway/pom.xml +++ b/spring-cloud-modules/spring-cloud-gateway/pom.xml @@ -62,7 +62,7 @@ test - org.hibernate + org.hibernate.validator hibernate-validator-cdi ${hibernate-validator.version} @@ -185,7 +185,7 @@ - 6.0.2.Final + 8.0.1.Final 0.7.2 9.19 From 3435cd06509844c366a0d06a811bb967fc52ab2e Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 11 Nov 2023 13:43:35 +0530 Subject: [PATCH 088/107] JAVA-27187 Upgrade hibernate validator version in spring-core-2 --- spring-core-2/pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spring-core-2/pom.xml b/spring-core-2/pom.xml index 2d11cc2124..f27b16acc3 100644 --- a/spring-core-2/pom.xml +++ b/spring-core-2/pom.xml @@ -88,9 +88,8 @@ - org.hibernate + org.hibernate.validator hibernate-validator - ${hibernate.version} @@ -160,8 +159,6 @@ com.baeldung.sample.App 1.3.2 - - 5.2.5.Final 3.6 2.1.0 From 3d5b1cff86e129f3cd33b934967d30e0b5cefc53 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sat, 11 Nov 2023 14:11:32 +0530 Subject: [PATCH 089/107] JAVA-27188 Upgrade hibernate-validator version in spring-exceptions --- spring-exceptions/pom.xml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/spring-exceptions/pom.xml b/spring-exceptions/pom.xml index 49c44f88f2..e0071a4206 100644 --- a/spring-exceptions/pom.xml +++ b/spring-exceptions/pom.xml @@ -72,7 +72,7 @@ - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -108,11 +108,6 @@ ${org.springframework.version} test - - javax.el - el-api - ${javax.el.version} - org.apache.derby derby @@ -171,8 +166,7 @@ 7.0.73 10.13.1.1 - 5.3.3.Final - 2.2 + 8.0.1.Final 2.3.0 4.4.5 From 8fff0f323cb8b949b31ef47177c1e1035d4a03bc Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Sat, 11 Nov 2023 10:53:34 +0000 Subject: [PATCH 090/107] [JAVA-20077] Sorted modules in alphabetical order (#15168) * [JAVA-20077] Sorted modules in alphabetical order * [JAVA-2007] --- pom.xml | 680 ++++++++++++++++++++++++++------------------------------ 1 file changed, 310 insertions(+), 370 deletions(-) diff --git a/pom.xml b/pom.xml index bb5a0c9e7b..47c566023d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,8 @@ + 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 com.baeldung parent-modules @@ -690,35 +690,157 @@ - parent-boot-3 - lombok-modules - osgi - spring-katharsis - logging-modules - spring-boot-modules - apache-httpclient - apache-httpclient4 + akka-modules + algorithms-modules + antlr + apache-cxf-modules apache-httpclient-2 - spring-mobile - microservices-modules - spring-ejb-modules - spring-di - spring-di-2 - spring-jinq - vavr-modules - java-websocket + apache-httpclient4 + apache-httpclient + apache-kafka-2 + apache-kafka + apache-libraries-2 + apache-libraries + apache-olingo + apache-poi-2 + apache-poi-3 + apache-poi + apache-thrift + apache-tika + apache-velocity + asciidoctor + asm + atomikos + atomix + aws-modules azure - netflix-modules - spf4j - spring-jersey - jersey - jaxb - + bazel + checker-framework + core-groovy-modules + core-java-modules + custom-pmd + data-structures + deeplearning4j + di-modules + disruptor + docker-modules + dozer + drools + dubbo + + gcp-firebase + geotools + google-auto-project + google-cloud + gradle-modules/gradle/maven-to-gradle + graphql-modules + grpc + guava-modules + hazelcast + httpclient-simple + hystrix + image-compressing + image-processing + jackson-modules + jackson-simple + java-blockchain + java-jdi + + java-rmi + java-spi + java-websocket javafx - spring-batch + javax-sound + javaxval-2 + javaxval + jaxb + jersey + jetbrains + jgit + jhipster-6 + jib + jmeter + jmh + jsf + json-modules + jsoup + jws + ksqldb + kubernetes-modules + language-interop + libraries-2 + libraries-3 + libraries-4 + libraries-5 + libraries-6 + libraries-ai + libraries-apache-commons-2 + libraries-apache-commons-collections + libraries-apache-commons-io + libraries-apache-commons + libraries-concurrency + libraries-data-2 + libraries-data-db + libraries-data-io + libraries-data + libraries-files + libraries-http-2 + libraries-http + libraries-io + libraries-llms + libraries-primitive + libraries-rpc + libraries-security + libraries-server-2 + libraries-server + libraries-testing + libraries-transform + libraries + lightrun + logging-modules + lombok-modules + lucene + mapstruct + maven-modules + mesos-marathon + messaging-modules + metrics + microservices-modules + mustache + mybatis + netflix-modules + optaplanner + orika + osgi + parent-boot-3 + patterns-modules + pdf-2 + pdf + performance-tests + persistence-modules + persistence-modules/spring-data-neo4j + protobuffer + quarkus-modules + reactive-systems + reactor-core + rsocket + rule-engines-modules + rxjava-modules + saas-modules + security-modules + server-modules + spf4j + spring-5-webflux-2 + spring-5-webflux + spring-5 + spring-activiti + spring-actuator + spring-aop-2 + spring-aop spring-batch-2 + spring-batch + spring-boot-modules spring-boot-rest - spring-drools spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker spring-cloud-modules/spring-cloud-contract @@ -728,210 +850,58 @@ spring-cloud-modules/spring-cloud-security spring-cloud-modules/spring-cloud-stream-starters spring-cloud-modules/spring-cloud-zuul-eureka-integration - - spring-exceptions - spring-jenkins-pipeline - spring-core - spring-core-4 - spring-integration - spring-remoting-modules - libraries-security - libraries-data-db - - performance-tests - security-modules - libraries-server-2 - orika - patterns-modules - json-modules - libraries-data - saas-modules - server-modules - apache-cxf-modules - - spring-aop - jmeter - spring-aop-2 - - algorithms-modules - apache-libraries - apache-libraries-2 - apache-poi - apache-velocity - di-modules - asciidoctor - aws-modules - - checker-framework - core-groovy-modules - - core-java-modules - custom-pmd - data-structures - jackson-modules - jmh - deeplearning4j - docker-modules - drools - guava-modules - kubernetes-modules - libraries-concurrency - jhipster-6 - libraries-testing - maven-modules - optaplanner - persistence-modules - quarkus-modules - spring-reactive-modules - spring-swagger-codegen/custom-validations-opeanpi-codegen - testing-modules - testing-modules/mockito-simple - - rule-engines-modules - - reactive-systems - rxjava-modules - - lightrun - tablesaw - image-compressing - geotools - - jws - - - - akka-modules - httpclient-simple - antlr - apache-kafka - apache-kafka-2 - apache-olingo - - apache-poi-2 - apache-poi-3 - apache-thrift - apache-tika - - asm - atomikos - atomix - - bazel - google-auto-project - disruptor - dozer - dubbo - - google-cloud - graphql-modules - grpc - hazelcast - hystrix - jackson-simple - java-blockchain - java-jdi - java-rmi - java-spi - javax-sound - javaxval - javaxval-2 - jetbrains - jgit - jib - - jsoup - ksqldb - jsf - - libraries - libraries-2 - libraries-4 - libraries-5 - libraries-6 - - libraries-apache-commons - libraries-apache-commons-2 - libraries-apache-commons-collections - libraries-apache-commons-io - libraries-data-2 - libraries-data-io - libraries-files - libraries-http - libraries-http-2 - libraries-io - libraries-ai - libraries-primitive - libraries-rpc - libraries-server - libraries-transform - - lucene - mapstruct - mesos-marathon - metrics - mustache - mybatis - pdf - pdf-2 - protobuffer - reactor-core - rsocket - - - spring-5 - spring-5-webflux - spring-5-webflux-2 - spring-6-rsocket - spring-activiti - spring-actuator spring-core-2 spring-core-3 + spring-core-4 + spring-core spring-credhub - spring-di-3 spring-cucumber - + spring-di-2 + spring-di-3 + spring-di-4 + spring-di + spring-drools + spring-ejb-modules + spring-exceptions + spring-integration + spring-jenkins-pipeline + spring-jersey + spring-jinq + spring-kafka-2 spring-kafka - + spring-katharsis + spring-mobile spring-native - spring-soap - spring-security-modules spring-protobuf + spring-pulsar spring-quartz - + spring-reactive-modules + spring-remoting-modules spring-scheduling - - spring-state-machine + spring-security-modules spring-shell + spring-soap spring-spel + spring-state-machine spring-static-resources + spring-swagger-codegen/custom-validations-opeanpi-codegen spring-threads spring-vault - spring-websockets spring-web-modules + spring-websockets static-analysis + tablesaw tensorflow-java - vertx-modules - xstream - webrtc - - messaging-modules - + testing-modules + testing-modules/mockito-simple vaadin - libraries-3 + vavr-modules + vertx-modules web-modules - xml + webrtc xml-2 - image-processing - language-interop - gradle-modules/gradle/maven-to-gradle - persistence-modules/spring-data-neo4j - gcp-firebase - spring-di-4 - spring-kafka-2 - - libraries-llms - spring-pulsar + xml + xstream @@ -965,248 +935,218 @@ - parent-boot-3 - lombok-modules - osgi - spring-katharsis - logging-modules - spring-boot-modules - apache-httpclient - apache-httpclient4 - apache-httpclient-2 - spring-mobile - microservices-modules - spring-ejb-modules - spring-di - spring-di-2 - spring-jinq - vavr-modules - java-websocket - azure - netflix-modules - spf4j - spring-jersey - jersey - jaxb - - javafx - spring-batch - spring-batch-2 - spring-boot-rest - spring-drools - spring-cloud-modules/spring-cloud-azure - spring-cloud-modules/spring-cloud-circuit-breaker - spring-cloud-modules/spring-cloud-eureka - spring-cloud-modules/spring-cloud-contract - spring-cloud-modules/spring-cloud-data-flow - spring-cloud-modules/spring-cloud-netflix-feign - spring-cloud-modules/spring-cloud-stream-starters - spring-cloud-modules/spring-cloud-security - spring-cloud-modules/spring-cloud-zuul-eureka-integration - - spring-exceptions - spring-jenkins-pipeline - spring-core - spring-core-4 - spring-integration - spring-remoting-modules - libraries-security - libraries-data-db - - performance-tests - security-modules - libraries-server-2 - orika - patterns-modules - json-modules - libraries-data - saas-modules - server-modules - apache-cxf-modules - - algorithms-modules - apache-libraries - apache-libraries-2 - apache-poi - apache-velocity - di-modules - asciidoctor - aws-modules - - checker-framework - - core-groovy-modules - - core-java-modules - gcp-firebase - spring-aop - spring-aop-2 - custom-pmd - data-structures - jackson-modules - jmh - deeplearning4j - jmeter - docker-modules - drools - guava-modules - kubernetes-modules - libraries-concurrency - jhipster-6 - libraries-testing - maven-modules - optaplanner - persistence-modules - quarkus-modules - spring-reactive-modules - spring-swagger-codegen/custom-validations-opeanpi-codegen - testing-modules - testing-modules/mockito-simple - - rule-engines-modules - - reactive-systems - rxjava-modules - - lightrun - tablesaw - image-compressing - geotools - - jws - - - akka-modules + algorithms-modules antlr - apache-kafka + apache-cxf-modules + apache-httpclient-2 + apache-httpclient4 + apache-httpclient apache-kafka-2 + apache-kafka + apache-libraries-2 + apache-libraries apache-olingo - apache-poi-2 apache-poi-3 + apache-poi apache-thrift apache-tika - + apache-velocity + asciidoctor asm atomikos atomix - + aws-modules + azure bazel - google-auto-project + checker-framework + core-groovy-modules + core-java-modules + custom-pmd + data-structures + deeplearning4j + di-modules disruptor + docker-modules dozer - + drools dubbo + gcp-firebase + geotools + google-auto-project google-cloud + gradle-modules/gradle/maven-to-gradle graphql-modules grpc + guava-modules hazelcast httpclient-simple hystrix + image-compressing + image-processing + jackson-modules jackson-simple java-blockchain java-jdi + java-rmi java-spi + java-websocket + javafx javax-sound - javaxval javaxval-2 + javaxval + jaxb + jersey jetbrains jgit + jhipster-6 jib - - jsoup + jmeter + jmh jsf + json-modules + jsoup + jws ksqldb - - libraries + kubernetes-modules + language-interop libraries-2 + libraries-3 libraries-4 libraries-5 libraries-6 - libraries-apache-commons + libraries-ai libraries-apache-commons-2 libraries-apache-commons-collections libraries-apache-commons-io + libraries-apache-commons + libraries-concurrency libraries-data-2 + libraries-data-db libraries-data-io + libraries-data libraries-files - libraries-http libraries-http-2 + libraries-http libraries-io - libraries-ai + libraries-llms libraries-primitive libraries-rpc + libraries-security + libraries-server-2 libraries-server + libraries-testing libraries-transform - + libraries + lightrun + logging-modules + lombok-modules lucene mapstruct + maven-modules mesos-marathon + messaging-modules metrics + microservices-modules mustache mybatis - pdf + netflix-modules + optaplanner + orika + osgi + parent-boot-3 + patterns-modules pdf-2 + pdf + performance-tests + persistence-modules + persistence-modules/spring-data-neo4j protobuffer + quarkus-modules + reactive-systems reactor-core rsocket - - - - spring-5 - spring-5-webflux + rule-engines-modules + rxjava-modules + saas-modules + security-modules + server-modules + spf4j spring-5-webflux-2 + spring-5-webflux + spring-5 spring-activiti + spring-actuator + spring-aop-2 + spring-aop + spring-batch-2 + spring-batch + spring-boot-modules + spring-boot-rest + spring-cloud-modules/spring-cloud-azure + spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-contract + spring-cloud-modules/spring-cloud-data-flow + spring-cloud-modules/spring-cloud-eureka + spring-cloud-modules/spring-cloud-netflix-feign + spring-cloud-modules/spring-cloud-security + spring-cloud-modules/spring-cloud-stream-starters + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-core-2 spring-core-3 + spring-core-4 + spring-core spring-credhub - spring-di-3 spring-cucumber - + spring-di-2 + spring-di-3 + spring-di-4 + spring-di + spring-drools + spring-ejb-modules + spring-exceptions + spring-integration + spring-jenkins-pipeline + spring-jersey + spring-jinq + spring-kafka-2 spring-kafka - + spring-katharsis + spring-mobile spring-native - spring-soap - spring-security-modules spring-protobuf + spring-pulsar spring-quartz - + spring-reactive-modules + spring-remoting-modules spring-scheduling - - spring-state-machine + spring-security-modules spring-shell + spring-soap spring-spel + spring-state-machine spring-static-resources + spring-swagger-codegen/custom-validations-opeanpi-codegen spring-threads spring-vault - spring-websockets spring-web-modules + spring-websockets static-analysis + tablesaw tensorflow-java - vertx-modules - xstream - webrtc - - messaging-modules - + testing-modules + testing-modules/mockito-simple vaadin - libraries-3 + vavr-modules + vertx-modules web-modules - xml + webrtc xml-2 - image-processing - language-interop - gradle-modules/gradle/maven-to-gradle - persistence-modules/spring-data-neo4j - spring-actuator - spring-di-4 - spring-kafka-2 - - libraries-llms - spring-pulsar + xml + xstream From 3f850f7d00d6bb52046edb1b502062ae18c816cd Mon Sep 17 00:00:00 2001 From: Gaetano Piazzolla Date: Sat, 11 Nov 2023 12:05:30 +0100 Subject: [PATCH 091/107] JAVA-26728 | update sshj lib (#15144) * JAVA-26728 | update sshj lib * JAVA-26728 | added compression --- libraries-io/pom.xml | 2 +- .../io/remote/SftpFileTransferLiveTest.java | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libraries-io/pom.xml b/libraries-io/pom.xml index 08ad0afc3f..7464b9a507 100644 --- a/libraries-io/pom.xml +++ b/libraries-io/pom.xml @@ -56,7 +56,7 @@ 0.1.55 - 0.27.0 + 0.37.0 2.4 2.9.0 5.8 diff --git a/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java b/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java index 5846128082..81c6cb556c 100644 --- a/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java +++ b/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java @@ -20,14 +20,14 @@ import net.schmizz.sshj.transport.verification.PromiscuousVerifier; public class SftpFileTransferLiveTest { - private String remoteHost = "HOST_NAME_HERE"; - private String username = "USERNAME_HERE"; - private String password = "PASSWORD_HERE"; - private String localFile = "src/main/resources/input.txt"; - private String remoteFile = "welcome.txt"; - private String localDir = "src/main/resources/"; - private String remoteDir = "remote_sftp_test/"; - private String knownHostsFileLoc = "/Users/USERNAME/known_hosts_sample"; + private final String remoteHost = "HOST_NAME_HERE"; + private final String username = "USERNAME_HERE"; + private final String password = "PASSWORD_HERE"; + private final String localFile = "src/main/resources/input.txt"; + private final String remoteFile = "welcome.txt"; + private final String localDir = "src/main/resources/"; + private final String remoteDir = "remote_sftp_test/"; + private final String knownHostsFileLoc = "/Users/USERNAME/known_hosts_sample"; @Test public void whenUploadFileUsingJsch_thenSuccess() throws JSchException, SftpException { @@ -100,6 +100,7 @@ public class SftpFileTransferLiveTest { client.addHostKeyVerifier(new PromiscuousVerifier()); client.connect(remoteHost); client.authPassword(username, password); + client.useCompression(); return client; } From 47f7b926e60709efe74245b33a37a3cb0c2f7db0 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sun, 12 Nov 2023 07:32:39 +0200 Subject: [PATCH 092/107] [JAVA-26774] Upgraded mapstruct library to latest version --- core-java-modules/core-java-lang-6/pom.xml | 3 +-- jhipster-6/bookstore-monolith/pom.xml | 2 +- jhipster-modules/jhipster-microservice/car-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/dealer-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/gateway-app/pom.xml | 2 +- jhipster-modules/jhipster-monolithic/pom.xml | 2 +- jhipster-modules/jhipster-uaa/gateway/pom.xml | 2 +- jhipster-modules/jhipster-uaa/quotes/pom.xml | 2 +- jhipster-modules/jhipster-uaa/uaa/pom.xml | 2 +- mapstruct/pom.xml | 2 +- performance-tests/pom.xml | 2 +- persistence-modules/spring-data-jpa-enterprise/pom.xml | 4 ++-- spring-boot-modules/spring-boot-3-2/pom.xml | 2 +- spring-boot-modules/spring-boot-3/pom.xml | 4 ++-- 14 files changed, 16 insertions(+), 17 deletions(-) diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index 6561c4fdcc..54035c1eb0 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -29,7 +29,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.5.1 17 17 @@ -50,7 +49,7 @@ 17 17 UTF-8 - 1.5.5.Final + 1.6.0.Beta1 \ No newline at end of file diff --git a/jhipster-6/bookstore-monolith/pom.xml b/jhipster-6/bookstore-monolith/pom.xml index a35abb9c19..26a1ff6214 100644 --- a/jhipster-6/bookstore-monolith/pom.xml +++ b/jhipster-6/bookstore-monolith/pom.xml @@ -1159,7 +1159,7 @@ 5.1.5.RELEASE 2.0.1.Final 2.3.2 - 1.3.0.Final + 1.6.0.Beta1 3.1.0 diff --git a/jhipster-modules/jhipster-microservice/car-app/pom.xml b/jhipster-modules/jhipster-microservice/car-app/pom.xml index f345688939..3789dc35c1 100644 --- a/jhipster-modules/jhipster-microservice/car-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/car-app/pom.xml @@ -36,7 +36,7 @@ 3.6.2 4.8 jdt_apt - 1.1.0.Final + 1.6.0.Beta1 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml index 056bd60f33..5d588e8dcb 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml @@ -35,7 +35,7 @@ 3.6.2 4.8 jdt_apt - 1.1.0.Final + 1.6.0.Beta1 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml index b90f22f009..26c621bb57 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml @@ -39,7 +39,7 @@ 4.8 1.3.0 jdt_apt - 1.1.0.Final + 1.6.0.Beta1 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-monolithic/pom.xml b/jhipster-modules/jhipster-monolithic/pom.xml index fbcee8f1ff..a8b93b5514 100644 --- a/jhipster-modules/jhipster-monolithic/pom.xml +++ b/jhipster-modules/jhipster-monolithic/pom.xml @@ -904,7 +904,7 @@ 3.6.2 4.8 jdt_apt - 1.1.0.Final + 1.6.0.Beta1 1.4.1 3.0.1 2.10 diff --git a/jhipster-modules/jhipster-uaa/gateway/pom.xml b/jhipster-modules/jhipster-uaa/gateway/pom.xml index 13652575cd..b1982a6f93 100644 --- a/jhipster-modules/jhipster-uaa/gateway/pom.xml +++ b/jhipster-modules/jhipster-uaa/gateway/pom.xml @@ -1048,7 +1048,7 @@ 3.5.5 3.6 2.0.1.Final - 1.2.0.Final + 1.6.0.Beta1 3.1.0 diff --git a/jhipster-modules/jhipster-uaa/quotes/pom.xml b/jhipster-modules/jhipster-uaa/quotes/pom.xml index 2a3c550071..11033af395 100644 --- a/jhipster-modules/jhipster-uaa/quotes/pom.xml +++ b/jhipster-modules/jhipster-uaa/quotes/pom.xml @@ -868,7 +868,7 @@ 3.5.5 3.6 2.0.1.Final - 1.2.0.Final + 1.6.0.Beta1 3.1.0 diff --git a/jhipster-modules/jhipster-uaa/uaa/pom.xml b/jhipster-modules/jhipster-uaa/uaa/pom.xml index 42802b6040..47a5c81c1e 100644 --- a/jhipster-modules/jhipster-uaa/uaa/pom.xml +++ b/jhipster-modules/jhipster-uaa/uaa/pom.xml @@ -869,7 +869,7 @@ 3.5.5 3.6 2.0.1.Final - 1.2.0.Final + 1.6.0.Beta1 3.1.0 diff --git a/mapstruct/pom.xml b/mapstruct/pom.xml index 7c279acb7b..5332bcaeb3 100644 --- a/mapstruct/pom.xml +++ b/mapstruct/pom.xml @@ -73,7 +73,7 @@ - 1.5.5.Final + 1.6.0.Beta1 4.3.4.RELEASE 0.2.0 diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 9f57a1a90c..d22a9cf3ac 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -151,7 +151,7 @@ 1.5.4 6.5.2 - 1.5.2.Final + 1.6.0.Beta1 3.2.0 1.6.1.CR2 diff --git a/persistence-modules/spring-data-jpa-enterprise/pom.xml b/persistence-modules/spring-data-jpa-enterprise/pom.xml index 6bd89032fa..d998849ffb 100644 --- a/persistence-modules/spring-data-jpa-enterprise/pom.xml +++ b/persistence-modules/spring-data-jpa-enterprise/pom.xml @@ -45,7 +45,7 @@ org.mapstruct - mapstruct-jdk8 + mapstruct ${mapstruct.version} provided @@ -97,7 +97,7 @@ - 1.3.1.Final + 1.6.0.Beta1 1.19.1 diff --git a/spring-boot-modules/spring-boot-3-2/pom.xml b/spring-boot-modules/spring-boot-3-2/pom.xml index 276659c609..9b5b7ea254 100644 --- a/spring-boot-modules/spring-boot-3-2/pom.xml +++ b/spring-boot-modules/spring-boot-3-2/pom.xml @@ -280,7 +280,7 @@ - 1.5.2.Final + 1.6.0.Beta1 2.0.0 3.0.0-M7 5.14.0 diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index bb8c5dd53c..a1a5eab563 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -206,8 +206,8 @@ - 19 - 1.5.2.Final + 17 + 1.6.0.Beta1 2.2.0 3.0.0-M7 com.baeldung.sample.TodoApplication From 6db881bfa2df6776a67b7de0873c07bed1402aed Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sun, 12 Nov 2023 07:53:55 +0200 Subject: [PATCH 093/107] [JAVA-26774] Revert mapstruct upgrade on jhipster modules --- jhipster-6/bookstore-monolith/pom.xml | 2 +- jhipster-modules/jhipster-microservice/car-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/dealer-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/gateway-app/pom.xml | 2 +- jhipster-modules/jhipster-monolithic/pom.xml | 2 +- jhipster-modules/jhipster-uaa/gateway/pom.xml | 2 +- jhipster-modules/jhipster-uaa/quotes/pom.xml | 2 +- jhipster-modules/jhipster-uaa/uaa/pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jhipster-6/bookstore-monolith/pom.xml b/jhipster-6/bookstore-monolith/pom.xml index 26a1ff6214..a35abb9c19 100644 --- a/jhipster-6/bookstore-monolith/pom.xml +++ b/jhipster-6/bookstore-monolith/pom.xml @@ -1159,7 +1159,7 @@ 5.1.5.RELEASE 2.0.1.Final 2.3.2 - 1.6.0.Beta1 + 1.3.0.Final 3.1.0 diff --git a/jhipster-modules/jhipster-microservice/car-app/pom.xml b/jhipster-modules/jhipster-microservice/car-app/pom.xml index 3789dc35c1..f345688939 100644 --- a/jhipster-modules/jhipster-microservice/car-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/car-app/pom.xml @@ -36,7 +36,7 @@ 3.6.2 4.8 jdt_apt - 1.6.0.Beta1 + 1.1.0.Final 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml index 5d588e8dcb..056bd60f33 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml @@ -35,7 +35,7 @@ 3.6.2 4.8 jdt_apt - 1.6.0.Beta1 + 1.1.0.Final 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml index 26c621bb57..b90f22f009 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml @@ -39,7 +39,7 @@ 4.8 1.3.0 jdt_apt - 1.6.0.Beta1 + 1.1.0.Final 2.10 1.4.1 3.0.1 diff --git a/jhipster-modules/jhipster-monolithic/pom.xml b/jhipster-modules/jhipster-monolithic/pom.xml index a8b93b5514..fbcee8f1ff 100644 --- a/jhipster-modules/jhipster-monolithic/pom.xml +++ b/jhipster-modules/jhipster-monolithic/pom.xml @@ -904,7 +904,7 @@ 3.6.2 4.8 jdt_apt - 1.6.0.Beta1 + 1.1.0.Final 1.4.1 3.0.1 2.10 diff --git a/jhipster-modules/jhipster-uaa/gateway/pom.xml b/jhipster-modules/jhipster-uaa/gateway/pom.xml index b1982a6f93..13652575cd 100644 --- a/jhipster-modules/jhipster-uaa/gateway/pom.xml +++ b/jhipster-modules/jhipster-uaa/gateway/pom.xml @@ -1048,7 +1048,7 @@ 3.5.5 3.6 2.0.1.Final - 1.6.0.Beta1 + 1.2.0.Final 3.1.0 diff --git a/jhipster-modules/jhipster-uaa/quotes/pom.xml b/jhipster-modules/jhipster-uaa/quotes/pom.xml index 11033af395..2a3c550071 100644 --- a/jhipster-modules/jhipster-uaa/quotes/pom.xml +++ b/jhipster-modules/jhipster-uaa/quotes/pom.xml @@ -868,7 +868,7 @@ 3.5.5 3.6 2.0.1.Final - 1.6.0.Beta1 + 1.2.0.Final 3.1.0 diff --git a/jhipster-modules/jhipster-uaa/uaa/pom.xml b/jhipster-modules/jhipster-uaa/uaa/pom.xml index 47a5c81c1e..42802b6040 100644 --- a/jhipster-modules/jhipster-uaa/uaa/pom.xml +++ b/jhipster-modules/jhipster-uaa/uaa/pom.xml @@ -869,7 +869,7 @@ 3.5.5 3.6 2.0.1.Final - 1.6.0.Beta1 + 1.2.0.Final 3.1.0 From 7dbd9cf9f60aa62ce088a7196d606f6c2e4c870c Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sun, 12 Nov 2023 08:00:42 +0200 Subject: [PATCH 094/107] [JAVA-26774] --- spring-boot-modules/spring-boot-3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index a1a5eab563..ae9e9d7308 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -206,7 +206,7 @@ - 17 + 19 1.6.0.Beta1 2.2.0 3.0.0-M7 From 46dbc56913f2b3dc7f90b1d12e540a20edcb3ebf Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 12 Nov 2023 11:51:29 +0530 Subject: [PATCH 095/107] JAVA-27189 Upgrade hibernate validator version in spring-static-resources --- spring-static-resources/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-static-resources/pom.xml b/spring-static-resources/pom.xml index f682eafdbe..f635583e62 100644 --- a/spring-static-resources/pom.xml +++ b/spring-static-resources/pom.xml @@ -117,7 +117,7 @@ ${jackson.version} - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -194,7 +194,7 @@ 1.8.9 - 6.0.10.Final + 8.0.1.Final 4.1.0 2.10 1 From 21f73644b4b55c9508d588f0613690390ed404e7 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 12 Nov 2023 13:24:22 +0530 Subject: [PATCH 096/107] JAVA-27191 Upgrade hibernate validator version in spring-mvc-basics-2 --- spring-web-modules/spring-mvc-basics-2/pom.xml | 4 ++-- .../com/baeldung/spring/controller/CustomerController.java | 2 +- .../com/baeldung/spring/controller/EmployeeController.java | 2 +- .../java/com/baeldung/spring/controller/MailController.java | 2 +- .../src/main/java/com/baeldung/spring/domain/Employee.java | 4 ++-- .../main/java/com/baeldung/spring/domain/MailObject.java | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-web-modules/spring-mvc-basics-2/pom.xml b/spring-web-modules/spring-mvc-basics-2/pom.xml index 28eb3a16f2..613e42dee3 100644 --- a/spring-web-modules/spring-mvc-basics-2/pom.xml +++ b/spring-web-modules/spring-mvc-basics-2/pom.xml @@ -42,7 +42,7 @@ ${jstl.version} - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -148,7 +148,7 @@ - 6.0.10.Final + 8.0.1.Final enter-location-of-server 3.0.11.RELEASE 2.4.12 diff --git a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java index 8ecfce58e3..e1d2a8e37f 100644 --- a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java +++ b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/CustomerController.java @@ -1,6 +1,6 @@ package com.baeldung.spring.controller; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; diff --git a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java index 6543a98af1..5299d8289b 100644 --- a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java +++ b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/EmployeeController.java @@ -3,7 +3,7 @@ package com.baeldung.spring.controller; import java.util.HashMap; import java.util.Map; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java index b6e19a4c39..f4088b8bb3 100644 --- a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java +++ b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/MailController.java @@ -8,7 +8,7 @@ import java.util.Set; import javax.mail.MessagingException; import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java index 900770b873..a0641b0a32 100644 --- a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java +++ b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/Employee.java @@ -1,7 +1,7 @@ package com.baeldung.spring.domain; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; public class Employee { diff --git a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java index d425ca9a26..23807926ca 100644 --- a/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java +++ b/spring-web-modules/spring-mvc-basics-2/src/main/java/com/baeldung/spring/domain/MailObject.java @@ -1,8 +1,8 @@ package com.baeldung.spring.domain; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; /** * Created by Olga on 7/20/2016. From 57b035bade3b2481ec793d1ca7bd85f012f86dee Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 12 Nov 2023 14:01:38 +0530 Subject: [PATCH 097/107] JAVA-27192 Upgrade hibernate validator in spring-mvc-crash --- spring-web-modules/spring-mvc-crash/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-web-modules/spring-mvc-crash/pom.xml b/spring-web-modules/spring-mvc-crash/pom.xml index f3faa18816..9bfcfb488e 100644 --- a/spring-web-modules/spring-mvc-crash/pom.xml +++ b/spring-web-modules/spring-mvc-crash/pom.xml @@ -147,7 +147,7 @@ 4.4.5 4.5.2 - 6.0.10.Final + 8.0.1.Final 3.0.1-b08 2.8.0 From e6316d25d3f8be6060ea15aae0fc2c7196240db0 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 12 Nov 2023 14:30:03 +0530 Subject: [PATCH 098/107] JAVA-27193 Upgrade hibernate validator version in spring-mvc-forms-jsp --- spring-web-modules/spring-mvc-forms-jsp/pom.xml | 4 ++-- .../controller/CustomerController.java | 2 +- .../controller/EmployeeController.java | 2 +- .../springmvcforms/controller/UserController.java | 2 +- .../com/baeldung/springmvcforms/domain/Employee.java | 4 ++-- .../com/baeldung/springmvcforms/domain/User.java | 12 ++++++------ 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spring-web-modules/spring-mvc-forms-jsp/pom.xml b/spring-web-modules/spring-mvc-forms-jsp/pom.xml index 3ad815e95f..5096c6e23d 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/pom.xml +++ b/spring-web-modules/spring-mvc-forms-jsp/pom.xml @@ -48,7 +48,7 @@ ${mysql-connector-java.version} - org.hibernate + org.hibernate.validator hibernate-validator ${hibernate-validator.version} @@ -102,7 +102,7 @@ - 6.0.10.Final + 8.0.1.Final 5.2.5.Final 6.0.6 1.3.2 diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java index 586c2467fe..81dd700551 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/CustomerController.java @@ -1,6 +1,6 @@ package com.baeldung.springmvcforms.controller; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java index 478b3532fe..9c0b3a7086 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/EmployeeController.java @@ -7,7 +7,7 @@ import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; -import javax.validation.Valid; +import jakarta.validation.Valid; import java.util.HashMap; import java.util.Map; diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java index f5553cf2b7..80f56645a9 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/controller/UserController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; -import javax.validation.Valid; +import jakarta.validation.Valid; import java.util.Arrays; import java.util.Collections; import java.util.List; diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java index 23cb72b3dc..ae174e2020 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/Employee.java @@ -1,7 +1,7 @@ package com.baeldung.springmvcforms.domain; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; public class Employee { diff --git a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java index 9e0e7c99be..db055763a4 100644 --- a/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java +++ b/spring-web-modules/spring-mvc-forms-jsp/src/main/java/com/baeldung/springmvcforms/domain/User.java @@ -1,11 +1,11 @@ package com.baeldung.springmvcforms.domain; -import javax.validation.constraints.Digits; -import javax.validation.constraints.Email; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.Digits; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; public class User { From ec251f847b550c513d6431ea34de0599e298c239 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Sun, 12 Nov 2023 16:35:46 +0200 Subject: [PATCH 099/107] [JAVA-26739] Upgraded json-path to latest version --- core-java-modules/core-java-optional/pom.xml | 4 +- .../java9additions/Java9OptionalUnitTest.java | 170 +++++++++--------- ethereum/pom.xml | 2 +- jackson-modules/jackson-annotations/pom.xml | 4 +- json-modules/json-path/pom.xml | 4 +- .../spring-mvc-basics-5/pom.xml | 2 +- spring-web-modules/spring-mvc-java/pom.xml | 2 +- video-tutorials/jackson-annotations/pom.xml | 2 +- 8 files changed, 94 insertions(+), 96 deletions(-) diff --git a/core-java-modules/core-java-optional/pom.xml b/core-java-modules/core-java-optional/pom.xml index eeefed867e..68800f67fc 100644 --- a/core-java-modules/core-java-optional/pom.xml +++ b/core-java-modules/core-java-optional/pom.xml @@ -47,14 +47,14 @@ io.rest-assured json-path - ${rest-assured.version} + ${json-path.version} test 5.4.0.Final - 3.1.1 + 5.3.2 \ No newline at end of file diff --git a/core-java-modules/core-java-optional/src/test/java/com/baeldung/java9additions/Java9OptionalUnitTest.java b/core-java-modules/core-java-optional/src/test/java/com/baeldung/java9additions/Java9OptionalUnitTest.java index ee04432e44..e7daac4b8c 100644 --- a/core-java-modules/core-java-optional/src/test/java/com/baeldung/java9additions/Java9OptionalUnitTest.java +++ b/core-java-modules/core-java-optional/src/test/java/com/baeldung/java9additions/Java9OptionalUnitTest.java @@ -8,88 +8,88 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -// Uncomment code when code base is compatible with Java 9 -//public class Java9OptionalUnitTest { -// -// @Test -// public void givenOptionalOfSome_whenToStream_thenShouldTreatItAsOneElementStream() { -// //given -// Optional value = Optional.of("a"); -// -// //when -// List collect = value.stream().map(String::toUpperCase).collect(Collectors.toList()); -// -// //then -// assertThat(collect).hasSameElementsAs(List.of("A")); -// } -// -// @Test -// public void givenOptionalOfNone_whenToStream_thenShouldTreatItAsZeroElementStream() { -// //given -// Optional value = Optional.empty(); -// -// //when -// List collect = value.stream().map(String::toUpperCase).collect(Collectors.toList()); -// -// //then -// assertThat(collect).isEmpty(); -// } -// -// @Test -// public void givenOptional_whenPresent_thenShouldExecuteProperCallback() { -// //given -// Optional value = Optional.of("properValue"); -// AtomicInteger successCounter = new AtomicInteger(0); -// AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0); -// -// //when -// value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet); -// -// //then -// assertThat(successCounter.get()).isEqualTo(1); -// assertThat(onEmptyOptionalCounter.get()).isEqualTo(0); -// } -// -// @Test -// public void givenOptional_whenNotPresent_thenShouldExecuteProperCallback() { -// //given -// Optional value = Optional.empty(); -// AtomicInteger successCounter = new AtomicInteger(0); -// AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0); -// -// //when -// value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet); -// -// //then -// assertThat(successCounter.get()).isEqualTo(0); -// assertThat(onEmptyOptionalCounter.get()).isEqualTo(1); -// } -// -// @Test -// public void givenOptional_whenPresent_thenShouldTakeAValueFromIt() { -// //given -// String expected = "properValue"; -// Optional value = Optional.of(expected); -// Optional defaultValue = Optional.of("default"); -// -// //when -// Optional result = value.or(() -> defaultValue); -// -// //then -// assertThat(result.get()).isEqualTo(expected); -// } -// -// @Test -// public void givenOptional_whenEmpty_thenShouldTakeAValueFromOr() { -// //given -// String defaultString = "default"; -// Optional value = Optional.empty(); -// Optional defaultValue = Optional.of(defaultString); -// -// //when -// Optional result = value.or(() -> defaultValue); -// -// //then -// assertThat(result.get()).isEqualTo(defaultString); -// } -//} \ No newline at end of file + +public class Java9OptionalUnitTest { + + @Test + public void givenOptionalOfSome_whenToStream_thenShouldTreatItAsOneElementStream() { + //given + Optional value = Optional.of("a"); + + //when + List collect = value.stream().map(String::toUpperCase).collect(Collectors.toList()); + + //then + assertThat(collect).hasSameElementsAs(List.of("A")); + } + + @Test + public void givenOptionalOfNone_whenToStream_thenShouldTreatItAsZeroElementStream() { + //given + Optional value = Optional.empty(); + + //when + List collect = value.stream().map(String::toUpperCase).collect(Collectors.toList()); + + //then + assertThat(collect).isEmpty(); + } + + @Test + public void givenOptional_whenPresent_thenShouldExecuteProperCallback() { + //given + Optional value = Optional.of("properValue"); + AtomicInteger successCounter = new AtomicInteger(0); + AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0); + + //when + value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet); + + //then + assertThat(successCounter.get()).isEqualTo(1); + assertThat(onEmptyOptionalCounter.get()).isEqualTo(0); + } + + @Test + public void givenOptional_whenNotPresent_thenShouldExecuteProperCallback() { + //given + Optional value = Optional.empty(); + AtomicInteger successCounter = new AtomicInteger(0); + AtomicInteger onEmptyOptionalCounter = new AtomicInteger(0); + + //when + value.ifPresentOrElse((v) -> successCounter.incrementAndGet(), onEmptyOptionalCounter::incrementAndGet); + + //then + assertThat(successCounter.get()).isEqualTo(0); + assertThat(onEmptyOptionalCounter.get()).isEqualTo(1); + } + + @Test + public void givenOptional_whenPresent_thenShouldTakeAValueFromIt() { + //given + String expected = "properValue"; + Optional value = Optional.of(expected); + Optional defaultValue = Optional.of("default"); + + //when + Optional result = value.or(() -> defaultValue); + + //then + assertThat(result.get()).isEqualTo(expected); + } + + @Test + public void givenOptional_whenEmpty_thenShouldTakeAValueFromOr() { + //given + String defaultString = "default"; + Optional value = Optional.empty(); + Optional defaultValue = Optional.of(defaultString); + + //when + Optional result = value.or(() -> defaultValue); + + //then + assertThat(result.get()).isEqualTo(defaultString); + } +} \ No newline at end of file diff --git a/ethereum/pom.xml b/ethereum/pom.xml index 8dc25427d9..a94f74c115 100644 --- a/ethereum/pom.xml +++ b/ethereum/pom.xml @@ -192,7 +192,7 @@ 1.5.0-RELEASE 3.3.1 1.5.6.RELEASE - 2.4.0 + 2.8.0 2.0.4.RELEASE 3.1 diff --git a/jackson-modules/jackson-annotations/pom.xml b/jackson-modules/jackson-annotations/pom.xml index e2d5e1e607..59d7d3d197 100644 --- a/jackson-modules/jackson-annotations/pom.xml +++ b/jackson-modules/jackson-annotations/pom.xml @@ -21,7 +21,7 @@ io.rest-assured json-path - ${rest-assured.version} + ${json-path.version} test @@ -59,7 +59,7 @@ 2.1.214 - 3.1.1 + 5.3.2 2.5.0 diff --git a/json-modules/json-path/pom.xml b/json-modules/json-path/pom.xml index 88b81dfc68..763a275290 100644 --- a/json-modules/json-path/pom.xml +++ b/json-modules/json-path/pom.xml @@ -13,7 +13,6 @@ - com.jayway.jsonpath json-path @@ -22,8 +21,7 @@ - - 2.4.0 + 2.8.0 \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-5/pom.xml b/spring-web-modules/spring-mvc-basics-5/pom.xml index e0d603e303..1c8c87a2ef 100644 --- a/spring-web-modules/spring-mvc-basics-5/pom.xml +++ b/spring-web-modules/spring-mvc-basics-5/pom.xml @@ -82,7 +82,7 @@ 1.3.2 - 2.7.0 + 2.8.0 2.3.5 2.0.0 3.0.0 diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 8098f07282..717c3b76b8 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -237,7 +237,7 @@ 4.0.1 2.3.3 2.32 - 2.4.0 + 2.8.0 com.baeldung.SpringMVCApplication diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index eaec50c1f7..f6a2e6928a 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -120,7 +120,7 @@ 3.0.1 3.0.0 2.2.6 - 3.0.1 + 5.3.2 \ No newline at end of file From c0a9532c647bfee5f6a68d6e4550636940cbd4de Mon Sep 17 00:00:00 2001 From: Lucian Snare Date: Sun, 12 Nov 2023 10:59:00 -0500 Subject: [PATCH 100/107] BAEL-6790: Write and Read file with HashMap (#15087) * Add examples for reading and writing a HashMap from a file * Add test for gson --- .../core-java-collections-maps-7/README.md | 4 +- .../core-java-collections-maps-7/pom.xml | 65 ++------- .../map/readandwritefile/Student.java | 51 +++++++ .../ReadAndWriteFileWithHashMapUnitTest.java | 135 ++++++++++++++++++ 4 files changed, 199 insertions(+), 56 deletions(-) create mode 100644 core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/readandwritefile/Student.java create mode 100644 core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/readandwritefile/ReadAndWriteFileWithHashMapUnitTest.java diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md index 2e1531050e..a62bdda7af 100644 --- a/core-java-modules/core-java-collections-maps-7/README.md +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -1,5 +1,7 @@ -## Relevant Articles +## Relevant Articles: - [Difference Between putIfAbsent() and computeIfAbsent() in Java’s Map](https://www.baeldung.com/java-map-putifabsent-computeifabsent) +- [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/how-to-write-and-read-a-file-with-a-java-hashmap/) - [How to Write Hashmap to CSV File](https://www.baeldung.com/java-write-hashmap-csv) - [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair) - [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file) +- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6) \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-7/pom.xml b/core-java-modules/core-java-collections-maps-7/pom.xml index cefee201cc..a7acded9cf 100644 --- a/core-java-modules/core-java-collections-maps-7/pom.xml +++ b/core-java-modules/core-java-collections-maps-7/pom.xml @@ -1,11 +1,15 @@ + 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 core-java-collections-maps-7 core-java-collections-maps-7 jar + + 2.10.1 + 1.5 + core-java-modules @@ -13,72 +17,24 @@ 0.0.1-SNAPSHOT - - 5.2.5.RELEASE - com.fasterxml.jackson.core jackson-databind - 2.12.4 - - - org.openjdk.jmh - jmh-core - 1.36 + ${jackson.version} com.google.code.gson gson - 2.8.9 - - - org.json - json - 20230227 - - - junit - junit - 4.13.1 - test - - - org.junit.jupiter - junit-jupiter - 5.8.1 - test - - - org.junit.jupiter - junit-jupiter - 5.8.1 - test - - - junit - junit - 4.13.1 - test - - - org.junit.jupiter - junit-jupiter - 5.8.1 - test - - - junit - junit - 4.13.1 - test + ${gson.version} org.apache.commons commons-csv - 1.5 + ${csv.version} + @@ -92,5 +48,4 @@ - diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/readandwritefile/Student.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/readandwritefile/Student.java new file mode 100644 index 0000000000..b981de6300 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/readandwritefile/Student.java @@ -0,0 +1,51 @@ +package com.baeldung.map.readandwritefile; + +import java.io.Serializable; +import java.util.Objects; + +public class Student implements Serializable { + private static final long serialVersionUID = 1L; + private String firstName; + private String lastName; + + /** Default constructor for JSON serialization */ + public Student() { + + } + + public Student(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Student student = (Student) o; + return Objects.equals(firstName, student.firstName) && Objects.equals(lastName, student.lastName); + } + + @Override + public int hashCode() { + return super.hashCode(); + } +} diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/readandwritefile/ReadAndWriteFileWithHashMapUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/readandwritefile/ReadAndWriteFileWithHashMapUnitTest.java new file mode 100644 index 0000000000..56867d3885 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/readandwritefile/ReadAndWriteFileWithHashMapUnitTest.java @@ -0,0 +1,135 @@ +package com.baeldung.map.readandwritefile; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.junit.After; +import org.junit.Test; +import org.junit.Before; + +public class ReadAndWriteFileWithHashMapUnitTest { + + private static final Map STUDENT_DATA = new HashMap<>(); + + static { + STUDENT_DATA.put(1234, new Student("Henry", "Winter")); + STUDENT_DATA.put(5678, new Student("Richard", "Papen")); + } + + private File file; + + @Before + public void createFile() throws IOException { + file = File.createTempFile("student", ".data"); + } + + @After + public void deleteFile() { + file.delete(); + } + + @Test + public void givenHashMap_whenWrittenAsPropertiesFile_thenReloadedMapIsIdentical() throws IOException { + // Given a map containing student data + Map studentData = new HashMap<>(); + studentData.put("student.firstName", "Henry"); + studentData.put("student.lastName", "Winter"); + + // When converting to a Properties object and writing to a file + Properties props = new Properties(); + props.putAll(studentData); + try (OutputStream output = Files.newOutputStream(file.toPath())) { + props.store(output, null); + } + + // Then the map resulting from loading the Properties file is identical + Properties propsFromFile = new Properties(); + try (InputStream input = Files.newInputStream(file.toPath())) { + propsFromFile.load(input); + } + + Map studentDataFromProps = propsFromFile.stringPropertyNames() + .stream() + .collect(Collectors.toMap(key -> key, props::getProperty)); + assertThat(studentDataFromProps).isEqualTo(studentData); + } + + @Test + public void givenHashMap_whenSerializedToFile_thenDeserializedMapIsIdentical() throws IOException, ClassNotFoundException { + // Given a map containing student data (STUDENT_DATA) + + // When serializing the map to a file + try (FileOutputStream fileOutput = new FileOutputStream(file); ObjectOutputStream objectStream = new ObjectOutputStream(fileOutput)) { + objectStream.writeObject(STUDENT_DATA); + } + + // Then read the file back into a map and check the contents + Map studentsFromFile; + try (FileInputStream fileReader = new FileInputStream(file); ObjectInputStream objectStream = new ObjectInputStream(fileReader)) { + studentsFromFile = (HashMap) objectStream.readObject(); + } + assertThat(studentsFromFile).isEqualTo(STUDENT_DATA); + } + + @Test + public void givenHashMap_whenSerializedToFileWithJackson_thenDeserializedMapIsIdentical() throws IOException { + // Given a map containing student data (STUDENT_DATA) + + // When converting to JSON with Jackson and writing to a file + ObjectMapper mapper = new ObjectMapper(); + try (FileOutputStream fileOutput = new FileOutputStream(file)) { + mapper.writeValue(fileOutput, STUDENT_DATA); + } + + // Then deserialize the file back into a map and check that it's identical + Map mapFromFile; + try (FileInputStream fileInput = new FileInputStream(file)) { + // Create a TypeReference so we can deserialize the parameterized type + TypeReference> mapType = new TypeReference>() { + }; + mapFromFile = mapper.readValue(fileInput, mapType); + } + assertThat(mapFromFile).isEqualTo(STUDENT_DATA); + } + + @Test + public void givenHashMap_whenSerializedToFileWithGson_thenDeserializedMapIsIdentical() throws IOException { + // Given a map containing student data (STUDENT_DATA) + + // When converting to JSON using Gson and writing to a file + Gson gson = new Gson(); + try (FileWriter writer = new FileWriter(file)) { + gson.toJson(STUDENT_DATA, writer); + } + + // Then deserialize the file back into a map and check that it's identical + Map studentsFromFile; + try (FileReader reader = new FileReader(file)) { + Type mapType = new TypeToken>() { + }.getType(); + studentsFromFile = gson.fromJson(reader, mapType); + } + assertThat(studentsFromFile).isEqualTo(STUDENT_DATA); + } +} From 573df300b06ea130e8d4762c71f4072ab0cfd81c Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sun, 12 Nov 2023 09:00:56 -0700 Subject: [PATCH 101/107] Fix indentation issues --- .../atomicinteger/Employee.java | 3 +- .../synchronizestatic/none/Employee.java | 3 +- .../reentrantlock/Employee.java | 3 +- .../synchronizedblock/Employee.java | 3 +- .../synchronizedclass/Employee.java | 3 +- .../SychronizeStaticDataUnitTest.java | 38 ++++++++----------- 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java index 9c3c9b987c..bb7c1c6b4c 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/atomicinteger/Employee.java @@ -13,8 +13,7 @@ public class Employee { String name; String title; - public Employee(int id, String name, String title) - { + public Employee(int id, String name, String title) { incrementCount(); this.id = id; this.name = name; diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java index f050a68be4..ba722e15e9 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/none/Employee.java @@ -10,8 +10,7 @@ public class Employee { String name; String title; - public Employee(int id, String name, String title) - { + public Employee(int id, String name, String title) { incrementCount(); this.id = id; this.name = name; diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java index 2ac0b0d3f2..e74013ad0e 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/reentrantlock/Employee.java @@ -14,8 +14,7 @@ public class Employee { String name; String title; - public Employee(int id, String name, String title) - { + public Employee(int id, String name, String title) { incrementCount(); this.id = id; this.name = name; diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java index 9c078e7abe..4cf04e5b06 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedblock/Employee.java @@ -12,8 +12,7 @@ public class Employee { String name; String title; - public Employee(int id, String name, String title) - { + public Employee(int id, String name, String title) { incrementCount(); this.id = id; this.name = name; diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java index a69b633f3b..627040e88c 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/synchronizestatic/synchronizedclass/Employee.java @@ -10,8 +10,7 @@ public class Employee String name; String title; - public Employee(int id, String name, String title) - { + public Employee(int id, String name, String title) { incrementCount(); this.id = id; this.name = name; diff --git a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java index e633005c6f..b4e03673a1 100644 --- a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/synchronizestatic/SychronizeStaticDataUnitTest.java @@ -11,8 +11,7 @@ import java.util.concurrent.Executors; * package. When not synchronized the out will not be sequential; * when it is synchronized the output will be in sequential. */ -public class SychronizeStaticDataUnitTest -{ +public class SychronizeStaticDataUnitTest { private final Executor pool = Executors.newFixedThreadPool(4); private final int numberToTest = 100; @@ -24,10 +23,9 @@ public class SychronizeStaticDataUnitTest for(int i = 0; i < numberToTest; i++) { int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.none.Employee(finalI, "John", "Smith"); - }); + pool.execute(() -> { + new com.baeldung.concurrent.synchronizestatic.none.Employee(finalI, "John", "Smith"); + }); } } @@ -38,10 +36,9 @@ public class SychronizeStaticDataUnitTest for(int i = 0; i < numberToTest; i++) { int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.synchronizedmethod.Employee(finalI, "John", "Smith"); - }); + pool.execute(() -> { + new com.baeldung.concurrent.synchronizestatic.synchronizedmethod.Employee(finalI, "John", "Smith"); + }); } } @@ -52,10 +49,9 @@ public class SychronizeStaticDataUnitTest for(int i = 0; i < numberToTest; i++) { int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.synchronizedclass.Employee(finalI, "John", "Smith"); - }); + pool.execute(() -> { + new com.baeldung.concurrent.synchronizestatic.synchronizedclass.Employee(finalI, "John", "Smith"); + }); } } @@ -66,10 +62,9 @@ public class SychronizeStaticDataUnitTest for(int i = 0; i < numberToTest; i++) { int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.synchronizedblock.Employee(finalI, "John", "Smith"); - }); + pool.execute(() -> { + new com.baeldung.concurrent.synchronizestatic.synchronizedblock.Employee(finalI, "John", "Smith"); + }); } } @@ -87,10 +82,9 @@ public class SychronizeStaticDataUnitTest for(int i = 0; i < numberToTest; i++) { int finalI = i; - pool.execute(() -> - { - new com.baeldung.concurrent.synchronizestatic.reentrantlock.Employee(finalI, "John", "Smith"); - }); + pool.execute(() -> { + new com.baeldung.concurrent.synchronizestatic.reentrantlock.Employee(finalI, "John", "Smith"); + }); } } } From ffe2c5780ebad433ca55f67e5b53f5251b9e8f3e Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Mon, 13 Nov 2023 12:05:47 +0530 Subject: [PATCH 102/107] JAVA-27194 Upgarde hibernate validator version in spring-mvc-java --- spring-web-modules/spring-mvc-java/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 8098f07282..745a6f45c0 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -101,7 +101,6 @@ org.hibernate.validator hibernate-validator - ${hibernate-validator.version} org.glassfish @@ -217,8 +216,6 @@ 6.0.10.Final 5.1.40 - - 6.0.10.Final 2.2.0 From 72391c6947feb37c1bf2783a57e7fe5ed9c7d246 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Mon, 13 Nov 2023 14:52:49 +0530 Subject: [PATCH 103/107] JAVA-27194 Upgrade hibernate validator version in spring-mvc-xml-2 --- spring-web-modules/spring-mvc-xml-2/pom.xml | 29 ++++++++----------- .../ConstraintViolationExceptionHandler.java | 2 +- ...stAndPathVariableValidationController.java | 10 +++---- .../baeldung/spring/taglibrary/Person.java | 2 +- .../spring/taglibrary/PersonController.java | 2 +- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/spring-web-modules/spring-mvc-xml-2/pom.xml b/spring-web-modules/spring-mvc-xml-2/pom.xml index 8c0062f538..49590758cc 100644 --- a/spring-web-modules/spring-mvc-xml-2/pom.xml +++ b/spring-web-modules/spring-mvc-xml-2/pom.xml @@ -10,8 +10,9 @@ com.baeldung - spring-web-modules + parent-spring-6 0.0.1-SNAPSHOT + ../../parent-spring-6 @@ -19,26 +20,18 @@ org.springframework spring-web - ${spring.version} org.springframework spring-webmvc - ${spring.version} - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} provided - - javax.servlet - jstl - ${jstl.version} - runtime - org.hibernate.validator hibernate-validator @@ -57,9 +50,9 @@ ${commons-io.version} - org.glassfish - javax.el - ${javax.el.version} + org.glassfish.expressly + expressly + ${expressly.version} org.springframework.boot @@ -98,9 +91,11 @@ 5.1.40 4.4.5 4.5.2 - 6.0.10.Final - 3.0.1-b08 + 8.0.1.Final + 5.0.0 1.6.1 + 6.0.0 + 3.1.5 \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java index 645b36c2a5..d3d833a696 100644 --- a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java +++ b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/controller/ConstraintViolationExceptionHandler.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import javax.validation.ConstraintViolationException; +import jakarta.validation.ConstraintViolationException; @ControllerAdvice public class ConstraintViolationExceptionHandler extends ResponseEntityExceptionHandler { diff --git a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/paramsvalidation/RequestAndPathVariableValidationController.java b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/paramsvalidation/RequestAndPathVariableValidationController.java index 4768237871..e1842564ac 100644 --- a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/paramsvalidation/RequestAndPathVariableValidationController.java +++ b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/paramsvalidation/RequestAndPathVariableValidationController.java @@ -7,11 +7,11 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; @Controller @RequestMapping("/public/api/1") diff --git a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/Person.java b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/Person.java index ed2fa903ef..a08f0f515c 100644 --- a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/Person.java +++ b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/Person.java @@ -2,7 +2,7 @@ package com.baeldung.spring.taglibrary; import java.util.List; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import org.springframework.web.multipart.MultipartFile; diff --git a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/PersonController.java b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/PersonController.java index 0fcb66f2dd..79e65b1fde 100644 --- a/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/PersonController.java +++ b/spring-web-modules/spring-mvc-xml-2/src/main/java/com/baeldung/spring/taglibrary/PersonController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import javax.validation.Valid; +import jakarta.validation.Valid; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; From 7d0c744c7c89d845b32cc4609fa98e40d876e2fd Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Mon, 13 Nov 2023 09:27:36 +0000 Subject: [PATCH 104/107] [JAVA-26433] Formatting (#15179) --- .../collectors/Java8CollectorsUnitTest.java | 155 ++++++++++-------- 1 file changed, 91 insertions(+), 64 deletions(-) diff --git a/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java b/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java index 085c1b5d7f..1faada9d23 100644 --- a/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java +++ b/core-java-modules/core-java-streams-simple/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java @@ -3,6 +3,7 @@ package com.baeldung.streams.collectors; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; + import org.junit.Test; import java.util.*; @@ -23,142 +24,159 @@ public class Java8CollectorsUnitTest { private final List listWithDuplicates = Arrays.asList("a", "bb", "c", "d", "bb"); @Test - public void whenCollectingToList_shouldCollectToList() throws Exception { - final List result = givenList.stream().collect(toList()); + public void whenCollectingToList_shouldCollectToList() { + final List result = givenList.stream() + .collect(toList()); assertThat(result).containsAll(givenList); } @Test public void whenCollectingToUnmodifiableList_shouldCollectToUnmodifiableList() { - final List result = givenList.stream().collect(toUnmodifiableList()); + final List result = givenList.stream() + .collect(toUnmodifiableList()); - assertThatThrownBy(() -> result.add("foo")) - .isInstanceOf(UnsupportedOperationException.class); + assertThatThrownBy(() -> result.add("foo")).isInstanceOf(UnsupportedOperationException.class); } @Test - public void whenCollectingToSet_shouldCollectToSet() throws Exception { - final Set result = givenList.stream().collect(toSet()); + public void whenCollectingToSet_shouldCollectToSet() { + final Set result = givenList.stream() + .collect(toSet()); assertThat(result).containsAll(givenList); } @Test public void whenCollectingToUnmodifiableSet_shouldCollectToUnmodifiableSet() { - final Set result = givenList.stream().collect(toUnmodifiableSet()); + final Set result = givenList.stream() + .collect(toUnmodifiableSet()); - assertThatThrownBy(() -> result.add("foo")) - .isInstanceOf(UnsupportedOperationException.class); + assertThatThrownBy(() -> result.add("foo")).isInstanceOf(UnsupportedOperationException.class); } @Test public void givenContainsDuplicateElements_whenCollectingToSet_shouldAddDuplicateElementsOnlyOnce() throws Exception { - final Set result = listWithDuplicates.stream().collect(toSet()); + final Set result = listWithDuplicates.stream() + .collect(toSet()); assertThat(result).hasSize(4); } @Test - public void whenCollectingToCollection_shouldCollectToCollection() throws Exception { - final List result = givenList.stream().collect(toCollection(LinkedList::new)); + public void whenCollectingToCollection_shouldCollectToCollection() { + final List result = givenList.stream() + .collect(toCollection(LinkedList::new)); - assertThat(result).containsAll(givenList).isInstanceOf(LinkedList.class); + assertThat(result).containsAll(givenList) + .isInstanceOf(LinkedList.class); } @Test - public void whenCollectingToImmutableCollection_shouldThrowException() throws Exception { + public void whenCollectingToImmutableCollection_shouldThrowException() { assertThatThrownBy(() -> { - givenList.stream().collect(toCollection(ImmutableList::of)); + givenList.stream() + .collect(toCollection(ImmutableList::of)); }).isInstanceOf(UnsupportedOperationException.class); } @Test - public void whenCollectingToMap_shouldCollectToMap() throws Exception { - final Map result = givenList.stream().collect(toMap(Function.identity(), String::length)); + public void whenCollectingToMap_shouldCollectToMap() { + final Map result = givenList.stream() + .collect(toMap(Function.identity(), String::length)); - assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2); + assertThat(result).containsEntry("a", 1) + .containsEntry("bb", 2) + .containsEntry("ccc", 3) + .containsEntry("dd", 2); } @Test public void whenCollectingToUnmodifiableMap_shouldCollectToUnmodifiableMap() { final Map result = givenList.stream() - .collect(toUnmodifiableMap(Function.identity(), String::length)); + .collect(toUnmodifiableMap(Function.identity(), String::length)); - assertThatThrownBy(() -> result.put("foo", 3)) - .isInstanceOf(UnsupportedOperationException.class); + assertThatThrownBy(() -> result.put("foo", 3)).isInstanceOf(UnsupportedOperationException.class); } @Test public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception { - final Map result = listWithDuplicates.stream().collect( - toMap( - Function.identity(), - String::length, - (item, identicalItem) -> item - ) - ); + final Map result = listWithDuplicates.stream() + .collect(toMap(Function.identity(), String::length, (item, identicalItem) -> item)); - assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("c", 1).containsEntry("d", 1); + assertThat(result).containsEntry("a", 1) + .containsEntry("bb", 2) + .containsEntry("c", 1) + .containsEntry("d", 1); } @Test - public void givenContainsDuplicateElements_whenCollectingToMap_shouldThrowException() throws Exception { + public void givenContainsDuplicateElements_whenCollectingToMap_shouldThrowException() { assertThatThrownBy(() -> { - listWithDuplicates.stream().collect(toMap(Function.identity(), String::length)); + listWithDuplicates.stream() + .collect(toMap(Function.identity(), String::length)); }).isInstanceOf(IllegalStateException.class); } @Test - public void whenCollectingAndThen_shouldCollect() throws Exception { - final List result = givenList.stream().collect(collectingAndThen(toList(), ImmutableList::copyOf)); + public void whenCollectingAndThen_shouldCollect() { + final List result = givenList.stream() + .collect(collectingAndThen(toList(), ImmutableList::copyOf)); - assertThat(result).containsAll(givenList).isInstanceOf(ImmutableList.class); + assertThat(result).containsAll(givenList) + .isInstanceOf(ImmutableList.class); } @Test - public void whenJoining_shouldJoin() throws Exception { - final String result = givenList.stream().collect(joining()); + public void whenJoining_shouldJoin() { + final String result = givenList.stream() + .collect(joining()); assertThat(result).isEqualTo("abbcccdd"); } @Test - public void whenJoiningWithSeparator_shouldJoinWithSeparator() throws Exception { - final String result = givenList.stream().collect(joining(" ")); + public void whenJoiningWithSeparator_shouldJoinWithSeparator() { + final String result = givenList.stream() + .collect(joining(" ")); assertThat(result).isEqualTo("a bb ccc dd"); } @Test - public void whenJoiningWithSeparatorAndPrefixAndPostfix_shouldJoinWithSeparatorPrePost() throws Exception { - final String result = givenList.stream().collect(joining(" ", "PRE-", "-POST")); + public void whenJoiningWithSeparatorAndPrefixAndPostfix_shouldJoinWithSeparatorPrePost() { + final String result = givenList.stream() + .collect(joining(" ", "PRE-", "-POST")); assertThat(result).isEqualTo("PRE-a bb ccc dd-POST"); } @Test - public void whenPartitioningBy_shouldPartition() throws Exception { - final Map> result = givenList.stream().collect(partitioningBy(s -> s.length() > 2)); + public void whenPartitioningBy_shouldPartition() { + final Map> result = givenList.stream() + .collect(partitioningBy(s -> s.length() > 2)); - assertThat(result).containsKeys(true, false).satisfies(booleanListMap -> { - assertThat(booleanListMap.get(true)).contains("ccc"); + assertThat(result).containsKeys(true, false) + .satisfies(booleanListMap -> { + assertThat(booleanListMap.get(true)).contains("ccc"); - assertThat(booleanListMap.get(false)).contains("a", "bb", "dd"); - }); + assertThat(booleanListMap.get(false)).contains("a", "bb", "dd"); + }); } @Test - public void whenCounting_shouldCount() throws Exception { - final Long result = givenList.stream().collect(counting()); + public void whenCounting_shouldCount() { + final Long result = givenList.stream() + .collect(counting()); assertThat(result).isEqualTo(4); } @Test - public void whenSummarizing_shouldSummarize() throws Exception { - final DoubleSummaryStatistics result = givenList.stream().collect(summarizingDouble(String::length)); + public void whenSummarizing_shouldSummarize() { + final DoubleSummaryStatistics result = givenList.stream() + .collect(summarizingDouble(String::length)); assertThat(result.getAverage()).isEqualTo(2); assertThat(result.getCount()).isEqualTo(4); @@ -168,38 +186,47 @@ public class Java8CollectorsUnitTest { } @Test - public void whenAveraging_shouldAverage() throws Exception { - final Double result = givenList.stream().collect(averagingDouble(String::length)); + public void whenAveraging_shouldAverage() { + final Double result = givenList.stream() + .collect(averagingDouble(String::length)); assertThat(result).isEqualTo(2); } @Test - public void whenSumming_shouldSum() throws Exception { - final Double result = givenList.stream().filter(i -> true).collect(summingDouble(String::length)); + public void whenSumming_shouldSum() { + final Double result = givenList.stream() + .collect(summingDouble(String::length)); assertThat(result).isEqualTo(8); } @Test - public void whenMaxingBy_shouldMaxBy() throws Exception { - final Optional result = givenList.stream().collect(maxBy(Comparator.naturalOrder())); + public void whenMaxingBy_shouldMaxBy() { + final Optional result = givenList.stream() + .collect(maxBy(Comparator.naturalOrder())); - assertThat(result).isPresent().hasValue("dd"); + assertThat(result).isPresent() + .hasValue("dd"); } @Test - public void whenGroupingBy_shouldGroupBy() throws Exception { - final Map> result = givenList.stream().collect(groupingBy(String::length, toSet())); + public void whenGroupingBy_shouldGroupBy() { + final Map> result = givenList.stream() + .collect(groupingBy(String::length, toSet())); - assertThat(result).containsEntry(1, newHashSet("a")).containsEntry(2, newHashSet("bb", "dd")).containsEntry(3, newHashSet("ccc")); + assertThat(result).containsEntry(1, newHashSet("a")) + .containsEntry(2, newHashSet("bb", "dd")) + .containsEntry(3, newHashSet("ccc")); } @Test - public void whenCreatingCustomCollector_shouldCollect() throws Exception { - final ImmutableSet result = givenList.stream().collect(toImmutableSet()); + public void whenCreatingCustomCollector_shouldCollect() { + final ImmutableSet result = givenList.stream() + .collect(toImmutableSet()); - assertThat(result).isInstanceOf(ImmutableSet.class).contains("a", "bb", "ccc", "dd"); + assertThat(result).isInstanceOf(ImmutableSet.class) + .contains("a", "bb", "ccc", "dd"); } From e82269d2069859be8ef9e1b253c5b95b7d34256e Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Mon, 13 Nov 2023 15:02:17 +0530 Subject: [PATCH 105/107] JAVA-27224 Upgrade parent-boot-3 to latest version of Boot (#15188) --- parent-boot-3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-boot-3/pom.xml b/parent-boot-3/pom.xml index dabcd7850b..9f9d6f7901 100644 --- a/parent-boot-3/pom.xml +++ b/parent-boot-3/pom.xml @@ -230,7 +230,7 @@ 3.3.0 2.22.2 - 3.1.2 + 3.1.5 5.8.2 0.9.17 17 From 21eb70547f10f84ac1be2b903f8a6d00742253ff Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:00:45 +0000 Subject: [PATCH 106/107] [JAVA-26719] Upgraded joda-time to latest version (#15189) --- .../core-java-8-datetime-2/pom.xml | 2 +- .../parsingDates/SimpleParseDate.java | 2 +- .../parsingDates/SimpleParseDateUnitTest.java | 42 +++++++++---------- .../core-java-8-datetime/pom.xml | 2 +- .../core-java-date-operations-1/pom.xml | 2 +- .../core-java-date-operations-2/pom.xml | 2 +- .../core-java-datetime-conversion/pom.xml | 2 +- json-modules/gson/pom.xml | 2 +- .../spring-data-couchbase-2/pom.xml | 2 +- spring-ejb-modules/ejb-beans/pom.xml | 2 +- spring-static-resources/pom.xml | 7 ---- testing-modules/rest-assured/pom.xml | 6 --- video-tutorials/jackson-annotations/pom.xml | 2 +- 13 files changed, 30 insertions(+), 45 deletions(-) diff --git a/core-java-modules/core-java-8-datetime-2/pom.xml b/core-java-modules/core-java-8-datetime-2/pom.xml index ce349d9dc3..02af06dc9d 100644 --- a/core-java-modules/core-java-8-datetime-2/pom.xml +++ b/core-java-modules/core-java-8-datetime-2/pom.xml @@ -55,7 +55,7 @@ 1.8 1.8 - 2.10 + 2.12.5 \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/parsingDates/SimpleParseDate.java b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/parsingDates/SimpleParseDate.java index cb024eea53..ba4f14ec5f 100644 --- a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/parsingDates/SimpleParseDate.java +++ b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/parsingDates/SimpleParseDate.java @@ -7,7 +7,7 @@ import java.util.List; public class SimpleParseDate { - public Date parseDate(String dateString, List formatStrings) { + public static Date parseDate(String dateString, List formatStrings) { for (String formatString : formatStrings) { try { return new SimpleDateFormat(formatString).parse(dateString); diff --git a/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/parsingDates/SimpleParseDateUnitTest.java b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/parsingDates/SimpleParseDateUnitTest.java index d7cbb6a834..ed8607fd96 100644 --- a/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/parsingDates/SimpleParseDateUnitTest.java +++ b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/parsingDates/SimpleParseDateUnitTest.java @@ -1,43 +1,41 @@ package com.baeldung.parsingDates; -import com.baeldung.parsingDates.SimpleDateTimeFormat; -import com.baeldung.parsingDates.SimpleDateTimeFormater; -import com.baeldung.parsingDates.SimpleDateUtils; -import com.baeldung.parsingDates.SimpleParseDate; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.time.format.DateTimeParseException; import java.util.Arrays; -import org.junit.*; -import static org.junit.Assert.*; + import org.joda.time.LocalDate; +import org.junit.jupiter.api.Test; -public class SimpleParseDateUnitTest { +class SimpleParseDateUnitTest { @Test - public void whenInvalidInput_thenGettingUnexpectedResult() { - SimpleParseDate simpleParseDate = new SimpleParseDate(); + void whenInvalidInput_thenGettingUnexpectedResult() { String date = "2022-40-40"; - assertEquals("Sat May 10 00:00:00 UTC 2025", simpleParseDate.parseDate(date, Arrays.asList("MM/dd/yyyy", "dd.MM.yyyy", "yyyy-MM-dd")).toString()); + assertEquals("Sat May 10 00:00:00 UTC 2025", SimpleParseDate.parseDate(date, Arrays.asList("MM/dd/yyyy", "dd.MM.yyyy", "yyyy-MM-dd")) + .toString()); } @Test - public void whenInvalidDate_thenAssertThrows() { - SimpleDateTimeFormater simpleDateTimeFormater = new SimpleDateTimeFormater(); - assertEquals(java.time.LocalDate.parse("2022-12-04"), simpleDateTimeFormater.parseDate("2022-12-04")); - assertThrows(DateTimeParseException.class, () -> simpleDateTimeFormater.parseDate("2022-13-04")); + void whenInvalidDate_thenAssertThrows() { + assertEquals(java.time.LocalDate.parse("2022-12-04"), SimpleDateTimeFormater.parseDate("2022-12-04")); + assertThrows(DateTimeParseException.class, () -> SimpleDateTimeFormater.parseDate("2022-13-04")); } @Test - public void whenDateIsCorrect_thenParseCorrect() { - SimpleDateUtils simpleDateUtils = new SimpleDateUtils(); - assertNull(simpleDateUtils.parseDate("53/10/2014")); - assertEquals("Wed Sep 10 00:00:00 UTC 2014", simpleDateUtils.parseDate("10/09/2014").toString()); + void whenDateIsCorrect_thenParseCorrect() { + assertNull(SimpleDateUtils.parseDate("53/10/2014")); + assertEquals("Wed Sep 10 00:00:00 UTC 2014", SimpleDateUtils.parseDate("10/09/2014") + .toString()); } @Test - public void whenDateIsCorrect_thenResultCorrect() { - SimpleDateTimeFormat simpleDateTimeFormat = new SimpleDateTimeFormat(); - assertNull(simpleDateTimeFormat.parseDate("53/10/2014")); - assertEquals(LocalDate.parse("2014-10-10"), simpleDateTimeFormat.parseDate("2014-10-10")); + void whenDateIsCorrect_thenResultCorrect() { + assertNull(SimpleDateTimeFormat.parseDate("53/10/2014")); + assertEquals(LocalDate.parse("2014-10-10"), SimpleDateTimeFormat.parseDate("2014-10-10")); } } diff --git a/core-java-modules/core-java-8-datetime/pom.xml b/core-java-modules/core-java-8-datetime/pom.xml index 481b1a6a69..06ecc3d017 100644 --- a/core-java-modules/core-java-8-datetime/pom.xml +++ b/core-java-modules/core-java-8-datetime/pom.xml @@ -56,7 +56,7 @@ 1.8 1.8 - 2.10 + 2.12.5 \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index 5bfbb5bab0..3d7335c86e 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -54,7 +54,7 @@ - 2.10 + 2.12.5 RELEASE 1.9 1.9 diff --git a/core-java-modules/core-java-date-operations-2/pom.xml b/core-java-modules/core-java-date-operations-2/pom.xml index c6a22a4166..86fbbf614e 100644 --- a/core-java-modules/core-java-date-operations-2/pom.xml +++ b/core-java-modules/core-java-date-operations-2/pom.xml @@ -47,7 +47,7 @@ - 2.10 + 2.12.5 1.5.1 3.2.7.Final 5.9 diff --git a/core-java-modules/core-java-datetime-conversion/pom.xml b/core-java-modules/core-java-datetime-conversion/pom.xml index 3ff26323df..8e148edaad 100644 --- a/core-java-modules/core-java-datetime-conversion/pom.xml +++ b/core-java-modules/core-java-datetime-conversion/pom.xml @@ -54,7 +54,7 @@ - 2.10 + 2.12.5 1.9 1.9 diff --git a/json-modules/gson/pom.xml b/json-modules/gson/pom.xml index ba968d9ae1..9e29bab3c4 100644 --- a/json-modules/gson/pom.xml +++ b/json-modules/gson/pom.xml @@ -65,7 +65,7 @@ 2.10.1 - 2.9.6 + 2.12.5 \ No newline at end of file diff --git a/persistence-modules/spring-data-couchbase-2/pom.xml b/persistence-modules/spring-data-couchbase-2/pom.xml index 45462d477e..eda2c45371 100644 --- a/persistence-modules/spring-data-couchbase-2/pom.xml +++ b/persistence-modules/spring-data-couchbase-2/pom.xml @@ -72,7 +72,7 @@ 6.0.6 5.0.3 8.0.1.Final - 2.12.2 + 2.12.5 \ No newline at end of file diff --git a/spring-ejb-modules/ejb-beans/pom.xml b/spring-ejb-modules/ejb-beans/pom.xml index 94f7963ad6..6203db5f5a 100644 --- a/spring-ejb-modules/ejb-beans/pom.xml +++ b/spring-ejb-modules/ejb-beans/pom.xml @@ -192,7 +192,7 @@ 2.21.0 2.8 8.2.1.Final - 2.10.12 + 2.12.5 \ No newline at end of file diff --git a/spring-static-resources/pom.xml b/spring-static-resources/pom.xml index f682eafdbe..173c5a5af0 100644 --- a/spring-static-resources/pom.xml +++ b/spring-static-resources/pom.xml @@ -121,12 +121,6 @@ hibernate-validator ${hibernate-validator.version} - - - joda-time - joda-time - ${joda-time.version} - com.github.jknack @@ -196,7 +190,6 @@ 6.0.10.Final 4.1.0 - 2.10 1 1.5.1 diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml index a4860b641d..d07e6d3b28 100644 --- a/testing-modules/rest-assured/pom.xml +++ b/testing-modules/rest-assured/pom.xml @@ -93,11 +93,6 @@ mail ${javax.mail.version} - - joda-time - joda-time - ${joda-time.version} - com.fasterxml.jackson.core jackson-annotations @@ -184,7 +179,6 @@ 4.5.2 0.9 8.0.0 - 2.9.6 1.1 1.2 2.27.2 diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index eaec50c1f7..611a337b0c 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -114,7 +114,7 @@ - 2.9.6 + 2.12.5 2.8.0 3.0.1 From 8325025cb7cddb8e7ffee50e533e65face3bfed3 Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Mon, 13 Nov 2023 23:08:31 +0530 Subject: [PATCH 107/107] JAVA-18764: Changes made for adding the H2 dependency for removing integration failure --- security-modules/cas/cas-secured-app/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/security-modules/cas/cas-secured-app/pom.xml b/security-modules/cas/cas-secured-app/pom.xml index 6e1b878354..7c4864b1c0 100644 --- a/security-modules/cas/cas-secured-app/pom.xml +++ b/security-modules/cas/cas-secured-app/pom.xml @@ -55,6 +55,11 @@ spring-security-test test + + com.h2database + h2 + ${h2.version} +