response = template.withBasicAuth(username, password)
- .postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\"}", Boolean.class);
- boolean value = response.getBody();
- assertTrue(true == value);
+ .postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class);
+ assertTrue(response.getBody());
}
}
diff --git a/spring-5/src/test/java/com/baeldung/jsonb/JsonbTest.java b/spring-5/src/test/java/com/baeldung/jsonb/JsonbTest.java
index 7133999551..4caab86f7d 100644
--- a/spring-5/src/test/java/com/baeldung/jsonb/JsonbTest.java
+++ b/spring-5/src/test/java/com/baeldung/jsonb/JsonbTest.java
@@ -22,15 +22,15 @@ public class JsonbTest {
@Test
public void givenPersonObject_whenSerializeWithJsonb_thenGetPersonJson() {
- Person person = new Person("Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000));
+ Person person = new Person(1, "Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000));
String jsonPerson = jsonb.toJson(person);
- assertTrue("{\"email\":\"jhon@test.com\",\"person-name\":\"Jhon\",\"registeredDate\":\"07-09-2019\",\"salary\":\"1000.0\"}".equals(jsonPerson));
+ assertTrue("{\"email\":\"jhon@test.com\",\"id\":1,\"person-name\":\"Jhon\",\"registeredDate\":\"07-09-2019\",\"salary\":\"1000.0\"}".equals(jsonPerson));
}
@Test
public void givenPersonJson_whenDeserializeWithJsonb_thenGetPersonObject() {
- Person person = new Person("Jhon", "jhon@test.com", 0, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000.0));
- String jsonPerson = "{\"email\":\"jhon@test.com\",\"person-name\":\"Jhon\",\"registeredDate\":\"07-09-2019\",\"salary\":\"1000.0\"}";
+ Person person = new Person(1, "Jhon", "jhon@test.com", 0, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000.0));
+ String jsonPerson = "{\"email\":\"jhon@test.com\",\"id\":1,\"person-name\":\"Jhon\",\"registeredDate\":\"07-09-2019\",\"salary\":\"1000.0\"}";
assertTrue(jsonb.fromJson(jsonPerson, Person.class)
.equals(person));
}
diff --git a/spring-all/pom.xml b/spring-all/pom.xml
index 1ecb824c40..6615e1d6cd 100644
--- a/spring-all/pom.xml
+++ b/spring-all/pom.xml
@@ -195,7 +195,11 @@
spring-core
${org.springframework.version}
-
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
@@ -280,4 +284,4 @@
-
\ No newline at end of file
+
diff --git a/spring-all/src/main/java/org/baeldung/controller/controller/PassParametersController.java b/spring-all/src/main/java/org/baeldung/controller/controller/PassParametersController.java
index 54047cedf3..c282ae6a62 100644
--- a/spring-all/src/main/java/org/baeldung/controller/controller/PassParametersController.java
+++ b/spring-all/src/main/java/org/baeldung/controller/controller/PassParametersController.java
@@ -3,8 +3,7 @@ package org.baeldung.controller.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
/**
@@ -16,23 +15,23 @@ import org.springframework.web.servlet.ModelAndView;
*/
@Controller
public class PassParametersController {
- @RequestMapping(value = "/showViewPage", method = RequestMethod.GET)
+ @GetMapping("/showViewPage")
public String passParametersWithModel(Model model) {
model.addAttribute("message", "Baeldung");
return "viewPage";
}
- @RequestMapping(value = "/printViewPage", method = RequestMethod.GET)
+ @GetMapping("/printViewPage")
public String passParametersWithModelMap(ModelMap map) {
map.addAttribute("welcomeMessage", "welcome");
map.addAttribute("message", "Baeldung");
return "viewPage";
}
- @RequestMapping(value = "/goToViewPage", method = RequestMethod.GET)
+ @GetMapping("/goToViewPage")
public ModelAndView passParametersWithModelAndView() {
ModelAndView modelAndView = new ModelAndView("viewPage");
modelAndView.addObject("message", "Baeldung");
return modelAndView;
}
-}
\ No newline at end of file
+}
diff --git a/spring-all/src/main/webapp/WEB-INF/view/viewPage.html b/spring-all/src/main/webapp/WEB-INF/view/viewPage.html
new file mode 100644
index 0000000000..71f766407e
--- /dev/null
+++ b/spring-all/src/main/webapp/WEB-INF/view/viewPage.html
@@ -0,0 +1,9 @@
+
+
+
+ Title
+
+
+ Web Application. Passed parameter : th:text="${message}"
+
+
diff --git a/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp b/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp
deleted file mode 100644
index ca638b33f5..0000000000
--- a/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp
+++ /dev/null
@@ -1,11 +0,0 @@
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-
-
- Title
-
-
-
- Web Application. Passed parameter : ${message}
-
-
-
diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml
index e36f5265b2..44e72535f8 100644
--- a/spring-cloud/pom.xml
+++ b/spring-cloud/pom.xml
@@ -15,6 +15,7 @@
spring-cloud-ribbon-client
spring-cloud-rest
spring-cloud-zookeeper
+ spring-cloud-gateway
pom
diff --git a/spring-cloud/spring-cloud-gateway/README.MD b/spring-cloud/spring-cloud-gateway/README.MD
new file mode 100644
index 0000000000..48fbf41b8e
--- /dev/null
+++ b/spring-cloud/spring-cloud-gateway/README.MD
@@ -0,0 +1,2 @@
+### Relevant Articles:
+- [Explore the new Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway)
diff --git a/spring-cloud/spring-cloud-gateway/gateway-service/pom.xml b/spring-cloud/spring-cloud-gateway/gateway-service/pom.xml
new file mode 100644
index 0000000000..14cde4901a
--- /dev/null
+++ b/spring-cloud/spring-cloud-gateway/gateway-service/pom.xml
@@ -0,0 +1,79 @@
+
+ 4.0.0
+
+ gateway-service
+ 1.0.0-SNAPSHOT
+ jar
+
+ Spring Cloud Gateway Service
+
+
+ com.baeldung.spring.cloud
+ spring-cloud-gateway
+ 1.0.0-SNAPSHOT
+ ..
+
+
+
+ 2.0.0.M2
+
+
+
+
+ org.springframework.boot
+ spring-boot-actuator
+ ${version}
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+ ${version}
+
+
+ org.springframework.cloud
+ spring-cloud-gateway-core
+ ${version}
+
+
+ org.springframework.cloud
+ spring-cloud-starter-eureka
+ ${version}
+
+
+ org.hibernate
+ hibernate-validator-cdi
+ 6.0.2.Final
+
+
+ javax.validation
+ validation-api
+ 2.0.0.Final
+
+
+ io.projectreactor.ipc
+ reactor-netty
+ 0.7.0.M1
+
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/snapshot
+
+ true
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/milestone
+
+ false
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-gateway/gateway-service/src/main/java/com/baeldung/spring/cloud/GatewayApplication.java b/spring-cloud/spring-cloud-gateway/gateway-service/src/main/java/com/baeldung/spring/cloud/GatewayApplication.java
new file mode 100644
index 0000000000..4d5f61315f
--- /dev/null
+++ b/spring-cloud/spring-cloud-gateway/gateway-service/src/main/java/com/baeldung/spring/cloud/GatewayApplication.java
@@ -0,0 +1,12 @@
+package com.baeldung.spring.cloud;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class GatewayApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(GatewayApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-gateway/gateway-service/src/main/resources/application.yml b/spring-cloud/spring-cloud-gateway/gateway-service/src/main/resources/application.yml
new file mode 100644
index 0000000000..8b981f8071
--- /dev/null
+++ b/spring-cloud/spring-cloud-gateway/gateway-service/src/main/resources/application.yml
@@ -0,0 +1,13 @@
+server:
+ port: 80
+spring:
+ cloud:
+ gateway:
+ routes:
+ - id: baeldung_route
+ uri: http://www.baeldung.com
+ predicates:
+ - Path=/baeldung
+management:
+ security:
+ enabled: false
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml
new file mode 100644
index 0000000000..095ca4ea31
--- /dev/null
+++ b/spring-cloud/spring-cloud-gateway/pom.xml
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+
+ com.baeldung.spring.cloud
+ spring-cloud-gateway
+ 1.0.0-SNAPSHOT
+
+ gateway-service
+
+ pom
+
+ Spring Cloud Gateway
+
+
+ com.baeldung.spring.cloud
+ spring-cloud
+ 1.0.0-SNAPSHOT
+ ..
+
+
+
+ UTF-8
+ 3.6.0
+ 1.4.2.RELEASE
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ 1.8
+ 1.8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring-boot-maven-plugin.version}
+
+
+
+
+
diff --git a/spring-core/README.md b/spring-core/README.md
index 237f8cd4e9..81a7aaa952 100644
--- a/spring-core/README.md
+++ b/spring-core/README.md
@@ -8,4 +8,3 @@
- [Spring YAML Configuration](http://www.baeldung.com/spring-yaml)
- [Introduction to Spring’s StreamUtils](http://www.baeldung.com/spring-stream-utils)
- [Using Spring @Value with Defaults](http://www.baeldung.com/spring-value-defaults)
-
diff --git a/spring-hibernate5/README.md b/spring-hibernate5/README.md
index fd539fdcb6..01a1ad7121 100644
--- a/spring-hibernate5/README.md
+++ b/spring-hibernate5/README.md
@@ -1,3 +1,4 @@
### Relevant articles
- [Guide to @Immutable Annotation in Hibernate](http://www.baeldung.com/hibernate-immutable)
+- [Hibernate Many to Many Annotation Tutorial](http://www.baeldung.com/hibernate-many-to-many)
diff --git a/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/Event.java b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/Event.java
index 2928ffe981..ec88d629a6 100644
--- a/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/Event.java
+++ b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/Event.java
@@ -2,15 +2,9 @@ package com.baeldung.hibernate.immutable.entities;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
-import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Immutable;
-import javax.persistence.Column;
-import javax.persistence.ElementCollection;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
import java.util.Set;
@Entity
@@ -20,8 +14,6 @@ public class Event {
@Id
@Column(name = "event_id")
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name = "increment", strategy = "increment")
private Long id;
@Column(name = "title")
@@ -31,6 +23,14 @@ public class Event {
@Immutable
private Set guestList;
+ public Event() {}
+
+ public Event(Long id, String title, Set guestList) {
+ this.id = id;
+ this.title = title;
+ this.guestList = guestList;
+ }
+
public Long getId() {
return id;
}
diff --git a/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/EventGeneratedId.java b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/EventGeneratedId.java
new file mode 100644
index 0000000000..33af9313ae
--- /dev/null
+++ b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/entities/EventGeneratedId.java
@@ -0,0 +1,55 @@
+package com.baeldung.hibernate.immutable.entities;
+
+import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.annotations.Immutable;
+
+import javax.persistence.*;
+
+@Entity
+@Immutable
+@Table(name = "events_generated")
+public class EventGeneratedId {
+
+ @Id
+ @Column(name = "event_generated_id")
+ @GeneratedValue(generator = "increment")
+ @GenericGenerator(name = "increment", strategy = "increment")
+ private Long id;
+
+ @Column(name = "name")
+ private String name;
+ @Column(name = "description")
+ private String description;
+
+ public EventGeneratedId() {
+ }
+
+ public EventGeneratedId(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
diff --git a/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/util/HibernateUtil.java b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/util/HibernateUtil.java
index e4a2319c37..722f0251d1 100644
--- a/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/util/HibernateUtil.java
+++ b/spring-hibernate5/src/main/java/com/baeldung/hibernate/immutable/util/HibernateUtil.java
@@ -1,6 +1,7 @@
package com.baeldung.hibernate.immutable.util;
import com.baeldung.hibernate.immutable.entities.Event;
+import com.baeldung.hibernate.immutable.entities.EventGeneratedId;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
@@ -14,6 +15,7 @@ public class HibernateUtil {
// Create a session factory from immutable.cfg.xml
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(Event.class);
+ configuration.addAnnotatedClass(EventGeneratedId.class);
configuration.configure("immutable.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
return configuration.buildSessionFactory(serviceRegistry);
diff --git a/spring-hibernate5/src/main/resources/hibernate5Config.xml b/spring-hibernate5/src/main/resources/hibernate5Config.xml
index 55546a862a..bbb61cb3e0 100644
--- a/spring-hibernate5/src/main/resources/hibernate5Config.xml
+++ b/spring-hibernate5/src/main/resources/hibernate5Config.xml
@@ -21,7 +21,7 @@
-
+
diff --git a/spring-hibernate5/src/main/resources/persistence-h2.properties b/spring-hibernate5/src/main/resources/persistence-h2.properties
index 537626bc2a..696e805cff 100644
--- a/spring-hibernate5/src/main/resources/persistence-h2.properties
+++ b/spring-hibernate5/src/main/resources/persistence-h2.properties
@@ -1,7 +1,7 @@
# jdbc.X
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
-jdbc.user=sa
+jdbc.eventGeneratedId=sa
jdbc.pass=sa
# hibernate.X
diff --git a/spring-hibernate5/src/main/resources/persistence-mysql.properties b/spring-hibernate5/src/main/resources/persistence-mysql.properties
index 1180929b30..b3cfd31f46 100644
--- a/spring-hibernate5/src/main/resources/persistence-mysql.properties
+++ b/spring-hibernate5/src/main/resources/persistence-mysql.properties
@@ -1,7 +1,7 @@
# jdbc.X
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate5_01?createDatabaseIfNotExist=true
-jdbc.user=tutorialuser
+jdbc.eventGeneratedId=tutorialuser
jdbc.pass=tutorialmy5ql
# hibernate.X
diff --git a/spring-hibernate5/src/test/java/com/baeldung/hibernate/immutable/HibernateImmutableIntegrationTest.java b/spring-hibernate5/src/test/java/com/baeldung/hibernate/immutable/HibernateImmutableIntegrationTest.java
index 801ddcdb45..b8cc3dc1a6 100644
--- a/spring-hibernate5/src/test/java/com/baeldung/hibernate/immutable/HibernateImmutableIntegrationTest.java
+++ b/spring-hibernate5/src/test/java/com/baeldung/hibernate/immutable/HibernateImmutableIntegrationTest.java
@@ -1,6 +1,7 @@
package com.baeldung.hibernate.immutable;
import com.baeldung.hibernate.immutable.entities.Event;
+import com.baeldung.hibernate.immutable.entities.EventGeneratedId;
import com.baeldung.hibernate.immutable.util.HibernateUtil;
import com.google.common.collect.Sets;
import org.hibernate.CacheMode;
@@ -10,6 +11,9 @@ import org.junit.rules.ExpectedException;
import javax.persistence.PersistenceException;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+
public class HibernateImmutableIntegrationTest {
private static Session session;
@@ -22,6 +26,7 @@ public class HibernateImmutableIntegrationTest {
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
createEvent();
+ createEventGenerated();
session.setCacheMode(CacheMode.REFRESH);
}
@@ -35,9 +40,12 @@ public class HibernateImmutableIntegrationTest {
HibernateUtil.getSessionFactory().close();
}
+ //
+
@Test
public void addEvent() {
Event event = new Event();
+ event.setId(2L);
event.setTitle("Public Event");
session.save(event);
session.getTransaction().commit();
@@ -47,8 +55,12 @@ public class HibernateImmutableIntegrationTest {
public void updateEvent() {
Event event = (Event) session.createQuery("FROM Event WHERE title='New Event'").list().get(0);
event.setTitle("Private Event");
- session.saveOrUpdate(event);
- session.getTransaction().commit();
+ session.update(event);
+ session.flush();
+ session.refresh(event);
+
+ assertThat(event.getTitle(), equalTo("New Event"));
+ assertThat(event.getId(), equalTo(5L));
}
@Test
@@ -80,10 +92,29 @@ public class HibernateImmutableIntegrationTest {
session.getTransaction().commit();
}
- public static void createEvent() {
- Event event = new Event();
- event.setTitle("New Event");
- event.setGuestList(Sets.newHashSet("guest"));
+ @Test
+ public void updateEventGenerated() {
+ EventGeneratedId eventGeneratedId = (EventGeneratedId) session.createQuery("FROM EventGeneratedId WHERE name LIKE '%John%'").list().get(0);
+ eventGeneratedId.setName("Mike");
+ session.update(eventGeneratedId);
+ session.flush();
+ session.refresh(eventGeneratedId);
+
+ assertThat(eventGeneratedId.getName(), equalTo("John"));
+ assertThat(eventGeneratedId.getId(), equalTo(1L));
+ }
+
+ //
+
+ private static void createEvent() {
+ Event event = new Event(5L, "New Event", Sets.newHashSet("guest"));
session.save(event);
}
+
+ private static void createEventGenerated() {
+ EventGeneratedId eventGeneratedId = new EventGeneratedId("John", "Doe");
+ eventGeneratedId.setId(4L);
+ session.save(eventGeneratedId);
+ }
+
}
diff --git a/spring-mvc-kotlin/README.md b/spring-mvc-kotlin/README.md
new file mode 100644
index 0000000000..c9bb78b6d8
--- /dev/null
+++ b/spring-mvc-kotlin/README.md
@@ -0,0 +1,2 @@
+### Relevant articles
+- [Spring MVC Setup with Kotlin](http://www.baeldung.com/spring-mvc-kotlin)
diff --git a/spring-rest-angular/README.md b/spring-rest-angular/README.md
index 3c1b418d95..dcbbd048ba 100644
--- a/spring-rest-angular/README.md
+++ b/spring-rest-angular/README.md
@@ -2,3 +2,4 @@
### Relevant Articles:
+- [Spring’s RequestBody and ResponseBody Annotations](http://www.baeldung.com/spring-request-response-body)
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
similarity index 97%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java
rename to spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
index c20f968704..33926d6200 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java
+++ b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
@@ -21,7 +21,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApplication.class)
-public class ExamplePostControllerRequestUnitTest {
+public class ExamplePostControllerRequestIntegrationTest {
MockMvc mockMvc;
@Mock private ExampleService exampleService;
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
similarity index 97%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java
rename to spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
index 3d09622c47..5c5e5c0a64 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java
+++ b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
@@ -23,7 +23,7 @@ import org.baeldung.config.MainApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApplication.class)
-public class ExamplePostControllerResponseUnitTest {
+public class ExamplePostControllerResponseIntegrationTest {
MockMvc mockMvc;
@Mock private ExampleService exampleService;
diff --git a/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java b/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java
deleted file mode 100644
index 398e3c04e9..0000000000
--- a/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.baeldung.web.log.test;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import org.junit.Test;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-import com.baeldung.web.log.data.TaxiRide;
-
-public class TestTaxiFareController {
-
- private static final String URL = "http://localhost:" + 8082 + "/spring-rest/taxifare/";
-
- @Test
- public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
- TestRestTemplate testRestTemplate = new TestRestTemplate();
- ResponseEntity response = testRestTemplate.getForEntity(URL + "get/", String.class);
-
- assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
- }
-
- @Test
- public void givenTaxiRide_whenCalculatedFare_thanStatus200() {
- TestRestTemplate testRestTemplate = new TestRestTemplate();
- TaxiRide taxiRide = new TaxiRide(true, 10l);
- String fare = testRestTemplate.postForObject(URL + "calculate/", taxiRide, String.class);
-
- assertThat(fare, equalTo("200"));
- }
-}
diff --git a/spring-security-mvc-boot/README.MD b/spring-security-mvc-boot/README.MD
index feda6efcd7..32976b0896 100644
--- a/spring-security-mvc-boot/README.MD
+++ b/spring-security-mvc-boot/README.MD
@@ -8,3 +8,4 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com
- [Two Login Pages with Spring Security](http://www.baeldung.com/spring-security-two-login-pages)
- [Multiple Entry Points in Spring Security](http://www.baeldung.com/spring-security-multiple-entry-points)
- [Multiple Authentication Providers in Spring Security](http://www.baeldung.com/spring-security-multiple-auth-providers)
+- [Granted Authority Versus Role in Spring Security](http://www.baeldung.com/spring-security-granted-authority-vs-role)
diff --git a/spring-swagger-codegen/README.md b/spring-swagger-codegen/README.md
new file mode 100644
index 0000000000..ee6b240c30
--- /dev/null
+++ b/spring-swagger-codegen/README.md
@@ -0,0 +1,3 @@
+### Relevant articles
+
+- [Generate Spring Boot REST Client with Swagger](http://www.baeldung.com/spring-boot-rest-client-swagger-codegen)
diff --git a/testing/README.md b/testing/README.md
index 3171b67b60..889f6706d4 100644
--- a/testing/README.md
+++ b/testing/README.md
@@ -14,4 +14,4 @@
- [Introduction to JUnitParams](http://www.baeldung.com/junit-params)
- [Cucumber Java 8 Support](http://www.baeldung.com/cucumber-java-8-support)
- [Introduction to Lambda Behave](http://www.baeldung.com/lambda-behave)
-
+- [Introduction to Jukito](http://www.baeldung.com/jukito)
diff --git a/testing/src/main/java/com/baeldung/junit/Calculator.java b/testing/src/main/java/com/baeldung/junit/Calculator.java
new file mode 100644
index 0000000000..8ea7b3ed1f
--- /dev/null
+++ b/testing/src/main/java/com/baeldung/junit/Calculator.java
@@ -0,0 +1,11 @@
+package com.baeldung.junit;
+
+public class Calculator {
+ public int add(int a, int b) {
+ return a + b;
+ }
+
+ public int sub(int a, int b) {
+ return a - b;
+ }
+}
diff --git a/testing/src/test/java/com/baeldung/junit/AdditionTest.java b/testing/src/test/java/com/baeldung/junit/AdditionTest.java
new file mode 100644
index 0000000000..0d492f8058
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/AdditionTest.java
@@ -0,0 +1,14 @@
+package com.baeldung.junit;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class AdditionTest {
+ Calculator calculator = new Calculator();
+
+ @Test
+ public void testAddition() {
+ assertEquals("addition", 8, calculator.add(5, 3));
+ }
+}
diff --git a/testing/src/test/java/com/baeldung/junit/BlockingTestRunner.java b/testing/src/test/java/com/baeldung/junit/BlockingTestRunner.java
new file mode 100644
index 0000000000..432d5cda83
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/BlockingTestRunner.java
@@ -0,0 +1,18 @@
+package com.baeldung.junit;
+
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+
+public class BlockingTestRunner extends BlockJUnit4ClassRunner {
+ public BlockingTestRunner(Class> klass) throws InitializationError {
+ super(klass);
+ }
+
+ @Override
+ protected Statement methodInvoker(FrameworkMethod method, Object test) {
+ System.out.println("invoking: " + method.getName());
+ return super.methodInvoker(method, test);
+ }
+}
diff --git a/testing/src/test/java/com/baeldung/junit/CalculatorTest.java b/testing/src/test/java/com/baeldung/junit/CalculatorTest.java
new file mode 100644
index 0000000000..d1b35d1442
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/CalculatorTest.java
@@ -0,0 +1,17 @@
+package com.baeldung.junit;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(JUnit4.class)
+public class CalculatorTest {
+ Calculator calculator = new Calculator();
+
+ @Test
+ public void testAddition() {
+ assertEquals("addition", 8, calculator.add(5, 3));
+ }
+}
diff --git a/testing/src/test/java/com/baeldung/junit/SubstractionTest.java b/testing/src/test/java/com/baeldung/junit/SubstractionTest.java
new file mode 100644
index 0000000000..9650d83afe
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/SubstractionTest.java
@@ -0,0 +1,14 @@
+package com.baeldung.junit;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SubstractionTest {
+ Calculator calculator = new Calculator();
+
+ @Test
+ public void substraction() {
+ assertEquals("substraction", 2, calculator.sub(5, 3));
+ }
+}
diff --git a/testing/src/test/java/com/baeldung/junit/SuiteTest.java b/testing/src/test/java/com/baeldung/junit/SuiteTest.java
new file mode 100644
index 0000000000..428319e72e
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/SuiteTest.java
@@ -0,0 +1,12 @@
+package com.baeldung.junit;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({
+ AdditionTest.class,
+ SubstractionTest.class})
+public class SuiteTest {
+}
diff --git a/testing/src/test/java/com/baeldung/junit/TestRunner.java b/testing/src/test/java/com/baeldung/junit/TestRunner.java
new file mode 100644
index 0000000000..9eb4b3141b
--- /dev/null
+++ b/testing/src/test/java/com/baeldung/junit/TestRunner.java
@@ -0,0 +1,41 @@
+package com.baeldung.junit;
+
+import org.junit.Test;
+import org.junit.runner.Description;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
+
+import java.lang.reflect.Method;
+
+public class TestRunner extends Runner {
+
+ private Class testClass;
+ public TestRunner(Class testClass) {
+ super();
+ this.testClass = testClass;
+ }
+
+ @Override
+ public Description getDescription() {
+ return Description.createTestDescription(testClass, "My runner description");
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ System.out.println("running the tests from MyRunner: " + testClass);
+ try {
+ Object testObject = testClass.newInstance();
+ for (Method method : testClass.getMethods()) {
+ if (method.isAnnotationPresent(Test.class)) {
+ notifier.fireTestStarted(Description
+ .createTestDescription(testClass, method.getName()));
+ method.invoke(testObject);
+ notifier.fireTestFinished(Description
+ .createTestDescription(testClass, method.getName()));
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/vavr/README.md b/vavr/README.md
index d7816f3f9f..4361363fbd 100644
--- a/vavr/README.md
+++ b/vavr/README.md
@@ -5,4 +5,6 @@
- [Property Testing Example With Vavr](http://www.baeldung.com/javaslang-property-testing)
- [Exceptions in Lambda Expression Using Vavr](http://www.baeldung.com/exceptions-using-vavr)
- [Vavr (ex-Javaslang) Support in Spring Data](http://www.baeldung.com/spring-vavr)
-
+- [Introduction to Vavr’s Validation API](http://www.baeldung.com/vavr-validation-api)
+- [Guide to Collections API in Vavr](http://www.baeldung.com/vavr-collections)
+- [Collection Factory Methods for Vavr](http://www.baeldung.com/vavr-collection-factory-methods)
diff --git a/vavr/pom.xml b/vavr/pom.xml
index 53cd07ddf7..878430611b 100644
--- a/vavr/pom.xml
+++ b/vavr/pom.xml
@@ -5,12 +5,13 @@
vavr
1.0
vavr
-
+
org.springframework.boot
spring-boot-starter-parent
- 2.0.0.BUILD-SNAPSHOT
-
+ 1.5.6.RELEASE
+
+
@@ -35,10 +36,11 @@
com.h2database
h2
-
+
org.springframework.boot
spring-boot-starter-test
+ test
@@ -74,7 +76,7 @@
1.8
- 0.9.0
+ 0.9.1
4.12
3.0.0
diff --git a/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java
index 84621e3a68..437742c964 100644
--- a/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java
+++ b/vavr/src/test/java/com/baeldung/vavr/future/FutureUnitTest.java
@@ -5,17 +5,23 @@ import static io.vavr.API.Case;
import static io.vavr.API.Match;
import static io.vavr.Predicates.exists;
import static io.vavr.Predicates.forAll;
-import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.CancellationException;
+import java.util.function.Consumer;
import java.util.function.Predicate;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.internal.verification.VerificationModeFactory;
+import org.mockito.verification.Timeout;
+import io.vavr.Tuple;
+import io.vavr.Tuple2;
import io.vavr.collection.List;
import io.vavr.concurrent.Future;
+import io.vavr.control.Try;
public class FutureUnitTest {
@@ -26,8 +32,7 @@ public class FutureUnitTest {
public void givenFunctionReturnInteger_WhenCallWithFuture_ShouldReturnFunctionValue() {
Future future = Future.of(() -> 1);
- assertEquals(1, future.get()
- .intValue());
+ assertEquals(1, future.get().intValue());
}
@Test
@@ -57,33 +62,29 @@ public class FutureUnitTest {
@Test
public void givenFunction_WhenCallWithFutureAndRegisterConsumerForSuccess_ShouldCallConsumerToStoreValue() {
- final int[] store = new int[] { 0 };
Future future = Future.of(() -> 1);
- future.onSuccess(i -> {
- store[0] = i;
- });
- await().until(() -> store[0] == 1);
+ MockConsumer consumer = Mockito.mock(MockConsumer.class);
+ future.onSuccess(consumer);
+ Mockito.verify(consumer, new Timeout(1000, VerificationModeFactory.times(1))).accept(1);
}
@Test
public void givenFunctionThrowException_WhenCallWithFutureAndRegisterConsumerForFailer_ShouldCallConsumerToStoreException() {
- final Throwable[] store = new Throwable[] { null };
Future future = Future.of(() -> getResourceThrowException(""));
- future.onFailure(err -> store[0] = err);
- await().until(() -> RuntimeException.class.isInstance(store[0]));
+ MockThrowableConsumer consumer = Mockito.mock(MockThrowableConsumer.class);
+ future.onFailure(consumer);
+ Mockito.verify(consumer, new Timeout(1000, VerificationModeFactory.times(1))).accept(Mockito.any());
}
@Test
public void givenAFuture_WhenAddAndThenConsumer_ShouldCallConsumerWithResultOfFutureAction() {
- int[] store1 = new int[1];
- int[] store2 = new int[1];
+ MockTryConsumer consumer1 = Mockito.mock(MockTryConsumer.class);
+ MockTryConsumer consumer2 = Mockito.mock(MockTryConsumer.class);
Future future = Future.of(() -> 1);
- Future andThenFuture = future.andThen(i -> store1[0] = i.get() + 1)
- .andThen(i -> store2[0] = store1[0] + 1);
+ Future andThenFuture = future.andThen(consumer1).andThen(consumer2);
andThenFuture.await();
-
- assertEquals(2, store1[0]);
- assertEquals(3, store2[0]);
+ Mockito.verify(consumer1, VerificationModeFactory.times(1)).accept(Try.success(1));
+ Mockito.verify(consumer2, VerificationModeFactory.times(1)).accept(Try.success(1));
}
@Test
@@ -91,8 +92,7 @@ public class FutureUnitTest {
Future future = Future.failed(new RuntimeException());
Future future2 = future.orElse(Future.of(() -> 2));
- assertEquals(2, future2.get()
- .intValue());
+ assertEquals(2, future2.get().intValue());
}
@Test(expected = CancellationException.class)
@@ -124,17 +124,46 @@ public class FutureUnitTest {
Future future = Future.failed(new RuntimeException());
Future fallbackFuture = Future.of(() -> expectedResult);
Future futureResult = future.fallbackTo(fallbackFuture);
- futureResult.await();
assertEquals(expectedResult, futureResult.get());
}
+
+ @Test
+ public void givenAFuture_WhenTransformByAddingOne_ShouldReturn() {
+ Future