From 01f5b186a8b0bd61e0fff9aebd5465c1ac4ada40 Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Sat, 2 Jan 2021 14:49:45 +0530 Subject: [PATCH 01/61] BAEL-3636 - introduction to alibaba sentinel --- spring-cloud/pom.xml | 1 + spring-cloud/spring-cloud-sentinel/pom.xml | 35 +++++++++++++++++++ .../cloud/sentinel/SentinelApplication.java | 11 ++++++ .../config/SentinelAspectConfiguration.java | 35 +++++++++++++++++++ .../controller/GreetingController.java | 19 ++++++++++ .../sentinel/service/GreetingService.java | 19 ++++++++++ 6 files changed, 120 insertions(+) create mode 100644 spring-cloud/spring-cloud-sentinel/pom.xml create mode 100644 spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java create mode 100644 spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java create mode 100644 spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java create mode 100644 spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index c0e452afaf..efa9df40d9 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -44,6 +44,7 @@ spring-cloud-circuit-breaker spring-cloud-eureka-self-preservation + spring-cloud-sentinel diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml new file mode 100644 index 0000000000..8864baa7b2 --- /dev/null +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + spring-cloud-sentinel + spring-cloud-sentinel + http://maven.apache.org + pom + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-alibaba-sentinel + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + UTF-8 + + diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java new file mode 100644 index 0000000000..4459c8374d --- /dev/null +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java @@ -0,0 +1,11 @@ +package org.spring.cloud.sentinel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SentinelApplication { + public static void main(String[] args) { + SpringApplication.run(SentinelApplication.class, args); + } +} diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java new file mode 100644 index 0000000000..5241c59527 --- /dev/null +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java @@ -0,0 +1,35 @@ +package org.spring.cloud.sentinel.config; + +import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; + +@Configuration +public class SentinelAspectConfiguration { + + @Bean + public SentinelResourceAspect sentinelResourceAspect() { + return new SentinelResourceAspect(); + } + + @PostConstruct + public void initFlowRules() { + List flowRules = new ArrayList<>(); + FlowRule flowRule = new FlowRule(); + // Defined resource + flowRule.setResource("greeting"); + flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); + // number of requests that QPS can pass in a second + flowRule.setCount(1); + flowRules.add(flowRule); + FlowRuleManager.loadRules(flowRules); + } + +} diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java new file mode 100644 index 0000000000..83d68e6444 --- /dev/null +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java @@ -0,0 +1,19 @@ +package org.spring.cloud.sentinel.controller; + +import org.spring.cloud.sentinel.service.GreetingService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class GreetingController { + + @Autowired + private GreetingService greetingService; + + @GetMapping("/hello") + public String getGreeting() { + return greetingService.getGreeting(); + } + +} diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java new file mode 100644 index 0000000000..3c45401ca1 --- /dev/null +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java @@ -0,0 +1,19 @@ +package org.spring.cloud.sentinel.service; + +import com.alibaba.csp.sentinel.annotation.SentinelResource; +import org.springframework.stereotype.Service; + +@Service +public class GreetingService { + + @SentinelResource(value = "greeting", fallback = "getGreetingFallback") + public String getGreeting() { + return "Hello World!"; + } + + public String getGreetingFallback(Throwable e) { + e.printStackTrace(); + return "Bye world!"; + } + +} From 8b9ee317500fa365bcf1d9d031e83cacbf264fd9 Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Tue, 26 Jan 2021 11:00:31 +0530 Subject: [PATCH 02/61] BAEL-3636 remove duplicate spring web starter dependency --- spring-cloud/spring-cloud-sentinel/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml index 8864baa7b2..e1ed26a716 100644 --- a/spring-cloud/spring-cloud-sentinel/pom.xml +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -13,10 +13,6 @@ - - org.springframework.boot - spring-boot-starter-web - org.springframework.cloud spring-cloud-starter-alibaba-sentinel From 18d754bda4af1ad275e67810356461b4a87e6724 Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Tue, 26 Jan 2021 11:59:20 +0530 Subject: [PATCH 03/61] BAEL-3636 fix pom dependencies problem --- spring-cloud/spring-cloud-sentinel/pom.xml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml index e1ed26a716..e14fca0354 100644 --- a/spring-cloud/spring-cloud-sentinel/pom.xml +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -13,15 +13,19 @@ - - org.springframework.cloud - spring-cloud-starter-alibaba-sentinel - - org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-web + + + com.alibaba.csp + sentinel-core + 1.8.0 + + + com.alibaba.csp + sentinel-annotation-aspectj + 1.8.0 From 8cbc8d5a3ad2d0f25e671aca1617aa22840f1fa5 Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Tue, 9 Feb 2021 19:18:23 +0530 Subject: [PATCH 04/61] BAEL-3636 Change package name and format xml according to feedback --- spring-cloud/spring-cloud-sentinel/pom.xml | 64 ++++++++++--------- .../cloud/sentinel/SentinelApplication.java | 2 +- .../config/SentinelAspectConfiguration.java | 2 +- .../controller/GreetingController.java | 5 +- .../sentinel/service/GreetingService.java | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-) rename spring-cloud/spring-cloud-sentinel/src/main/java/{org => com/baeldung}/spring/cloud/sentinel/SentinelApplication.java (87%) rename spring-cloud/spring-cloud-sentinel/src/main/java/{org => com/baeldung}/spring/cloud/sentinel/config/SentinelAspectConfiguration.java (95%) rename spring-cloud/spring-cloud-sentinel/src/main/java/{org => com/baeldung}/spring/cloud/sentinel/controller/GreetingController.java (77%) rename spring-cloud/spring-cloud-sentinel/src/main/java/{org => com/baeldung}/spring/cloud/sentinel/service/GreetingService.java (88%) diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml index e14fca0354..a78cd8e74d 100644 --- a/spring-cloud/spring-cloud-sentinel/pom.xml +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -1,35 +1,37 @@ - - 4.0.0 - spring-cloud-sentinel - spring-cloud-sentinel - http://maven.apache.org - pom - - com.baeldung.spring.cloud - spring-cloud - 1.0.0-SNAPSHOT - + + 4.0.0 + spring-cloud-sentinel + spring-cloud-sentinel + http://maven.apache.org + pom + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + - - - org.springframework.boot - spring-boot-starter-web - - - com.alibaba.csp - sentinel-core - 1.8.0 - - - com.alibaba.csp - sentinel-annotation-aspectj - 1.8.0 - - + + + org.springframework.boot + spring-boot-starter-web + + + com.alibaba.csp + sentinel-core + 1.8.0 + + + com.alibaba.csp + sentinel-annotation-aspectj + 1.8.0 + + - - UTF-8 - + + UTF-8 + diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/SentinelApplication.java similarity index 87% rename from spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java rename to spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/SentinelApplication.java index 4459c8374d..4d921844df 100644 --- a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/SentinelApplication.java +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/SentinelApplication.java @@ -1,4 +1,4 @@ -package org.spring.cloud.sentinel; +package com.baeldung.spring.cloud.sentinel; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java similarity index 95% rename from spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java rename to spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java index 5241c59527..8ddceaa58f 100644 --- a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/config/SentinelAspectConfiguration.java +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java @@ -1,4 +1,4 @@ -package org.spring.cloud.sentinel.config; +package com.baeldung.spring.cloud.sentinel.config; import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; import com.alibaba.csp.sentinel.slots.block.RuleConstant; diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/controller/GreetingController.java similarity index 77% rename from spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java rename to spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/controller/GreetingController.java index 83d68e6444..fa3852466d 100644 --- a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/controller/GreetingController.java +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/controller/GreetingController.java @@ -1,10 +1,11 @@ -package org.spring.cloud.sentinel.controller; +package com.baeldung.spring.cloud.sentinel.controller; -import org.spring.cloud.sentinel.service.GreetingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.spring.cloud.sentinel.service.GreetingService; + @RestController public class GreetingController { diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/service/GreetingService.java similarity index 88% rename from spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java rename to spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/service/GreetingService.java index 3c45401ca1..e60d679b92 100644 --- a/spring-cloud/spring-cloud-sentinel/src/main/java/org/spring/cloud/sentinel/service/GreetingService.java +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/service/GreetingService.java @@ -1,4 +1,4 @@ -package org.spring.cloud.sentinel.service; +package com.baeldung.spring.cloud.sentinel.service; import com.alibaba.csp.sentinel.annotation.SentinelResource; import org.springframework.stereotype.Service; From 9b1388c6e2957bd573de889f6a2c3ba7f3961666 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 02:43:49 +0200 Subject: [PATCH 05/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../com/baeldung/hibernate/model/Branch.java | 98 +++++++++++++++++++ .../baeldung/hibernate/model/Employee.java | 84 ++++++++++++++++ .../lazyCollection/LazyCollectionTests.java | 95 ++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java create mode 100644 persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java create mode 100644 persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java new file mode 100644 index 0000000000..0369bc96ae --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java @@ -0,0 +1,98 @@ +package com.baeldung.hibernate.lazyCollection.model; + +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +public class Branch { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + public Branch() { + } + public Branch(String name) { + this.name = name; + } + + @OneToMany(mappedBy = "mainBranch") + @LazyCollection(LazyCollectionOption.TRUE) + private List mainEmployees; + + @OneToMany(mappedBy = "subBranch") + @LazyCollection(LazyCollectionOption.FALSE) + private List subEmployees; + + @OneToMany(mappedBy = "additionalBranch") + @LazyCollection(LazyCollectionOption.EXTRA) + @OrderColumn(name = "id") + private List additionalEmployees; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getMainEmployees() { + return mainEmployees; + } + + public void setMainEmployees(List mainEmployees) { + this.mainEmployees = mainEmployees; + } + + public List getSubEmployees() { + return subEmployees; + } + + public void setSubEmployees(List subEmployees) { + this.subEmployees = subEmployees; + } + + public List getAdditionalEmployees() { + return additionalEmployees; + } + + public void setAdditionalEmployees(List additionalEmployees) { + this.additionalEmployees = additionalEmployees; + } + + public void addMainEmployee(Employee employee) { + if (this.mainEmployees == null) { + this.mainEmployees = new ArrayList<>(); + } + this.mainEmployees.add(employee); + } + + public void addSubEmployee(Employee employee) { + if (this.subEmployees == null) { + this.subEmployees = new ArrayList<>(); + } + this.subEmployees.add(employee); + } + + public void addAdditionalEmployee(Employee employee) { + if (this.additionalEmployees == null) { + this.additionalEmployees = new ArrayList<>(); + } + this.additionalEmployees.add(employee); + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java new file mode 100644 index 0000000000..29c89bb94a --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java @@ -0,0 +1,84 @@ +package com.baeldung.hibernate.lazyCollection.model; + +import javax.persistence.*; + +@Entity +public class Employee { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + private Long rank; + + public Employee() { + + } + + public Employee(String name, Long rank, Branch mainBranch, Branch subBranch, Branch additionalBranch) { + this.name = name; + this.rank = rank; + this.mainBranch = mainBranch; + this.subBranch = subBranch; + this.additionalBranch = additionalBranch; + } + + @ManyToOne + private Branch mainBranch; + + @ManyToOne + private Branch subBranch; + + @ManyToOne + private Branch additionalBranch; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getRank() { + return rank; + } + + public void setRank(Long rank) { + this.rank = rank; + } + + public Branch getMainBranch() { + return mainBranch; + } + + public void setMainBranch(Branch mainBranch) { + this.mainBranch = mainBranch; + } + + public Branch getSubBranch() { + return subBranch; + } + + public void setSubBranch(Branch subBranch) { + this.subBranch = subBranch; + } + + public Branch getAdditionalBranch() { + return additionalBranch; + } + + public void setAdditionalBranch(Branch additionalBranch) { + this.additionalBranch = additionalBranch; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java new file mode 100644 index 0000000000..6f71959257 --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java @@ -0,0 +1,95 @@ +package com.baeldung.hibernate.lazyCollection; + +import com.baeldung.hibernate.lazyCollection.model.Branch; +import com.baeldung.hibernate.lazyCollection.model.Employee; +import org.hibernate.Hibernate; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.service.ServiceRegistry; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.PostConstruct; + +@SpringBootTest +public class LazyCollectionTests { + + private static SessionFactory sessionFactory; + + private Session session; + + Branch branch; + + @PostConstruct + public void beforeTests() { + Configuration configuration = new Configuration().addAnnotatedClass(Branch.class).addAnnotatedClass(Employee.class) + .setProperty("hibernate.dialect", H2Dialect.class.getName()) + .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) + .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") + .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "") + .setProperty("hibernate.hbm2ddl.auto", "update"); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()).build(); + + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + setUp(); + } + + private void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + + branch = new Branch("Main Branch"); + + session.save(branch); + + Employee mainEmployee1 = new Employee("main employee 1",1L, branch, null, null); + Employee mainEmployee2 = new Employee("main employee 2", 2L, branch, null, null); + Employee mainEmployee3 = new Employee("main employee 3", 3L, branch, null, null); + + session.save(mainEmployee1); + session.save(mainEmployee2); + session.save(mainEmployee3); + + Employee subEmployee1 = new Employee("sub employee 1", 1L, null, branch, null); + Employee subEmployee2 = new Employee("sub employee 2", 2L, null, branch, null); + Employee subEmployee3 = new Employee("sub employee 3", 3L, null, branch, null); + + session.save(subEmployee1); + session.save(subEmployee2); + session.save(subEmployee3); + + Employee additionalEmployee1 = new Employee("additional employee 1", 1L, null, null, branch); + Employee additionalEmployee2 = new Employee("additional employee 2", 2L, null, null, branch); + Employee additionalEmployee3 = new Employee("additional employee 3", 3L, null, null, branch); + + session.save(additionalEmployee1); + session.save(additionalEmployee2); + session.save(additionalEmployee3); + + session.flush(); + session.refresh(branch); + session.getTransaction().commit(); + session.close(); + } + + @Test + public void testLazyFetching() { + Assertions.assertFalse(Hibernate.isInitialized(branch.getMainEmployees())); + } + + @Test + public void testEagerFetching() { + Assertions.assertTrue(Hibernate.isInitialized(branch.getSubEmployees())); + } + + @Test + public void testExtraFetching() { + Assertions.assertFalse(Hibernate.isInitialized(branch.getAdditionalEmployees())); + } +} From 13b16b915a080934fbd4c799a36723ee67170c07 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 10:40:43 +0200 Subject: [PATCH 06/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../lazyCollection/LazyCollectionTests.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java index 6f71959257..14b35cfd7b 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java @@ -9,13 +9,16 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.H2Dialect; import org.hibernate.service.ServiceRegistry; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import javax.annotation.PostConstruct; -@SpringBootTest public class LazyCollectionTests { private static SessionFactory sessionFactory; @@ -24,8 +27,8 @@ public class LazyCollectionTests { Branch branch; - @PostConstruct - public void beforeTests() { + @BeforeClass + public static void beforeTests() { Configuration configuration = new Configuration().addAnnotatedClass(Branch.class).addAnnotatedClass(Employee.class) .setProperty("hibernate.dialect", H2Dialect.class.getName()) .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) @@ -37,10 +40,10 @@ public class LazyCollectionTests { sessionFactory = configuration.buildSessionFactory(serviceRegistry); - setUp(); } - private void setUp() { + @Before + public void setUp() { session = sessionFactory.openSession(); session.beginTransaction(); @@ -80,16 +83,27 @@ public class LazyCollectionTests { @Test public void testLazyFetching() { - Assertions.assertFalse(Hibernate.isInitialized(branch.getMainEmployees())); + Assert.assertFalse(Hibernate.isInitialized(branch.getMainEmployees())); } @Test public void testEagerFetching() { - Assertions.assertTrue(Hibernate.isInitialized(branch.getSubEmployees())); + Assert.assertTrue(Hibernate.isInitialized(branch.getSubEmployees())); } @Test public void testExtraFetching() { - Assertions.assertFalse(Hibernate.isInitialized(branch.getAdditionalEmployees())); + Assert.assertFalse(Hibernate.isInitialized(branch.getAdditionalEmployees())); + } + + @After + public void tearDown() { + session.getTransaction().commit(); + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); } } From 34b1a35afbd54c5f19c0b4ab43a2afa0833524b3 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 11:31:04 +0200 Subject: [PATCH 07/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../{LazyCollectionTests.java => LazyCollectionTest.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/{LazyCollectionTests.java => LazyCollectionTest.java} (98%) diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java similarity index 98% rename from persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java index 14b35cfd7b..9fa46fcc40 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTests.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java @@ -19,7 +19,7 @@ import org.junit.Test; import javax.annotation.PostConstruct; -public class LazyCollectionTests { +public class LazyCollectionTest { private static SessionFactory sessionFactory; @@ -51,7 +51,7 @@ public class LazyCollectionTests { session.save(branch); - Employee mainEmployee1 = new Employee("main employee 1",1L, branch, null, null); + Employee mainEmployee1 = new Employee("main employee 1", 1L, branch, null, null); Employee mainEmployee2 = new Employee("main employee 2", 2L, branch, null, null); Employee mainEmployee3 = new Employee("main employee 3", 3L, branch, null, null); From 5f2ea499261a452417738a5bcaf96178f3784102 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 11:41:27 +0200 Subject: [PATCH 08/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- ...zyCollectionTest.java => LazyCollectionIntegrationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/{LazyCollectionTest.java => LazyCollectionIntegrationTest.java} (98%) diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java similarity index 98% rename from persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java index 9fa46fcc40..d5eb9624b2 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionTest.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java @@ -19,7 +19,7 @@ import org.junit.Test; import javax.annotation.PostConstruct; -public class LazyCollectionTest { +public class LazyCollectionIntegrationTest { private static SessionFactory sessionFactory; From 5586a74acdd4f0026186c8dc08b5d70deaed96c4 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 15:47:38 +0200 Subject: [PATCH 09/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../{ => lazyCollection}/model/Branch.java | 0 .../{ => lazyCollection}/model/Employee.java | 13 ++++++------- .../LazyCollectionIntegrationTest.java | 18 +++++++++--------- 3 files changed, 15 insertions(+), 16 deletions(-) rename persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/{ => lazyCollection}/model/Branch.java (100%) rename persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/{ => lazyCollection}/model/Employee.java (83%) diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java similarity index 100% rename from persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Branch.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java similarity index 83% rename from persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java index 29c89bb94a..05949334c9 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/model/Employee.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java @@ -11,15 +11,14 @@ public class Employee { private String name; - private Long rank; + private String address; public Employee() { } - public Employee(String name, Long rank, Branch mainBranch, Branch subBranch, Branch additionalBranch) { + public Employee(String name, Branch mainBranch, Branch subBranch, Branch additionalBranch) { this.name = name; - this.rank = rank; this.mainBranch = mainBranch; this.subBranch = subBranch; this.additionalBranch = additionalBranch; @@ -50,12 +49,12 @@ public class Employee { this.name = name; } - public Long getRank() { - return rank; + public String getAddress() { + return address; } - public void setRank(Long rank) { - this.rank = rank; + public void setAddress(String address) { + this.address = address; } public Branch getMainBranch() { diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java index d5eb9624b2..cec57a3dbf 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java @@ -51,25 +51,25 @@ public class LazyCollectionIntegrationTest { session.save(branch); - Employee mainEmployee1 = new Employee("main employee 1", 1L, branch, null, null); - Employee mainEmployee2 = new Employee("main employee 2", 2L, branch, null, null); - Employee mainEmployee3 = new Employee("main employee 3", 3L, branch, null, null); + Employee mainEmployee1 = new Employee("main employee 1", branch, null, null); + Employee mainEmployee2 = new Employee("main employee 2", branch, null, null); + Employee mainEmployee3 = new Employee("main employee 3", branch, null, null); session.save(mainEmployee1); session.save(mainEmployee2); session.save(mainEmployee3); - Employee subEmployee1 = new Employee("sub employee 1", 1L, null, branch, null); - Employee subEmployee2 = new Employee("sub employee 2", 2L, null, branch, null); - Employee subEmployee3 = new Employee("sub employee 3", 3L, null, branch, null); + Employee subEmployee1 = new Employee("sub employee 1", null, branch, null); + Employee subEmployee2 = new Employee("sub employee 2", null, branch, null); + Employee subEmployee3 = new Employee("sub employee 3", null, branch, null); session.save(subEmployee1); session.save(subEmployee2); session.save(subEmployee3); - Employee additionalEmployee1 = new Employee("additional employee 1", 1L, null, null, branch); - Employee additionalEmployee2 = new Employee("additional employee 2", 2L, null, null, branch); - Employee additionalEmployee3 = new Employee("additional employee 3", 3L, null, null, branch); + Employee additionalEmployee1 = new Employee("additional employee 1", null, null, branch); + Employee additionalEmployee2 = new Employee("additional employee 2", null, null, branch); + Employee additionalEmployee3 = new Employee("additional employee 3", null, null, branch); session.save(additionalEmployee1); session.save(additionalEmployee2); From 342730c4a959034671a296904c28a3dca427758f Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 16 Feb 2021 15:48:06 +0200 Subject: [PATCH 10/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../com/baeldung/hibernate/lazyCollection/model/Branch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java index 0369bc96ae..3f9549ca3a 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java @@ -32,7 +32,7 @@ public class Branch { @OneToMany(mappedBy = "additionalBranch") @LazyCollection(LazyCollectionOption.EXTRA) - @OrderColumn(name = "id") + @OrderColumn(name = "order_id") private List additionalEmployees; public Long getId() { From 927b10e02e80bc74e376b562503d69534acff9c4 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 23 Feb 2021 15:51:13 +0200 Subject: [PATCH 11/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../model/Branch.java | 9 ++++++-- .../model/Employee.java | 9 ++++++-- .../LazyCollectionIntegrationTest.java | 21 ++++++++++--------- 3 files changed, 25 insertions(+), 14 deletions(-) rename persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/{lazyCollection => lazycollection}/model/Branch.java (89%) rename persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/{lazyCollection => lazycollection}/model/Employee.java (84%) rename persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/{lazyCollection => lazycollection}/LazyCollectionIntegrationTest.java (80%) diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Branch.java similarity index 89% rename from persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Branch.java index 3f9549ca3a..de88647546 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Branch.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Branch.java @@ -1,9 +1,14 @@ -package com.baeldung.hibernate.lazyCollection.model; +package com.baeldung.hibernate.lazycollection.model; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; -import javax.persistence.*; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OrderColumn; +import javax.persistence.OneToMany; +import javax.persistence.Entity; import java.util.ArrayList; import java.util.List; diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java similarity index 84% rename from persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java index 05949334c9..332e676439 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazyCollection/model/Employee.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java @@ -1,6 +1,11 @@ -package com.baeldung.hibernate.lazyCollection.model; +package com.baeldung.hibernate.lazycollection.model; -import javax.persistence.*; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OrderColumn; +import javax.persistence.OneToMany; +import javax.persistence.Entity; @Entity public class Employee { diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java similarity index 80% rename from persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java index cec57a3dbf..63ea1e1e3f 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazyCollection/LazyCollectionIntegrationTest.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java @@ -1,7 +1,7 @@ -package com.baeldung.hibernate.lazyCollection; +package com.baeldung.hibernate.lazycollection; -import com.baeldung.hibernate.lazyCollection.model.Branch; -import com.baeldung.hibernate.lazyCollection.model.Employee; +import com.baeldung.hibernate.lazycollection.model.Branch; +import com.baeldung.hibernate.lazycollection.model.Employee; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -29,14 +29,15 @@ public class LazyCollectionIntegrationTest { @BeforeClass public static void beforeTests() { - Configuration configuration = new Configuration().addAnnotatedClass(Branch.class).addAnnotatedClass(Employee.class) - .setProperty("hibernate.dialect", H2Dialect.class.getName()) - .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) - .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") - .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "") - .setProperty("hibernate.hbm2ddl.auto", "update"); + Configuration configuration = new Configuration().addAnnotatedClass(Branch.class) + .addAnnotatedClass(Employee.class).setProperty("hibernate.dialect", H2Dialect.class.getName()) + .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) + .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") + .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "") + .setProperty("hibernate.hbm2ddl.auto", "update"); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() - .applySettings(configuration.getProperties()).build(); + .applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); From 8a004c459a96f746e1c6bc5b134d86aa86706848 Mon Sep 17 00:00:00 2001 From: AbdallahSawan Date: Tue, 23 Feb 2021 15:56:18 +0200 Subject: [PATCH 12/61] Usage of the Hibernate @LazyCollection Annotation Article by Abdallah Sawan --- .../com/baeldung/hibernate/lazycollection/model/Employee.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java index 332e676439..831518a365 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/lazycollection/model/Employee.java @@ -4,7 +4,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OrderColumn; -import javax.persistence.OneToMany; +import javax.persistence.ManyToOne; import javax.persistence.Entity; @Entity From 8ba99b06c0b4c51dc5f55693002afc3e401fbd88 Mon Sep 17 00:00:00 2001 From: Carlos Cavero Date: Fri, 26 Feb 2021 18:15:59 +0100 Subject: [PATCH 13/61] Add Backpressure test to the spring-5-reactive-2 project --- .../backpressure/BackpressureServiceTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java new file mode 100644 index 0000000000..67ee1822b7 --- /dev/null +++ b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java @@ -0,0 +1,82 @@ +package com.baeldung.backpressure; + +import org.junit.jupiter.api.Test; +import reactor.core.publisher.BaseSubscriber; +import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; + +public class BackpressureServiceTest { + + @Test + public void whenLimitRateSet_thenSplitIntoChunks() throws InterruptedException { + Flux limit$ = Flux.range(1, 25); + + limit$.limitRate(10); + limit$.subscribe( + value -> System.out.println(value), + err -> err.printStackTrace(), + () -> System.out.println("Finished!!"), + subscription -> subscription.request(15) + ); + + StepVerifier.create(limit$) + .expectSubscription() + .thenRequest(15) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .expectNext(11, 12, 13, 14, 15) + .thenRequest(10) + .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25) + .verifyComplete(); + } + + @Test + public void whenRequestingChunks10_thenMessagesAreReceived() { + Flux request$ = Flux.range(1, 50); + + request$.subscribe( + System.out::println, + err -> err.printStackTrace(), + () -> System.out.println("All 50 items have been successfully processed!!!"), + subscription -> { + for (int i = 0; i < 5; i++) { + System.out.println("Requesting the next 10 elements!!!"); + subscription.request(10); + } + } + ); + + StepVerifier.create(request$) + .expectSubscription() + .thenRequest(10) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .thenRequest(10) + .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) + .thenRequest(10) + .expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30) + .thenRequest(10) + .expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40) + .thenRequest(10) + .expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50) + .verifyComplete(); + } + + @Test + public void whenCancel_thenSubscriptionFinished() { + Flux cancel$ = Flux.range(1, 10).log(); + + cancel$.subscribe(new BaseSubscriber() { + @Override + protected void hookOnNext(Integer value) { + request(3); + System.out.println(value); + cancel(); + } + }); + + StepVerifier.create(cancel$) + .expectNext(1, 2, 3) + .thenCancel() + .verify(); + } +} + From 86a8634c787e175a0fc645eef0b22713e1592698 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sun, 21 Mar 2021 12:29:38 +0330 Subject: [PATCH 14/61] bael-4828: add main source --- .../java/com/baeldung/tls/HomeController.java | 16 +++++++++++++ .../java/com/baeldung/tls/SecurityConfig.java | 16 +++++++++++++ .../baeldung/tls/TLSEnabledApplication.java | 15 ++++++++++++ .../main/resources/application-tls.properties | 23 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java new file mode 100644 index 0000000000..c72821cc9b --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java @@ -0,0 +1,16 @@ +package com.baeldung.tls; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/baeldung") + public ResponseEntity welcome() { + return new ResponseEntity<>("tls/baeldung", HttpStatus.OK); + } + +} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java new file mode 100644 index 0000000000..63b59b8cc8 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.tls; + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/**") + .permitAll(); + } +} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java new file mode 100644 index 0000000000..62ba77d769 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.tls; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +public class TLSEnabledApplication { + + public static void main(String... args) { + SpringApplication application = new SpringApplication(TLSEnabledApplication.class); + application.setAdditionalProfiles("tls"); + application.run(args); + } +} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties new file mode 100644 index 0000000000..002d702eab --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties @@ -0,0 +1,23 @@ + +server.port=8443 + +# enable/disable https +server.ssl.enabled=true +# keystore format +server.ssl.key-store-type=PKCS12 +# keystore location +server.ssl.key-store=classpath:keystore/keystore.p12 +# keystore password +server.ssl.key-store-password=changeit +server.ssl.key-alias=baeldung +# SSL protocol to use +server.ssl.protocol=TLS +# Enabled SSL protocols +server.ssl.enabled-protocols=TLSv1.2 + +#server.ssl.client-auth=need + +#trust store location +#server.ssl.trust-store=classpath:keystore/truststore.p12 +#trust store password +#server.ssl.trust-store-password=changeit \ No newline at end of file From 3a0e5ecf68e10690aed030113f28741c43dc30b1 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sun, 21 Mar 2021 12:30:03 +0330 Subject: [PATCH 15/61] bael-4828: add keystore and certificate files --- .../src/main/resources/keystore/baeldung.cer | 28 ++++++++++++++++++ .../src/main/resources/keystore/keystore.p12 | Bin 0 -> 4083 bytes 2 files changed, 28 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer create mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer new file mode 100644 index 0000000000..1a6bb4d49b --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIExzCCAq+gAwIBAgIEbh/WszANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDEwls +b2NhbGhvc3QwHhcNMjEwMzIxMDgzMzU3WhcNMzEwMzE5MDgzMzU3WjAUMRIwEAYD +VQQDEwlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCD +QWvAEewDE+vFFqYPgXFJ94bMgPZT6qdb17DkWWbL2jV5QENbSYTLAPNQ1TGUgKhj +t1LCHpooLwWIo6xvhK/qZYjh3YonSIe8Eo0fBCDoZpLO+Vp0us22NBgLOYH8hvAm +zEvPXdSZo5Qkeaqjwd6kB/z083y8OL+Civ0ARXoLsn7CFslKfZp2o/aebH6i/T+3 +hWVqasIIMtfNUrxE/pnOnV8aSAt24jcm/VxbtheqIzmcOPlCXSP1RAmFez6tJsNu +2dbUhaeOf95RCaM6a43soEvLvooGa/uqBPsRojg5WEFGf7Tc7pzB+BtALwRmHAqr +hiYjVv329QGZ+g8dADBvvqvGpGysy+X0LxixvIP14KdCqG8uMYmw5cBTJHc23AHV +iP+JsfDtdu+bzZeOZmhSsv4M3DZ1QPHEX+zCnotE+SeycqEr+3SaJELyjCB1twFT +pCRCQGWFKYCRwhjQ1vGY7qhD6ZDn30a96xAlPS+T35pA01rNgORJi8j9sf3oiwEe +oPQOecgFHdua5drHJ78j7MUz/Gvj02GnwKnBKbMYDGeBKJWm0ir4MxoU7HPaDwLj +jofXgIz+CMXkp+9arVu5IsZwL2MKNZ4fiM+VWZg9R73CAVpKvs6dTlQXe++DCaOr +XGiQeCPPpIC74vqWhAHuzPncGJndHlmXYGLhi0sk0wIDAQABoyEwHzAdBgNVHQ4E +FgQUhW4a3uWREJoTxodyD5u7i7mCaacwDQYJKoZIhvcNAQELBQADggIBAD/Qfkot +qklQr4r7eoHtyFCGozfZvsPwEediZORkycU/fCZozdVh95ebt2/N/jw7RlNhv+t+ +HahMoiXbLX2RUrqM/2X5U7BbxIpy3XjhcEYTJudqFfCxDQfxD1bFrWHygQzAanOb +sPHkcEt3tu2suV2YsJpHry/1BMo83WAoTgw/3dFtJ7oEoi/LaI03v9Qlp0+hLfA5 +zwyuuRqFn24FRvdWHX5GqAweF+WUdmmlkiJiKu2RtQsPoN7ITvZQs9t4l0zZ8w2v +QV0YdhWYLkS3g53oyOP8T5YlCFGuUOyo433hRyrzaxj3aFDkMbNrX9REB9v8Iz7X +aFsmLDJsfT5Spovz68HCIMDW1Sl1WqVkNN2V3Rwt72bn7DEbKZzGW9RC5eXEW1Zw +46XeYOVdEjzl/l623moWC5ZTlwPF1qRDaoZXT/1d1eAJE8ZBHm1YjwgDD5aFvylG +0OT1qWD5gx3nOmAbBk1e3r8ESMo9k29/4hycUUUgtFuWtBwBaY/O/4YoLx59wbpL +rFR/zjKIdYFj0AM2ABTgrG7v5pEhjLTnzjc+mZV7hJCBvB+bbC5vvfDg0K7lQUpJ +ruIPvqKfJyuTwkKmoTF5jmG04jwUDtA5iGUB3U3QiQ8zcbTiVRptXLEQDYw/bzDk +0fd4xTbok1ygI7wJ/KRyMvFXdbTKSvVu/tnM +-----END CERTIFICATE----- diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..6f0d9c508cc70edfb43979b88cc08b2d1155d0c6 GIT binary patch literal 4083 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 Date: Sun, 21 Mar 2021 18:57:06 +0530 Subject: [PATCH 16/61] BAEL-3636 Add sentinel dashboard dependency --- spring-cloud/spring-cloud-sentinel/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml index a78cd8e74d..c8f79f5f40 100644 --- a/spring-cloud/spring-cloud-sentinel/pom.xml +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -29,6 +29,11 @@ sentinel-annotation-aspectj 1.8.0 + + com.alibaba.csp + sentinel-transport-simple-http + 1.8.0 + From ce2995c1cd42a21d8a392ba9fd674a968b71df4c Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Sun, 21 Mar 2021 19:23:03 +0530 Subject: [PATCH 17/61] BAEL-3636 Use spaces instead of tabs --- spring-cloud/spring-cloud-sentinel/pom.xml | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/spring-cloud/spring-cloud-sentinel/pom.xml b/spring-cloud/spring-cloud-sentinel/pom.xml index c8f79f5f40..612cbcbfbe 100644 --- a/spring-cloud/spring-cloud-sentinel/pom.xml +++ b/spring-cloud/spring-cloud-sentinel/pom.xml @@ -1,42 +1,42 @@ - 4.0.0 - spring-cloud-sentinel - spring-cloud-sentinel - http://maven.apache.org - pom - - com.baeldung.spring.cloud - spring-cloud - 1.0.0-SNAPSHOT - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + spring-cloud-sentinel + spring-cloud-sentinel + http://maven.apache.org + pom + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + - - - org.springframework.boot - spring-boot-starter-web - - - com.alibaba.csp - sentinel-core - 1.8.0 - - - com.alibaba.csp - sentinel-annotation-aspectj - 1.8.0 - - - com.alibaba.csp - sentinel-transport-simple-http - 1.8.0 - - + + + org.springframework.boot + spring-boot-starter-web + + + com.alibaba.csp + sentinel-core + 1.8.0 + + + com.alibaba.csp + sentinel-annotation-aspectj + 1.8.0 + + + com.alibaba.csp + sentinel-transport-simple-http + 1.8.0 + + - - UTF-8 - + + UTF-8 + From a6b215d7a35c293f0c4fdd6ff556ed457c890221 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 14 Mar 2021 08:38:24 +0530 Subject: [PATCH 18/61] BAEL-4810 Spring Boot with JSP initial sample commit --- spring-web-modules/pom.xml | 1 + spring-web-modules/spring-boot-jsp/README.md | 6 ++ spring-web-modules/spring-boot-jsp/pom.xml | 86 +++++++++++++++++++ .../boot/jsp/SpringBootJspApplication.java | 19 ++++ .../boot/jsp/SpringBootJspConfiguration.java | 30 +++++++ .../boot/jsp/controller/BookController.java | 45 ++++++++++ .../java/com/baeldung/boot/jsp/dto/Book.java | 14 +++ .../jsp/exception/DuplicateBookException.java | 13 +++ .../exception/LibraryControllerAdvice.java | 19 ++++ .../boot/jsp/repository/BookRepository.java | 14 +++ .../impl/InMemoryBookRepository.java | 36 ++++++++ .../boot/jsp/repository/model/BookData.java | 16 ++++ .../boot/jsp/service/BookService.java | 11 +++ .../jsp/service/impl/BookServiceImpl.java | 50 +++++++++++ .../src/main/resources/application.properties | 4 + .../src/main/resources/static/css/common.css | 10 +++ .../src/main/resources/static/error/4xx.html | 10 +++ .../src/main/webapp/WEB-INF/jsp/add-book.jsp | 23 +++++ .../main/webapp/WEB-INF/jsp/error-book.jsp | 18 ++++ .../main/webapp/WEB-INF/jsp/view-books.jsp | 30 +++++++ 20 files changed, 455 insertions(+) create mode 100644 spring-web-modules/spring-boot-jsp/README.md create mode 100644 spring-web-modules/spring-boot-jsp/pom.xml create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspApplication.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/controller/BookController.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/dto/Book.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/DuplicateBookException.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/LibraryControllerAdvice.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/BookRepository.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepository.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/model/BookData.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/BookService.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/impl/BookServiceImpl.java create mode 100644 spring-web-modules/spring-boot-jsp/src/main/resources/application.properties create mode 100644 spring-web-modules/spring-boot-jsp/src/main/resources/static/css/common.css create mode 100644 spring-web-modules/spring-boot-jsp/src/main/resources/static/error/4xx.html create mode 100644 spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp create mode 100644 spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp create mode 100644 spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 37ee84da25..ca96dcff35 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -41,6 +41,7 @@ spring-thymeleaf spring-thymeleaf-2 spring-thymeleaf-3 + spring-boot-jsp diff --git a/spring-web-modules/spring-boot-jsp/README.md b/spring-web-modules/spring-boot-jsp/README.md new file mode 100644 index 0000000000..8242461917 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/README.md @@ -0,0 +1,6 @@ +## Spring MVC Forms JSP + +This module contains articles about Spring Boot used with JSP + +### Relevant Articles +- [Spring Boot with JSP](https://www.baeldung.com/?) diff --git a/spring-web-modules/spring-boot-jsp/pom.xml b/spring-web-modules/spring-boot-jsp/pom.xml new file mode 100644 index 0000000000..1599f4aa34 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + com.baeldung + spring-boot-jsp + 0.0.1-SNAPSHOT + spring-boot-jsp + war + + + com.baeldung + spring-web-modules + 0.0.1-SNAPSHOT + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + javax.servlet + jstl + ${jstl.version} + + + org.apache.tomcat.embed + tomcat-embed-jasper + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + + + + spring-boot-jsp + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.boot.jsp.SpringBootJspApplication + + + + + repackage + + + + + + + + + 1.2 + 2.4.0 + + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspApplication.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspApplication.java new file mode 100644 index 0000000000..c77554f9f6 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspApplication.java @@ -0,0 +1,19 @@ +package com.baeldung.boot.jsp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication(scanBasePackages = "com.baeldung.boot.jsp") +public class SpringBootJspApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(SpringBootJspApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SpringBootJspApplication.class); + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java new file mode 100644 index 0000000000..83847a40a3 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java @@ -0,0 +1,30 @@ +package com.baeldung.boot.jsp; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.impl.InMemoryBookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; + +@Configuration +@ComponentScan(basePackages = "com.baeldung.boot.jsp") +public class SpringBootJspConfiguration { + + @Bean + public BookRepository provideBookRepository() { + return new InMemoryBookRepository(initialBookData()); + } + + private static Map initialBookData() { + Map initData = new HashMap<>(); + initData.put("ISBN-TEST-1", new BookData("ISBN-TEST-1", "Book 1", "Book 1 Author")); + initData.put("ISBN-TEST-2", new BookData("ISBN-TEST-2", "Book 2", "Book 2 Author")); + initData.put("ISBN-TEST-3", new BookData("ISBN-TEST-3", "Book 3", "Book 3 Author")); + return initData; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/controller/BookController.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/controller/BookController.java new file mode 100644 index 0000000000..c104a9cad3 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/controller/BookController.java @@ -0,0 +1,45 @@ +package com.baeldung.boot.jsp.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.springframework.web.servlet.view.RedirectView; + +import com.baeldung.boot.jsp.dto.Book; +import com.baeldung.boot.jsp.service.BookService; + +@Controller +@RequestMapping("/book") +public class BookController { + + private final BookService bookService; + + public BookController(BookService bookService) { + this.bookService = bookService; + } + + @GetMapping("/viewBooks") + public String viewBooks(Model model) { + model.addAttribute("books", bookService.getBooks()); + return "view-books"; + } + + @GetMapping("/addBook") + public String addBookView(Model model) { + model.addAttribute("book", new Book()); + return "add-book"; + } + + @PostMapping("/addBook") + public RedirectView addBook(@ModelAttribute("book") Book book, RedirectAttributes redirectAttributes) { + final RedirectView redirectView = new RedirectView("/book/addBook", true); + Book savedBook = bookService.addBook(book); + redirectAttributes.addFlashAttribute("savedBook", savedBook); + redirectAttributes.addFlashAttribute("addBookSuccess", true); + return redirectView; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/dto/Book.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/dto/Book.java new file mode 100644 index 0000000000..f4cd6b0b3b --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/dto/Book.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.jsp.dto; + +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class Book { + private String isbn; + private String name; + private String author; +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/DuplicateBookException.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/DuplicateBookException.java new file mode 100644 index 0000000000..bd52a591e3 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/DuplicateBookException.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.jsp.exception; + +import com.baeldung.boot.jsp.dto.Book; +import lombok.Getter; + +@Getter +public class DuplicateBookException extends RuntimeException { + private final Book book; + + public DuplicateBookException(Book book) { + this.book = book; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/LibraryControllerAdvice.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/LibraryControllerAdvice.java new file mode 100644 index 0000000000..8217fea2e3 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/exception/LibraryControllerAdvice.java @@ -0,0 +1,19 @@ +package com.baeldung.boot.jsp.exception; + +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.servlet.ModelAndView; + +@ControllerAdvice +public class LibraryControllerAdvice { + + @ExceptionHandler(value = DuplicateBookException.class) + public ModelAndView duplicateBookException(DuplicateBookException e) { + final ModelAndView modelAndView = new ModelAndView(); + modelAndView.addObject("ref", e.getBook().getIsbn()); + modelAndView.addObject("object", e.getBook()); + modelAndView.addObject("message", "Cannot add an already existing book"); + modelAndView.setViewName("error-book"); + return modelAndView; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/BookRepository.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/BookRepository.java new file mode 100644 index 0000000000..f10cecfa81 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/BookRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.jsp.repository; + +import java.util.Collection; +import java.util.Optional; + +import com.baeldung.boot.jsp.repository.model.BookData; + +public interface BookRepository { + Collection findAll(); + + Optional findById(String isbn); + + BookData add(BookData book); +} diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepository.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepository.java new file mode 100644 index 0000000000..8fae303158 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepository.java @@ -0,0 +1,36 @@ +package com.baeldung.boot.jsp.repository.impl; + +import java.util.*; + +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; + +public class InMemoryBookRepository implements BookRepository { + + private final Map storedBooks; + + public InMemoryBookRepository(Map storedBooks) { + this.storedBooks = new HashMap<>(); + this.storedBooks.putAll(storedBooks); + } + + @Override + public Collection findAll() { + if (storedBooks.isEmpty()) { + return Collections.emptyList(); + } + + return storedBooks.values(); + } + + @Override + public Optional findById(String isbn) { + return Optional.ofNullable(storedBooks.get(isbn)); + } + + @Override + public BookData add(BookData book) { + storedBooks.put(book.getIsbn(), book); + return book; + } +} diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/model/BookData.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/model/BookData.java new file mode 100644 index 0000000000..7c722a92e5 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/repository/model/BookData.java @@ -0,0 +1,16 @@ +package com.baeldung.boot.jsp.repository.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class BookData { + private String isbn; + private String name; + private String author; +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/BookService.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/BookService.java new file mode 100644 index 0000000000..7c2c401ef2 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/BookService.java @@ -0,0 +1,11 @@ +package com.baeldung.boot.jsp.service; + +import java.util.Collection; + +import com.baeldung.boot.jsp.dto.Book; + +public interface BookService { + Collection getBooks(); + + Book addBook(Book book); +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/impl/BookServiceImpl.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/impl/BookServiceImpl.java new file mode 100644 index 0000000000..519ee19205 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/service/impl/BookServiceImpl.java @@ -0,0 +1,50 @@ +package com.baeldung.boot.jsp.service.impl; + +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; + +import com.baeldung.boot.jsp.exception.DuplicateBookException; +import org.springframework.stereotype.Service; + +import com.baeldung.boot.jsp.dto.Book; +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; +import com.baeldung.boot.jsp.service.BookService; + +@Service +public class BookServiceImpl implements BookService { + + private final BookRepository bookRepository; + + public BookServiceImpl(BookRepository bookRepository) { + this.bookRepository = bookRepository; + } + + @Override + public Collection getBooks() { + return bookRepository.findAll() + .stream() + .map(BookServiceImpl::convertBookData) + .collect(Collectors.toList()); + } + + @Override + public Book addBook(Book book) { + final Optional existingBook = bookRepository.findById(book.getIsbn()); + if (existingBook.isPresent()) { + throw new DuplicateBookException(book); + } + + final BookData savedBook = bookRepository.add(convertBook(book)); + return convertBookData(savedBook); + } + + private static Book convertBookData(BookData bookData) { + return new Book(bookData.getIsbn(), bookData.getName(), bookData.getAuthor()); + } + + private static BookData convertBook(Book book) { + return new BookData(book.getIsbn(), book.getName(), book.getAuthor()); + } +} diff --git a/spring-web-modules/spring-boot-jsp/src/main/resources/application.properties b/spring-web-modules/spring-boot-jsp/src/main/resources/application.properties new file mode 100644 index 0000000000..56638f8c1a --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.servlet.context-path=/spring-boot-jsp + +spring.mvc.view.prefix: /WEB-INF/jsp/ +spring.mvc.view.suffix: .jsp \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/resources/static/css/common.css b/spring-web-modules/spring-boot-jsp/src/main/resources/static/css/common.css new file mode 100644 index 0000000000..a32d81c6a2 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/resources/static/css/common.css @@ -0,0 +1,10 @@ +table { + font-family: arial, sans-serif; + border-collapse: collapse; +} + +td, th { + border: 1px solid #dddddd; + text-align: left; + padding: 8px; +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/resources/static/error/4xx.html b/spring-web-modules/spring-boot-jsp/src/main/resources/static/error/4xx.html new file mode 100644 index 0000000000..c27bd8bb7a --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/resources/static/error/4xx.html @@ -0,0 +1,10 @@ + + + + + Error + + +Opps! 4xx Error Occurred. + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp new file mode 100644 index 0000000000..3b815dfafb --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp @@ -0,0 +1,23 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Add Book + + + + +
Successfully added Book with ISBN: ${savedBook.isbn}
+
+ + + + ISBN: + Book Name: + Author Name: + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp new file mode 100644 index 0000000000..c04756462d --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp @@ -0,0 +1,18 @@ +<%-- + Created by IntelliJ IDEA. + User: jason + Date: 3/13/21 + Time: 10:39 PM + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Error + + +

