TSK-1142 Removed JUnit4 dependency in taskana-simplehistory-provider

This commit is contained in:
Sofie Hofmann 2020-03-05 15:44:39 +01:00
parent 32d069ac97
commit 6c6a278b08
8 changed files with 137 additions and 185 deletions

View File

@ -64,21 +64,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${version.junit.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${version.powermock}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${version.powermock}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${version.junit.mockito}</version>
<scope>test</scope>
</dependency>
<dependency>
@ -93,5 +81,5 @@
<version>${version.h2}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
</project>

View File

@ -23,8 +23,7 @@ public class SimpleHistoryServiceImpl implements TaskanaHistory {
@Override
public void initialize(TaskanaEngineConfiguration taskanaEngineConfiguration) {
try {
this.taskanaHistoryEngine =
TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration);
this.taskanaHistoryEngine = getTaskanaEngine(taskanaEngineConfiguration);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Simple history service implementation initialized with schemaName: {} ",
@ -59,4 +58,12 @@ public class SimpleHistoryServiceImpl implements TaskanaHistory {
public HistoryQuery createHistoryQuery() {
return new HistoryQueryImpl(taskanaHistoryEngine, historyQueryMapper);
}
/*
* ATTENTION: This method exists for testing purposes.
*/
TaskanaHistoryEngineImpl getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration)
throws SQLException {
return TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngineConfiguration);
}
}

View File

@ -11,7 +11,7 @@ import java.util.Objects;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,7 +45,7 @@ public class AbstractAccTest {
// not called
}
@BeforeClass
@BeforeAll
public static void setupTest() throws Exception {
resetDb(null);
}

View File

@ -1,20 +1,19 @@
package acceptance.query;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import acceptance.AbstractAccTest;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import pro.taskana.common.api.BaseQuery.SortDirection;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.simplehistory.impl.HistoryEventImpl;
import pro.taskana.simplehistory.query.HistoryQuery;
import pro.taskana.simplehistory.query.HistoryQueryColumnName;
import pro.taskana.spi.history.api.events.TaskanaHistoryEvent;
/** Test for History queries. */
public class QueryHistoryAccTest extends AbstractAccTest {
@ -31,14 +30,17 @@ public class QueryHistoryAccTest extends AbstractAccTest {
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.ASCENDING);
assertThat(ascendingList).hasSize(3);
assertThat(ascendingList).isEqualTo(defaultList);
List<String> descendingList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.DESCENDING);
Collections.reverse(ascendingList);
assertEquals(3, ascendingList.size());
assertArrayEquals(defaultList.toArray(), ascendingList.toArray());
assertEquals(ascendingList.get(2), descendingList.get(0));
assertThat(ascendingList).isEqualTo(descendingList);
}
@Test
@ -51,15 +53,14 @@ public class QueryHistoryAccTest extends AbstractAccTest {
.orderByCreated(SortDirection.DESCENDING);
List<HistoryEventImpl> results = query.list();
assertEquals(2, results.size());
assertEquals("admin", results.get(0).getUserId());
assertEquals("peter", results.get(1).getUserId());
assertThat(results)
.extracting(TaskanaHistoryEvent::getUserId)
.containsExactly("admin", "peter");
results = query.orderByUserId(SortDirection.DESCENDING).list();
assertEquals(2, results.size());
assertEquals("admin", results.get(0).getUserId());
assertEquals("peter", results.get(1).getUserId());
assertEquals(3, query.domainLike().count());
assertThat(results)
.extracting(TaskanaHistoryEvent::getUserId)
.containsExactly("admin", "peter");
assertThat(query.domainLike().count()).isEqualTo(3);
}
@Test
@ -67,300 +68,299 @@ public class QueryHistoryAccTest extends AbstractAccTest {
List<HistoryEventImpl> result = getHistoryService().createHistoryQuery().list(1, 2);
List<HistoryEventImpl> wrongList = getHistoryService().createHistoryQuery().list();
assertEquals(2, result.size());
assertNotEquals(wrongList.get(0).getUserId(), result.get(0).getUserId());
assertEquals(wrongList.get(1).getUserId(), result.get(0).getUserId());
assertThat(result).hasSize(2);
assertThat(result.get(0).getUserId()).isNotEqualTo(wrongList.get(0).getUserId());
assertThat(result.get(0).getUserId()).isEqualTo(wrongList.get(1).getUserId());
}
@Test
public void testCorrectResultWithWrongConstraints() {
List<HistoryEventImpl> result = getHistoryService().createHistoryQuery().list(1, 1000);
assertEquals(2, result.size());
assertEquals("created by Peter", result.get(0).getComment());
assertThat(result).hasSize(2);
assertThat(result.get(0).getComment()).isEqualTo("created by Peter");
result = getHistoryService().createHistoryQuery().list(100, 1000);
assertTrue(result.isEmpty());
assertThat(result).isEmpty();
}
@Test
public void testSingle() {
HistoryEventImpl single = getHistoryService().createHistoryQuery().userIdIn("peter").single();
assertEquals("CREATE", single.getEventType());
assertThat(single.getEventType()).isEqualTo("CREATE");
single = getHistoryService().createHistoryQuery().eventTypeIn("CREATE", "xy").single();
assertEquals("admin", single.getUserId());
assertThat(single.getUserId()).isEqualTo("admin");
}
@Test
public void testCount() {
long count = getHistoryService().createHistoryQuery().userIdIn("peter").count();
assertEquals(1, count);
assertThat(count).isOne();
count = getHistoryService().createHistoryQuery().count();
assertEquals(3, count);
assertThat(count).isEqualTo(3);
count = getHistoryService().createHistoryQuery().userIdIn("klaus", "arnold", "benni").count();
assertEquals(0, count);
assertThat(count).isZero();
}
@Test
public void testQueryAttributesIn() {
List<HistoryEventImpl> returnValues =
getHistoryService().createHistoryQuery().businessProcessIdIn("BPI:01", "BPI:02").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues =
getHistoryService().createHistoryQuery().parentBusinessProcessIdIn("BPI:01").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues =
getHistoryService()
.createHistoryQuery()
.taskIdIn("TKI:000000000000000000000000000000000000")
.list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().eventTypeIn("CREATE").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
returnValues = getHistoryService().createHistoryQuery().createdWithin(timeInterval).list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().userIdIn("admin").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().domainIn("DOMAIN_A").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues =
getHistoryService()
.createHistoryQuery()
.workbasketKeyIn("WBI:100000000000000000000000000000000001")
.list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().porCompanyIn("00").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().porSystemIn("PASystem").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().porInstanceIn("22").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().porTypeIn("VN").list();
assertEquals(0, returnValues.size());
assertThat(returnValues).isEmpty();
returnValues = getHistoryService().createHistoryQuery().porValueIn("11223344").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues =
getHistoryService().createHistoryQuery().taskClassificationKeyIn("L140101").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues =
getHistoryService().createHistoryQuery().taskClassificationCategoryIn("TASK").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues =
getHistoryService()
.createHistoryQuery()
.attachmentClassificationKeyIn("DOCTYPE_DEFAULT")
.list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().custom1In("custom1").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues = getHistoryService().createHistoryQuery().custom2In("custom2").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().custom3In("custom3").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().custom4In("custom4").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().commentIn("created a bug").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().oldValueIn("old_val").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().newValueIn("new_val").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().oldDataIn("123").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().newDataIn("456").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues = getHistoryService().createHistoryQuery().oldValueLike("old%").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().newValueLike("new_%").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().oldDataLike("%23%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues = getHistoryService().createHistoryQuery().newDataLike("456%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
}
@Test
public void testSomeLikeMethods() {
List<HistoryEventImpl> returnValues =
getHistoryService().createHistoryQuery().businessProcessIdLike("BPI:0%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues =
getHistoryService().createHistoryQuery().parentBusinessProcessIdLike("BPI:01", " %").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues =
getHistoryService().createHistoryQuery().taskIdLike("TKI:000000000000000%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues = getHistoryService().createHistoryQuery().oldValueLike("old%").list();
assertEquals(1, returnValues.size());
assertThat(returnValues).hasSize(1);
returnValues = getHistoryService().createHistoryQuery().newValueLike("new_%").list();
assertEquals(2, returnValues.size());
assertThat(returnValues).hasSize(2);
returnValues = getHistoryService().createHistoryQuery().oldDataLike("%23%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
returnValues = getHistoryService().createHistoryQuery().newDataLike("456%").list();
assertEquals(3, returnValues.size());
assertThat(returnValues).hasSize(3);
}
@Test
public void testListValues() {
List<String> returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.ID, null);
assertEquals(3, returnedList.size());
assertThat(returnedList).hasSize(3);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.BUSINESS_PROCESS_ID, null);
assertEquals(3, returnedList.size());
assertThat(returnedList).hasSize(3);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.PARENT_BUSINESS_PROCESS_ID, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.TASK_ID, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.EVENT_TYPE, null);
assertEquals(1, returnedList.size());
assertThat(returnedList).hasSize(1);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CREATED, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.USER_ID, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.DOMAIN, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.WORKBASKET_KEY, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.POR_COMPANY, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.POR_SYSTEM, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.POR_INSTANCE, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.POR_TYPE, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.POR_VALUE, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_KEY, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_CATEGORY, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService()
.createHistoryQuery()
.listValues(HistoryQueryColumnName.ATTACHMENT_CLASSIFICATION_KEY, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.COMMENT, null);
assertEquals(3, returnedList.size());
assertThat(returnedList).hasSize(3);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.OLD_VALUE, null);
assertEquals(3, returnedList.size());
assertThat(returnedList).hasSize(3);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.NEW_VALUE, null);
assertEquals(3, returnedList.size());
assertThat(returnedList).hasSize(3);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_1, null);
assertEquals(1, returnedList.size());
assertThat(returnedList).hasSize(1);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_2, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_3, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_4, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.OLD_DATA, null);
assertEquals(2, returnedList.size());
assertThat(returnedList).hasSize(2);
returnedList =
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.NEW_DATA, null);
assertEquals(1, returnedList.size());
assertThat(returnedList).hasSize(1);
}
}

View File

@ -1,12 +1,11 @@
package configuration;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import acceptance.AbstractAccTest;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import pro.taskana.TaskanaEngineConfiguration;
import pro.taskana.common.api.TaskanaEngine;
@ -26,19 +25,19 @@ public class TaskanaEngineConfigurationTest extends AbstractAccTest {
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
Assert.assertNotNull(te);
assertThat(te).isNotNull();
}
@Test
public void testCreateTaskanaHistoryEventWithNonDefaultSchemaName() throws SQLException {
resetDb("SOMECUSTOMSCHEMANAME");
long count = getHistoryService().createHistoryQuery().workbasketKeyIn("wbKey1").count();
assertEquals(0, count);
assertThat(count).isZero();
getHistoryService()
.create(
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2","someUserId"));
count = getHistoryService().createHistoryQuery().workbasketKeyIn("wbKey1").count();
assertEquals(1, count);
assertThat(count).isOne();
}
}

View File

@ -1,6 +1,6 @@
package pro.taskana.simplehistory.impl;
import static org.junit.Assert.assertArrayEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.validateMockitoUsage;
@ -9,11 +9,11 @@ import java.sql.SQLException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.simplehistory.impl.mappings.HistoryQueryMapper;
@ -23,7 +23,7 @@ import pro.taskana.simplehistory.impl.mappings.HistoryQueryMapper;
*
* @author BV
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class HistoryQueryImplTest {
private HistoryQueryImpl historyQueryImpl;
@ -32,7 +32,7 @@ public class HistoryQueryImplTest {
@Mock private HistoryQueryMapper historyQueryMock;
@Before
@BeforeEach
public void setup() {
historyQueryImpl = new HistoryQueryImpl(taskanaHistoryEngineMock, historyQueryMock);
}
@ -58,7 +58,7 @@ public class HistoryQueryImplTest {
.list();
validateMockitoUsage();
assertArrayEquals(returnList.toArray(), result.toArray());
assertThat(result).isEqualTo(returnList);
}
private HistoryEventImpl createHistoryEvent(

View File

@ -1,45 +1,33 @@
package pro.taskana.simplehistory.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import acceptance.AbstractAccTest;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.session.SqlSessionManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import pro.taskana.TaskanaEngineConfiguration;
import pro.taskana.simplehistory.impl.mappings.HistoryEventMapper;
import pro.taskana.simplehistory.impl.mappings.HistoryQueryMapper;
/**
* Unit Test for SimpleHistoryServiceImplTest.
*
* @author MMR
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(TaskanaHistoryEngineImpl.class)
@PowerMockIgnore("javax.management.*")
/** Unit Test for SimpleHistoryServiceImplTest. */
@ExtendWith(MockitoExtension.class)
public class SimpleHistoryServiceImplTest {
@InjectMocks private SimpleHistoryServiceImpl cutSpy;
@InjectMocks @Spy private SimpleHistoryServiceImpl cutSpy;
@Mock private HistoryEventMapper historyEventMapperMock;
@ -51,42 +39,14 @@ public class SimpleHistoryServiceImplTest {
@Mock private SqlSessionManager sqlSessionManagerMock;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@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);
verify(sqlSessionManagerMock, times(2)).getMapper(any());
verify(taskanaHistoryEngineMock, times(2)).getSqlSession();
}
@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);
when(sqlSessionManagerMock.getMapper(HistoryEventMapper.class))
.thenReturn(historyEventMapperMock);
when(sqlSessionManagerMock.getMapper(HistoryQueryMapper.class))
.thenReturn(historyQueryMapperMock);
when(taskanaHistoryEngineMock.getSqlSession()).thenReturn(sqlSessionManagerMock);
doReturn(taskanaHistoryEngineMock).when(cutSpy).getTaskanaEngine(taskanaEngineConfiguration);
cutSpy.initialize(taskanaEngineConfiguration);
verify(sqlSessionManagerMock, times(2)).getMapper(any());
@ -98,13 +58,12 @@ public class SimpleHistoryServiceImplTest {
HistoryEventImpl expectedWb =
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2", "someUserId");
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());
assertThat(expectedWb.getCreated()).isNotNull();
}
@Test
@ -113,14 +72,14 @@ public class SimpleHistoryServiceImplTest {
returnList.add(
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2", "someUserId"));
doReturn(returnList).when(historyQueryMapperMock).queryHistoryEvent(any());
when(historyQueryMapperMock.queryHistoryEvent(any())).thenReturn(returnList);
final List<HistoryEventImpl> 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());
assertThat(result).hasSize(returnList.size());
assertThat(result.get(0).getWorkbasketKey()).isEqualTo(returnList.get(0).getWorkbasketKey());
}
}

View File

@ -82,7 +82,6 @@
spring mock tests see LdapClientTest -->
<version.byte-buddy>1.10.8</version.byte-buddy>
<version.byte-buddy-agent>1.10.8</version.byte-buddy-agent>
<version.powermock>2.0.5</version.powermock>
<version.hamcrest>2.2</version.hamcrest>
<version.equalsverifier>3.1.12</version.equalsverifier>
<version.openpojo>0.8.13</version.openpojo>