Update test coverage
Change-Id: Ib92d00266d17635b53593eaa544ca3b312c7ddb2
Issue-ID: SDC-2310
Signed-off-by: kooper <sergey.sachkov@est.tech>
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 33b8aaf..fc1adc6 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 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
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 0000000..08dcd4e
--- /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 deb8ac5..f96282e 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 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4-common</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
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 0000000..438c8cb
--- /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 0000000..7bf8028
--- /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 0000000..44efcc7
--- /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);
+ }
+}