diff --git a/pom.xml b/pom.xml index eaf7f47a2b..3feba96d5a 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,6 @@ - spring-activiti aws akka-streams algorithms @@ -129,6 +128,7 @@ spark-java spring-5-mvc + spring-activiti spring-akka spring-amqp spring-all diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index 3d2f1386df..c5289b20a6 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -53,6 +53,23 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + true + + diff --git a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java index 3924d31f68..fd184556c4 100644 --- a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java +++ b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java @@ -1,9 +1,5 @@ package com.example.activitiwithspring; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.task.Task; @@ -12,12 +8,15 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; +import java.util.stream.Collectors; + @RestController public class ActivitiController { private static final Logger logger = LoggerFactory.getLogger(ActivitiController.class); + @Autowired private RuntimeService runtimeService; @@ -28,32 +27,30 @@ public class ActivitiController { public String startProcess() { runtimeService.startProcessInstanceByKey("my-process"); return "Process started. Number of currently running process instances = " + runtimeService.createProcessInstanceQuery() - .count(); + .count(); } @GetMapping("/get-tasks/{processInstanceId}") public List getTasks(@PathVariable String processInstanceId) { List usertasks = taskService.createTaskQuery() - .processInstanceId(processInstanceId) - .list(); + .processInstanceId(processInstanceId) + .list(); - List tasks = usertasks.stream().map(task -> { - TaskRepresentation taskRepresentation = new TaskRepresentation(task.getId(), task.getName(), task.getProcessInstanceId()); - return taskRepresentation; - }).collect(Collectors.toList()); - return tasks; + return usertasks.stream() + .map(task -> new TaskRepresentation(task.getId(), task.getName(), task.getProcessInstanceId())) + .collect(Collectors.toList()); } @GetMapping("/complete-task-A/{processInstanceId}") public TaskRepresentation completeTaskA(@PathVariable String processInstanceId) { Task task = taskService.createTaskQuery() - .processInstanceId(processInstanceId) - .singleResult(); + .processInstanceId(processInstanceId) + .singleResult(); taskService.complete(task.getId()); logger.info("Task completed"); task = taskService.createTaskQuery() - .processInstanceId(processInstanceId) - .singleResult(); + .processInstanceId(processInstanceId) + .singleResult(); return new TaskRepresentation(task.getId(), task.getName(), task.getProcessInstanceId()); } diff --git a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiWithSpringApplication.java b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiWithSpringApplication.java index e98b8ad7ca..2cfacdcf0d 100644 --- a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiWithSpringApplication.java +++ b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiWithSpringApplication.java @@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ActivitiWithSpringApplication { - public static void main(String[] args) { SpringApplication.run(ActivitiWithSpringApplication.class, args); } diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerTest.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java similarity index 78% rename from spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerTest.java rename to spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java index 3176207664..baca58f6ff 100644 --- a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerTest.java +++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java @@ -1,10 +1,6 @@ package com.example.activitiwithspring; -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.List; - +import com.fasterxml.jackson.databind.ObjectMapper; import org.activiti.engine.RuntimeService; import org.activiti.engine.runtime.ProcessInstance; import org.junit.Before; @@ -21,13 +17,16 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @SpringBootTest -public class ActivitiControllerTest { - private static final Logger logger = LoggerFactory.getLogger(ActivitiControllerTest.class); +public class ActivitiControllerIntegrationTest { + private static final Logger logger = LoggerFactory.getLogger(ActivitiControllerIntegrationTest.class); private MockMvc mockMvc; @Autowired @@ -39,10 +38,10 @@ public class ActivitiControllerTest { @Before public void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) - .build(); + .build(); for (ProcessInstance instance : runtimeService.createProcessInstanceQuery() - .list()) { + .list()) { runtimeService.deleteProcessInstance(instance.getId(), "Reset Processes"); } } @@ -51,21 +50,21 @@ public class ActivitiControllerTest { public void givenProcess_whenStartProcess_thenIncreaseInProcessInstanceCount() throws Exception { String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/start-process")) - .andReturn() - .getResponse() - .getContentAsString(); + .andReturn() + .getResponse() + .getContentAsString(); assertEquals("Process started. Number of currently running process instances = 1", responseBody); responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/start-process")) - .andReturn() - .getResponse() - .getContentAsString(); + .andReturn() + .getResponse() + .getContentAsString(); assertEquals("Process started. Number of currently running process instances = 2", responseBody); responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/start-process")) - .andReturn() - .getResponse() - .getContentAsString(); + .andReturn() + .getResponse() + .getContentAsString(); assertEquals("Process started. Number of currently running process instances = 3", responseBody); } @@ -73,19 +72,19 @@ public class ActivitiControllerTest { public void givenProcess_whenProcessInstance_thenReceivedRunningTask() throws Exception { this.mockMvc.perform(MockMvcRequestBuilders.get("/start-process")) - .andReturn() - .getResponse(); + .andReturn() + .getResponse(); ProcessInstance pi = runtimeService.createProcessInstanceQuery() - .orderByProcessInstanceId() - .desc() - .list() - .get(0); + .orderByProcessInstanceId() + .desc() + .list() + .get(0); logger.info("process instance = " + pi.getId()); String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/get-tasks/" + pi.getId())) - .andReturn() - .getResponse() - .getContentAsString(); + .andReturn() + .getResponse() + .getContentAsString(); ObjectMapper mapper = new ObjectMapper(); List tasks = Arrays.asList(mapper.readValue(responseBody, TaskRepresentation[].class)); @@ -98,19 +97,19 @@ public class ActivitiControllerTest { public void givenProcess_whenCompleteTaskA_thenReceivedNextTask() throws Exception { this.mockMvc.perform(MockMvcRequestBuilders.get("/start-process")) - .andReturn() - .getResponse(); + .andReturn() + .getResponse(); ProcessInstance pi = runtimeService.createProcessInstanceQuery() - .orderByProcessInstanceId() - .desc() - .list() - .get(0); + .orderByProcessInstanceId() + .desc() + .list() + .get(0); logger.info("process instance = " + pi.getId()); String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/complete-task-A/" + pi.getId())) - .andReturn() - .getResponse() - .getContentAsString(); + .andReturn() + .getResponse() + .getContentAsString(); ObjectMapper mapper = new ObjectMapper(); TaskRepresentation task = mapper.readValue(responseBody, TaskRepresentation.class); diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationTests.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationIntegrationTest.java similarity index 84% rename from spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationTests.java rename to spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationIntegrationTest.java index da22c6c7fa..7460c302d8 100644 --- a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationTests.java +++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiWithSpringApplicationIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class ActivitiWithSpringApplicationTests { +public class ActivitiWithSpringApplicationIntegrationTest { @Test public void contextLoads() { diff --git a/vavr/pom.xml b/vavr/pom.xml index d35a408389..426155263c 100644 --- a/vavr/pom.xml +++ b/vavr/pom.xml @@ -71,4 +71,26 @@ 4.12 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + true + + + + + \ No newline at end of file diff --git a/vavr/src/test/java/com/baeldung/vavr/PatternMatchingUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/PatternMatchingUnitTest.java index 1adff2e845..1c7d70a9a4 100644 --- a/vavr/src/test/java/com/baeldung/vavr/PatternMatchingUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/PatternMatchingUnitTest.java @@ -1,18 +1,24 @@ package com.baeldung.vavr; +import io.vavr.MatchError; +import io.vavr.control.Option; +import org.junit.Test; + import static io.vavr.API.$; import static io.vavr.API.Case; import static io.vavr.API.Match; import static io.vavr.API.run; -import static io.vavr.Predicates.*; +import static io.vavr.Predicates.allOf; +import static io.vavr.Predicates.anyOf; +import static io.vavr.Predicates.instanceOf; +import static io.vavr.Predicates.is; +import static io.vavr.Predicates.isIn; +import static io.vavr.Predicates.isNotNull; +import static io.vavr.Predicates.isNull; +import static io.vavr.Predicates.noneOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Test; - -import io.vavr.MatchError; -import io.vavr.control.Option; - public class PatternMatchingUnitTest { @Test public void whenMatchesDefault_thenCorrect() { diff --git a/vavr/src/test/java/com/baeldung/vavr/PropertyBasedLongRunningUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/PropertyBasedLongRunningUnitTest.java index 8409dbfa60..e93084f2c0 100644 --- a/vavr/src/test/java/com/baeldung/vavr/PropertyBasedLongRunningUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/PropertyBasedLongRunningUnitTest.java @@ -9,7 +9,9 @@ import org.junit.Test; import java.util.function.Predicate; -import static io.vavr.API.*; +import static io.vavr.API.$; +import static io.vavr.API.Case; +import static io.vavr.API.Match; public class PropertyBasedLongRunningUnitTest { diff --git a/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java index 5ddd344c5c..08a5e20b40 100644 --- a/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/VavrUnitTest.java @@ -5,7 +5,9 @@ import io.vavr.Function1; import io.vavr.Function2; import io.vavr.Function5; import io.vavr.Lazy; -import io.vavr.*; +import io.vavr.Tuple; +import io.vavr.Tuple2; +import io.vavr.Tuple3; import io.vavr.collection.List; import io.vavr.collection.Seq; import io.vavr.control.Option; @@ -13,23 +15,25 @@ import io.vavr.control.Try; import io.vavr.control.Validation; import org.junit.Test; -import com.baeldung.vavr.Person; -import com.baeldung.vavr.PersonValidator; - import java.util.Arrays; import java.util.Collections; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.IntStream; -import static io.vavr.API.*; -import static org.junit.Assert.*; +import static io.vavr.API.$; +import static io.vavr.API.Case; +import static io.vavr.API.Match; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class VavrUnitTest { @Test public void givenList_whenSorts_thenCorrect() { List sortedList = List.of(3, 2, 1) - .sorted(); + .sorted(); } /* @@ -123,7 +127,7 @@ public class VavrUnitTest { @Test public void whenCreatesFunction_thenCorrect0() { Function0 getClazzName = () -> this.getClass() - .getName(); + .getName(); String clazzName = getClazzName.apply(); assertEquals("com.baeldung.vavr.VavrUnitTest", clazzName); } @@ -257,7 +261,7 @@ public class VavrUnitTest { public void whenSumsJava8List_thenCorrect() { // Arrays.asList(1, 2, 3).stream().reduce((i, j) -> i + j); int sum = IntStream.of(1, 2, 3) - .sum(); + .sum(); assertEquals(6, sum); } @@ -273,8 +277,8 @@ public class VavrUnitTest { @Test public void whenSumsVavrList_thenCorrect() { int sum = List.of(1, 2, 3) - .sum() - .intValue(); + .sum() + .intValue(); assertEquals(6, sum); } @@ -307,21 +311,21 @@ public class VavrUnitTest { int input = 2; String output; switch (input) { - case 0: - output = "zero"; - break; - case 1: - output = "one"; - break; - case 2: - output = "two"; - break; - case 3: - output = "three"; - break; - default: - output = "unknown"; - break; + case 0: + output = "zero"; + break; + case 1: + output = "one"; + break; + case 2: + output = "two"; + break; + case 3: + output = "three"; + break; + default: + output = "unknown"; + break; } assertEquals("two", output); } diff --git a/vavr/src/test/java/com/baeldung/vavr/collections/CollectionAPIUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/collections/CollectionAPIUnitTest.java index 9f0c48e3ee..4b4eb55fc5 100644 --- a/vavr/src/test/java/com/baeldung/vavr/collections/CollectionAPIUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/collections/CollectionAPIUnitTest.java @@ -1,17 +1,5 @@ package com.baeldung.vavr.collections; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.Comparator; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import org.junit.Test; - import io.vavr.Tuple; import io.vavr.Tuple2; import io.vavr.collection.Array; @@ -28,6 +16,17 @@ import io.vavr.collection.Stream; import io.vavr.collection.TreeMap; import io.vavr.collection.TreeSet; import io.vavr.collection.Vector; +import org.junit.Test; + +import java.util.Comparator; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; public class CollectionAPIUnitTest { @@ -234,7 +233,7 @@ public class CollectionAPIUnitTest { .toJavaMap(i -> Tuple.of(i, Integer.valueOf(i))); assertEquals(new Integer(2), map.get("2")); } - + @Test public void givenVavrList_whenCollected_thenCorrect() { java.util.Set javaSet = List.of(1, 2, 3) diff --git a/vavr/src/test/java/com/baeldung/vavr/either/EitherUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/either/EitherUnitTest.java index 6b0a34f9e4..155932888d 100644 --- a/vavr/src/test/java/com/baeldung/vavr/either/EitherUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/either/EitherUnitTest.java @@ -7,32 +7,32 @@ import static org.junit.Assert.assertEquals; public class EitherUnitTest { - @Test - public void givenMarks_whenPassNumber_thenExpectNumber() { - Either result = EitherDemo.computeWithEither(100); - int marks = result.right() - .getOrElseThrow(x -> new IllegalStateException()); + @Test + public void givenMarks_whenPassNumber_thenExpectNumber() { + Either result = EitherDemo.computeWithEither(100); + int marks = result.right() + .getOrElseThrow(x -> new IllegalStateException()); - assertEquals(100, marks); - } + assertEquals(100, marks); + } - @Test - public void givenMarks_whenFailNumber_thenExpectErrorMesssage() { - Either result = EitherDemo.computeWithEither(50); - String error = result.left() + @Test + public void givenMarks_whenFailNumber_thenExpectErrorMesssage() { + Either result = EitherDemo.computeWithEither(50); + String error = result.left() .getOrNull(); - assertEquals("Marks not acceptable", error); - } + assertEquals("Marks not acceptable", error); + } - @Test - public void givenPassMarks_whenModified_thenExpectNumber() { - Either result = EitherDemo.computeWithEither(90); - int marks = result.right() + @Test + public void givenPassMarks_whenModified_thenExpectNumber() { + Either result = EitherDemo.computeWithEither(90); + int marks = result.right() .map(x -> x * 2) .get(); - assertEquals(180, marks); - } + assertEquals(180, marks); + } } diff --git a/vavr/src/test/java/com/baeldung/vavr/exception/handling/VavrTryUnitTest.java b/vavr/src/test/java/com/baeldung/vavr/exception/handling/VavrTryUnitTest.java index 9c3e5a9cae..c7f17c2afc 100644 --- a/vavr/src/test/java/com/baeldung/vavr/exception/handling/VavrTryUnitTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/exception/handling/VavrTryUnitTest.java @@ -3,16 +3,18 @@ package com.baeldung.vavr.exception.handling; import com.baeldung.vavr.exception.handling.client.ClientException; import com.baeldung.vavr.exception.handling.client.HttpClient; import com.baeldung.vavr.exception.handling.client.Response; -import com.baeldung.vavr.exception.handling.VavrTry; - import io.vavr.collection.Stream; import io.vavr.control.Option; import io.vavr.control.Try; import org.junit.Test; -import static io.vavr.API.*; +import static io.vavr.API.$; +import static io.vavr.API.Case; +import static io.vavr.API.Match; import static io.vavr.Predicates.instanceOf; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; public class VavrTryUnitTest { @@ -26,8 +28,8 @@ public class VavrTryUnitTest { //when Try response = new VavrTry(httpClient).getResponse(); Integer chainedResult = response - .map(this::actionThatTakesResponse) - .getOrElse(defaultChainedResult); + .map(this::actionThatTakesResponse) + .getOrElse(defaultChainedResult); Stream stream = response.toStream().map(it -> it.id); //then @@ -49,8 +51,8 @@ public class VavrTryUnitTest { //when Try response = new VavrTry(httpClient).getResponse(); Integer chainedResult = response - .map(this::actionThatTakesResponse) - .getOrElse(defaultChainedResult); + .map(this::actionThatTakesResponse) + .getOrElse(defaultChainedResult); Option optionalResponse = response.toOption(); //then @@ -70,9 +72,9 @@ public class VavrTryUnitTest { //when Try recovered = new VavrTry(httpClient).getResponse() - .recover(r -> Match(r).of( - Case($(instanceOf(ClientException.class)), defaultResponse) - )); + .recover(r -> Match(r).of( + Case($(instanceOf(ClientException.class)), defaultResponse) + )); //then assertTrue(recovered.isFailure()); @@ -92,10 +94,10 @@ public class VavrTryUnitTest { //when Try recovered = new VavrTry(httpClient).getResponse() - .recover(r -> Match(r).of( - Case($(instanceOf(ClientException.class)), defaultResponse), - Case($(instanceOf(IllegalArgumentException.class)), defaultResponse) - )); + .recover(r -> Match(r).of( + Case($(instanceOf(ClientException.class)), defaultResponse), + Case($(instanceOf(IllegalArgumentException.class)), defaultResponse) + )); //then assertTrue(recovered.isSuccess()); @@ -106,7 +108,7 @@ public class VavrTryUnitTest { return response.id.hashCode(); } - public int actionThatTakesTryResponse(Try response, int defaultTransformation){ + public int actionThatTakesTryResponse(Try response, int defaultTransformation) { return response.transform(responses -> response.map(it -> it.id.hashCode()).getOrElse(defaultTransformation)); } diff --git a/vavr/src/test/java/com/baeldung/vavr/repositories/VavrRepositoryIntegrationTest.java b/vavr/src/test/java/com/baeldung/vavr/repositories/VavrRepositoryIntegrationTest.java index c2e9f377dd..63338afc24 100644 --- a/vavr/src/test/java/com/baeldung/vavr/repositories/VavrRepositoryIntegrationTest.java +++ b/vavr/src/test/java/com/baeldung/vavr/repositories/VavrRepositoryIntegrationTest.java @@ -3,18 +3,18 @@ package com.baeldung.vavr.repositories; import com.baeldung.Application; import com.baeldung.repositories.VavrUserRepository; import com.baeldung.vavr.User; - import io.vavr.collection.Seq; import io.vavr.control.Option; - -import org.junit.Test; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class)