From 02a3b49bec86eb0a434afb86e158ca2670cb718f Mon Sep 17 00:00:00 2001 From: kooper Date: Wed, 15 May 2019 10:39:07 +0000 Subject: Update test coverage Change-Id: Ib92d00266d17635b53593eaa544ca3b312c7ddb2 Issue-ID: SDC-2310 Signed-off-by: kooper --- .../validation-rest-services/pom.xml | 5 +++ .../rest/service/ValidationImplTest.java | 44 ++++++++++++++++++++++ .../openecomp-sdc-activity-log-manager/pom.xml | 23 +++++++++++ .../sdc/activitylog/impl/ActivityLogDaoStub.java | 37 ++++++++++++++++++ .../impl/ActivityLogManagerFactoryImplTest.java | 41 ++++++++++++++++++++ .../impl/ActivityLogManagerImplTest.java | 43 +++++++++++++++++++++ 6 files changed, 193 insertions(+) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/src/test/java/org/openecomp/sdcrests/validation/rest/service/ValidationImplTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogDaoStub.java create mode 100644 openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerFactoryImplTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-activity-log-manager/src/main/test/java/org/openecomp/sdc/activitylog/impl/ActivityLogManagerImplTest.java diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/pom.xml index 33b8aafec1..fc1adc6bbb 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/pom.xml +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/pom.xml @@ -128,6 +128,11 @@ junit test + + org.mockito + mockito-core + test + diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/src/test/java/org/openecomp/sdcrests/validation/rest/service/ValidationImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/src/test/java/org/openecomp/sdcrests/validation/rest/service/ValidationImplTest.java new file mode 100644 index 0000000000..08dcd4ed97 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/validation-rest/validation-rest-services/src/test/java/org/openecomp/sdcrests/validation/rest/service/ValidationImplTest.java @@ -0,0 +1,44 @@ +package org.openecomp.sdcrests.validation.rest.service; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.openecomp.sdc.validation.UploadValidationManager; +import org.openecomp.sdc.validation.types.ValidationFileResponse; +import org.openecomp.sdcrests.validation.rest.services.ValidationImpl; + +import javax.ws.rs.core.Response; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +public class ValidationImplTest { + + @Mock + private UploadValidationManager uploadValidationManager; + @InjectMocks + private ValidationImpl validation; + + @Before + public void setUp(){ + initMocks(this); + } + + @Test + public void validateFileTest() throws IOException { + when(uploadValidationManager.validateFile(any(), any())).thenReturn(new ValidationFileResponse()); + Response response = validation.validateFile("", new ByteArrayInputStream("".getBytes())); + assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test(expected = RuntimeException.class) + public void validateFileExceptionTest() throws IOException { + when(uploadValidationManager.validateFile(any(), any())).thenThrow(new IOException()); + Response response = validation.validateFile("", new ByteArrayInputStream("".getBytes())); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-activity-log-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-activity-log-manager/pom.xml index deb8ac5c34..f96282e013 100644 --- a/openecomp-be/backend/openecomp-sdc-activity-log-manager/pom.xml +++ b/openecomp-be/backend/openecomp-sdc-activity-log-manager/pom.xml @@ -46,6 +46,29 @@ ${project.version} runtime + + junit + junit + test + + + org.powermock + powermock-module-junit4-common + ${powermock.version} + test + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + 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 list(ActivityLogEntity entity) { + List 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 collection = activityLogManager.listLoggedActivities("1", new Version()); + assertEquals(collection.size(), 1); + } +} -- cgit 1.2.3-korg