diff options
6 files changed, 193 insertions, 0 deletions
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 @@ <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 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 @@ <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 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); + } +} |