7a6b94a1a67d537254de26d7b41601eb89771d43
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / AsyncInstantiationBusinessLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.services;
22
23 import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
24 import static net.javacrumbs.jsonunit.JsonAssert.whenIgnoringPaths;
25 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
26 import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.hamcrest.Matchers.containsInAnyOrder;
29 import static org.hamcrest.Matchers.containsString;
30 import static org.hamcrest.Matchers.hasItem;
31 import static org.hamcrest.Matchers.hasItems;
32 import static org.hamcrest.Matchers.hasProperty;
33 import static org.hamcrest.Matchers.hasSize;
34 import static org.hamcrest.Matchers.is;
35 import static org.hamcrest.Matchers.matchesPattern;
36 import static org.hamcrest.Matchers.not;
37 import static org.hamcrest.Matchers.nullValue;
38 import static org.hamcrest.core.Every.everyItem;
39 import static org.hamcrest.core.IsEqual.equalTo;
40 import static org.mockito.ArgumentMatchers.any;
41 import static org.mockito.ArgumentMatchers.anyInt;
42 import static org.mockito.ArgumentMatchers.anyString;
43 import static org.mockito.ArgumentMatchers.eq;
44 import static org.mockito.Mockito.doNothing;
45 import static org.mockito.Mockito.doReturn;
46 import static org.mockito.Mockito.doThrow;
47 import static org.mockito.Mockito.mock;
48 import static org.mockito.Mockito.reset;
49 import static org.mockito.Mockito.spy;
50 import static org.mockito.Mockito.times;
51 import static org.mockito.Mockito.verify;
52 import static org.mockito.Mockito.when;
53 import static org.onap.vid.job.Job.JobStatus.COMPLETED;
54 import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_ERRORS;
55 import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_NO_ACTION;
56 import static org.onap.vid.job.Job.JobStatus.FAILED;
57 import static org.onap.vid.job.Job.JobStatus.IN_PROGRESS;
58 import static org.onap.vid.job.Job.JobStatus.PAUSE;
59 import static org.onap.vid.job.Job.JobStatus.PENDING;
60 import static org.onap.vid.job.Job.JobStatus.STOPPED;
61 import static org.onap.vid.testUtils.TestUtils.generateRandomAlphaNumeric;
62 import static org.testng.Assert.assertEquals;
63 import static org.testng.Assert.assertFalse;
64 import static org.testng.Assert.assertNotNull;
65 import static org.testng.Assert.assertNull;
66 import static org.testng.Assert.assertTrue;
67
68 import com.fasterxml.jackson.databind.ObjectMapper;
69 import com.google.common.collect.ImmutableList;
70 import com.google.common.collect.ImmutableMap;
71 import java.io.IOException;
72 import java.lang.reflect.Method;
73 import java.net.URL;
74 import java.time.Instant;
75 import java.time.LocalDate;
76 import java.time.LocalDateTime;
77 import java.time.ZoneId;
78 import java.time.ZonedDateTime;
79 import java.util.ArrayList;
80 import java.util.Arrays;
81 import java.util.Collections;
82 import java.util.Comparator;
83 import java.util.Date;
84 import java.util.HashMap;
85 import java.util.HashSet;
86 import java.util.List;
87 import java.util.Map;
88 import java.util.Optional;
89 import java.util.Set;
90 import java.util.UUID;
91 import java.util.concurrent.Callable;
92 import java.util.concurrent.ExecutorService;
93 import java.util.concurrent.Executors;
94 import java.util.stream.Collectors;
95 import java.util.stream.IntStream;
96 import org.apache.commons.io.IOUtils;
97 import org.apache.commons.lang3.time.DateUtils;
98 import org.jetbrains.annotations.NotNull;
99 import org.json.JSONException;
100 import org.mockito.ArgumentCaptor;
101 import org.mockito.Mock;
102 import org.mockito.Mockito;
103 import org.mockito.MockitoAnnotations;
104 import org.mockito.stubbing.Answer;
105 import org.onap.portalsdk.core.util.SystemProperties;
106 import org.onap.vid.aai.ExceptionWithRequestInfo;
107 import org.onap.vid.aai.model.ResourceType;
108 import org.onap.vid.changeManagement.RequestDetailsWrapper;
109 import org.onap.vid.config.DataSourceConfig;
110 import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig;
111 import org.onap.vid.dal.AsyncInstantiationRepository;
112 import org.onap.vid.exceptions.MaxRetriesException;
113 import org.onap.vid.exceptions.NotFoundException;
114 import org.onap.vid.exceptions.OperationNotAllowedException;
115 import org.onap.vid.job.Job;
116 import org.onap.vid.job.Job.JobStatus;
117 import org.onap.vid.job.JobAdapter;
118 import org.onap.vid.job.JobType;
119 import org.onap.vid.job.JobsBrokerService;
120 import org.onap.vid.job.command.MsoRequestBuilder;
121 import org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator;
122 import org.onap.vid.job.impl.JobDaoImpl;
123 import org.onap.vid.job.impl.JobSharedData;
124 import org.onap.vid.model.Action;
125 import org.onap.vid.model.JobAuditStatus;
126 import org.onap.vid.model.NameCounter;
127 import org.onap.vid.model.ResourceInfo;
128 import org.onap.vid.model.ServiceInfo;
129 import org.onap.vid.model.serviceInstantiation.BaseResource;
130 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
131 import org.onap.vid.model.serviceInstantiation.Vnf;
132 import org.onap.vid.mso.MsoOperationalEnvironmentTest;
133 import org.onap.vid.mso.RestObject;
134 import org.onap.vid.mso.model.ModelInfo;
135 import org.onap.vid.mso.model.ServiceInstantiationRequestDetails;
136 import org.onap.vid.mso.rest.AsyncRequestStatus;
137 import org.onap.vid.mso.rest.RequestStatus;
138 import org.onap.vid.properties.Features;
139 import org.onap.vid.testUtils.TestUtils;
140 import org.onap.vid.utils.DaoUtils;
141 import org.onap.vid.utils.TimeUtils;
142 import org.springframework.test.context.ContextConfiguration;
143 import org.testng.Assert;
144 import org.testng.annotations.AfterMethod;
145 import org.testng.annotations.BeforeClass;
146 import org.testng.annotations.BeforeMethod;
147 import org.testng.annotations.DataProvider;
148 import org.testng.annotations.Test;
149
150 @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
151 public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseTest {
152
153
154
155     @Mock
156     private JobAdapter jobAdapterMock;
157
158     @Mock
159     private JobsBrokerService jobsBrokerServiceMock;
160
161     private AsyncInstantiationRepository asyncInstantiationRepository;
162
163     private AuditService auditService;
164
165
166     private AsyncInstantiationBusinessLogicImpl asyncInstantiationBL;
167
168     protected MsoRequestBuilder msoRequestBuilder;
169
170     private static final String UPDATE_SERVICE_INFO_EXCEPTION_MESSAGE =
171             "Failed to retrieve class .*ServiceInfo with jobId .* from table. no resource found";
172
173     private static final String DELETE_SERVICE_INFO_STATUS_EXCEPTION_MESSAGE =
174             "Service status does not allow deletion from the queue";
175
176     private String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
177     private org.hamcrest.Matcher uuidRegexMatcher = is(matchesPattern(uuidRegex));
178
179
180     @BeforeClass
181     void initServicesInfoService() {
182         MockitoAnnotations.initMocks(this);
183         doReturn(false).when(featureManager).isActive(Features.FLAG_DISABLE_HOMING);
184         AsyncInstantiationRepository realAsyncInstantiationRepository = new AsyncInstantiationRepository(dataAccessService);
185         asyncInstantiationRepository = spy(realAsyncInstantiationRepository);
186
187         auditService = new AuditServiceImpl(null, asyncInstantiationRepository);
188
189         AsyncInstantiationBusinessLogicImpl realAsyncInstantiationBL = new AsyncInstantiationBusinessLogicImpl(jobAdapterMock, jobsBrokerServiceMock, sessionFactory, aaiClient, featureManager, cloudOwnerService, asyncInstantiationRepository, auditService);
190         asyncInstantiationBL = Mockito.spy(realAsyncInstantiationBL);
191
192         msoRequestBuilder = new MsoRequestBuilder(asyncInstantiationBL, cloudOwnerService, aaiClient, featureManager);
193
194         createInstanceParamsMaps();
195     }
196
197     @BeforeMethod
198     void defineMocks() {
199         Mockito.reset(aaiClient);
200         Mockito.reset(jobAdapterMock);
201         Mockito.reset(jobsBrokerServiceMock);
202         Mockito.reset(asyncInstantiationRepository);
203         mockAaiClientAnyNameFree();
204         enableAddCloudOwnerOnMsoRequest();
205     }
206
207     @BeforeMethod
208     void resetServiceCount() {
209         serviceCount = 0;
210     }
211
212     @AfterMethod
213     void clearDb() {
214         dataAccessService.deleteDomainObjects(JobDaoImpl.class, "1=1", getPropsMap());
215         dataAccessService.deleteDomainObjects(ServiceInfo.class, "1=1", getPropsMap());
216         dataAccessService.deleteDomainObjects(JobAuditStatus.class, "1=1", getPropsMap());
217         dataAccessService.deleteDomainObjects(NameCounter.class, "1=1", getPropsMap());
218     }
219
220
221     private void createNewTestServicesInfoForFilter(String userId) {
222         LocalDateTime createdDate, modifiedDate;
223         LocalDateTime NOW = LocalDateTime.now();
224         UUID uuid;
225
226         // Old job
227         uuid = UUID.randomUUID();
228         addNewJob(uuid);
229         createdDate = NOW.minusYears(1);
230         addNewServiceInfo(uuid, userId, "Old", createdDate, createdDate, COMPLETED, false, false,
231             MODEL_UUID);
232
233         uuid = UUID.randomUUID();
234         addNewJob(uuid);
235         createdDate = NOW.minusDays(20);
236         modifiedDate = NOW.minusDays(19);
237         addNewServiceInfo(uuid, userId, "Hidden", createdDate, modifiedDate, PAUSE, true, false,
238             MODEL_UUID);
239
240         createNewTestServicesInfo(String.valueOf(userId));
241     }
242
243     private void createNewTestServicesInfo(String userId) {
244
245         LocalDateTime createdDate, modifiedDate;
246         LocalDateTime NOW = LocalDateTime.now();
247         UUID uuid;
248
249         uuid = UUID.randomUUID();
250         addNewJob(uuid);
251
252         createdDate = NOW.minusDays(40);
253         addNewServiceInfo(uuid, userId, "service instance 5", createdDate, createdDate, COMPLETED, false, false,
254             MODEL_UUID);
255         addNewServiceInfo(uuid, userId, "service instance 6", createdDate, createdDate, STOPPED, false, false,
256             MODEL_UUID);
257
258         uuid = UUID.randomUUID();
259         addNewJob(uuid);
260
261         createdDate = NOW.minusDays(20);
262         modifiedDate = NOW.minusDays(10);
263         addNewServiceInfo(uuid, userId, "service instance 4", createdDate, modifiedDate, STOPPED, false, false,
264             MODEL_UUID);
265         addNewServiceInfo(uuid, userId, "service instance 2", createdDate, modifiedDate, COMPLETED, false, false,
266             MODEL_UUID);
267         addNewServiceInfo(uuid, userId, "service instance 3", createdDate, modifiedDate, PAUSE, false, false,
268             MODEL_UUID);
269
270         modifiedDate = NOW.minusDays(19);
271         addNewServiceInfo(uuid, userId, "service instance 1", createdDate, modifiedDate, FAILED, false, false,
272             MODEL_UUID);
273
274
275         // Job to a different user
276         uuid = UUID.randomUUID();
277         addNewJob(uuid);
278
279         createdDate = NOW.minusMonths(2);
280         addNewServiceInfo(uuid, "2221", "service instance 7", createdDate, createdDate, COMPLETED, false, false,
281             MODEL_UUID);
282
283     }
284
285
286
287     private UUID createServicesInfoWithDefaultValues(Job.JobStatus status) {
288
289         LocalDateTime NOW = LocalDateTime.now();
290         UUID uuid;
291
292         uuid = UUID.randomUUID();
293         addNewJob(uuid, status);
294
295         addNewServiceInfo(uuid, null, "service instance 1", NOW, NOW, status, false, false,
296             MODEL_UUID);
297
298         return uuid;
299
300     }
301
302     private List<ServiceInfo> getFullList() {
303         List<ServiceInfo> expectedOrderServiceInfo = dataAccessService.getList(ServiceInfo.class, getPropsMap());
304         assertThat("Failed to retrieve all predefined services", expectedOrderServiceInfo.size(), equalTo(serviceCount));
305         expectedOrderServiceInfo.sort(new ServiceInfoComparator());
306         return expectedOrderServiceInfo;
307     }
308
309
310
311     private LocalDateTime fromDate(Date date) {
312         return Instant.ofEpochMilli(date.getTime())
313                 .atZone(ZoneId.systemDefault())
314                 .toLocalDateTime();
315     }
316
317     private void setCreateDateToServiceInfo(UUID jobUuid, LocalDateTime createDate) {
318         List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
319         DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> {
320             serviceInfoList.stream()
321                     .filter(serviceInfo -> jobUuid.equals(serviceInfo.getJobId()))
322                     .forEach(serviceInfo -> {
323                         serviceInfo.setCreated(toDate(createDate));
324                         session.saveOrUpdate(serviceInfo);
325                     });
326             return 1;
327         });
328     }
329
330     private void addNewJob(UUID uuid) {
331         addNewJob(uuid, null);
332     }
333
334     private void addNewJob(UUID uuid, Job.JobStatus status) {
335         JobDaoImpl jobDao = new JobDaoImpl();
336         jobDao.setUuid(uuid);
337         jobDao.setStatus(status);
338         dataAccessService.saveDomainObject(jobDao, getPropsMap());
339     }
340
341     private ServiceInstantiation addOriginalService(UUID jobId, String userID){
342         addNewServiceInfo(jobId, userID, "name", LocalDateTime.now(), LocalDateTime.now(), COMPLETED_WITH_ERRORS, false,
343             true,
344             MODEL_UUID);
345         assertThat(asyncInstantiationRepository.getServiceInfoByJobId(jobId).isRetryEnabled(), is(true));
346         ServiceInstantiation originalServiceInstantiation = prepareServiceInstantiation(true, 1);
347         doReturn(originalServiceInstantiation).when(asyncInstantiationRepository).getJobRequest(jobId);
348         return originalServiceInstantiation;
349     }
350
351     private void assertRetryDisabled(UUID jobId){
352         assertThat(asyncInstantiationRepository.getServiceInfoByJobId(jobId).isRetryEnabled(), is(false));
353     }
354
355     private void assertNewJobExistsAsExpectedAfterRetry(List<UUID> newJobIds, ServiceInstantiation expectedServiceInstantiation, UUID jobId, String userId){
356         assertThat(newJobIds, hasSize(1));
357         assertThat(newJobIds.get(0), not(equalTo(jobId)));
358
359         ArgumentCaptor<ServiceInstantiation> requestsCaptor = ArgumentCaptor.forClass(ServiceInstantiation.class);
360         ArgumentCaptor<UUID> uuidsCaptor = ArgumentCaptor.forClass(UUID.class);
361         ArgumentCaptor<JobType> jobTypeCaptor = ArgumentCaptor.forClass(JobType.class);
362
363         verify(asyncInstantiationRepository).addJobRequest(uuidsCaptor.capture(), requestsCaptor.capture());
364         verify(jobAdapterMock).createServiceInstantiationJob(jobTypeCaptor.capture(), requestsCaptor.capture(), uuidsCaptor.capture(), eq(userId), any(), anyString(), anyInt());
365         verify(jobsBrokerServiceMock).add(any());
366
367         requestsCaptor.getAllValues().forEach(x->assertJsonEquals(expectedServiceInstantiation, x, whenIgnoringPaths(
368                 "trackById",
369                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.trackById",
370                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.vfModules.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0:001.trackById",
371                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.vfModules.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0:002.trackById"
372         )));
373
374     }
375
376     @Test
377     public void testServiceInfoAreOrderedAsExpected() {
378         int userId = 2222;
379         createNewTestServicesInfo(String.valueOf(userId));
380         List<ServiceInfo> expectedOrderServiceInfo = getFullList();
381         List<ServiceInfo> serviceInfoListResult = asyncInstantiationBL.getAllServicesInfo();
382         assertThat("Services aren't ordered as expected", serviceInfoListResult, equalTo(expectedOrderServiceInfo));
383     }
384
385     @Test
386     public void whenNewServiceInfoCreated_isRetryEnablesIsFalse() {
387         UUID uuid = createServicesInfoWithDefaultValues(PENDING);
388         assertFalse(asyncInstantiationRepository.getServiceInfoByJobId(uuid).isRetryEnabled());
389     }
390
391     @Test
392     public void testServiceInfoAreFilteredAsExpected() {
393         int userId = 2222;
394         createNewTestServicesInfoForFilter(String.valueOf(userId));
395         List<ServiceInfo> expectedOrderServiceInfo = getFullList();
396
397         List<ServiceInfo> expectedFilterByUser = expectedOrderServiceInfo.stream().filter(x ->
398                 !x.getServiceInstanceName().equals("Old") && !x.getServiceInstanceName().equals("Hidden")
399
400         ).collect(Collectors.toList());
401
402
403         List<ServiceInfo> serviceInfoFilteredByUser = asyncInstantiationBL.getAllServicesInfo();
404         assertThat("Services aren't ordered filtered as expected", serviceInfoFilteredByUser, equalTo(expectedFilterByUser));
405     }
406
407     @Test(dataProvider = "pauseAndInstanceParams")
408     public void createMacroServiceInstantiationMsoRequestUniqueName(Boolean isPause, HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams) throws Exception {
409         defineMocks();
410         ServiceInstantiation serviceInstantiationPayload = generateMockMacroServiceInstantiationPayload(isPause, createVnfList(vfModuleInstanceParamsMap, vnfInstanceParams, true), 2, true, PROJECT_NAME, false);
411         final URL resource = this.getClass().getResource("/payload_jsons/bulk_service_request_unique_names.json");
412         when(jobAdapterMock.createServiceInstantiationJob(any(), any(), any(), any(), any(), anyString(), any())).thenAnswer(invocation -> {
413             Object[] args = invocation.getArguments();
414             return new MockedJob((String)args[5]);
415         });
416
417         when(jobsBrokerServiceMock.add(any(MockedJob.class))).thenAnswer((Answer<UUID>) invocation -> {
418             Object[] args = invocation.getArguments();
419             MockedJob job = (MockedJob) args[0];
420             MockedJob.putJob(job.uuid, job);
421             return job.getUuid();
422         });
423
424         when(asyncInstantiationBL.isPartOfBulk(any())).thenReturn(true);
425
426         List<UUID> uuids = asyncInstantiationBL.pushBulkJob(serviceInstantiationPayload, "az2016");
427         for (int i = 0; i < 2; i++) {
428             UUID currentUuid = uuids.get(i);
429             RequestDetailsWrapper<ServiceInstantiationRequestDetails> result =
430                     msoRequestBuilder.generateMacroServiceInstantiationRequest(currentUuid, serviceInstantiationPayload,
431                             MockedJob.getJob(currentUuid).getOptimisticUniqueServiceInstanceName(), "az2016");
432             String unique =  i==0 ? "" : String.format("_00%s", i);
433             String expected = IOUtils.toString(resource, "UTF-8")
434                     .replace("{SERVICE_UNIQENESS}", unique)
435                     .replace("{VNF_UNIQENESS}", unique)
436                     .replace("{VF_MODULE_UNIQENESS}", unique)
437                     .replace("{VF_MODULE_2_UNIQENESS}", unique)
438                     .replace("{VG_UNIQUENESS}", unique);
439             MsoOperationalEnvironmentTest.assertThatExpectationIsLikeObject(expected, result);
440             Optional<ServiceInfo> optionalServiceInfo = getJobById(currentUuid);
441             assertThat(optionalServiceInfo.get().getServiceInstanceName(), equalTo("vPE_Service" + unique));
442             verifySearchNodeTypeByName(unique, "vPE_Service", ResourceType.SERVICE_INSTANCE);
443             verifySearchNodeTypeByName(unique, VNF_NAME, ResourceType.GENERIC_VNF);
444             verifySearchNodeTypeByName(unique, "vmxnjr001_AVPN_base_vPE_BV_base", ResourceType.VF_MODULE);
445             verifySearchNodeTypeByName(unique, "vmxnjr001_AVPN_base_vRE_BV_expansion", ResourceType.VF_MODULE);
446             verifySearchNodeTypeByName(unique, "myVgName", ResourceType.VOLUME_GROUP);
447         }
448     }
449
450     protected void verifySearchNodeTypeByName(String unique, String resourceName, ResourceType serviceInstance) {
451         String uniqueName = resourceName + unique;
452         verify(aaiClient, times(1)).isNodeTypeExistsByName(uniqueName, serviceInstance);
453         when(aaiClient.isNodeTypeExistsByName(uniqueName, serviceInstance)).thenReturn(true);
454     }
455
456
457
458
459     @DataProvider
460     public static Object[][] dataProviderForInstanceNames() {
461         return new Object[][]{
462                 {true, ImmutableList.of("vPE_Service", "vPE_Service_001", "vPE_Service_002")},
463                 {false, ImmutableList.of("", "", "")},
464         };
465     }
466
467     @Test(dataProvider="dataProviderForInstanceNames")
468     public void pushBulkJob_bulkWithSize3_instancesNamesAreExactlyAsExpected(boolean isUserProvidedNaming, List<String> expectedNames) {
469         final ServiceInstantiation request = prepareServiceInstantiation(isUserProvidedNaming, 3);
470
471
472         asyncInstantiationBL.pushBulkJob(request, "myUserId");
473
474         List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
475         assertEquals(serviceInfoList.stream().map(ServiceInfo::getServiceInstanceName).collect(Collectors.toList()), expectedNames);
476     }
477
478     protected ServiceInstantiation prepareServiceInstantiation(String projectName, boolean isUserProvidedNaming, int bulkSize) {
479         final ServiceInstantiation request = generateMockMacroServiceInstantiationPayload(
480                 false,
481                 createVnfList(instanceParamsMapWithoutParams, Collections.EMPTY_LIST, true),
482                 bulkSize, isUserProvidedNaming, projectName, true
483         );
484
485         // in "createServiceInstantiationJob()" we will probe the service, with the generated names
486         configureMockitoWithMockedJob();
487         return request;
488     }
489
490     protected ServiceInstantiation prepareServiceInstantiation(boolean isUserProvidedNaming, int bulkSize) {
491         return prepareServiceInstantiation(PROJECT_NAME, isUserProvidedNaming, bulkSize);
492     }
493
494     @DataProvider
495     public static Object[][] dataProviderSummarizedMap() {
496         return new Object[][]{
497             {"/payload_jsons/templateSummarize4vnfs6vfmodules.json", ImmutableMap.of("vnf", 4L, "vfModule", 6L, "volumeGroup", 1L, "network", 2L)},
498             {"/payload_jsons/templateSummarize3Vnfs8Vfmodule2VolumeGroups.json", ImmutableMap.of("vnf", 3L, "vfModule", 8L, "volumeGroup", 2L)},
499             {"/payload_jsons/templateSummarize3Networks.json", ImmutableMap.of("network", 3L)},
500
501         };
502     }
503
504     @Test(dataProvider = "dataProviderSummarizedMap")
505     public void summarizedChildrenMap_givenServiceInstantiation_yieldCorrectMap(String pathInResource, Map<String, Long> expectedMap){
506         ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
507             pathInResource, ServiceInstantiation.class);
508         Map<String, Long> childrenMap =  asyncInstantiationBL.summarizedChildrenMap(serviceInstantiation);
509         assertEquals(childrenMap,expectedMap);
510     }
511
512     @Test
513     public void requestSummaryOrNull_givenActionWhichIsNotCreate_yieldNullRegardlessOfPayload(){
514         ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
515
516         when(serviceInstantiation.getAction()).thenReturn(Action.Upgrade);
517         when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(true);
518
519         assertThat(asyncInstantiationBL.requestSummaryOrNull(serviceInstantiation), is(nullValue()));
520     }
521
522     @Test
523     public void whenPushBulkJob_thenJobRequestIsSaveInJobRequestDb() {
524         Mockito.reset(asyncInstantiationRepository);
525         int bulkSize = 3;
526         final ServiceInstantiation request = prepareServiceInstantiation(true, bulkSize);
527         when(jobsBrokerServiceMock.add(any())).thenReturn(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID());
528         List<UUID> jobIds = asyncInstantiationBL.pushBulkJob(request, "abc");
529
530         ArgumentCaptor<JobAdapter.AsyncJobRequest> asyncJobRequestCaptor = ArgumentCaptor.forClass(JobAdapter.AsyncJobRequest.class);
531         ArgumentCaptor<ServiceInstantiation> requestsCaptor = ArgumentCaptor.forClass(ServiceInstantiation.class);
532         ArgumentCaptor<UUID> uuidsCaptor = ArgumentCaptor.forClass(UUID.class);
533         verify(asyncInstantiationRepository, times(bulkSize)).addJobRequest(uuidsCaptor.capture(), requestsCaptor.capture());
534         verify(jobsBrokerServiceMock, times(bulkSize)).add(any());
535         verify(jobAdapterMock, times(bulkSize)).createServiceInstantiationJob(any(), asyncJobRequestCaptor.capture(), any(), any(), any(), any(), any());
536
537         //verify that all for each job we saved an row in jobRequest table
538         assertThat(uuidsCaptor.getAllValues(), containsInAnyOrder(jobIds.toArray()));
539
540         //assert that each real job we created with the adaptor, request is save in jobRequest table
541         assertThat(requestsCaptor.getAllValues(), containsInAnyOrder(asyncJobRequestCaptor.getAllValues().toArray()));
542
543         assertThat(requestsCaptor.getAllValues(),everyItem(hasProperty("bulkSize", is(1))));
544
545         //assert that the requests that save in DB are the same as original request expect of the trackById
546         requestsCaptor.getAllValues().forEach(x->assertJsonEquals(request, x, whenIgnoringPaths(
547                 "bulkSize",
548                 "trackById",
549                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.trackById",
550                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.vfModules.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0:001.trackById",
551                 "vnfs.2016-73_MOW-AVPN-vPE-BV-L.vfModules.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0.201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0:002.trackById"
552         )));
553
554         //assert that each trackById on all bulk jobs is unique
555         Set<String> usedUUID = new HashSet<>();
556         requestsCaptor.getAllValues().forEach(x->assertTrackByIdRecursively(x, uuidRegexMatcher, usedUUID));
557     }
558
559     @Test
560     public void whenRetryJob_prevJobRetryIsDisabled() {
561         reset(asyncInstantiationRepository);
562         UUID jobId = UUID.randomUUID();
563         String userID = generateRandomAlphaNumeric(8);
564         addOriginalService(jobId, userID);
565         doReturn(mock(Map.class)).when(asyncInstantiationRepository).getResourceInfoByRootJobId(jobId);
566         asyncInstantiationBL.retryJob(jobId, userID);
567         assertRetryDisabled(jobId);
568     }
569
570     @Test
571     public void whenRetryJobWithEditedData_prevJobRetryIsDisabled() {
572         reset(asyncInstantiationRepository);
573         UUID jobId = UUID.randomUUID();
574         String userID = generateRandomAlphaNumeric(8);
575         addOriginalService(jobId, userID);
576         ServiceInstantiation editedServiceInstantiation = prepareServiceInstantiation("editedProjectName", true, 1);
577         asyncInstantiationBL.retryJob(editedServiceInstantiation, jobId, userID);
578         assertRetryDisabled(jobId);
579     }
580
581     @Test
582     public void retryJobWithEditedData_expectedNewJobDifferentData() {
583         reset(asyncInstantiationRepository);
584         UUID jobId = UUID.randomUUID();
585         String userID = generateRandomAlphaNumeric(8);
586         addOriginalService(jobId, userID);
587         ServiceInstantiation editedServiceInstantiation = prepareServiceInstantiation("editedProjectName", true, 1);
588         List<UUID> newJobIds =  asyncInstantiationBL.retryJob(editedServiceInstantiation, jobId, userID);
589         assertNewJobExistsAsExpectedAfterRetry(newJobIds, editedServiceInstantiation, jobId, userID);
590     }
591
592     @Test
593     public void retryJob_expectedNewJob() {
594         reset(asyncInstantiationRepository);
595         UUID jobId = UUID.randomUUID();
596         String userID = "az2016";
597         ServiceInstantiation originalServiceInstantiation =  addOriginalService(jobId, userID);
598         doReturn(mock(Map.class)).when(asyncInstantiationRepository).getResourceInfoByRootJobId(jobId);
599         List<UUID> newJobIds = asyncInstantiationBL.retryJob(jobId, userID);
600         assertNewJobExistsAsExpectedAfterRetry(newJobIds, originalServiceInstantiation, jobId, userID);
601     }
602
603     @Test (dataProvider = "aLaCarteAndMacroPayload")
604     public void generateMockServiceInstantiationPayload_serializeBackAndForth_sourceShouldBeTheSame(ServiceInstantiation serviceInstantiationPayload) throws IOException {
605         ObjectMapper mapper = new ObjectMapper();
606         final String asString = mapper.writeValueAsString(serviceInstantiationPayload);
607
608         final ServiceInstantiation asObject = mapper.readValue(asString, ServiceInstantiation.class);
609         final String asString2 = mapper.writeValueAsString(asObject);
610
611         assertJsonEquals(asString, asString2);
612     }
613
614     @DataProvider
615     public Object[][] aLaCarteAndMacroPayload() {
616         ServiceInstantiation macroPayload = generateMockMacroServiceInstantiationPayload(
617                 false,
618                 createVnfList(instanceParamsMapWithoutParams, ImmutableList.of(vnfInstanceParamsMapWithParamsToRemove, vnfInstanceParamsMapWithParamsToRemove), true),
619                 2, false,PROJECT_NAME, false);
620         ServiceInstantiation aLaCartePayload = generateALaCarteServiceInstantiationPayload();
621
622         return new Object[][]{
623                 {macroPayload},
624                 {aLaCartePayload}
625         };
626     }
627
628     public static class ServiceInfoComparator implements Comparator<ServiceInfo> {
629
630         @Override
631         public int compare(ServiceInfo o1, ServiceInfo o2) {
632             int compare;
633
634             compare = o1.getCreatedBulkDate().compareTo(o2.getCreatedBulkDate());
635             if (compare != 0) {
636                 return -compare;
637             }
638
639             // check jobStatus priority
640             int o1Priority = getPriority(o1);
641             int o2Priority = getPriority(o2);
642             compare = o1Priority - o2Priority;
643             if (compare != 0) {
644                 return compare;
645             }
646
647             // check statusModifiedDate
648             return o1.getStatusModifiedDate().compareTo(o2.getStatusModifiedDate());
649         }
650
651         private int getPriority(ServiceInfo o) throws JSONException {
652             Job.JobStatus status = o.getJobStatus();
653             switch (status) {
654                 case COMPLETED:
655                 case FAILED:
656                     return 1;
657                 case IN_PROGRESS:
658                     return 2;
659                 case PAUSE:
660                     return 3;
661                 case STOPPED:
662                 case PENDING:
663                     return 4;
664                 default:
665                     return 5;
666             }
667         }
668     }
669
670     @DataProvider
671     public Object[][] pauseAndInstanceParams() {
672         return new Object[][]{
673                 {Boolean.TRUE, instanceParamsMapWithoutParams, Collections.EMPTY_LIST},
674                 {Boolean.FALSE, instanceParamsMapWithoutParams, Collections.EMPTY_LIST},
675                 {Boolean.TRUE, vfModuleInstanceParamsMapWithParamsToRemove, Collections.singletonList(vnfInstanceParamsMapWithParamsToRemove)}
676         };
677     }
678
679     @Test
680     public void testUpdateServiceInfo_WithExistingServiceInfo_ServiceInfoIsUpdated() {
681         UUID uuid = createFakedJobAndServiceInfo();
682         final String STEPH_CURRY = "Steph Curry";
683         asyncInstantiationBL.updateServiceInfo(uuid, x -> {
684             x.setServiceInstanceName(STEPH_CURRY);
685             x.setJobStatus(Job.JobStatus.IN_PROGRESS);
686         });
687         Optional<ServiceInfo> optionalServiceInfo = getJobById(uuid);
688         assertThat(optionalServiceInfo.get().getServiceInstanceName(), equalTo(STEPH_CURRY));
689         assertThat(optionalServiceInfo.get().getJobStatus(), equalTo(Job.JobStatus.IN_PROGRESS));
690     }
691
692     private Optional<ServiceInfo> getJobById(UUID jobId) {
693         List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, null);
694         return serviceInfoList.stream().filter(x -> jobId.equals(x.getJobId())).findFirst();
695     }
696
697     private UUID createFakedJobAndServiceInfo() {
698         UUID uuid = UUID.randomUUID();
699         addNewJob(uuid);
700         ServiceInfo serviceInfo = new ServiceInfo();
701         serviceInfo.setServiceInstanceName("Lebron James");
702         serviceInfo.setJobId(uuid);
703         serviceInfo.setJobStatus(Job.JobStatus.PENDING);
704         dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
705         return uuid;
706     }
707
708     @Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = UPDATE_SERVICE_INFO_EXCEPTION_MESSAGE)
709     public void testUpdateServiceInfo_WithNonExisting_ThrowException() {
710         asyncInstantiationBL.updateServiceInfo(UUID.randomUUID(), x -> x.setServiceInstanceName("not matter"));
711     }
712
713     @Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = UPDATE_SERVICE_INFO_EXCEPTION_MESSAGE)
714     public void testUpdateServiceInfo_WithDoubleServiceWithSameJobUuid_ThrowException() {
715         UUID uuid = createFakedJobAndServiceInfo();
716         ServiceInfo serviceInfo = new ServiceInfo();
717         serviceInfo.setJobId(uuid);
718         dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
719         asyncInstantiationBL.updateServiceInfo(UUID.randomUUID(), x -> x.setServiceInstanceName("not matter"));
720     }
721
722
723     @DataProvider
724     public static Object[][] isPauseAndPropertyDataProvider() {
725         return new Object[][]{
726                 {true, "mso.restapi.serviceInstanceAssign"},
727                 {false, "mso.restapi.service.instance"},
728         };
729     }
730
731
732     @Test(dataProvider = "isPauseAndPropertyDataProvider")
733     public void testServiceInstantiationPath_RequestPathIsAsExpected(boolean isPause, String expectedProperty) {
734         ServiceInstantiation serviceInstantiationPauseFlagTrue = generateMacroMockServiceInstantiationPayload(isPause, createVnfList(instanceParamsMapWithoutParams, Collections.EMPTY_LIST, true));
735         String path = asyncInstantiationBL.getServiceInstantiationPath(serviceInstantiationPauseFlagTrue);
736         Assert.assertEquals(path, SystemProperties.getProperty(expectedProperty));
737     }
738
739     @Test
740     public void testCreateVnfEndpoint_useProvidedInstanceId() {
741         String path = asyncInstantiationBL.getVnfInstantiationPath("myGreatId");
742         assertThat(path, equalTo("/serviceInstantiation/v7/serviceInstances/myGreatId/vnfs"));
743     }
744
745
746
747     @Test
748     public void pushBulkJob_macroServiceverifyCreatedDateBehavior_createdDateIsTheSameForAllServicesInSameBulk() {
749         LocalDateTime startTestDate = LocalDateTime.now().withNano(0);
750         final ServiceInstantiation request = generateMockMacroServiceInstantiationPayload(
751                 false,
752                 createVnfList(instanceParamsMapWithoutParams, Collections.EMPTY_LIST, true),
753                 100, true,PROJECT_NAME, true
754         );
755
756         pushJobAndAssertDates(startTestDate, request);
757     }
758
759     @Test
760     public void whenCreateServiceInfo_thenModelId_isModelVersionId() {
761         ServiceInfo serviceInfo = asyncInstantiationBL.createServiceInfo("userID",
762                 generateALaCarteWithVnfsServiceInstantiationPayload(),
763                 UUID.randomUUID(),
764                 UUID.randomUUID(),
765                 new Date(),
766                 "myName", ServiceInfo.ServiceAction.INSTANTIATE, null);
767         assertEquals(SERVICE_MODEL_VERSION_ID, serviceInfo.getServiceModelId());
768
769     }
770
771     @Test
772     public void pushBulkJob_aLaCarteServiceverifyCreatedDateBehavior_createdDateIsTheSameForAllServicesInSameBulk() {
773         LocalDateTime startTestDate = LocalDateTime.now().withNano(0);
774         final ServiceInstantiation request = generateALaCarteServiceInstantiationPayload();
775         pushJobAndAssertDates(startTestDate, request);
776     }
777
778     protected void pushJobAndAssertDates(LocalDateTime startTestDate, ServiceInstantiation request) {
779         // in "createServiceInstantiationJob()" we will probe the service, with the generated names
780         configureMockitoWithMockedJob();
781
782         asyncInstantiationBL.pushBulkJob(request, "myUserId");
783         List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, getPropsMap());
784
785         List<Date> creationDates = new ArrayList<>();
786         for (ServiceInfo serviceInfo : serviceInfoList) {
787             creationDates.add(serviceInfo.getCreatedBulkDate());
788         }
789         LocalDateTime endTestDate = LocalDateTime.now();
790
791         //creation date of all services is the same
792         Assert.assertTrue(creationDates.stream().distinct().count() <= 1);
793         LocalDateTime creationDate = fromDate(creationDates.get(0));
794         assertFalse(creationDate.isBefore(startTestDate));
795         assertFalse(creationDate.isAfter(endTestDate));
796     }
797
798     protected void configureMockitoWithMockedJob() {
799         Mockito.reset(jobAdapterMock);
800         final Job job = mock(Job.class);
801         when(job.getStatus()).thenReturn(PENDING);
802         when(job.getUuid()).thenReturn(UUID.fromString("db2c5ed9-1c19-41ce-9cb7-edf0d878cdeb"));
803         when(jobAdapterMock.createServiceInstantiationJob(any(), any(), any(), any(), any(), any(), any())).thenReturn(job);
804         when(jobsBrokerServiceMock.add(job)).thenReturn(UUID.randomUUID());
805     }
806
807     @DataProvider
808     public static Object[][] msoToJobStatusDataProvider() {
809         return new Object[][]{
810                 {"IN_PROGRESS", JobStatus.IN_PROGRESS},
811                 {"INPROGRESS", JobStatus.IN_PROGRESS},
812                 {"IN ProGREsS", JobStatus.IN_PROGRESS},
813                 {"JAMES_HARDEN", JobStatus.IN_PROGRESS},
814                 {"FAILED", JobStatus.FAILED},
815                 {"COMpleTE", JobStatus.COMPLETED},
816                 {"PENDING", JobStatus.IN_PROGRESS},
817                 {"Paused", JobStatus.PAUSE},
818                 {"Pause", JobStatus.PAUSE},
819                 {"PENDING_MANUAL_TASK", JobStatus.PAUSE},
820                 {"UNLOCKED", JobStatus.IN_PROGRESS},
821                 {"AbORtEd", COMPLETED_WITH_ERRORS},
822                 {"RoLlED_baCK", FAILED},
823                 {"ROllED_BAcK_To_ASsIGnED", FAILED},
824                 {"rOLLED_bACK_tO_CrEATeD", FAILED},
825         };
826     }
827
828     @Test(dataProvider = "msoToJobStatusDataProvider")
829     public void whenGetStatusFromMso_calcRightJobStatus(String msoStatus, Job.JobStatus expectedJobStatus) {
830         AsyncRequestStatus asyncRequestStatus = asyncRequestStatusResponse(msoStatus);
831         assertThat(asyncInstantiationBL.calcStatus(asyncRequestStatus), equalTo(expectedJobStatus));
832     }
833
834     @DataProvider
835     public static Object[][] msoRequestStatusFiles(Method test) {
836         return new Object[][]{
837                 {"/responses/mso/orchestrationRequestsServiceInstance.json"},
838                 {"/responses/mso/orchestrationRequestsVnf.json"},
839                 {"/responses/mso/orchestrationRequestsMockedMinimalResponse.json"}
840         };
841     }
842
843     @Test(dataProvider="msoRequestStatusFiles")
844     public void verifyAsyncRequestStatus_canBeReadFromSample(String msoResponseFile) throws IOException {
845         AsyncRequestStatus asyncRequestStatus = TestUtils.readJsonResourceFileAsObject(
846                 msoResponseFile,
847                 AsyncRequestStatus.class);
848         assertThat(asyncRequestStatus.request.requestStatus.getRequestState(), equalTo("COMPLETE"));
849     }
850
851     @Test
852     public void deleteJobInfo_pending_deleted() {
853         doNothing().when(jobsBrokerServiceMock).delete(any());
854         UUID uuid = createServicesInfoWithDefaultValues(PENDING);
855         asyncInstantiationBL.deleteJob(uuid);
856         assertNotNull(asyncInstantiationRepository.getServiceInfoByJobId(uuid).getDeletedAt(), "service info wasn't deleted");
857     }
858
859     @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = DELETE_SERVICE_INFO_STATUS_EXCEPTION_MESSAGE)
860     public void deleteJobInfo_notAllowdStatus_shouldSendError() {
861         UUID uuid = createServicesInfoWithDefaultValues(COMPLETED);
862         doThrow(new IllegalStateException(DELETE_SERVICE_INFO_STATUS_EXCEPTION_MESSAGE)).when(jobsBrokerServiceMock).delete(any());
863         try {
864             asyncInstantiationBL.deleteJob(uuid);
865         } catch (Exception e) {
866             assertNull(asyncInstantiationRepository.getServiceInfoByJobId(uuid).getDeletedAt(), "service info shouldn't deleted");
867             throw e;
868         }
869     }
870
871     @DataProvider
872     public Object[][] jobStatusesFinal() {
873         return Arrays.stream(Job.JobStatus.values())
874                 .filter(t -> ImmutableList.of(COMPLETED, FAILED, STOPPED).contains(t))
875                 .map(v -> new Object[]{v}).collect(Collectors.toList()).toArray(new Object[][]{});
876     }
877
878     @Test(dataProvider = "jobStatusesFinal")
879     public void whenHideService_theServiceNotReturnedInServiceList(JobStatus jobStatus) {
880         UUID uuidToHide = createServicesInfoWithDefaultValues(jobStatus);
881         UUID uuidToShown = createServicesInfoWithDefaultValues(jobStatus);
882         List<UUID> serviceInfoList = listServicesUUID();
883         assertThat(serviceInfoList, hasItems(uuidToHide, uuidToShown));
884
885         asyncInstantiationBL.hideServiceInfo(uuidToHide);
886         serviceInfoList = listServicesUUID();
887         assertThat(serviceInfoList, hasItem(uuidToShown));
888         assertThat(serviceInfoList, not(hasItem(uuidToHide)));
889
890     }
891
892     protected List<UUID> listServicesUUID() {
893         return asyncInstantiationBL.getAllServicesInfo().stream().map(ServiceInfo::getJobId).collect(Collectors.toList());
894     }
895
896     @DataProvider
897     public Object[][] jobStatusesNotFinal() {
898         return Arrays.stream(Job.JobStatus.values())
899                 .filter(t -> ImmutableList.of(PENDING, IN_PROGRESS, PAUSE).contains(t))
900                 .map(v -> new Object[]{v}).collect(Collectors.toList()).toArray(new Object[][]{});
901     }
902
903     @Test(dataProvider = "jobStatusesNotFinal",
904             expectedExceptions = OperationNotAllowedException.class,
905             expectedExceptionsMessageRegExp = "jobId.*Service status does not allow hide service, status = .*")
906     public void hideServiceInfo_notAllowedStatus_shouldSendError(JobStatus jobStatus) {
907         UUID uuid = createServicesInfoWithDefaultValues(jobStatus);
908         try {
909             asyncInstantiationBL.hideServiceInfo(uuid);
910         } catch (Exception e) {
911             assertFalse(asyncInstantiationRepository.getServiceInfoByJobId(uuid).isHidden(), "service info shouldn't be hidden");
912             throw e;
913         }
914     }
915
916     @Test
917     public void whenUseGetCounterInMultiThreads_EachThreadGetDifferentCounter() throws InterruptedException {
918         int SIZE = 200;
919         ExecutorService executor = Executors.newFixedThreadPool(SIZE);
920         List<Callable<Integer>> tasks = IntStream.rangeClosed(0, SIZE)
921                 .mapToObj(x-> ((Callable<Integer>)() -> asyncInstantiationBL.getCounterForName("a")))
922                 .collect(Collectors.toList());
923         Set<Integer> expectedResults = IntStream.rangeClosed(0, SIZE).boxed().collect(Collectors.toSet());
924         executor.invokeAll(tasks)
925                 .forEach(future -> {
926                     try {
927                         assertTrue( expectedResults.remove(future.get()), "got unexpected counter");
928                     }
929                     catch (Exception e) {
930                         throw new RuntimeException(e);
931                     }
932                 });
933
934         assertThat(expectedResults.size(), is(0));
935     }
936
937     @Test
938     public void whenUseGetCounterForSameName_numbersReturnedByOrder() {
939
940         String name = UUID.randomUUID().toString();
941         int SIZE=10;
942         for (int i=0; i<SIZE; i++) {
943             assertThat(asyncInstantiationBL.getCounterForName(name), is(i));
944         }
945     }
946
947     @Test
948     public void whenNamedInUsedInAai_getNextNumber() {
949         String name = someCommonStepsAndGetName();
950         ResourceType type = ResourceType.GENERIC_VNF;
951         when(aaiClient.isNodeTypeExistsByName(name, type)).thenReturn(true);
952         when(aaiClient.isNodeTypeExistsByName(name+"_001", type)).thenReturn(false);
953         assertThat(asyncInstantiationBL.getUniqueName(name, type), equalTo(name+"_001"));
954     }
955
956     @Test(enabled = false) //skip till we will handle macro bulk again...
957     public void whenNamedNotInUsedInAai_getSameNameTwice() {
958         String name = someCommonStepsAndGetName();
959         ResourceType type = ResourceType.GENERIC_VNF;
960         when(aaiClient.isNodeTypeExistsByName(name, type)).thenReturn(false);
961         assertThat(asyncInstantiationBL.getUniqueName(name, type), equalTo(name));
962         assertThat(asyncInstantiationBL.getUniqueName(name, type), equalTo(name));
963         when(aaiClient.isNodeTypeExistsByName(name, type)).thenReturn(true);
964         assertThat(asyncInstantiationBL.getUniqueName(name, type), equalTo(name+"_001"));
965     }
966
967     private String someCommonStepsAndGetName() {
968         mockAaiClientAaiStatusOK();
969         return UUID.randomUUID().toString();
970     }
971
972     @Test(expectedExceptions= ExceptionWithRequestInfo.class)
973     public void whenAaiBadResponseCode_throwInvalidAAIResponseException() {
974         String name = someCommonStepsAndGetName();
975         ResourceType type = ResourceType.SERVICE_INSTANCE;
976         when(aaiClient.isNodeTypeExistsByName(name, type)).thenThrow(aaiNodeQueryBadResponseException());
977         asyncInstantiationBL.getUniqueName(name, type);
978     }
979
980     @Test(expectedExceptions=MaxRetriesException.class)
981     public void whenAaiAlwaysReturnNameUsed_throwInvalidAAIResponseException() {
982         String name = someCommonStepsAndGetName();
983         ResourceType type = ResourceType.VF_MODULE;
984         when(aaiClient.isNodeTypeExistsByName(any(), eq(type))).thenReturn(true);
985         asyncInstantiationBL.setMaxRetriesGettingFreeNameFromAai(10);
986         asyncInstantiationBL.getUniqueName(name, type);
987     }
988
989     @Test
990     public void testFormattingOfNameAndCounter() {
991         AsyncInstantiationBusinessLogicImpl bl = (AsyncInstantiationBusinessLogicImpl) asyncInstantiationBL;
992         assertThat(bl.formatNameAndCounter("x", 0), equalTo("x"));
993         assertThat(bl.formatNameAndCounter("x", 3), equalTo("x_003"));
994         assertThat(bl.formatNameAndCounter("x", 99), equalTo("x_099"));
995         assertThat(bl.formatNameAndCounter("x", 100), equalTo("x_100"));
996         assertThat(bl.formatNameAndCounter("x", 1234), equalTo("x_1234"));
997     }
998
999     @Test
1000     public void pushBulkJob_verifyAlacarteFlow_useALaCartServiceInstantiationJobType(){
1001         final ServiceInstantiation request = generateALaCarteServiceInstantiationPayload();
1002
1003         // in "createServiceInstantiationJob()" we will probe the service, with the generated names
1004         configureMockitoWithMockedJob();
1005
1006         ArgumentCaptor<JobType> argumentCaptor = ArgumentCaptor.forClass(JobType.class);
1007         asyncInstantiationBL.pushBulkJob(request, "myUserId");
1008         verify(jobAdapterMock).createServiceInstantiationJob(argumentCaptor.capture(),any(),any(),anyString(), anyString(),  anyString(), anyInt());
1009         assertTrue(argumentCaptor.getValue().equals(JobType.ALaCarteServiceInstantiation));
1010     }
1011
1012     @Test
1013     public void pushBulkJob_verifyMacroFlow_useMacroServiceInstantiationJobType(){
1014         final ServiceInstantiation request = generateMacroMockServiceInstantiationPayload(false, Collections.emptyMap());
1015
1016         // in "createServiceInstantiationJob()" we will probe the service, with the generated names
1017         configureMockitoWithMockedJob();
1018
1019         ArgumentCaptor<JobType> argumentCaptor = ArgumentCaptor.forClass(JobType.class);
1020         asyncInstantiationBL.pushBulkJob(request, "myUserId");
1021         verify(jobAdapterMock).createServiceInstantiationJob(argumentCaptor.capture(),any(),any(),anyString(), any(),  anyString(), anyInt());
1022         assertTrue(argumentCaptor.getValue().equals(JobType.MacroServiceInstantiation));
1023     }
1024
1025
1026
1027     @Test
1028     public void getALaCarteServiceDeletionPath_verifyPathIsAsExpected() {
1029
1030         String expected = "/serviceInstantiation/v7/serviceInstances/f36f5734-e9df-4fbf-9f35-61be13f028a1";
1031
1032         String result = asyncInstantiationBL.getServiceDeletionPath("f36f5734-e9df-4fbf-9f35-61be13f028a1");
1033
1034         assertThat(expected,equalTo(result));
1035     }
1036
1037     @Test
1038     public void getResumeRequestPath_verifyPathIsAsExpected() {
1039
1040         String expected = "/orchestrationRequests/v7/rq1234d1-5a33-55df-13ab-12abad84e333/resume";
1041
1042         String result = asyncInstantiationBL.getResumeRequestPath("rq1234d1-5a33-55df-13ab-12abad84e333");
1043
1044         assertThat(expected, equalTo(result));
1045     }
1046
1047     @Test
1048     public void getInstanceGroupsDeletionPath_verifyPathIsAsExpected()  {
1049         assertEquals(asyncInstantiationBL.getInstanceGroupDeletePath("9aada4af-0f9b-424f-ae21-e693bd3e005b"),
1050                 "/serviceInstantiation/v7/instanceGroups/9aada4af-0f9b-424f-ae21-e693bd3e005b");
1051     }
1052
1053     @Test
1054     public void whenLcpRegionNotEmpty_thenCloudRegionIdOfResourceIsLegacy() {
1055         String legacyCloudRegion = "legacyCloudRegion";
1056         Vnf vnf = new Vnf(new ModelInfo(), null, null, Action.Create.name(), null, "anyCloudRegion", legacyCloudRegion,
1057                 null, null, null, false, null, null, UUID.randomUUID().toString(), null, null, null);
1058         assertThat(vnf.getLcpCloudRegionId(), equalTo(legacyCloudRegion));
1059     }
1060
1061     @Test
1062     public void whenLcpRegionNotEmpty_thenCloudRegionIdOfServiceIsLegacy() {
1063         String legacyCloudRegion = "legacyCloudRegion";
1064         ServiceInstantiation service = new ServiceInstantiation(new ModelInfo(), null, null, null, null, null, null,
1065                 null, null, "anyCloudRegion", legacyCloudRegion, null, null, null, null, null, null, null, null, null,
1066                 false, 1,false, false, null, null, Action.Create.name(), UUID.randomUUID().toString(), null, null, null);
1067         assertThat(service.getLcpCloudRegionId(), equalTo(legacyCloudRegion));
1068     }
1069
1070     @DataProvider
1071     public static Object[][] getJobTypeByRequest_verifyResultAsExpectedDataProvider() {
1072         return new Object[][]{
1073                 {false, Action.Create, JobType.MacroServiceInstantiation},
1074                 {true, Action.Create, JobType.ALaCarteServiceInstantiation},
1075                 {true, Action.Delete, JobType.ALaCarteService},
1076         };
1077     }
1078
1079     @Test(dataProvider = "getJobTypeByRequest_verifyResultAsExpectedDataProvider")
1080     public void getJobTypeByRequest_verifyResultAsExpected(boolean isALaCarte, Action action, JobType expectedJobType) {
1081         ServiceInstantiation service = createServiceWithIsALaCarteAndAction(isALaCarte, action);
1082         assertThat(asyncInstantiationBL.getJobType(service), equalTo(expectedJobType));
1083     }
1084
1085     @NotNull
1086     protected ServiceInstantiation createServiceWithIsALaCarteAndAction(boolean isALaCarte, Action action) {
1087         return new ServiceInstantiation(new ModelInfo(), null, null, null, null, null, null,
1088                 null, null, null, null, null, null, null, null, null, null, null, null, null,
1089                 false, 1, false, isALaCarte, null, null, action.name(),
1090                 UUID.randomUUID().toString(), null, null, null);
1091     }
1092
1093     @DataProvider
1094     public static Object[][] isRetryEnabledForStatusDataProvider(Method test) {
1095         return new Object[][]{
1096                 {FAILED, true, true},
1097                 {COMPLETED_WITH_ERRORS, true, true},
1098                 {COMPLETED_WITH_NO_ACTION, true, false},
1099                 {COMPLETED, true, false},
1100                 {IN_PROGRESS, true, false},
1101                 {FAILED, false, false},
1102                 {COMPLETED_WITH_ERRORS, false, false},
1103                 {COMPLETED, false, false},
1104         };
1105     }
1106
1107     @Test(dataProvider = "isRetryEnabledForStatusDataProvider")
1108     public void whenUpdateServiceInfoAndAuditStatus_thenServiceInfoRowIsUpdatedAndIsRetryIsRight(
1109             JobStatus jobStatus, boolean isRetryfeatureEnabled, boolean expectedIsRetry) {
1110         when(featureManager.isActive(Features.FLAG_1902_RETRY_JOB)).thenReturn(isRetryfeatureEnabled);
1111         UUID uuid = createFakedJobAndServiceInfo();
1112         asyncInstantiationBL.updateServiceInfoAndAuditStatus(uuid, jobStatus);
1113         ServiceInfo serviceInfo = ((List<ServiceInfo>)dataAccessService.getList(ServiceInfo.class, getPropsMap())).
1114                 stream().filter(x->x.getJobId().equals(uuid)).findFirst().get();
1115         assertEquals(jobStatus, serviceInfo.getJobStatus());
1116
1117         //we don't test serviceInfo.getStatusModifiedDate() because it's too complicated
1118
1119         assertEquals(expectedIsRetry, serviceInfo.isRetryEnabled());
1120     }
1121
1122     @Test
1123     public void givenServiceWithNullTrackByIds_whenReplaceTrackByIds_thenAllLevelsHasTrackByIdWithUUID() {
1124         ServiceInstantiation serviceInstantiation = FakeResourceCreator.createServiceWith2InstancesInEachLevel(Action.Create);
1125         //assert for the given that all trackById are null
1126         assertTrackByIdRecursively(serviceInstantiation, is(nullValue()), new HashSet<>());
1127         ServiceInstantiation modifiedServiceInstantiation = asyncInstantiationBL.prepareServiceToBeUnique(serviceInstantiation);
1128         assertTrackByIdRecursively(modifiedServiceInstantiation, uuidRegexMatcher, new HashSet<>());
1129     }
1130
1131     private void assertTrackByIdRecursively(BaseResource baseResource, org.hamcrest.Matcher matcher, Set<String> usedUuids) {
1132         assertThat(baseResource.getTrackById(), matcher);
1133         if (baseResource.getTrackById()!=null) {
1134             assertThat(usedUuids, not(hasItem(baseResource.getTrackById())));
1135             usedUuids.add(baseResource.getTrackById());
1136         }
1137         baseResource.getChildren().forEach(x->assertTrackByIdRecursively(x, matcher, usedUuids));
1138     }
1139
1140     @Test
1141     public void givenServicefromDB_returnsTheBulkRequest() throws IOException {
1142         ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject("/payload_jsons/VnfGroupCreate3Delete1None1Request.json", ServiceInstantiation.class);
1143         UUID jobId = UUID.randomUUID();
1144         doReturn(serviceInstantiation).when(asyncInstantiationRepository).getJobRequest(jobId);
1145         doReturn(mock(Map.class)).when(asyncInstantiationRepository).getResourceInfoByRootJobId(jobId);
1146         ServiceInstantiation modifiedServiceInstantiation = asyncInstantiationBL.getBulkForRetry(jobId);
1147         assertThat(modifiedServiceInstantiation, jsonEquals(serviceInstantiation).when(IGNORING_ARRAY_ORDER));
1148     }
1149
1150     @Test
1151     public void givenServiceFromDB_returnsResolvedData() throws IOException {
1152         ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject("/payload_jsons/VnfGroupCreate3Delete1None1Request.json", ServiceInstantiation.class);
1153         ServiceInstantiation expectedServiceInstantiation = TestUtils.readJsonResourceFileAsObject("/payload_jsons/VnfGroupCreate3Delete1None1RequestResolvedForRetry.json", ServiceInstantiation.class);
1154         UUID jobId = UUID.randomUUID();
1155         AsyncRequestStatus asyncRequestStatus = TestUtils.readJsonResourceFileAsObject(
1156                 "/responses/mso/orchestrationRequestsVnf.json",
1157                 AsyncRequestStatus.class);
1158         Map<String, ResourceInfo> mockedResourceInfoMap = ImmutableMap.of(
1159                 "groupingservicefortest..ResourceInstanceGroup..0:001", new ResourceInfo("groupingservicefortest..ResourceInstanceGroup..0:001",jobId,"VNF_GROUP1_INSTANCE_ID", COMPLETED, asyncRequestStatus),// TODO case: delete completed
1160                 "ag5aav86u4j", new ResourceInfo("ag5aav86u4j",jobId, null, FAILED, asyncRequestStatus),// case: failed
1161                 "asedrftjko", new ResourceInfo("asedrftjko",jobId, "VNF_GROUP1_INSTANCE_ID_3", COMPLETED, asyncRequestStatus),//case: completed after retry failed
1162                 "rgedfdged4", new ResourceInfo("rgedfdged4", jobId,"VNF_GROUP1_INSTANCE_ID_4", COMPLETED, asyncRequestStatus ));// case: create completed
1163
1164         doReturn(mockedResourceInfoMap).when(asyncInstantiationRepository).getResourceInfoByRootJobId(jobId);
1165         ServiceInstantiation modifiedServiceInstantiation = asyncInstantiationBL.enrichBulkForRetry(serviceInstantiation,jobId);
1166         assertThat(modifiedServiceInstantiation, jsonEquals(expectedServiceInstantiation).when(IGNORING_ARRAY_ORDER));
1167     }
1168
1169     @DataProvider
1170     public static Object[][] readStatusMsgDataProvider(Method test) throws IOException {
1171         AsyncRequestStatus asyncRequestStatus = TestUtils.readJsonResourceFileAsObject(
1172                 "/responses/mso/orchestrationRequestsVnf.json",
1173                 AsyncRequestStatus.class);
1174         return new Object[][]{
1175                 {null, null},
1176                 {new AsyncRequestStatus(), null},
1177                 {new AsyncRequestStatus(new AsyncRequestStatus.Request()), null},
1178                 {new AsyncRequestStatus(new AsyncRequestStatus.Request(new RequestStatus())), null},
1179                 {asyncRequestStatus, "Vnf has been created successfully."}
1180         };
1181     }
1182
1183     @Test(dataProvider = "readStatusMsgDataProvider")
1184     public void resourceInfoReadStatusMsg_returnsStatusMsgOrNull(AsyncRequestStatus asyncRequestStatus, String expected) {
1185         ResourceInfo resourceInfo = new ResourceInfo("groupingservicefortest..ResourceInstanceGroup..0:001",UUID.randomUUID(),"VNF_GROUP1_INSTANCE_ID", COMPLETED, asyncRequestStatus);
1186         String msg= asyncInstantiationBL.readStatusMsg(resourceInfo);
1187         assertThat(msg, equalTo( expected));
1188     }
1189
1190     @Test
1191     public void testAddResourceInfoForOkResponse() {
1192         reset(asyncInstantiationRepository);
1193         String serviceInstanceId = "service-instance-id";
1194         UUID jobUuid = UUID.randomUUID();
1195
1196         asyncInstantiationBL.addResourceInfo(prepareSharedDataForAddResourceInfo(jobUuid), JobStatus.IN_PROGRESS, serviceInstanceId);
1197
1198         ArgumentCaptor<ResourceInfo> resourceInfoCaptor = ArgumentCaptor.forClass(ResourceInfo.class);
1199         verify(asyncInstantiationRepository).saveResourceInfo(resourceInfoCaptor.capture());
1200
1201         ResourceInfo resourceInfo = resourceInfoCaptor.getValue();
1202         assertResourceInfoValues(resourceInfo, serviceInstanceId, jobUuid, JobStatus.IN_PROGRESS);
1203         assertThat(resourceInfo.getErrorMessage(), is(nullValue()));
1204     }
1205
1206     private JobSharedData prepareSharedDataForAddResourceInfo(UUID jobUuid) {
1207         ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
1208         when(serviceInstantiation.getTrackById()).thenReturn("track-by-id");
1209         return new JobSharedData(jobUuid, "", serviceInstantiation, "");
1210     }
1211
1212     private void assertResourceInfoValues(ResourceInfo resourceInfo, String serviceInstanceId, UUID jobUuid, JobStatus jobStatus) {
1213         assertThat(resourceInfo.getInstanceId(), equalTo(serviceInstanceId));
1214         assertThat(resourceInfo.getJobStatus(), equalTo(jobStatus));
1215         assertThat(resourceInfo.getRootJobId(), equalTo(jobUuid));
1216         assertThat(resourceInfo.getTrackById(), equalTo("track-by-id"));
1217     }
1218
1219     @DataProvider
1220     public static Object[][] addResourceInfoWithError() {
1221         String message = "Failed to create service instance";
1222         return new Object[][]{
1223                 {500, message},
1224                 {199, "{\"serviceException\":{\"messageId\":\"SVC2000\",\"text\":\"Error: " + message + "\"}}"}
1225         };
1226     }
1227
1228     @Test(dataProvider = "addResourceInfoWithError")
1229     public void testAddResourceInfoForErrorResponse(int errorCode, String errorMessage) {
1230         reset(asyncInstantiationRepository);
1231         UUID jobUuid = UUID.randomUUID();
1232
1233         RestObject restObject = mock(RestObject.class);
1234         when(restObject.getStatusCode()).thenReturn(errorCode);
1235         when(restObject.getRaw()).thenReturn(errorMessage);
1236         asyncInstantiationBL.addFailedResourceInfo(prepareSharedDataForAddResourceInfo(jobUuid), restObject);
1237
1238         ArgumentCaptor<ResourceInfo> resourceInfoCaptor = ArgumentCaptor.forClass(ResourceInfo.class);
1239         verify(asyncInstantiationRepository).saveResourceInfo(resourceInfoCaptor.capture());
1240
1241         ResourceInfo resourceInfo = resourceInfoCaptor.getValue();
1242         assertResourceInfoValues(resourceInfo, null, jobUuid, JobStatus.FAILED);
1243         assertThat(resourceInfo.getErrorMessage().request.requestStatus.getStatusMessage(), containsString("Failed to create service instance"));
1244         assertThat(resourceInfo.getErrorMessage().request.requestStatus.getStatusMessage(), containsString(String.valueOf(errorCode)));
1245         ZonedDateTime parsedDate = TimeUtils.parseZonedDateTime(resourceInfo.getErrorMessage().request.requestStatus.getTimestamp());
1246         assertThat(parsedDate.toLocalDate(), is(LocalDate.now()));
1247
1248         doReturn(resourceInfo).when(asyncInstantiationRepository).getResourceInfoByTrackId(any());
1249         JobAuditStatus jobAuditStatus = auditService.getResourceAuditStatus(resourceInfo.getTrackById());
1250         assertThat(jobAuditStatus.getJobStatus(), equalTo("FAILED"));
1251         assertThat(jobAuditStatus.getAdditionalInfo(), containsString("Failed to create service instance"));
1252         assertThat(jobAuditStatus.getAdditionalInfo(), containsString(String.valueOf(errorCode)));
1253         assertTrue(DateUtils.isSameDay(jobAuditStatus.getCreatedDate(), new Date()));
1254     }
1255
1256     @DataProvider
1257     public static Object[][] updateResourceInfoParameters() {
1258         return new Object[][] {
1259                 {JobStatus.COMPLETED, "Instance was created successfully"},
1260                 {JobStatus.FAILED, "Failed to create instance"}
1261         };
1262     }
1263
1264     @Test(dataProvider = "updateResourceInfoParameters")
1265     public void testUpdateResourceInfo(JobStatus jobStatus, String message) {
1266         reset(asyncInstantiationRepository);
1267         UUID jobUuid = UUID.randomUUID();
1268         JobSharedData sharedData = new JobSharedData(jobUuid, "", mock(ServiceInstantiation.class),"");
1269
1270         ResourceInfo resourceInfoMock = new ResourceInfo();
1271         resourceInfoMock.setTrackById(UUID.randomUUID().toString());
1272         doReturn(resourceInfoMock).when(asyncInstantiationRepository).getResourceInfoByTrackId(any());
1273
1274         AsyncRequestStatus asyncRequestStatus = asyncInstantiationBL.convertMessageToAsyncRequestStatus(message);
1275
1276         asyncInstantiationBL.updateResourceInfo(sharedData, jobStatus, asyncRequestStatus);
1277
1278         ArgumentCaptor<ResourceInfo> resourceInfoCaptor = ArgumentCaptor.forClass(ResourceInfo.class);
1279         verify(asyncInstantiationRepository).saveResourceInfo(resourceInfoCaptor.capture());
1280
1281         ResourceInfo resourceInfo = resourceInfoCaptor.getValue();
1282         assertThat(resourceInfo.getJobStatus(), equalTo(jobStatus));
1283         if (jobStatus == JobStatus.FAILED) {
1284             assertThat(resourceInfo.getErrorMessage(), is(not(nullValue())));
1285             assertThat(resourceInfo.getErrorMessage().request.requestStatus.getStatusMessage(), equalTo(message));
1286             ZonedDateTime parsedDate = TimeUtils.parseZonedDateTime(resourceInfo.getErrorMessage().request.requestStatus.getTimestamp());
1287             assertThat(parsedDate.toLocalDate(), is(LocalDate.now()));
1288         } else {
1289             assertThat(resourceInfo.getErrorMessage(), is(nullValue()));
1290         }
1291
1292         JobAuditStatus jobAuditStatus = auditService.getResourceAuditStatus(resourceInfo.getTrackById());
1293         if (jobStatus == JobStatus.FAILED) {
1294             assertThat(jobAuditStatus.getJobStatus(), equalTo("FAILED"));
1295             assertThat(jobAuditStatus.getAdditionalInfo(), equalTo(message));
1296         } else {
1297             assertThat(jobAuditStatus, is(nullValue()));
1298         }
1299
1300     }
1301
1302     static class MockedJob implements Job {
1303
1304         private static Map<UUID, MockedJob> uuidToJob = new HashMap<>();
1305
1306         public static void putJob(UUID uuid, MockedJob job) {
1307             uuidToJob.put(uuid, job);
1308         }
1309
1310         public static MockedJob getJob(UUID uuid) {
1311             return uuidToJob.get(uuid);
1312         }
1313
1314
1315         private String optimisticUniqueServiceInstanceName;
1316
1317         public MockedJob(String optimisticUniqueServiceInstanceName) {
1318             this.optimisticUniqueServiceInstanceName = optimisticUniqueServiceInstanceName;
1319         }
1320
1321         private UUID uuid = UUID.randomUUID();
1322
1323         @Override
1324         public UUID getUuid() {
1325             return uuid;
1326         }
1327
1328         @Override
1329         public void setUuid(UUID uuid) {
1330             this.uuid = uuid;
1331         }
1332
1333         @Override
1334         public JobStatus getStatus() {
1335             return JobStatus.PENDING;
1336         }
1337
1338         @Override
1339         public void setStatus(JobStatus status) {
1340
1341         }
1342
1343         @Override
1344         public Map<String, Object> getData() {
1345             return null;
1346         }
1347
1348         @Override
1349         public JobSharedData getSharedData() {
1350             return new JobSharedData(uuid, "", null,"");
1351         }
1352
1353         @Override
1354         public void setTypeAndData(JobType jobType, Map<String, Object> commandData) {
1355
1356         }
1357
1358         @Override
1359         public UUID getTemplateId() {
1360             return null;
1361         }
1362
1363         @Override
1364         public void setTemplateId(UUID templateId) {
1365
1366         }
1367
1368         @Override
1369         public Integer getIndexInBulk() {
1370             return null;
1371         }
1372
1373         @Override
1374         public void setIndexInBulk(Integer indexInBulk) {
1375
1376         }
1377
1378         @Override
1379         public JobType getType() {
1380             return null;
1381         }
1382
1383         public String getOptimisticUniqueServiceInstanceName() {
1384             return optimisticUniqueServiceInstanceName;
1385         }
1386     }
1387
1388
1389     @Test
1390     public void testGetVfModuleReplacePath_asMSOexpected()
1391     {
1392         String path = asyncInstantiationBL.getVfModuleReplacePath("myService", "myVNF", "myVFModule");
1393         assertThat(path, equalTo("/serviceInstantiation/v7/serviceInstances/myService/vnfs/myVNF/vfModules/myVFModule/replace"));
1394
1395     }
1396
1397 }