2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.requesthandler;
28 import static junit.framework.TestCase.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.mockito.Matchers.anyBoolean;
31 import static org.mockito.Matchers.anyObject;
32 import static org.mockito.Matchers.anyString;
33 import static org.mockito.Matchers.eq;
35 import java.time.Instant;
37 import java.util.UUID;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mockito;
43 import org.mockito.invocation.InvocationOnMock;
44 import org.mockito.stubbing.Answer;
45 import org.openecomp.appc.domainmodel.lcm.*;
46 import org.openecomp.appc.executor.UnstableVNFException;
47 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
48 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
49 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
50 import org.openecomp.appc.requesthandler.exceptions.*;
51 import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
52 import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
53 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
54 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
55 import org.openecomp.appc.workflow.WorkFlowManager;
56 import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
57 import org.openecomp.appc.workflow.objects.WorkflowRequest;
58 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
59 import org.openecomp.sdnc.sli.SvcLogicContext;
60 import org.openecomp.sdnc.sli.SvcLogicResource;
61 import org.openecomp.sdnc.sli.aai.AAIService;
62 import org.osgi.framework.Bundle;
63 import org.osgi.framework.BundleContext;
64 import org.osgi.framework.FrameworkUtil;
65 import org.osgi.framework.ServiceReference;
66 import org.powermock.api.mockito.PowerMockito;
67 import org.powermock.core.classloader.annotations.PrepareForTest;
68 import org.powermock.modules.junit4.PowerMockRunner;
70 import com.att.eelf.configuration.EELFLogger;
71 import com.att.eelf.configuration.EELFManager;
74 @RunWith(PowerMockRunner.class)
75 @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
76 public class TestRequestValidator {
78 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
80 private static final String TTL_FLAG= "TTL";
82 private RequestValidatorImpl requestValidator;
84 AAIService aaiAdapter ;
85 LifecycleManager lifecyclemanager;
86 WorkFlowManager workflowManager;
87 WorkingStateManager workingStateManager ;
88 LCMStateManager lcmStateManager;
91 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
92 private final Bundle bundleService=Mockito.mock(Bundle.class);
93 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
98 public void init() throws Exception {
100 // dao = Mockito.mock(AppcDAOImpl.class);
101 // PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
102 // Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
103 // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
106 AAIService aaiService = Mockito.mock(AAIService.class);;
107 PowerMockito.mockStatic(FrameworkUtil.class);
108 PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
109 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
110 PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
111 PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
112 PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
114 public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
115 Object[] args = invocation.getArguments();
116 SvcLogicContext ctx =(SvcLogicContext)args[6];
117 String prefix = (String)args[4];
118 String key = (String)args[3];
119 if(key.contains("'28'")){
120 return SvcLogicResource.QueryStatus.FAILURE ;
121 }else if ( key.contains("'8'")) {
122 return SvcLogicResource.QueryStatus.NOT_FOUND ;
124 ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
125 ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
127 return SvcLogicResource.QueryStatus.SUCCESS ;
130 PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
131 //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
135 aaiAdapter = Mockito.mock(AAIService.class);
136 lifecyclemanager= Mockito.mock(LifecycleManager.class);
137 workflowManager= Mockito.mock(WorkFlowManager.class);
138 workingStateManager = Mockito.mock(WorkingStateManager.class);
139 lcmStateManager = Mockito.mock(LCMStateManager.class);
141 // transactionRecorder= spy(TransactionRecorder.class);
142 requestValidator = new RequestValidatorImpl();
143 // requestValidator = Mockito.mock(RequestValidator.class);
144 requestValidator.setWorkflowManager(workflowManager);
145 requestValidator.setLifecyclemanager(lifecyclemanager);
146 requestValidator.setWorkingStateManager(workingStateManager);
147 requestValidator.setLcmStateManager(lcmStateManager);
149 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
150 /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
151 Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
152 // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
154 /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
155 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
156 PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
157 Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
158 PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
159 Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
160 PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
161 Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
162 PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
163 Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
164 PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
165 Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
166 PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
167 Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
168 PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
169 Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
170 PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
171 Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
172 PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
173 Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
174 PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
175 Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
176 PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
177 Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
179 /*for(Integer i=130; i<=140 ; i++)
181 PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
182 Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
184 PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
185 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
186 PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
187 Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
190 PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
191 Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
194 PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
195 Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
196 PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
197 Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
199 PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
200 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
202 PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
203 Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
205 PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
206 Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
208 PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
209 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
211 PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
212 Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
214 public AAIService getAaiadapter() {
215 return this.aaiAdapter;
217 /* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
218 GenericVnf genericVnf = new GenericVnf();
219 genericVnf.setVnfType(vnfType);
220 // genericVnf.setOperationalState(operationalState);
221 genericVnf.setOrchestrationStatus(operationalState);
224 private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){
225 String API_VERSION= "2.0.0";
226 RequestHandlerInput input = new RequestHandlerInput();
227 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
228 RequestContext requestContext = runtimeContext.getRequestContext();
229 input.setRequestContext(requestContext);
230 requestContext.getActionIdentifiers().setVnfId(vnfID);
231 requestContext.setAction(action);
232 if (action != null) {
233 input.setRpcName(convertActionNameToUrl(action.name()));
236 input.setRpcName(null);
238 requestContext.getCommonHeader().setRequestId(requestId);
239 requestContext.getCommonHeader().setSubRequestId(subRequestId);
240 requestContext.getCommonHeader().setOriginatorId(originatorId);
241 requestContext.getCommonHeader().setFlags(new Flags(null, force, ttl));
242 requestContext.getCommonHeader().getTimeStamp();
243 requestContext.getCommonHeader().setApiVer(API_VERSION);
244 requestContext.getCommonHeader().setTimestamp(timeStamp);
248 public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
249 logger.debug("=====================testNullVnfID=============================");
250 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
251 RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
252 false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
254 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
256 requestValidator.validateRequest(runtimeContext);
257 }catch(InvalidInputException e ) {
260 // assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
262 logger.debug("=====================testNullVnfID=============================");
266 public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
267 logger.debug("=====================testPositiveFlowWithConfigure=============================");
268 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
269 Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
270 RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
271 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
273 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
275 requestValidator.validateRequest(runtimeContext);
276 }catch(Exception e ) {
280 logger.debug("testPositiveFlowWithConfigure");
281 logger.debug("=====================testPositiveFlowWithConfigure=============================");
285 public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
286 logger.debug("=====================testVnfNotFound=============================");
287 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
288 RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
289 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
291 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
293 requestValidator.validateRequest(runtimeContext);
294 }catch(Exception e ) {
298 logger.debug("=====================testVnfNotFound=============================");
304 public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
305 logger.debug("=====================testNullCommand=============================");
306 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
307 RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
308 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
310 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
312 requestValidator.validateRequest(runtimeContext);
313 }catch(InvalidInputException e ) {
317 logger.debug("=====================testNullCommand=============================");
321 public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
322 logger.debug("=====================testNullVnfIDAndCommand=============================");
323 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
324 RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
325 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
327 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
329 requestValidator.validateRequest(runtimeContext);
330 }catch(InvalidInputException e ) {
334 logger.debug("=====================testNullVnfIDAndCommand=============================");
338 public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
339 logger.debug("=====================testWorkflowNotFound=============================");
340 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
341 RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
342 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
344 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
346 requestValidator.validateRequest(runtimeContext);
347 }catch(Exception e ) {
351 logger.debug("=====================testWorkflowNotFound=============================");
355 public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
356 logger.debug("=====================testUnstableVnfWithConfigure=============================");
357 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
358 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
360 RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
361 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
363 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
365 requestValidator.validateRequest(runtimeContext);
366 }catch(Exception e ) {
370 logger.debug("=====================testUnstableVnfWithConfigure=============================");
374 public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
375 logger.debug("=====================testUnstableVnfWithTest=============================");
376 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
377 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
378 RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
379 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
381 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
383 requestValidator.validateRequest(runtimeContext);
384 }catch(Exception e ) {
388 logger.debug("=====================testUnstableVnfWithTest=============================");
392 public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
393 logger.debug("=====================testUnstableVnfWithStart=============================");
394 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
396 RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
397 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
399 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
401 requestValidator.validateRequest(runtimeContext);
402 }catch(Exception e ) {
406 logger.debug("=====================testUnstableVnfWithStart=============================");
410 public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
411 logger.debug("=====================testUnstableVnfWithTerminate=============================");
412 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
413 RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
414 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
416 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
418 requestValidator.validateRequest(runtimeContext);
419 }catch(Exception e ) {
423 logger.debug("=====================testUnstableVnfWithTerminate=============================");
427 public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
428 logger.debug("=====================testUnstableVnfWithRestart=============================");
429 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
431 RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
432 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
434 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
436 requestValidator.validateRequest(runtimeContext);
437 }catch(Exception e ) {
441 logger.debug("=====================testUnstableVnfWithRestart=============================");
445 public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
446 logger.debug("=====================testUnstableVnfWithRebuild=============================");
447 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
449 // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
450 RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
451 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
453 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
455 requestValidator.validateRequest(runtimeContext);
456 }catch(Exception e ) {
460 logger.debug("=====================testUnstableVnfWithRebuild=============================");
467 public void testAAIDown() throws Exception {
468 logger.debug("=====================testAAIDown=============================");
469 // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
470 // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
471 // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
472 RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
473 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
475 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
477 requestValidator.validateRequest(runtimeContext);
479 }catch(Exception e ) {
483 logger.debug("=====================testAAIDown=============================");
487 public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
488 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
489 Instant now = Instant.now();
490 Instant past = now.minusMillis(1000000);
491 RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30,
492 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past);
494 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
497 requestValidator.validateRequest(runtimeContext);
498 }catch(Exception e ) {
502 logger.debug("testNegativeFlowWithTimeStamp");
503 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
508 public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
509 String originatorID = UUID.randomUUID().toString();
510 String requestID = UUID.randomUUID().toString();
511 String subRequestID = UUID.randomUUID().toString();
513 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
514 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
515 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
516 RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
518 RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
520 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
521 RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
524 requestValidator.validateRequest(runtimeContext);
525 }catch(Exception e ) {
531 requestValidator.validateRequest(runtimeContext1);
532 }catch(Exception e ) {
539 public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
540 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
541 testOperation("no-matter", VNFOperation.Lock);
545 public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
546 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
547 testOperation("no-matter", VNFOperation.Unlock);
551 public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
552 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
553 testOperation("no-matter", VNFOperation.CheckLock);
556 @Test(expected = NoTransitionDefinedException.class)
557 public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
558 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
559 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
560 testOperation("no-matter", VNFOperation.Lock);
563 @Test(expected = NoTransitionDefinedException.class)
564 public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
565 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
566 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
567 testOperation("no-matter", VNFOperation.Unlock);
570 @Test(expected = NoTransitionDefinedException.class)
571 public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
572 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
573 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
574 testOperation("no-matter", VNFOperation.CheckLock);
577 @Test(expected = LCMOperationsDisabledException.class)
578 public void testLCMOperationsDisabled() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
579 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
580 testOperation("no-matter", VNFOperation.Configure);
582 private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
583 String originatorID = UUID.randomUUID().toString();
584 String requestID = UUID.randomUUID().toString();
585 String subRequestID = UUID.randomUUID().toString();
587 RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now());
588 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
589 requestValidator.validateRequest(runtimeContext);
593 private RuntimeContext createRuntimeContextWithSubObjects() {
594 RuntimeContext runtimeContext = new RuntimeContext();
595 RequestContext requestContext = new RequestContext();
596 runtimeContext.setRequestContext(requestContext);
597 ResponseContext responseContext = createResponseContextWithSuObjects();
598 runtimeContext.setResponseContext(responseContext);
599 CommonHeader commonHeader = new CommonHeader();
600 requestContext.setCommonHeader(commonHeader);
601 commonHeader.setFlags(new Flags(null, false, 0));
602 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
603 requestContext.setActionIdentifiers(actionIdentifiers);
604 VNFContext vnfContext = new VNFContext();
605 runtimeContext.setVnfContext(vnfContext);
606 return runtimeContext;
610 private ResponseContext createResponseContextWithSuObjects(){
611 ResponseContext responseContext = new ResponseContext();
612 CommonHeader commonHeader = new CommonHeader();
613 responseContext.setCommonHeader(commonHeader);
614 responseContext.setStatus(new Status(0, null));
615 commonHeader.setFlags(new Flags(null, false, 0));
616 return responseContext;
619 private String convertActionNameToUrl(String action) {
620 String regex = "([a-z])([A-Z]+)";
621 String replacement = "$1-$2";
622 return action.replaceAll(regex, replacement)
626 private RuntimeContext putInputToRuntimeContext(RequestHandlerInput input) {
627 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
628 runtimeContext.setRequestContext(input.getRequestContext());
629 runtimeContext.setRpcName(input.getRpcName());
630 runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
631 //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
632 return runtimeContext;
634 //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp