diff options
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java index 4a893608d..012c37f4d 100644 --- a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java @@ -25,6 +25,8 @@ import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.core.IsEqual.equalTo; import static org.onap.vid.job.Job.JobStatus.COMPLETED; @@ -50,6 +52,7 @@ import org.onap.vid.services.AsyncInstantiationBaseTest; import org.onap.vid.utils.TimeUtils; import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class}) @@ -57,17 +60,20 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest @Inject private DataAccessService dataAccessService; + private AsyncInstantiationRepository asyncInstantiationRepository; @BeforeClass void initServicesInfoService() { + asyncInstantiationRepository = new AsyncInstantiationRepository(dataAccessService); createInstanceParamsMaps(); + createNewTestServicesInfoWithServiceModelID(); } private void createNewTestServicesInfoWithServiceModelID() { LocalDateTime NOW = LocalDateTime.now(); - addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusDays(1L), NOW, COMPLETED, false, false, + addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusYears(1L), NOW, COMPLETED, false, false, MODEL_UUID); addNewServiceInfo(UUID.randomUUID(), "abc", "2", NOW, NOW, COMPLETED, false, false, MODEL_UUID_2); @@ -77,23 +83,33 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest MODEL_UUID); } - @Test - public void testListServicesByServiceModelId() { - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); - createNewTestServicesInfoWithServiceModelID(); - List<ServiceInfo> serviceInfoListResult = underTest.listServicesByServiceModelId(UUID.fromString(MODEL_UUID)); + @DataProvider + public static Object[][] listServicesByServiceModelIdDataProvider() { + return new Object[][]{ + { "services info filtered by MODEL_UUID not hidden , ordered by newer first", MODEL_UUID, "3", "1" }, + { "services info filtered by MODEL_UUID2", MODEL_UUID_2, "2" }, + }; + } - assertThat(serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()), - contains("3", "1")); + @Test(dataProvider = "listServicesByServiceModelIdDataProvider") + public void testListServicesByServiceModelId(String desc, String modelUUID, String... expectedResult) { + List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.fromString(modelUUID)); + assertThat(desc, serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()), + contains(expectedResult)); + } + + @Test + public void whenFilterServiceByNotExistUUID_emptyListIsReturned() { + List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.randomUUID()); + assertThat(serviceInfoListResult, is(empty())); } @Test public void whenSaveNewRequest_thenRequestIsRetrieved() { - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); ServiceInstantiation serviceInstantiation = generateALaCarteWithVnfsServiceInstantiationPayload(); UUID jobUuid = UUID.randomUUID(); - underTest.addJobRequest(jobUuid, serviceInstantiation); - ServiceInstantiation stored = underTest.getJobRequest(jobUuid); + asyncInstantiationRepository.addJobRequest(jobUuid, serviceInstantiation); + ServiceInstantiation stored = asyncInstantiationRepository.getJobRequest(jobUuid); assertThat(stored, jsonEquals(serviceInstantiation).when(IGNORING_ARRAY_ORDER)); } @@ -105,7 +121,6 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest @Test public void getResourceInfoByRootJobId_returnsMapOfjobIdResources(){ - AsyncInstantiationRepository underTest = new AsyncInstantiationRepository(dataAccessService); UUID jobId1= UUID.randomUUID(); UUID jobId2= UUID.randomUUID(); AsyncRequestStatus errorMessage= createAsyncRequestStatus("MSO failed resource", "FAILED"); @@ -118,9 +133,9 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest new ResourceInfo("ffffff",jobId2, "66f3123a-f9a8-4591-b481-ghfgh6767567", Job.JobStatus.COMPLETED, null) ); for(ResourceInfo info: requestInfoList){ - underTest.saveResourceInfo(info); + asyncInstantiationRepository.saveResourceInfo(info); } - Map<String, ResourceInfo> storedByTrackId = underTest.getResourceInfoByRootJobId(jobId1); + Map<String, ResourceInfo> storedByTrackId = asyncInstantiationRepository.getResourceInfoByRootJobId(jobId1); assertThat(storedByTrackId.values(), hasSize(4)); assertThat(storedByTrackId.get("aaaaaa").getInstanceId(), equalTo("64f3123a-f9a8-4591-b481-d662134bcb52")); assertThat(storedByTrackId.get("cccccc").getErrorMessage().request.requestStatus.getStatusMessage(), equalTo("MSO failed resource")); |