diff --git a/ci/test.sh b/ci/test.sh index a74ebf5b0..42480d21a 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -30,6 +30,7 @@ function main { (cd $REL/../web && npm run test) mvn clean verify -q -f $REL/../lib/ -B mvn clean install -q -f $REL/../rest/ -B + mvn clean verify -q -f $REL/../rest/ -B -pl taskana-rest-spring-example -P history.plugin else mvn clean verify -q -f $REL/../lib/taskana-core -B fi diff --git a/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java b/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java index 81d392a15..ed99b1d5f 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java +++ b/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java @@ -22,7 +22,6 @@ public final class HistoryEventProducer { private ServiceLoader serviceLoader; private boolean enabled = false; - public static synchronized HistoryEventProducer getInstance(TaskanaEngineConfiguration taskanaEngineConfiguration) { if (emitterInstance == null) { emitterInstance = new HistoryEventProducer(taskanaEngineConfiguration); diff --git a/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskCompletionEvent.java b/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskCompletionEvent.java index 7aab982c2..149a06b19 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskCompletionEvent.java +++ b/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskCompletionEvent.java @@ -11,7 +11,6 @@ public class TaskCompletionEvent extends TaskHistoryEvent { super(completedTask); type = "TASK_COMPLETED"; created = completedTask.getCompleted(); - } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskHistoryEvent.java b/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskHistoryEvent.java index d65543131..c517a0f33 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskHistoryEvent.java +++ b/lib/taskana-core/src/main/java/pro/taskana/history/api/TaskHistoryEvent.java @@ -33,11 +33,13 @@ public class TaskHistoryEvent extends TaskanaHistoryEvent { if (!task.getAttachments().isEmpty()) { attachmentClassificationKey = task.getAttachments().get(0).getClassificationSummary().getKey(); } - porCompany = task.getPrimaryObjRef().getCompany(); - porSystem = task.getPrimaryObjRef().getSystem(); - porInstance = task.getPrimaryObjRef().getSystemInstance(); - porType = task.getPrimaryObjRef().getType(); - porValue = task.getPrimaryObjRef().getValue(); + if (task.getPrimaryObjRef() != null) { + porCompany = task.getPrimaryObjRef().getCompany(); + porSystem = task.getPrimaryObjRef().getSystem(); + porInstance = task.getPrimaryObjRef().getSystemInstance(); + porType = task.getPrimaryObjRef().getType(); + porValue = task.getPrimaryObjRef().getValue(); + } } public String getTaskId() { diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java index f3b98578b..05c821d85 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java @@ -223,10 +223,8 @@ public class TaskServiceImpl implements TaskService { task.setOwner(userId); taskMapper.update(task); LOGGER.debug("Task '{}' completed by user '{}'.", taskId, userId); - if (HistoryEventProducer.isHistoryEnabled()) { - TaskCompletionEvent event = new TaskCompletionEvent(task); - historyEventProducer.createEvent(event); + historyEventProducer.createEvent(new TaskCompletionEvent(task)); } } finally { diff --git a/lib/taskana-core/src/test/java/acceptance/history/HistoryEventProducerTest.java b/lib/taskana-core/src/test/java/acceptance/history/HistoryEventProducerTest.java new file mode 100644 index 000000000..b7cd854a0 --- /dev/null +++ b/lib/taskana-core/src/test/java/acceptance/history/HistoryEventProducerTest.java @@ -0,0 +1,21 @@ +package acceptance.history; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import acceptance.AbstractAccTest; +import pro.taskana.history.HistoryEventProducer; +import pro.taskana.impl.TaskanaEngineImpl; + +/** + * Acceptance test for historyEventProducer class. + */ +public class HistoryEventProducerTest extends AbstractAccTest { + + @Test + public void testHistoryEventProducerIsNotEnabled() { + HistoryEventProducer historyEventProducer = ((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer(); + assertEquals(false, historyEventProducer.isEnabled()); + } +} diff --git a/lib/taskana-spring-example/pom.xml b/lib/taskana-spring-example/pom.xml index 8dc9431ea..c7862164d 100644 --- a/lib/taskana-spring-example/pom.xml +++ b/lib/taskana-spring-example/pom.xml @@ -1,80 +1,78 @@ - 4.0.0 - pro.taskana - taskana-spring-example - 1.0.5-SNAPSHOT - - org.springframework.boot - spring-boot-starter-parent - 2.0.2.RELEASE - - - - - 1.8 - 1.8 - UTF-8 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-jdbc - - - org.springframework - spring-tx - - - com.h2database - h2 - - - org.springframework.boot - spring-boot-starter-test - - - pro.taskana - taskana-core - ${project.version} - - - pro.taskana - taskana-spring - ${project.version} - - - junit - junit - 4.12 - test - - - org.hamcrest - hamcrest-library - 1.3 - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - ${project.groupId}:${project.artifactId} - http://taskana.pro - The Taskana Spring sample application. + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + pro.taskana + taskana-spring-example + 1.0.5-SNAPSHOT + + org.springframework.boot + spring-boot-starter-parent + 2.0.2.RELEASE + + + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework + spring-tx + + + com.h2database + h2 + + + org.springframework.boot + spring-boot-starter-test + + + pro.taskana + taskana-core + ${project.version} + + + pro.taskana + taskana-spring + ${project.version} + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + ${project.groupId}:${project.artifactId} + http://taskana.pro + The Taskana Spring sample application. diff --git a/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionTest.java b/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java similarity index 98% rename from lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionTest.java rename to lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java index dfc7e37f3..0ab53721f 100644 --- a/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionTest.java +++ b/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java @@ -8,7 +8,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -23,11 +22,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatcher; import org.mockito.Captor; import org.mockito.Mock; import org.slf4j.LoggerFactory; -import org.slf4j.event.Level; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -37,8 +34,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.LoggingEvent; import ch.qos.logback.core.Appender; import pro.taskana.exceptions.DomainNotFoundException; @@ -47,6 +42,7 @@ import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.TaskanaException; import pro.taskana.exceptions.WorkbasketAlreadyExistException; import pro.taskana.exceptions.WorkbasketNotFoundException; +import pro.taskana.history.HistoryEventProducer; import pro.taskana.impl.TaskImpl; import pro.taskana.impl.TaskanaEngineImpl; import pro.taskana.impl.WorkbasketImpl; @@ -63,7 +59,7 @@ import pro.taskana.transaction.TaskanaTransactionProvider; webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles({"inmemorydb", "dev"}) @Import({TransactionalJobsConfiguration.class}) -public class TaskanaTransactionTest { +public class TaskanaTransactionIntTest { private static final int POOL_TIME_TO_WAIT = 50; diff --git a/rest/taskana-rest-spring-example/pom.xml b/rest/taskana-rest-spring-example/pom.xml index ddc5589c2..0f731de45 100644 --- a/rest/taskana-rest-spring-example/pom.xml +++ b/rest/taskana-rest-spring-example/pom.xml @@ -35,6 +35,42 @@ 2.3.2.RELEASE + + + history.plugin + + false + + + history.plugin + + + + pro.taskana.simplehistory + taskana-simplehistory-provider + 0.0.4 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + **/*Plugin*Test.java + + + **/Test/*.java + + + + + + + + pro.taskana @@ -67,7 +103,7 @@ h2 1.4.197 - + com.ibm.db2.jcc db2jcc4 @@ -134,6 +170,18 @@ spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + **/*Plugin*Test.java + + + + org.apache.maven.plugins diff --git a/rest/taskana-rest-spring-example/src/test/java/pro/taskana/historyPlugin/HistoryPluginLoaderTest.java b/rest/taskana-rest-spring-example/src/test/java/pro/taskana/historyPlugin/HistoryPluginLoaderTest.java new file mode 100644 index 000000000..0663737fc --- /dev/null +++ b/rest/taskana-rest-spring-example/src/test/java/pro/taskana/historyPlugin/HistoryPluginLoaderTest.java @@ -0,0 +1,38 @@ +package pro.taskana.historyPlugin; + +import static org.junit.Assert.assertEquals; + +import javax.sql.DataSource; + +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.jdbc.core.JdbcTemplate; +import org.springframework.test.context.junit4.SpringRunner; + +import pro.taskana.TaskanaEngine; +import pro.taskana.history.HistoryEventProducer; +import pro.taskana.impl.TaskanaEngineImpl; +import pro.taskana.rest.RestConfiguration; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestConfiguration.class) +public class HistoryPluginLoaderTest { + + @Autowired + private DataSource dataSource; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private TaskanaEngine taskanaEngine; + + @Test + public void testHistoryEventProducerIsEnabled() { + HistoryEventProducer historyEventProducer = ((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer(); + assertEquals(historyEventProducer.isEnabled(), true); + } + +} diff --git a/rest/taskana-rest-spring-example/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java b/rest/taskana-rest-spring-example/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java index 1f5554e9c..46505bd9c 100644 --- a/rest/taskana-rest-spring-example/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java +++ b/rest/taskana-rest-spring-example/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -86,6 +85,8 @@ public class AsyncUpdateJobIntTest { // 1st step: get old classification : Instant before = Instant.now(); + ObjectMapper mapper = new ObjectMapper(); + String updatedClassification; ResponseEntity response = template.exchange( "http://127.0.0.1:" + port + "/v1/classifications/CLI:100000000000000000000000000000000003", @@ -103,7 +104,7 @@ public class AsyncUpdateJobIntTest { classification.setServiceLevel("P5D"); classification.setPriority(1000); - String updatedClassification = new JSONObject(classification).toString(); + updatedClassification = mapper.writeValueAsString(classification); URL url = new URL(server + port + "/v1/classifications/CLI:100000000000000000000000000000000003"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); @@ -201,7 +202,7 @@ public class AsyncUpdateJobIntTest { converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json")); converter.setObjectMapper(mapper); - RestTemplate template = new RestTemplate(Collections.> singletonList(converter)); + RestTemplate template = new RestTemplate(Collections.>singletonList(converter)); return template; }