Reference: ${ref}

+

Error Message: ${message}

+

Object: ${object}

+ + diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp new file mode 100644 index 0000000000..46bfbbac99 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp @@ -0,0 +1,30 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + View Books + + " rel="stylesheet" type="text/css"> + + + + + + + + + + + + + + + + + + + + +
ISBNNameAuthor
${book.isbn}${book.name}${book.author}
+ + \ No newline at end of file From c5e0771e1de17e1037c6cb9bca2bb6271f84a92e Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 21 Mar 2021 10:23:56 +0530 Subject: [PATCH 19/61] BAEL-4810: First Review Improvements. Added test cases and fixed some indentations --- spring-web-modules/spring-boot-jsp/pom.xml | 24 ++++- .../boot/jsp/SpringBootJspConfiguration.java | 9 +- .../src/main/webapp/WEB-INF/jsp/add-book.jsp | 32 +++---- .../main/webapp/WEB-INF/jsp/error-book.jsp | 16 ++-- .../main/webapp/WEB-INF/jsp/view-books.jsp | 46 +++++---- .../BookControllerIntegrationTest.java | 93 +++++++++++++++++++ .../controller/BookControllerUnitTest.java | 76 +++++++++++++++ .../impl/InMemoryBookRepositoryUnitTest.java | 62 +++++++++++++ .../service/BookServiceIntegrationTest.java | 84 +++++++++++++++++ .../service/impl/BookServiceImplUnitTest.java | 75 +++++++++++++++ 10 files changed, 460 insertions(+), 57 deletions(-) create mode 100644 spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerIntegrationTest.java create mode 100644 spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerUnitTest.java create mode 100644 spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepositoryUnitTest.java create mode 100644 spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/BookServiceIntegrationTest.java create mode 100644 spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/impl/BookServiceImplUnitTest.java diff --git a/spring-web-modules/spring-boot-jsp/pom.xml b/spring-web-modules/spring-boot-jsp/pom.xml index 1599f4aa34..672cc8b426 100644 --- a/spring-web-modules/spring-boot-jsp/pom.xml +++ b/spring-web-modules/spring-boot-jsp/pom.xml @@ -37,7 +37,7 @@ org.apache.tomcat.embed tomcat-embed-jasper - + @@ -50,12 +50,29 @@ org.springframework.boot spring-boot-starter-web - + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + org.springframework.boot + spring-boot-starter-test + test + @@ -80,7 +97,8 @@ 1.2 - 2.4.0 + 5.7.1 + 2.4.4 \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java index 83847a40a3..7fdae2c2a6 100644 --- a/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java +++ b/spring-web-modules/spring-boot-jsp/src/main/java/com/baeldung/boot/jsp/SpringBootJspConfiguration.java @@ -3,8 +3,8 @@ package com.baeldung.boot.jsp; import java.util.HashMap; import java.util.Map; +import org.springframework.boot.SpringBootConfiguration; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import com.baeldung.boot.jsp.repository.BookRepository; @@ -12,7 +12,6 @@ import com.baeldung.boot.jsp.repository.impl.InMemoryBookRepository; import com.baeldung.boot.jsp.repository.model.BookData; @Configuration -@ComponentScan(basePackages = "com.baeldung.boot.jsp") public class SpringBootJspConfiguration { @Bean @@ -22,9 +21,9 @@ public class SpringBootJspConfiguration { private static Map initialBookData() { Map initData = new HashMap<>(); - initData.put("ISBN-TEST-1", new BookData("ISBN-TEST-1", "Book 1", "Book 1 Author")); - initData.put("ISBN-TEST-2", new BookData("ISBN-TEST-2", "Book 2", "Book 2 Author")); - initData.put("ISBN-TEST-3", new BookData("ISBN-TEST-3", "Book 3", "Book 3 Author")); + initData.put("ISBN-1", new BookData("ISBN-1", "Book 1", "Book 1 Author")); + initData.put("ISBN-2", new BookData("ISBN-2", "Book 2", "Book 2 Author")); + initData.put("ISBN-3", new BookData("ISBN-3", "Book 3", "Book 3 Author")); return initData; } } \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp index 3b815dfafb..8195743da8 100644 --- a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/add-book.jsp @@ -2,22 +2,20 @@ <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> - - Add Book - - + + Add Book + + + +
Successfully added Book with ISBN: ${savedBook.isbn}
+
- -
Successfully added Book with ISBN: ${savedBook.isbn}
-
- - - - ISBN: - Book Name: - Author Name: - - - - + + + ISBN: + Book Name: + Author Name: + + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp index c04756462d..6db90ca5c7 100644 --- a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/error-book.jsp @@ -7,12 +7,12 @@ --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> - - Error - - -

Reference: ${ref}

-

Error Message: ${message}

-

Object: ${object}

- + + Error + + +

Reference: ${ref}

+

Error Message: ${message}

+

Object: ${object}

+ diff --git a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp index 46bfbbac99..4a8e00a69b 100644 --- a/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp +++ b/spring-web-modules/spring-boot-jsp/src/main/webapp/WEB-INF/jsp/view-books.jsp @@ -1,30 +1,28 @@ <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> - - View Books - - " rel="stylesheet" type="text/css"> - - - - - - - - - - - - - + + View Books + " rel="stylesheet" type="text/css"> + + +
ISBNNameAuthor
+ - - - + + + - - -
${book.isbn}${book.name}${book.author}ISBNNameAuthor
- + + + + + ${book.isbn} + ${book.name} + ${book.author} + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerIntegrationTest.java b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerIntegrationTest.java new file mode 100644 index 0000000000..1847cbf545 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerIntegrationTest.java @@ -0,0 +1,93 @@ +package com.baeldung.boot.jsp.controller; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasProperty; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +import java.util.Collections; +import java.util.Optional; + +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.impl.InMemoryBookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +@ContextConfiguration +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class BookControllerIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private BookRepository bookRepository; + + @Test + @Order(1) + public void whenAddBook_thenBookSaved() throws Exception { + MockHttpServletRequestBuilder addBookRequest = MockMvcRequestBuilders.post("/book/addBook") + .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE) + .param("isbn", "isbn1") + .param("name", "name1") + .param("author", "author1"); + mockMvc.perform(addBookRequest) + .andReturn(); + + Optional storedBookOpt = bookRepository.findById("isbn1"); + assertTrue(storedBookOpt.isPresent()); + assertEquals("name1", storedBookOpt.get() + .getName()); + assertEquals("author1", storedBookOpt.get() + .getAuthor()); + } + + @Test + @Order(2) + public void givenAlreadyExistingBook_whenAddBook_thenShowErrorPage() throws Exception { + MockHttpServletRequestBuilder addBookRequest = MockMvcRequestBuilders.post("/book/addBook") + .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE) + .param("isbn", "isbn1") + .param("name", "name1") + .param("author", "author1"); + ResultActions addBookResult = mockMvc.perform(addBookRequest); + + addBookResult.andExpect(view().name("error-book")) + .andExpect(model().attribute("ref", "isbn1")) + .andExpect(model().attribute("object", hasProperty("isbn", equalTo("isbn1")))) + .andExpect(model().attribute("message", "Cannot add an already existing book")); + } + + @Configuration + @ComponentScan("com.baeldung.boot.jsp") + static class ContextConfiguration { + + @Bean + public BookRepository provideBookRepository() { + return new InMemoryBookRepository(Collections.emptyMap()); + } + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerUnitTest.java b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerUnitTest.java new file mode 100644 index 0000000000..af1d3d4956 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/controller/BookControllerUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.boot.jsp.controller; + +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.mockito.AdditionalAnswers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.baeldung.boot.jsp.dto.Book; +import com.baeldung.boot.jsp.service.BookService; + +@WebMvcTest(BookController.class) +class BookControllerUnitTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private BookService bookService; + + @Test + public void whenViewBooks_thenReturnBooksView() throws Exception { + when(bookService.getBooks()).thenReturn(existingBooks()); + ResultActions viewBooksResult = mockMvc.perform(get("/book/viewBooks")); + + viewBooksResult.andExpect(view().name("view-books")) + .andExpect(model().attribute("books", hasSize(3))); + } + + @Test + public void whenAddBookView_thenReturnAddBooksView() throws Exception { + ResultActions addBookViewResult = mockMvc.perform(get("/book/addBook")); + + addBookViewResult.andExpect(view().name("add-book")) + .andExpect(model().attribute("book", isA(Book.class))); + } + + @Test + public void whenAddBookPost_thenRedirectToAddBookView() throws Exception { + when(bookService.addBook(any(Book.class))).thenAnswer(AdditionalAnswers.returnsFirstArg()); + MockHttpServletRequestBuilder addBookRequest = MockMvcRequestBuilders.post("/book/addBook") + .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE) + .param("isbn", "isbn1") + .param("name", "name1") + .param("author", "author1"); + ResultActions addBookResult = mockMvc.perform(addBookRequest); + + addBookResult.andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrl("/book/addBook")) + .andExpect(flash().attribute("savedBook", hasProperty("isbn", equalTo("isbn1")))) + .andExpect(flash().attribute("addBookSuccess", true)); + } + + private static Collection existingBooks() { + List books = new ArrayList<>(); + books.add(new Book("isbn1", "name1", "author1")); + books.add(new Book("isbn2", "name2", "author2")); + books.add(new Book("isbn3", "name3", "author3")); + return books; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepositoryUnitTest.java b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepositoryUnitTest.java new file mode 100644 index 0000000000..83f0c19e26 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/repository/impl/InMemoryBookRepositoryUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.boot.jsp.repository.impl; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.*; + +import org.junit.jupiter.api.Test; + +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; + +public class InMemoryBookRepositoryUnitTest { + + @Test + public void givenEmtpyData_whenFindAll_thenReturnEmptyCollection() { + BookRepository bookRepository = new InMemoryBookRepository(Collections.emptyMap()); + Collection storedBooks = bookRepository.findAll(); + + assertEquals(0, storedBooks.size()); + } + + @Test + public void givenInitialData_whenFindAll_thenReturnInitialData() { + BookRepository bookRepository = new InMemoryBookRepository(initialBookData()); + Collection storedBooks = bookRepository.findAll(); + + assertEquals(3, storedBooks.size()); + } + + @Test + public void givenInitialData_whenFindUnavailableIsbn_thenReturnEmpty() { + BookRepository bookRepository = new InMemoryBookRepository(initialBookData()); + Optional storedBookOpt = bookRepository.findById("isbn4"); + + assertFalse(storedBookOpt.isPresent()); + } + + @Test + public void givenInitialData_whenFindAvailableIsbn_thenReturnItem() { + BookRepository bookRepository = new InMemoryBookRepository(initialBookData()); + Optional storedBookOpt = bookRepository.findById("isbn1"); + + assertTrue(storedBookOpt.isPresent()); + } + + @Test + public void givenAddedIsbn_whenFindAvailableIsbn_thenReturnItem() { + BookRepository bookRepository = new InMemoryBookRepository(Collections.emptyMap()); + bookRepository.add(new BookData("isbn4", "name4", "author4")); + Optional storedBookOpt = bookRepository.findById("isbn4"); + + assertTrue(storedBookOpt.isPresent()); + } + + private static Map initialBookData() { + Map initData = new HashMap<>(); + initData.put("isbn1", new BookData("isbn1", "name1", "author1")); + initData.put("isbn2", new BookData("isbn2", "name2", "author2")); + initData.put("isbn3", new BookData("isbn3", "name3", "author3")); + return initData; + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/BookServiceIntegrationTest.java b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/BookServiceIntegrationTest.java new file mode 100644 index 0000000000..4223f3f970 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/BookServiceIntegrationTest.java @@ -0,0 +1,84 @@ +package com.baeldung.boot.jsp.service; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.boot.jsp.dto.Book; +import com.baeldung.boot.jsp.exception.DuplicateBookException; +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.impl.InMemoryBookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; + +@ExtendWith(SpringExtension.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class) +public class BookServiceIntegrationTest { + + @Autowired + private BookService bookService; + + @Test + @Order(1) + public void givenNoAddedBooks_whenGetAllBooks_thenReturnInitialBooks() { + Collection storedBooks = bookService.getBooks(); + + assertEquals(3, storedBooks.size()); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("ISBN-TEST-1")))); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("ISBN-TEST-2")))); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("ISBN-TEST-3")))); + } + + @Test + @Order(2) + public void givenBookNotAlreadyExists_whenAddBook_thenReturnSuccessfully() { + Book bookToBeAdded = new Book("ISBN-ADD-TEST-4", "Added Book 4", "Added Book 4 Author"); + Book storedBook = bookService.addBook(bookToBeAdded); + + assertEquals(bookToBeAdded.getIsbn(), storedBook.getIsbn()); + } + + @Test + @Order(3) + public void givenBookAlreadyExists_whenAddBook_thenDuplicateBookException() { + Book bookToBeAdded = new Book("ISBN-ADD-TEST-4", "Updated Book 4", "Updated Book 4 Author"); + + assertThrows(DuplicateBookException.class, () -> bookService.addBook(bookToBeAdded)); + } + + @Configuration + @ComponentScan("com.baeldung.boot.jsp") + static class ContextConfiguration { + + @Bean + public BookRepository provideBookRepository() { + return new InMemoryBookRepository(initialBookData()); + } + + private static Map initialBookData() { + Map initData = new HashMap<>(); + initData.put("ISBN-TEST-1", new BookData("ISBN-TEST-1", "Book 1", "Book 1 Author")); + initData.put("ISBN-TEST-2", new BookData("ISBN-TEST-2", "Book 2", "Book 2 Author")); + initData.put("ISBN-TEST-3", new BookData("ISBN-TEST-3", "Book 3", "Book 3 Author")); + return initData; + } + } +} \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/impl/BookServiceImplUnitTest.java b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/impl/BookServiceImplUnitTest.java new file mode 100644 index 0000000000..defbf71fd9 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/java/com/baeldung/boot/jsp/service/impl/BookServiceImplUnitTest.java @@ -0,0 +1,75 @@ +package com.baeldung.boot.jsp.service.impl; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.AdditionalAnswers; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.baeldung.boot.jsp.dto.Book; +import com.baeldung.boot.jsp.exception.DuplicateBookException; +import com.baeldung.boot.jsp.repository.BookRepository; +import com.baeldung.boot.jsp.repository.model.BookData; +import com.baeldung.boot.jsp.service.BookService; + +@ExtendWith(MockitoExtension.class) +public class BookServiceImplUnitTest { + + @Mock + private BookRepository bookRepository; + + @Test + public void whenGetBooks_thenAllBooksReturned() { + when(bookRepository.findAll()).thenReturn(existingBooks()); + BookService bookService = new BookServiceImpl(bookRepository); + + Collection storedBooks = bookService.getBooks(); + assertEquals(3, storedBooks.size()); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("isbn1")))); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("isbn2")))); + assertThat(storedBooks, hasItem(hasProperty("isbn", equalTo("isbn3")))); + } + + @Test + public void whenAddBook_thenAddSuccessful() { + when(bookRepository.findById(anyString())).thenReturn(Optional.empty()); + when(bookRepository.add(any(BookData.class))).thenAnswer(AdditionalAnswers.returnsFirstArg()); + BookService bookService = new BookServiceImpl(bookRepository); + Book book = bookService.addBook(new Book("isbn1", "name1", "author1")); + + assertEquals("isbn1", book.getIsbn()); + assertEquals("name1", book.getName()); + assertEquals("author1", book.getAuthor()); + } + + @Test + public void givenBookAlreadyExist_whenAddBook_thenDuplicateBookException() { + BookData existingBook = new BookData("isbn1", "name1", "author1"); + when(bookRepository.findById("isbn1")).thenReturn(Optional.of(existingBook)); + BookService bookService = new BookServiceImpl(bookRepository); + Book bookToBeAdded = new Book("isbn1", "name1", "author1"); + + assertThrows(DuplicateBookException.class, () -> bookService.addBook(bookToBeAdded)); + } + + private static Collection existingBooks() { + List books = new ArrayList<>(); + books.add(new BookData("isbn1", "name1", "author1")); + books.add(new BookData("isbn2", "name2", "author2")); + books.add(new BookData("isbn3", "name3", "author3")); + return books; + } +} \ No newline at end of file From 4c1b4723e02fd6019e7ee6ebe4368e9b708fb8cc Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 22 Mar 2021 21:00:53 +0530 Subject: [PATCH 20/61] BAEL-4810: Second Review Improvements. Fixed some pom warnings and dependencies. Removed incorrectly added Readme.md --- spring-web-modules/spring-boot-jsp/README.md | 6 ------ spring-web-modules/spring-boot-jsp/pom.xml | 15 +-------------- 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 spring-web-modules/spring-boot-jsp/README.md diff --git a/spring-web-modules/spring-boot-jsp/README.md b/spring-web-modules/spring-boot-jsp/README.md deleted file mode 100644 index 8242461917..0000000000 --- a/spring-web-modules/spring-boot-jsp/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Spring MVC Forms JSP - -This module contains articles about Spring Boot used with JSP - -### Relevant Articles -- [Spring Boot with JSP](https://www.baeldung.com/?) diff --git a/spring-web-modules/spring-boot-jsp/pom.xml b/spring-web-modules/spring-boot-jsp/pom.xml index 672cc8b426..d646b6058a 100644 --- a/spring-web-modules/spring-boot-jsp/pom.xml +++ b/spring-web-modules/spring-boot-jsp/pom.xml @@ -3,8 +3,6 @@ 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 spring-boot-jsp 0.0.1-SNAPSHOT spring-boot-jsp @@ -56,18 +54,6 @@ - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - test - - - org.mockito - mockito-core - ${mockito.version} - test - org.springframework.boot spring-boot-starter-test @@ -81,6 +67,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} com.baeldung.boot.jsp.SpringBootJspApplication From 074cb209b269a4ce7ab3941015b28f9af3041631 Mon Sep 17 00:00:00 2001 From: mikr Date: Fri, 26 Mar 2021 11:29:11 +0100 Subject: [PATCH 21/61] JAVA-4866 Update spring-cloud-bus module --- spring-cloud-bus/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud-bus/pom.xml b/spring-cloud-bus/pom.xml index 15eed8dcf0..82d0bccd0b 100644 --- a/spring-cloud-bus/pom.xml +++ b/spring-cloud-bus/pom.xml @@ -34,8 +34,7 @@ - Hoxton.SR4 - 2.3.3.RELEASE + 2020.0.0 From 6f57b06ffca82de63f42a11cfc842442b8d189b4 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 29 Mar 2021 13:07:03 +0530 Subject: [PATCH 22/61] JAVA-3296: Fix references to parents --- discord4j/pom.xml | 21 ++++++++++----------- docker/docker-spring-boot-postgres/pom.xml | 21 +++++++++++---------- docker/pom.xml | 14 +++++++------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/discord4j/pom.xml b/discord4j/pom.xml index 664692f60a..ed20d6f19e 100644 --- a/discord4j/pom.xml +++ b/discord4j/pom.xml @@ -2,21 +2,16 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.5.RELEASE - - - com.baeldung discord4j-bot - 0.0.1-SNAPSHOT discord4j-bot Demo Discord bot using Discord4J + Spring Boot - - 1.8 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + @@ -67,5 +62,9 @@
+ + + 1.8 + diff --git a/docker/docker-spring-boot-postgres/pom.xml b/docker/docker-spring-boot-postgres/pom.xml index 0b359138f6..d08ae130db 100644 --- a/docker/docker-spring-boot-postgres/pom.xml +++ b/docker/docker-spring-boot-postgres/pom.xml @@ -2,21 +2,18 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.4.0 - - com.baeldung.docker docker-spring-boot-postgres 0.0.1-SNAPSHOT docker-spring-boot-postgres Demo project showing Spring Boot, PostgreSQL, and Docker - - - 11 - + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + @@ -44,5 +41,9 @@
+ + + 11 + \ No newline at end of file diff --git a/docker/pom.xml b/docker/pom.xml index f05c303938..3fcc9ca94f 100644 --- a/docker/pom.xml +++ b/docker/pom.xml @@ -4,19 +4,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.1.RELEASE - - - com.baeldung.docker docker 0.0.1 docker Demo project showing Spring Boot and Docker pom + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + 11 From 9bfe24895c6e3e2f12211ba59b87cf9c06041f02 Mon Sep 17 00:00:00 2001 From: Carlos Cavero Date: Mon, 29 Mar 2021 10:54:50 +0200 Subject: [PATCH 23/61] Rename ServiceTest to UnitTest for the PMD checking to pass. Adjust indentation and remove $ from the variables --- .../backpressure/BackpressureServiceTest.java | 82 ------------------- .../backpressure/BackpressureUnitTest.java | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java create mode 100644 spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java deleted file mode 100644 index 67ee1822b7..0000000000 --- a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureServiceTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.backpressure; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.BaseSubscriber; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -public class BackpressureServiceTest { - - @Test - public void whenLimitRateSet_thenSplitIntoChunks() throws InterruptedException { - Flux limit$ = Flux.range(1, 25); - - limit$.limitRate(10); - limit$.subscribe( - value -> System.out.println(value), - err -> err.printStackTrace(), - () -> System.out.println("Finished!!"), - subscription -> subscription.request(15) - ); - - StepVerifier.create(limit$) - .expectSubscription() - .thenRequest(15) - .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - .expectNext(11, 12, 13, 14, 15) - .thenRequest(10) - .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25) - .verifyComplete(); - } - - @Test - public void whenRequestingChunks10_thenMessagesAreReceived() { - Flux request$ = Flux.range(1, 50); - - request$.subscribe( - System.out::println, - err -> err.printStackTrace(), - () -> System.out.println("All 50 items have been successfully processed!!!"), - subscription -> { - for (int i = 0; i < 5; i++) { - System.out.println("Requesting the next 10 elements!!!"); - subscription.request(10); - } - } - ); - - StepVerifier.create(request$) - .expectSubscription() - .thenRequest(10) - .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - .thenRequest(10) - .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) - .thenRequest(10) - .expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30) - .thenRequest(10) - .expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40) - .thenRequest(10) - .expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50) - .verifyComplete(); - } - - @Test - public void whenCancel_thenSubscriptionFinished() { - Flux cancel$ = Flux.range(1, 10).log(); - - cancel$.subscribe(new BaseSubscriber() { - @Override - protected void hookOnNext(Integer value) { - request(3); - System.out.println(value); - cancel(); - } - }); - - StepVerifier.create(cancel$) - .expectNext(1, 2, 3) - .thenCancel() - .verify(); - } -} - diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java new file mode 100644 index 0000000000..e7cb60dbf9 --- /dev/null +++ b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java @@ -0,0 +1,82 @@ +package com.baeldung.backpressure; + +import org.junit.jupiter.api.Test; +import reactor.core.publisher.BaseSubscriber; +import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; + +public class BackpressureUnitTest { + + @Test + public void whenLimitRateSet_thenSplitIntoChunks() throws InterruptedException { + Flux limit = Flux.range(1, 25); + + limit.limitRate(10); + limit.subscribe( + value -> System.out.println(value), + err -> err.printStackTrace(), + () -> System.out.println("Finished!!"), + subscription -> subscription.request(15) + ); + + StepVerifier.create(limit) + .expectSubscription() + .thenRequest(15) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .expectNext(11, 12, 13, 14, 15) + .thenRequest(10) + .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25) + .verifyComplete(); + } + + @Test + public void whenRequestingChunks10_thenMessagesAreReceived() { + Flux request = Flux.range(1, 50); + + request.subscribe( + System.out::println, + err -> err.printStackTrace(), + () -> System.out.println("All 50 items have been successfully processed!!!"), + subscription -> { + for (int i = 0; i < 5; i++) { + System.out.println("Requesting the next 10 elements!!!"); + subscription.request(10); + } + } + ); + + StepVerifier.create(request) + .expectSubscription() + .thenRequest(10) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .thenRequest(10) + .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) + .thenRequest(10) + .expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30) + .thenRequest(10) + .expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40) + .thenRequest(10) + .expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50) + .verifyComplete(); + } + + @Test + public void whenCancel_thenSubscriptionFinished() { + Flux cancel = Flux.range(1, 10).log(); + + cancel.subscribe(new BaseSubscriber() { + @Override + protected void hookOnNext(Integer value) { + request(3); + System.out.println(value); + cancel(); + } + }); + + StepVerifier.create(cancel) + .expectNext(1, 2, 3) + .thenCancel() + .verify(); + } +} + From f0dd323c50d871db0fca24b2125ee8e8001d7c24 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 30 Mar 2021 20:55:52 +0200 Subject: [PATCH 24/61] JAVA-3578: Verify sub-modules - core-java-modules --- core-java-modules/pom.xml | 1 + pom.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 4cfe7fe34c..d44ce97f14 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -100,6 +100,7 @@ core-java-networking core-java-networking-2 + core-java-networking-3 core-java-nio core-java-nio-2 diff --git a/pom.xml b/pom.xml index 78a6d8d329..0e39d012fc 100644 --- a/pom.xml +++ b/pom.xml @@ -1273,7 +1273,7 @@ core-java-modules/core-java-9-streams core-java-modules/core-java-10 - core-java-modules/core-java-11 + core-java-modules/core-java-11-2 @@ -1318,6 +1318,7 @@ core-java-modules/core-java-9-streams core-java-modules/core-java-10 core-java-modules/core-java-11 + core-java-modules/core-java-11-2 From 9ecd012b1e2fc4690ba80255b92ec4dd35ce0d81 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 30 Mar 2021 21:00:58 +0200 Subject: [PATCH 25/61] JAVA-3578: Verify sub-modules - logging-modules --- logging-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logging-modules/pom.xml b/logging-modules/pom.xml index 85d5c18219..e396d477dc 100644 --- a/logging-modules/pom.xml +++ b/logging-modules/pom.xml @@ -14,11 +14,11 @@ + flogger log4j log4j2 logback log-mdc - flogger From 5e1f1518ae432a3a0b19e1ab1a4a154a856319a5 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 30 Mar 2021 21:05:21 +0200 Subject: [PATCH 26/61] JAVA-3578: Verify sub-modules - maven-modules --- maven-modules/pom.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index c9a2b67a6c..a476eacc64 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -20,14 +20,15 @@ maven-integration-test maven-multi-source maven-plugins - maven-unused-dependencies - maven-war-plugin maven-profiles maven-properties - versions-maven-plugin - version-collision + + maven-unused-dependencies + maven-war-plugin optional-dependencies + version-collision version-overriding-plugins + versions-maven-plugin From 270f54dce68ecef2bf92f1c24fa989e0badf1c3a Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 31 Mar 2021 15:32:26 +0200 Subject: [PATCH 27/61] JAVA-3578: Verify sub-modules - persistence-modules --- persistence-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 8789a8473b..32423a42dd 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -38,6 +38,7 @@ java-jdbi java-jpa java-jpa-2 + java-jpa-3 java-mongodb jnosql jooq From ce89004e9604eeef0451b1c017d0fae37aac87c4 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 31 Mar 2021 15:39:52 +0200 Subject: [PATCH 28/61] JAVA-3578: Verify sub-modules - spring-security-modules --- spring-security-modules/pom.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 096ffb9c3f..78e406dc84 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -14,33 +14,33 @@ - spring-ldap spring-5-security spring-5-security-cognito spring-5-security-oauth + spring-ldap spring-security-acl spring-security-auth0 - spring-security-web-angular/server spring-security-config spring-security-core - spring-security-web-mvc - spring-security-web-boot-1 - spring-security-web-boot-2 - spring-security-web-mvc-custom - spring-security-web-digest-auth spring-security-ldap - spring-security-web-login - spring-security-web-persisted-remember-me - spring-security-web-sockets spring-security-legacy-oidc + spring-security-oauth2-sso spring-security-oidc spring-security-okta spring-security-saml + spring-security-web-angular/server + spring-security-web-boot-1 + spring-security-web-boot-2 + spring-security-web-digest-auth + spring-security-web-login + spring-security-web-mvc-custom + spring-security-web-mvc + spring-security-web-persisted-remember-me spring-security-web-react - spring-security-web-rest spring-security-web-rest-basic-auth spring-security-web-rest-custom - spring-security-oauth2-sso + spring-security-web-rest + spring-security-web-sockets spring-security-web-thymeleaf spring-security-web-x509 spring-session From 3693d2ea0b355f03119ba42e7921d40b2e7103ea Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:16:07 +0800 Subject: [PATCH 29/61] Update README.md --- core-java-modules/core-java-streams-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-streams-3/README.md b/core-java-modules/core-java-streams-3/README.md index 9adde005e6..f81dca485b 100644 --- a/core-java-modules/core-java-streams-3/README.md +++ b/core-java-modules/core-java-streams-3/README.md @@ -10,4 +10,5 @@ This module contains articles about the Stream API in Java. - [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams) - [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals) - [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close) +- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection) - More articles: [[<-- prev>]](/../core-java-streams-2) From 4f0e4e808a0480b4111e2360c37b87cbcb1efebd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:18:51 +0800 Subject: [PATCH 30/61] Create README.md --- testing-modules/mockito-3/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 testing-modules/mockito-3/README.md diff --git a/testing-modules/mockito-3/README.md b/testing-modules/mockito-3/README.md new file mode 100644 index 0000000000..c9766031a3 --- /dev/null +++ b/testing-modules/mockito-3/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Mocking Static Methods With Mockito](https://www.baeldung.com/mockito-mock-static-methods) From f9f83d2305041c1dd68d575e1e50cbe51032dcd5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:21:28 +0800 Subject: [PATCH 31/61] Update README.md --- persistence-modules/core-java-persistence-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/core-java-persistence-2/README.md b/persistence-modules/core-java-persistence-2/README.md index 36c33cc6e1..cebd81388d 100644 --- a/persistence-modules/core-java-persistence-2/README.md +++ b/persistence-modules/core-java-persistence-2/README.md @@ -2,3 +2,4 @@ - [Getting Database URL From JDBC Connection Object](https://www.baeldung.com/jdbc-get-url-from-connection) - [JDBC URL Format For Different Databases](https://www.baeldung.com/java-jdbc-url-format) +- [How to Check if a Database Table Exists with JDBC](https://www.baeldung.com/jdbc-check-table-exists) From 457fc61bd5472448f1618ea93a583a7c8493948d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:23:26 +0800 Subject: [PATCH 32/61] Update README.md --- persistence-modules/spring-jooq/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-jooq/README.md b/persistence-modules/spring-jooq/README.md index 515ab8be3c..d0cb946614 100644 --- a/persistence-modules/spring-jooq/README.md +++ b/persistence-modules/spring-jooq/README.md @@ -5,6 +5,7 @@ This module contains articles about Spring with jOOQ ### Relevant Articles: - [Spring Boot Support for jOOQ](https://www.baeldung.com/spring-boot-support-for-jooq) - [Introduction to jOOQ with Spring](https://www.baeldung.com/jooq-with-spring) +- [Count Query In jOOQ](https://www.baeldung.com/jooq-count-query) In order to fix the error "Plugin execution not covered by lifecycle configuration: org.jooq:jooq-codegen-maven:3.7.3:generate (execution: default, phase: generate-sources)", right-click on the error message and choose "Mark goal generated as ignore in pom.xml". Until version 1.4.x, the maven-plugin-plugin was covered by the default lifecycle mapping that ships with m2e. From ce0b69e6fa397d173979c0c1cae3567d533ee4c6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:25:10 +0800 Subject: [PATCH 33/61] Update README.md --- core-java-modules/core-java-lang-oop-types/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-oop-types/README.md b/core-java-modules/core-java-lang-oop-types/README.md index 6c649877b3..1ac5a5c804 100644 --- a/core-java-modules/core-java-lang-oop-types/README.md +++ b/core-java-modules/core-java-lang-oop-types/README.md @@ -13,3 +13,4 @@ This module contains articles about types in Java - [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums) - [Determine if an Object is of Primitive Type](https://www.baeldung.com/java-object-primitive-type) - [Extending Enums in Java](https://www.baeldung.com/java-extending-enums) +- [Java Class File Naming Conventions](https://www.baeldung.com/java-class-file-naming) From 755dfd391695d5db56d91b4fe7a9a74214fde934 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:27:16 +0800 Subject: [PATCH 34/61] Update README.md --- spring-core-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-5/README.md b/spring-core-5/README.md index 4109faca67..6befae7372 100644 --- a/spring-core-5/README.md +++ b/spring-core-5/README.md @@ -5,4 +5,5 @@ This module contains articles about core Spring functionality ## Relevant Articles: - [Spring @Component Annotation](https://www.baeldung.com/spring-component-annotation) +- [Solving Spring’s “not eligible for auto-proxying” Warning](https://www.baeldung.com/spring-not-eligible-for-auto-proxying) - More articles: [[<-- prev]](/spring-core-4) From b06a661edf30b2d27ad64c5fcbd7ad456c1c7424 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:32:04 +0800 Subject: [PATCH 35/61] Update README.md --- spring-boot-modules/spring-boot-libraries-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-libraries-2/README.md b/spring-boot-modules/spring-boot-libraries-2/README.md index 4218dfc1be..7bf51b5424 100644 --- a/spring-boot-modules/spring-boot-libraries-2/README.md +++ b/spring-boot-modules/spring-boot-libraries-2/README.md @@ -5,3 +5,4 @@ This module contains articles about various Spring Boot libraries ### Relevant Articles: - [Background Jobs in Spring with JobRunr](https://www.baeldung.com/java-jobrunr-spring) +- [Open API Server Implementation Using OpenAPI Generator](https://www.baeldung.com/java-openapi-generator-server) From 28d103508fd68589ad7560711d4009e2a3d528c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 31 Mar 2021 20:13:00 +0200 Subject: [PATCH 36/61] JAVA-3578: Verify sub-modules - testing-modules --- testing-modules/pom.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index c0c28e085d..228e47838c 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -16,35 +16,35 @@ assertion-libraries easy-random + easymock gatling groovy-spock + hamcrest + junit-4 + junit-5-advanced + junit-5-basics junit-5 junit5-annotations junit5-migration load-testing-comparison + mockito-2 + mockito-3 mockito - mockito-2 - mockito-3 - hamcrest mocks mockserver parallel-tests-junit + powermock rest-assured rest-testing selenium-junit-testng - spring-testing spring-testing-2 + spring-testing test-containers testing-assertions - testng - junit-5-basics - easymock - junit-5-advanced - xmlunit-2 - junit-4 - testing-libraries testing-libraries-2 - powermock + testing-libraries + testng + xmlunit-2 zerocode From 24b447d83c86eefa1c20774e3ffeb85800e1fc38 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 31 Mar 2021 20:23:41 +0200 Subject: [PATCH 37/61] JAVA-3578: Verify sub-modules - main pom.xml --- pom.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0e39d012fc..13f24d7aea 100644 --- a/pom.xml +++ b/pom.xml @@ -412,6 +412,7 @@ google-web-toolkit + graphql/graphql-java grpc @@ -614,11 +615,12 @@ spring-aop spring-apache-camel - spring-batch - spring-batch-2 + spring-batch + spring-batch-2 spring-bom spring-boot-modules spring-boot-rest + spring-boot-rest-2 spring-caching @@ -875,6 +877,7 @@ google-web-toolkit + graphql/graphql-java grpc @@ -930,6 +933,7 @@ jooby jsf json + json-2 json-path jsoup jta @@ -1068,9 +1072,11 @@ spring-apache-camel spring-batch + spring-batch-2 spring-bom spring-boot-modules spring-boot-rest + spring-boot-rest-2 spring-caching @@ -1089,6 +1095,7 @@ spring-data-rest spring-data-rest-querydsl spring-di + spring-di-2 spring-drools spring-ejb From 9706d7b6fde6d45f194dafd7572d141a9bca3955 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Wed, 31 Mar 2021 22:52:31 +0200 Subject: [PATCH 38/61] Bael 4485 (#10612) * BAEL-4485 RSA in Java * BAEL-4485 RSA in Java * BAEL-4485 RSA in Java Co-authored-by: majewsk6 --- .../java/com/baeldung/rsa/RsaUnitTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java new file mode 100644 index 0000000000..ac93f71125 --- /dev/null +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java @@ -0,0 +1,92 @@ +package com.baeldung.cipher; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.crypto.Cipher; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.security.PublicKey; + +public class RsaUnitTest { + + @Test + public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception { + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + KeyPair pair = generator.generateKeyPair(); + PrivateKey privateKey = pair.getPrivate(); + PublicKey publicKey = pair.getPublic(); + + String secretMessage = "Baeldung secret message"; + Cipher encryptCipher = Cipher.getInstance("RSA"); + encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); + byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8); + byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes); + + Cipher decryptCipher = Cipher.getInstance("RSA"); + decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); + byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes); + String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8); + + Assertions.assertEquals(secretMessage, decryptedMessage); + } + + @Test + public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception { + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + KeyPair pair = generator.generateKeyPair(); + PrivateKey privateKey = pair.getPrivate(); + PublicKey publicKey = pair.getPublic(); + + String originalContent = "some secret message"; + Path tempFile = Files.createTempFile("temp", "txt"); + writeString(tempFile, originalContent); + + byte[] fileBytes = Files.readAllBytes(tempFile); + Cipher encryptCipher = Cipher.getInstance("RSA"); + encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); + byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(encryptedFileBytes); + } + + encryptedFileBytes = Files.readAllBytes(tempFile); + Cipher decryptCipher = Cipher.getInstance("RSA"); + decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); + byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes); + try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) { + stream.write(decryptedFileBytes); + } + + String fileContent = readString(tempFile); + + Assertions.assertEquals(originalContent, fileContent); + } + + private void writeString(Path path, String content) throws Exception { + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + writer.write(content); + } + } + + private String readString(Path path) throws Exception { + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line); + } + } + return resultStringBuilder.toString(); + } +} From 273ffd5aba441e67204dc234fbcc5145af02ed13 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 31 Mar 2021 23:30:49 +0200 Subject: [PATCH 39/61] JAVA-3578: Ignore failing unit test in the java-jpa-3 --- .../com/baeldung/ignorable/fields/TransientFieldUnitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java index 114a4cca4c..f50436e2ec 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java @@ -7,6 +7,7 @@ import java.io.*; import java.util.List; import java.util.Random; +import org.junit.Ignore; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; @@ -22,6 +23,7 @@ public class TransientFieldUnitTest { private final User user = new User("user" + randInt + "@bar.com", "hunter2", "MacOSX"); + @Ignore @Test public void givenFieldWithTransientAnnotation_whenSavingViaJPA_thenFieldIgnored() { userDao.saveUser(user); From 86575c861b3920dd917534992686b7d69dd3f3cd Mon Sep 17 00:00:00 2001 From: Amy DeGregorio Date: Thu, 1 Apr 2021 11:14:25 -0400 Subject: [PATCH 40/61] BAEL-4825 (#10616) * BAEL-4825 * BAEL-4825 added integration tests * BAEL-4825 Fix line continuation indents * BAEL-4825 Fix line continuation indents --- .../enabling/SecurityConfiguration.java | 18 +++++++++--------- .../EndpointEnablingIntegrationTest.java | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java index 24b78642f2..894c24693e 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java +++ b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java @@ -17,20 +17,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { protected void configure(AuthenticationManagerBuilder auth) throws Exception { PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); auth.inMemoryAuthentication() - .withUser("user") - .password(encoder.encode("password")) - .roles("USER") - .and() - .withUser("admin") - .password(encoder.encode("admin")) - .roles("USER", "ADMIN"); + .withUser("user") + .password(encoder.encode("password")) + .roles("USER") + .and() + .withUser("admin") + .password(encoder.encode("admin")) + .roles("USER", "ADMIN"); } @Override protected void configure(HttpSecurity http) throws Exception { http.requestMatcher(EndpointRequest.toAnyEndpoint()) - .authorizeRequests((requests) -> requests.anyRequest() - .hasRole("ADMIN")); + .authorizeRequests((requests) -> requests.anyRequest() + .hasRole("ADMIN")); http.httpBasic(); } } diff --git a/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java b/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java index 8a9dd4ca72..8274619517 100644 --- a/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java +++ b/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java @@ -21,16 +21,16 @@ public class EndpointEnablingIntegrationTest { @WithMockUser(username = "user", password = "password", roles = "USER") public void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception { mockMvc.perform(get("/actuator")) - .andExpect(status().isForbidden()); + .andExpect(status().isForbidden()); } @Test @WithMockUser(username = "admin", password = "admin", roles = "ADMIN") public void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception { mockMvc.perform(get("/actuator")) - .andExpect(jsonPath("$._links").exists()) - .andExpect(jsonPath("$._links.beans").exists()) - .andExpect(jsonPath("$._links.env").exists()) - .andExpect(jsonPath("$._links.shutdown").exists()); + .andExpect(jsonPath("$._links").exists()) + .andExpect(jsonPath("$._links.beans").exists()) + .andExpect(jsonPath("$._links.env").exists()) + .andExpect(jsonPath("$._links.shutdown").exists()); } } From 429108b62b81b8dc2108db01801fcb43af56f257 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 1 Apr 2021 20:01:45 +0200 Subject: [PATCH 41/61] JAVA-3578: Fix README.md files --- core-java-modules/core-java-networking-2/README.md | 1 - core-java-modules/core-java-networking-3/README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java-modules/core-java-networking-2/README.md b/core-java-modules/core-java-networking-2/README.md index 9def4c8eb6..fa49c35bf8 100644 --- a/core-java-modules/core-java-networking-2/README.md +++ b/core-java-modules/core-java-networking-2/README.md @@ -14,5 +14,4 @@ This module contains articles about networking in Java - [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception) - [Getting MAC addresses in Java](https://www.baeldung.com/java-mac-address) - [Sending Emails with Attachments in Java](https://www.baeldung.com/java-send-emails-attachments) -- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port) - [[<-- Prev]](/core-java-modules/core-java-networking) diff --git a/core-java-modules/core-java-networking-3/README.md b/core-java-modules/core-java-networking-3/README.md index a81e85751d..09470fe88c 100644 --- a/core-java-modules/core-java-networking-3/README.md +++ b/core-java-modules/core-java-networking-3/README.md @@ -4,5 +4,5 @@ This module contains articles about networking in Java ### Relevant Articles -- TODO: add link once live +- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port) - [[<-- Prev]](/core-java-modules/core-java-networking-2) From e22ad64847689bb1971de9f20d8a3c02067d98c1 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 1 Apr 2021 23:31:16 +0200 Subject: [PATCH 42/61] JAVA-5083: Fix unit tests in java-jpa-3 module --- .../ignorable/fields/HibernateConfig.java | 13 ++--- .../fields/TransientFieldUnitTest.java | 48 +++++++++++-------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java index 9285c23dfa..d121c81c6b 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/ignorable/fields/HibernateConfig.java @@ -9,6 +9,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.service.ServiceRegistry; public class HibernateConfig { + private static SessionFactory sessionFactory; public static SessionFactory getSessionFactory() { @@ -16,12 +17,12 @@ public class HibernateConfig { Configuration configuration = new Configuration(); Properties settings = new Properties(); - settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver"); - settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false"); - settings.put(Environment.USER, "root"); - settings.put(Environment.PASS, "password"); - settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); - settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); + settings.put(Environment.DRIVER, "org.h2.Driver"); + settings.put(Environment.URL, "jdbc:h2:mem:test"); + settings.put(Environment.USER, "sa"); + settings.put(Environment.PASS, ""); + settings.put(Environment.DIALECT, "org.hibernate.dialect.H2Dialect"); + settings.put(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperties(settings); configuration.addAnnotatedClass(User.class); diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java index f50436e2ec..6d4eba2c29 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/ignorable/fields/TransientFieldUnitTest.java @@ -1,19 +1,24 @@ package com.baeldung.ignorable.fields; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.io.*; -import java.util.List; -import java.util.Random; - -import org.junit.Ignore; -import org.junit.Test; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Random; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TransientFieldUnitTest { @@ -23,7 +28,6 @@ public class TransientFieldUnitTest { private final User user = new User("user" + randInt + "@bar.com", "hunter2", "MacOSX"); - @Ignore @Test public void givenFieldWithTransientAnnotation_whenSavingViaJPA_thenFieldIgnored() { userDao.saveUser(user); @@ -36,18 +40,20 @@ public class TransientFieldUnitTest { @Test public void givenFieldWithTransientAnnotation_whenSerializingObject_thenFieldSerialized() throws IOException, ClassNotFoundException { - FileOutputStream fout = new FileOutputStream("test.obj"); - ObjectOutputStream out = new ObjectOutputStream(fout); - out.writeObject(user); - out.flush(); - out.close(); + try (FileOutputStream fout = new FileOutputStream("test.obj")) { + ObjectOutputStream out = new ObjectOutputStream(fout); + out.writeObject(user); + out.flush(); + } - FileInputStream fin = new FileInputStream("test.obj"); - ObjectInputStream in = new ObjectInputStream(fin); - User savedUser = (User) in.readObject(); - in.close(); + try (FileInputStream fin = new FileInputStream("test.obj")) { + ObjectInputStream in = new ObjectInputStream(fin); + User savedUser = (User) in.readObject(); - assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice()); + assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice()); + } + + Files.deleteIfExists(Paths.get("test.obj")); } @Test From 71f941a0828025cc7895f59b3b5404239dc71549 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Fri, 2 Apr 2021 06:53:32 +0200 Subject: [PATCH 43/61] BAEL-4912: Set lazy initialization using SpringApplication and SpringApplicationBuilder (#10617) Co-authored-by: Krzysztof Woyke --- .../lazyinitialization/Application.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java b/spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java index 195b260399..72c55e2de5 100644 --- a/spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java +++ b/spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java @@ -3,6 +3,7 @@ package com.baeldung.lazyinitialization; import com.baeldung.lazyinitialization.services.Writer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -20,7 +21,9 @@ public class Application { } public static void main(String[] args) { + ApplicationContext ctx = SpringApplication.run(Application.class, args); + System.out.println("Application context initialized!!!"); Writer writer1 = ctx.getBean("writer1", Writer.class); @@ -29,4 +32,23 @@ public class Application { Writer writer2 = ctx.getBean("writer2", Writer.class); writer2.write("Second message"); } + + /* + This method shows how to set lazy initialization and start the application using SpringApplicationBuilder + */ + private static ApplicationContext runUsingSpringApplicationBuilder(String[] args){ + return new SpringApplicationBuilder(Application.class) + .lazyInitialization(true) + .build(args) + .run(); + } + + /* + This method shows how to set lazy initialization and start the application using SpringApplication + */ + private static ApplicationContext runUsingSpringApplication(String[] args){ + SpringApplication app = new SpringApplication(Application.class); + app.setLazyInitialization(true); + return app.run(args); + } } From 49769beacf0db962e4dc240a278efd5b3ff7497b Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Fri, 2 Apr 2021 12:09:09 +0430 Subject: [PATCH 44/61] bael-4828: add new maven module:spring-security-web-boot-3 --- spring-security-modules/pom.xml | 1 + .../spring-security-web-boot-3/pom.xml | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-3/pom.xml diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 096ffb9c3f..a678307ef0 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -26,6 +26,7 @@ spring-security-web-mvc spring-security-web-boot-1 spring-security-web-boot-2 + spring-security-web-boot-3 spring-security-web-mvc-custom spring-security-web-digest-auth spring-security-ldap diff --git a/spring-security-modules/spring-security-web-boot-3/pom.xml b/spring-security-modules/spring-security-web-boot-3/pom.xml new file mode 100644 index 0000000000..a6e2b48d75 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + spring-security-web-boot-3 + 0.0.1-SNAPSHOT + spring-security-web-boot-3 + jar + Spring Security MVC Boot - 3 + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + From 7f249e41338d45b9156c1772a1b04445b99d33f4 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Fri, 2 Apr 2021 12:09:36 +0430 Subject: [PATCH 45/61] bael-4828: add main source to new maven module --- .../java/com/baeldung/tls/HomeController.java | 16 ++++++++++++++++ .../java/com/baeldung/tls/SecurityConfig.java | 16 ++++++++++++++++ .../com/baeldung/tls/TLSEnabledApplication.java | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/HomeController.java create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/SecurityConfig.java create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/TLSEnabledApplication.java diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/HomeController.java b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/HomeController.java new file mode 100644 index 0000000000..c72821cc9b --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/HomeController.java @@ -0,0 +1,16 @@ +package com.baeldung.tls; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/baeldung") + public ResponseEntity welcome() { + return new ResponseEntity<>("tls/baeldung", HttpStatus.OK); + } + +} diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/SecurityConfig.java new file mode 100644 index 0000000000..63b59b8cc8 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/SecurityConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.tls; + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/**") + .permitAll(); + } +} diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/TLSEnabledApplication.java b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/TLSEnabledApplication.java new file mode 100644 index 0000000000..62ba77d769 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/main/java/com/baeldung/tls/TLSEnabledApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.tls; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +public class TLSEnabledApplication { + + public static void main(String... args) { + SpringApplication application = new SpringApplication(TLSEnabledApplication.class); + application.setAdditionalProfiles("tls"); + application.run(args); + } +} From b4b9c55726f065ef2c03b7c1ec237f5f0fea58e9 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Fri, 2 Apr 2021 12:09:57 +0430 Subject: [PATCH 46/61] bael-4828: add resource files to new maven module --- .../main/resources/application-tls.properties | 23 ++++++++++++++ .../src/main/resources/keystore/baeldung.cer | 28 ++++++++++++++++++ .../src/main/resources/keystore/keystore.p12 | Bin 0 -> 4083 bytes 3 files changed, 51 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/resources/application-tls.properties create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/baeldung.cer create mode 100644 spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/keystore.p12 diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/resources/application-tls.properties b/spring-security-modules/spring-security-web-boot-3/src/main/resources/application-tls.properties new file mode 100644 index 0000000000..002d702eab --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/main/resources/application-tls.properties @@ -0,0 +1,23 @@ + +server.port=8443 + +# enable/disable https +server.ssl.enabled=true +# keystore format +server.ssl.key-store-type=PKCS12 +# keystore location +server.ssl.key-store=classpath:keystore/keystore.p12 +# keystore password +server.ssl.key-store-password=changeit +server.ssl.key-alias=baeldung +# SSL protocol to use +server.ssl.protocol=TLS +# Enabled SSL protocols +server.ssl.enabled-protocols=TLSv1.2 + +#server.ssl.client-auth=need + +#trust store location +#server.ssl.trust-store=classpath:keystore/truststore.p12 +#trust store password +#server.ssl.trust-store-password=changeit \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/baeldung.cer b/spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/baeldung.cer new file mode 100644 index 0000000000..1a6bb4d49b --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/baeldung.cer @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIExzCCAq+gAwIBAgIEbh/WszANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDEwls +b2NhbGhvc3QwHhcNMjEwMzIxMDgzMzU3WhcNMzEwMzE5MDgzMzU3WjAUMRIwEAYD +VQQDEwlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCD +QWvAEewDE+vFFqYPgXFJ94bMgPZT6qdb17DkWWbL2jV5QENbSYTLAPNQ1TGUgKhj +t1LCHpooLwWIo6xvhK/qZYjh3YonSIe8Eo0fBCDoZpLO+Vp0us22NBgLOYH8hvAm +zEvPXdSZo5Qkeaqjwd6kB/z083y8OL+Civ0ARXoLsn7CFslKfZp2o/aebH6i/T+3 +hWVqasIIMtfNUrxE/pnOnV8aSAt24jcm/VxbtheqIzmcOPlCXSP1RAmFez6tJsNu +2dbUhaeOf95RCaM6a43soEvLvooGa/uqBPsRojg5WEFGf7Tc7pzB+BtALwRmHAqr +hiYjVv329QGZ+g8dADBvvqvGpGysy+X0LxixvIP14KdCqG8uMYmw5cBTJHc23AHV +iP+JsfDtdu+bzZeOZmhSsv4M3DZ1QPHEX+zCnotE+SeycqEr+3SaJELyjCB1twFT +pCRCQGWFKYCRwhjQ1vGY7qhD6ZDn30a96xAlPS+T35pA01rNgORJi8j9sf3oiwEe +oPQOecgFHdua5drHJ78j7MUz/Gvj02GnwKnBKbMYDGeBKJWm0ir4MxoU7HPaDwLj +jofXgIz+CMXkp+9arVu5IsZwL2MKNZ4fiM+VWZg9R73CAVpKvs6dTlQXe++DCaOr +XGiQeCPPpIC74vqWhAHuzPncGJndHlmXYGLhi0sk0wIDAQABoyEwHzAdBgNVHQ4E +FgQUhW4a3uWREJoTxodyD5u7i7mCaacwDQYJKoZIhvcNAQELBQADggIBAD/Qfkot +qklQr4r7eoHtyFCGozfZvsPwEediZORkycU/fCZozdVh95ebt2/N/jw7RlNhv+t+ +HahMoiXbLX2RUrqM/2X5U7BbxIpy3XjhcEYTJudqFfCxDQfxD1bFrWHygQzAanOb +sPHkcEt3tu2suV2YsJpHry/1BMo83WAoTgw/3dFtJ7oEoi/LaI03v9Qlp0+hLfA5 +zwyuuRqFn24FRvdWHX5GqAweF+WUdmmlkiJiKu2RtQsPoN7ITvZQs9t4l0zZ8w2v +QV0YdhWYLkS3g53oyOP8T5YlCFGuUOyo433hRyrzaxj3aFDkMbNrX9REB9v8Iz7X +aFsmLDJsfT5Spovz68HCIMDW1Sl1WqVkNN2V3Rwt72bn7DEbKZzGW9RC5eXEW1Zw +46XeYOVdEjzl/l623moWC5ZTlwPF1qRDaoZXT/1d1eAJE8ZBHm1YjwgDD5aFvylG +0OT1qWD5gx3nOmAbBk1e3r8ESMo9k29/4hycUUUgtFuWtBwBaY/O/4YoLx59wbpL +rFR/zjKIdYFj0AM2ABTgrG7v5pEhjLTnzjc+mZV7hJCBvB+bbC5vvfDg0K7lQUpJ +ruIPvqKfJyuTwkKmoTF5jmG04jwUDtA5iGUB3U3QiQ8zcbTiVRptXLEQDYw/bzDk +0fd4xTbok1ygI7wJ/KRyMvFXdbTKSvVu/tnM +-----END CERTIFICATE----- diff --git a/spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/keystore.p12 b/spring-security-modules/spring-security-web-boot-3/src/main/resources/keystore/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..6f0d9c508cc70edfb43979b88cc08b2d1155d0c6 GIT binary patch literal 4083 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 Date: Fri, 2 Apr 2021 12:10:29 +0430 Subject: [PATCH 47/61] bael-4828: add readme to new maven module --- .../spring-security-web-boot-3/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 spring-security-modules/spring-security-web-boot-3/README.md diff --git a/spring-security-modules/spring-security-web-boot-3/README.md b/spring-security-modules/spring-security-web-boot-3/README.md new file mode 100644 index 0000000000..0e962273c5 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/README.md @@ -0,0 +1,11 @@ +## Spring Boot Security MVC + +This module contains articles about Spring Security with Spring MVC in Boot applications + +### The Course +The "REST With Spring" Classes: http://github.learnspringsecurity.com + +### Relevant Articles: + +- [TLS Setup in Spring](https://www.baeldung.com/) +- More articles: [[<-- prev]](/spring-security-modules/spring-security-web-boot-2) From d7ad10fd9c78e67aac718d492b78cc153b10cb30 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Fri, 2 Apr 2021 12:14:20 +0430 Subject: [PATCH 48/61] bael-4828: remove classes and files from module spring-security-web-boot-2 --- .../java/com/baeldung/tls/HomeController.java | 16 ---------- .../java/com/baeldung/tls/SecurityConfig.java | 16 ---------- .../baeldung/tls/TLSEnabledApplication.java | 15 ---------- .../main/resources/application-tls.properties | 23 -------------- .../src/main/resources/keystore/baeldung.cer | 28 ------------------ .../src/main/resources/keystore/keystore.p12 | Bin 4083 -> 0 bytes 6 files changed, 98 deletions(-) delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer delete mode 100644 spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java deleted file mode 100644 index c72821cc9b..0000000000 --- a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/HomeController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.tls; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class HomeController { - - @GetMapping("/baeldung") - public ResponseEntity welcome() { - return new ResponseEntity<>("tls/baeldung", HttpStatus.OK); - } - -} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java deleted file mode 100644 index 63b59b8cc8..0000000000 --- a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/SecurityConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.tls; - -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@EnableWebSecurity -public class SecurityConfig extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .antMatchers("/**") - .permitAll(); - } -} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java deleted file mode 100644 index 62ba77d769..0000000000 --- a/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/tls/TLSEnabledApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.tls; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -public class TLSEnabledApplication { - - public static void main(String... args) { - SpringApplication application = new SpringApplication(TLSEnabledApplication.class); - application.setAdditionalProfiles("tls"); - application.run(args); - } -} diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties deleted file mode 100644 index 002d702eab..0000000000 --- a/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-tls.properties +++ /dev/null @@ -1,23 +0,0 @@ - -server.port=8443 - -# enable/disable https -server.ssl.enabled=true -# keystore format -server.ssl.key-store-type=PKCS12 -# keystore location -server.ssl.key-store=classpath:keystore/keystore.p12 -# keystore password -server.ssl.key-store-password=changeit -server.ssl.key-alias=baeldung -# SSL protocol to use -server.ssl.protocol=TLS -# Enabled SSL protocols -server.ssl.enabled-protocols=TLSv1.2 - -#server.ssl.client-auth=need - -#trust store location -#server.ssl.trust-store=classpath:keystore/truststore.p12 -#trust store password -#server.ssl.trust-store-password=changeit \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer deleted file mode 100644 index 1a6bb4d49b..0000000000 --- a/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.cer +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIExzCCAq+gAwIBAgIEbh/WszANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDEwls -b2NhbGhvc3QwHhcNMjEwMzIxMDgzMzU3WhcNMzEwMzE5MDgzMzU3WjAUMRIwEAYD -VQQDEwlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCD -QWvAEewDE+vFFqYPgXFJ94bMgPZT6qdb17DkWWbL2jV5QENbSYTLAPNQ1TGUgKhj -t1LCHpooLwWIo6xvhK/qZYjh3YonSIe8Eo0fBCDoZpLO+Vp0us22NBgLOYH8hvAm -zEvPXdSZo5Qkeaqjwd6kB/z083y8OL+Civ0ARXoLsn7CFslKfZp2o/aebH6i/T+3 -hWVqasIIMtfNUrxE/pnOnV8aSAt24jcm/VxbtheqIzmcOPlCXSP1RAmFez6tJsNu -2dbUhaeOf95RCaM6a43soEvLvooGa/uqBPsRojg5WEFGf7Tc7pzB+BtALwRmHAqr -hiYjVv329QGZ+g8dADBvvqvGpGysy+X0LxixvIP14KdCqG8uMYmw5cBTJHc23AHV -iP+JsfDtdu+bzZeOZmhSsv4M3DZ1QPHEX+zCnotE+SeycqEr+3SaJELyjCB1twFT -pCRCQGWFKYCRwhjQ1vGY7qhD6ZDn30a96xAlPS+T35pA01rNgORJi8j9sf3oiwEe -oPQOecgFHdua5drHJ78j7MUz/Gvj02GnwKnBKbMYDGeBKJWm0ir4MxoU7HPaDwLj -jofXgIz+CMXkp+9arVu5IsZwL2MKNZ4fiM+VWZg9R73CAVpKvs6dTlQXe++DCaOr -XGiQeCPPpIC74vqWhAHuzPncGJndHlmXYGLhi0sk0wIDAQABoyEwHzAdBgNVHQ4E -FgQUhW4a3uWREJoTxodyD5u7i7mCaacwDQYJKoZIhvcNAQELBQADggIBAD/Qfkot -qklQr4r7eoHtyFCGozfZvsPwEediZORkycU/fCZozdVh95ebt2/N/jw7RlNhv+t+ -HahMoiXbLX2RUrqM/2X5U7BbxIpy3XjhcEYTJudqFfCxDQfxD1bFrWHygQzAanOb -sPHkcEt3tu2suV2YsJpHry/1BMo83WAoTgw/3dFtJ7oEoi/LaI03v9Qlp0+hLfA5 -zwyuuRqFn24FRvdWHX5GqAweF+WUdmmlkiJiKu2RtQsPoN7ITvZQs9t4l0zZ8w2v -QV0YdhWYLkS3g53oyOP8T5YlCFGuUOyo433hRyrzaxj3aFDkMbNrX9REB9v8Iz7X -aFsmLDJsfT5Spovz68HCIMDW1Sl1WqVkNN2V3Rwt72bn7DEbKZzGW9RC5eXEW1Zw -46XeYOVdEjzl/l623moWC5ZTlwPF1qRDaoZXT/1d1eAJE8ZBHm1YjwgDD5aFvylG -0OT1qWD5gx3nOmAbBk1e3r8ESMo9k29/4hycUUUgtFuWtBwBaY/O/4YoLx59wbpL -rFR/zjKIdYFj0AM2ABTgrG7v5pEhjLTnzjc+mZV7hJCBvB+bbC5vvfDg0K7lQUpJ -ruIPvqKfJyuTwkKmoTF5jmG04jwUDtA5iGUB3U3QiQ8zcbTiVRptXLEQDYw/bzDk -0fd4xTbok1ygI7wJ/KRyMvFXdbTKSvVu/tnM ------END CERTIFICATE----- diff --git a/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/keystore.p12 deleted file mode 100644 index 6f0d9c508cc70edfb43979b88cc08b2d1155d0c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4083 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 Date: Fri, 2 Apr 2021 15:21:04 +0200 Subject: [PATCH 49/61] JAVA-3596: Upgrade exec-maven-plugin to 3.0.0 in the main pom.xml --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 13f24d7aea..ab3c73ff8a 100644 --- a/pom.xml +++ b/pom.xml @@ -1375,13 +1375,12 @@ 2.21.0 3.8.1 - 1.6.0 + 3.0.0 1.8 1.2.17 2.2.2.0 1.28 1.28 - 1.6.0 2.21.0 2.8.0 2.6 From 63e5a2dad069a16e59e34fa598de3655e32bbf79 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 2 Apr 2021 15:43:27 +0200 Subject: [PATCH 50/61] JAVA-3596: Clean up exec-maven-plugin config --- algorithms-genetic/pom.xml | 12 ------------ algorithms-miscellaneous-1/pom.xml | 12 ------------ algorithms-miscellaneous-2/pom.xml | 12 ------------ algorithms-miscellaneous-3/pom.xml | 12 ------------ algorithms-miscellaneous-4/pom.xml | 12 ------------ algorithms-miscellaneous-5/pom.xml | 12 ------------ algorithms-sorting-2/pom.xml | 12 ------------ algorithms-sorting/pom.xml | 12 ------------ apache-cxf/pom.xml | 1 - core-java-modules/core-java-console/pom.xml | 3 --- core-java-modules/core-java-io/pom.xml | 2 -- core-java-modules/core-java-jar/pom.xml | 3 --- .../core-java-lang-math-2/pom.xml | 12 ------------ core-java-modules/core-java-sun/pom.xml | 2 -- core-java-modules/core-java/pom.xml | 3 --- data-structures/pom.xml | 1 - libraries-3/pom.xml | 2 -- libraries-concurrency/pom.xml | 1 - micronaut/pom.xml | 2 -- .../jnosql/jnosql-diana/pom.xml | 1 - saas/pom.xml | 1 - slack/pom.xml | 1 - .../property-exp-custom-config/pom.xml | 2 -- spring-integration/pom.xml | 2 -- testing-modules/junit-5/pom.xml | 16 ---------------- testing-modules/junit5-migration/pom.xml | 18 ------------------ testing-modules/test-containers/pom.xml | 1 - 27 files changed, 170 deletions(-) diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index 942acd69c6..4d15464138 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -44,18 +44,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.6.1 3.7.0 diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index d9ecbd78e8..00cb4eeda9 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -49,18 +49,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml index 7144a7a391..89d5b3657a 100644 --- a/algorithms-miscellaneous-2/pom.xml +++ b/algorithms-miscellaneous-2/pom.xml @@ -54,18 +54,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml index 4b67a30abb..166a7be623 100644 --- a/algorithms-miscellaneous-3/pom.xml +++ b/algorithms-miscellaneous-3/pom.xml @@ -74,18 +74,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.9.0 4.3 diff --git a/algorithms-miscellaneous-4/pom.xml b/algorithms-miscellaneous-4/pom.xml index 50fef5ff71..31a6db5354 100644 --- a/algorithms-miscellaneous-4/pom.xml +++ b/algorithms-miscellaneous-4/pom.xml @@ -34,18 +34,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.9.0 27.0.1-jre diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml index 615cf03467..71a5a3d410 100644 --- a/algorithms-miscellaneous-5/pom.xml +++ b/algorithms-miscellaneous-5/pom.xml @@ -49,18 +49,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 1.0.1 3.9.0 diff --git a/algorithms-sorting-2/pom.xml b/algorithms-sorting-2/pom.xml index 529474afda..5ef90b9825 100644 --- a/algorithms-sorting-2/pom.xml +++ b/algorithms-sorting-2/pom.xml @@ -44,18 +44,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.6.1 3.9.0 diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml index 2de8eed04e..1d0b7718ac 100644 --- a/algorithms-sorting/pom.xml +++ b/algorithms-sorting/pom.xml @@ -45,18 +45,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.6.1 3.9.0 diff --git a/apache-cxf/pom.xml b/apache-cxf/pom.xml index 3d64000c2e..0975996c06 100644 --- a/apache-cxf/pom.xml +++ b/apache-cxf/pom.xml @@ -30,7 +30,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} diff --git a/core-java-modules/core-java-console/pom.xml b/core-java-modules/core-java-console/pom.xml index 1d58d8c253..fc4f1875ca 100644 --- a/core-java-modules/core-java-console/pom.xml +++ b/core-java-modules/core-java-console/pom.xml @@ -45,7 +45,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -105,7 +104,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} run-benchmarks @@ -134,7 +132,6 @@ 3.0.0-M1 - 1.6.0 1.8 1.8 diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 0968536e65..02b5adae7c 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -60,7 +60,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -108,7 +107,6 @@ org.codehaus.mojo exec-maven-plugin - run-benchmarks diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index 6e9d713d7c..45500de739 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -189,7 +189,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -249,7 +248,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} run-benchmarks @@ -397,7 +395,6 @@ 1.4.4 3.1.1 2.0.3.RELEASE - 1.6.0 1.8 1.8 diff --git a/core-java-modules/core-java-lang-math-2/pom.xml b/core-java-modules/core-java-lang-math-2/pom.xml index 42704c784a..56e18158b3 100644 --- a/core-java-modules/core-java-lang-math-2/pom.xml +++ b/core-java-modules/core-java-lang-math-2/pom.xml @@ -62,18 +62,6 @@ - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - 3.6.1 3.9.0 diff --git a/core-java-modules/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml index 0f53407ec1..541af2445f 100644 --- a/core-java-modules/core-java-sun/pom.xml +++ b/core-java-modules/core-java-sun/pom.xml @@ -44,7 +44,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -68,7 +67,6 @@ org.codehaus.mojo exec-maven-plugin - run-benchmarks diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml index b8d75058eb..9b595288e6 100644 --- a/core-java-modules/core-java/pom.xml +++ b/core-java-modules/core-java/pom.xml @@ -94,7 +94,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -154,7 +153,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} run-benchmarks @@ -193,7 +191,6 @@ 1.1 3.0.0-M1 - 1.6.0 1.8 1.8 diff --git a/data-structures/pom.xml b/data-structures/pom.xml index e2d2e23090..7bf34b1c63 100644 --- a/data-structures/pom.xml +++ b/data-structures/pom.xml @@ -35,7 +35,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index 2f6e9fa747..3d3b5db890 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -189,7 +189,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} start-server @@ -229,7 +228,6 @@ 4.4.13 4.5.12 2.2 - 1.6.0 0.3.0 2.8 2.1.3 diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml index b7dc5187b1..66296d829f 100644 --- a/libraries-concurrency/pom.xml +++ b/libraries-concurrency/pom.xml @@ -47,7 +47,6 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 com.baeldung.quasar.App target/classes diff --git a/micronaut/pom.xml b/micronaut/pom.xml index d6df6a0347..bd0022c9e1 100644 --- a/micronaut/pom.xml +++ b/micronaut/pom.xml @@ -102,7 +102,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec.plugin.version} java @@ -146,7 +145,6 @@ 1.2.3 3.1.6.RELEASE 3.7.0 - 1.6.0 3.1.0 diff --git a/persistence-modules/jnosql/jnosql-diana/pom.xml b/persistence-modules/jnosql/jnosql-diana/pom.xml index 79c455646c..d5746eef05 100644 --- a/persistence-modules/jnosql/jnosql-diana/pom.xml +++ b/persistence-modules/jnosql/jnosql-diana/pom.xml @@ -55,7 +55,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} document diff --git a/saas/pom.xml b/saas/pom.xml index be5d18f020..93965b37c4 100644 --- a/saas/pom.xml +++ b/saas/pom.xml @@ -40,7 +40,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} java com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed diff --git a/slack/pom.xml b/slack/pom.xml index ebe5ce2f60..51a4cf029f 100644 --- a/slack/pom.xml +++ b/slack/pom.xml @@ -45,7 +45,6 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 com.baeldung.examples.slack.MainClass diff --git a/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/pom.xml b/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/pom.xml index f0df50cf76..07aeca9ad2 100644 --- a/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/pom.xml +++ b/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/pom.xml @@ -69,7 +69,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} com.baeldung.propertyexpansion.SpringBootPropertyExpansionApp @@ -80,7 +79,6 @@ Custom Property Value 2.7 - 1.6.0 diff --git a/spring-integration/pom.xml b/spring-integration/pom.xml index 11b2803095..f46445a39f 100644 --- a/spring-integration/pom.xml +++ b/spring-integration/pom.xml @@ -108,7 +108,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} com.baeldung.samples.FileCopyConfig @@ -122,7 +121,6 @@ 1.4.7 1.1.1 2.10 - 1.5.0 1.4.197 diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index ded3e9e26d..63d766a469 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -105,21 +105,6 @@ - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - java - - - - - com.baeldung.TestLauncher - - org.apache.maven.plugins maven-surefire-report-plugin @@ -136,7 +121,6 @@ 2.8.2 2.0.0 2.22.0 - 1.6.0 5.0.1.RELEASE 3.0.0-M3 diff --git a/testing-modules/junit5-migration/pom.xml b/testing-modules/junit5-migration/pom.xml index e3ef21f506..bab7bc0406 100644 --- a/testing-modules/junit5-migration/pom.xml +++ b/testing-modules/junit5-migration/pom.xml @@ -47,23 +47,6 @@ true - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - java - - - - - com.baeldung.TestLauncher - - - @@ -71,7 +54,6 @@ 1.2.0 5.2.0 2.21.0 - 1.6.0 diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml index 1946b7306f..3fad49edca 100644 --- a/testing-modules/test-containers/pom.xml +++ b/testing-modules/test-containers/pom.xml @@ -83,7 +83,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} From 34e77a64a8e3a25c3f2d5c539794c81283fc71af Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 3 Apr 2021 12:06:08 +0300 Subject: [PATCH 51/61] use junit 5, change log level --- .../src/main/resources/logback.xml | 13 +++++++++++++ .../projection/JpaProjectionIntegrationTest.java | 5 +---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/resources/logback.xml diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/resources/logback.xml b/persistence-modules/spring-data-jpa-filtering/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java index 96eaf4ed07..5fdcf6a787 100644 --- a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java @@ -6,18 +6,15 @@ import com.baeldung.projection.repository.PersonRepository; import com.baeldung.projection.view.AddressView; import com.baeldung.projection.view.PersonDto; import com.baeldung.projection.view.PersonView; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; @DataJpaTest -@RunWith(SpringRunner.class) @Sql(scripts = "/projection-insert-data.sql") @Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD) public class JpaProjectionIntegrationTest { From d211a24aed463859c0f74fbabc79413f66f5a719 Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 4 Apr 2021 11:44:22 -0400 Subject: [PATCH 52/61] Update pom.xml Removed dulicate modules --- spring-security-modules/pom.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 29f753b9be..bb2702fc9d 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -22,12 +22,6 @@ spring-security-auth0 spring-security-config spring-security-core - spring-security-web-mvc - spring-security-web-boot-1 - spring-security-web-boot-2 - spring-security-web-boot-3 - spring-security-web-mvc-custom - spring-security-web-digest-auth spring-security-ldap spring-security-legacy-oidc spring-security-oauth2-sso @@ -37,6 +31,7 @@ spring-security-web-angular/server spring-security-web-boot-1 spring-security-web-boot-2 + spring-security-web-boot-3 spring-security-web-digest-auth spring-security-web-login spring-security-web-mvc-custom From 71119f2193b49574e29a546c6bd3e8e8544ec98c Mon Sep 17 00:00:00 2001 From: Amit Bhave Date: Sun, 4 Apr 2021 21:49:59 +0530 Subject: [PATCH 53/61] BAEL-3636 Add degrade and system protection rules configurations --- .../config/SentinelAspectConfiguration.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java index 8ddceaa58f..4dfacef999 100644 --- a/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java +++ b/spring-cloud/spring-cloud-sentinel/src/main/java/com/baeldung/spring/cloud/sentinel/config/SentinelAspectConfiguration.java @@ -2,8 +2,12 @@ package com.baeldung.spring.cloud.sentinel.config; import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; +import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import com.alibaba.csp.sentinel.slots.system.SystemRule; +import com.alibaba.csp.sentinel.slots.system.SystemRuleManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -14,17 +18,25 @@ import java.util.List; @Configuration public class SentinelAspectConfiguration { + public static final String RESOURCE_NAME = "greeting"; + @Bean public SentinelResourceAspect sentinelResourceAspect() { return new SentinelResourceAspect(); } @PostConstruct - public void initFlowRules() { + public void init() { + initFlowRules(); + initDegradeRules(); + initSystemProtectionRules(); + } + + private void initFlowRules() { List flowRules = new ArrayList<>(); FlowRule flowRule = new FlowRule(); // Defined resource - flowRule.setResource("greeting"); + flowRule.setResource(RESOURCE_NAME); flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); // number of requests that QPS can pass in a second flowRule.setCount(1); @@ -32,4 +44,22 @@ public class SentinelAspectConfiguration { FlowRuleManager.loadRules(flowRules); } + private void initDegradeRules() { + List rules = new ArrayList(); + DegradeRule rule = new DegradeRule(); + rule.setResource(RESOURCE_NAME); + rule.setCount(10); + rule.setTimeWindow(10); + rules.add(rule); + DegradeRuleManager.loadRules(rules); + } + + private void initSystemProtectionRules() { + List rules = new ArrayList<>(); + SystemRule rule = new SystemRule(); + rule.setHighestSystemLoad(10); + rules.add(rule); + SystemRuleManager.loadRules(rules); + } + } From 7b7324f6fc6df904462b2df5d027b9aaa6a246b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20G=C5=82=C3=B3wka?= Date: Tue, 6 Apr 2021 00:30:08 +0200 Subject: [PATCH 54/61] BAEL-4290: fixed tests (#10632) --- .../autoproxying/EligibleForAutoProxyingIntegrationTest.java | 2 +- .../autoproxying/NotEligibleForAutoProxyingIntegrationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-core-5/src/test/java/com/baeldung/component/autoproxying/EligibleForAutoProxyingIntegrationTest.java b/spring-core-5/src/test/java/com/baeldung/component/autoproxying/EligibleForAutoProxyingIntegrationTest.java index 4af700813a..c7943e355b 100644 --- a/spring-core-5/src/test/java/com/baeldung/component/autoproxying/EligibleForAutoProxyingIntegrationTest.java +++ b/spring-core-5/src/test/java/com/baeldung/component/autoproxying/EligibleForAutoProxyingIntegrationTest.java @@ -40,7 +40,7 @@ public class EligibleForAutoProxyingIntegrationTest { @Test public void givenAutowireInBeanPostProcessor_whenSpringContextInitialize_thenNotEligibleLogShouldShowAndGroupFieldPopulated() { - List notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.autoproxying.RandomIntGenerator] " + + List notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.component.autoproxying.RandomIntGenerator] " + "is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)"); assertEquals(0, notEligibleEvents.size()); diff --git a/spring-core-5/src/test/java/com/baeldung/component/autoproxying/NotEligibleForAutoProxyingIntegrationTest.java b/spring-core-5/src/test/java/com/baeldung/component/autoproxying/NotEligibleForAutoProxyingIntegrationTest.java index 9434f77a30..f49f1ce602 100644 --- a/spring-core-5/src/test/java/com/baeldung/component/autoproxying/NotEligibleForAutoProxyingIntegrationTest.java +++ b/spring-core-5/src/test/java/com/baeldung/component/autoproxying/NotEligibleForAutoProxyingIntegrationTest.java @@ -39,7 +39,7 @@ public class NotEligibleForAutoProxyingIntegrationTest { @Test public void givenAutowireInBeanPostProcessor_whenSpringContextInitialize_thenNotEligibleLogShouldShowAndGroupFieldNotPopulated() { - List notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.autoproxying.RandomIntGenerator] " + + List notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.component.autoproxying.RandomIntGenerator] " + "is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)"); assertEquals(1, notEligibleEvents.size()); From a23b752f7569a9b3a43f291ee1d0219c0f3cf69f Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 6 Apr 2021 22:31:47 +0200 Subject: [PATCH 55/61] JAVA-3596: Fix exec-maven-plugin config in the testing-modules --- testing-modules/junit-5/pom.xml | 15 +++++++++++++++ testing-modules/test-containers/pom.xml | 16 ---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 63d766a469..90898ebb3f 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -105,6 +105,21 @@ + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + + java + + + + + com.baeldung.TestLauncher + + org.apache.maven.plugins maven-surefire-report-plugin diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml index 3fad49edca..2280a89b4a 100644 --- a/testing-modules/test-containers/pom.xml +++ b/testing-modules/test-containers/pom.xml @@ -79,22 +79,6 @@ true - - - org.codehaus.mojo - exec-maven-plugin - - - - java - - - - - com.baeldung.TestLauncher - - - From cdaac992a46b83d9bae4fd8e43fcf0519071379a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 7 Apr 2021 16:30:30 +0800 Subject: [PATCH 56/61] Update README.md --- spring-boot-modules/spring-boot-actuator/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-actuator/README.md b/spring-boot-modules/spring-boot-actuator/README.md index 3e8ef3411b..9e2f30786f 100644 --- a/spring-boot-modules/spring-boot-actuator/README.md +++ b/spring-boot-modules/spring-boot-actuator/README.md @@ -10,3 +10,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Liveness and Readiness Probes in Spring Boot](https://www.baeldung.com/spring-liveness-readiness-probes) - [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom) - [Health Indicators in Spring Boot](https://www.baeldung.com/spring-boot-health-indicators) +- [How to Enable All Endpoints in Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuator-enable-endpoints) From ca37bcc876afddd2ccc621dc1fd44b2841f5573a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 7 Apr 2021 16:33:34 +0800 Subject: [PATCH 57/61] Create README.md --- spring-web-modules/spring-boot-jsp/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-web-modules/spring-boot-jsp/README.md diff --git a/spring-web-modules/spring-boot-jsp/README.md b/spring-web-modules/spring-boot-jsp/README.md new file mode 100644 index 0000000000..535f86531d --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Boot With JavaServer Pages (JSP)](https://www.baeldung.com/spring-boot-jsp) From f932667dbd9df388f86d2d3f1b172960606d43e7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 7 Apr 2021 16:36:09 +0800 Subject: [PATCH 58/61] Update README.md --- spring-5-reactive-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive-2/README.md b/spring-5-reactive-2/README.md index 397f6be57c..98a5f26433 100644 --- a/spring-5-reactive-2/README.md +++ b/spring-5-reactive-2/README.md @@ -9,4 +9,5 @@ This module contains articles about reactive Spring 5 - [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) - [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content) - [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) +- [Backpressure Mechanism in Spring WebFlux](https://www.baeldung.com/spring-webflux-backpressure) - More articles: [[<-- prev]](/spring-5-reactive) From 3f3e27ee6a61b2262dd8cafeb89f1d9e9de0de68 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 7 Apr 2021 16:39:07 +0800 Subject: [PATCH 59/61] Update README.md --- spring-security-modules/spring-security-web-boot-3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-web-boot-3/README.md b/spring-security-modules/spring-security-web-boot-3/README.md index 0e962273c5..aeba397f40 100644 --- a/spring-security-modules/spring-security-web-boot-3/README.md +++ b/spring-security-modules/spring-security-web-boot-3/README.md @@ -7,5 +7,5 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com ### Relevant Articles: -- [TLS Setup in Spring](https://www.baeldung.com/) +- [TLS Setup in Spring](https://www.baeldung.com/spring-tls-setup) - More articles: [[<-- prev]](/spring-security-modules/spring-security-web-boot-2) From 6d98814a0a8cae3160bd50654f69dd270f299f53 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Thu, 8 Apr 2021 00:14:32 +0530 Subject: [PATCH 60/61] added a new readme file --- spring-cloud/spring-cloud-docker/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-cloud/spring-cloud-docker/README.md diff --git a/spring-cloud/spring-cloud-docker/README.md b/spring-cloud/spring-cloud-docker/README.md new file mode 100644 index 0000000000..018d4ab1eb --- /dev/null +++ b/spring-cloud/spring-cloud-docker/README.md @@ -0,0 +1,3 @@ +## Relevant Articles: + +- [Dockerizing a Spring Boot Application](https://www.baeldung.com/dockerizing-spring-boot-application) From a378cb75318c49be86f43b6c02bce638426d42a0 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Thu, 8 Apr 2021 00:22:17 +0530 Subject: [PATCH 61/61] Delete README.md --- spring-5/src/test/java/com/baeldung/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-5/src/test/java/com/baeldung/README.md diff --git a/spring-5/src/test/java/com/baeldung/README.md b/spring-5/src/test/java/com/baeldung/README.md deleted file mode 100644 index 0ff61914d5..0000000000 --- a/spring-5/src/test/java/com/baeldung/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests)