diff options
author | kooper <sergey.sachkov@est.tech> | 2019-05-15 10:39:07 +0000 |
---|---|---|
committer | kooper <sergey.sachkov@est.tech> | 2019-05-15 10:39:07 +0000 |
commit | 02a3b49bec86eb0a434afb86e158ca2670cb718f (patch) | |
tree | b24193003058bb85db012172fae19e2dc31a10b4 /openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main | |
parent | 19493ec749d39407c90e841a2f3e503f6a03ecd7 (diff) |
Update test coverage
Change-Id: Ib92d00266d17635b53593eaa544ca3b312c7ddb2
Issue-ID: SDC-2310
Signed-off-by: kooper <sergey.sachkov@est.tech>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main')
3 files changed, 121 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogDaoStub.java b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogDaoStub.java new file mode 100644 index 0000000000..438c8cb986 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogDaoStub.java @@ -0,0 +1,37 @@ +package org.openecomp.sdc.activitylog.impl; + +import org.openecomp.sdc.activitylog.dao.ActivityLogDao; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class ActivityLogDaoStub implements ActivityLogDao { + @Override + public Collection<ActivityLogEntity> list(ActivityLogEntity entity) { + List<ActivityLogEntity> list = new ArrayList<>(); + list.add(entity); + return list; + } + + @Override + public void create(ActivityLogEntity entity) { + //stub method + } + + @Override + public void update(ActivityLogEntity entity) { + //stub method + } + + @Override + public ActivityLogEntity get(ActivityLogEntity entity) { + return null; + } + + @Override + public void delete(ActivityLogEntity entity) { + //stub method + } +} diff --git a/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerFactoryImplTest.java b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerFactoryImplTest.java new file mode 100644 index 0000000000..7bf8028352 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerFactoryImplTest.java @@ -0,0 +1,41 @@ +package org.openecomp.sdc.activitylog.impl; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openecomp.sdc.activitylog.ActivityLogManager; +import org.openecomp.sdc.activitylog.dao.ActivityLogDao; +import org.openecomp.sdc.activitylog.dao.ActivityLogDaoFactory; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.MockitoAnnotations.initMocks; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(ActivityLogDaoFactory.class) +public class ActivityLogManagerFactoryImplTest { + + @Mock + ActivityLogDaoFactory activityLogDaoFactory; + @Mock + ActivityLogDao activityLogDao; + + @Before + public void setUp(){ + initMocks(this); + PowerMockito.mockStatic(ActivityLogDaoFactory.class); + when(ActivityLogDaoFactory.getInstance()).thenReturn(activityLogDaoFactory); + when(activityLogDaoFactory.createInterface()).thenReturn(activityLogDao); + + } + + @Test + public void createInterfaceTest(){ + ActivityLogManager activityLogManager = new ActivityLogManagerFactoryImpl().createInterface(); + assertNotNull(activityLogManager); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerImplTest.java new file mode 100644 index 0000000000..44efcc75fa --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerImplTest.java @@ -0,0 +1,43 @@ +package org.openecomp.sdc.activitylog.impl; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +public class ActivityLogManagerImplTest { + private ActivityLogManagerImpl activityLogManager; + + @Mock + private ActivityLogDaoStub activityLogDao; + + @Before + public void setUp(){ + initMocks(this); + } + + @Test + public void logActivityTest(){ + activityLogManager = new ActivityLogManagerImpl(activityLogDao); + activityLogManager.logActivity(new ActivityLogEntity()); + verify(activityLogDao, times(1)).create(any()); + } + + @Test + public void listLoggedActivitiesTest(){ + activityLogManager = new ActivityLogManagerImpl(activityLogDao); + when(activityLogDao.list(any())).thenCallRealMethod(); + Collection<ActivityLogEntity> collection = activityLogManager.listLoggedActivities("1", new Version()); + assertEquals(collection.size(), 1); + } +} |