From 112f33acb9a0fd45fc640091ab836d9a0bbdfae0 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 13 Dec 2017 11:25:47 +0100 Subject: [PATCH 1/8] Optimize build (#3227) * Exclude NeurophTest * Fix build --- ...itoryInitialMigrationIntegrationTest.java} | 2 +- ...rRepositoryInsertDataIntegrationTest.java} | 2 +- ...llConstraintMigrationIntegrationTest.java} | 2 +- ...nstraintJavaMigrationIntegrationTest.java} | 2 +- ...ueConstraintMigrationIntegrationTest.java} | 2 +- .../{XORTest.java => XORIntegrationTest.java} | 2 +- pom.xml | 3 +- spring-acl/pom.xml | 66 ---------- .../org/baeldung/acl/config/ACLContext.java | 80 ------------ .../AclMethodSecurityConfiguration.java | 21 ---- .../acl/config/JPAPersistenceConfig.java | 16 --- .../dao/NoticeMessageRepository.java | 24 ---- .../acl/persistence/entity/NoticeMessage.java | 29 ----- spring-acl/src/main/resources/acl-data.sql | 28 ----- spring-acl/src/main/resources/acl-schema.sql | 58 --------- .../org.baeldung.acl.datasource.properties | 12 -- .../java/org/baeldung/acl/SpringAclTest.java | 119 ------------------ ...est.java => SpringACLIntegrationTest.java} | 2 +- 18 files changed, 8 insertions(+), 462 deletions(-) rename flyway/spring-flyway/src/test/java/com/baeldung/springflyway/{CustomerRepositoryInitialMigrationTest.java => CustomerRepositoryInitialMigrationIntegrationTest.java} (92%) rename flyway/spring-flyway/src/test/java/com/baeldung/springflyway/{CustomerRepositoryInsertDataMigrationTest.java => CustomerRepositoryInsertDataIntegrationTest.java} (94%) rename flyway/spring-flyway/src/test/java/com/baeldung/springflyway/{CustomerRepositoryNotNullConstraintMigrationTest.java => CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java} (91%) rename flyway/spring-flyway/src/test/java/com/baeldung/springflyway/{CustomerRepositoryUniqueConstraintJavaMigrationTest.java => CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java} (92%) rename flyway/spring-flyway/src/test/java/com/baeldung/springflyway/{CustomerRepositoryUniqueConstraintMigrationTest.java => CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java} (92%) rename libraries/src/test/java/com/baeldung/neuroph/{XORTest.java => XORIntegrationTest.java} (97%) delete mode 100644 spring-acl/pom.xml delete mode 100644 spring-acl/src/main/java/org/baeldung/acl/config/ACLContext.java delete mode 100644 spring-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java delete mode 100644 spring-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java delete mode 100644 spring-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java delete mode 100644 spring-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java delete mode 100644 spring-acl/src/main/resources/acl-data.sql delete mode 100644 spring-acl/src/main/resources/acl-schema.sql delete mode 100644 spring-acl/src/main/resources/org.baeldung.acl.datasource.properties delete mode 100644 spring-acl/src/test/java/org/baeldung/acl/SpringAclTest.java rename spring-security-acl/src/test/java/org/baeldung/acl/{SpringAclTest.java => SpringACLIntegrationTest.java} (98%) diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java similarity index 92% rename from flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationTest.java rename to flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java index b3f2cb29e1..59ef5820d7 100644 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationTest.java +++ b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java @@ -12,7 +12,7 @@ import static org.junit.Assert.assertNotNull; @RunWith(SpringRunner.class) @SpringBootTest -public class CustomerRepositoryInitialMigrationTest { +public class CustomerRepositoryInitialMigrationIntegrationTest { @Autowired CustomerRepository customerRepository; diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataMigrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java similarity index 94% rename from flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataMigrationTest.java rename to flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java index 369e61d98f..3feedf2fd9 100644 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataMigrationTest.java +++ b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.*; @RunWith(SpringRunner.class) @SpringBootTest -public class CustomerRepositoryInsertDataMigrationTest { +public class CustomerRepositoryInsertDataIntegrationTest { @Autowired CustomerRepository customerRepository; diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java similarity index 91% rename from flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationTest.java rename to flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java index 90517c9225..9ec5d4d77e 100644 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationTest.java +++ b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java @@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class CustomerRepositoryNotNullConstraintMigrationTest { +public class CustomerRepositoryNotNullConstraintMigrationIntegrationTest { @Autowired CustomerRepository customerRepository; diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java similarity index 92% rename from flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationTest.java rename to flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java index e5ba782fda..f615f477bc 100644 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationTest.java +++ b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest(properties = { "flyway.locations[0]=db/migration", "flyway.locations[1]=com/baeldung/springflyway/migration" }) -public class CustomerRepositoryUniqueConstraintJavaMigrationTest { +public class CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest { @Autowired CustomerRepository customerRepository; diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java similarity index 92% rename from flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationTest.java rename to flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java index 9fa2dee42d..e9ac34b384 100644 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationTest.java +++ b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java @@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class CustomerRepositoryUniqueConstraintMigrationTest { +public class CustomerRepositoryUniqueConstraintMigrationIntegrationTest { @Autowired CustomerRepository customerRepository; diff --git a/libraries/src/test/java/com/baeldung/neuroph/XORTest.java b/libraries/src/test/java/com/baeldung/neuroph/XORIntegrationTest.java similarity index 97% rename from libraries/src/test/java/com/baeldung/neuroph/XORTest.java rename to libraries/src/test/java/com/baeldung/neuroph/XORIntegrationTest.java index 4a6ecf8e46..5da1d166f6 100644 --- a/libraries/src/test/java/com/baeldung/neuroph/XORTest.java +++ b/libraries/src/test/java/com/baeldung/neuroph/XORIntegrationTest.java @@ -7,7 +7,7 @@ import org.neuroph.core.NeuralNetwork; import static org.junit.Assert.*; -public class XORTest { +public class XORIntegrationTest { private NeuralNetwork ann = null; private void print(String input, double output, double actual) { diff --git a/pom.xml b/pom.xml index cf01712cba..b3da4655d6 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,6 @@ spark-java spring-5-mvc - spring-acl spring-activiti spring-akka spring-amqp @@ -152,7 +151,7 @@ spring-batch spring-bom spring-boot - spring-boot-keycloak + spring-boot-keycloak spring-boot-bootstrap spring-cloud-data-flow spring-cloud diff --git a/spring-acl/pom.xml b/spring-acl/pom.xml deleted file mode 100644 index 3bcc0cf596..0000000000 --- a/spring-acl/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - - com.baeldung - spring-acl - 0.0.1-SNAPSHOT - war - - spring-acl - Spring ACL - - - parent-boot-5 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-5 - - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - com.h2database - h2 - - - - org.springframework - spring-test - test - - - - org.springframework.security - spring-security-test - test - - - - org.springframework.security - spring-security-acl - - - org.springframework.security - spring-security-config - - - org.springframework - spring-context-support - - - net.sf.ehcache - ehcache-core - 2.6.11 - jar - - - - - diff --git a/spring-acl/src/main/java/org/baeldung/acl/config/ACLContext.java b/spring-acl/src/main/java/org/baeldung/acl/config/ACLContext.java deleted file mode 100644 index 63a4ea58ef..0000000000 --- a/spring-acl/src/main/java/org/baeldung/acl/config/ACLContext.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.baeldung.acl.config; - -import javax.sql.DataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cache.ehcache.EhCacheFactoryBean; -import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; -import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; -import org.springframework.security.acls.AclPermissionCacheOptimizer; -import org.springframework.security.acls.AclPermissionEvaluator; -import org.springframework.security.acls.domain.AclAuthorizationStrategy; -import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl; -import org.springframework.security.acls.domain.ConsoleAuditLogger; -import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy; -import org.springframework.security.acls.domain.EhCacheBasedAclCache; -import org.springframework.security.acls.jdbc.BasicLookupStrategy; -import org.springframework.security.acls.jdbc.JdbcMutableAclService; -import org.springframework.security.acls.jdbc.LookupStrategy; -import org.springframework.security.acls.model.PermissionGrantingStrategy; -import org.springframework.security.core.authority.SimpleGrantedAuthority; - -@Configuration -@EnableAutoConfiguration -public class ACLContext { - - @Autowired - DataSource dataSource; - - @Bean - public EhCacheBasedAclCache aclCache() { - return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(), permissionGrantingStrategy(), aclAuthorizationStrategy()); - } - - @Bean - public EhCacheFactoryBean aclEhCacheFactoryBean() { - EhCacheFactoryBean ehCacheFactoryBean = new EhCacheFactoryBean(); - ehCacheFactoryBean.setCacheManager(aclCacheManager().getObject()); - ehCacheFactoryBean.setCacheName("aclCache"); - return ehCacheFactoryBean; - } - - @Bean - public EhCacheManagerFactoryBean aclCacheManager() { - return new EhCacheManagerFactoryBean(); - } - - @Bean - public PermissionGrantingStrategy permissionGrantingStrategy() { - return new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()); - } - - @Bean - public AclAuthorizationStrategy aclAuthorizationStrategy() { - return new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_ADMIN")); - } - - @Bean - public MethodSecurityExpressionHandler defaultMethodSecurityExpressionHandler() { - DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler(); - AclPermissionEvaluator permissionEvaluator = new AclPermissionEvaluator(aclService()); - expressionHandler.setPermissionEvaluator(permissionEvaluator); - expressionHandler.setPermissionCacheOptimizer(new AclPermissionCacheOptimizer(aclService())); - return expressionHandler; - } - - @Bean - public LookupStrategy lookupStrategy() { - return new BasicLookupStrategy(dataSource, aclCache(), aclAuthorizationStrategy(), new ConsoleAuditLogger()); - } - - @Bean - public JdbcMutableAclService aclService() { - return new JdbcMutableAclService(dataSource, lookupStrategy(), aclCache()); - } - -} \ No newline at end of file diff --git a/spring-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java b/spring-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java deleted file mode 100644 index 110c4a6d24..0000000000 --- a/spring-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.baeldung.acl.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; - -@Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) -public class AclMethodSecurityConfiguration extends GlobalMethodSecurityConfiguration { - - @Autowired - MethodSecurityExpressionHandler defaultMethodSecurityExpressionHandler; - - @Override - protected MethodSecurityExpressionHandler createExpressionHandler() { - return defaultMethodSecurityExpressionHandler; - } - -} diff --git a/spring-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java b/spring-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java deleted file mode 100644 index 9b87efa92c..0000000000 --- a/spring-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.baeldung.acl.config; - -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@Configuration -@EnableTransactionManagement -@EnableJpaRepositories(basePackages = "org.baeldung.acl.persistence.dao") -@PropertySource("classpath:org.baeldung.acl.datasource.properties") -@EntityScan(basePackages={ "org.baeldung.acl.persistence.entity" }) -public class JPAPersistenceConfig { - -} diff --git a/spring-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java b/spring-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java deleted file mode 100644 index 8662c88d6c..0000000000 --- a/spring-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.baeldung.acl.persistence.dao; - -import java.util.List; - -import org.baeldung.acl.persistence.entity.NoticeMessage; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.query.Param; -import org.springframework.security.access.prepost.PostAuthorize; -import org.springframework.security.access.prepost.PostFilter; -import org.springframework.security.access.prepost.PreAuthorize; - -public interface NoticeMessageRepository extends JpaRepository{ - - @PostFilter("hasPermission(filterObject, 'READ')") - List findAll(); - - @PostAuthorize("hasPermission(returnObject, 'READ')") - NoticeMessage findById(Integer id); - - @SuppressWarnings("unchecked") - @PreAuthorize("hasPermission(#noticeMessage, 'WRITE')") - NoticeMessage save(@Param("noticeMessage")NoticeMessage noticeMessage); - -} diff --git a/spring-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java b/spring-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java deleted file mode 100644 index 23f01a8edb..0000000000 --- a/spring-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.baeldung.acl.persistence.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name="system_message") -public class NoticeMessage { - - @Id - @Column - private Integer id; - @Column - private String content; - public Integer getId() { - return id; - } - public void setId(Integer id) { - this.id = id; - } - public String getContent() { - return content; - } - public void setContent(String content) { - this.content = content; - } -} \ No newline at end of file diff --git a/spring-acl/src/main/resources/acl-data.sql b/spring-acl/src/main/resources/acl-data.sql deleted file mode 100644 index 6c01eaacc2..0000000000 --- a/spring-acl/src/main/resources/acl-data.sql +++ /dev/null @@ -1,28 +0,0 @@ -INSERT INTO system_message(id,content) VALUES (1,'First Level Message'); -INSERT INTO system_message(id,content) VALUES (2,'Second Level Message'); -INSERT INTO system_message(id,content) VALUES (3,'Third Level Message'); - -INSERT INTO acl_class (id, class) VALUES -(1, 'org.baeldung.acl.persistence.entity.NoticeMessage'); - -INSERT INTO acl_sid (id, principal, sid) VALUES -(1, 1, 'manager'), -(2, 1, 'hr'), -(3, 1, 'admin'), -(4, 0, 'ROLE_EDITOR'); - -INSERT INTO acl_object_identity (id, object_id_class, object_id_identity, parent_object, owner_sid, entries_inheriting) VALUES -(1, 1, 1, NULL, 3, 0), -(2, 1, 2, NULL, 3, 0), -(3, 1, 3, NULL, 3, 0) -; - -INSERT INTO acl_entry (id, acl_object_identity, ace_order, sid, mask, granting, audit_success, audit_failure) VALUES -(1, 1, 1, 1, 1, 1, 1, 1), -(2, 1, 2, 1, 2, 1, 1, 1), -(3, 1, 3, 4, 1, 1, 1, 1), -(4, 2, 1, 2, 1, 1, 1, 1), -(5, 2, 2, 4, 1, 1, 1, 1), -(6, 3, 1, 4, 1, 1, 1, 1), -(7, 3, 2, 4, 2, 1, 1, 1) -; \ No newline at end of file diff --git a/spring-acl/src/main/resources/acl-schema.sql b/spring-acl/src/main/resources/acl-schema.sql deleted file mode 100644 index 58e9394b2b..0000000000 --- a/spring-acl/src/main/resources/acl-schema.sql +++ /dev/null @@ -1,58 +0,0 @@ -create table system_message (id integer not null, content varchar(255), primary key (id)); - -CREATE TABLE IF NOT EXISTS acl_sid ( - id bigint(20) NOT NULL AUTO_INCREMENT, - principal tinyint(1) NOT NULL, - sid varchar(100) NOT NULL, - PRIMARY KEY (id), - UNIQUE KEY unique_uk_1 (sid,principal) -); - -CREATE TABLE IF NOT EXISTS acl_class ( - id bigint(20) NOT NULL AUTO_INCREMENT, - class varchar(255) NOT NULL, - PRIMARY KEY (id), - UNIQUE KEY unique_uk_2 (class) -); - -CREATE TABLE IF NOT EXISTS acl_entry ( - id bigint(20) NOT NULL AUTO_INCREMENT, - acl_object_identity bigint(20) NOT NULL, - ace_order int(11) NOT NULL, - sid bigint(20) NOT NULL, - mask int(11) NOT NULL, - granting tinyint(1) NOT NULL, - audit_success tinyint(1) NOT NULL, - audit_failure tinyint(1) NOT NULL, - PRIMARY KEY (id), - UNIQUE KEY unique_uk_4 (acl_object_identity,ace_order) -); - -CREATE TABLE IF NOT EXISTS acl_object_identity ( - id bigint(20) NOT NULL AUTO_INCREMENT, - object_id_class bigint(20) NOT NULL, - object_id_identity bigint(20) NOT NULL, - parent_object bigint(20) DEFAULT NULL, - owner_sid bigint(20) DEFAULT NULL, - entries_inheriting tinyint(1) NOT NULL, - PRIMARY KEY (id), - UNIQUE KEY unique_uk_3 (object_id_class,object_id_identity) -); - -ALTER TABLE acl_entry -ADD FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id); - -ALTER TABLE acl_entry -ADD FOREIGN KEY (sid) REFERENCES acl_sid(id); - --- --- Constraints for table acl_object_identity --- -ALTER TABLE acl_object_identity -ADD FOREIGN KEY (parent_object) REFERENCES acl_object_identity (id); - -ALTER TABLE acl_object_identity -ADD FOREIGN KEY (object_id_class) REFERENCES acl_class (id); - -ALTER TABLE acl_object_identity -ADD FOREIGN KEY (owner_sid) REFERENCES acl_sid (id); \ No newline at end of file diff --git a/spring-acl/src/main/resources/org.baeldung.acl.datasource.properties b/spring-acl/src/main/resources/org.baeldung.acl.datasource.properties deleted file mode 100644 index 739dd3f07c..0000000000 --- a/spring-acl/src/main/resources/org.baeldung.acl.datasource.properties +++ /dev/null @@ -1,12 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE -spring.datasource.username=sa -spring.datasource.password= -spring.datasource.driverClassName=org.h2.Driver -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect - -spring.h2.console.path=/myconsole -spring.h2.console.enabled=true -spring.datasource.initialize=true -spring.datasource.schema=classpath:acl-schema.sql -spring.datasource.data=classpath:acl-data.sql \ No newline at end of file diff --git a/spring-acl/src/test/java/org/baeldung/acl/SpringAclTest.java b/spring-acl/src/test/java/org/baeldung/acl/SpringAclTest.java deleted file mode 100644 index fd9069d9bc..0000000000 --- a/spring-acl/src/test/java/org/baeldung/acl/SpringAclTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.baeldung.acl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.List; - -import org.baeldung.acl.persistence.dao.NoticeMessageRepository; -import org.baeldung.acl.persistence.entity.NoticeMessage; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.access.AccessDeniedException; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; -import org.springframework.test.context.support.DirtiesContextTestExecutionListener; -import org.springframework.test.context.transaction.TransactionalTestExecutionListener; -import org.springframework.test.context.web.ServletTestExecutionListener; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@TestExecutionListeners(listeners={ServletTestExecutionListener.class, - DependencyInjectionTestExecutionListener.class, - DirtiesContextTestExecutionListener.class, - TransactionalTestExecutionListener.class, - WithSecurityContextTestExecutionListener.class}) -public class SpringAclTest extends AbstractJUnit4SpringContextTests{ - - private static Integer FIRST_MESSAGE_ID = 1; - private static Integer SECOND_MESSAGE_ID = 2; - private static Integer THIRD_MESSAGE_ID = 3; - private static String EDITTED_CONTENT = "EDITED"; - - @Configuration - @ComponentScan("org.baeldung.acl.*") - public static class SpringConfig { - - } - - @Autowired - NoticeMessageRepository repo; - - @Test - @WithMockUser(username="manager") - public void givenUsernameManager_whenFindAllMessage_thenReturnFirstMessage(){ - List details = repo.findAll(); - assertNotNull(details); - assertEquals(1,details.size()); - assertEquals(FIRST_MESSAGE_ID,details.get(0).getId()); - } - - @Test - @WithMockUser(username="manager") - public void givenUsernameManager_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenOK(){ - NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID); - assertNotNull(firstMessage); - assertEquals(FIRST_MESSAGE_ID,firstMessage.getId()); - - firstMessage.setContent(EDITTED_CONTENT); - repo.save(firstMessage); - - NoticeMessage editedFirstMessage = repo.findById(FIRST_MESSAGE_ID); - assertNotNull(editedFirstMessage); - assertEquals(FIRST_MESSAGE_ID,editedFirstMessage.getId()); - assertEquals(EDITTED_CONTENT,editedFirstMessage.getContent()); - } - - @Test - @WithMockUser(username="hr") - public void givenUsernameHr_whenFindMessageById2_thenOK(){ - NoticeMessage secondMessage = repo.findById(SECOND_MESSAGE_ID); - assertNotNull(secondMessage); - assertEquals(SECOND_MESSAGE_ID,secondMessage.getId()); - } - - @Test(expected=AccessDeniedException.class) - @WithMockUser(username="hr") - public void givenUsernameHr_whenUpdateMessageWithId2_thenFail(){ - NoticeMessage secondMessage = new NoticeMessage(); - secondMessage.setId(SECOND_MESSAGE_ID); - secondMessage.setContent(EDITTED_CONTENT); - repo.save(secondMessage); - } - - @Test - @WithMockUser(roles={"EDITOR"}) - public void givenRoleEditor_whenFindAllMessage_thenReturnThreeMessage(){ - List details = repo.findAll(); - assertNotNull(details); - assertEquals(3,details.size()); - } - - @Test - @WithMockUser(roles={"EDITOR"}) - public void givenRoleEditor_whenUpdateThirdMessage_thenOK(){ - NoticeMessage thirdMessage = new NoticeMessage(); - thirdMessage.setId(THIRD_MESSAGE_ID); - thirdMessage.setContent(EDITTED_CONTENT); - repo.save(thirdMessage); - } - - @Test(expected=AccessDeniedException.class) - @WithMockUser(roles={"EDITOR"}) - public void givenRoleEditor_whenFindFirstMessageByIdAndUpdateFirstMessageContent_thenFail(){ - NoticeMessage firstMessage = repo.findById(FIRST_MESSAGE_ID); - assertNotNull(firstMessage); - assertEquals(FIRST_MESSAGE_ID,firstMessage.getId()); - firstMessage.setContent(EDITTED_CONTENT); - repo.save(firstMessage); - } -} - \ No newline at end of file diff --git a/spring-security-acl/src/test/java/org/baeldung/acl/SpringAclTest.java b/spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java similarity index 98% rename from spring-security-acl/src/test/java/org/baeldung/acl/SpringAclTest.java rename to spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java index b864639d74..1460d4f47b 100644 --- a/spring-security-acl/src/test/java/org/baeldung/acl/SpringAclTest.java +++ b/spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java @@ -31,7 +31,7 @@ import org.springframework.test.context.web.ServletTestExecutionListener; DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, WithSecurityContextTestExecutionListener.class}) -public class SpringAclTest extends AbstractJUnit4SpringContextTests{ +public class SpringACLIntegrationTest extends AbstractJUnit4SpringContextTests{ private static Integer FIRST_MESSAGE_ID = 1; private static Integer SECOND_MESSAGE_ID = 2; From cee5dcf7b26ee7a7125c0c36e129deca19470c92 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Wed, 13 Dec 2017 14:08:18 +0200 Subject: [PATCH 2/8] adding new module --- pom.xml | 1 + spring-5-reactive/.gitignore | 12 ++ spring-5-reactive/README.md | 15 ++ spring-5-reactive/pom.xml | 203 ++++++++++++++++++ .../java/com/baeldung/Spring5Application.java | 15 ++ .../baeldung/SpringSecurity5Application.java | 34 +++ .../java/com/baeldung/functional/Actor.java | 23 ++ ...Spring5URLPatternUsingRouterFunctions.java | 61 ++++++ .../com/baeldung/functional/FormHandler.java | 41 ++++ .../FunctionalSpringBootApplication.java | 87 ++++++++ .../functional/FunctionalWebApplication.java | 80 +++++++ .../functional/IndexRewriteFilter.java | 27 +++ .../com/baeldung/functional/MyService.java | 11 + .../com/baeldung/functional/RootServlet.java | 82 +++++++ .../main/java/com/baeldung/jsonb/Person.java | 127 +++++++++++ .../com/baeldung/jsonb/PersonController.java | 58 +++++ .../baeldung/jsonb/Spring5Application.java | 30 +++ .../jupiter/MethodParameterFactory.java | 46 ++++ .../jupiter/ParameterAutowireUtils.java | 44 ++++ .../com/baeldung/jupiter/SpringExtension.java | 94 ++++++++ .../baeldung/jupiter/SpringJUnit5Config.java | 39 ++++ .../java/com/baeldung/jupiter/TestConfig.java | 20 ++ .../baeldung/persistence/DataSetupBean.java | 27 +++ .../baeldung/persistence/FooRepository.java | 10 + .../baeldung/security/GreetController.java | 37 ++++ .../com/baeldung/security/GreetService.java | 15 ++ .../com/baeldung/security/SecurityConfig.java | 42 ++++ .../src/main/java/com/baeldung/web/Foo.java | 84 ++++++++ .../java/com/baeldung/web/FooController.java | 53 +++++ .../baeldung/web/PathPatternController.java | 39 ++++ .../java/com/baeldung/web/reactive/Task.java | 28 +++ .../reactive/client/WebClientController.java | 85 ++++++++ .../src/main/resources/application.properties | 3 + .../src/main/resources/files/hello.txt | 1 + .../src/main/resources/files/test/test.txt | 1 + .../src/main/webapp/WEB-INF/web.xml | 21 ++ .../com/baeldung/Example1IntegrationTest.java | 29 +++ .../com/baeldung/Example2IntegrationTest.java | 29 +++ .../com/baeldung/ParallelIntegrationTest.java | 24 +++ .../Spring5ApplicationIntegrationTest.java | 16 ++ ...pring5JUnit4ConcurrentIntegrationTest.java | 52 +++++ .../functional/BeanRegistrationTest.java | 42 ++++ ...ng5URLPatternUsingRouterFunctionsTest.java | 110 ++++++++++ ...nctionalWebApplicationIntegrationTest.java | 141 ++++++++++++ .../baeldung/jsonb/JsonbIntegrationTest.java | 43 ++++ .../com/baeldung/jupiter/EnabledOnJava8.java | 18 ++ .../jupiter/Spring5EnabledAnnotationTest.java | 50 +++++ ...nit5ComposedAnnotationIntegrationTest.java | 38 ++++ .../jupiter/Spring5JUnit5IntegrationTest.java | 25 +++ .../Spring5JUnit5ParallelIntegrationTest.java | 25 +++ ...pring5Java8NewFeaturesIntegrationTest.java | 31 +++ ...g5ReactiveServerClientIntegrationTest.java | 94 ++++++++ .../jupiter/SpringJUnitConfigTest.java | 33 +++ .../jupiter/SpringJUnitWebConfigTest.java | 34 +++ .../com/baeldung/security/SecurityTest.java | 48 +++++ ...ernsUsingHandlerMethodIntegrationTest.java | 101 +++++++++ .../web/client/WebTestClientTest.java | 60 ++++++ .../src/test/resources/baeldung-weekly.png | Bin 0 -> 22275 bytes .../baeldung/web/PathPatternController.java | 1 - 59 files changed, 2639 insertions(+), 1 deletion(-) create mode 100644 spring-5-reactive/.gitignore create mode 100644 spring-5-reactive/README.md create mode 100644 spring-5-reactive/pom.xml create mode 100644 spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/Foo.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/FooController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java create mode 100644 spring-5-reactive/src/main/resources/application.properties create mode 100644 spring-5-reactive/src/main/resources/files/hello.txt create mode 100644 spring-5-reactive/src/main/resources/files/test/test.txt create mode 100644 spring-5-reactive/src/main/webapp/WEB-INF/web.xml create mode 100644 spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java create mode 100644 spring-5-reactive/src/test/resources/baeldung-weekly.png diff --git a/pom.xml b/pom.xml index b3da4655d6..88f54be629 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,7 @@ persistence-modules/solr spark-java + spring-5-reactive spring-5-mvc spring-activiti spring-akka diff --git a/spring-5-reactive/.gitignore b/spring-5-reactive/.gitignore new file mode 100644 index 0000000000..dec013dfa4 --- /dev/null +++ b/spring-5-reactive/.gitignore @@ -0,0 +1,12 @@ +#folders# +.idea +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md new file mode 100644 index 0000000000..400e343263 --- /dev/null +++ b/spring-5-reactive/README.md @@ -0,0 +1,15 @@ +## Spring REST Example Project + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles + +- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests) +- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) +- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching) +- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient) +- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans) +- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config) +- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive) +- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml new file mode 100644 index 0000000000..43d9a5ed94 --- /dev/null +++ b/spring-5-reactive/pom.xml @@ -0,0 +1,203 @@ + + + 4.0.0 + + com.baeldung + spring-5-reactive + 0.0.1-SNAPSHOT + jar + + spring-5 + spring 5 sample project about new features + + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.M7 + + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.projectreactor + reactor-spring + ${reactor-spring.version} + + + javax.json.bind + javax.json.bind-api + ${jsonb-api.version} + + + + + + + + + + + + + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + ${geronimo-json_1.1_spec.version} + + + org.apache.johnzon + johnzon-jsonb + ${johnzon.version} + + + + org.apache.commons + commons-lang3 + + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + com.h2database + h2 + runtime + + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + org.apache.commons + commons-collections4 + 4.1 + test + + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + test + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.Spring5Application + JAR + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 3 + true + methods + true + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + UTF-8 + UTF-8 + 1.8 + 1.0.0 + 5.0.0 + 2.20 + 5.0.1.RELEASE + 1.0.1.RELEASE + 1.1.3 + 1.0 + 1.0 + + + diff --git a/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java b/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java new file mode 100644 index 0000000000..f321871646 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java @@ -0,0 +1,15 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = { "com.baeldung.web" }) +public class Spring5Application { + + public static void main(String[] args) { + SpringApplication.run(Spring5Application.class, args); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java b/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java new file mode 100644 index 0000000000..02c91a1879 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java @@ -0,0 +1,34 @@ +package com.baeldung; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; +import org.springframework.web.reactive.config.EnableWebFlux; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; + +@ComponentScan(basePackages = {"com.baeldung.security"}) +@EnableWebFlux +public class SpringSecurity5Application { + + public static void main(String[] args) { + try (AnnotationConfigApplicationContext context = + new AnnotationConfigApplicationContext(SpringSecurity5Application.class)) { + context.getBean(NettyContext.class).onClose().block(); + } + } + + @Bean + public NettyContext nettyContext(ApplicationContext context) { + HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) + .build(); + ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); + HttpServer httpServer = HttpServer.create("localhost", 8080); + return httpServer.newHandler(adapter).block(); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java b/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java new file mode 100644 index 0000000000..23c88b89e1 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java @@ -0,0 +1,23 @@ +package com.baeldung.functional; + +class Actor { + private String firstname; + private String lastname; + + public Actor() { + } + + public Actor(String firstname, String lastname) { + this.firstname = firstname; + this.lastname = lastname; + } + + public String getFirstname() { + return firstname; + } + + public String getLastname() { + return lastname; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java new file mode 100644 index 0000000000..2a6d04538c --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java @@ -0,0 +1,61 @@ +package com.baeldung.functional; + +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; +import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; +import static org.springframework.web.reactive.function.server.ServerResponse.ok; + +import org.apache.catalina.Context; +import org.apache.catalina.startup.Tomcat; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.server.WebServer; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; + +public class ExploreSpring5URLPatternUsingRouterFunctions { + + private RouterFunction routingFunction() { + + return route(GET("/p?ths"), serverRequest -> ok().body(fromObject("/p?ths"))).andRoute(GET("/test/{*id}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("id")))) + .andRoute(GET("/*card"), serverRequest -> ok().body(fromObject("/*card path was accessed"))) + .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) + .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromObject("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) + .and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/"))); + } + + WebServer start() throws Exception { + WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction()); + HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler) + .filter(new IndexRewriteFilter()) + .build(); + + Tomcat tomcat = new Tomcat(); + tomcat.setHostname("localhost"); + tomcat.setPort(9090); + Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir")); + ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler); + Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet); + rootContext.addServletMappingDecoded("/", "httpHandlerServlet"); + + TomcatWebServer server = new TomcatWebServer(tomcat); + server.start(); + return server; + + } + + public static void main(String[] args) { + try { + new FunctionalWebApplication().start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java new file mode 100644 index 0000000000..05069735bb --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java @@ -0,0 +1,41 @@ +package com.baeldung.functional; + +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.util.MultiValueMap; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; + +import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; +import static org.springframework.web.reactive.function.BodyExtractors.toFormData; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.server.ServerResponse.ok; + +public class FormHandler { + + Mono handleLogin(ServerRequest request) { + return request.body(toFormData()) + .map(MultiValueMap::toSingleValueMap) + .filter(formData -> "baeldung".equals(formData.get("user"))) + .filter(formData -> "you_know_what_to_do".equals(formData.get("token"))) + .flatMap(formData -> ok().body(Mono.just("welcome back!"), String.class)) + .switchIfEmpty(ServerResponse.badRequest() + .build()); + } + + Mono handleUpload(ServerRequest request) { + return request.body(toDataBuffers()) + .collectList() + .flatMap(dataBuffers -> ok().body(fromObject(extractData(dataBuffers).toString()))); + } + + private AtomicLong extractData(List dataBuffers) { + AtomicLong atomicLong = new AtomicLong(0); + dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() + .array().length)); + return atomicLong; + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java new file mode 100644 index 0000000000..402b607b19 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java @@ -0,0 +1,87 @@ +package com.baeldung.functional; + +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RequestPredicates.path; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; +import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; +import static org.springframework.web.reactive.function.server.ServerResponse.ok; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.server.reactive.HttpHandler; +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; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; + +import reactor.core.publisher.Flux; + +@SpringBootApplication +@ComponentScan(basePackages = { "com.baeldung.functional" }) +public class FunctionalSpringBootApplication { + + private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); + private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); + private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); + + private RouterFunction routingFunction() { + FormHandler formHandler = new FormHandler(); + + RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) + .doOnNext(actors::add) + .then(ok().build())); + + return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) + .andRoute(POST("/upload"), formHandler::handleUpload) + .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) + .andNest(path("/actor"), restfulRouter) + .filter((request, next) -> { + System.out.println("Before handler invocation: " + request.path()); + return next.handle(request); + }); + } + + @Bean + public ServletRegistrationBean servletRegistrationBean() throws Exception { + HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler((WebHandler) toHttpHandler(routingFunction())) + .filter(new IndexRewriteFilter()) + .build(); + ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(new RootServlet(httpHandler), "/"); + registrationBean.setLoadOnStartup(1); + registrationBean.setAsyncSupported(true); + return registrationBean; + } + + @Configuration + @EnableWebSecurity + @Profile("!https") + static class SecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.authorizeRequests() + .anyRequest() + .permitAll(); + } + } + + public static void main(String[] args) { + SpringApplication.run(FunctionalSpringBootApplication.class, args); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java new file mode 100644 index 0000000000..5a7d70d3db --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java @@ -0,0 +1,80 @@ +package com.baeldung.functional; + +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RequestPredicates.path; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; +import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; +import static org.springframework.web.reactive.function.server.ServerResponse.ok; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.catalina.Context; +import org.apache.catalina.startup.Tomcat; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.server.WebServer; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; + +import reactor.core.publisher.Flux; + +public class FunctionalWebApplication { + + private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); + private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); + private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); + + private RouterFunction routingFunction() { + FormHandler formHandler = new FormHandler(); + + RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) + .doOnNext(actors::add) + .then(ok().build())); + + return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) + .andRoute(POST("/upload"), formHandler::handleUpload) + .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) + .andNest(path("/actor"), restfulRouter) + .filter((request, next) -> { + System.out.println("Before handler invocation: " + request.path()); + return next.handle(request); + }); + } + + WebServer start() throws Exception { + WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction()); + HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler) + .filter(new IndexRewriteFilter()) + .build(); + + Tomcat tomcat = new Tomcat(); + tomcat.setHostname("localhost"); + tomcat.setPort(9090); + Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir")); + ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler); + Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet); + rootContext.addServletMappingDecoded("/", "httpHandlerServlet"); + + TomcatWebServer server = new TomcatWebServer(tomcat); + server.start(); + return server; + + } + + public static void main(String[] args) { + try { + new FunctionalWebApplication().start(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java b/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java new file mode 100644 index 0000000000..3e91a0354b --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java @@ -0,0 +1,27 @@ +package com.baeldung.functional; + +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; +import org.springframework.web.server.WebFilterChain; +import reactor.core.publisher.Mono; + +class IndexRewriteFilter implements WebFilter { + + @Override + public Mono filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) { + ServerHttpRequest request = serverWebExchange.getRequest(); + if (request.getURI() + .getPath() + .equals("/")) { + return webFilterChain.filter(serverWebExchange.mutate() + .request(builder -> builder.method(request.getMethod()) + .contextPath(request.getPath() + .toString()) + .path("/test")) + .build()); + } + return webFilterChain.filter(serverWebExchange); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java b/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java new file mode 100644 index 0000000000..b7b8b13d8b --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java @@ -0,0 +1,11 @@ +package com.baeldung.functional; + +import java.util.Random; + +public class MyService { + + public int getRandomNumber() { + return (new Random().nextInt(10)); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java b/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java new file mode 100644 index 0000000000..8fe24821de --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java @@ -0,0 +1,82 @@ +package com.baeldung.functional; + +import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; +import static org.springframework.web.reactive.function.BodyExtractors.toFormData; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RequestPredicates.path; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; +import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; +import static org.springframework.web.reactive.function.server.ServerResponse.ok; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicLong; + +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; +import org.springframework.util.MultiValueMap; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class RootServlet extends ServletHttpHandlerAdapter { + + public RootServlet() { + this(WebHttpHandlerBuilder.webHandler((WebHandler) toHttpHandler(routingFunction())) + .filter(new IndexRewriteFilter()) + .build()); + } + + RootServlet(HttpHandler httpHandler) { + super(httpHandler); + } + + private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); + private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); + private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); + + private static RouterFunction routingFunction() { + + return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), serverRequest -> serverRequest.body(toFormData()) + .map(MultiValueMap::toSingleValueMap) + .map(formData -> { + System.out.println("form data: " + formData.toString()); + if ("baeldung".equals(formData.get("user")) && "you_know_what_to_do".equals(formData.get("token"))) { + return ok().body(Mono.just("welcome back!"), String.class) + .block(); + } + return ServerResponse.badRequest() + .build() + .block(); + })) + .andRoute(POST("/upload"), serverRequest -> serverRequest.body(toDataBuffers()) + .collectList() + .map(dataBuffers -> { + AtomicLong atomicLong = new AtomicLong(0); + dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() + .array().length)); + System.out.println("data length:" + atomicLong.get()); + return ok().body(fromObject(atomicLong.toString())) + .block(); + })) + .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) + .andNest(path("/actor"), route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) + .doOnNext(actors::add) + .then(ok().build()))) + .filter((request, next) -> { + System.out.println("Before handler invocation: " + request.path()); + return next.handle(request); + }); + + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java new file mode 100644 index 0000000000..7a54b37574 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java @@ -0,0 +1,127 @@ +package com.baeldung.jsonb; + +import java.math.BigDecimal; +import java.time.LocalDate; + +import javax.json.bind.annotation.JsonbDateFormat; +import javax.json.bind.annotation.JsonbNumberFormat; +import javax.json.bind.annotation.JsonbProperty; +import javax.json.bind.annotation.JsonbTransient; + +public class Person { + + private int id; + @JsonbProperty("person-name") + private String name; + @JsonbProperty(nillable = true) + private String email; + @JsonbTransient + private int age; + @JsonbDateFormat("dd-MM-yyyy") + private LocalDate registeredDate; + private BigDecimal salary; + + public Person() { + } + + public Person(int id, String name, String email, int age, LocalDate registeredDate, BigDecimal salary) { + super(); + this.id = id; + this.name = name; + this.email = email; + this.age = age; + this.registeredDate = registeredDate; + this.salary = salary; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @JsonbNumberFormat(locale = "en_US", value = "#0.0") + public BigDecimal getSalary() { + return salary; + } + + public void setSalary(BigDecimal salary) { + this.salary = salary; + } + + public LocalDate getRegisteredDate() { + return registeredDate; + } + + public void setRegisteredDate(LocalDate registeredDate) { + this.registeredDate = registeredDate; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Person [id="); + builder.append(id); + builder.append(", name="); + builder.append(name); + builder.append(", email="); + builder.append(email); + builder.append(", age="); + builder.append(age); + builder.append(", registeredDate="); + builder.append(registeredDate); + builder.append(", salary="); + builder.append(salary); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Person other = (Person) obj; + if (id != other.id) + return false; + return true; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java new file mode 100644 index 0000000000..e216a282eb --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java @@ -0,0 +1,58 @@ +package com.baeldung.jsonb; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController("/person") +public class PersonController { + + List personRepository; + + @PostConstruct + public void init() { + // @formatter:off + personRepository = new ArrayList<>(Arrays.asList( + new Person(1, "Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)), + new Person(2, "Jhon", "jhon1@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500)), + new Person(3, "Jhon", null, 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)), + new Person(4, "Tom", "tom@test.com", 21, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500)), + new Person(5, "Mark", "mark@test.com", 21, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1200)), + new Person(6, "Julia", "jhon@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)))); + // @formatter:on + + } + + @GetMapping("/person/{id}") + @ResponseBody + public Person findById(@PathVariable final int id) { + return personRepository.get(id); + } + + @PostMapping("/person") + @ResponseStatus(HttpStatus.OK) + @ResponseBody + public boolean insertPerson(@RequestBody final Person person) { + return personRepository.add(person); + } + + @GetMapping("/person") + @ResponseBody + public List findAll() { + return personRepository; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java new file mode 100644 index 0000000000..00fce06834 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java @@ -0,0 +1,30 @@ +package com.baeldung.jsonb; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.JsonbHttpMessageConverter; + +@SpringBootApplication +@ComponentScan(basePackages = { "com.baeldung.jsonb" }) +public class Spring5Application { + + public static void main(String[] args) { + SpringApplication.run(Spring5Application.class, args); + } + + @Bean + public HttpMessageConverters customConverters() { + Collection> messageConverters = new ArrayList<>(); + JsonbHttpMessageConverter jsonbHttpMessageConverter = new JsonbHttpMessageConverter(); + messageConverters.add(jsonbHttpMessageConverter); + return new HttpMessageConverters(true, messageConverters); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java new file mode 100644 index 0000000000..85bd505d11 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java @@ -0,0 +1,46 @@ +package com.baeldung.jupiter; + +import org.springframework.core.MethodParameter; +import org.springframework.core.annotation.SynthesizingMethodParameter; +import org.springframework.util.Assert; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Executable; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +abstract class MethodParameterFactory { + + private MethodParameterFactory() { + } + + public static MethodParameter createMethodParameter(Parameter parameter) { + Assert.notNull(parameter, "Parameter must not be null"); + Executable executable = parameter.getDeclaringExecutable(); + if (executable instanceof Method) { + return new MethodParameter((Method) executable, getIndex(parameter)); + } + return new MethodParameter((Constructor) executable, getIndex(parameter)); + } + + public static SynthesizingMethodParameter createSynthesizingMethodParameter(Parameter parameter) { + Assert.notNull(parameter, "Parameter must not be null"); + Executable executable = parameter.getDeclaringExecutable(); + if (executable instanceof Method) { + return new SynthesizingMethodParameter((Method) executable, getIndex(parameter)); + } + throw new UnsupportedOperationException("Cannot create a SynthesizingMethodParameter for a constructor parameter: " + parameter); + } + + private static int getIndex(Parameter parameter) { + Assert.notNull(parameter, "Parameter must not be null"); + Executable executable = parameter.getDeclaringExecutable(); + Parameter[] parameters = executable.getParameters(); + for (int i = 0; i < parameters.length; i++) { + if (parameters[i] == parameter) { + return i; + } + } + throw new IllegalStateException(String.format("Failed to resolve index of parameter [%s] in executable [%s]", parameter, executable.toGenericString())); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java new file mode 100644 index 0000000000..d1a4cc8b29 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java @@ -0,0 +1,44 @@ +package com.baeldung.jupiter; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.DependencyDescriptor; +import org.springframework.context.ApplicationContext; +import org.springframework.core.MethodParameter; +import org.springframework.core.annotation.AnnotatedElementUtils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Optional; + +import static org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation; + +abstract class ParameterAutowireUtils { + + private ParameterAutowireUtils() { + } + + public static boolean isAutowirable(Parameter parameter) { + return ApplicationContext.class.isAssignableFrom(parameter.getType()) || hasAnnotation(parameter, Autowired.class) || hasAnnotation(parameter, Qualifier.class) || hasAnnotation(parameter, Value.class); + } + + public static Object resolveDependency(Parameter parameter, Class containingClass, ApplicationContext applicationContext) { + + boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required) + .orElse(true); + MethodParameter methodParameter = (parameter.getDeclaringExecutable() instanceof Method ? MethodParameterFactory.createSynthesizingMethodParameter(parameter) : MethodParameterFactory.createMethodParameter(parameter)); + DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required); + descriptor.setContainingClass(containingClass); + + return applicationContext.getAutowireCapableBeanFactory() + .resolveDependency(descriptor, null); + } + + private static Optional findMergedAnnotation(AnnotatedElement element, Class annotationType) { + + return Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(element, annotationType)); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java new file mode 100644 index 0000000000..7218d984ef --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java @@ -0,0 +1,94 @@ +package com.baeldung.jupiter; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Executable; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.api.extension.ParameterResolver; +import org.junit.jupiter.api.extension.TestInstancePostProcessor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextManager; +import org.springframework.util.Assert; + +public class SpringExtension implements BeforeAllCallback, AfterAllCallback, TestInstancePostProcessor, BeforeEachCallback, AfterEachCallback, ParameterResolver { + + private static final ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(SpringExtension.class); + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + getTestContextManager(context).beforeTestClass(); + } + + @Override + public void afterAll(ExtensionContext context) throws Exception { + try { + getTestContextManager(context).afterTestClass(); + } finally { + context.getStore(namespace) + .remove(context.getTestClass() + .get()); + } + } + + @Override + public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception { + getTestContextManager(context).prepareTestInstance(testInstance); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + Object testInstance = context.getTestInstance(); + Method testMethod = context.getTestMethod() + .get(); + getTestContextManager(context).beforeTestMethod(testInstance, testMethod); + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + Object testInstance = context.getTestInstance(); + Method testMethod = context.getTestMethod() + .get(); + Throwable testException = context.getExecutionException() + .orElse(null); + getTestContextManager(context).afterTestMethod(testInstance, testMethod, testException); + } + + @Override + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + Parameter parameter = parameterContext.getParameter(); + Executable executable = parameter.getDeclaringExecutable(); + return ((executable instanceof Constructor) && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter); + } + + @Override + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + Parameter parameter = parameterContext.getParameter(); + Class testClass = extensionContext.getTestClass() + .get(); + ApplicationContext applicationContext = getApplicationContext(extensionContext); + return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext); + } + + private ApplicationContext getApplicationContext(ExtensionContext context) { + return getTestContextManager(context).getTestContext() + .getApplicationContext(); + } + + private TestContextManager getTestContextManager(ExtensionContext context) { + Assert.notNull(context, "ExtensionContext must not be null"); + Class testClass = context.getTestClass() + .get(); + ExtensionContext.Store store = context.getStore(namespace); + return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java new file mode 100644 index 0000000000..8f02d71d49 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java @@ -0,0 +1,39 @@ +package com.baeldung.jupiter; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.annotation.AliasFor; +import org.springframework.test.context.ContextConfiguration; + +import java.lang.annotation.*; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SpringJUnit5Config { + + @AliasFor(annotation = ContextConfiguration.class, attribute = "classes") + Class[] value() default {}; + + @AliasFor(annotation = ContextConfiguration.class) + Class[] classes() default {}; + + @AliasFor(annotation = ContextConfiguration.class) + String[] locations() default {}; + + @AliasFor(annotation = ContextConfiguration.class) + Class>[] initializers() default {}; + + @AliasFor(annotation = ContextConfiguration.class) + boolean inheritLocations() default true; + + @AliasFor(annotation = ContextConfiguration.class) + boolean inheritInitializers() default true; + + @AliasFor(annotation = ContextConfiguration.class) + String name() default ""; +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java new file mode 100644 index 0000000000..a29f77c5df --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java @@ -0,0 +1,20 @@ +package com.baeldung.jupiter; + +import com.baeldung.web.reactive.Task; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; + +@Configuration +public class TestConfig { + + @Bean + static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + + @Bean + Task taskName() { + return new Task("taskName", 1); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java b/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java new file mode 100644 index 0000000000..9f5d9ff6c2 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java @@ -0,0 +1,27 @@ +package com.baeldung.persistence; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; + +import java.util.stream.IntStream; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.baeldung.web.Foo; + +@Component +public class DataSetupBean implements InitializingBean { + + @Autowired + private FooRepository repo; + + // + + @Override + public void afterPropertiesSet() throws Exception { + IntStream.range(1, 20) + .forEach(i -> repo.save(new Foo(randomAlphabetic(8)))); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java b/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java new file mode 100644 index 0000000000..1f1e071158 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.persistence; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +import com.baeldung.web.Foo; + +public interface FooRepository extends JpaRepository, JpaSpecificationExecutor { + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java b/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java new file mode 100644 index 0000000000..6b69e3bc9b --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java @@ -0,0 +1,37 @@ +package com.baeldung.security; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +import java.security.Principal; + +@RestController +public class GreetController { + + private GreetService greetService; + + public GreetController(GreetService greetService) { + this.greetService = greetService; + } + + @GetMapping("/") + public Mono greet(Mono principal) { + return principal + .map(Principal::getName) + .map(name -> String.format("Hello, %s", name)); + } + + @GetMapping("/admin") + public Mono greetAdmin(Mono principal) { + return principal + .map(Principal::getName) + .map(name -> String.format("Admin access: %s", name)); + } + + @GetMapping("/greetService") + public Mono greetService() { + return greetService.greet(); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java b/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java new file mode 100644 index 0000000000..7622b360be --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java @@ -0,0 +1,15 @@ +package com.baeldung.security; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class GreetService { + + @PreAuthorize("hasRole('ADMIN')") + public Mono greet() { + return Mono.just("Hello from service!"); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java b/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java new file mode 100644 index 0000000000..a9e44a2eee --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java @@ -0,0 +1,42 @@ +package com.baeldung.security; + +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.web.server.SecurityWebFilterChain; + +@EnableWebFluxSecurity +@EnableReactiveMethodSecurity +public class SecurityConfig { + + @Bean + public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) { + return http.authorizeExchange() + .pathMatchers("/admin").hasAuthority("ROLE_ADMIN") + .anyExchange().authenticated() + .and().formLogin() + .and().build(); + } + + @Bean + public MapReactiveUserDetailsService userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + + UserDetails admin = User.withDefaultPasswordEncoder() + .username("admin") + .password("password") + .roles("ADMIN") + .build(); + + return new MapReactiveUserDetailsService(user, admin); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java new file mode 100644 index 0000000000..c4868a9958 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java @@ -0,0 +1,84 @@ +package com.baeldung.web; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Foo { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String name; + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + + this.name = name; + } + + public Foo(final long id, final String name) { + super(); + + this.id = id; + this.name = name; + } + + // API + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + // + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Foo other = (Foo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "Foo [name=" + name + "]"; + } + +} \ No newline at end of file diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java b/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java new file mode 100644 index 0000000000..925f2b49f4 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java @@ -0,0 +1,53 @@ +package com.baeldung.web; + +import com.baeldung.persistence.FooRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.HttpStatus; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import java.util.List; + +@RestController("/foos") +public class FooController { + + @Autowired + private FooRepository repo; + + // API - read + + @GetMapping("/foos/{id}") + @ResponseBody + @Validated + public Foo findById(@PathVariable @Min(0) final long id) { + return repo.findById(id) + .orElse(null); + } + + @GetMapping + @ResponseBody + public List findAll() { + return repo.findAll(); + } + + @GetMapping(params = { "page", "size" }) + @ResponseBody + @Validated + public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { + return repo.findAll(PageRequest.of(page, size)) + .getContent(); + } + + // API - write + + @PutMapping("/foos/{id}") + @ResponseStatus(HttpStatus.OK) + @ResponseBody + public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { + return foo; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java b/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java new file mode 100644 index 0000000000..fa413e4f00 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java @@ -0,0 +1,39 @@ +package com.baeldung.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PathPatternController { + + @GetMapping("/spring5/{*id}") + public String URIVariableHandler(@PathVariable String id) { + return id; + } + + @GetMapping("/s?ring5") + public String wildcardTakingExactlyOneChar() { + return "/s?ring5"; + } + + @GetMapping("/spring5/*id") + public String wildcardTakingZeroOrMoreChar() { + return "/spring5/*id"; + } + + @GetMapping("/resources/**") + public String wildcardTakingZeroOrMorePathSegments() { + return "/resources/**"; + } + + @GetMapping("/{baeldung:[a-z]+}") + public String regexInPathVariable(@PathVariable String baeldung) { + return baeldung; + } + + @GetMapping("/{var1}_{var2}") + public String multiplePathVariablesInSameSegment(@PathVariable String var1, @PathVariable String var2) { + return "Two variables are var1=" + var1 + " and var2=" + var2; + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java new file mode 100644 index 0000000000..725fd931e1 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java @@ -0,0 +1,28 @@ +package com.baeldung.web.reactive; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Task { + + private final String name; + + private final int id; + + public Task(@JsonProperty("name") String name, @JsonProperty("id") int id) { + this.name = name; + this.id = id; + } + + public String getName() { + return this.name; + } + + public int getId() { + return this.id; + } + + @Override + public String toString() { + return "Task{" + "name='" + name + '\'' + ", id=" + id + '}'; + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java new file mode 100644 index 0000000000..a218c6b7cf --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -0,0 +1,85 @@ +package com.baeldung.web.reactive.client; + +import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; +import org.springframework.http.*; +import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.reactive.function.BodyInserter; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.net.URI; +import java.nio.charset.Charset; +import java.time.ZonedDateTime; +import java.util.Collections; + +@RestController +public class WebClientController { + + @ResponseStatus(HttpStatus.OK) + @GetMapping("/resource") + public void getResource() { + } + + public void demonstrateWebClient() { + // request + WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); + WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); + + // request body specifications + WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) + .uri("/resource"); + WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() + .uri(URI.create("/resource")); + + // request header specification + WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); + WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromObject("data")); + + // inserters + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters + .fromPublisher(Subscriber::onComplete, String.class); + + LinkedMultiValueMap map = new LinkedMultiValueMap<>(); + map.add("key1", "value1"); + map.add("key2", "value2"); + + BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); + BodyInserter inserter3 = BodyInserters.fromObject("body"); + + // responses + WebClient.ResponseSpec response1 = uri1.body(inserter3) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + .acceptCharset(Charset.forName("UTF-8")) + .ifNoneMatch("*") + .ifModifiedSince(ZonedDateTime.now()) + .retrieve(); + WebClient.ResponseSpec response2 = requestSpec2.retrieve(); + + } + + private WebClient createWebClient() { + return WebClient.create(); + } + + private WebClient createWebClientWithServerURL() { + return WebClient.create("http://localhost:8081"); + } + + private WebClient createWebClientWithServerURLAndDefaultValues() { + return WebClient.builder() + .baseUrl("http://localhost:8081") + .defaultCookie("cookieKey", "cookieValue") + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) + .build(); + } + +} diff --git a/spring-5-reactive/src/main/resources/application.properties b/spring-5-reactive/src/main/resources/application.properties new file mode 100644 index 0000000000..ccec014c2b --- /dev/null +++ b/spring-5-reactive/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=8081 + +logging.level.root=INFO \ No newline at end of file diff --git a/spring-5-reactive/src/main/resources/files/hello.txt b/spring-5-reactive/src/main/resources/files/hello.txt new file mode 100644 index 0000000000..b6fc4c620b --- /dev/null +++ b/spring-5-reactive/src/main/resources/files/hello.txt @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/spring-5-reactive/src/main/resources/files/test/test.txt b/spring-5-reactive/src/main/resources/files/test/test.txt new file mode 100644 index 0000000000..30d74d2584 --- /dev/null +++ b/spring-5-reactive/src/main/resources/files/test/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/spring-5-reactive/src/main/webapp/WEB-INF/web.xml b/spring-5-reactive/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..bfcf43dad2 --- /dev/null +++ b/spring-5-reactive/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + Spring Functional Application + + + functional + com.baeldung.functional.RootServlet + 1 + true + + + functional + / + + + + \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java new file mode 100644 index 0000000000..8b9e66213f --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Example1IntegrationTest { + + @Test + public void test1a() { + block(3000); + } + + @Test + public void test1b() { + block(3000); + } + + public static void block(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + System.out.println("Thread interrupted"); + } + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java new file mode 100644 index 0000000000..6ed53ca4e9 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Example2IntegrationTest { + + @Test + public void test1a() { + block(3000); + } + + @Test + public void test1b() { + block(3000); + } + + public static void block(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java new file mode 100644 index 0000000000..1ce96de4ef --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java @@ -0,0 +1,24 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.experimental.ParallelComputer; +import org.junit.runner.Computer; +import org.junit.runner.JUnitCore; + +public class ParallelIntegrationTest { + + @Test + public void runTests() { + final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; + + JUnitCore.runClasses(new Computer(), classes); + } + + @Test + public void runTestsInParallel() { + final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; + + JUnitCore.runClasses(new ParallelComputer(true, true), classes); + } + +} \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java new file mode 100644 index 0000000000..af288c3c2d --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Spring5ApplicationIntegrationTest { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java new file mode 100644 index 0000000000..7e494465b2 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = Spring5JUnit4ConcurrentIntegrationTest.SimpleConfiguration.class) +public class Spring5JUnit4ConcurrentIntegrationTest implements ApplicationContextAware, InitializingBean { + + @Configuration + public static class SimpleConfiguration { + } + + private ApplicationContext applicationContext; + + private boolean beanInitialized = false; + + @Override + public final void afterPropertiesSet() throws Exception { + this.beanInitialized = true; + } + + @Override + public final void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @Test + public final void verifyApplicationContextSet() throws InterruptedException { + TimeUnit.SECONDS.sleep(2); + assertNotNull("The application context should have been set due to ApplicationContextAware semantics.", this.applicationContext); + } + + @Test + public final void verifyBeanInitialized() throws InterruptedException { + TimeUnit.SECONDS.sleep(2); + assertTrue("This test bean should have been initialized due to InitializingBean semantics.", this.beanInitialized); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java new file mode 100644 index 0000000000..0b1542dbbc --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java @@ -0,0 +1,42 @@ +package com.baeldung.functional; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.context.support.GenericWebApplicationContext; + +import com.baeldung.Spring5Application; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Spring5Application.class) +public class BeanRegistrationTest { + + @Autowired + private GenericWebApplicationContext context; + + @Test + public void whenRegisterBean_thenOk() { + context.registerBean(MyService.class, () -> new MyService()); + MyService myService = (MyService) context.getBean("com.baeldung.functional.MyService"); + assertTrue(myService.getRandomNumber() < 10); + } + + @Test + public void whenRegisterBeanWithName_thenOk() { + context.registerBean("mySecondService", MyService.class, () -> new MyService()); + MyService mySecondService = (MyService) context.getBean("mySecondService"); + assertTrue(mySecondService.getRandomNumber() < 10); + } + + @Test + public void whenRegisterBeanWithCallback_thenOk() { + context.registerBean("myCallbackService", MyService.class, () -> new MyService(), bd -> bd.setAutowireCandidate(false)); + MyService myCallbackService = (MyService) context.getBean("myCallbackService"); + assertTrue(myCallbackService.getRandomNumber() < 10); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java new file mode 100644 index 0000000000..7a38fa697f --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java @@ -0,0 +1,110 @@ +package com.baeldung.functional; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.boot.web.server.WebServer; +import org.springframework.test.web.reactive.server.WebTestClient; + +public class ExploreSpring5URLPatternUsingRouterFunctionsTest { + + private static WebTestClient client; + private static WebServer server; + + @BeforeClass + public static void setup() throws Exception { + server = new ExploreSpring5URLPatternUsingRouterFunctions().start(); + client = WebTestClient.bindToServer() + .baseUrl("http://localhost:" + server.getPort()) + .build(); + } + + @AfterClass + public static void destroy() { + server.stop(); + } + + @Test + public void givenRouter_whenGetPathWithSingleCharWildcard_thenGotPathPattern() throws Exception { + client.get() + .uri("/paths") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("/p?ths"); + } + + @Test + public void givenRouter_whenMultipleURIVariablePattern_thenGotPathVariable() throws Exception { + client.get() + .uri("/test/ab/cd") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("/ab/cd"); + } + + @Test + public void givenRouter_whenGetMultipleCharWildcard_thenGotPathPattern() throws Exception { + + client.get() + .uri("/wildcard") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("/*card path was accessed"); + } + + @Test + public void givenRouter_whenGetMultiplePathVaribleInSameSegment_thenGotPathVariables() throws Exception { + + client.get() + .uri("/baeldung_tutorial") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("baeldung , tutorial"); + } + + @Test + public void givenRouter_whenGetRegexInPathVarible_thenGotPathVariable() throws Exception { + + client.get() + .uri("/abcd") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("/{baeldung:[a-z]+} was accessed and baeldung=abcd"); + + client.get() + .uri("/1234") + .exchange() + .expectStatus() + .is4xxClientError(); + } + + @Test + public void givenResources_whenAccess_thenGot() throws Exception { + client.get() + .uri("/files/test/test.txt") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("test"); + + client.get() + .uri("/files/hello.txt") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("hello"); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java new file mode 100644 index 0000000000..a7b951b930 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java @@ -0,0 +1,141 @@ +package com.baeldung.functional; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.boot.web.server.WebServer; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.reactive.function.BodyInserters; + +import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromResource; + +public class FunctionalWebApplicationIntegrationTest { + + private static WebTestClient client; + private static WebServer server; + + @BeforeClass + public static void setup() throws Exception { + server = new FunctionalWebApplication().start(); + client = WebTestClient.bindToServer() + .baseUrl("http://localhost:" + server.getPort()) + .build(); + } + + @AfterClass + public static void destroy() { + server.stop(); + } + + @Test + public void givenRouter_whenGetTest_thenGotHelloWorld() throws Exception { + client.get() + .uri("/test") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("helloworld"); + } + + @Test + public void givenIndexFilter_whenRequestRoot_thenRewrittenToTest() throws Exception { + client.get() + .uri("/") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("helloworld"); + } + + @Test + public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception { + MultiValueMap formData = new LinkedMultiValueMap<>(1); + formData.add("user", "baeldung"); + formData.add("token", "you_know_what_to_do"); + + client.post() + .uri("/login") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .body(BodyInserters.fromFormData(formData)) + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("welcome back!"); + } + + @Test + public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Exception { + MultiValueMap formData = new LinkedMultiValueMap<>(2); + formData.add("user", "baeldung"); + formData.add("token", "try_again"); + + client.post() + .uri("/login") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .body(BodyInserters.fromFormData(formData)) + .exchange() + .expectStatus() + .isBadRequest(); + } + + @Test + public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception { + Resource resource = new ClassPathResource("/baeldung-weekly.png"); + client.post() + .uri("/upload") + .contentType(MediaType.MULTIPART_FORM_DATA) + .body(fromResource(resource)) + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo(String.valueOf(resource.contentLength())); + } + + @Test + public void givenActors_whenAddActor_thenAdded() throws Exception { + client.get() + .uri("/actor") + .exchange() + .expectStatus() + .isOk() + .expectBodyList(Actor.class) + .hasSize(2); + + client.post() + .uri("/actor") + .body(fromObject(new Actor("Clint", "Eastwood"))) + .exchange() + .expectStatus() + .isOk(); + + client.get() + .uri("/actor") + .exchange() + .expectStatus() + .isOk() + .expectBodyList(Actor.class) + .hasSize(3); + } + + @Test + public void givenResources_whenAccess_thenGot() throws Exception { + client.get() + .uri("/files/hello.txt") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("hello"); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java new file mode 100644 index 0000000000..756b303f3b --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java @@ -0,0 +1,43 @@ +package com.baeldung.jsonb; + +import static org.junit.Assert.assertTrue; + +import java.math.BigDecimal; +import java.time.LocalDate; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class JsonbIntegrationTest { + @Value("${security.user.name}") + private String username; + @Value("${security.user.password}") + private String password; + + @Autowired + private TestRestTemplate template; + + @Test + public void givenId_whenUriIsPerson_thenGetPerson() { + ResponseEntity response = template.withBasicAuth(username, password) + .getForEntity("/person/1", Person.class); + Person person = response.getBody(); + assertTrue(person.equals(new Person(2, "Jhon", "jhon1@test.com", 0, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500.0)))); + } + + @Test + public void whenSendPostAPerson_thenGetOkStatus() { + ResponseEntity response = template.withBasicAuth(username, password) + .postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class); + assertTrue(response.getBody()); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java new file mode 100644 index 0000000000..c6d3b7ff10 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java @@ -0,0 +1,18 @@ +package com.baeldung.jupiter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.junit.jupiter.EnabledIf; + +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@EnabledIf( + expression = "#{systemProperties['java.version'].startsWith('1.8')}", + reason = "Enabled on Java 8" +) +public @interface EnabledOnJava8 { + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java new file mode 100644 index 0000000000..ae058bc8ba --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.jupiter; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.DisabledIf; +import org.springframework.test.context.junit.jupiter.EnabledIf; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +@SpringJUnitConfig(Spring5EnabledAnnotationTest.Config.class) +@TestPropertySource(properties = { "tests.enabled=true" }) +public class Spring5EnabledAnnotationTest { + + @Configuration + static class Config { + } + + @EnabledIf("true") + @Test + void givenEnabledIfLiteral_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledIf(expression = "${tests.enabled}", loadContext = true) + @Test + void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}") + @Test + void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledOnJava8 + @Test + void givenEnabledOnJava8_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @DisabledIf("#{systemProperties['java.version'].startsWith('1.7')}") + @Test + void givenDisabledIf_WhenTrue_ThenTestNotExecuted() { + assertTrue(true); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java new file mode 100644 index 0000000000..42d27b90f4 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java @@ -0,0 +1,38 @@ +package com.baeldung.jupiter; + +import com.baeldung.web.reactive.Task; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringJUnit5Config(TestConfig.class) +@DisplayName("@SpringJUnit5Config Tests") +class Spring5JUnit5ComposedAnnotationIntegrationTest { + + @Autowired + private Task task; + + @Autowired + private List tasks; + + @Test + @DisplayName("ApplicationContext injected into method") + void givenAMethodName_whenInjecting_thenApplicationContextInjectedIntoMethod(ApplicationContext applicationContext) { + assertNotNull(applicationContext, "ApplicationContext should have been injected into method by Spring"); + assertEquals(this.task, applicationContext.getBean("taskName", Task.class)); + } + + @Test + @DisplayName("Spring @Beans injected into fields") + void givenAnObject_whenInjecting_thenSpringBeansInjected() { + assertNotNull(task, "Task should have been @Autowired by Spring"); + assertEquals("taskName", task.getName(), "Task's name"); + assertEquals(1, tasks.size(), "Number of Tasks in context"); + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java new file mode 100644 index 0000000000..0f00a85832 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.jupiter; + +import com.baeldung.web.reactive.Task; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = TestConfig.class) +class Spring5JUnit5IntegrationTest { + + @Autowired + private Task task; + + @Test + void givenAMethodName_whenInjecting_thenApplicationContextInjectedIntoMetho(ApplicationContext applicationContext) { + assertNotNull(applicationContext, "ApplicationContext should have been injected by Spring"); + assertEquals(this.task, applicationContext.getBean("taskName", Task.class)); + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java new file mode 100644 index 0000000000..55b0fcf267 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.jupiter; + +import com.baeldung.Example1IntegrationTest; +import com.baeldung.Example2IntegrationTest; +import org.junit.experimental.ParallelComputer; +import org.junit.jupiter.api.Test; +import org.junit.runner.Computer; +import org.junit.runner.JUnitCore; + +class Spring5JUnit5ParallelIntegrationTest { + + @Test + void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingParallel() { + final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; + + JUnitCore.runClasses(new ParallelComputer(true, true), classes); + } + + @Test + void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear() { + final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; + + JUnitCore.runClasses(new Computer(), classes); + } +} \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java new file mode 100644 index 0000000000..f58bf9f3cd --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java @@ -0,0 +1,31 @@ +package com.baeldung.jupiter; + +import org.junit.jupiter.api.Test; + +import java.util.function.Supplier; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class Spring5Java8NewFeaturesIntegrationTest { + + @FunctionalInterface + public interface FunctionalInterfaceExample { + Result reverseString(Input input); + } + + public class StringUtils { + FunctionalInterfaceExample functionLambdaString = s -> Pattern.compile(" +") + .splitAsStream(s) + .map(word -> new StringBuilder(word).reverse()) + .collect(Collectors.joining(" ")); + } + + @Test + void givenStringUtil_whenSupplierCall_thenFunctionalInterfaceReverseString() throws Exception { + Supplier stringUtilsSupplier = StringUtils::new; + + assertEquals(stringUtilsSupplier.get().functionLambdaString.reverseString("hello"), "olleh"); + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java new file mode 100644 index 0000000000..bbd852d625 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java @@ -0,0 +1,94 @@ +package com.baeldung.jupiter; + +import com.baeldung.web.reactive.Task; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; + +import java.time.Duration; + +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; + +public class Spring5ReactiveServerClientIntegrationTest { + + private static NettyContext nettyContext; + + @BeforeAll + public static void setUp() throws Exception { + HttpServer server = HttpServer.create("localhost", 8080); + RouterFunction route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok() + .body(request.bodyToFlux(Task.class) + .map(ll -> new Task("TaskName", 1)), Task.class)) + .and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok() + .body(Mono.just("server is alive"), String.class))); + HttpHandler httpHandler = RouterFunctions.toHttpHandler(route); + ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); + nettyContext = server.newHandler(adapter) + .block(); + } + + @AfterAll + public static void shutDown() { + nettyContext.dispose(); + } + + // @Test + // public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception { + // WebClient client = WebClient.create("http://localhost:8080"); + // Mono result = client + // .get() + // .uri("/task") + // .exchange() + // .then(response -> response.bodyToMono(String.class)); + // + // assertThat(result.block()).isInstanceOf(String.class); + // } + + // @Test + // public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception { + // URI uri = URI.create("http://localhost:8080/task/process"); + // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); + // ClientRequest request = ClientRequest + // .method(HttpMethod.POST, uri) + // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) + // .build(); + // + // Flux taskResponse = exchange + // .exchange(request) + // .flatMap(response -> response.bodyToFlux(Task.class)); + // + // assertThat(taskResponse.blockFirst()).isInstanceOf(Task.class); + // } + + // @Test + // public void givenCheckTask_whenServerHandle_thenOragicServerResponseALiveString() throws Exception { + // URI uri = URI.create("http://localhost:8080/task"); + // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); + // ClientRequest request = ClientRequest + // .method(HttpMethod.GET, uri) + // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) + // .build(); + // + // Flux taskResponse = exchange + // .exchange(request) + // .flatMap(response -> response.bodyToFlux(String.class)); + // + // assertThat(taskResponse.blockFirst()).isInstanceOf(String.class); + // } + + private static Flux getLatLngs() { + return Flux.range(0, 3) + .zipWith(Flux.interval(Duration.ofSeconds(1))) + .map(x -> new Task("taskname", 1)) + .doOnNext(ll -> System.out.println("Produced: {}" + ll)); + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java new file mode 100644 index 0000000000..6b0a6f9808 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java @@ -0,0 +1,33 @@ +package com.baeldung.jupiter; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +/** + * @SpringJUnitConfig(SpringJUnitConfigTest.Config.class) is equivalent to: + * + * @ExtendWith(SpringExtension.class) + * @ContextConfiguration(classes = SpringJUnitConfigTest.Config.class ) + * + */ +@SpringJUnitConfig(SpringJUnitConfigTest.Config.class) +public class SpringJUnitConfigTest { + + @Configuration + static class Config { + } + + @Autowired + private ApplicationContext applicationContext; + + @Test + void givenAppContext_WhenInjected_ThenItShouldNotBeNull() { + assertNotNull(applicationContext); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java new file mode 100644 index 0000000000..c679dce77f --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java @@ -0,0 +1,34 @@ +package com.baeldung.jupiter; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.web.context.WebApplicationContext; + +/** + * @SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) is equivalent to: + * + * @ExtendWith(SpringExtension.class) + * @WebAppConfiguration + * @ContextConfiguration(classes = SpringJUnitWebConfigTest.Config.class ) + * + */ +@SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) +public class SpringJUnitWebConfigTest { + + @Configuration + static class Config { + } + + @Autowired + private WebApplicationContext webAppContext; + + @Test + void givenWebAppContext_WhenInjected_ThenItShouldNotBeNull() { + assertNotNull(webAppContext); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java b/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java new file mode 100644 index 0000000000..a1c940a17a --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java @@ -0,0 +1,48 @@ +package com.baeldung.security; + +import com.baeldung.SpringSecurity5Application; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = SpringSecurity5Application.class) +public class SecurityTest { + + @Autowired + ApplicationContext context; + + private WebTestClient rest; + + @Before + public void setup() { + this.rest = WebTestClient + .bindToApplicationContext(this.context) + .configureClient() + .build(); + } + + @Test + public void whenNoCredentials_thenRedirectToLogin() { + this.rest.get() + .uri("/") + .exchange() + .expectStatus().is3xxRedirection(); + } + + @Test + @WithMockUser + public void whenHasCredentials_thenSeesGreeting() { + this.rest.get() + .uri("/") + .exchange() + .expectStatus().isOk() + .expectBody(String.class).isEqualTo("Hello, user"); + } +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java new file mode 100644 index 0000000000..c2ed8ff071 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java @@ -0,0 +1,101 @@ +package com.baeldung.web; + +import com.baeldung.Spring5Application; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Spring5Application.class) +public class PathPatternsUsingHandlerMethodIntegrationTest { + + private static WebTestClient client; + + @BeforeClass + public static void setUp() { + client = WebTestClient.bindToController(new PathPatternController()) + .build(); + } + + @Test + public void givenHandlerMethod_whenMultipleURIVariablePattern_then200() { + + client.get() + .uri("/spring5/ab/cd") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("/ab/cd"); + } + + @Test + public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMoreChar_then200() { + + client.get() + .uri("/spring5/userid") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("/spring5/*id"); + } + + @Test + public void givenHandlerMethod_whenURLWithWildcardTakingExactlyOneChar_then200() { + + client.get() + .uri("/string5") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("/s?ring5"); + } + + @Test + public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMorePathSegments_then200() { + + client.get() + .uri("/resources/baeldung") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("/resources/**"); + } + + @Test + public void givenHandlerMethod_whenURLWithRegexInPathVariable_thenExpectedOutput() { + + client.get() + .uri("/abc") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("abc"); + + client.get() + .uri("/123") + .exchange() + .expectStatus() + .is4xxClientError(); + } + + @Test + public void givenHandlerMethod_whenURLWithMultiplePathVariablesInSameSegment_then200() { + + client.get() + .uri("/baeldung_tutorial") + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectBody() + .equals("Two variables are var1=baeldung and var2=tutorial"); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java new file mode 100644 index 0000000000..43114b5b50 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java @@ -0,0 +1,60 @@ +package com.baeldung.web.client; + +import com.baeldung.Spring5Application; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; +import reactor.core.publisher.Mono; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class WebTestClientTest { + + @LocalServerPort + private int port; + + private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(RequestPredicates.GET("/resource"), request -> ServerResponse.ok() + .build()); + private final WebHandler WEB_HANDLER = exchange -> Mono.empty(); + + @Test + public void testWebTestClientWithServerWebHandler() { + WebTestClient.bindToWebHandler(WEB_HANDLER) + .build(); + } + + @Test + public void testWebTestClientWithRouterFunction() { + WebTestClient.bindToRouterFunction(ROUTER_FUNCTION) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .isEmpty(); + } + + @Test + public void testWebTestClientWithServerURL() { + WebTestClient.bindToServer() + .baseUrl("http://localhost:" + port) + .build() + .get() + .uri("/resource") + .exchange() + .expectStatus() + .is3xxRedirection() + .expectBody(); + } + +} diff --git a/spring-5-reactive/src/test/resources/baeldung-weekly.png b/spring-5-reactive/src/test/resources/baeldung-weekly.png new file mode 100644 index 0000000000000000000000000000000000000000..5a27d61dae718016a947083e01411ed1bc14f90e GIT binary patch literal 22275 zcmV*KKxMy)P)4Tx062|}Rb6NtRTMtEb7vzY&QokOg>Hg1+lHrgWS zWcKdPn90sKGrRqvPeo9CG3uKX#J{(IASm?@+di}}l?o-=)F3E6wD^Ni=!>T7nL9I? zX}YoAW$t|Qo$sD|?zw001?ah|SeB6#0T!CBEf+H4bBB+JJu8rehoBb*p;u8ID_yBf z0ya+zcePvJL&AGs+11_tpRKn>9TgyPA7ZoSs0)aX0r00)%XR^J`jH<$>RKN5V(7Oq zK*TS4xZz{h!*f1C3ECFkK$#7nA@pGN!$;%jYvwjAKwmYb0gKL(K8 z-kPtb5${A?tlI~wzMrJ6wTdBr=Y%%%EaEMQ&o}4FQ^DA)s*}Z>!FI&AHCpoWI|RUq zx?7s@$8!5^Q=anY%X@i5{QA6kNc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v-}tI*9#RV?84c3e)5$fH&5^IUqP@=<(yntFx>eITqem zXIu*-SXcE}R>JtBsi}!>z4cbbju5C5%jrT6h=(7t8kRPmWiO^0k%OqYtzF+NZ`+k4 zUm|e4FMHgCxU;tnCsd2zxLo*kw+xoogMIL@Zmw=3l?Ctg~|Uq)8Z1 zXIzueW}chC>jGR{TtxbnlF|}!4BK2+S63m47AI`@4>sO#i-TG#itUVHUI;^e6>N(E zb;h+V{yVjfY;Z^-_3}$E3x8r5ZeW(PHXP49E^N1F&Ya1C_>$mz?j@I8Vv$)Go=qoDo)oh@3@5hl*e;gF z*azW4)uV!aVL+X6?dy4T=?(Z`NT4Cfedd{G1mV8(_B#|66(u}mV07P|J+yYE;8}BX zb4Av}fhhy&`|rLN(L&&SzV!D?sp4#f@Kcr?(Y5bak8O_ub;h;*Gcec#@WGEf`iSt3 zL6k!1PLCfyPW$)o7s4zoumAFwzlf~pk38~-kWwQ>DFDPhW$F~d(iakJM2A4|c-;HZ zM;{S#6aOjYPc&xC7)=UE+!qiSfQ<@vi~*H!?fBuyyC&tffphtD|9MV0n6u+zOQw2)DMjmWqms$d5z20FZ Date: Wed, 13 Dec 2017 13:10:46 +0100 Subject: [PATCH 3/8] Update pom.xml (#3232) --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index 88f54be629..2c611e6efe 100644 --- a/pom.xml +++ b/pom.xml @@ -49,8 +49,6 @@ core-java-8 core-java-concurrency couchbase - cas/cas-server - cas/cas-secured-app deltaspike dozer From df8b6bea54252e476327480cd769799d47abf710 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Wed, 13 Dec 2017 15:15:46 +0200 Subject: [PATCH 4/8] reactive work --- spring-5-reactive/pom.xml | 24 ++- .../java/com/baeldung/Spring5Application.java | 15 -- .../baeldung/SpringSecurity5Application.java | 34 ----- .../java/com/baeldung/functional/Actor.java | 23 --- ...Spring5URLPatternUsingRouterFunctions.java | 61 -------- .../com/baeldung/functional/FormHandler.java | 41 ----- .../FunctionalSpringBootApplication.java | 87 ----------- .../functional/FunctionalWebApplication.java | 80 ---------- .../functional/IndexRewriteFilter.java | 27 ---- .../com/baeldung/functional/MyService.java | 11 -- .../com/baeldung/functional/RootServlet.java | 82 ---------- .../main/java/com/baeldung/jsonb/Person.java | 127 ---------------- .../com/baeldung/jsonb/PersonController.java | 58 ------- .../baeldung/jsonb/Spring5Application.java | 30 ---- .../jupiter/MethodParameterFactory.java | 46 ------ .../jupiter/ParameterAutowireUtils.java | 44 ------ .../com/baeldung/jupiter/SpringExtension.java | 94 ------------ .../baeldung/jupiter/SpringJUnit5Config.java | 39 ----- .../java/com/baeldung/jupiter/TestConfig.java | 20 --- .../baeldung/persistence/DataSetupBean.java | 27 ---- .../baeldung/persistence/FooRepository.java | 10 -- .../reactive/Spring5ReactiveApplication.java | 13 ++ .../com/baeldung/reactive/controller/Foo.java | 13 ++ .../controller/FooReactiveController.java | 34 +++++ .../baeldung/security/GreetController.java | 37 ----- .../com/baeldung/security/GreetService.java | 15 -- .../com/baeldung/security/SecurityConfig.java | 42 ------ .../src/main/java/com/baeldung/web/Foo.java | 84 ----------- .../java/com/baeldung/web/FooController.java | 53 ------- .../baeldung/web/PathPatternController.java | 39 ----- .../java/com/baeldung/web/reactive/Task.java | 28 ---- .../reactive/client/WebClientController.java | 85 ----------- .../src/main/resources/application.properties | 2 - .../com/baeldung/Example1IntegrationTest.java | 29 ---- .../com/baeldung/Example2IntegrationTest.java | 29 ---- .../com/baeldung/ParallelIntegrationTest.java | 24 --- .../Spring5ApplicationIntegrationTest.java | 16 -- ...pring5JUnit4ConcurrentIntegrationTest.java | 52 ------- .../functional/BeanRegistrationTest.java | 42 ------ ...ng5URLPatternUsingRouterFunctionsTest.java | 110 -------------- ...nctionalWebApplicationIntegrationTest.java | 141 ------------------ .../baeldung/jsonb/JsonbIntegrationTest.java | 43 ------ .../com/baeldung/jupiter/EnabledOnJava8.java | 18 --- .../jupiter/Spring5EnabledAnnotationTest.java | 50 ------- ...nit5ComposedAnnotationIntegrationTest.java | 38 ----- .../jupiter/Spring5JUnit5IntegrationTest.java | 25 ---- .../Spring5JUnit5ParallelIntegrationTest.java | 25 ---- ...pring5Java8NewFeaturesIntegrationTest.java | 31 ---- ...g5ReactiveServerClientIntegrationTest.java | 94 ------------ .../jupiter/SpringJUnitConfigTest.java | 33 ---- .../jupiter/SpringJUnitWebConfigTest.java | 34 ----- .../com/baeldung/security/SecurityTest.java | 48 ------ ...ernsUsingHandlerMethodIntegrationTest.java | 101 ------------- .../web/client/WebTestClientTest.java | 60 -------- .../src/test/resources/baeldung-weekly.png | Bin 22275 -> 0 bytes 55 files changed, 71 insertions(+), 2397 deletions(-) delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/Foo.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/FooController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java delete mode 100644 spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java delete mode 100644 spring-5-reactive/src/test/resources/baeldung-weekly.png diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 43d9a5ed94..c1c18fbc82 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -22,10 +22,6 @@ org.springframework.boot spring-boot-starter-data-jpa - - org.springframework.boot - spring-boot-starter-security - org.springframework.boot spring-boot-starter-validation @@ -46,8 +42,8 @@ javax.json.bind javax.json.bind-api - ${jsonb-api.version} + @@ -60,6 +56,7 @@ + org.apache.geronimo.specs geronimo-json_1.1_spec @@ -68,7 +65,6 @@ org.apache.johnzon johnzon-jsonb - ${johnzon.version} @@ -98,11 +94,6 @@ spring-boot-starter-test test - - org.springframework.security - spring-security-test - test - org.apache.commons @@ -114,12 +105,10 @@ org.junit.jupiter junit-jupiter-api - ${junit.jupiter.version} org.junit.jupiter junit-jupiter-engine - ${junit.jupiter.version} test @@ -135,6 +124,15 @@ test + + org.projectlombok + lombok + + + org.apache.commons + commons-lang3 + + diff --git a/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java b/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java deleted file mode 100644 index f321871646..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/Spring5Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -@SpringBootApplication -@ComponentScan(basePackages = { "com.baeldung.web" }) -public class Spring5Application { - - public static void main(String[] args) { - SpringApplication.run(Spring5Application.class, args); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java b/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java deleted file mode 100644 index 02c91a1879..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/SpringSecurity5Application.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; -import org.springframework.web.reactive.config.EnableWebFlux; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import reactor.ipc.netty.NettyContext; -import reactor.ipc.netty.http.server.HttpServer; - -@ComponentScan(basePackages = {"com.baeldung.security"}) -@EnableWebFlux -public class SpringSecurity5Application { - - public static void main(String[] args) { - try (AnnotationConfigApplicationContext context = - new AnnotationConfigApplicationContext(SpringSecurity5Application.class)) { - context.getBean(NettyContext.class).onClose().block(); - } - } - - @Bean - public NettyContext nettyContext(ApplicationContext context) { - HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) - .build(); - ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); - HttpServer httpServer = HttpServer.create("localhost", 8080); - return httpServer.newHandler(adapter).block(); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java b/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java deleted file mode 100644 index 23c88b89e1..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.functional; - -class Actor { - private String firstname; - private String lastname; - - public Actor() { - } - - public Actor(String firstname, String lastname) { - this.firstname = firstname; - this.lastname = lastname; - } - - public String getFirstname() { - return firstname; - } - - public String getLastname() { - return lastname; - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java deleted file mode 100644 index 2a6d04538c..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctions.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.functional; - -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; -import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; -import static org.springframework.web.reactive.function.server.ServerResponse.ok; - -import org.apache.catalina.Context; -import org.apache.catalina.startup.Tomcat; -import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; -import org.springframework.boot.web.server.WebServer; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.WebHandler; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; - -public class ExploreSpring5URLPatternUsingRouterFunctions { - - private RouterFunction routingFunction() { - - return route(GET("/p?ths"), serverRequest -> ok().body(fromObject("/p?ths"))).andRoute(GET("/test/{*id}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("id")))) - .andRoute(GET("/*card"), serverRequest -> ok().body(fromObject("/*card path was accessed"))) - .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) - .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromObject("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) - .and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/"))); - } - - WebServer start() throws Exception { - WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction()); - HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler) - .filter(new IndexRewriteFilter()) - .build(); - - Tomcat tomcat = new Tomcat(); - tomcat.setHostname("localhost"); - tomcat.setPort(9090); - Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir")); - ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler); - Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet); - rootContext.addServletMappingDecoded("/", "httpHandlerServlet"); - - TomcatWebServer server = new TomcatWebServer(tomcat); - server.start(); - return server; - - } - - public static void main(String[] args) { - try { - new FunctionalWebApplication().start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java deleted file mode 100644 index 05069735bb..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.functional; - -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.util.MultiValueMap; -import org.springframework.web.reactive.function.server.ServerRequest; -import org.springframework.web.reactive.function.server.ServerResponse; -import reactor.core.publisher.Mono; - -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - -import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; -import static org.springframework.web.reactive.function.BodyExtractors.toFormData; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.server.ServerResponse.ok; - -public class FormHandler { - - Mono handleLogin(ServerRequest request) { - return request.body(toFormData()) - .map(MultiValueMap::toSingleValueMap) - .filter(formData -> "baeldung".equals(formData.get("user"))) - .filter(formData -> "you_know_what_to_do".equals(formData.get("token"))) - .flatMap(formData -> ok().body(Mono.just("welcome back!"), String.class)) - .switchIfEmpty(ServerResponse.badRequest() - .build()); - } - - Mono handleUpload(ServerRequest request) { - return request.body(toDataBuffers()) - .collectList() - .flatMap(dataBuffers -> ok().body(fromObject(extractData(dataBuffers).toString()))); - } - - private AtomicLong extractData(List dataBuffers) { - AtomicLong atomicLong = new AtomicLong(0); - dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() - .array().length)); - return atomicLong; - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java deleted file mode 100644 index 402b607b19..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.functional; - -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RequestPredicates.path; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; -import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; -import static org.springframework.web.reactive.function.server.ServerResponse.ok; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.server.reactive.HttpHandler; -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; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.WebHandler; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; - -import reactor.core.publisher.Flux; - -@SpringBootApplication -@ComponentScan(basePackages = { "com.baeldung.functional" }) -public class FunctionalSpringBootApplication { - - private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); - private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); - private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); - - private RouterFunction routingFunction() { - FormHandler formHandler = new FormHandler(); - - RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) - .doOnNext(actors::add) - .then(ok().build())); - - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) - .andRoute(POST("/upload"), formHandler::handleUpload) - .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) - .andNest(path("/actor"), restfulRouter) - .filter((request, next) -> { - System.out.println("Before handler invocation: " + request.path()); - return next.handle(request); - }); - } - - @Bean - public ServletRegistrationBean servletRegistrationBean() throws Exception { - HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler((WebHandler) toHttpHandler(routingFunction())) - .filter(new IndexRewriteFilter()) - .build(); - ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(new RootServlet(httpHandler), "/"); - registrationBean.setLoadOnStartup(1); - registrationBean.setAsyncSupported(true); - return registrationBean; - } - - @Configuration - @EnableWebSecurity - @Profile("!https") - static class SecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(final HttpSecurity http) throws Exception { - http.authorizeRequests() - .anyRequest() - .permitAll(); - } - } - - public static void main(String[] args) { - SpringApplication.run(FunctionalSpringBootApplication.class, args); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java deleted file mode 100644 index 5a7d70d3db..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.baeldung.functional; - -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RequestPredicates.path; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; -import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; -import static org.springframework.web.reactive.function.server.ServerResponse.ok; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.catalina.Context; -import org.apache.catalina.startup.Tomcat; -import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; -import org.springframework.boot.web.server.WebServer; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.WebHandler; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; - -import reactor.core.publisher.Flux; - -public class FunctionalWebApplication { - - private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); - private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); - private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); - - private RouterFunction routingFunction() { - FormHandler formHandler = new FormHandler(); - - RouterFunction restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) - .doOnNext(actors::add) - .then(ok().build())); - - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) - .andRoute(POST("/upload"), formHandler::handleUpload) - .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) - .andNest(path("/actor"), restfulRouter) - .filter((request, next) -> { - System.out.println("Before handler invocation: " + request.path()); - return next.handle(request); - }); - } - - WebServer start() throws Exception { - WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction()); - HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler) - .filter(new IndexRewriteFilter()) - .build(); - - Tomcat tomcat = new Tomcat(); - tomcat.setHostname("localhost"); - tomcat.setPort(9090); - Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir")); - ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler); - Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet); - rootContext.addServletMappingDecoded("/", "httpHandlerServlet"); - - TomcatWebServer server = new TomcatWebServer(tomcat); - server.start(); - return server; - - } - - public static void main(String[] args) { - try { - new FunctionalWebApplication().start(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java b/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java deleted file mode 100644 index 3e91a0354b..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.functional; - -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilter; -import org.springframework.web.server.WebFilterChain; -import reactor.core.publisher.Mono; - -class IndexRewriteFilter implements WebFilter { - - @Override - public Mono filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) { - ServerHttpRequest request = serverWebExchange.getRequest(); - if (request.getURI() - .getPath() - .equals("/")) { - return webFilterChain.filter(serverWebExchange.mutate() - .request(builder -> builder.method(request.getMethod()) - .contextPath(request.getPath() - .toString()) - .path("/test")) - .build()); - } - return webFilterChain.filter(serverWebExchange); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java b/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java deleted file mode 100644 index b7b8b13d8b..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/MyService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.functional; - -import java.util.Random; - -public class MyService { - - public int getRandomNumber() { - return (new Random().nextInt(10)); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java b/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java deleted file mode 100644 index 8fe24821de..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.functional; - -import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers; -import static org.springframework.web.reactive.function.BodyExtractors.toFormData; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RequestPredicates.path; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; -import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; -import static org.springframework.web.reactive.function.server.ServerResponse.ok; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; -import org.springframework.util.MultiValueMap; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.WebHandler; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -public class RootServlet extends ServletHttpHandlerAdapter { - - public RootServlet() { - this(WebHttpHandlerBuilder.webHandler((WebHandler) toHttpHandler(routingFunction())) - .filter(new IndexRewriteFilter()) - .build()); - } - - RootServlet(HttpHandler httpHandler) { - super(httpHandler); - } - - private static final Actor BRAD_PITT = new Actor("Brad", "Pitt"); - private static final Actor TOM_HANKS = new Actor("Tom", "Hanks"); - private static final List actors = new CopyOnWriteArrayList<>(Arrays.asList(BRAD_PITT, TOM_HANKS)); - - private static RouterFunction routingFunction() { - - return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), serverRequest -> serverRequest.body(toFormData()) - .map(MultiValueMap::toSingleValueMap) - .map(formData -> { - System.out.println("form data: " + formData.toString()); - if ("baeldung".equals(formData.get("user")) && "you_know_what_to_do".equals(formData.get("token"))) { - return ok().body(Mono.just("welcome back!"), String.class) - .block(); - } - return ServerResponse.badRequest() - .build() - .block(); - })) - .andRoute(POST("/upload"), serverRequest -> serverRequest.body(toDataBuffers()) - .collectList() - .map(dataBuffers -> { - AtomicLong atomicLong = new AtomicLong(0); - dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() - .array().length)); - System.out.println("data length:" + atomicLong.get()); - return ok().body(fromObject(atomicLong.toString())) - .block(); - })) - .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) - .andNest(path("/actor"), route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) - .doOnNext(actors::add) - .then(ok().build()))) - .filter((request, next) -> { - System.out.println("Before handler invocation: " + request.path()); - return next.handle(request); - }); - - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java deleted file mode 100644 index 7a54b37574..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Person.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.baeldung.jsonb; - -import java.math.BigDecimal; -import java.time.LocalDate; - -import javax.json.bind.annotation.JsonbDateFormat; -import javax.json.bind.annotation.JsonbNumberFormat; -import javax.json.bind.annotation.JsonbProperty; -import javax.json.bind.annotation.JsonbTransient; - -public class Person { - - private int id; - @JsonbProperty("person-name") - private String name; - @JsonbProperty(nillable = true) - private String email; - @JsonbTransient - private int age; - @JsonbDateFormat("dd-MM-yyyy") - private LocalDate registeredDate; - private BigDecimal salary; - - public Person() { - } - - public Person(int id, String name, String email, int age, LocalDate registeredDate, BigDecimal salary) { - super(); - this.id = id; - this.name = name; - this.email = email; - this.age = age; - this.registeredDate = registeredDate; - this.salary = salary; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @JsonbNumberFormat(locale = "en_US", value = "#0.0") - public BigDecimal getSalary() { - return salary; - } - - public void setSalary(BigDecimal salary) { - this.salary = salary; - } - - public LocalDate getRegisteredDate() { - return registeredDate; - } - - public void setRegisteredDate(LocalDate registeredDate) { - this.registeredDate = registeredDate; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Person [id="); - builder.append(id); - builder.append(", name="); - builder.append(name); - builder.append(", email="); - builder.append(email); - builder.append(", age="); - builder.append(age); - builder.append(", registeredDate="); - builder.append(registeredDate); - builder.append(", salary="); - builder.append(salary); - builder.append("]"); - return builder.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Person other = (Person) obj; - if (id != other.id) - return false; - return true; - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java deleted file mode 100644 index e216a282eb..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jsonb/PersonController.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.jsonb; - -import java.math.BigDecimal; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.PostConstruct; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -@RestController("/person") -public class PersonController { - - List personRepository; - - @PostConstruct - public void init() { - // @formatter:off - personRepository = new ArrayList<>(Arrays.asList( - new Person(1, "Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)), - new Person(2, "Jhon", "jhon1@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500)), - new Person(3, "Jhon", null, 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)), - new Person(4, "Tom", "tom@test.com", 21, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500)), - new Person(5, "Mark", "mark@test.com", 21, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1200)), - new Person(6, "Julia", "jhon@test.com", 20, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1000)))); - // @formatter:on - - } - - @GetMapping("/person/{id}") - @ResponseBody - public Person findById(@PathVariable final int id) { - return personRepository.get(id); - } - - @PostMapping("/person") - @ResponseStatus(HttpStatus.OK) - @ResponseBody - public boolean insertPerson(@RequestBody final Person person) { - return personRepository.add(person); - } - - @GetMapping("/person") - @ResponseBody - public List findAll() { - return personRepository; - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java b/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java deleted file mode 100644 index 00fce06834..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jsonb/Spring5Application.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.jsonb; - -import java.util.ArrayList; -import java.util.Collection; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.http.HttpMessageConverters; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.JsonbHttpMessageConverter; - -@SpringBootApplication -@ComponentScan(basePackages = { "com.baeldung.jsonb" }) -public class Spring5Application { - - public static void main(String[] args) { - SpringApplication.run(Spring5Application.class, args); - } - - @Bean - public HttpMessageConverters customConverters() { - Collection> messageConverters = new ArrayList<>(); - JsonbHttpMessageConverter jsonbHttpMessageConverter = new JsonbHttpMessageConverter(); - messageConverters.add(jsonbHttpMessageConverter); - return new HttpMessageConverters(true, messageConverters); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java deleted file mode 100644 index 85bd505d11..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jupiter/MethodParameterFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.jupiter; - -import org.springframework.core.MethodParameter; -import org.springframework.core.annotation.SynthesizingMethodParameter; -import org.springframework.util.Assert; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Executable; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -abstract class MethodParameterFactory { - - private MethodParameterFactory() { - } - - public static MethodParameter createMethodParameter(Parameter parameter) { - Assert.notNull(parameter, "Parameter must not be null"); - Executable executable = parameter.getDeclaringExecutable(); - if (executable instanceof Method) { - return new MethodParameter((Method) executable, getIndex(parameter)); - } - return new MethodParameter((Constructor) executable, getIndex(parameter)); - } - - public static SynthesizingMethodParameter createSynthesizingMethodParameter(Parameter parameter) { - Assert.notNull(parameter, "Parameter must not be null"); - Executable executable = parameter.getDeclaringExecutable(); - if (executable instanceof Method) { - return new SynthesizingMethodParameter((Method) executable, getIndex(parameter)); - } - throw new UnsupportedOperationException("Cannot create a SynthesizingMethodParameter for a constructor parameter: " + parameter); - } - - private static int getIndex(Parameter parameter) { - Assert.notNull(parameter, "Parameter must not be null"); - Executable executable = parameter.getDeclaringExecutable(); - Parameter[] parameters = executable.getParameters(); - for (int i = 0; i < parameters.length; i++) { - if (parameters[i] == parameter) { - return i; - } - } - throw new IllegalStateException(String.format("Failed to resolve index of parameter [%s] in executable [%s]", parameter, executable.toGenericString())); - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java deleted file mode 100644 index d1a4cc8b29..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jupiter/ParameterAutowireUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.jupiter; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.DependencyDescriptor; -import org.springframework.context.ApplicationContext; -import org.springframework.core.MethodParameter; -import org.springframework.core.annotation.AnnotatedElementUtils; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.Optional; - -import static org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation; - -abstract class ParameterAutowireUtils { - - private ParameterAutowireUtils() { - } - - public static boolean isAutowirable(Parameter parameter) { - return ApplicationContext.class.isAssignableFrom(parameter.getType()) || hasAnnotation(parameter, Autowired.class) || hasAnnotation(parameter, Qualifier.class) || hasAnnotation(parameter, Value.class); - } - - public static Object resolveDependency(Parameter parameter, Class containingClass, ApplicationContext applicationContext) { - - boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required) - .orElse(true); - MethodParameter methodParameter = (parameter.getDeclaringExecutable() instanceof Method ? MethodParameterFactory.createSynthesizingMethodParameter(parameter) : MethodParameterFactory.createMethodParameter(parameter)); - DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required); - descriptor.setContainingClass(containingClass); - - return applicationContext.getAutowireCapableBeanFactory() - .resolveDependency(descriptor, null); - } - - private static Optional findMergedAnnotation(AnnotatedElement element, Class annotationType) { - - return Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(element, annotationType)); - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java deleted file mode 100644 index 7218d984ef..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringExtension.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.baeldung.jupiter; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Executable; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; - -import org.junit.jupiter.api.extension.AfterAllCallback; -import org.junit.jupiter.api.extension.AfterEachCallback; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; -import org.junit.jupiter.api.extension.ParameterResolver; -import org.junit.jupiter.api.extension.TestInstancePostProcessor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.test.context.TestContextManager; -import org.springframework.util.Assert; - -public class SpringExtension implements BeforeAllCallback, AfterAllCallback, TestInstancePostProcessor, BeforeEachCallback, AfterEachCallback, ParameterResolver { - - private static final ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(SpringExtension.class); - - @Override - public void beforeAll(ExtensionContext context) throws Exception { - getTestContextManager(context).beforeTestClass(); - } - - @Override - public void afterAll(ExtensionContext context) throws Exception { - try { - getTestContextManager(context).afterTestClass(); - } finally { - context.getStore(namespace) - .remove(context.getTestClass() - .get()); - } - } - - @Override - public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception { - getTestContextManager(context).prepareTestInstance(testInstance); - } - - @Override - public void beforeEach(ExtensionContext context) throws Exception { - Object testInstance = context.getTestInstance(); - Method testMethod = context.getTestMethod() - .get(); - getTestContextManager(context).beforeTestMethod(testInstance, testMethod); - } - - @Override - public void afterEach(ExtensionContext context) throws Exception { - Object testInstance = context.getTestInstance(); - Method testMethod = context.getTestMethod() - .get(); - Throwable testException = context.getExecutionException() - .orElse(null); - getTestContextManager(context).afterTestMethod(testInstance, testMethod, testException); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - Parameter parameter = parameterContext.getParameter(); - Executable executable = parameter.getDeclaringExecutable(); - return ((executable instanceof Constructor) && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - Parameter parameter = parameterContext.getParameter(); - Class testClass = extensionContext.getTestClass() - .get(); - ApplicationContext applicationContext = getApplicationContext(extensionContext); - return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext); - } - - private ApplicationContext getApplicationContext(ExtensionContext context) { - return getTestContextManager(context).getTestContext() - .getApplicationContext(); - } - - private TestContextManager getTestContextManager(ExtensionContext context) { - Assert.notNull(context, "ExtensionContext must not be null"); - Class testClass = context.getTestClass() - .get(); - ExtensionContext.Store store = context.getStore(namespace); - return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java deleted file mode 100644 index 8f02d71d49..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jupiter/SpringJUnit5Config.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.jupiter; - -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.annotation.AliasFor; -import org.springframework.test.context.ContextConfiguration; - -import java.lang.annotation.*; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration -@Documented -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface SpringJUnit5Config { - - @AliasFor(annotation = ContextConfiguration.class, attribute = "classes") - Class[] value() default {}; - - @AliasFor(annotation = ContextConfiguration.class) - Class[] classes() default {}; - - @AliasFor(annotation = ContextConfiguration.class) - String[] locations() default {}; - - @AliasFor(annotation = ContextConfiguration.class) - Class>[] initializers() default {}; - - @AliasFor(annotation = ContextConfiguration.class) - boolean inheritLocations() default true; - - @AliasFor(annotation = ContextConfiguration.class) - boolean inheritInitializers() default true; - - @AliasFor(annotation = ContextConfiguration.class) - String name() default ""; -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java b/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java deleted file mode 100644 index a29f77c5df..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/jupiter/TestConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.jupiter; - -import com.baeldung.web.reactive.Task; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; - -@Configuration -public class TestConfig { - - @Bean - static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Bean - Task taskName() { - return new Task("taskName", 1); - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java b/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java deleted file mode 100644 index 9f5d9ff6c2..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/persistence/DataSetupBean.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.persistence; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; - -import java.util.stream.IntStream; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.baeldung.web.Foo; - -@Component -public class DataSetupBean implements InitializingBean { - - @Autowired - private FooRepository repo; - - // - - @Override - public void afterPropertiesSet() throws Exception { - IntStream.range(1, 20) - .forEach(i -> repo.save(new Foo(randomAlphabetic(8)))); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java b/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java deleted file mode 100644 index 1f1e071158..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/persistence/FooRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.persistence; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -import com.baeldung.web.Foo; - -public interface FooRepository extends JpaRepository, JpaSpecificationExecutor { - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java new file mode 100644 index 0000000000..a9308124fa --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.reactive; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Spring5ReactiveApplication { + + public static void main(String[] args) { + SpringApplication.run(Spring5ReactiveApplication.class, args); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java new file mode 100644 index 0000000000..480782a551 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java @@ -0,0 +1,13 @@ +package com.baeldung.reactive.controller; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class Foo { + + private long id; + private String name; + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java new file mode 100644 index 0000000000..d82692619d --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java @@ -0,0 +1,34 @@ +package com.baeldung.reactive.controller; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; + +import java.time.Duration; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.ConnectableFlux; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@RestController("/foos") +public class FooReactiveController { + + @GetMapping("/{id}") + public Mono getFoo(@PathVariable("id") long id) { + return Mono.just(new Foo(id, randomAlphabetic(6))); + } + + @GetMapping("/") + public Flux getAllFoos() { + final ConnectableFlux flux = Flux. create(fluxSink -> { + while (true) { + fluxSink.next(new Foo(System.currentTimeMillis(), randomAlphabetic(6))); + } + }).sample(Duration.ofSeconds(1)).publish(); + + return flux; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java b/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java deleted file mode 100644 index 6b69e3bc9b..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/security/GreetController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.security; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.Mono; - -import java.security.Principal; - -@RestController -public class GreetController { - - private GreetService greetService; - - public GreetController(GreetService greetService) { - this.greetService = greetService; - } - - @GetMapping("/") - public Mono greet(Mono principal) { - return principal - .map(Principal::getName) - .map(name -> String.format("Hello, %s", name)); - } - - @GetMapping("/admin") - public Mono greetAdmin(Mono principal) { - return principal - .map(Principal::getName) - .map(name -> String.format("Admin access: %s", name)); - } - - @GetMapping("/greetService") - public Mono greetService() { - return greetService.greet(); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java b/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java deleted file mode 100644 index 7622b360be..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/security/GreetService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.security; - -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -@Service -public class GreetService { - - @PreAuthorize("hasRole('ADMIN')") - public Mono greet() { - return Mono.just("Hello from service!"); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java b/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java deleted file mode 100644 index a9e44a2eee..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/security/SecurityConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.security; - -import org.springframework.context.annotation.Bean; -import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; -import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; -import org.springframework.security.config.web.server.ServerHttpSecurity; -import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.web.server.SecurityWebFilterChain; - -@EnableWebFluxSecurity -@EnableReactiveMethodSecurity -public class SecurityConfig { - - @Bean - public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) { - return http.authorizeExchange() - .pathMatchers("/admin").hasAuthority("ROLE_ADMIN") - .anyExchange().authenticated() - .and().formLogin() - .and().build(); - } - - @Bean - public MapReactiveUserDetailsService userDetailsService() { - UserDetails user = User.withDefaultPasswordEncoder() - .username("user") - .password("password") - .roles("USER") - .build(); - - UserDetails admin = User.withDefaultPasswordEncoder() - .username("admin") - .password("password") - .roles("ADMIN") - .build(); - - return new MapReactiveUserDetailsService(user, admin); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java deleted file mode 100644 index c4868a9958..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/web/Foo.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.baeldung.web; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Foo { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - - private String name; - - public Foo() { - super(); - } - - public Foo(final String name) { - super(); - - this.name = name; - } - - public Foo(final long id, final String name) { - super(); - - this.id = id; - this.name = name; - } - - // API - - public long getId() { - return id; - } - - public void setId(final long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - // - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Foo other = (Foo) obj; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - @Override - public String toString() { - return "Foo [name=" + name + "]"; - } - -} \ No newline at end of file diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java b/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java deleted file mode 100644 index 925f2b49f4..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/web/FooController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.web; - -import com.baeldung.persistence.FooRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; -import java.util.List; - -@RestController("/foos") -public class FooController { - - @Autowired - private FooRepository repo; - - // API - read - - @GetMapping("/foos/{id}") - @ResponseBody - @Validated - public Foo findById(@PathVariable @Min(0) final long id) { - return repo.findById(id) - .orElse(null); - } - - @GetMapping - @ResponseBody - public List findAll() { - return repo.findAll(); - } - - @GetMapping(params = { "page", "size" }) - @ResponseBody - @Validated - public List findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { - return repo.findAll(PageRequest.of(page, size)) - .getContent(); - } - - // API - write - - @PutMapping("/foos/{id}") - @ResponseStatus(HttpStatus.OK) - @ResponseBody - public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { - return foo; - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java b/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java deleted file mode 100644 index fa413e4f00..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/web/PathPatternController.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class PathPatternController { - - @GetMapping("/spring5/{*id}") - public String URIVariableHandler(@PathVariable String id) { - return id; - } - - @GetMapping("/s?ring5") - public String wildcardTakingExactlyOneChar() { - return "/s?ring5"; - } - - @GetMapping("/spring5/*id") - public String wildcardTakingZeroOrMoreChar() { - return "/spring5/*id"; - } - - @GetMapping("/resources/**") - public String wildcardTakingZeroOrMorePathSegments() { - return "/resources/**"; - } - - @GetMapping("/{baeldung:[a-z]+}") - public String regexInPathVariable(@PathVariable String baeldung) { - return baeldung; - } - - @GetMapping("/{var1}_{var2}") - public String multiplePathVariablesInSameSegment(@PathVariable String var1, @PathVariable String var2) { - return "Two variables are var1=" + var1 + " and var2=" + var2; - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java deleted file mode 100644 index 725fd931e1..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/Task.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.web.reactive; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Task { - - private final String name; - - private final int id; - - public Task(@JsonProperty("name") String name, @JsonProperty("id") int id) { - this.name = name; - this.id = id; - } - - public String getName() { - return this.name; - } - - public int getId() { - return this.id; - } - - @Override - public String toString() { - return "Task{" + "name='" + name + '\'' + ", id=" + id + '}'; - } -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java deleted file mode 100644 index a218c6b7cf..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.web.reactive.client; - -import org.reactivestreams.Publisher; -import org.reactivestreams.Subscriber; -import org.springframework.http.*; -import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.BodyInserter; -import org.springframework.web.reactive.function.BodyInserters; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -import java.net.URI; -import java.nio.charset.Charset; -import java.time.ZonedDateTime; -import java.util.Collections; - -@RestController -public class WebClientController { - - @ResponseStatus(HttpStatus.OK) - @GetMapping("/resource") - public void getResource() { - } - - public void demonstrateWebClient() { - // request - WebClient.UriSpec request1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST); - WebClient.UriSpec request2 = createWebClientWithServerURLAndDefaultValues().post(); - - // request body specifications - WebClient.RequestBodySpec uri1 = createWebClientWithServerURLAndDefaultValues().method(HttpMethod.POST) - .uri("/resource"); - WebClient.RequestBodySpec uri2 = createWebClientWithServerURLAndDefaultValues().post() - .uri(URI.create("/resource")); - - // request header specification - WebClient.RequestHeadersSpec requestSpec1 = uri1.body(BodyInserters.fromPublisher(Mono.just("data"), String.class)); - WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromObject("data")); - - // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters - .fromPublisher(Subscriber::onComplete, String.class); - - LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add("key1", "value1"); - map.add("key2", "value2"); - - BodyInserter, ClientHttpRequest> inserter2 = BodyInserters.fromMultipartData(map); - BodyInserter inserter3 = BodyInserters.fromObject("body"); - - // responses - WebClient.ResponseSpec response1 = uri1.body(inserter3) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .acceptCharset(Charset.forName("UTF-8")) - .ifNoneMatch("*") - .ifModifiedSince(ZonedDateTime.now()) - .retrieve(); - WebClient.ResponseSpec response2 = requestSpec2.retrieve(); - - } - - private WebClient createWebClient() { - return WebClient.create(); - } - - private WebClient createWebClientWithServerURL() { - return WebClient.create("http://localhost:8081"); - } - - private WebClient createWebClientWithServerURLAndDefaultValues() { - return WebClient.builder() - .baseUrl("http://localhost:8081") - .defaultCookie("cookieKey", "cookieValue") - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080")) - .build(); - } - -} diff --git a/spring-5-reactive/src/main/resources/application.properties b/spring-5-reactive/src/main/resources/application.properties index ccec014c2b..4b49e8e8a2 100644 --- a/spring-5-reactive/src/main/resources/application.properties +++ b/spring-5-reactive/src/main/resources/application.properties @@ -1,3 +1 @@ -server.port=8081 - logging.level.root=INFO \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java deleted file mode 100644 index 8b9e66213f..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/Example1IntegrationTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Example1IntegrationTest { - - @Test - public void test1a() { - block(3000); - } - - @Test - public void test1b() { - block(3000); - } - - public static void block(long ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - System.out.println("Thread interrupted"); - } - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java deleted file mode 100644 index 6ed53ca4e9..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/Example2IntegrationTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Example2IntegrationTest { - - @Test - public void test1a() { - block(3000); - } - - @Test - public void test1b() { - block(3000); - } - - public static void block(long ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - System.out.println("Thread Interrupted"); - } - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java deleted file mode 100644 index 1ce96de4ef..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/ParallelIntegrationTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.experimental.ParallelComputer; -import org.junit.runner.Computer; -import org.junit.runner.JUnitCore; - -public class ParallelIntegrationTest { - - @Test - public void runTests() { - final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; - - JUnitCore.runClasses(new Computer(), classes); - } - - @Test - public void runTestsInParallel() { - final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; - - JUnitCore.runClasses(new ParallelComputer(true, true), classes); - } - -} \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java deleted file mode 100644 index af288c3c2d..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/Spring5ApplicationIntegrationTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Spring5ApplicationIntegrationTest { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java deleted file mode 100644 index 7e494465b2..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/Spring5JUnit4ConcurrentIntegrationTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Spring5JUnit4ConcurrentIntegrationTest.SimpleConfiguration.class) -public class Spring5JUnit4ConcurrentIntegrationTest implements ApplicationContextAware, InitializingBean { - - @Configuration - public static class SimpleConfiguration { - } - - private ApplicationContext applicationContext; - - private boolean beanInitialized = false; - - @Override - public final void afterPropertiesSet() throws Exception { - this.beanInitialized = true; - } - - @Override - public final void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - - @Test - public final void verifyApplicationContextSet() throws InterruptedException { - TimeUnit.SECONDS.sleep(2); - assertNotNull("The application context should have been set due to ApplicationContextAware semantics.", this.applicationContext); - } - - @Test - public final void verifyBeanInitialized() throws InterruptedException { - TimeUnit.SECONDS.sleep(2); - assertTrue("This test bean should have been initialized due to InitializingBean semantics.", this.beanInitialized); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java deleted file mode 100644 index 0b1542dbbc..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/BeanRegistrationTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.functional; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.context.support.GenericWebApplicationContext; - -import com.baeldung.Spring5Application; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5Application.class) -public class BeanRegistrationTest { - - @Autowired - private GenericWebApplicationContext context; - - @Test - public void whenRegisterBean_thenOk() { - context.registerBean(MyService.class, () -> new MyService()); - MyService myService = (MyService) context.getBean("com.baeldung.functional.MyService"); - assertTrue(myService.getRandomNumber() < 10); - } - - @Test - public void whenRegisterBeanWithName_thenOk() { - context.registerBean("mySecondService", MyService.class, () -> new MyService()); - MyService mySecondService = (MyService) context.getBean("mySecondService"); - assertTrue(mySecondService.getRandomNumber() < 10); - } - - @Test - public void whenRegisterBeanWithCallback_thenOk() { - context.registerBean("myCallbackService", MyService.class, () -> new MyService(), bd -> bd.setAutowireCandidate(false)); - MyService myCallbackService = (MyService) context.getBean("myCallbackService"); - assertTrue(myCallbackService.getRandomNumber() < 10); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java deleted file mode 100644 index 7a38fa697f..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/ExploreSpring5URLPatternUsingRouterFunctionsTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.baeldung.functional; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.boot.web.server.WebServer; -import org.springframework.test.web.reactive.server.WebTestClient; - -public class ExploreSpring5URLPatternUsingRouterFunctionsTest { - - private static WebTestClient client; - private static WebServer server; - - @BeforeClass - public static void setup() throws Exception { - server = new ExploreSpring5URLPatternUsingRouterFunctions().start(); - client = WebTestClient.bindToServer() - .baseUrl("http://localhost:" + server.getPort()) - .build(); - } - - @AfterClass - public static void destroy() { - server.stop(); - } - - @Test - public void givenRouter_whenGetPathWithSingleCharWildcard_thenGotPathPattern() throws Exception { - client.get() - .uri("/paths") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("/p?ths"); - } - - @Test - public void givenRouter_whenMultipleURIVariablePattern_thenGotPathVariable() throws Exception { - client.get() - .uri("/test/ab/cd") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("/ab/cd"); - } - - @Test - public void givenRouter_whenGetMultipleCharWildcard_thenGotPathPattern() throws Exception { - - client.get() - .uri("/wildcard") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("/*card path was accessed"); - } - - @Test - public void givenRouter_whenGetMultiplePathVaribleInSameSegment_thenGotPathVariables() throws Exception { - - client.get() - .uri("/baeldung_tutorial") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("baeldung , tutorial"); - } - - @Test - public void givenRouter_whenGetRegexInPathVarible_thenGotPathVariable() throws Exception { - - client.get() - .uri("/abcd") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("/{baeldung:[a-z]+} was accessed and baeldung=abcd"); - - client.get() - .uri("/1234") - .exchange() - .expectStatus() - .is4xxClientError(); - } - - @Test - public void givenResources_whenAccess_thenGot() throws Exception { - client.get() - .uri("/files/test/test.txt") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("test"); - - client.get() - .uri("/files/hello.txt") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("hello"); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java deleted file mode 100644 index a7b951b930..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.baeldung.functional; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.boot.web.server.WebServer; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.http.MediaType; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.reactive.function.BodyInserters; - -import static org.springframework.web.reactive.function.BodyInserters.fromObject; -import static org.springframework.web.reactive.function.BodyInserters.fromResource; - -public class FunctionalWebApplicationIntegrationTest { - - private static WebTestClient client; - private static WebServer server; - - @BeforeClass - public static void setup() throws Exception { - server = new FunctionalWebApplication().start(); - client = WebTestClient.bindToServer() - .baseUrl("http://localhost:" + server.getPort()) - .build(); - } - - @AfterClass - public static void destroy() { - server.stop(); - } - - @Test - public void givenRouter_whenGetTest_thenGotHelloWorld() throws Exception { - client.get() - .uri("/test") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("helloworld"); - } - - @Test - public void givenIndexFilter_whenRequestRoot_thenRewrittenToTest() throws Exception { - client.get() - .uri("/") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("helloworld"); - } - - @Test - public void givenLoginForm_whenPostValidToken_thenSuccess() throws Exception { - MultiValueMap formData = new LinkedMultiValueMap<>(1); - formData.add("user", "baeldung"); - formData.add("token", "you_know_what_to_do"); - - client.post() - .uri("/login") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) - .body(BodyInserters.fromFormData(formData)) - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("welcome back!"); - } - - @Test - public void givenLoginForm_whenRequestWithInvalidToken_thenFail() throws Exception { - MultiValueMap formData = new LinkedMultiValueMap<>(2); - formData.add("user", "baeldung"); - formData.add("token", "try_again"); - - client.post() - .uri("/login") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) - .body(BodyInserters.fromFormData(formData)) - .exchange() - .expectStatus() - .isBadRequest(); - } - - @Test - public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception { - Resource resource = new ClassPathResource("/baeldung-weekly.png"); - client.post() - .uri("/upload") - .contentType(MediaType.MULTIPART_FORM_DATA) - .body(fromResource(resource)) - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo(String.valueOf(resource.contentLength())); - } - - @Test - public void givenActors_whenAddActor_thenAdded() throws Exception { - client.get() - .uri("/actor") - .exchange() - .expectStatus() - .isOk() - .expectBodyList(Actor.class) - .hasSize(2); - - client.post() - .uri("/actor") - .body(fromObject(new Actor("Clint", "Eastwood"))) - .exchange() - .expectStatus() - .isOk(); - - client.get() - .uri("/actor") - .exchange() - .expectStatus() - .isOk() - .expectBodyList(Actor.class) - .hasSize(3); - } - - @Test - public void givenResources_whenAccess_thenGot() throws Exception { - client.get() - .uri("/files/hello.txt") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("hello"); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java deleted file mode 100644 index 756b303f3b..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jsonb/JsonbIntegrationTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.jsonb; - -import static org.junit.Assert.assertTrue; - -import java.math.BigDecimal; -import java.time.LocalDate; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class JsonbIntegrationTest { - @Value("${security.user.name}") - private String username; - @Value("${security.user.password}") - private String password; - - @Autowired - private TestRestTemplate template; - - @Test - public void givenId_whenUriIsPerson_thenGetPerson() { - ResponseEntity response = template.withBasicAuth(username, password) - .getForEntity("/person/1", Person.class); - Person person = response.getBody(); - assertTrue(person.equals(new Person(2, "Jhon", "jhon1@test.com", 0, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500.0)))); - } - - @Test - public void whenSendPostAPerson_thenGetOkStatus() { - ResponseEntity response = template.withBasicAuth(username, password) - .postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class); - assertTrue(response.getBody()); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java deleted file mode 100644 index c6d3b7ff10..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.jupiter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.test.context.junit.jupiter.EnabledIf; - -@Target({ ElementType.TYPE, ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@EnabledIf( - expression = "#{systemProperties['java.version'].startsWith('1.8')}", - reason = "Enabled on Java 8" -) -public @interface EnabledOnJava8 { - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java deleted file mode 100644 index ae058bc8ba..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.jupiter; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.DisabledIf; -import org.springframework.test.context.junit.jupiter.EnabledIf; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -@SpringJUnitConfig(Spring5EnabledAnnotationTest.Config.class) -@TestPropertySource(properties = { "tests.enabled=true" }) -public class Spring5EnabledAnnotationTest { - - @Configuration - static class Config { - } - - @EnabledIf("true") - @Test - void givenEnabledIfLiteral_WhenTrue_ThenTestExecuted() { - assertTrue(true); - } - - @EnabledIf(expression = "${tests.enabled}", loadContext = true) - @Test - void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() { - assertTrue(true); - } - - @EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}") - @Test - void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() { - assertTrue(true); - } - - @EnabledOnJava8 - @Test - void givenEnabledOnJava8_WhenTrue_ThenTestExecuted() { - assertTrue(true); - } - - @DisabledIf("#{systemProperties['java.version'].startsWith('1.7')}") - @Test - void givenDisabledIf_WhenTrue_ThenTestNotExecuted() { - assertTrue(true); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java deleted file mode 100644 index 42d27b90f4..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ComposedAnnotationIntegrationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.jupiter; - -import com.baeldung.web.reactive.Task; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@SpringJUnit5Config(TestConfig.class) -@DisplayName("@SpringJUnit5Config Tests") -class Spring5JUnit5ComposedAnnotationIntegrationTest { - - @Autowired - private Task task; - - @Autowired - private List tasks; - - @Test - @DisplayName("ApplicationContext injected into method") - void givenAMethodName_whenInjecting_thenApplicationContextInjectedIntoMethod(ApplicationContext applicationContext) { - assertNotNull(applicationContext, "ApplicationContext should have been injected into method by Spring"); - assertEquals(this.task, applicationContext.getBean("taskName", Task.class)); - } - - @Test - @DisplayName("Spring @Beans injected into fields") - void givenAnObject_whenInjecting_thenSpringBeansInjected() { - assertNotNull(task, "Task should have been @Autowired by Spring"); - assertEquals("taskName", task.getName(), "Task's name"); - assertEquals(1, tasks.size(), "Number of Tasks in context"); - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java deleted file mode 100644 index 0f00a85832..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5IntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.jupiter; - -import com.baeldung.web.reactive.Task; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = TestConfig.class) -class Spring5JUnit5IntegrationTest { - - @Autowired - private Task task; - - @Test - void givenAMethodName_whenInjecting_thenApplicationContextInjectedIntoMetho(ApplicationContext applicationContext) { - assertNotNull(applicationContext, "ApplicationContext should have been injected by Spring"); - assertEquals(this.task, applicationContext.getBean("taskName", Task.class)); - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java deleted file mode 100644 index 55b0fcf267..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5JUnit5ParallelIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.jupiter; - -import com.baeldung.Example1IntegrationTest; -import com.baeldung.Example2IntegrationTest; -import org.junit.experimental.ParallelComputer; -import org.junit.jupiter.api.Test; -import org.junit.runner.Computer; -import org.junit.runner.JUnitCore; - -class Spring5JUnit5ParallelIntegrationTest { - - @Test - void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingParallel() { - final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; - - JUnitCore.runClasses(new ParallelComputer(true, true), classes); - } - - @Test - void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear() { - final Class[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class }; - - JUnitCore.runClasses(new Computer(), classes); - } -} \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java deleted file mode 100644 index f58bf9f3cd..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5Java8NewFeaturesIntegrationTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.jupiter; - -import org.junit.jupiter.api.Test; - -import java.util.function.Supplier; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class Spring5Java8NewFeaturesIntegrationTest { - - @FunctionalInterface - public interface FunctionalInterfaceExample { - Result reverseString(Input input); - } - - public class StringUtils { - FunctionalInterfaceExample functionLambdaString = s -> Pattern.compile(" +") - .splitAsStream(s) - .map(word -> new StringBuilder(word).reverse()) - .collect(Collectors.joining(" ")); - } - - @Test - void givenStringUtil_whenSupplierCall_thenFunctionalInterfaceReverseString() throws Exception { - Supplier stringUtilsSupplier = StringUtils::new; - - assertEquals(stringUtilsSupplier.get().functionLambdaString.reverseString("hello"), "olleh"); - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java deleted file mode 100644 index bbd852d625..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/Spring5ReactiveServerClientIntegrationTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.baeldung.jupiter; - -import com.baeldung.web.reactive.Task; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.ipc.netty.NettyContext; -import reactor.ipc.netty.http.server.HttpServer; - -import java.time.Duration; - -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; - -public class Spring5ReactiveServerClientIntegrationTest { - - private static NettyContext nettyContext; - - @BeforeAll - public static void setUp() throws Exception { - HttpServer server = HttpServer.create("localhost", 8080); - RouterFunction route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok() - .body(request.bodyToFlux(Task.class) - .map(ll -> new Task("TaskName", 1)), Task.class)) - .and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok() - .body(Mono.just("server is alive"), String.class))); - HttpHandler httpHandler = RouterFunctions.toHttpHandler(route); - ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); - nettyContext = server.newHandler(adapter) - .block(); - } - - @AfterAll - public static void shutDown() { - nettyContext.dispose(); - } - - // @Test - // public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception { - // WebClient client = WebClient.create("http://localhost:8080"); - // Mono result = client - // .get() - // .uri("/task") - // .exchange() - // .then(response -> response.bodyToMono(String.class)); - // - // assertThat(result.block()).isInstanceOf(String.class); - // } - - // @Test - // public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception { - // URI uri = URI.create("http://localhost:8080/task/process"); - // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); - // ClientRequest request = ClientRequest - // .method(HttpMethod.POST, uri) - // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) - // .build(); - // - // Flux taskResponse = exchange - // .exchange(request) - // .flatMap(response -> response.bodyToFlux(Task.class)); - // - // assertThat(taskResponse.blockFirst()).isInstanceOf(Task.class); - // } - - // @Test - // public void givenCheckTask_whenServerHandle_thenOragicServerResponseALiveString() throws Exception { - // URI uri = URI.create("http://localhost:8080/task"); - // ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector()); - // ClientRequest request = ClientRequest - // .method(HttpMethod.GET, uri) - // .body(BodyInserters.fromPublisher(getLatLngs(), Task.class)) - // .build(); - // - // Flux taskResponse = exchange - // .exchange(request) - // .flatMap(response -> response.bodyToFlux(String.class)); - // - // assertThat(taskResponse.blockFirst()).isInstanceOf(String.class); - // } - - private static Flux getLatLngs() { - return Flux.range(0, 3) - .zipWith(Flux.interval(Duration.ofSeconds(1))) - .map(x -> new Task("taskname", 1)) - .doOnNext(ll -> System.out.println("Produced: {}" + ll)); - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java deleted file mode 100644 index 6b0a6f9808..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitConfigTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.jupiter; - -import static org.junit.Assert.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -/** - * @SpringJUnitConfig(SpringJUnitConfigTest.Config.class) is equivalent to: - * - * @ExtendWith(SpringExtension.class) - * @ContextConfiguration(classes = SpringJUnitConfigTest.Config.class ) - * - */ -@SpringJUnitConfig(SpringJUnitConfigTest.Config.class) -public class SpringJUnitConfigTest { - - @Configuration - static class Config { - } - - @Autowired - private ApplicationContext applicationContext; - - @Test - void givenAppContext_WhenInjected_ThenItShouldNotBeNull() { - assertNotNull(applicationContext); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java b/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java deleted file mode 100644 index c679dce77f..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/jupiter/SpringJUnitWebConfigTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.jupiter; - -import static org.junit.Assert.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; -import org.springframework.web.context.WebApplicationContext; - -/** - * @SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) is equivalent to: - * - * @ExtendWith(SpringExtension.class) - * @WebAppConfiguration - * @ContextConfiguration(classes = SpringJUnitWebConfigTest.Config.class ) - * - */ -@SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) -public class SpringJUnitWebConfigTest { - - @Configuration - static class Config { - } - - @Autowired - private WebApplicationContext webAppContext; - - @Test - void givenWebAppContext_WhenInjected_ThenItShouldNotBeNull() { - assertNotNull(webAppContext); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java b/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java deleted file mode 100644 index a1c940a17a..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/security/SecurityTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.security; - -import com.baeldung.SpringSecurity5Application; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; - -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = SpringSecurity5Application.class) -public class SecurityTest { - - @Autowired - ApplicationContext context; - - private WebTestClient rest; - - @Before - public void setup() { - this.rest = WebTestClient - .bindToApplicationContext(this.context) - .configureClient() - .build(); - } - - @Test - public void whenNoCredentials_thenRedirectToLogin() { - this.rest.get() - .uri("/") - .exchange() - .expectStatus().is3xxRedirection(); - } - - @Test - @WithMockUser - public void whenHasCredentials_thenSeesGreeting() { - this.rest.get() - .uri("/") - .exchange() - .expectStatus().isOk() - .expectBody(String.class).isEqualTo("Hello, user"); - } -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java deleted file mode 100644 index c2ed8ff071..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/web/PathPatternsUsingHandlerMethodIntegrationTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.baeldung.web; - -import com.baeldung.Spring5Application; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5Application.class) -public class PathPatternsUsingHandlerMethodIntegrationTest { - - private static WebTestClient client; - - @BeforeClass - public static void setUp() { - client = WebTestClient.bindToController(new PathPatternController()) - .build(); - } - - @Test - public void givenHandlerMethod_whenMultipleURIVariablePattern_then200() { - - client.get() - .uri("/spring5/ab/cd") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("/ab/cd"); - } - - @Test - public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMoreChar_then200() { - - client.get() - .uri("/spring5/userid") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("/spring5/*id"); - } - - @Test - public void givenHandlerMethod_whenURLWithWildcardTakingExactlyOneChar_then200() { - - client.get() - .uri("/string5") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("/s?ring5"); - } - - @Test - public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMorePathSegments_then200() { - - client.get() - .uri("/resources/baeldung") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("/resources/**"); - } - - @Test - public void givenHandlerMethod_whenURLWithRegexInPathVariable_thenExpectedOutput() { - - client.get() - .uri("/abc") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("abc"); - - client.get() - .uri("/123") - .exchange() - .expectStatus() - .is4xxClientError(); - } - - @Test - public void givenHandlerMethod_whenURLWithMultiplePathVariablesInSameSegment_then200() { - - client.get() - .uri("/baeldung_tutorial") - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectBody() - .equals("Two variables are var1=baeldung and var2=tutorial"); - } - -} diff --git a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java b/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java deleted file mode 100644 index 43114b5b50..0000000000 --- a/spring-5-reactive/src/test/java/com/baeldung/web/client/WebTestClientTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.web.client; - -import com.baeldung.Spring5Application; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.reactive.function.server.RequestPredicates; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.WebHandler; -import reactor.core.publisher.Mono; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class WebTestClientTest { - - @LocalServerPort - private int port; - - private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(RequestPredicates.GET("/resource"), request -> ServerResponse.ok() - .build()); - private final WebHandler WEB_HANDLER = exchange -> Mono.empty(); - - @Test - public void testWebTestClientWithServerWebHandler() { - WebTestClient.bindToWebHandler(WEB_HANDLER) - .build(); - } - - @Test - public void testWebTestClientWithRouterFunction() { - WebTestClient.bindToRouterFunction(ROUTER_FUNCTION) - .build() - .get() - .uri("/resource") - .exchange() - .expectStatus() - .isOk() - .expectBody() - .isEmpty(); - } - - @Test - public void testWebTestClientWithServerURL() { - WebTestClient.bindToServer() - .baseUrl("http://localhost:" + port) - .build() - .get() - .uri("/resource") - .exchange() - .expectStatus() - .is3xxRedirection() - .expectBody(); - } - -} diff --git a/spring-5-reactive/src/test/resources/baeldung-weekly.png b/spring-5-reactive/src/test/resources/baeldung-weekly.png deleted file mode 100644 index 5a27d61dae718016a947083e01411ed1bc14f90e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22275 zcmV*KKxMy)P)4Tx062|}Rb6NtRTMtEb7vzY&QokOg>Hg1+lHrgWS zWcKdPn90sKGrRqvPeo9CG3uKX#J{(IASm?@+di}}l?o-=)F3E6wD^Ni=!>T7nL9I? zX}YoAW$t|Qo$sD|?zw001?ah|SeB6#0T!CBEf+H4bBB+JJu8rehoBb*p;u8ID_yBf z0ya+zcePvJL&AGs+11_tpRKn>9TgyPA7ZoSs0)aX0r00)%XR^J`jH<$>RKN5V(7Oq zK*TS4xZz{h!*f1C3ECFkK$#7nA@pGN!$;%jYvwjAKwmYb0gKL(K8 z-kPtb5${A?tlI~wzMrJ6wTdBr=Y%%%EaEMQ&o}4FQ^DA)s*}Z>!FI&AHCpoWI|RUq zx?7s@$8!5^Q=an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g(t=m818W}1_@##{v-}tI*9#RV?84c3e)5$fH&5^IUqP@=<(yntFx>eITqem zXIu*-SXcE}R>JtBsi}!>z4cbbju5C5%jrT6h=(7t8kRPmWiO^0k%OqYtzF+NZ`+k4 zUm|e4FMHgCxU;tnCsd2zxLo*kw+xoogMIL@Zmw=3l?Ctg~|Uq)8Z1 zXIzueW}chC>jGR{TtxbnlF|}!4BK2+S63m47AI`@4>sO#i-TG#itUVHUI;^e6>N(E zb;h+V{yVjfY;Z^-_3}$E3x8r5ZeW(PHXP49E^N1F&Ya1C_>$mz?j@I8Vv$)Go=qoDo)oh@3@5hl*e;gF z*azW4)uV!aVL+X6?dy4T=?(Z`NT4Cfedd{G1mV8(_B#|66(u}mV07P|J+yYE;8}BX zb4Av}fhhy&`|rLN(L&&SzV!D?sp4#f@Kcr?(Y5bak8O_ub;h;*Gcec#@WGEf`iSt3 zL6k!1PLCfyPW$)o7s4zoumAFwzlf~pk38~-kWwQ>DFDPhW$F~d(iakJM2A4|c-;HZ zM;{S#6aOjYPc&xC7)=UE+!qiSfQ<@vi~*H!?fBuyyC&tffphtD|9MV0n6u+zOQw2)DMjmWqms$d5z20FZ Date: Wed, 13 Dec 2017 14:32:44 +0100 Subject: [PATCH 5/8] Add main entry point (#3233) --- spring-security-acl/pom.xml | 1 - .../src/main/java/org/baeldung/acl/Application.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spring-security-acl/src/main/java/org/baeldung/acl/Application.java diff --git a/spring-security-acl/pom.xml b/spring-security-acl/pom.xml index 67197bc2f8..a19a54dd88 100644 --- a/spring-security-acl/pom.xml +++ b/spring-security-acl/pom.xml @@ -3,7 +3,6 @@ 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-security-acl 0.0.1-SNAPSHOT war diff --git a/spring-security-acl/src/main/java/org/baeldung/acl/Application.java b/spring-security-acl/src/main/java/org/baeldung/acl/Application.java new file mode 100644 index 0000000000..665ca64076 --- /dev/null +++ b/spring-security-acl/src/main/java/org/baeldung/acl/Application.java @@ -0,0 +1,11 @@ +package org.baeldung.acl; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} From c68acf03d9dd803c4f027fffa71574f7cb6d3906 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Wed, 13 Dec 2017 15:56:37 +0200 Subject: [PATCH 6/8] flux generating data on interval --- .../controller/FooReactiveController.java | 11 ++++--- .../com/baeldung/reactive/FluxUnitTest.java | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java index d82692619d..1115036ad3 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java @@ -8,25 +8,24 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.ConnectableFlux; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -@RestController("/foos") +@RestController public class FooReactiveController { - @GetMapping("/{id}") + @GetMapping("/foos/{id}") public Mono getFoo(@PathVariable("id") long id) { return Mono.just(new Foo(id, randomAlphabetic(6))); } - @GetMapping("/") + @GetMapping("/foos") public Flux getAllFoos() { - final ConnectableFlux flux = Flux. create(fluxSink -> { + final Flux flux = Flux. create(fluxSink -> { while (true) { fluxSink.next(new Foo(System.currentTimeMillis(), randomAlphabetic(6))); } - }).sample(Duration.ofSeconds(1)).publish(); + }).sample(Duration.ofSeconds(1)).log(); return flux; } diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java new file mode 100644 index 0000000000..5499e72877 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.reactive; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.junit.Assert.assertNotNull; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; + +import com.baeldung.reactive.controller.Foo; + +import reactor.core.publisher.Flux; + +public class FluxUnitTest { + + @Test + public void whenFluxIsConstructed_thenCorrect() { + final Flux flux = Flux. create(fluxSink -> { + while (true) { + fluxSink.next(new Foo(System.currentTimeMillis(), randomAlphabetic(6))); + } + }).sample(Duration.ofSeconds(1)).log(); + + flux.subscribe(); + + assertNotNull(flux); + } + +} From 471ed5d99297d2acd627bf80f55948749309d29c Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Wed, 13 Dec 2017 18:59:17 +0200 Subject: [PATCH 7/8] new client project, general cleanup, testing work --- spring-5-reactive-client/.gitignore | 12 ++ spring-5-reactive-client/README.md | 15 ++ spring-5-reactive-client/pom.xml | 201 ++++++++++++++++++ .../com/baeldung/reactive/model}/Foo.java | 2 +- .../src/main/resources/application.properties | 3 + .../src/main/resources/logback.xml | 16 ++ .../src/main/webapp/WEB-INF/web.xml | 21 ++ .../reactive/ReactiveIntegrationTest.java | 42 ++++ .../Spring5ReactiveTestApplication.java | 35 +++ .../src/test/resources/logback-test.xml | 16 ++ .../controller/FooReactiveController.java | 17 +- .../java/com/baeldung/reactive/model/Foo.java | 13 ++ .../src/main/resources/files/hello.txt | 1 - .../src/main/resources/files/test/test.txt | 1 - .../com/baeldung/reactive/FluxUnitTest.java | 5 +- 15 files changed, 393 insertions(+), 7 deletions(-) create mode 100644 spring-5-reactive-client/.gitignore create mode 100644 spring-5-reactive-client/README.md create mode 100644 spring-5-reactive-client/pom.xml rename {spring-5-reactive/src/main/java/com/baeldung/reactive/controller => spring-5-reactive-client/src/main/java/com/baeldung/reactive/model}/Foo.java (78%) create mode 100644 spring-5-reactive-client/src/main/resources/application.properties create mode 100644 spring-5-reactive-client/src/main/resources/logback.xml create mode 100644 spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java create mode 100644 spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java create mode 100644 spring-5-reactive-client/src/test/resources/logback-test.xml create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java delete mode 100644 spring-5-reactive/src/main/resources/files/hello.txt delete mode 100644 spring-5-reactive/src/main/resources/files/test/test.txt diff --git a/spring-5-reactive-client/.gitignore b/spring-5-reactive-client/.gitignore new file mode 100644 index 0000000000..dec013dfa4 --- /dev/null +++ b/spring-5-reactive-client/.gitignore @@ -0,0 +1,12 @@ +#folders# +.idea +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-5-reactive-client/README.md b/spring-5-reactive-client/README.md new file mode 100644 index 0000000000..400e343263 --- /dev/null +++ b/spring-5-reactive-client/README.md @@ -0,0 +1,15 @@ +## Spring REST Example Project + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles + +- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests) +- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) +- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching) +- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient) +- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans) +- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config) +- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive) +- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5) diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml new file mode 100644 index 0000000000..8aa579b724 --- /dev/null +++ b/spring-5-reactive-client/pom.xml @@ -0,0 +1,201 @@ + + + 4.0.0 + + com.baeldung + spring-5-reactive-client + 0.0.1-SNAPSHOT + jar + + spring-5 + spring 5 sample project about new features + + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.M7 + + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.projectreactor + reactor-spring + ${reactor-spring.version} + + + javax.json.bind + javax.json.bind-api + + + + + + + + + + + + + + + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + ${geronimo-json_1.1_spec.version} + + + org.apache.johnzon + johnzon-jsonb + + + + org.apache.commons + commons-lang3 + + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + com.h2database + h2 + runtime + + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.apache.commons + commons-collections4 + 4.1 + test + + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + test + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + org.projectlombok + lombok + + + org.apache.commons + commons-lang3 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.Spring5Application + JAR + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 3 + true + methods + true + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + UTF-8 + UTF-8 + 1.8 + 1.0.0 + 5.0.0 + 2.20 + 5.0.1.RELEASE + 1.0.1.RELEASE + 1.1.3 + 1.0 + 1.0 + + + diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java similarity index 78% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java rename to spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java index 480782a551..2c49e6146a 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/Foo.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java @@ -1,4 +1,4 @@ -package com.baeldung.reactive.controller; +package com.baeldung.reactive.model; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/spring-5-reactive-client/src/main/resources/application.properties b/spring-5-reactive-client/src/main/resources/application.properties new file mode 100644 index 0000000000..2d93456aeb --- /dev/null +++ b/spring-5-reactive-client/src/main/resources/application.properties @@ -0,0 +1,3 @@ +logging.level.root=INFO + +server.port=8081 \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/resources/logback.xml b/spring-5-reactive-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..8bbe8c1d67 --- /dev/null +++ b/spring-5-reactive-client/src/main/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + # Pattern of log message for console appender + %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n + + + + + + + + + + \ No newline at end of file diff --git a/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml b/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..bfcf43dad2 --- /dev/null +++ b/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + Spring Functional Application + + + functional + com.baeldung.functional.RootServlet + 1 + true + + + functional + / + + + + \ No newline at end of file diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java new file mode 100644 index 0000000000..394ff42e5f --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java @@ -0,0 +1,42 @@ +package com.baeldung.reactive; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; + +import com.baeldung.reactive.model.Foo; + +import reactor.core.publisher.Mono; + +@SpringBootTest +public class ReactiveIntegrationTest { + + private WebClient client; + + @BeforeEach + public void before() { + client = WebClient.create("http://localhost:8080"); + } + + // + + @Test + public void whenMonoReactiveEndpointIsConsumed_thenCorrectOutput() { + final Mono fooMono = client.get().uri("/foos/123").exchange().log(); + + System.out.println(fooMono.subscribe()); + } + + @Test + public void whenFluxReactiveEndpointIsConsumed_thenCorrectOutput() throws InterruptedException { + client.get().uri("/foos") + .retrieve() + .bodyToFlux(Foo.class).log() + .subscribe(System.out::println); + + System.out.println(); + } + +} diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java new file mode 100644 index 0000000000..c884ace323 --- /dev/null +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java @@ -0,0 +1,35 @@ +package com.baeldung.reactive; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.function.client.WebClient; + +import com.baeldung.reactive.model.Foo; + +@SpringBootApplication +public class Spring5ReactiveTestApplication { + + @Bean + public WebClient client() { + return WebClient.create("http://localhost:8080"); + } + + @Bean + CommandLineRunner cmd(WebClient client) { + return args -> { + client.get().uri("/foos2") + .retrieve() + .bodyToFlux(Foo.class).log() + .subscribe(System.out::println); + }; + } + + // + + public static void main(String[] args) { + SpringApplication.run(Spring5ReactiveTestApplication.class, args); + } + +} diff --git a/spring-5-reactive-client/src/test/resources/logback-test.xml b/spring-5-reactive-client/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8bbe8c1d67 --- /dev/null +++ b/spring-5-reactive-client/src/test/resources/logback-test.xml @@ -0,0 +1,16 @@ + + + + + # Pattern of log message for console appender + %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n + + + + + + + + + + \ No newline at end of file diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java index 1115036ad3..933d469f65 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java @@ -3,13 +3,19 @@ package com.baeldung.reactive.controller; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import java.time.Duration; +import java.util.Random; +import java.util.stream.Stream; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.reactive.model.Foo; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; @RestController public class FooReactiveController { @@ -19,11 +25,18 @@ public class FooReactiveController { return Mono.just(new Foo(id, randomAlphabetic(6))); } - @GetMapping("/foos") + @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE, value = "/foos") + public Flux getAllFoos2() { + final Flux foosFlux = Flux.fromStream(Stream.generate(() -> new Foo(new Random().nextLong(), randomAlphabetic(6)))); + final Flux emmitFlux = Flux.interval(Duration.ofSeconds(1)); + return Flux.zip(foosFlux, emmitFlux).map(Tuple2::getT1); + } + + @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE, value = "/foos2") public Flux getAllFoos() { final Flux flux = Flux. create(fluxSink -> { while (true) { - fluxSink.next(new Foo(System.currentTimeMillis(), randomAlphabetic(6))); + fluxSink.next(new Foo(new Random().nextLong(), randomAlphabetic(6))); } }).sample(Duration.ofSeconds(1)).log(); diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java new file mode 100644 index 0000000000..2c49e6146a --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java @@ -0,0 +1,13 @@ +package com.baeldung.reactive.model; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class Foo { + + private long id; + private String name; + +} diff --git a/spring-5-reactive/src/main/resources/files/hello.txt b/spring-5-reactive/src/main/resources/files/hello.txt deleted file mode 100644 index b6fc4c620b..0000000000 --- a/spring-5-reactive/src/main/resources/files/hello.txt +++ /dev/null @@ -1 +0,0 @@ -hello \ No newline at end of file diff --git a/spring-5-reactive/src/main/resources/files/test/test.txt b/spring-5-reactive/src/main/resources/files/test/test.txt deleted file mode 100644 index 30d74d2584..0000000000 --- a/spring-5-reactive/src/main/resources/files/test/test.txt +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java index 5499e72877..bad5fc5f22 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java @@ -4,10 +4,11 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.junit.Assert.assertNotNull; import java.time.Duration; +import java.util.Random; import org.junit.jupiter.api.Test; -import com.baeldung.reactive.controller.Foo; +import com.baeldung.reactive.model.Foo; import reactor.core.publisher.Flux; @@ -17,7 +18,7 @@ public class FluxUnitTest { public void whenFluxIsConstructed_thenCorrect() { final Flux flux = Flux. create(fluxSink -> { while (true) { - fluxSink.next(new Foo(System.currentTimeMillis(), randomAlphabetic(6))); + fluxSink.next(new Foo(new Random().nextLong(), randomAlphabetic(6))); } }).sample(Duration.ofSeconds(1)).log(); From 18c8747c98d0c89c64e1a7db8df80413737a4ef7 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 14 Dec 2017 06:26:03 +0200 Subject: [PATCH 8/8] BAEL-1248 google sheets api example (#3189) * google sheets api example * add dependencies * rename test * update test * add comment * trigger build * trigger build * Formatting to standards * Getting rid of stray tabs * Applying formatting rules to source files as well * trigger build --- libraries/pom.xml | 25 +++- .../google/sheets/GoogleAuthorizeUtil.java | 42 ++++++ .../google/sheets/SheetsServiceUtil.java | 23 +++ .../google-sheets-client-secret.json | 1 + .../sheets/GoogleSheetsIntegrationTest.java | 140 ++++++++++++++++++ 5 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 libraries/src/main/java/com/baeldung/google/sheets/GoogleAuthorizeUtil.java create mode 100644 libraries/src/main/java/com/baeldung/google/sheets/SheetsServiceUtil.java create mode 100644 libraries/src/main/resources/google-sheets-client-secret.json create mode 100644 libraries/src/test/java/com/baeldung/google/sheets/GoogleSheetsIntegrationTest.java diff --git a/libraries/pom.xml b/libraries/pom.xml index eaa2d9d38f..3627e74472 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -633,9 +633,26 @@ ${googleclient.version} - com.google.http-client - google-http-client-gson - ${googleclient.version} + com.google.http-client + google-http-client-gson + ${googleclient.version} + + + + + com.google.api-client + google-api-client + ${google-api.version} + + + com.google.oauth-client + google-oauth-client-jetty + ${google-api.version} + + + com.google.apis + google-api-services-sheets + ${google-sheets.version} @@ -710,5 +727,7 @@ 1.0.0 3.8.4 2.5.5 + 1.23.0 + v4-rev493-1.21.0 \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/google/sheets/GoogleAuthorizeUtil.java b/libraries/src/main/java/com/baeldung/google/sheets/GoogleAuthorizeUtil.java new file mode 100644 index 0000000000..650a1d084c --- /dev/null +++ b/libraries/src/main/java/com/baeldung/google/sheets/GoogleAuthorizeUtil.java @@ -0,0 +1,42 @@ +package com.baeldung.google.sheets; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.security.GeneralSecurityException; +import java.util.Arrays; +import java.util.List; + +import com.google.api.client.auth.oauth2.Credential; +import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; +import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; +import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; +import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.store.MemoryDataStoreFactory; +import com.google.api.services.sheets.v4.SheetsScopes; + +public class GoogleAuthorizeUtil { + public static Credential authorize() throws IOException, GeneralSecurityException { + InputStream in = GoogleAuthorizeUtil.class.getResourceAsStream("/google-sheets-client-secret.json"); + GoogleClientSecrets clientSecrets = GoogleClientSecrets + .load(JacksonFactory.getDefaultInstance(), new InputStreamReader(in)); + + List scopes = Arrays.asList(SheetsScopes.SPREADSHEETS); + + GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow + .Builder(GoogleNetHttpTransport.newTrustedTransport(), + JacksonFactory.getDefaultInstance(), + clientSecrets, + scopes) + .setDataStoreFactory(new MemoryDataStoreFactory()) + .setAccessType("offline") + .build(); + Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) + .authorize("user"); + + return credential; + } + +} diff --git a/libraries/src/main/java/com/baeldung/google/sheets/SheetsServiceUtil.java b/libraries/src/main/java/com/baeldung/google/sheets/SheetsServiceUtil.java new file mode 100644 index 0000000000..bbce96f389 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/google/sheets/SheetsServiceUtil.java @@ -0,0 +1,23 @@ +package com.baeldung.google.sheets; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import com.google.api.client.auth.oauth2.Credential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.services.sheets.v4.Sheets; + +public class SheetsServiceUtil { + + private static final String APPLICATION_NAME = "Google Sheets Example"; + + public static Sheets getSheetsService() throws IOException, GeneralSecurityException { + Credential credential = GoogleAuthorizeUtil.authorize(); + return new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(), + JacksonFactory.getDefaultInstance(), credential) + .setApplicationName(APPLICATION_NAME) + .build(); + } + +} diff --git a/libraries/src/main/resources/google-sheets-client-secret.json b/libraries/src/main/resources/google-sheets-client-secret.json new file mode 100644 index 0000000000..c92ccd6b9b --- /dev/null +++ b/libraries/src/main/resources/google-sheets-client-secret.json @@ -0,0 +1 @@ +{"installed":{"client_id":"394827218507-2ev02b2ha8plt7g2lh5nqse02ee737cf.apps.googleusercontent.com","project_id":"decisive-octane-187810","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"2MnN1DfenoCGWMay3v8Bf7eI","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/google/sheets/GoogleSheetsIntegrationTest.java b/libraries/src/test/java/com/baeldung/google/sheets/GoogleSheetsIntegrationTest.java new file mode 100644 index 0000000000..5280073be2 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/google/sheets/GoogleSheetsIntegrationTest.java @@ -0,0 +1,140 @@ +package com.baeldung.google.sheets; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.api.services.sheets.v4.Sheets; +import com.google.api.services.sheets.v4.model.AppendValuesResponse; +import com.google.api.services.sheets.v4.model.BatchGetValuesResponse; +import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest; +import com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest; +import com.google.api.services.sheets.v4.model.BatchUpdateValuesResponse; +import com.google.api.services.sheets.v4.model.CopyPasteRequest; +import com.google.api.services.sheets.v4.model.GridRange; +import com.google.api.services.sheets.v4.model.Request; +import com.google.api.services.sheets.v4.model.Spreadsheet; +import com.google.api.services.sheets.v4.model.SpreadsheetProperties; +import com.google.api.services.sheets.v4.model.UpdateSpreadsheetPropertiesRequest; +import com.google.api.services.sheets.v4.model.UpdateValuesResponse; +import com.google.api.services.sheets.v4.model.ValueRange; + +import static org.assertj.core.api.Assertions.*; + +public class GoogleSheetsIntegrationTest { + + private static Sheets sheetsService; + + // this id can be replaced with your spreadsheet id + // otherwise be advised that multiple people may run this test and update the public spreadsheet + private static final String SPREADSHEET_ID = "1sILuxZUnyl_7-MlNThjt765oWshN3Xs-PPLfqYe4DhI"; + + @BeforeClass + public static void setup() throws GeneralSecurityException, IOException { + sheetsService = SheetsServiceUtil.getSheetsService(); + } + + @Test + public void whenWriteSheet_thenReadSheetOk() throws IOException { + ValueRange body = new ValueRange() + .setValues(Arrays.asList( + Arrays.asList("Expenses January"), + Arrays.asList("books", "30"), + Arrays.asList("pens", "10"), + Arrays.asList("Expenses February"), + Arrays.asList("clothes", "20"), + Arrays.asList("shoes", "5"))); + UpdateValuesResponse result = sheetsService.spreadsheets().values() + .update(SPREADSHEET_ID, "A1", body) + .setValueInputOption("RAW") + .execute(); + + List data = new ArrayList<>(); + data.add(new ValueRange() + .setRange("D1") + .setValues(Arrays.asList( + Arrays.asList("January Total", "=B2+B3")))); + data.add(new ValueRange() + .setRange("D4") + .setValues(Arrays.asList( + Arrays.asList("February Total", "=B5+B6")))); + + BatchUpdateValuesRequest batchBody = new BatchUpdateValuesRequest() + .setValueInputOption("USER_ENTERED") + .setData(data); + BatchUpdateValuesResponse batchResult = + sheetsService.spreadsheets().values() + .batchUpdate(SPREADSHEET_ID, batchBody) + .execute(); + + List ranges = Arrays.asList("E1","E4"); + BatchGetValuesResponse readResult = + sheetsService.spreadsheets().values() + .batchGet(SPREADSHEET_ID) + .setRanges(ranges) + .execute(); + + ValueRange januaryTotal = readResult.getValueRanges().get(0); + assertThat(januaryTotal.getValues().get(0).get(0)).isEqualTo("40"); + + ValueRange febTotal = readResult.getValueRanges().get(1); + assertThat(febTotal.getValues().get(0).get(0)).isEqualTo("25"); + + ValueRange appendBody = new ValueRange() + .setValues(Arrays.asList( + Arrays.asList("Total", "=E1+E4"))); + AppendValuesResponse appendResult = + sheetsService.spreadsheets().values() + .append(SPREADSHEET_ID, "A1", appendBody) + .setValueInputOption("USER_ENTERED") + .setInsertDataOption("INSERT_ROWS") + .setIncludeValuesInResponse(true) + .execute(); + + ValueRange total = appendResult.getUpdates().getUpdatedData(); + assertThat(total.getValues().get(0).get(1)).isEqualTo("65"); + } + + + @Test + public void whenUpdateSpreadSheetTitle_thenOk() throws IOException { + + UpdateSpreadsheetPropertiesRequest updateRequest = new UpdateSpreadsheetPropertiesRequest() + .setFields("*") + .setProperties(new SpreadsheetProperties().setTitle("Expenses")); + + CopyPasteRequest copyRequest = new CopyPasteRequest() + .setSource(new GridRange().setSheetId(0) + .setStartColumnIndex(0).setEndColumnIndex(2) + .setStartRowIndex(0).setEndRowIndex(1)) + .setDestination(new GridRange().setSheetId(1) + .setStartColumnIndex(0).setEndColumnIndex(2) + .setStartRowIndex(0).setEndRowIndex(1)) + .setPasteType("PASTE_VALUES"); + + List requests = new ArrayList<>(); + + requests.add(new Request().setCopyPaste(copyRequest)); + requests.add(new Request().setUpdateSpreadsheetProperties(updateRequest)); + + BatchUpdateSpreadsheetRequest body = + new BatchUpdateSpreadsheetRequest().setRequests(requests); + + sheetsService.spreadsheets().batchUpdate(SPREADSHEET_ID, body).execute(); + } + + @Test + public void whenCreateSpreadSheet_thenIdOk() throws IOException { + Spreadsheet spreadSheet = new Spreadsheet() + .setProperties(new SpreadsheetProperties().setTitle("My Spreadsheet")); + Spreadsheet result = sheetsService.spreadsheets().create(spreadSheet).execute(); + + assertThat(result.getSpreadsheetId()).isNotNull(); + } + +}