From d0f06a63c422873069af578273072c8faf7ac72f Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Mon, 21 Oct 2019 07:11:24 +0200 Subject: [PATCH] TSK-925: refactored taskana-simplehistory-provider --- history/pom.xml | 225 +------------- .../taskana-simplehistory-provider/pom.xml | 287 +++++------------- .../impl/HistoryQueryImplTest.java | 2 +- .../impl/SimpleHistoryServiceImplTest.java | 101 +++--- 4 files changed, 121 insertions(+), 494 deletions(-) diff --git a/history/pom.xml b/history/pom.xml index 4f9538fcf..5cbe7dea6 100644 --- a/history/pom.xml +++ b/history/pom.xml @@ -3,11 +3,10 @@ 4.0.0 pro.taskana.simplehistory taskana-simplehistory-parent - 1.1.5-SNAPSHOT pom + ${project.groupId}:${project.artifactId} The taskana history events plugin parent and bom module. - http://taskana.pro pro.taskana @@ -23,226 +22,4 @@ taskana-simplehistory-rest-spring-example - - UTF-8 - UTF-8 - - 1.8 - - 1.8 - 1.8 - - 5.0.5.RELEASE - 2.0.2.RELEASE - - 1.4.197 - 4.12 - - - - - Holger Hagen - holger.hagen@novatec-gmbh.de - NovaTec Consulting GmbH - https://www.novatec-gmbh.de - - - - - http://github.com/taskana/TaskanaSimpleHistory/tree/master - scm:git:git://github.com/taskana/TaskanaSimpleHistory.git - scm:git:ssh://github.com:taskana/TaskanaSimpleHistory.git - - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - snapshot - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - false - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - release - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - false - - - - - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - [1.0.0,) - - check - - - - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - validate - validate - - ../qa/checkstyle/checkstyle.xml - UTF-8 - true - true - true - true - - - check - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - true - - -Xlint:all - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - - attach-javadocs - - jar - - - - - - - - - - snapshots-repo - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - diff --git a/history/taskana-simplehistory-provider/pom.xml b/history/taskana-simplehistory-provider/pom.xml index 4960bc554..58844772d 100644 --- a/history/taskana-simplehistory-provider/pom.xml +++ b/history/taskana-simplehistory-provider/pom.xml @@ -1,223 +1,76 @@ - - 4.0.0 - taskana-simplehistory-provider + + 4.0.0 + taskana-simplehistory-provider - ${project.groupId}:${project.artifactId} - The taskana history events plugin to include in your project. - http://taskana.pro + ${project.groupId}:${project.artifactId} + The taskana history events plugin to include in your project. - - pro.taskana.simplehistory - taskana-simplehistory-parent - 1.1.5-SNAPSHOT - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + pro.taskana.simplehistory + taskana-simplehistory-parent + 1.1.5-SNAPSHOT + - - - Holger Hagen - holger.hagen@novatec-gmbh.de - NovaTec Consulting GmbH - https://www.novatec-gmbh.de - - + + + pro.taskana + taskana-core + ${project.version} + + + org.slf4j + slf4j-api + ${version.slf4j} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${version.log4j} + test + + + org.apache.logging.log4j + log4j-core + ${version.log4j} + test + + + org.mybatis + mybatis + ${version.mybatis} + + + junit + junit + ${version.junit} + + + org.powermock + powermock-api-mockito2 + ${version.powermock} + test + + + org.powermock + powermock-module-junit4 + ${version.powermock} + test + + + org.mockito + mockito-core + ${version.mockito} + test + - - scm:git:git://github.com/taskana/TaskanaSimpleHistory.git - scm:git:ssh://github.com:taskana/TaskanaSimpleHistory.git - http://github.com/taskana/TaskanaSimpleHistory/tree/master - - - - - snapshot - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - false - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - release - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - false - - - - - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - true - - -Xlint:all - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - - attach-javadocs - - jar - - - - - - - - - pro.taskana - taskana-core - ${project.version} - - - org.slf4j - slf4j-api - 1.7.22 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.8.1 - test - - - org.apache.logging.log4j - log4j-core - 2.8.1 - test - - - org.mybatis - mybatis - 3.4.6 - - - org.mockito - mockito-core - 1.10.19 - test - - - junit - junit - ${version.junit} - - - org.powermock - powermock-api-mockito - 1.6.2 - test - - - org.powermock - powermock-module-junit4 - 1.6.2 - test - - - com.h2database - h2 - ${version.h2} - test - - + + com.h2database + h2 + ${version.h2} + test + + diff --git a/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/HistoryQueryImplTest.java b/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/HistoryQueryImplTest.java index f46375838..c4ea15c1c 100644 --- a/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/HistoryQueryImplTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/HistoryQueryImplTest.java @@ -14,7 +14,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import pro.taskana.TimeInterval; import pro.taskana.simplehistory.impl.mappings.HistoryQueryMapper; diff --git a/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/SimpleHistoryServiceImplTest.java b/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/SimpleHistoryServiceImplTest.java index 08219f9d2..6a9239cea 100644 --- a/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/SimpleHistoryServiceImplTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/pro/taskana/simplehistory/impl/SimpleHistoryServiceImplTest.java @@ -1,8 +1,8 @@ package pro.taskana.simplehistory.impl; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; @@ -58,68 +58,65 @@ public class SimpleHistoryServiceImplTest { @Mock private SqlSessionManager sqlSessionManagerMock; - @Mock - private HistoryQueryImpl historyQueryMock; - @Before public void setup() { MockitoAnnotations.initMocks(this); } - @Test - public void testInitializeSimpleHistoryService() throws SQLException { + @Test + public void testInitializeSimpleHistoryService() throws SQLException { + doReturn(historyEventMapperMock).when(sqlSessionManagerMock).getMapper(HistoryEventMapper.class); + doReturn(historyQueryMapperMock).when(sqlSessionManagerMock).getMapper(HistoryQueryMapper.class); + doReturn(sqlSessionManagerMock).when(taskanaHistoryEngineMock).getSqlSession(); + PowerMockito.mockStatic(TaskanaHistoryEngineImpl.class); + Mockito.when(TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration)) + .thenReturn(taskanaHistoryEngineMock); + cutSpy.initialize(taskanaEngineConfiguration); - doReturn(historyEventMapperMock).when(sqlSessionManagerMock).getMapper(HistoryEventMapper.class); - doReturn(historyQueryMapperMock).when(sqlSessionManagerMock).getMapper(HistoryQueryMapper.class); - doReturn(sqlSessionManagerMock).when(taskanaHistoryEngineMock).getSqlSession(); - PowerMockito.mockStatic(TaskanaHistoryEngineImpl.class); - Mockito.when(TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration)).thenReturn(taskanaHistoryEngineMock); - cutSpy.initialize(taskanaEngineConfiguration); + verify(sqlSessionManagerMock, times(2)).getMapper(any()); + verify(taskanaHistoryEngineMock, times(2)).getSqlSession(); + } - verify(sqlSessionManagerMock, times(2)).getMapper(any()); - verify(taskanaHistoryEngineMock, times(2)).getSqlSession(); - PowerMockito.verifyStatic(); - } + @Test + public void testInitializeSimpleHistoryServiceWithNonDefaultSchemaName() throws SQLException { - @Test - public void testInitializeSimpleHistoryServiceWithNonDefaultSchemaName() throws SQLException { + doReturn(historyEventMapperMock).when(sqlSessionManagerMock).getMapper(HistoryEventMapper.class); + doReturn(historyQueryMapperMock).when(sqlSessionManagerMock).getMapper(HistoryQueryMapper.class); + doReturn(sqlSessionManagerMock).when(taskanaHistoryEngineMock).getSqlSession(); + PowerMockito.mockStatic(TaskanaHistoryEngineImpl.class); + Mockito.when(TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration)) + .thenReturn(taskanaHistoryEngineMock); + cutSpy.initialize(taskanaEngineConfiguration); - doReturn(historyEventMapperMock).when(sqlSessionManagerMock).getMapper(HistoryEventMapper.class); - doReturn(historyQueryMapperMock).when(sqlSessionManagerMock).getMapper(HistoryQueryMapper.class); - doReturn(sqlSessionManagerMock).when(taskanaHistoryEngineMock).getSqlSession(); - PowerMockito.mockStatic(TaskanaHistoryEngineImpl.class); - Mockito.when(TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration)).thenReturn(taskanaHistoryEngineMock); - cutSpy.initialize(taskanaEngineConfiguration); + verify(sqlSessionManagerMock, times(2)).getMapper(any()); + verify(taskanaHistoryEngineMock, times(2)).getSqlSession(); + } - verify(sqlSessionManagerMock, times(2)).getMapper(any()); - verify(taskanaHistoryEngineMock, times(2)).getSqlSession(); - PowerMockito.verifyStatic(); - } + @Test + public void testCreateEvent() throws SQLException { + HistoryEventImpl expectedWb = AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", + "wbKey2"); + doNothing().when(historyEventMapperMock).insert(expectedWb); - @Test - public void testCreateEvent() throws SQLException { - HistoryEventImpl expectedWb = AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2"); - doNothing().when(historyEventMapperMock).insert(expectedWb); + cutSpy.create(expectedWb); + verify(taskanaHistoryEngineMock, times(1)).openConnection(); + verify(historyEventMapperMock, times(1)).insert(expectedWb); + verify(taskanaHistoryEngineMock, times(1)).returnConnection(); + assertNotNull(expectedWb.getCreated()); + } - cutSpy.create(expectedWb); - verify(taskanaHistoryEngineMock, times(1)).openConnection(); - verify(historyEventMapperMock, times(1)).insert(expectedWb); - verify(taskanaHistoryEngineMock, times(1)).returnConnection(); - assertTrue(expectedWb.getCreated() != null); - } + @Test + public void testQueryEvent() throws SQLException { + List returnList = new ArrayList<>(); + returnList.add(AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2")); + doReturn(returnList).when(historyQueryMapperMock).queryHistoryEvent(any()); - @Test - public void testQueryEvent() throws SQLException { - List returnList = new ArrayList<>(); - returnList.add(AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2")); - doReturn(returnList).when(historyQueryMapperMock).queryHistoryEvent(any()); + List result = cutSpy.createHistoryQuery().taskIdIn("taskId1").list(); - List result = cutSpy.createHistoryQuery().taskIdIn("taskId1").list(); - - verify(taskanaHistoryEngineMock, times(1)).openConnection(); - verify(historyQueryMapperMock, times(1)).queryHistoryEvent(any()); - verify(taskanaHistoryEngineMock, times(1)).returnConnection(); - assertEquals(returnList.size(), result.size()); - assertEquals(returnList.get(0).getWorkbasketKey(), result.get(0).getWorkbasketKey()); - } + verify(taskanaHistoryEngineMock, times(1)).openConnection(); + verify(historyQueryMapperMock, times(1)).queryHistoryEvent(any()); + verify(taskanaHistoryEngineMock, times(1)).returnConnection(); + assertEquals(returnList.size(), result.size()); + assertEquals(returnList.get(0).getWorkbasketKey(), result.get(0).getWorkbasketKey()); + } }