From 7769cde1c624a870e67fc619d1f3ba6f430bb010 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 1 Nov 2017 15:18:13 +0100 Subject: [PATCH 01/23] @RunWith in JUnit5 --- .../baeldung/junit5/mockito/Greetings.java | 9 +++++++++ .../test/java/com/baeldung/GreetingsTest.java | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java create mode 100644 junit5/src/test/java/com/baeldung/GreetingsTest.java diff --git a/junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java b/junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java new file mode 100644 index 0000000000..5391cbbc00 --- /dev/null +++ b/junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java @@ -0,0 +1,9 @@ +package com.baeldung.junit5.mockito; + +public class Greetings { + + public static String sayHello() { + return "Hello"; + } + +} diff --git a/junit5/src/test/java/com/baeldung/GreetingsTest.java b/junit5/src/test/java/com/baeldung/GreetingsTest.java new file mode 100644 index 0000000000..820bdf1e15 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/GreetingsTest.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; + +import com.baeldung.junit5.mockito.Greetings; + +@RunWith(JUnitPlatform.class) +public class GreetingsTest { + + @Test + void whenCallingSayHello_thenReturnHello() { + assertTrue("Hello".equals(Greetings.sayHello())); + } + +} From a77a10a42a7cff7e8d3a56157a58b3032bd0a3cb Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Thu, 2 Nov 2017 11:59:23 +0100 Subject: [PATCH 02/23] Greetings class moved to com.baeldung.junit5 package --- .../main/java/com/baeldung/junit5/{mockito => }/Greetings.java | 2 +- junit5/src/test/java/com/baeldung/GreetingsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename junit5/src/main/java/com/baeldung/junit5/{mockito => }/Greetings.java (72%) diff --git a/junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java b/junit5/src/main/java/com/baeldung/junit5/Greetings.java similarity index 72% rename from junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java rename to junit5/src/main/java/com/baeldung/junit5/Greetings.java index 5391cbbc00..f43269f646 100644 --- a/junit5/src/main/java/com/baeldung/junit5/mockito/Greetings.java +++ b/junit5/src/main/java/com/baeldung/junit5/Greetings.java @@ -1,4 +1,4 @@ -package com.baeldung.junit5.mockito; +package com.baeldung.junit5; public class Greetings { diff --git a/junit5/src/test/java/com/baeldung/GreetingsTest.java b/junit5/src/test/java/com/baeldung/GreetingsTest.java index 820bdf1e15..e894d5857c 100644 --- a/junit5/src/test/java/com/baeldung/GreetingsTest.java +++ b/junit5/src/test/java/com/baeldung/GreetingsTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import com.baeldung.junit5.mockito.Greetings; +import com.baeldung.junit5.Greetings; @RunWith(JUnitPlatform.class) public class GreetingsTest { From bc899ef38ff54dcdbc60cc9e5ec1e7bb80c31a7b Mon Sep 17 00:00:00 2001 From: Sergey Petunin Date: Sat, 4 Nov 2017 11:50:01 +0100 Subject: [PATCH 03/23] BAEL-1221: Added README.md with build and run instructions (#2947) * BAEL-1221: Added README.md with build and run instructions * BAEL-1281: Hibernate - Mapping Date/Time values (java.util and java.time) --- guest/spring-mvc/README.md | 17 ++ .../com/baeldung/hibernate/HibernateUtil.java | 2 + .../hibernate/pojo/TemporalValues.java | 195 ++++++++++++++++++ .../hibernate/TemporalValuesTest.java | 126 +++++++++++ 4 files changed, 340 insertions(+) create mode 100644 guest/spring-mvc/README.md create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java create mode 100644 hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesTest.java diff --git a/guest/spring-mvc/README.md b/guest/spring-mvc/README.md new file mode 100644 index 0000000000..9e5cd64a04 --- /dev/null +++ b/guest/spring-mvc/README.md @@ -0,0 +1,17 @@ +## Building + +To build the module, use Maven's `package` goal: + +``` +mvn clean package +``` + +## Running + +To run the application, use Spring Boot's `run` goal: + +``` +mvn spring-boot:run +``` + +The application will be accessible at [http://localhost:8080/](http://localhost:8080/) diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java index 91392bd454..0282673218 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -3,6 +3,7 @@ package com.baeldung.hibernate; import com.baeldung.hibernate.pojo.Employee; import com.baeldung.hibernate.pojo.EntityDescription; import com.baeldung.hibernate.pojo.Phone; +import com.baeldung.hibernate.pojo.TemporalValues; import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; @@ -31,6 +32,7 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(Employee.class); metadataSources.addAnnotatedClass(Phone.class); metadataSources.addAnnotatedClass(EntityDescription.class); + metadataSources.addAnnotatedClass(TemporalValues.class); Metadata metadata = metadataSources.buildMetadata(); return metadata.getSessionFactoryBuilder() diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java new file mode 100644 index 0000000000..f3fe095cae --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java @@ -0,0 +1,195 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.*; +import java.util.Calendar; + +@Entity +public class TemporalValues implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Basic + private java.sql.Date sqlDate; + + @Basic + private java.sql.Time sqlTime; + + @Basic + private java.sql.Timestamp sqlTimestamp; + + @Basic + @Temporal(TemporalType.DATE) + private java.util.Date utilDate; + + @Basic + @Temporal(TemporalType.TIME) + private java.util.Date utilTime; + + @Basic + @Temporal(TemporalType.TIMESTAMP) + private java.util.Date utilTimestamp; + + @Basic + @Temporal(TemporalType.DATE) + private java.util.Calendar calendarDate; + + @Basic + @Temporal(TemporalType.TIMESTAMP) + private java.util.Calendar calendarTimestamp; + + @Basic + private java.time.LocalDate localDate; + + @Basic + private java.time.LocalTime localTime; + + @Basic + private java.time.OffsetTime offsetTime; + + @Basic + private java.time.Instant instant; + + @Basic + private java.time.LocalDateTime localDateTime; + + @Basic + private java.time.OffsetDateTime offsetDateTime; + + @Basic + private java.time.ZonedDateTime zonedDateTime; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Date getSqlDate() { + return sqlDate; + } + + public void setSqlDate(Date sqlDate) { + this.sqlDate = sqlDate; + } + + public Time getSqlTime() { + return sqlTime; + } + + public void setSqlTime(Time sqlTime) { + this.sqlTime = sqlTime; + } + + public Timestamp getSqlTimestamp() { + return sqlTimestamp; + } + + public void setSqlTimestamp(Timestamp sqlTimestamp) { + this.sqlTimestamp = sqlTimestamp; + } + + public java.util.Date getUtilDate() { + return utilDate; + } + + public void setUtilDate(java.util.Date utilDate) { + this.utilDate = utilDate; + } + + public java.util.Date getUtilTime() { + return utilTime; + } + + public void setUtilTime(java.util.Date utilTime) { + this.utilTime = utilTime; + } + + public java.util.Date getUtilTimestamp() { + return utilTimestamp; + } + + public void setUtilTimestamp(java.util.Date utilTimestamp) { + this.utilTimestamp = utilTimestamp; + } + + public Calendar getCalendarDate() { + return calendarDate; + } + + public void setCalendarDate(Calendar calendarDate) { + this.calendarDate = calendarDate; + } + + public Calendar getCalendarTimestamp() { + return calendarTimestamp; + } + + public void setCalendarTimestamp(Calendar calendarTimestamp) { + this.calendarTimestamp = calendarTimestamp; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public void setLocalDate(LocalDate localDate) { + this.localDate = localDate; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public void setLocalTime(LocalTime localTime) { + this.localTime = localTime; + } + + public OffsetTime getOffsetTime() { + return offsetTime; + } + + public void setOffsetTime(OffsetTime offsetTime) { + this.offsetTime = offsetTime; + } + + public Instant getInstant() { + return instant; + } + + public void setInstant(Instant instant) { + this.instant = instant; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public OffsetDateTime getOffsetDateTime() { + return offsetDateTime; + } + + public void setOffsetDateTime(OffsetDateTime offsetDateTime) { + this.offsetDateTime = offsetDateTime; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(ZonedDateTime zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } +} diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesTest.java new file mode 100644 index 0000000000..ec8afc8db2 --- /dev/null +++ b/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesTest.java @@ -0,0 +1,126 @@ +package com.baeldung.hibernate; + +import com.baeldung.hibernate.pojo.TemporalValues; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.*; +import java.util.Calendar; +import java.util.TimeZone; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TemporalValuesTest { + + private Session session; + + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory().withOptions() + .jdbcTimeZone(TimeZone.getTimeZone("UTC")) + .openSession(); + transaction = session.beginTransaction(); + session.createNativeQuery("delete from temporalvalues").executeUpdate(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenEntity_whenMappingSqlTypes_thenTemporalIsSelectedAutomatically() { + TemporalValues temporalValues = new TemporalValues(); + temporalValues.setSqlDate(java.sql.Date.valueOf("2017-11-15")); + temporalValues.setSqlTime(java.sql.Time.valueOf("15:30:14")); + temporalValues.setSqlTimestamp(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getSqlDate()).isEqualTo(java.sql.Date.valueOf("2017-11-15")); + assertThat(temporalValues.getSqlTime()).isEqualTo(java.sql.Time.valueOf("15:30:14")); + assertThat(temporalValues.getSqlTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + } + + @Test + public void givenEntity_whenMappingUtilDateType_thenTemporalIsSpecifiedExplicitly() throws Exception { + TemporalValues temporalValues = new TemporalValues(); + temporalValues.setUtilDate(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + temporalValues.setUtilTime(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); + temporalValues.setUtilTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.332")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getUtilDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + assertThat(temporalValues.getUtilTime()).isEqualTo(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); + assertThat(temporalValues.getUtilTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + } + + @Test + public void givenEntity_whenMappingCalendarType_thenTemporalIsSpecifiedExplicitly() throws Exception { + TemporalValues temporalValues = new TemporalValues(); + + Calendar calendarDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendarDate.set(Calendar.YEAR, 2017); + calendarDate.set(Calendar.MONTH, 10); + calendarDate.set(Calendar.DAY_OF_MONTH, 15); + temporalValues.setCalendarDate(calendarDate); + + Calendar calendarTimestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendarTimestamp.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); + temporalValues.setCalendarTimestamp(calendarTimestamp); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getCalendarDate().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + assertThat(temporalValues.getCalendarTimestamp().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); + + } + + @Test + public void givenEntity_whenMappingJavaTimeTypes_thenTemporalIsSelectedAutomatically() { + TemporalValues temporalValues = new TemporalValues(); + + temporalValues.setLocalDate(LocalDate.parse("2017-11-15")); + temporalValues.setLocalTime(LocalTime.parse("15:30:18")); + temporalValues.setOffsetTime(OffsetTime.parse("08:22:12+01:00")); + temporalValues.setInstant(Instant.parse("2017-11-15T08:22:12Z")); + temporalValues.setLocalDateTime(LocalDateTime.parse("2017-11-15T08:22:12")); + temporalValues.setOffsetDateTime(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); + temporalValues.setZonedDateTime(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getLocalDate()).isEqualTo(LocalDate.parse("2017-11-15")); + assertThat(temporalValues.getLocalTime()).isEqualTo(LocalTime.parse("15:30:18")); + assertThat(temporalValues.getOffsetTime()).isEqualTo(OffsetTime.parse("08:22:12+01:00")); + assertThat(temporalValues.getInstant()).isEqualTo(Instant.parse("2017-11-15T08:22:12Z")); + assertThat(temporalValues.getLocalDateTime()).isEqualTo(LocalDateTime.parse("2017-11-15T08:22:12")); + assertThat(temporalValues.getOffsetDateTime()).isEqualTo(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); + assertThat(temporalValues.getZonedDateTime()).isEqualTo(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); + + } + +} From a3e241236b7f1f78c4c6b42509ec9da3b75f5116 Mon Sep 17 00:00:00 2001 From: Marcos Date: Sat, 4 Nov 2017 13:15:54 +0100 Subject: [PATCH 04/23] spring tests with JUnit 5 and ExtendWith --- junit5/pom.xml | 12 +++++++++++ .../junit5/spring/GreetingsSpringTest.java | 21 +++++++++++++++++++ .../spring/SpringTestConfiguration.java | 8 +++++++ 3 files changed, 41 insertions(+) create mode 100644 junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java create mode 100644 junit5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java diff --git a/junit5/pom.xml b/junit5/pom.xml index b820d7b7bc..b8a7622b3d 100644 --- a/junit5/pom.xml +++ b/junit5/pom.xml @@ -29,6 +29,7 @@ 3.6.0 2.19.1 4.12 + 5.0.1.RELEASE @@ -111,6 +112,17 @@ ${junit4.version} test + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework + spring-context + ${spring.version} + diff --git a/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java b/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java new file mode 100644 index 0000000000..d0045f0e5b --- /dev/null +++ b/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java @@ -0,0 +1,21 @@ +package com.baeldung.junit5.spring; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.baeldung.junit5.mockito.Greetings; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { SpringTestConfiguration.class }) +public class GreetingsSpringTest { + + @Test + void whenCallingSayHello_thenReturnHello() { + assertTrue("Hello".equals(Greetings.sayHello())); + } + +} diff --git a/junit5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java b/junit5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java new file mode 100644 index 0000000000..7651b2bd41 --- /dev/null +++ b/junit5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java @@ -0,0 +1,8 @@ +package com.baeldung.junit5.spring; + +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SpringTestConfiguration { + +} From efe0655cde1cb3d11602722df5753150d5e3594f Mon Sep 17 00:00:00 2001 From: Marcos Date: Sat, 4 Nov 2017 13:40:08 +0100 Subject: [PATCH 05/23] organize imports --- .../java/com/baeldung/junit5/spring/GreetingsSpringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java b/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java index d0045f0e5b..e7a8a1c1e7 100644 --- a/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java +++ b/junit5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import com.baeldung.junit5.mockito.Greetings; +import com.baeldung.junit5.Greetings; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SpringTestConfiguration.class }) From b32cd7a635d0668fedaf7a204d635880b9565d8c Mon Sep 17 00:00:00 2001 From: Yasin Bhojawala Date: Sat, 4 Nov 2017 18:12:45 +0530 Subject: [PATCH 06/23] Add example for implicit conversion in controller methods --- .../StringToEmployeeConverterController.java | 16 +++++++++ ...ringToEmployeeConverterControllerTest.java | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java create mode 100644 spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java diff --git a/spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java b/spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java new file mode 100644 index 0000000000..edd56dc136 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java @@ -0,0 +1,16 @@ +package org.baeldung.converter.controller; + +import com.baeldung.toggle.Employee; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/string-to-employee") +public class StringToEmployeeConverterController { + + @GetMapping + public ResponseEntity getStringToEmployee(@RequestParam("employee") Employee employee) { + return ResponseEntity.ok(employee); + } +} diff --git a/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java b/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java new file mode 100644 index 0000000000..a5ed7998b4 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java @@ -0,0 +1,34 @@ +package org.baeldung.converter.controller; + +import org.baeldung.Application; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class) +@AutoConfigureMockMvc +public class StringToEmployeeConverterControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void getStringToEmployeeTest() throws Exception { + mockMvc.perform(get("/string-to-employee?employee=1,2000")) + .andDo(print()) + .andExpect(jsonPath("$.id", is(1))) + .andExpect(jsonPath("$.salary", is(2000.0))) + .andExpect(status().isOk()); + } +} From 8e04a06bc916c1904c090a84e0918e3976f042bf Mon Sep 17 00:00:00 2001 From: lor6 Date: Sat, 4 Nov 2017 15:43:29 +0200 Subject: [PATCH 07/23] activiti with spring security example (#2909) --- spring-activiti/pom.xml | 9 +- .../java/com/baeldung/activiti/security.rar | Bin 0 -> 3760 bytes .../activiti/security/config/MvcConfig.java | 20 +++ .../security/config/ProcessController.java | 54 +++++++ .../config/SpringSecurityGroupManager.java | 86 +++++++++++ .../config/SpringSecurityUserManager.java | 144 ++++++++++++++++++ .../security/withactiviti/SecurityConfig.java | 47 ++++++ .../SpringSecurityActivitiApplication.java | 34 +++++ .../ActivitiSpringSecurityApplication.java | 39 +++++ .../security/withspring/SecurityConfig.java | 50 ++++++ spring-activiti/src/main/resources/data.sql | 3 + .../processes/protected-process.bpmn20.xml | 41 +++++ spring-activiti/src/main/resources/schema.sql | 3 + .../src/main/resources/templates/login.html | 21 +++ ...ActivitiSpringSecurityIntegrationTest.java | 31 ++++ 15 files changed, 581 insertions(+), 1 deletion(-) create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security.rar create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/config/MvcConfig.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/config/ProcessController.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityGroupManager.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityUserManager.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SecurityConfig.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SpringSecurityActivitiApplication.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/ActivitiSpringSecurityApplication.java create mode 100644 spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/SecurityConfig.java create mode 100644 spring-activiti/src/main/resources/data.sql create mode 100644 spring-activiti/src/main/resources/processes/protected-process.bpmn20.xml create mode 100644 spring-activiti/src/main/resources/schema.sql create mode 100644 spring-activiti/src/main/resources/templates/login.html create mode 100644 spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiSpringSecurityIntegrationTest.java diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index c5289b20a6..f6f992b7c0 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -19,9 +19,11 @@ + com.example.activitiwithspring.ActivitiWithSpringApplication UTF-8 UTF-8 1.8 + 6.0.0 @@ -30,9 +32,14 @@ activiti-spring-boot-starter-basic 6.0.0 + + org.activiti + activiti-spring-boot-starter-security + ${activiti.version} + org.springframework.boot - spring-boot-starter-web + spring-boot-starter-thymeleaf diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security.rar b/spring-activiti/src/main/java/com/baeldung/activiti/security.rar new file mode 100644 index 0000000000000000000000000000000000000000..38c4946168a456265f5999633bc8cb581a8360cc GIT binary patch literal 3760 zcmaLaXEdDK9tQBy38O{y=v@#!g~W(HMi54iG6thf%&5^xjuu^_cM?R68lsFEQ6{4X zQ6@UkMK9O6Ip?l*?p^EdPkZh4e)_N9^SpcOTcfyH$pF|mGynhu{9al2+_~Zm0EC19 zfHw&MKp5nA|J=RK1bkCk0>E|k2^tRbKq1_H%t0`BgeSrs@#Gl_;cEZnuVc`&XU+(i zwL1doD(-0QX${yW-;W``N!vf5$j%aQc5`l}RZuzn{suLr1nm#9K!)myzL-0D%`ti1 zY4kc^--ylq4`5M*S+TrW{Deyu;19`nA5$B4)^?_+!GS*?+L4m_Nh<&aVhe_Xd9!Tr zw_yn{v`nMJKKq+M>AsezTVP{5^nDWVr9cGQxSVu?#EyljXpaaCWvtPY%zoRghL4rK zFn$*#q9Y77@9#eDQ1~fM$zkMRd#Q;F-yMF18}b|&dve3@HvHZGA;9)l!%O|NwXGb( z=vSAUGobuUwwE&;eZ^oWjy8m|0P0+XYkVtmT3Uz}EvL7B`ZGY>Se+yc@FMpA|Gt)oZY zZlH5DvvQdHoG9yy_3>Zl)ysVDl*Ckt>y}wnyvYz zD~(}d4(eN}>Z;+j;cN%W3EbH<^33{GOY*UfoNA>=sx-MVQ^eylh127?02<7B6eJ;v zB= zvYdguYM({sU*CfA@~%`V1Lm#(B@!6sB(aS%C<#Md#dWj}tsNTln1s9k@Y<0%i(H)c$-$)g#A3tPVsLriD?xFWiKgjN zlMJkNI5PDlAHE7R^z%Q2&M0tU5LXjY0q|bsZuQUHr7h%D-)#6ZcbxwS`xT|0|<_o+Z!geB`8E0EDsySDWYp8 zjK9aWNlIC)K!80n`-#J27tfA781z&9$EMq3coKx?GYg9OLtpib@OaggwC}@e z=_=-3KdW){pwNZ#C6f(tn+PwdM~&q+zEbw8?db4q_ex?3bWS2nUa(5!@e3_ zvi35OtU9Cxl?5arbC-7d5F}*zX8S-)=lJ!}F=Gr2_fAO8LyrSn{jFr^p)D3wd(G}5 ztwY%nr^A`6`lD%CAdLEX6)auQIapY?E4rY^JZwk5as3E~3qop7>Dav0;6Tx|;eKU1 zlAJ&J?h+Hq6JeK79`-1COS}0R;w|3-&YgPdMhH*hO0N~C(aI#~q)bokC=*A!89PzV z=u{hq^e5hfzk0J(8lNmhMg|b@amilxd)QjU4Z30m0$g5&P~lHzbZ+4`{r?Uk`#+ie zUFcU?v_shc)#cYkB!Q{_F&3IDs~KdZ)MS;nP-9iE8l)Eo@)DSE%Z<%7#3l0Qoi;O0 zJe5m?s|%>Dc(>KdHB<1!FVmRq^mGg|YN;ftPqyMNL)j}mnXKq37JYVK#Fe|m8aT=$ zie@yFYV_sp_l}Do!pq7LpW66-iPF$h3c0*HkmfQ;*jMIB|Cp7A7_sc%Q_S_C9_Hf4 zzLIU}&)GD@VLjN@CYmwqZW&o#Oh14_sQM#JSsJCjzugB~RS$>e*}`}h5{@bVz~kf^ z&LzyYe(d|m@dQbd3Hrmq+y&$pU6)2~;Ze+S?rO6*V%cohM3O76SW_Y<&b|@?ghV=R zoX`ebh(bd0USw9Me_B|hs<#PI6SCvUhso7GEnfj_x?PW8@>^ub%~HWlo!ZH#0?f0r zVqT?I8bnLqw>t?l_GhHfM=jB@HRNMR#~V$?9x(UYM$x=rTj7u$Op1a`-6~N~Hum3v zcDAw{usTba+??NKvtz_kBh`v++ar|eptmAN8ravyB8X+vzL3#n-SN~O0#erc4}?y@ zJ@3St##Q!S+_s9#bWIb(`}8$lEY}##OqY$n>rgCv9NjWo9q6m-S0>NI{dtWk7NMhe ziiM8FB?W?7{MsXo*htF6>yKd-MNUWaFFF#qi!3^yvyHq#LdM^}uQ-W3#msI8eGjB%6~Lw{Utf>4IAyo`>zfUnuNMrKH!x3?z# zaW}S$UJrjnGk<7#NfsA(Kra=^u*ku~u%i>+U7a!!ozEIYwY$c$>2o%D9Ud>$FHt2; zi>{!481Y)RkEU@)~@@*+pYZGx9|M=jhP4ESS8c$E(+8*%6+B~G6AWt3sA`~#=JxBav|es>62P7 zh}H_TqXktoBQ#C7U5bj$h4r=CU_HW8$@NA*FZl2sC6zvH(R3awJx?Nyif5gP&E7^h zK!m8R&v?2h+tMSRvj}#gm4$Rvg^bNv{>U-nShM1}AT*CME?vLVlm-Ch5Dk3TjT{sb z_=4>*U)8)G%NF`3Geop&X+J6e6REfrCapsPO==`Z^4$+USd_>-wZ+;|^;raUnhs4p zr~Gv%bWDIfJhN#!a{}Tnupt>i;@7}5-DDDlatS4iaT)zI&BmOA<{Ez@S8EwbGrh7( zFL-wyytHNk`^GA-BAg{V{({E2(4g$o8IJK||Eh{_ZoRuh+ORxSVc(r{HROQ6*FIHY zU+v`)f6>b~A-jUwC3IbFHXa?E;*#2eoo1OeTT}zk7}N0|rGcMXG6(7d!AGRh1@W@2 z8je^PtpVYp@7E(i#+?@AN29t95g(VOYl-pPpngNpfW;xkXqD02M3ax0={_4T{w{_E zWqR7+^H7~-C5cKy!s%S3mbmTg7#~_bhPsxN0Tqe6<;gyMAmEL-q$J(iCM$5!s0iAM zzE^r#M{kg@$JbW2+RgSHcYZ2d=DTN`i*N3=5N>6r;Y`{xxU#Mdpd$hRC@8P2&&6~; z|9uq}{D0OB(Qwp1sBaeqCR4HeMSbN@>dz3bw<&6w&C1*HMdOb0SJV^AESF_Q>Rt&p z&B>%e)1MVgMa!F|t|M($g5@Icc>Jy6d6n(F2vrXH2M;-@JRb1b6J{0!P`rmz5QjCgdd)EGr-*kBI-5JQH55| z5u{Jb#FQl*z=!<6p?eZTq3uAT&FH!$BR3FFm3exGu1ZU^Y-?Rkc=J-XDEM`c@m^>C z=VIK~8!TljY_2HX!?(qXn^z5-o}n6)9?4x!IK6zUHd>}(7T&Ih zkGQB3z}$|WMH}OY22^tIFw+2iu%Q{5lDO4P87`Z~eDrAXk;|Wp4v!6f4;BJxGLWrf> zGe+%{C>6`iMrS^Xh1eCb$6*lr4v7wbVRmPa&=IE11e70=Gd~eyX2t zpt>wF(Cp4AlUk~7qP>G4ptJj2oY>WS;P<-vp8x=4RmNb3+vEV+tNq{aOu#nLSMN?m JUw{%B;9rQ$_E`V` literal 0 HcmV?d00001 diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/config/MvcConfig.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/MvcConfig.java new file mode 100644 index 0000000000..f9394742cd --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/MvcConfig.java @@ -0,0 +1,20 @@ +package com.baeldung.activiti.security.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +public class MvcConfig extends WebMvcConfigurerAdapter { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login") + .setViewName("login"); + registry.addViewController("/homepage") + .setViewName("homepage"); + } + +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/config/ProcessController.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/ProcessController.java new file mode 100644 index 0000000000..671b246328 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/ProcessController.java @@ -0,0 +1,54 @@ +package com.baeldung.activiti.security.config; + +import java.util.List; + +import org.activiti.engine.IdentityService; +import org.activiti.engine.RuntimeService; +import org.activiti.engine.TaskService; +import org.activiti.engine.runtime.ProcessInstance; +import org.activiti.engine.task.Task; +import org.activiti.spring.SpringProcessEngineConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ProcessController { + + @Autowired + private RuntimeService runtimeService; + + @Autowired + private TaskService taskService; + + @Autowired + private IdentityService identityService; + + @Autowired + SpringProcessEngineConfiguration config; + + @GetMapping("/protected-process") + public String startProcess() { + + String userId = SecurityContextHolder.getContext() + .getAuthentication() + .getName(); + + identityService.setAuthenticatedUserId(userId); + + ProcessInstance pi = runtimeService.startProcessInstanceByKey("protected-process"); + + List usertasks = taskService.createTaskQuery() + .processInstanceId(pi.getId()) + .list(); + + taskService.complete(usertasks.iterator() + .next() + .getId()); + + return "Process started. Number of currently running process instances = " + runtimeService.createProcessInstanceQuery() + .count(); + } + +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityGroupManager.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityGroupManager.java new file mode 100644 index 0000000000..00fc674e22 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityGroupManager.java @@ -0,0 +1,86 @@ +package com.baeldung.activiti.security.config; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.activiti.engine.identity.Group; +import org.activiti.engine.identity.GroupQuery; +import org.activiti.engine.impl.GroupQueryImpl; +import org.activiti.engine.impl.Page; +import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl; +import org.activiti.engine.impl.persistence.entity.GroupEntityImpl; +import org.activiti.engine.impl.persistence.entity.GroupEntityManagerImpl; +import org.activiti.engine.impl.persistence.entity.data.GroupDataManager; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.JdbcUserDetailsManager; + +public class SpringSecurityGroupManager extends GroupEntityManagerImpl { + + private JdbcUserDetailsManager userManager; + + public SpringSecurityGroupManager(ProcessEngineConfigurationImpl processEngineConfiguration, GroupDataManager groupDataManager) { + super(processEngineConfiguration, groupDataManager); + } + + @Override + public List findGroupByQueryCriteria(GroupQueryImpl query, Page page) { + + if (query.getUserId() != null) { + return findGroupsByUser(query.getUserId()); + } + return null; + } + + @Override + public long findGroupCountByQueryCriteria(GroupQueryImpl query) { + return findGroupByQueryCriteria(query, null).size(); + } + + @Override + public List findGroupsByUser(String userId) { + UserDetails userDetails = userManager.loadUserByUsername(userId); + System.out.println("group manager"); + if (userDetails != null) { + List groups = userDetails.getAuthorities() + .stream() + .map(a -> a.getAuthority()) + .map(a -> { + Group g = new GroupEntityImpl(); + g.setId(a); + return g; + }) + .collect(Collectors.toList()); + return groups; + } + return null; + } + + public void setUserManager(JdbcUserDetailsManager userManager) { + this.userManager = userManager; + } + + public Group createNewGroup(String groupId) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + + @Override + public void delete(String groupId) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + + public GroupQuery createNewGroupQuery() { + throw new UnsupportedOperationException("This operation is not supported!"); + } + + public List findGroupsByNativeQuery(Map parameterMap, int firstResult, int maxResults) { + throw new UnsupportedOperationException("This operation is not supported!"); + } + + public long findGroupCountByNativeQuery(Map parameterMap) { + throw new UnsupportedOperationException("This operation is not supported!"); + } + +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityUserManager.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityUserManager.java new file mode 100644 index 0000000000..ce9863eb6c --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/config/SpringSecurityUserManager.java @@ -0,0 +1,144 @@ +package com.baeldung.activiti.security.config; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.activiti.engine.identity.Group; +import org.activiti.engine.identity.User; +import org.activiti.engine.identity.UserQuery; +import org.activiti.engine.impl.Page; +import org.activiti.engine.impl.UserQueryImpl; +import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl; +import org.activiti.engine.impl.persistence.entity.GroupEntityImpl; +import org.activiti.engine.impl.persistence.entity.UserEntity; +import org.activiti.engine.impl.persistence.entity.UserEntityImpl; +import org.activiti.engine.impl.persistence.entity.UserEntityManagerImpl; +import org.activiti.engine.impl.persistence.entity.data.UserDataManager; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.JdbcUserDetailsManager; + +public class SpringSecurityUserManager extends UserEntityManagerImpl { + + private JdbcUserDetailsManager userManager; + + public SpringSecurityUserManager(ProcessEngineConfigurationImpl processEngineConfiguration, UserDataManager userDataManager, JdbcUserDetailsManager userManager) { + super(processEngineConfiguration, userDataManager); + this.userManager = userManager; + } + + @Override + public UserEntity findById(String userId) { + UserDetails userDetails = userManager.loadUserByUsername(userId); + if (userDetails != null) { + UserEntityImpl user = new UserEntityImpl(); + user.setId(userId); + return user; + } + return null; + + } + + @Override + public List findUserByQueryCriteria(UserQueryImpl query, Page page) { + List users = null; + if (query.getGroupId() != null) { + users = userManager.findUsersInGroup(query.getGroupId()) + .stream() + .map(username -> { + User user = new UserEntityImpl(); + user.setId(username); + return user; + }) + .collect(Collectors.toList()); + if (page != null) { + return users.subList(page.getFirstResult(), page.getFirstResult() + page.getMaxResults()); + + } + return users; + } + + if (query.getId() != null) { + UserDetails userDetails = userManager.loadUserByUsername(query.getId()); + if (userDetails != null) { + UserEntityImpl user = new UserEntityImpl(); + user.setId(query.getId()); + return Collections.singletonList(user); + } + } + return null; + } + + @Override + public Boolean checkPassword(String userId, String password) { + return true; + } + + public void setUserManager(JdbcUserDetailsManager userManager) { + this.userManager = userManager; + } + + public User createNewUser(String userId) { + throw new UnsupportedOperationException("This operation is not supported!"); + } + + public void updateUser(User updatedUser) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + + public void delete(UserEntity userEntity) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + + @Override + public void deletePicture(User user) { + UserEntity userEntity = (UserEntity) user; + if (userEntity.getPictureByteArrayRef() != null) { + userEntity.getPictureByteArrayRef() + .delete(); + } + } + + public void delete(String userId) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + + public long findUserCountByQueryCriteria(UserQueryImpl query) { + return findUserByQueryCriteria(query, null).size(); + } + + public List findGroupsByUser(String userId) { + UserDetails userDetails = userManager.loadUserByUsername(userId); + if (userDetails != null) { + List groups = userDetails.getAuthorities() + .stream() + .map(a -> a.getAuthority()) + .map(a -> { + Group g = new GroupEntityImpl(); + g.setId(a); + return g; + }) + .collect(Collectors.toList()); + return groups; + } + return null; + } + + public UserQuery createNewUserQuery() { + throw new UnsupportedOperationException("This operation is not supported!"); + } + + public List findUsersByNativeQuery(Map parameterMap, int firstResult, int maxResults) { + throw new UnsupportedOperationException("This operation is not supported!"); + } + + public long findUserCountByNativeQuery(Map parameterMap) { + throw new UnsupportedOperationException("This operation is not supported!"); + + } + +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SecurityConfig.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SecurityConfig.java new file mode 100644 index 0000000000..f471600553 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SecurityConfig.java @@ -0,0 +1,47 @@ +package com.baeldung.activiti.security.withactiviti; + +import org.activiti.engine.IdentityService; +import org.activiti.spring.security.IdentityServiceUserDetailsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + protected void configure(HttpSecurity http) throws Exception { + http.antMatcher("/**") + .authorizeRequests() + .antMatchers("/protected-process*") + .authenticated() + .anyRequest() + .permitAll() + .and() + .formLogin() + .loginPage("/login") + .defaultSuccessUrl("/homepage") + .failureUrl("/login?error=true") + .and() + .csrf() + .disable() + .logout() + .logoutSuccessUrl("/login"); + } + + @Autowired + private IdentityService identityService; + + @Bean + public IdentityServiceUserDetailsService userDetailsService() { + return new IdentityServiceUserDetailsService(identityService); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService()); + } + +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SpringSecurityActivitiApplication.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SpringSecurityActivitiApplication.java new file mode 100644 index 0000000000..2270a4d684 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/withactiviti/SpringSecurityActivitiApplication.java @@ -0,0 +1,34 @@ +package com.baeldung.activiti.security.withactiviti; + +import org.activiti.engine.IdentityService; +import org.activiti.engine.identity.Group; +import org.activiti.engine.identity.User; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication(scanBasePackages = { "com.baeldung.activiti.security.config", "com.baeldung.activiti.security.withactiviti" }) +public class SpringSecurityActivitiApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSecurityActivitiApplication.class, args); + } + + @Bean + InitializingBean usersAndGroupsInitializer(IdentityService identityService) { + return new InitializingBean() { + public void afterPropertiesSet() throws Exception { + User user = identityService.newUser("activiti_user"); + user.setPassword("pass"); + identityService.saveUser(user); + + Group group = identityService.newGroup("user"); + group.setName("ROLE_USER"); + group.setType("USER"); + identityService.saveGroup(group); + identityService.createMembership(user.getId(), group.getId()); + } + }; + } +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/ActivitiSpringSecurityApplication.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/ActivitiSpringSecurityApplication.java new file mode 100644 index 0000000000..5878a5d678 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/ActivitiSpringSecurityApplication.java @@ -0,0 +1,39 @@ +package com.baeldung.activiti.security.withspring; + +import org.activiti.engine.impl.persistence.entity.data.impl.MybatisGroupDataManager; +import org.activiti.engine.impl.persistence.entity.data.impl.MybatisUserDataManager; +import org.activiti.spring.SpringProcessEngineConfiguration; +import org.activiti.spring.boot.SecurityAutoConfiguration; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.provisioning.JdbcUserDetailsManager; + +import com.baeldung.activiti.security.config.SpringSecurityGroupManager; +import com.baeldung.activiti.security.config.SpringSecurityUserManager; + +@SpringBootApplication(exclude = SecurityAutoConfiguration.class, scanBasePackages = { "com.baeldung.activiti.security.config", "com.baeldung.activiti.security.withspring" }) +public class ActivitiSpringSecurityApplication { + + public static void main(String[] args) { + SpringApplication.run(ActivitiSpringSecurityApplication.class, args); + } + + @Autowired + private SpringProcessEngineConfiguration processEngineConfiguration; + + @Autowired + private JdbcUserDetailsManager userManager; + + @Bean + InitializingBean processEngineInitializer() { + return new InitializingBean() { + public void afterPropertiesSet() throws Exception { + processEngineConfiguration.setUserEntityManager(new SpringSecurityUserManager(processEngineConfiguration, new MybatisUserDataManager(processEngineConfiguration), userManager)); + processEngineConfiguration.setGroupEntityManager(new SpringSecurityGroupManager(processEngineConfiguration, new MybatisGroupDataManager(processEngineConfiguration))); + } + }; + } +} diff --git a/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/SecurityConfig.java b/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/SecurityConfig.java new file mode 100644 index 0000000000..df1991c3e4 --- /dev/null +++ b/spring-activiti/src/main/java/com/baeldung/activiti/security/withspring/SecurityConfig.java @@ -0,0 +1,50 @@ +package com.baeldung.activiti.security.withspring; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.provisioning.JdbcUserDetailsManager; + +@Configuration +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private DataSource dataSource; + + protected void configure(HttpSecurity http) throws Exception { + http.antMatcher("/**") + .authorizeRequests() + .antMatchers("/protected-process*") + .authenticated() + .anyRequest() + .permitAll() + .and() + .formLogin() + .loginPage("/login") + .defaultSuccessUrl("/homepage") + .failureUrl("/login?error=true") + .and() + .csrf() + .disable() + .logout() + .logoutSuccessUrl("/login"); + } + + @Bean + public JdbcUserDetailsManager userDetailsManager() { + JdbcUserDetailsManager manager = new JdbcUserDetailsManager(); + manager.setDataSource(dataSource); + return manager; + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsManager()); + } + +} diff --git a/spring-activiti/src/main/resources/data.sql b/spring-activiti/src/main/resources/data.sql new file mode 100644 index 0000000000..cb9b72617a --- /dev/null +++ b/spring-activiti/src/main/resources/data.sql @@ -0,0 +1,3 @@ +insert into users(username, password, enabled) values ('spring_user', 'pass', true); + +insert into authorities(username, authority) values ('spring_user','ROLE_USER'); \ No newline at end of file diff --git a/spring-activiti/src/main/resources/processes/protected-process.bpmn20.xml b/spring-activiti/src/main/resources/processes/protected-process.bpmn20.xml new file mode 100644 index 0000000000..b7e04515cd --- /dev/null +++ b/spring-activiti/src/main/resources/processes/protected-process.bpmn20.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + ROLE_USER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-activiti/src/main/resources/schema.sql b/spring-activiti/src/main/resources/schema.sql new file mode 100644 index 0000000000..bf882895fd --- /dev/null +++ b/spring-activiti/src/main/resources/schema.sql @@ -0,0 +1,3 @@ +create table users(username varchar(255), password varchar(255), enabled boolean); + +create table authorities(username varchar(255),authority varchar(255)); \ No newline at end of file diff --git a/spring-activiti/src/main/resources/templates/login.html b/spring-activiti/src/main/resources/templates/login.html new file mode 100644 index 0000000000..53077fd5f3 --- /dev/null +++ b/spring-activiti/src/main/resources/templates/login.html @@ -0,0 +1,21 @@ + + + +

Login

+
+ + + + + + + + + + + + +
User:
Password:
+
+ + \ No newline at end of file diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiSpringSecurityIntegrationTest.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiSpringSecurityIntegrationTest.java new file mode 100644 index 0000000000..c2eeb96555 --- /dev/null +++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiSpringSecurityIntegrationTest.java @@ -0,0 +1,31 @@ +package com.example.activitiwithspring; + +import org.activiti.engine.IdentityService; +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.security.core.userdetails.UsernameNotFoundException; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import com.baeldung.activiti.security.withspring.ActivitiSpringSecurityApplication; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ActivitiSpringSecurityApplication.class) +@WebAppConfiguration +public class ActivitiSpringSecurityIntegrationTest { + @Autowired + private IdentityService identityService; + + @Test + public void whenUserExists_thenOk() { + identityService.setUserPicture("spring_user", null); + } + + @Test(expected = UsernameNotFoundException.class) + public void whenUserNonExistent_thenSpringException() { + identityService.setUserPicture("user3", null); + } + +} From b4c327ea4f91045d4ce899d53852dd3d47a9978e Mon Sep 17 00:00:00 2001 From: Marco Battaglia Date: Sat, 4 Nov 2017 14:43:56 +0100 Subject: [PATCH 08/23] Fixed error on AopConfiguration (#2946) * com. to org. * changed all 'com.baeldung ' in 'org.baeldung' in order to make AopConfiguration class able to work --- .../org/baeldung/performancemonitor/AopConfiguration.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-aop/src/main/java/org/baeldung/performancemonitor/AopConfiguration.java b/spring-aop/src/main/java/org/baeldung/performancemonitor/AopConfiguration.java index a5f36fb716..00026baf07 100644 --- a/spring-aop/src/main/java/org/baeldung/performancemonitor/AopConfiguration.java +++ b/spring-aop/src/main/java/org/baeldung/performancemonitor/AopConfiguration.java @@ -16,10 +16,10 @@ import java.time.Month; @EnableAspectJAutoProxy public class AopConfiguration { - @Pointcut("execution(public String com.baeldung.performancemonitor.PersonService.getFullName(..))") + @Pointcut("execution(public String org.baeldung.performancemonitor.PersonService.getFullName(..))") public void monitor() { } - @Pointcut("execution(public int com.baeldung.performancemonitor.PersonService.getAge(..))") + @Pointcut("execution(public int org.baeldung.performancemonitor.PersonService.getAge(..))") public void myMonitor() { } @Bean @@ -30,7 +30,7 @@ public class AopConfiguration { @Bean public Advisor performanceMonitorAdvisor() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); - pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.monitor()"); + pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.monitor()"); return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor()); } @@ -52,7 +52,7 @@ public class AopConfiguration { @Bean public Advisor myPerformanceMonitorAdvisor() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); - pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.myMonitor()"); + pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.myMonitor()"); return new DefaultPointcutAdvisor(pointcut, myPerformanceMonitorInterceptor()); } From 1e13b57895330195daa2718c8be18ce8e2f76260 Mon Sep 17 00:00:00 2001 From: Sergey Travin Date: Sat, 4 Nov 2017 19:46:53 +0600 Subject: [PATCH 09/23] Minor fixes (#2865) * Update README.md * Fix duplicate dependency in pom.xml --- log4j/pom.xml | 6 ------ spring-jms/README.md | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/log4j/pom.xml b/log4j/pom.xml index 2e73baac49..20906c4c05 100644 --- a/log4j/pom.xml +++ b/log4j/pom.xml @@ -26,12 +26,6 @@ ${log4j.version}
- - log4j - apache-log4j-extras - ${log4j.version} - - org.apache.logging.log4j diff --git a/spring-jms/README.md b/spring-jms/README.md index 9093937f44..b942cc72a0 100644 --- a/spring-jms/README.md +++ b/spring-jms/README.md @@ -1,2 +1,2 @@ -###Relevant Articles: +### Relevant Articles: - [An Introduction To Spring JMS](http://www.baeldung.com/spring-jms) From 7a2d2c5fb0581b1b0dbe5b213a97c980c3aa1d1f Mon Sep 17 00:00:00 2001 From: Buddhini Samarakkody Date: Sat, 4 Nov 2017 19:17:25 +0530 Subject: [PATCH 10/23] More code changes for BAEL-656 (#2900) * Java Config file for LocalSessionFactoryBean * Remove test class * Remove test class * Add new test classes for BAEL-656 * remove unused spring config BAEL-656 * modification in test method * change in test method * change in test method --- .../spring/PersistenceConfigHibernate3.java | 81 +++++++++++++++++++ ...nateExceptionScen1MainIntegrationTest.java | 43 ++++++++++ ...nateExceptionScen2MainIntegrationTest.java | 45 +++++++++++ 3 files changed, 169 insertions(+) create mode 100644 spring-hibernate3/src/main/java/org/baeldung/spring/PersistenceConfigHibernate3.java create mode 100644 spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen1MainIntegrationTest.java create mode 100644 spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen2MainIntegrationTest.java diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/PersistenceConfigHibernate3.java b/spring-hibernate3/src/main/java/org/baeldung/spring/PersistenceConfigHibernate3.java new file mode 100644 index 0000000000..a128d8848c --- /dev/null +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/PersistenceConfigHibernate3.java @@ -0,0 +1,81 @@ +package org.baeldung.spring; + +import java.util.Properties; + +import javax.sql.DataSource; + +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.orm.hibernate3.HibernateTransactionManager; +import org.springframework.orm.hibernate3.LocalSessionFactoryBean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "org.baeldung.persistence.dao", "org.baeldung.persistence.service" }) +public class PersistenceConfigHibernate3 { + + @Autowired + private Environment env; + + public PersistenceConfigHibernate3() { + super(); + } + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + Resource config = new ClassPathResource("exceptionDemo.cfg.xml"); + sessionFactory.setDataSource(dataSource()); + sessionFactory.setConfigLocation(config); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource dataSource() { + final BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + @Autowired + public HibernateTransactionManager transactionManager(final SessionFactory sessionFactory) { + final HibernateTransactionManager txManager = new HibernateTransactionManager(); + txManager.setSessionFactory(sessionFactory); + + return txManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties hibernateProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); + return hibernateProperties; + } + +} diff --git a/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen1MainIntegrationTest.java b/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen1MainIntegrationTest.java new file mode 100644 index 0000000000..d53c4445a8 --- /dev/null +++ b/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen1MainIntegrationTest.java @@ -0,0 +1,43 @@ +package org.baeldung.persistence.service; + +import java.util.List; + +import org.baeldung.persistence.model.Event; +import org.baeldung.spring.PersistenceConfigHibernate3; +import org.hamcrest.core.IsInstanceOf; +import org.hibernate.HibernateException; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfigHibernate3.class }, loader = AnnotationConfigContextLoader.class) +public class HibernateExceptionScen1MainIntegrationTest { + + @Autowired + EventService service; + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public final void whenEntityIsCreated_thenNoExceptions() { + service.create(new Event("from LocalSessionFactoryBean")); + } + + @Test + @Ignore + public final void whenNoTransBoundToSession_thenException() { + expectedEx.expectCause(IsInstanceOf.instanceOf(HibernateException.class)); + expectedEx.expectMessage("No Hibernate Session bound to thread, " + + "and configuration does not allow creation " + + "of non-transactional one here"); + service.create(new Event("from LocalSessionFactoryBean")); + } +} diff --git a/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen2MainIntegrationTest.java b/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen2MainIntegrationTest.java new file mode 100644 index 0000000000..84cafe0536 --- /dev/null +++ b/spring-hibernate3/src/test/java/org/baeldung/persistence/service/HibernateExceptionScen2MainIntegrationTest.java @@ -0,0 +1,45 @@ +package org.baeldung.persistence.service; + +import java.util.List; + +import org.baeldung.persistence.model.Event; +import org.baeldung.spring.PersistenceConfig; +import org.hamcrest.core.IsInstanceOf; +import org.hibernate.HibernateException; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +public class HibernateExceptionScen2MainIntegrationTest { + + @Autowired + EventService service; + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public final void whenEntityIsCreated_thenNoExceptions() { + service.create(new Event("from AnnotationSessionFactoryBean")); + } + + @Test + @Ignore + public final void whenNoTransBoundToSession_thenException() { + expectedEx.expectCause(IsInstanceOf.instanceOf(HibernateException.class)); + expectedEx.expectMessage("No Hibernate Session bound to thread, " + + "and configuration does not allow creation " + + "of non-transactional one here"); + service.create(new Event("from AnnotationSessionFactoryBean")); + } + +} From b6f0ab774cd359d4bd947746e7539b6180634af1 Mon Sep 17 00:00:00 2001 From: Sergey Petunin Date: Sat, 4 Nov 2017 16:26:12 +0100 Subject: [PATCH 11/23] BAEL-1281: Hibernate - Mapping Date/Time values (java.util and java.time) (#2951) From 666206ce050c3f8a6f911b69eaaa69613f2e6860 Mon Sep 17 00:00:00 2001 From: Bogdan Stoean <4540392+BogdanStoean@users.noreply.github.com> Date: Sat, 4 Nov 2017 17:38:32 +0200 Subject: [PATCH 12/23] hipchat configuration (#2959) --- spring-boot-admin/pom.xml | 13 +++++++++++++ spring-boot-admin/spring-boot-admin-client/pom.xml | 4 ++-- spring-boot-admin/spring-boot-admin-server/pom.xml | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spring-boot-admin/pom.xml b/spring-boot-admin/pom.xml index 918eeaabeb..9c1eeeabff 100644 --- a/spring-boot-admin/pom.xml +++ b/spring-boot-admin/pom.xml @@ -13,6 +13,7 @@ UTF-8 + 1.5.8.RELEASE @@ -20,4 +21,16 @@ spring-boot-admin-client + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + \ No newline at end of file diff --git a/spring-boot-admin/spring-boot-admin-client/pom.xml b/spring-boot-admin/spring-boot-admin-client/pom.xml index accedca5cb..d119450e0b 100644 --- a/spring-boot-admin/spring-boot-admin-client/pom.xml +++ b/spring-boot-admin/spring-boot-admin-client/pom.xml @@ -11,10 +11,10 @@ Spring Boot Admin Client - parent-boot-5 + spring-boot-admin com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../spring-boot-admin diff --git a/spring-boot-admin/spring-boot-admin-server/pom.xml b/spring-boot-admin/spring-boot-admin-server/pom.xml index 4922d56878..f28b7a3dc9 100644 --- a/spring-boot-admin/spring-boot-admin-server/pom.xml +++ b/spring-boot-admin/spring-boot-admin-server/pom.xml @@ -11,10 +11,10 @@ Spring Boot Admin Server - parent-boot-5 + spring-boot-admin com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../spring-boot-admin From a9bea07bd5f4f273efe338afa28a7ea658422028 Mon Sep 17 00:00:00 2001 From: Tim Schimandle Date: Sat, 4 Nov 2017 09:46:20 -0600 Subject: [PATCH 13/23] BAEL-1176 Spring Cloud Connector Heroku (#2911) * BAEL-1176 setting up base application with in memory database * BAEL-1176 adding postgres stuff --- spring-cloud/pom.xml | 1 + .../spring-cloud-connectors-heroku/pom.xml | 100 ++++++++++++++++++ .../heroku/ConnectorsHerokuApplication.java | 12 +++ .../connectors/heroku/product/Product.java | 30 ++++++ .../heroku/product/ProductController.java | 26 +++++ .../heroku/product/ProductRepository.java | 6 ++ .../heroku/product/ProductService.java | 28 +++++ .../src/main/resources/application.properties | 8 ++ 8 files changed, 211 insertions(+) create mode 100644 spring-cloud/spring-cloud-connectors-heroku/pom.xml create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/ConnectorsHerokuApplication.java create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/Product.java create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductRepository.java create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java create mode 100644 spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 44e72535f8..93bf6ea74b 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -16,6 +16,7 @@ spring-cloud-rest spring-cloud-zookeeper spring-cloud-gateway + spring-cloud-connectors-heroku pom diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml new file mode 100644 index 0000000000..ba3f0ef28f --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + + spring-boot-starter-parent + org.springframework.boot + 1.4.4.RELEASE + + + + com.baeldung.spring.cloud + spring-cloud-connectors-heroku + 1.0.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-cloud-connectors + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-actuator + + + + org.postgresql + postgresql + 9.4-1201-jdbc4 + + + + com.h2database + h2 + runtime + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud-dependencies.version} + pom + import + + + + + + Brixton.SR7 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/ConnectorsHerokuApplication.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/ConnectorsHerokuApplication.java new file mode 100644 index 0000000000..63246e89cc --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/ConnectorsHerokuApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.cloud.connectors.heroku; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ConnectorsHerokuApplication { + + public static void main(String[] args) { + SpringApplication.run(ConnectorsHerokuApplication.class, args); + } +} diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/Product.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/Product.java new file mode 100644 index 0000000000..40e8809fc5 --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/Product.java @@ -0,0 +1,30 @@ +package com.baeldung.spring.cloud.connectors.heroku.product; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Product { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long productId; + private String sku; + + public Long getProductId() { + return productId; + } + + public void setProductId(Long productId) { + this.productId = productId; + } + + public String getSku() { + return sku; + } + + public void setSku(String sku) { + this.sku = sku; + } +} diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java new file mode 100644 index 0000000000..51cf4412bf --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java @@ -0,0 +1,26 @@ +package com.baeldung.spring.cloud.connectors.heroku.product; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/products") +public class ProductController { + + private final ProductService productService; + + @Autowired + public ProductController(ProductService productService) { + this.productService = productService; + } + + @GetMapping("/{productId}") + public Product findProduct(@PathVariable Long productId) { + return productService.findProductById(productId); + } + + @PostMapping + public Product createProduct(@RequestBody Product product) { + return productService.createProduct(product); + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductRepository.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductRepository.java new file mode 100644 index 0000000000..508e1d048b --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductRepository.java @@ -0,0 +1,6 @@ +package com.baeldung.spring.cloud.connectors.heroku.product; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ProductRepository extends JpaRepository{ +} diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java new file mode 100644 index 0000000000..f25b4ecf7b --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java @@ -0,0 +1,28 @@ +package com.baeldung.spring.cloud.connectors.heroku.product; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +public class ProductService { + private final ProductRepository productRepository; + + @Autowired + public ProductService(ProductRepository productRepository) { + this.productRepository = productRepository; + } + + public Product findProductById(Long productId) { + return productRepository.findOne(productId); + } + + @Transactional(propagation = Propagation.REQUIRED) + public Product createProduct(Product product) { + Product newProduct = new Product(); + newProduct.setSku(product.getSku()); + return productRepository.save(newProduct); + } +} diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties b/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties new file mode 100644 index 0000000000..d2f1c89dc5 --- /dev/null +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.maxActive=10 +spring.datasource.maxIdle=5 +spring.datasource.minIdle=2 +spring.datasource.initialSize=5 +spring.datasource.removeAbandoned=true + +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file From 3952b7ef591df4a9c501c45aa5b490cc87a205d7 Mon Sep 17 00:00:00 2001 From: lor6 Date: Sun, 5 Nov 2017 18:32:37 +0200 Subject: [PATCH 14/23] remove keycloak, refactor packages (#2963) --- spring-boot/pom.xml | 17 +--- .../org/baeldung/{ => boot}/Application.java | 2 +- .../baeldung/{ => boot}/client/Details.java | 2 +- .../client/DetailsServiceClient.java | 2 +- .../{ => boot}/config/H2JpaConfig.java | 6 +- .../baeldung/{ => boot}/config/WebConfig.java | 10 +-- .../controller/GenericEntityController.java | 8 +- .../controller/servlet/HelloWorldServlet.java | 86 +++++++++---------- .../servlet/SpringHelloWorldServlet.java | 86 +++++++++---------- .../converter/GenericBigDecimalConverter.java | 2 +- .../converter/StringToEmployeeConverter.java | 2 +- .../StringToEnumConverterFactory.java | 2 +- .../StringToLocalDateTimeConverter.java | 2 +- .../StringToEmployeeConverterController.java | 2 +- .../{ => boot}/domain/GenericEntity.java | 2 +- .../org/baeldung/{ => boot}/domain/Modes.java | 2 +- .../{ => boot}/jsoncomponent/User.java | 2 +- .../jsoncomponent/UserCombinedSerializer.java | 2 +- .../jsoncomponent/UserJsonDeserializer.java | 2 +- .../jsoncomponent/UserJsonSerializer.java | 2 +- .../monitor/jmx/MonitoringConfig.java | 44 +++++----- .../repository/GenericEntityRepository.java | 4 +- .../HeaderVersionArgumentResolver.java | 2 +- .../{ => boot}/web/resolver/Version.java | 2 +- .../{boot => demo}/DemoApplication.java | 2 +- .../{boot => demo}/boottest/Employee.java | 2 +- .../boottest/EmployeeRepository.java | 2 +- .../boottest/EmployeeRestController.java | 2 +- .../boottest/EmployeeService.java | 2 +- .../boottest/EmployeeServiceImpl.java | 2 +- .../{boot => demo}/components/FooService.java | 6 +- .../exceptions/CommonException.java | 2 +- .../exceptions/FooNotFoundException.java | 2 +- .../baeldung/{boot => demo}/model/Foo.java | 2 +- .../repository/FooRepository.java | 4 +- .../{boot => demo}/service/FooController.java | 6 +- .../info/TotalUsersInfoContributor.java | 2 +- .../baeldung/main/SpringBootApplication.java | 7 +- .../org/baeldung/{boot => }/model/User.java | 2 +- .../{boot => }/repository/UserRepository.java | 4 +- .../session/exception/Application.java | 2 +- .../exception/repository/FooRepository.java | 2 +- .../repository/FooRepositoryImpl.java | 2 +- .../SpringBootApplicationIntegrationTest.java | 3 +- .../baeldung/SpringBootH2IntegrationTest.java | 7 +- .../SpringBootJPAIntegrationTest.java | 5 +- .../SpringBootMailIntegrationTest.java | 1 + .../SpringBootProfileIntegrationTest.java | 5 +- .../boot/DemoApplicationIntegrationTest.java | 1 + .../DetailsServiceClientIntegrationTest.java | 5 +- .../UserJsonDeserializerIntegrationTest.java | 4 +- .../UserJsonSerializerIntegrationTest.java | 4 +- .../FooRepositoryIntegrationTest.java | 3 +- .../HibernateSessionIntegrationTest.java | 2 +- .../NoHibernateSessionIntegrationTest.java | 2 +- .../config/H2TestProfileJPAConfig.java | 2 +- .../converter/CustomConverterTest.java | 5 +- ...ringToEmployeeConverterControllerTest.java | 3 +- .../EmployeeControllerIntegrationTest.java | 5 +- .../EmployeeRepositoryIntegrationTest.java | 4 +- ...EmployeeRestControllerIntegrationTest.java | 6 +- .../EmployeeServiceImplIntegrationTest.java | 6 +- .../{boot => demo}/boottest/JsonUtil.java | 2 +- .../ConfigPropertiesIntegrationTest.java | 2 + 64 files changed, 220 insertions(+), 205 deletions(-) rename spring-boot/src/main/java/org/baeldung/{ => boot}/Application.java (95%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/client/Details.java (93%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/client/DetailsServiceClient.java (93%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/config/H2JpaConfig.java (89%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/config/WebConfig.java (74%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/controller/GenericEntityController.java (92%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/controller/servlet/HelloWorldServlet.java (93%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/controller/servlet/SpringHelloWorldServlet.java (93%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/converter/GenericBigDecimalConverter.java (97%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/converter/StringToEmployeeConverter.java (90%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/converter/StringToEnumConverterFactory.java (95%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/converter/StringToLocalDateTimeConverter.java (92%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/converter/controller/StringToEmployeeConverterController.java (90%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/domain/GenericEntity.java (95%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/domain/Modes.java (54%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/jsoncomponent/User.java (86%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/jsoncomponent/UserCombinedSerializer.java (97%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/jsoncomponent/UserJsonDeserializer.java (95%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/jsoncomponent/UserJsonSerializer.java (96%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/monitor/jmx/MonitoringConfig.java (90%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/repository/GenericEntityRepository.java (64%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/web/resolver/HeaderVersionArgumentResolver.java (96%) rename spring-boot/src/main/java/org/baeldung/{ => boot}/web/resolver/Version.java (86%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/DemoApplication.java (95%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/boottest/Employee.java (95%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/boottest/EmployeeRepository.java (91%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/boottest/EmployeeRestController.java (96%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/boottest/EmployeeService.java (89%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/boottest/EmployeeServiceImpl.java (96%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/components/FooService.java (76%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/exceptions/CommonException.java (85%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/exceptions/FooNotFoundException.java (86%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/model/Foo.java (95%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/repository/FooRepository.java (70%) rename spring-boot/src/main/java/org/baeldung/{boot => demo}/service/FooController.java (85%) rename spring-boot/src/main/java/org/baeldung/{boot => }/model/User.java (95%) rename spring-boot/src/main/java/org/baeldung/{boot => }/repository/UserRepository.java (77%) rename spring-boot/src/test/java/org/baeldung/{ => boot}/client/DetailsServiceClientIntegrationTest.java (92%) rename spring-boot/src/test/java/org/baeldung/{ => boot}/jsoncomponent/UserJsonDeserializerIntegrationTest.java (89%) rename spring-boot/src/test/java/org/baeldung/{ => boot}/jsoncomponent/UserJsonSerializerIntegrationTest.java (90%) rename spring-boot/src/test/java/org/baeldung/{boot => demo}/boottest/EmployeeControllerIntegrationTest.java (93%) rename spring-boot/src/test/java/org/baeldung/{boot => demo}/boottest/EmployeeRepositoryIntegrationTest.java (94%) rename spring-boot/src/test/java/org/baeldung/{boot => demo}/boottest/EmployeeRestControllerIntegrationTest.java (94%) rename spring-boot/src/test/java/org/baeldung/{boot => demo}/boottest/EmployeeServiceImplIntegrationTest.java (94%) rename spring-boot/src/test/java/org/baeldung/{boot => demo}/boottest/JsonUtil.java (91%) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 5e5f01013d..d6ee022522 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -24,10 +24,6 @@ org.springframework.boot spring-boot-starter-web - - org.keycloak - keycloak-spring-boot-starter - org.springframework.boot spring-boot-starter-data-jpa @@ -172,17 +168,6 @@ artemis-server
- - - - org.keycloak.bom - keycloak-adapter-bom - 3.3.0.CR2 - pom - import - - - spring-boot @@ -282,7 +267,7 @@ - org.baeldung.boot.DemoApplication + org.baeldung.demo.DemoApplication 4.3.4.RELEASE 2.2.1 3.1.1 diff --git a/spring-boot/src/main/java/org/baeldung/Application.java b/spring-boot/src/main/java/org/baeldung/boot/Application.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/Application.java rename to spring-boot/src/main/java/org/baeldung/boot/Application.java index 1c1e466afc..78e95455b8 100644 --- a/spring-boot/src/main/java/org/baeldung/Application.java +++ b/spring-boot/src/main/java/org/baeldung/boot/Application.java @@ -1,4 +1,4 @@ -package org.baeldung; +package org.baeldung.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot/src/main/java/org/baeldung/client/Details.java b/spring-boot/src/main/java/org/baeldung/boot/client/Details.java similarity index 93% rename from spring-boot/src/main/java/org/baeldung/client/Details.java rename to spring-boot/src/main/java/org/baeldung/boot/client/Details.java index 2ae3adc38f..1e3ddf7b21 100644 --- a/spring-boot/src/main/java/org/baeldung/client/Details.java +++ b/spring-boot/src/main/java/org/baeldung/boot/client/Details.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package org.baeldung.boot.client; public class Details { diff --git a/spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java b/spring-boot/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java similarity index 93% rename from spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java rename to spring-boot/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java index 51fa7c6181..f2b9d6d030 100644 --- a/spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java +++ b/spring-boot/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package org.baeldung.boot.client; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.stereotype.Service; diff --git a/spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java b/spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java similarity index 89% rename from spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java rename to spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java index 62791bf180..4e4b2e06bd 100644 --- a/spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java +++ b/spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package org.baeldung.boot.config; import java.util.Properties; @@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration -@EnableJpaRepositories(basePackages = { "org.baeldung.repository", "org.baeldung.boot.repository", "org.baeldung.boot.boottest" }) +@EnableJpaRepositories(basePackages = { "org.baeldung.boot.repository", "org.baeldung.boot.boottest","org.baeldung.repository" }) @PropertySource("classpath:persistence-generic-entity.properties") @EnableTransactionManagement public class H2JpaConfig { @@ -41,7 +41,7 @@ public class H2JpaConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest" }); + em.setPackagesToScan(new String[] { "org.baeldung.boot.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest", "org.baeldung.model" }); em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); em.setJpaProperties(additionalProperties()); return em; diff --git a/spring-boot/src/main/java/org/baeldung/config/WebConfig.java b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java similarity index 74% rename from spring-boot/src/main/java/org/baeldung/config/WebConfig.java rename to spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java index 6609791c69..caf88c3be7 100644 --- a/spring-boot/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java @@ -1,9 +1,9 @@ -package org.baeldung.config; +package org.baeldung.boot.config; -import org.baeldung.converter.GenericBigDecimalConverter; -import org.baeldung.converter.StringToEnumConverterFactory; -import org.baeldung.converter.StringToEmployeeConverter; -import org.baeldung.web.resolver.HeaderVersionArgumentResolver; +import org.baeldung.boot.converter.GenericBigDecimalConverter; +import org.baeldung.boot.converter.StringToEmployeeConverter; +import org.baeldung.boot.converter.StringToEnumConverterFactory; +import org.baeldung.boot.web.resolver.HeaderVersionArgumentResolver; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.method.support.HandlerMethodArgumentResolver; diff --git a/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java similarity index 92% rename from spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java rename to spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java index a9e7dee0b7..8b038e0335 100644 --- a/spring-boot/src/main/java/org/baeldung/controller/GenericEntityController.java +++ b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java @@ -1,8 +1,8 @@ -package org.baeldung.controller; +package org.baeldung.boot.controller; -import org.baeldung.domain.GenericEntity; -import org.baeldung.domain.Modes; -import org.baeldung.web.resolver.Version; +import org.baeldung.boot.domain.GenericEntity; +import org.baeldung.boot.domain.Modes; +import org.baeldung.boot.web.resolver.Version; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/spring-boot/src/main/java/org/baeldung/controller/servlet/HelloWorldServlet.java b/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java similarity index 93% rename from spring-boot/src/main/java/org/baeldung/controller/servlet/HelloWorldServlet.java rename to spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java index 9adaf7fd29..34ad11254c 100644 --- a/spring-boot/src/main/java/org/baeldung/controller/servlet/HelloWorldServlet.java +++ b/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java @@ -1,43 +1,43 @@ -package org.baeldung.controller.servlet; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Objects; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class HelloWorldServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - public HelloWorldServlet() { - super(); - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - PrintWriter out = null; - try { - out = response.getWriter(); - out.println("HelloWorldServlet: GET METHOD"); - out.flush(); - } finally { - if (!Objects.isNull(out)) - out.close(); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - PrintWriter out = null; - try { - out = response.getWriter(); - out.println("HelloWorldServlet: POST METHOD"); - out.flush(); - } finally { - if (!Objects.isNull(out)) - out.close(); - } - } - -} +package org.baeldung.boot.controller.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Objects; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HelloWorldServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + public HelloWorldServlet() { + super(); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = null; + try { + out = response.getWriter(); + out.println("HelloWorldServlet: GET METHOD"); + out.flush(); + } finally { + if (!Objects.isNull(out)) + out.close(); + } + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = null; + try { + out = response.getWriter(); + out.println("HelloWorldServlet: POST METHOD"); + out.flush(); + } finally { + if (!Objects.isNull(out)) + out.close(); + } + } + +} diff --git a/spring-boot/src/main/java/org/baeldung/controller/servlet/SpringHelloWorldServlet.java b/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java similarity index 93% rename from spring-boot/src/main/java/org/baeldung/controller/servlet/SpringHelloWorldServlet.java rename to spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java index 9a62bdbbf2..91547683c6 100644 --- a/spring-boot/src/main/java/org/baeldung/controller/servlet/SpringHelloWorldServlet.java +++ b/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java @@ -1,43 +1,43 @@ -package org.baeldung.controller.servlet; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Objects; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class SpringHelloWorldServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - public SpringHelloWorldServlet() { - super(); - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - PrintWriter out = null; - try { - out = response.getWriter(); - out.println("SpringHelloWorldServlet: GET METHOD"); - out.flush(); - } finally { - if (!Objects.isNull(out)) - out.close(); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - PrintWriter out = null; - try { - out = response.getWriter(); - out.println("SpringHelloWorldServlet: POST METHOD"); - out.flush(); - } finally { - if (!Objects.isNull(out)) - out.close(); - } - } - -} +package org.baeldung.boot.controller.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Objects; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class SpringHelloWorldServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + public SpringHelloWorldServlet() { + super(); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = null; + try { + out = response.getWriter(); + out.println("SpringHelloWorldServlet: GET METHOD"); + out.flush(); + } finally { + if (!Objects.isNull(out)) + out.close(); + } + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = null; + try { + out = response.getWriter(); + out.println("SpringHelloWorldServlet: POST METHOD"); + out.flush(); + } finally { + if (!Objects.isNull(out)) + out.close(); + } + } + +} diff --git a/spring-boot/src/main/java/org/baeldung/converter/GenericBigDecimalConverter.java b/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java similarity index 97% rename from spring-boot/src/main/java/org/baeldung/converter/GenericBigDecimalConverter.java rename to spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java index 1dbb7df6de..decd8ac5db 100644 --- a/spring-boot/src/main/java/org/baeldung/converter/GenericBigDecimalConverter.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java @@ -1,4 +1,4 @@ -package org.baeldung.converter; +package org.baeldung.boot.converter; import com.google.common.collect.ImmutableSet; import org.springframework.core.convert.TypeDescriptor; diff --git a/spring-boot/src/main/java/org/baeldung/converter/StringToEmployeeConverter.java b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java similarity index 90% rename from spring-boot/src/main/java/org/baeldung/converter/StringToEmployeeConverter.java rename to spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java index 5f680972b7..de9cf3f55a 100644 --- a/spring-boot/src/main/java/org/baeldung/converter/StringToEmployeeConverter.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java @@ -1,4 +1,4 @@ -package org.baeldung.converter; +package org.baeldung.boot.converter; import com.baeldung.toggle.Employee; diff --git a/spring-boot/src/main/java/org/baeldung/converter/StringToEnumConverterFactory.java b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/converter/StringToEnumConverterFactory.java rename to spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java index 17c6fd06de..6fa51bfdcc 100644 --- a/spring-boot/src/main/java/org/baeldung/converter/StringToEnumConverterFactory.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java @@ -1,4 +1,4 @@ -package org.baeldung.converter; +package org.baeldung.boot.converter; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; diff --git a/spring-boot/src/main/java/org/baeldung/converter/StringToLocalDateTimeConverter.java b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToLocalDateTimeConverter.java similarity index 92% rename from spring-boot/src/main/java/org/baeldung/converter/StringToLocalDateTimeConverter.java rename to spring-boot/src/main/java/org/baeldung/boot/converter/StringToLocalDateTimeConverter.java index cbb9e6ddb4..8a08b438f2 100644 --- a/spring-boot/src/main/java/org/baeldung/converter/StringToLocalDateTimeConverter.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/StringToLocalDateTimeConverter.java @@ -1,4 +1,4 @@ -package org.baeldung.converter; +package org.baeldung.boot.converter; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; diff --git a/spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java b/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java similarity index 90% rename from spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java rename to spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java index edd56dc136..ad921c2c43 100644 --- a/spring-boot/src/main/java/org/baeldung/converter/controller/StringToEmployeeConverterController.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java @@ -1,4 +1,4 @@ -package org.baeldung.converter.controller; +package org.baeldung.boot.converter.controller; import com.baeldung.toggle.Employee; import org.springframework.http.MediaType; diff --git a/spring-boot/src/main/java/org/baeldung/domain/GenericEntity.java b/spring-boot/src/main/java/org/baeldung/boot/domain/GenericEntity.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/domain/GenericEntity.java rename to spring-boot/src/main/java/org/baeldung/boot/domain/GenericEntity.java index 7b1d27cb66..f1c936e432 100644 --- a/spring-boot/src/main/java/org/baeldung/domain/GenericEntity.java +++ b/spring-boot/src/main/java/org/baeldung/boot/domain/GenericEntity.java @@ -1,4 +1,4 @@ -package org.baeldung.domain; +package org.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/spring-boot/src/main/java/org/baeldung/domain/Modes.java b/spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java similarity index 54% rename from spring-boot/src/main/java/org/baeldung/domain/Modes.java rename to spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java index 473406ef26..dcba064e8c 100644 --- a/spring-boot/src/main/java/org/baeldung/domain/Modes.java +++ b/spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java @@ -1,4 +1,4 @@ -package org.baeldung.domain; +package org.baeldung.boot.domain; public enum Modes { diff --git a/spring-boot/src/main/java/org/baeldung/jsoncomponent/User.java b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/User.java similarity index 86% rename from spring-boot/src/main/java/org/baeldung/jsoncomponent/User.java rename to spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/User.java index 8961874526..1f14131300 100644 --- a/spring-boot/src/main/java/org/baeldung/jsoncomponent/User.java +++ b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/User.java @@ -1,4 +1,4 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import javafx.scene.paint.Color; diff --git a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserCombinedSerializer.java b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserCombinedSerializer.java similarity index 97% rename from spring-boot/src/main/java/org/baeldung/jsoncomponent/UserCombinedSerializer.java rename to spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserCombinedSerializer.java index cb1b838ca4..4d3a2cf99e 100644 --- a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserCombinedSerializer.java +++ b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserCombinedSerializer.java @@ -1,4 +1,4 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; diff --git a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonDeserializer.java b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializer.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonDeserializer.java rename to spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializer.java index a310dcba5a..ad82ca06c0 100644 --- a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonDeserializer.java +++ b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializer.java @@ -1,4 +1,4 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonSerializer.java b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonSerializer.java similarity index 96% rename from spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonSerializer.java rename to spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonSerializer.java index 845bc3aac5..03330d81a4 100644 --- a/spring-boot/src/main/java/org/baeldung/jsoncomponent/UserJsonSerializer.java +++ b/spring-boot/src/main/java/org/baeldung/boot/jsoncomponent/UserJsonSerializer.java @@ -1,4 +1,4 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/spring-boot/src/main/java/org/baeldung/monitor/jmx/MonitoringConfig.java b/spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java similarity index 90% rename from spring-boot/src/main/java/org/baeldung/monitor/jmx/MonitoringConfig.java rename to spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java index 40f36ef924..d2e8fc228f 100644 --- a/spring-boot/src/main/java/org/baeldung/monitor/jmx/MonitoringConfig.java +++ b/spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java @@ -1,22 +1,22 @@ -package org.baeldung.monitor.jmx; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.codahale.metrics.JmxReporter; -import com.codahale.metrics.MetricRegistry; - -@Configuration -public class MonitoringConfig { - @Autowired - private MetricRegistry registry; - - @Bean - public JmxReporter jmxReporter() { - JmxReporter reporter = JmxReporter.forRegistry(registry) - .build(); - reporter.start(); - return reporter; - } -} +package org.baeldung.boot.monitor.jmx; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.codahale.metrics.JmxReporter; +import com.codahale.metrics.MetricRegistry; + +@Configuration +public class MonitoringConfig { + @Autowired + private MetricRegistry registry; + + @Bean + public JmxReporter jmxReporter() { + JmxReporter reporter = JmxReporter.forRegistry(registry) + .build(); + reporter.start(); + return reporter; + } +} diff --git a/spring-boot/src/main/java/org/baeldung/repository/GenericEntityRepository.java b/spring-boot/src/main/java/org/baeldung/boot/repository/GenericEntityRepository.java similarity index 64% rename from spring-boot/src/main/java/org/baeldung/repository/GenericEntityRepository.java rename to spring-boot/src/main/java/org/baeldung/boot/repository/GenericEntityRepository.java index 7bb1e6dcdc..d897e17afe 100644 --- a/spring-boot/src/main/java/org/baeldung/repository/GenericEntityRepository.java +++ b/spring-boot/src/main/java/org/baeldung/boot/repository/GenericEntityRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.repository; +package org.baeldung.boot.repository; -import org.baeldung.domain.GenericEntity; +import org.baeldung.boot.domain.GenericEntity; import org.springframework.data.jpa.repository.JpaRepository; public interface GenericEntityRepository extends JpaRepository { diff --git a/spring-boot/src/main/java/org/baeldung/web/resolver/HeaderVersionArgumentResolver.java b/spring-boot/src/main/java/org/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java similarity index 96% rename from spring-boot/src/main/java/org/baeldung/web/resolver/HeaderVersionArgumentResolver.java rename to spring-boot/src/main/java/org/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java index 89a77f38d1..b3a0dba7e8 100644 --- a/spring-boot/src/main/java/org/baeldung/web/resolver/HeaderVersionArgumentResolver.java +++ b/spring-boot/src/main/java/org/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java @@ -1,4 +1,4 @@ -package org.baeldung.web.resolver; +package org.baeldung.boot.web.resolver; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Component; diff --git a/spring-boot/src/main/java/org/baeldung/web/resolver/Version.java b/spring-boot/src/main/java/org/baeldung/boot/web/resolver/Version.java similarity index 86% rename from spring-boot/src/main/java/org/baeldung/web/resolver/Version.java rename to spring-boot/src/main/java/org/baeldung/boot/web/resolver/Version.java index 2a9e6e60b3..f69d40510e 100644 --- a/spring-boot/src/main/java/org/baeldung/web/resolver/Version.java +++ b/spring-boot/src/main/java/org/baeldung/boot/web/resolver/Version.java @@ -1,4 +1,4 @@ -package org.baeldung.web.resolver; +package org.baeldung.boot.web.resolver; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java rename to spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java index cb269f77f1..c4b0d48244 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java +++ b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.boot; +package org.baeldung.demo; import com.baeldung.graphql.GraphqlConfiguration; import org.springframework.boot.SpringApplication; diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java rename to spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java index a805e8f5fe..c1dd109f91 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java similarity index 91% rename from spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java rename to spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java index 98d1c33212..d991d9a8a9 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import java.util.List; diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java similarity index 96% rename from spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java rename to spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java index 1bfde0f0bd..516bff0e8c 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import java.util.List; diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java similarity index 89% rename from spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java rename to spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java index 13b5ca56e0..07765a511c 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import java.util.List; diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java similarity index 96% rename from spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java rename to spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java index 3fbfa92bc8..bd85234e02 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import java.util.List; diff --git a/spring-boot/src/main/java/org/baeldung/boot/components/FooService.java b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java similarity index 76% rename from spring-boot/src/main/java/org/baeldung/boot/components/FooService.java rename to spring-boot/src/main/java/org/baeldung/demo/components/FooService.java index 4ff8e9fdd4..334730ccb0 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/components/FooService.java +++ b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java @@ -1,7 +1,7 @@ -package org.baeldung.boot.components; +package org.baeldung.demo.components; -import org.baeldung.boot.model.Foo; -import org.baeldung.boot.repository.FooRepository; +import org.baeldung.demo.model.Foo; +import org.baeldung.demo.repository.FooRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/spring-boot/src/main/java/org/baeldung/boot/exceptions/CommonException.java b/spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java similarity index 85% rename from spring-boot/src/main/java/org/baeldung/boot/exceptions/CommonException.java rename to spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java index e03b859eab..51dd7bbd44 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/exceptions/CommonException.java +++ b/spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.exceptions; +package org.baeldung.demo.exceptions; public class CommonException extends RuntimeException { diff --git a/spring-boot/src/main/java/org/baeldung/boot/exceptions/FooNotFoundException.java b/spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java similarity index 86% rename from spring-boot/src/main/java/org/baeldung/boot/exceptions/FooNotFoundException.java rename to spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java index 0b04bd2759..59796c58f0 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/exceptions/FooNotFoundException.java +++ b/spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.exceptions; +package org.baeldung.demo.exceptions; public class FooNotFoundException extends RuntimeException { diff --git a/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java b/spring-boot/src/main/java/org/baeldung/demo/model/Foo.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/boot/model/Foo.java rename to spring-boot/src/main/java/org/baeldung/demo/model/Foo.java index d373e25b85..e5638cfd3d 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java +++ b/spring-boot/src/main/java/org/baeldung/demo/model/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.model; +package org.baeldung.demo.model; import java.io.Serializable; diff --git a/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java b/spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java similarity index 70% rename from spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java rename to spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java index 09d6975dba..c04e0c7438 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java +++ b/spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.boot.repository; +package org.baeldung.demo.repository; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; import org.springframework.data.jpa.repository.JpaRepository; public interface FooRepository extends JpaRepository { diff --git a/spring-boot/src/main/java/org/baeldung/boot/service/FooController.java b/spring-boot/src/main/java/org/baeldung/demo/service/FooController.java similarity index 85% rename from spring-boot/src/main/java/org/baeldung/boot/service/FooController.java rename to spring-boot/src/main/java/org/baeldung/demo/service/FooController.java index d400c3bf9e..c28dcde1a7 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/service/FooController.java +++ b/spring-boot/src/main/java/org/baeldung/demo/service/FooController.java @@ -1,7 +1,7 @@ -package org.baeldung.boot.service; +package org.baeldung.demo.service; -import org.baeldung.boot.components.FooService; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.components.FooService; +import org.baeldung.demo.model.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java b/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java index 790584644f..34b50a2c0a 100644 --- a/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java +++ b/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java @@ -3,7 +3,7 @@ package org.baeldung.endpoints.info; import java.util.HashMap; import java.util.Map; -import org.baeldung.boot.repository.UserRepository; +import org.baeldung.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java index 2d118b0eae..0ab4ecb128 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -1,9 +1,9 @@ package org.baeldung.main; +import org.baeldung.boot.controller.servlet.HelloWorldServlet; +import org.baeldung.boot.controller.servlet.SpringHelloWorldServlet; import org.baeldung.common.error.SpringHelloServletRegistrationBean; import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator; -import org.baeldung.controller.servlet.HelloWorldServlet; -import org.baeldung.controller.servlet.SpringHelloWorldServlet; import org.baeldung.service.LoginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -11,6 +11,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,7 +22,7 @@ import java.util.concurrent.Executors; @RestController @EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class) -@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service" }) +@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources","org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config"}) public class SpringBootApplication { private static ApplicationContext applicationContext; diff --git a/spring-boot/src/main/java/org/baeldung/boot/model/User.java b/spring-boot/src/main/java/org/baeldung/model/User.java similarity index 95% rename from spring-boot/src/main/java/org/baeldung/boot/model/User.java rename to spring-boot/src/main/java/org/baeldung/model/User.java index f60ac86fe4..61936584c4 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/model/User.java +++ b/spring-boot/src/main/java/org/baeldung/model/User.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.model; +package org.baeldung.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/spring-boot/src/main/java/org/baeldung/boot/repository/UserRepository.java b/spring-boot/src/main/java/org/baeldung/repository/UserRepository.java similarity index 77% rename from spring-boot/src/main/java/org/baeldung/boot/repository/UserRepository.java rename to spring-boot/src/main/java/org/baeldung/repository/UserRepository.java index 3a419a65bd..360dbf883c 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/repository/UserRepository.java +++ b/spring-boot/src/main/java/org/baeldung/repository/UserRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.boot.repository; +package org.baeldung.repository; -import org.baeldung.boot.model.User; +import org.baeldung.model.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java index c0cc669420..70c68368b5 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java @@ -1,6 +1,6 @@ package org.baeldung.session.exception; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java index 679d691b26..ce7bbfe57b 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java @@ -1,6 +1,6 @@ package org.baeldung.session.exception.repository; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; public interface FooRepository { diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java index 36d87e6dad..11df542d05 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java @@ -1,6 +1,6 @@ package org.baeldung.session.exception.repository; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java index 358ba942d9..823625f811 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootApplicationIntegrationTest.java @@ -1,6 +1,7 @@ package org.baeldung; -import org.baeldung.domain.Modes; +import org.baeldung.boot.Application; +import org.baeldung.boot.domain.Modes; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java index 185a36e571..2cb2f4dc10 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java @@ -1,8 +1,9 @@ package org.baeldung; -import org.baeldung.config.H2JpaConfig; -import org.baeldung.domain.GenericEntity; -import org.baeldung.repository.GenericEntityRepository; +import org.baeldung.boot.Application; +import org.baeldung.boot.config.H2JpaConfig; +import org.baeldung.boot.domain.GenericEntity; +import org.baeldung.boot.repository.GenericEntityRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java index 7c90622cdc..d9c30c67da 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java @@ -1,7 +1,8 @@ package org.baeldung; -import org.baeldung.domain.GenericEntity; -import org.baeldung.repository.GenericEntityRepository; +import org.baeldung.boot.Application; +import org.baeldung.boot.domain.GenericEntity; +import org.baeldung.boot.repository.GenericEntityRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java index 0e8a698f41..17e7d2d9e0 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java @@ -1,5 +1,6 @@ package org.baeldung; +import org.baeldung.boot.Application; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java index 9dd473f321..1d4ee262b0 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java @@ -1,8 +1,9 @@ package org.baeldung; +import org.baeldung.boot.Application; +import org.baeldung.boot.domain.GenericEntity; +import org.baeldung.boot.repository.GenericEntityRepository; import org.baeldung.config.H2TestProfileJPAConfig; -import org.baeldung.domain.GenericEntity; -import org.baeldung.repository.GenericEntityRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java index 4fcea35b4a..fba816c681 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java @@ -1,5 +1,6 @@ package org.baeldung.boot; +import org.baeldung.demo.DemoApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java similarity index 92% rename from spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java index 0f6c13ae1f..6f1cc66979 100644 --- a/spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package org.baeldung.boot.client; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Before; @@ -14,6 +14,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import org.baeldung.boot.client.Details; +import org.baeldung.boot.client.DetailsServiceClient; + @RunWith(SpringRunner.class) @RestClientTest(DetailsServiceClient.class) public class DetailsServiceClientIntegrationTest { diff --git a/spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonDeserializerIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializerIntegrationTest.java similarity index 89% rename from spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonDeserializerIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializerIntegrationTest.java index 4f5af3d0e7..f8b47a23fc 100644 --- a/spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonDeserializerIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonDeserializerIntegrationTest.java @@ -1,7 +1,9 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import com.fasterxml.jackson.databind.ObjectMapper; import javafx.scene.paint.Color; + +import org.baeldung.boot.jsoncomponent.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonSerializerIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonSerializerIntegrationTest.java similarity index 90% rename from spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonSerializerIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonSerializerIntegrationTest.java index ac47c5e5d9..060374e8fa 100644 --- a/spring-boot/src/test/java/org/baeldung/jsoncomponent/UserJsonSerializerIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/jsoncomponent/UserJsonSerializerIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.jsoncomponent; +package org.baeldung.boot.jsoncomponent; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -11,6 +11,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertEquals; +import org.baeldung.boot.jsoncomponent.User; + @JsonTest @RunWith(SpringRunner.class) public class UserJsonSerializerIntegrationTest { diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java index a844b26b2d..5d02d34f53 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java @@ -3,7 +3,8 @@ package org.baeldung.boot.repository; import static org.junit.Assert.assertThat; import org.baeldung.boot.DemoApplicationIntegrationTest; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; +import org.baeldung.demo.repository.FooRepository; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.is; diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java index be992bcc36..4658861162 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java @@ -5,7 +5,7 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; import org.baeldung.boot.ApplicationIntegrationTest; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; import org.baeldung.session.exception.repository.FooRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java index 55b7fa7216..8de7068949 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java @@ -1,7 +1,7 @@ package org.baeldung.boot.repository; import org.baeldung.boot.ApplicationIntegrationTest; -import org.baeldung.boot.model.Foo; +import org.baeldung.demo.model.Foo; import org.baeldung.session.exception.repository.FooRepository; import org.hibernate.HibernateException; import org.junit.Test; diff --git a/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java b/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java index eff383b440..499a755ae7 100644 --- a/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java +++ b/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java @@ -41,7 +41,7 @@ public class H2TestProfileJPAConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest" }); + em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.domain", "org.baeldung.boot.boottest","org.baeldung.model" }); em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); em.setJpaProperties(additionalProperties()); return em; diff --git a/spring-boot/src/test/java/org/baeldung/converter/CustomConverterTest.java b/spring-boot/src/test/java/org/baeldung/converter/CustomConverterTest.java index 6a585b9905..fb773fc44c 100644 --- a/spring-boot/src/test/java/org/baeldung/converter/CustomConverterTest.java +++ b/spring-boot/src/test/java/org/baeldung/converter/CustomConverterTest.java @@ -1,8 +1,9 @@ package org.baeldung.converter; import com.baeldung.toggle.Employee; -import org.baeldung.Application; -import org.baeldung.domain.Modes; + +import org.baeldung.boot.Application; +import org.baeldung.boot.domain.Modes; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java b/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java index a5ed7998b4..06c3f740c2 100644 --- a/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java +++ b/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerTest.java @@ -1,6 +1,5 @@ package org.baeldung.converter.controller; -import org.baeldung.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +14,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.baeldung.boot.Application; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class) @AutoConfigureMockMvc diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java similarity index 93% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java index 2146fc09bc..f06c144908 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java @@ -1,5 +1,8 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; +import org.baeldung.demo.boottest.Employee; +import org.baeldung.demo.boottest.EmployeeRestController; +import org.baeldung.demo.boottest.EmployeeService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java similarity index 94% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java index ebde0e243a..221beda900 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java @@ -1,5 +1,7 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; +import org.baeldung.demo.boottest.Employee; +import org.baeldung.demo.boottest.EmployeeRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java similarity index 94% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java index 9e5613ab10..e6f2203476 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java @@ -1,6 +1,8 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; -import org.baeldung.boot.DemoApplication; +import org.baeldung.demo.DemoApplication; +import org.baeldung.demo.boottest.Employee; +import org.baeldung.demo.boottest.EmployeeRepository; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java similarity index 94% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java rename to spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java index 9837b02df6..58ef3d4081 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java @@ -1,5 +1,9 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; +import org.baeldung.demo.boottest.Employee; +import org.baeldung.demo.boottest.EmployeeRepository; +import org.baeldung.demo.boottest.EmployeeService; +import org.baeldung.demo.boottest.EmployeeServiceImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java similarity index 91% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java rename to spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java index 36d07164b2..7e04f47696 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java @@ -1,4 +1,4 @@ -package org.baeldung.boot.boottest; +package org.baeldung.demo.boottest; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java index ffd5bf55d6..a51e3a6884 100644 --- a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java @@ -1,5 +1,7 @@ package org.baeldung.properties; +import org.baeldung.properties.ConfigProperties; +import org.baeldung.properties.ConfigPropertiesDemoApplication; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; From 2e7d254adbb92ff47ac6d025a6dabd7edb845e3d Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sun, 5 Nov 2017 14:06:25 -0600 Subject: [PATCH 15/23] BAEL-1133 README (#2962) * BAEL-973: updated README * BAEL-1069: Updated README * BAEL-817: add README file * BAEL-1084: README update * BAEL-960: Update README * BAEL-1155: updated README * BAEL-1041: updated README * BAEL-973: Updated README * BAEL-1187: updated README * BAEL-1183: Update README * BAEL-1133: Updated README --- core-kotlin/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 720187dc44..4b5f921f7b 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -15,5 +15,6 @@ - [Data Classes in Kotlin](http://www.baeldung.com/kotlin-data-classes) - [Delegated Properties in Kotlin](http://www.baeldung.com/kotlin-delegated-properties) - [Sealed Classes in Kotlin](http://www.baeldung.com/kotlin-sealed-classes) +- [JUnit 5 for Kotlin Developers](http://www.baeldung.com/junit-5-kotlin) From 90c2739563656be6c07e51ff3b1058be2322e06d Mon Sep 17 00:00:00 2001 From: tamasradu Date: Mon, 6 Nov 2017 03:46:29 +0200 Subject: [PATCH 16/23] Radu/bael 1265 junit updates (#2965) * Code for test article: Different Types of Bean Injection in Spring * Adding jUnits for test article: Different Types of Bean Injection in Spring * BAEL-1265: Adding jUnit for article * BAEL-1265: Closing ExecutorService in jUnit * BAEL-1265: Adding jUnit for CountDownLatch and example for ExecutorService.awaitTermination --- .../executorservice/DelayedCallable.java | 13 +++ .../WaitingForThreadsToFinishTest.java | 88 ++++++++++++++++--- .../ArticleFormatter.java | 16 ++++ .../ArticleWithConstructorInjection.java | 17 ++++ .../ArticleWithSetterInjection.java | 21 +++++ .../TextFormatter.java | 8 ++ .../dependencyinjectiontypes-context.xml | 23 +++++ .../DependencyInjectionTest.java | 35 ++++++++ 8 files changed, 211 insertions(+), 10 deletions(-) create mode 100644 spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleFormatter.java create mode 100644 spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithConstructorInjection.java create mode 100644 spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithSetterInjection.java create mode 100644 spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/TextFormatter.java create mode 100644 spring-core/src/main/resources/dependencyinjectiontypes-context.xml create mode 100644 spring-core/src/test/java/com/baeldung/dependencyinjectiontypes/DependencyInjectionTest.java diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java index 2f0796b491..16d9aa4c9f 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java @@ -1,11 +1,18 @@ package com.baeldung.concurrent.executorservice; import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; public class DelayedCallable implements Callable { private String name; private long period; + private CountDownLatch latch; + + public DelayedCallable(String name, long period, CountDownLatch latch) { + this(name, period); + this.latch = latch; + } public DelayedCallable(String name, long period) { this.name = name; @@ -16,9 +23,15 @@ public class DelayedCallable implements Callable { try { Thread.sleep(period); + + if (latch != null) { + latch.countDown(); + } + } catch (InterruptedException ex) { // handle exception ex.printStackTrace(); + Thread.currentThread().interrupt(); } return name; diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java index 0f461909ea..17b71aa35b 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java @@ -9,22 +9,91 @@ import java.util.List; import java.util.concurrent.*; import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.fail; public class WaitingForThreadsToFinishTest { private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishTest.class); private final static ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10); + public void awaitTerminationAfterShutdown(ExecutorService threadPool) { + threadPool.shutdown(); + try { + if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) { + threadPool.shutdownNow(); + } + } catch (InterruptedException ex) { + threadPool.shutdownNow(); + Thread.currentThread().interrupt(); + } + } + + @Test + public void givenMultipleThreads_whenUsingCountDownLatch_thenMainShoudWaitForAllToFinish() { + + ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10); + + try { + long startTime = System.currentTimeMillis(); + + // create a CountDownLatch that waits for the 2 threads to finish + CountDownLatch latch = new CountDownLatch(2); + + for (int i = 0; i < 2; i++) { + WORKER_THREAD_POOL.submit(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(1000); + latch.countDown(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + } + }); + } + + // wait for the latch to be decremented by the two threads + latch.await(); + + long processingTime = System.currentTimeMillis() - startTime; + assertTrue(processingTime >= 1000); + + } catch (InterruptedException e) { + e.printStackTrace(); + } + + awaitTerminationAfterShutdown(WORKER_THREAD_POOL); + } + @Test public void givenMultipleThreads_whenInvokeAll_thenMainThreadShouldWaitForAllToFinish() { ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10); - List> callables = Arrays.asList(new DelayedCallable("fast thread", 100), new DelayedCallable("slow thread", 3000)); - + List> callables = Arrays.asList( + new DelayedCallable("fast thread", 100), + new DelayedCallable("slow thread", 3000)); + try { long startProcessingTime = System.currentTimeMillis(); List> futures = WORKER_THREAD_POOL.invokeAll(callables); + + awaitTerminationAfterShutdown(WORKER_THREAD_POOL); + + try { + WORKER_THREAD_POOL.submit(new Callable() { + @Override + public String call() throws Exception { + fail("This thread should have been rejected !"); + Thread.sleep(1000000); + return null; + } + }); + } catch (RejectedExecutionException ex) { + // + } long totalProcessingTime = System.currentTimeMillis() - startProcessingTime; assertTrue(totalProcessingTime >= 3000); @@ -39,9 +108,7 @@ public class WaitingForThreadsToFinishTest { } catch (ExecutionException | InterruptedException ex) { ex.printStackTrace(); - } - - WORKER_THREAD_POOL.shutdown(); + } } @Test @@ -49,14 +116,14 @@ public class WaitingForThreadsToFinishTest { CompletionService service = new ExecutorCompletionService<>(WORKER_THREAD_POOL); - List> callables = Arrays.asList(new DelayedCallable("fast thread", 100), new DelayedCallable("slow thread", 3000)); + List> callables = Arrays.asList( + new DelayedCallable("fast thread", 100), + new DelayedCallable("slow thread", 3000)); for (Callable callable : callables) { service.submit(callable); } - WORKER_THREAD_POOL.shutdown(); - try { long startProcessingTime = System.currentTimeMillis(); @@ -79,8 +146,9 @@ public class WaitingForThreadsToFinishTest { } catch (ExecutionException | InterruptedException ex) { ex.printStackTrace(); + } finally { + awaitTerminationAfterShutdown(WORKER_THREAD_POOL); } - } @Test @@ -142,6 +210,6 @@ public class WaitingForThreadsToFinishTest { e.printStackTrace(); } - WORKER_THREAD_POOL.shutdown(); + awaitTerminationAfterShutdown(WORKER_THREAD_POOL); } } diff --git a/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleFormatter.java b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleFormatter.java new file mode 100644 index 0000000000..069e9df084 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleFormatter.java @@ -0,0 +1,16 @@ +package com.baeldung.dependencyinjectiontypes; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class ArticleFormatter { + + @SuppressWarnings("resource") + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml"); + ArticleWithSetterInjection article = (ArticleWithSetterInjection) context.getBean("articleWithSetterInjectionBean"); + String formattedArticle = article.format("This is a text !"); + + System.out.print(formattedArticle); + } +} diff --git a/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithConstructorInjection.java b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithConstructorInjection.java new file mode 100644 index 0000000000..776e9f4040 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithConstructorInjection.java @@ -0,0 +1,17 @@ +package com.baeldung.dependencyinjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; + +public class ArticleWithConstructorInjection { + + private TextFormatter formatter; + + @Autowired + public ArticleWithConstructorInjection(TextFormatter formatter) { + this.formatter = formatter; + } + + public String format(String text) { + return formatter.format(text); + } +} diff --git a/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithSetterInjection.java b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithSetterInjection.java new file mode 100644 index 0000000000..931c6ea276 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/ArticleWithSetterInjection.java @@ -0,0 +1,21 @@ +package com.baeldung.dependencyinjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; + +public class ArticleWithSetterInjection { + + private TextFormatter formatter; + + public ArticleWithSetterInjection(TextFormatter formatter) { + this.formatter = formatter; + } + + @Autowired + public void setTextFormatter(TextFormatter formatter) { + this.formatter = formatter; + } + + public String format(String text) { + return formatter.format(text); + } +} diff --git a/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/TextFormatter.java b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/TextFormatter.java new file mode 100644 index 0000000000..204436c9bd --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependencyinjectiontypes/TextFormatter.java @@ -0,0 +1,8 @@ +package com.baeldung.dependencyinjectiontypes; + +public class TextFormatter { + + public String format(String text) { + return text.toUpperCase(); + } +} diff --git a/spring-core/src/main/resources/dependencyinjectiontypes-context.xml b/spring-core/src/main/resources/dependencyinjectiontypes-context.xml new file mode 100644 index 0000000000..bd6b3c408d --- /dev/null +++ b/spring-core/src/main/resources/dependencyinjectiontypes-context.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/dependencyinjectiontypes/DependencyInjectionTest.java b/spring-core/src/test/java/com/baeldung/dependencyinjectiontypes/DependencyInjectionTest.java new file mode 100644 index 0000000000..57c1927e58 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/dependencyinjectiontypes/DependencyInjectionTest.java @@ -0,0 +1,35 @@ +package com.baeldung.dependencyinjectiontypes; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class DependencyInjectionTest { + + @Test + public void givenAutowiredAnnotation_WhenSetOnSetter_ThenDependencyValid() { + + ApplicationContext context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml"); + ArticleWithSetterInjection article = (ArticleWithSetterInjection) context.getBean("articleWithSetterInjectionBean"); + + String originalText = "This is a text !"; + String formattedArticle = article.format(originalText); + + assertTrue(originalText.toUpperCase().equals(formattedArticle)); + } + + @Test + public void givenAutowiredAnnotation_WhenSetOnConstructor_ThenDependencyValid() { + + ApplicationContext context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml"); + ArticleWithConstructorInjection article = (ArticleWithConstructorInjection) context.getBean("articleWithConstructorInjectionBean"); + + String originalText = "This is a text !"; + String formattedArticle = article.format(originalText); + + assertTrue(originalText.toUpperCase().equals(formattedArticle)); + } + +} From c65795c7b03025f17b7f496bcca74a2172b05cdb Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 6 Nov 2017 18:12:14 +0200 Subject: [PATCH 17/23] Remove true (#2919) --- core-java/pom.xml | 2 +- .../java/com/baeldung/serenity/MemberStatusIntegrationTest.java | 1 - mustache/pom.xml | 1 - parent-boot-4/pom.xml | 2 +- parent-boot-5/pom.xml | 1 - pom.xml | 2 +- selenium-junit-testng/pom.xml | 1 - spring-5-mvc/pom.xml | 2 +- spring-activiti/pom.xml | 2 +- spring-rest-simple/pom.xml | 2 +- spring-vertx/pom.xml | 2 +- vavr/pom.xml | 2 +- 12 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core-java/pom.xml b/core-java/pom.xml index bb3958f36c..cea5e9b3ec 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -249,7 +249,7 @@ **/*LongRunningUnitTest.java **/*ManualTest.java - true + diff --git a/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java b/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java index 18488f9380..e95b63aa96 100644 --- a/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java +++ b/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java @@ -51,7 +51,6 @@ public class MemberStatusIntegrationTest { /** * This test should fail, comment out @Ignore to see how failed test can be reflected in Serenity report.
- * Remember to add <testFailureIgnore>true</testFailureIgnore> under maven-surefire-plugin configuration. */ @Test @Ignore diff --git a/mustache/pom.xml b/mustache/pom.xml index 8aab038313..230aeecd60 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -85,7 +85,6 @@ **/JdbcTest.java **/*LiveTest.java - true diff --git a/parent-boot-4/pom.xml b/parent-boot-4/pom.xml index 2af36e9365..608e57ddaf 100644 --- a/parent-boot-4/pom.xml +++ b/parent-boot-4/pom.xml @@ -63,7 +63,7 @@ **/JdbcTest.java **/*LiveTest.java - true + diff --git a/parent-boot-5/pom.xml b/parent-boot-5/pom.xml index 57e9ed3c67..2fa397f298 100644 --- a/parent-boot-5/pom.xml +++ b/parent-boot-5/pom.xml @@ -65,7 +65,6 @@ **/*EntryPointsTest.java **/*LiveTest.java - true diff --git a/pom.xml b/pom.xml index 9aa45b1d5d..c2dee7d2f9 100644 --- a/pom.xml +++ b/pom.xml @@ -339,7 +339,7 @@ **/JdbcTest.java **/*LiveTest.java - true + diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index 5b695ca900..faad194b59 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -27,7 +27,6 @@ **/*LiveTest.java - false diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 7b7ddcba88..b188ee590a 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -152,7 +152,7 @@ org.apache.maven.plugins maven-surefire-plugin - true + false **/*IntegrationTest.java diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index f6f992b7c0..92d9618b65 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -74,7 +74,7 @@ **/JdbcTest.java **/*LiveTest.java - true + diff --git a/spring-rest-simple/pom.xml b/spring-rest-simple/pom.xml index f662b736ad..f3fdd78ff4 100644 --- a/spring-rest-simple/pom.xml +++ b/spring-rest-simple/pom.xml @@ -230,7 +230,7 @@ **/JdbcTest.java **/*LiveTest.java - true + diff --git a/spring-vertx/pom.xml b/spring-vertx/pom.xml index 2ab506f667..2b26d939a5 100644 --- a/spring-vertx/pom.xml +++ b/spring-vertx/pom.xml @@ -80,7 +80,7 @@ **/JdbcTest.java **/*LiveTest.java - true + diff --git a/vavr/pom.xml b/vavr/pom.xml index 878430611b..f9fed7d4fc 100644 --- a/vavr/pom.xml +++ b/vavr/pom.xml @@ -97,7 +97,7 @@ **/JdbcTest.java **/*LiveTest.java - true + From 93ecfad7fe749344984fb04fceec0bf976c68693 Mon Sep 17 00:00:00 2001 From: thakursantosh Date: Mon, 6 Nov 2017 16:16:12 -0500 Subject: [PATCH 18/23] Code for BAEL-1306 - thakursantosh/st1972@gmail.com (#2940) * New code for First Article 'Types of Bean Injection' * Adding code for BAEL-1306 * Code changes for BAEL-1306 * Removed code of my evaluation article --- .../baeldung/breakcontinue/BreakContinue.java | 138 ++++++++++++++++++ .../breakcontinue/BreakContinueTest.java | 39 +++++ 2 files changed, 177 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/breakcontinue/BreakContinue.java create mode 100644 core-java/src/test/java/com/baeldung/breakcontinue/BreakContinueTest.java diff --git a/core-java/src/main/java/com/baeldung/breakcontinue/BreakContinue.java b/core-java/src/main/java/com/baeldung/breakcontinue/BreakContinue.java new file mode 100644 index 0000000000..ce85b487c1 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/breakcontinue/BreakContinue.java @@ -0,0 +1,138 @@ +package com.baeldung.breakcontinue; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * @author Santosh + * + */ +public class BreakContinue { + + public static int unlabeledBreak() { + String searchName = "Wilson"; + int counter = 0; + List names = Arrays.asList("John", "Peter", "Robert", "Wilson", "Anthony", "Donald", "Richard"); + + for (String name : names) { + counter++; + if (name.equalsIgnoreCase(searchName)) { + break; + } + } + + return counter; + } + + public static int unlabeledBreakNestedLoops() { + String searchName = "Wilson"; + int counter = 0; + Map> nameMap = new HashMap<>(); + nameMap.put("Grade1", Arrays.asList("John", "Peter", "Robert", "Wilson")); + nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Richard", "Arnold")); + nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Stephen", "Ryan")); + + Iterator>> iterator = nameMap.entrySet() + .iterator(); + Entry> entry = null; + List names = null; + while (iterator.hasNext()) { + entry = iterator.next(); + names = entry.getValue(); + for (String name : names) { + if (name.equalsIgnoreCase(searchName)) { + counter++; + break; + } + } + } + + return counter; + } + + public static int labeledBreak() { + String searchName = "Wilson"; + int counter = 0; + Map> nameMap = new HashMap<>(); + nameMap.put("Grade1", Arrays.asList("John", "Peter", "Robert", "Wilson")); + nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Richard", "Arnold")); + nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Stephen", "Ryan")); + + Iterator>> iterator = nameMap.entrySet() + .iterator(); + Entry> entry = null; + List names = null; + compare: + while (iterator.hasNext()) { + entry = iterator.next(); + names = entry.getValue(); + for (String name : names) { + if (name.equalsIgnoreCase(searchName)) { + counter++; + break compare; + } + } + } + + return counter; + } + + public static int unlabeledContinue() { + String searchName = "Wilson"; + int counter = 0; + Map> nameMap = new HashMap<>(); + nameMap.put("Grade1", Arrays.asList("John", "Wilson", "Robert", "Wilson")); + nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Wilson", "Arnold")); + nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Wilson", "Ryan")); + + Iterator>> iterator = nameMap.entrySet() + .iterator(); + Entry> entry = null; + List names = null; + while (iterator.hasNext()) { + entry = iterator.next(); + names = entry.getValue(); + for (String name : names) { + if (!name.equalsIgnoreCase(searchName)) { + continue; + } + + counter++; + } + } + + return counter; + } + + public static int labeledContinue() { + String searchName = "Wilson"; + int counter = 0; + Map> nameMap = new HashMap<>(); + nameMap.put("Grade1", Arrays.asList("John", "Wilson", "Robert", "Wilson")); + nameMap.put("Grade2", Arrays.asList("Anthony", "Donald", "Wilson", "Arnold")); + nameMap.put("Grade3", Arrays.asList("Wilson", "Michael", "Wilson", "Ryan")); + + Iterator>> iterator = nameMap.entrySet() + .iterator(); + Entry> entry = null; + List names = null; + compare: + while (iterator.hasNext()) { + entry = iterator.next(); + names = entry.getValue(); + for (String name : names) { + if (name.equalsIgnoreCase(searchName)) { + counter++; + continue compare; + } + } + } + + return counter; + } + +} diff --git a/core-java/src/test/java/com/baeldung/breakcontinue/BreakContinueTest.java b/core-java/src/test/java/com/baeldung/breakcontinue/BreakContinueTest.java new file mode 100644 index 0000000000..1980497cd3 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/breakcontinue/BreakContinueTest.java @@ -0,0 +1,39 @@ +package com.baeldung.breakcontinue; + +import static com.baeldung.breakcontinue.BreakContinue.labeledBreak; +import static com.baeldung.breakcontinue.BreakContinue.labeledContinue; +import static com.baeldung.breakcontinue.BreakContinue.unlabeledBreak; +import static com.baeldung.breakcontinue.BreakContinue.unlabeledBreakNestedLoops; +import static com.baeldung.breakcontinue.BreakContinue.unlabeledContinue; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BreakContinueTest { + + @Test + public void whenUnlabeledBreak_ThenEqual() { + assertEquals(4, unlabeledBreak()); + } + + @Test + public void whenUnlabeledBreakNestedLoops_ThenEqual() { + assertEquals(2, unlabeledBreakNestedLoops()); + } + + @Test + public void whenLabeledBreak_ThenEqual() { + assertEquals(1, labeledBreak()); + } + + @Test + public void whenUnlabeledContinue_ThenEqual() { + assertEquals(5, unlabeledContinue()); + } + + @Test + public void whenLabeledContinue_ThenEqual() { + assertEquals(3, labeledContinue()); + } + +} From 50daef5bdc03ee2ca42629b1fb6da58182e605c6 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Mon, 6 Nov 2017 22:23:20 +0100 Subject: [PATCH 19/23] Refactor Cas-Server Configurations (#2970) * added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code * added example code for bytebuddy * added example code for PCollections * update pom * refactored tests for PCollections * spring security xml config * spring security xml config * remove redundant comment * example code for apache-shiro * updated example code for Vavr Collections * updated Vavr's Collection example * updated Vavr Collection file * updated example code for Apache Shiro * updated Vavr Collections example * added example code for N1QL * update example code for N1QL * added integration test for N1QL * update N1QL Example code * update the N1QL example Code * rename module to couchbase * rename module to couchbase * change module name in parent module and pom * added cas-server module * added cas secured app for Spring SSO with CAS * refactor cas modules into cas folder * updated files * removed redundant files * refactor the config for cas-server --- .../CasSecuredAppApplication.java | 8 +- cas/cas-server/etc/cas/thekeystore | Bin 2225 -> 0 bytes cas/cas-server/etc/cas/thekeystore.crt | Bin 808 -> 0 bytes .../src/main/resources/application.properties | 16 ++- .../src/main/resources/cas.properties | 7 +- .../resources/etc/cas/config/application.yml | 2 + .../resources/etc/cas/config/cas.properties | 7 ++ .../main/resources/etc/cas/config/log4j2.xml | 117 ++++++++++++++++++ .../src/main/resources/etc/cas/thekeystore | Bin 0 -> 2243 bytes .../main/resources/etc/cas/thekeystore.crt | Bin 0 -> 885 bytes 10 files changed, 145 insertions(+), 12 deletions(-) delete mode 100644 cas/cas-server/etc/cas/thekeystore delete mode 100644 cas/cas-server/etc/cas/thekeystore.crt create mode 100644 cas/cas-server/src/main/resources/etc/cas/config/application.yml create mode 100644 cas/cas-server/src/main/resources/etc/cas/config/cas.properties create mode 100644 cas/cas-server/src/main/resources/etc/cas/config/log4j2.xml create mode 100644 cas/cas-server/src/main/resources/etc/cas/thekeystore create mode 100644 cas/cas-server/src/main/resources/etc/cas/thekeystore.crt diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredAppApplication.java b/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredAppApplication.java index fc05e3b38f..25cbb9bc9b 100644 --- a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredAppApplication.java +++ b/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredAppApplication.java @@ -40,14 +40,14 @@ public class CasSecuredAppApplication { @Primary public AuthenticationEntryPoint authenticationEntryPoint(ServiceProperties sP) { CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint(); - entryPoint.setLoginUrl("https://localhost:8443/cas/login"); + entryPoint.setLoginUrl("https://localhost:6443/cas/login"); entryPoint.setServiceProperties(sP); return entryPoint; } @Bean public TicketValidator ticketValidator() { - return new Cas30ServiceTicketValidator("https://localhost:8443/cas"); + return new Cas30ServiceTicketValidator("https://localhost:6443/cas"); } @Bean @@ -71,7 +71,7 @@ public class CasSecuredAppApplication { @Bean public LogoutFilter logoutFilter() { LogoutFilter logoutFilter = new LogoutFilter( - "https://localhost:8443/cas/logout", securityContextLogoutHandler()); + "https://localhost:6443/cas/logout", securityContextLogoutHandler()); logoutFilter.setFilterProcessesUrl("/logout/cas"); return logoutFilter; } @@ -79,7 +79,7 @@ public class CasSecuredAppApplication { @Bean public SingleSignOutFilter singleSignOutFilter() { SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter(); - singleSignOutFilter.setCasServerUrlPrefix("https://localhost:8443/cas"); + singleSignOutFilter.setCasServerUrlPrefix("https://localhost:6443/cas"); singleSignOutFilter.setIgnoreInitConfiguration(true); return singleSignOutFilter; } diff --git a/cas/cas-server/etc/cas/thekeystore b/cas/cas-server/etc/cas/thekeystore deleted file mode 100644 index 15f9af2dae6366804459009361140e8526f811b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2225 zcmchY`8yPf8pmfdWEuM;h2bD;Mv*NOWhsn(m>Fv^MPo*m3LR5skg?5;Ff}bih^QF* z+LSqxeJm}U+>ptdxtLOPb)Ivd+x-Xb5AXXtpYQYj@NUohZZB;w0RRBdjsgENiP$g# zkq{pf8yQX5(E^u!qf-C?5fG9J*+#;k;`&e^1gHm+1p-9?5GrKeg_iR+!Qf)q3mJ?0 zgoR1to}B%S?(j%$R0ugSx$`SZ`jMK?WBN$r#xqu6=tQz44p*1n5f_ki_*IBv0S6_% z*>gqD5w*;Mouz@qZsi4y<6Q%!NcYpj)L9|Btz-waqYl6~!x;eU(33HmH4{dftT$Tu zr169O^xLA`^tfD^8AGcN3=bB}m22PHD-s!E>sDMDM@!t|gK?gK+?zk!C$f?f2XuidjJ8b9~Wm)XSxdKJ#Sd5zP>%91kcIhNkm9R8w**kC?qmF(1d) zF|RFiBf@|;Lop?7D)4rrdUI>kv12pt{^v|FE=lf5(#U{GFq7VseuutV>E?jx(|kPz zMHg$8{+X>3a(R-%AWq{YOt;ZBm_s&*;hCWDIDKRvheuKTqU!fy?J}+nCp%wuw1`6v z8=G@%H*N8M`=+GMq#3N_Ua#>sS9}+^O-tKiZ}Wa0LbHL{VO$Jrs^!U3)axPm}zB9qbs$Dgh_nk`SSA8M(RgQVHLp7g zZrmFbib%nLMMNyFzjLY(n`hB{<1@pMKsK1v$RA?Bo%XQ3_CNhyKg0@4gFo`xGO+b8 ze!W$09S644SvluSrp zUOD0JOrn$0gYJP7?v4oU-j5AS)_(eDW$TSsjG?yp`-0H*M~a<+O$WaQXneHox?1ko zWO5|}@0ARl+26b8dieVdjS;upYeyR>w(})w!G>Pn?!iw-Ej8-A@edjy>6&Y?79|9$ zB%M*FDru4EP#bu%mch1$UNvxghx!>kZC;%W+@1 zl@Fb1YR)#V|25-UEK?JquIiL+3s%3pHjnQs9{-G-aB9}EJ89ALqWzvt$ailL_IpTl*CVr*zH(wy4M?+JgDHe%I z!+sRn5NDJtU+msi8Ls|zP9!u@o&k$_&M7(Xt2UcDc8|O5cRrq&?P>GTb(PLK9;4fo ztSLHJJY%4J*^kV7zo3&3O=-88D4jTYx?}N$K+^LBQL_4_LZ!W>a$lTmn3wn`jYxiB z)|n_j4F9fB)Ht2@F0Ur2CXQ;kw|j^C*HnV2ZQ= z0Kg$gDmVy91vwUiK|l})f_9IQMoK|<>7|}X6-oht5+VR(u(1Sk7Zi+vK;=QMj>b|* ziJu@Q5Ai0%#Qq0G{};voMp>lv&tM68F)y^Ox3{7DapS)w@P8$w>TW4xGh-yu^x#it zf!{&%U-18s0Trn6YuP(r0Zau-1CUgpIEV@a0t%5~h8Km|eI5$DexX9ub$Ko-)-SVJ zm&I8wK@o4ouFN7z|D@crdXvKG(!&vC@Z_A&3nH&9DA{X8By@|B`L~PxQD8CdH&f3LwX^{X$<66(+#$Ywh0k*3?)*q9nRf3e5vVDyY>jQPDO5-cG7mn4A+y z2;TBO2lSPF!#)`gz@#Pi{(idAoOaJBe)Za+UcZs~3ii{uu}04A)@!YFnw0rbYr%NA zXlL((Dsaj;tXmNYb(;m|EGN9Bo)u{(JD@aJ2+h093%o1^^n}IO11nmBT_LW_eeD*H zJY+9_LD4&4^W=oibc{r%gkru8aAotW4p1Cd=qfmPl=U~*5%5?t8K z=eF$Ek$rA%;Q*0w5L4!kodW zrFjazKvf2E;=G3Dh6VFh9*%!u7!c2fiaXzA4fDX?l5R#)PZ@P5y+8eYHVcq zTOZsgTPma(bl+=^-kT@SzX@&+vU%^qa9Ga1VOyYDrfaN&QsD1M+un#@`;UIzW$^9v z?9iO+jn)maCi$Pz61Hd03|P8k{`?m#)dEU~{CBUs{%`v+=^xhN&yTHGCd$w9yZPJY zqjHCtOhbgD#3mYjEB(AqJMp^K`%g;Dl5;P5FdkKL;f;X5m*tl$01>Q&Rva35}4_NMf}$nd^hS0eqN6|xI7 zHf-?}D^z~rqah}|{XC~p&xvIZZN#d&Luz_89xPrbr@eVu>BPLn_1wP{O_M(UPO4&5 zu|BipQL1bMjz{c=RLKU8(SGb?&$e-G}wpj?j83m z<=yL3W*Z2t5wi%671tG5mS?ylp*q|D0KDYkd}-gkWj8M5-+je@cd?>@yn!q*S;_LTh_Q&YJHHb@cHKCaG5K^|-kqbb z71xQ*LrK-l1`Gzez;KTy%+P+Cq182x$hPylZc<7u@rwr-~sU~Z@s>F Lt(?_lzc& diff --git a/cas/cas-server/src/main/resources/application.properties b/cas/cas-server/src/main/resources/application.properties index 2d5e9a7277..afacd4cbc1 100644 --- a/cas/cas-server/src/main/resources/application.properties +++ b/cas/cas-server/src/main/resources/application.properties @@ -2,9 +2,9 @@ # CAS Server Context Configuration # server.context-path=/cas -server.port=8443 +server.port=6443 -server.ssl.key-store=file:/etc/cas/thekeystore +server.ssl.key-store=classpath:/etc/cas/thekeystore server.ssl.key-store-password=changeit server.ssl.key-password=changeit # server.ssl.ciphers= @@ -40,6 +40,12 @@ spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=true +## +#CAS CONFIG LOCATION +# +cas.standalone.config=classpath:/etc/cas/config + + ## # CAS Cloud Bus Configuration # @@ -82,6 +88,7 @@ spring.thymeleaf.mode=HTML # CAS Log4j Configuration # # logging.config=file:/etc/cas/log4j2.xml + server.context-parameters.isLog4jAutoInitializationDisabled=true ## @@ -104,9 +111,10 @@ cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect cas.authn.jdbc.query[0].user=root cas.authn.jdbc.query[0].password= cas.authn.jdbc.query[0].ddlAuto=none -cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver +#cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver +cas.authn.jdbc.query[0].driverClass=com.mysql.cj.jdbc.Driver cas.authn.jdbc.query[0].fieldPassword=password -cas.authn.jdbc.query[0].passwordEncoder.type=BCRYPT +cas.authn.jdbc.query[0].passwordEncoder.type=NONE ## diff --git a/cas/cas-server/src/main/resources/cas.properties b/cas/cas-server/src/main/resources/cas.properties index be2babcd14..f80f22fc11 100644 --- a/cas/cas-server/src/main/resources/cas.properties +++ b/cas/cas-server/src/main/resources/cas.properties @@ -1,16 +1,15 @@ -cas.server.name: https://localhost:8443 -cas.server.prefix: https://localhost:8443/cas +cas.server.name: https://localhost:6443 +cas.server.prefix: https://localhost:643/cas cas.adminPagesSecurity.ip=127\.0\.0\.1 -logging.config: file:/etc/cas/config/log4j2.xml - cas.serviceRegistry.initFromJson=true cas.serviceRegistry.config.location=classpath:/services cas.authn.accept.users= cas.authn.accept.name= + #CAS Database Authentication Property # cas.authn.jdbc.query[0].healthQuery= diff --git a/cas/cas-server/src/main/resources/etc/cas/config/application.yml b/cas/cas-server/src/main/resources/etc/cas/config/application.yml new file mode 100644 index 0000000000..be1f7c3edd --- /dev/null +++ b/cas/cas-server/src/main/resources/etc/cas/config/application.yml @@ -0,0 +1,2 @@ +info: + description: CAS Configuration \ No newline at end of file diff --git a/cas/cas-server/src/main/resources/etc/cas/config/cas.properties b/cas/cas-server/src/main/resources/etc/cas/config/cas.properties new file mode 100644 index 0000000000..47a1477308 --- /dev/null +++ b/cas/cas-server/src/main/resources/etc/cas/config/cas.properties @@ -0,0 +1,7 @@ +cas.server.name: https://cas.example.org:8443 +cas.server.prefix: https://cas.example.org:8443/cas + +cas.adminPagesSecurity.ip=127\.0\.0\.1 + +logging.config: file:/etc/cas/config/log4j2.xml +# cas.serviceRegistry.config.location: classpath:/services diff --git a/cas/cas-server/src/main/resources/etc/cas/config/log4j2.xml b/cas/cas-server/src/main/resources/etc/cas/config/log4j2.xml new file mode 100644 index 0000000000..53b30b4228 --- /dev/null +++ b/cas/cas-server/src/main/resources/etc/cas/config/log4j2.xml @@ -0,0 +1,117 @@ + + + + + + . + + warn + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cas/cas-server/src/main/resources/etc/cas/thekeystore b/cas/cas-server/src/main/resources/etc/cas/thekeystore new file mode 100644 index 0000000000000000000000000000000000000000..86170dff16f95409b7f2857a75cba1094b43b5b1 GIT binary patch literal 2243 zcmchYS5(u962|jSqosf#(j2`+{zbohagVRU` zX+~)a$#-XPQ?gf+s@EGNM>zK8*U@a^mr7E&JTq*02^1?!n9TK5Xg#IOCT5WKz#`Y~y9rm#``uapQiu6@9xUi6XOu^RwqPU1dxY0* z8VcRA0dSERqnHQzLn0I=t!JKz*=z4vN%;={*Fx*`Hs-hnFE|4M;$Z|;0&5bh4^ z;iG`LWUW`KTj3Atd4dGg;~0DICG_3LXeoZS`Zohdi(>2ry=DzYAuA+0?fCYqwy$>K zL9iOCj$FuK`nbQvbB!6(fegNosi^nKqE7Gz!bl;WA-I{5Gew8fE|#HEi6qRX z8VIK&znc=Bed-V+&gibiM^Yks-vivn3A-7Y1n%dC?z5(2nhcJetwJ?(o0I2^#p{RX zqqFA{4S&h$?G7S7yxfd-Txh4y`5L0e$c_ZfS4`ekaL-^WT5C^xj1`l+!ieiQkx9R(x?Jdw0#5Jrd5u8#@BE>3!Ftun{ zV~d@rsPr3)=?-05akqJ~;O7wXr(X~5_gimkE$q)=4|x#Xu!Y6~8&}Rn!Ly$b*ef;M zJxlz(=uV@^pg7_Lvn(&cNu8g?Hf@?*5@T2X_U-;w_vsoD*9X>7q>@BsLaIhV{QYsU zmg5a;s_D*VtsChodeOG|A66SDms(mOil^rB&c+|++8itPMrJqfmRggWqA-$TVYxNO zmTJNnS~3>ULd8SAA{mG?V9K)6dOf|2^7hBPYd>#p?j_sy4V-*vzhIdbWpUhD;lGiK zn9pLz>pZGI5-Zf@Ubvf8OY5|->DaE_D7%J##`o^l{ep7?6p^Xh%z(eoBkb}SWt=() z1i6l*Lws>`Fy$!(41mE4hiRwizY>HBLRR52Ew`Hxo{kC2pJ0J1z#lMQ8>h3 zz|IT1;N(j4|CibR-Ys8@mHhQNg8+`f{LFS(mhLoD9 zzg2z{eRo@Un3XUQCiWlQE+uysveI|}GCIr1Y_l;$kPnDUlRU{D1DFWWU`mx_l*l`y z*Ox9o73yj_ha^4sP$`RzqsTZWuo5PB@~1gUX$g2 zrpmsY-LIQ*&~2=sU7{5!6QPzyaI)_0BHc3)QehGFzq|Wr8`!bs8Oy;2xtvB}RN9&OW6hycj6?#tI{ALz6L_Tu7f!RcrqcYcGeO;*gy8rx%w zkM#Ufy5BjeyKjs3axoD<>$1x6%~_e!DHd7_WSed+F*zS}zwi!R@4w45=MR?hhi$Xg za~v#}+@7xJxABSUT@P11H)McdrC~cz>c=!JX=hx9QvPUtGFQe_PAnZa-$5G3iTJzR zI?T+j+73`#oY9|@yRH-D7D3ATn0v=JJ`fj{bK^F3PE%xB=q-|?_yS_*`PI>wUhQ~; z!D%J)Xb(*CJNTgYnIdcKiSo!9AzIj+rtwwz7==f%Gj>(ZVW-r~hv`)aYO|e%+L8cx r$2(t8yGpIvZ)QewhgS{MlKqldYTq&f_lfyx_^8gsEdFM5g;ms__$ADZ literal 0 HcmV?d00001 diff --git a/cas/cas-server/src/main/resources/etc/cas/thekeystore.crt b/cas/cas-server/src/main/resources/etc/cas/thekeystore.crt new file mode 100644 index 0000000000000000000000000000000000000000..5bd9d5babaa13aeb8f33af053456117325b39d3e GIT binary patch literal 885 zcmXqLVlFgjVv1bA%*4pV#3G-u|AYZA8>d#AN85K^Mn-N{27^pPZUas>=1>+kVJ1I! zLp}o@5QjsU)h97MzZk}6hw+6B1VHj!!kjtz$%#1``NbuMP%&;SV$4Wl26E!OhUSKb z24;rFh6W}kQ9!N*kZTC#($gtTj7rD>!N|(M+{DPwV9>W?gSP!NK<`Xq!w{Q9yl2*P;d4-BQN8_b9XUMLTHU zJ5X@Jh#}x<-*uBiskNKG$zAG{zVV^&ZoN{l{b`fT54@Ybt}x$vvV7jLXcwN)f9`MY z2~NtoBHt)i9l2e#RpyfCuAqnoQl}4ku2W3^AaUxjOYH0J%QoA?S?8EP;kYROJ1uqp zM}OV4WuEi+j`zB*Y*>}6DYn9#)jvUHs~2V$qL-VhrL-@4mG<$#R1C>atUzVF#{EN#v_yOy4&@ccHgJ)+1FW zW=00a#fk><2C~5DmgQp+V-cCqqp7*xcDCS6*Vl!wcb!+0=UwBC9EiZw1Pnw*2H$

6bdcT4uOb$?IYv;P~zpOfaTY@GI<^IM8( z?y(o@)7X;8notTXk6wag=_v%H*Ze0Y9tNxs#7-nQHM+9Q*Iwk-Kcm)Nf5>8%b| z6yMnLSSr8%g|%0*PP_iBj>oavQ|c8gH{NL4&XamLHqhdY1k=yFWs Date: Mon, 6 Nov 2017 17:44:53 -0500 Subject: [PATCH 20/23] BAEL-1238 (#2974) * michael.good703@gmail.com michael.good703@gmail.com * michael.good703@gmail.com michael.good703@gmail.com * michael.good703@gmail.com michael.good703@gmail.com * update * michael.good703@gmail.com Had to add @SpringBootApplication(exclude = MySQLAutoconfiguration.class) * Updated for 3.3.0.Final BAEL-1238 * Update pom.xml * BAEL-1238 Added new module spring-boot-keycloak and removed Keycloak code from spring-boot module * Minor changes to pom.xml * Update CustomConverterTest.java * Update StringToEmployeeConverter.java * Update GenericBigDecimalConverter.java * Update MyFeatures.java * Update .gitignore * Formatting changes * "Resolving conflicts" * Updated spring-boot to remove keycloak * Updated to see * Update * Updated * Found remnant file and deleted it * Update pom.xml Added spring-boot-keycloak module * Added reference to parent-boot-5 I changed the parent from org.springframework.boot to parent-boot-5. * Update GenericBigDecimalConverter.java Copy current GenericBigDecimalConverter to resolve any conflicts * Update StringToEmployeeConverter.java Copy current version to resolve any conflicts * Update pom.xml * Update pom.xml * Delete remnant files * Updated pom.xml * Update pom.xml --- pom.xml | 1 + spring-boot-keycloak/pom.xml | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c2dee7d2f9..8fa402b69e 100644 --- a/pom.xml +++ b/pom.xml @@ -149,6 +149,7 @@ spring-batch spring-bom spring-boot + spring-boot-keycloak spring-boot-bootstrap spring-cloud-data-flow spring-cloud diff --git a/spring-boot-keycloak/pom.xml b/spring-boot-keycloak/pom.xml index 657f96a265..ab76d0af43 100644 --- a/spring-boot-keycloak/pom.xml +++ b/spring-boot-keycloak/pom.xml @@ -12,10 +12,12 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - org.springframework.boot - spring-boot-starter-parent - 1.5.8.RELEASE - + + com.baeldung + parent-boot-4 + 0.0.1-SNAPSHOT + ../parent-boot-4 + From 1d61601aa7f27d42a25cea895666375c18c80476 Mon Sep 17 00:00:00 2001 From: Nik Date: Tue, 7 Nov 2017 13:47:10 +0800 Subject: [PATCH 21/23] BAEL-1267 spring rest project through tomcat created in java (#2969) * BAEL-1267 spring rest project through tomcat created in java * BAEL-1267 including empty file for webapp --- pom.xml | 2 + spring-rest-embedded-tomcat/pom.xml | 83 +++++++++++++++++++ .../configuration/AppInitializer.java | 22 +++++ .../configuration/UserConfiguration.java | 12 +++ .../embedded/controller/UserController.java | 28 +++++++ .../org/baeldung/embedded/domain/User.java | 23 +++++ .../embedded/service/UserService.java | 38 +++++++++ .../src/main/webapp/emptyFile | 0 .../baeldung/embedded/EmbeddedTomcatApp.java | 70 ++++++++++++++++ .../embedded/EmbeddedTomcatRunner.java | 45 ++++++++++ .../embedded/UserIntegrationTest.java | 60 ++++++++++++++ 11 files changed, 383 insertions(+) create mode 100644 spring-rest-embedded-tomcat/pom.xml create mode 100644 spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/AppInitializer.java create mode 100644 spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/UserConfiguration.java create mode 100644 spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/controller/UserController.java create mode 100644 spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/domain/User.java create mode 100644 spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/service/UserService.java create mode 100644 spring-rest-embedded-tomcat/src/main/webapp/emptyFile create mode 100644 spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatApp.java create mode 100644 spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatRunner.java create mode 100644 spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/UserIntegrationTest.java diff --git a/pom.xml b/pom.xml index 8fa402b69e..bc8e35ba94 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,8 @@ spring-zuul spring-reactor spring-vertx + + spring-rest-embedded-tomcat testing diff --git a/spring-rest-embedded-tomcat/pom.xml b/spring-rest-embedded-tomcat/pom.xml new file mode 100644 index 0000000000..554040e763 --- /dev/null +++ b/spring-rest-embedded-tomcat/pom.xml @@ -0,0 +1,83 @@ + + 4.0.0 + org.baeldung.embedded + SpringRestTomcat + 0.0.1-SNAPSHOT + + spring-rest-embedded-tomcat + war + + + + junit + junit + ${junit.version} + test + + + + org.springframework + spring-core + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + javax.servlet + javax.servlet-api + 4.0.0 + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.library} + + + + org.apache.tomcat.embed + tomcat-embed-core + 9.0.1 + test + + + + org.apache.tomcat + tomcat-jasper + 9.0.1 + test + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + + + + spring-rest-embedded-tomcat + + + + 5.0.1.RELEASE + 4.12 + 2.9.2 + 1.8 + 1.8 + false + + + \ No newline at end of file diff --git a/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/AppInitializer.java b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/AppInitializer.java new file mode 100644 index 0000000000..24bd28166b --- /dev/null +++ b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/AppInitializer.java @@ -0,0 +1,22 @@ +package org.baeldung.embedded.configuration; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + + @Override + protected Class[] getRootConfigClasses() { + return new Class[] { UserConfiguration.class }; + } + + @Override + protected Class[] getServletConfigClasses() { + return null; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } + +} diff --git a/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/UserConfiguration.java b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/UserConfiguration.java new file mode 100644 index 0000000000..4c102a74cb --- /dev/null +++ b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/configuration/UserConfiguration.java @@ -0,0 +1,12 @@ +package org.baeldung.embedded.configuration; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "org.baeldung.embedded") +public class UserConfiguration { + +} diff --git a/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/controller/UserController.java b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/controller/UserController.java new file mode 100644 index 0000000000..a9a5faa0c6 --- /dev/null +++ b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/controller/UserController.java @@ -0,0 +1,28 @@ +package org.baeldung.embedded.controller; + +import org.baeldung.embedded.domain.User; +import org.baeldung.embedded.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class UserController { + + @Autowired + UserService userService; + + @RequestMapping("/") + public String welcome() { + return "Hello World!"; + } + + @RequestMapping(method = RequestMethod.GET, value = "/user/{userName}") + @ResponseBody + public User user(@PathVariable String userName) { + return this.userService.getUser(userName); + } +} diff --git a/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/domain/User.java b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/domain/User.java new file mode 100644 index 0000000000..2f9443daea --- /dev/null +++ b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/domain/User.java @@ -0,0 +1,23 @@ +package org.baeldung.embedded.domain; + +public class User { + + private String name; + private String hobby; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getHobby() { + return hobby; + } + + public void setHobby(String hobby) { + this.hobby = hobby; + } +} diff --git a/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/service/UserService.java b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/service/UserService.java new file mode 100644 index 0000000000..76696e12c2 --- /dev/null +++ b/spring-rest-embedded-tomcat/src/main/java/org/baeldung/embedded/service/UserService.java @@ -0,0 +1,38 @@ +package org.baeldung.embedded.service; + +import java.util.ArrayList; +import java.util.List; + +import org.baeldung.embedded.domain.User; +import org.springframework.stereotype.Service; + +@Service +public class UserService { + private List users = new ArrayList<>(); + + public void addUser(String name) { + User user = new User(); + user.setName(name); + if (name == "HarryPotter") { + user.setHobby("Quidditch"); + } else { + user.setHobby("MuggleActivity"); + } + users.add(user); + } + + public User getUser(String name) { + for (User user : users) { + if (user.getName() + .equalsIgnoreCase(name)) { + return user; + } + } + + User user = new User(); + user.setName(name); + user.setHobby("None"); + + return user; + } +} diff --git a/spring-rest-embedded-tomcat/src/main/webapp/emptyFile b/spring-rest-embedded-tomcat/src/main/webapp/emptyFile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatApp.java b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatApp.java new file mode 100644 index 0000000000..f340f6c837 --- /dev/null +++ b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatApp.java @@ -0,0 +1,70 @@ +package org.baeldung.embedded; + +import java.io.File; +import java.util.concurrent.CountDownLatch; +import org.apache.catalina.Context; +import org.apache.catalina.startup.Tomcat; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +public class EmbeddedTomcatApp { + + private Tomcat tomcatInstance; + private WebApplicationContext webApplicationContext; + private CountDownLatch started = new CountDownLatch(1); + + public void start() throws Exception { + tomcatInstance = new Tomcat(); + tomcatInstance.setBaseDir(new File(getClass().getResource(".") + .toURI()).getAbsolutePath()); // Tomcat's temporary directory + tomcatInstance.setPort(0); + + Context webapp = tomcatInstance.addWebapp("", new File("src/main/webapp/").getAbsolutePath()); + + webapp.addLifecycleListener(event -> { + if (event.getType() + .equals("after_stop")) { + started.countDown(); + } else if (event.getType() + .equals("after_start")) { + webApplicationContext = WebApplicationContextUtils + .findWebApplicationContext(webapp.getServletContext()); + + ((ConfigurableListableBeanFactory) webApplicationContext + .getAutowireCapableBeanFactory()).registerSingleton("baseUrl", getBaseUrl()); + + started.countDown(); + } + }); + + tomcatInstance.start(); + started.await(); + } + + public Tomcat getTomcatInstance() { + return this.tomcatInstance; + } + + public String getBaseUrl() { + return String.format("http://localhost:%d%s", getLocalPort(), getWebApplicationContext().getServletContext() + .getContextPath()); + } + + public int getLocalPort() { + return tomcatInstance.getConnector() + .getLocalPort(); + } + + public WebApplicationContext getWebApplicationContext() { + return webApplicationContext; + } + + public boolean isStarted() { + return started.getCount() == 0; + } + + public boolean isStartedSucessfully() { + return webApplicationContext != null; + } +} diff --git a/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatRunner.java b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatRunner.java new file mode 100644 index 0000000000..1bf15556e8 --- /dev/null +++ b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/EmbeddedTomcatRunner.java @@ -0,0 +1,45 @@ +package org.baeldung.embedded; + +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; + +public class EmbeddedTomcatRunner extends BlockJUnit4ClassRunner { + + public EmbeddedTomcatRunner(Class klass) throws InitializationError { + super(klass); + } + + // use one static Tomcat instance shared across all tests + private static EmbeddedTomcatApp embeddedTomcatApp = new EmbeddedTomcatApp(); + + @Override + protected Statement classBlock(RunNotifier notifier) { + ensureSharedTomcatStarted(); + Statement result = super.classBlock(notifier); + return result; + } + + private void ensureSharedTomcatStarted() { + if (!embeddedTomcatApp.isStarted()) { + try { + embeddedTomcatApp.start(); + } catch (Exception e) { + throw new RuntimeException("Error while starting embedded Tomcat server", e); + } + } + } + + @Override + protected Object createTest() throws Exception { + if (!embeddedTomcatApp.isStartedSucessfully()) { + throw new RuntimeException("Tomcat server not started successfully. Skipping test"); + } + Object testInstance = super.createTest(); + embeddedTomcatApp.getWebApplicationContext() + .getAutowireCapableBeanFactory() + .autowireBean(testInstance); + return testInstance; + } +} \ No newline at end of file diff --git a/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/UserIntegrationTest.java b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/UserIntegrationTest.java new file mode 100644 index 0000000000..1c5d482171 --- /dev/null +++ b/spring-rest-embedded-tomcat/src/test/java/org/baeldung/embedded/UserIntegrationTest.java @@ -0,0 +1,60 @@ +package org.baeldung.embedded; + +import java.io.IOException; +import java.util.Map; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.baeldung.embedded.service.UserService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(EmbeddedTomcatRunner.class) +public class UserIntegrationTest { + + @Autowired + protected String baseUrl; + + @Autowired + private UserService userService; + + private String userName = "HarryPotter"; + + @Before + public void setUp() { + userService.addUser(userName); + } + + @Test + public void givenUserName_whenSendGetForHarryPotter_thenHobbyQuidditch() throws IOException { + String url = baseUrl + "/user/" + userName; + + HttpClient httpClient = HttpClientBuilder.create() + .build(); + HttpGet getUserRequest = new HttpGet(url); + getUserRequest.addHeader("Content-type", "application/json"); + HttpResponse response = httpClient.execute(getUserRequest); + + Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine() + .getStatusCode()); + + HttpEntity responseEntity = response.getEntity(); + + Assert.assertNotNull(responseEntity); + + ObjectMapper mapper = new ObjectMapper(); + String retSrc = EntityUtils.toString(responseEntity); + Map result = mapper.readValue(retSrc, Map.class); + + Assert.assertEquals("Quidditch", result.get("hobby")); + } +} From 30d8509b44e6349a86b25d822709f306a17e798e Mon Sep 17 00:00:00 2001 From: lor6 Date: Tue, 7 Nov 2017 14:46:21 +0200 Subject: [PATCH 22/23] Update README.MD --- spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 5d7eb11954..f126df00af 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -27,4 +27,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Java Client for a WebSockets API](http://www.baeldung.com/websockets-api-java-spring-client) - [Spring Boot and Togglz Aspect](http://www.baeldung.com/spring-togglz) - [Getting Started with GraphQL and Spring Boot](http://www.baeldung.com/spring-graphql) +- [Guide to Spring Type Conversions](http://www.baeldung.com/spring-type-conversions) From 2f5370dea6d6a5eebb609645784817c1cb4ba806 Mon Sep 17 00:00:00 2001 From: Muhammed Almas Date: Wed, 8 Nov 2017 12:54:37 +0530 Subject: [PATCH 23/23] Spring core xml (#2971) * BAEL-1247 Spring XML injection. * BAEL-1247 - updated test * BAEL-1247 - updated test --- .../main/resources/com.baeldung.di.spring.xml | 8 +++--- .../baeldung/di/spring/BeanInjectionTest.java | 28 +++++-------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/spring-core/src/main/resources/com.baeldung.di.spring.xml b/spring-core/src/main/resources/com.baeldung.di.spring.xml index 9c44d911d1..e0c5d22abb 100644 --- a/spring-core/src/main/resources/com.baeldung.di.spring.xml +++ b/spring-core/src/main/resources/com.baeldung.di.spring.xml @@ -5,7 +5,7 @@ - + @@ -29,15 +29,15 @@ - + - + - + \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/di/spring/BeanInjectionTest.java b/spring-core/src/test/java/com/baeldung/di/spring/BeanInjectionTest.java index 1d133faf63..1660b99726 100644 --- a/spring-core/src/test/java/com/baeldung/di/spring/BeanInjectionTest.java +++ b/spring-core/src/test/java/com/baeldung/di/spring/BeanInjectionTest.java @@ -15,31 +15,17 @@ public class BeanInjectionTest { applicationContext = new ClassPathXmlApplicationContext("com.baeldung.di.spring.xml"); } - @Test - public void protoBean_getBean_returnsMultipleInstance() { - final MessageApp messageApp1 = applicationContext.getBean("messageWorldApp", MessageApp.class); - final MessageApp messageApp2 = applicationContext.getBean("messageWorldApp", MessageApp.class); - assertNotEquals(messageApp1, messageApp2); - } - - @Test - public void protoFactoryMethod_getBean_returnsMultipleInstance() { - final IndexApp indexApp1 = applicationContext.getBean("indexAppWithFactoryMethod", IndexApp.class); - final IndexApp indexApp2 = applicationContext.getBean("indexAppWithFactoryMethod", IndexApp.class); - assertNotEquals(indexApp1, indexApp2); - } - - @Test - public void protoStaticFactory_getBean_returnsMultipleInstance() { - final IndexApp indexApp1 = applicationContext.getBean("indexAppWithStaticFactory", IndexApp.class); - final IndexApp indexApp2 = applicationContext.getBean("indexAppWithStaticFactory", IndexApp.class); - assertNotEquals(indexApp1, indexApp2); - } - @Test public void singletonBean_getBean_returnsSingleInstance() { final IndexApp indexApp1 = applicationContext.getBean("indexApp", IndexApp.class); final IndexApp indexApp2 = applicationContext.getBean("indexApp", IndexApp.class); assertEquals(indexApp1, indexApp2); } + + @Test + public void getBean_returnsInstance() { + final IndexApp indexApp = applicationContext.getBean("indexApp", IndexApp.class); + assertNotNull(indexApp); + } + }