2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.requesthandler;
25 import static junit.framework.TestCase.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.mockito.Matchers.anyBoolean;
28 import static org.mockito.Matchers.anyObject;
29 import static org.mockito.Matchers.anyString;
30 import static org.mockito.Matchers.eq;
32 import java.time.Instant;
34 import java.util.UUID;
36 import org.junit.Before;
37 import org.junit.Ignore;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.Mockito;
41 import org.mockito.invocation.InvocationOnMock;
42 import org.mockito.stubbing.Answer;
43 import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers;
44 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
45 import org.openecomp.appc.domainmodel.lcm.Flags;
46 import org.openecomp.appc.domainmodel.lcm.RequestContext;
47 import org.openecomp.appc.domainmodel.lcm.ResponseContext;
48 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
49 import org.openecomp.appc.domainmodel.lcm.Status;
50 import org.openecomp.appc.domainmodel.lcm.VNFContext;
51 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
52 import org.openecomp.appc.executor.UnstableVNFException;
53 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
54 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
55 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
56 import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException;
57 import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException;
58 import org.openecomp.appc.requesthandler.exceptions.InvalidInputException;
59 import org.openecomp.appc.requesthandler.exceptions.RequestExpiredException;
60 import org.openecomp.appc.requesthandler.exceptions.VNFNotFoundException;
61 import org.openecomp.appc.requesthandler.exceptions.WorkflowNotFoundException;
62 import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
63 import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
64 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
65 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
66 import org.openecomp.appc.workflow.WorkFlowManager;
67 import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
68 import org.openecomp.appc.workflow.objects.WorkflowRequest;
69 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
70 import org.openecomp.sdnc.sli.SvcLogicContext;
71 import org.openecomp.sdnc.sli.SvcLogicResource;
72 import org.openecomp.sdnc.sli.aai.AAIService;
73 import org.osgi.framework.Bundle;
74 import org.osgi.framework.BundleContext;
75 import org.osgi.framework.FrameworkUtil;
76 import org.osgi.framework.ServiceReference;
77 import org.powermock.api.mockito.PowerMockito;
78 import org.powermock.core.classloader.annotations.PrepareForTest;
79 import org.powermock.modules.junit4.PowerMockRunner;
81 import com.att.eelf.configuration.EELFLogger;
82 import com.att.eelf.configuration.EELFManager;
85 @RunWith(PowerMockRunner.class)
86 @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
88 public class TestRequestValidator {
90 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
92 private static final String TTL_FLAG= "TTL";
94 private RequestValidatorImpl requestValidator;
96 AAIService aaiAdapter ;
97 LifecycleManager lifecyclemanager;
98 WorkFlowManager workflowManager;
99 WorkingStateManager workingStateManager ;
102 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
103 private final Bundle bundleService=Mockito.mock(Bundle.class);
104 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
109 public void init() throws Exception {
111 // dao = Mockito.mock(AppcDAOImpl.class);
112 // PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
113 // Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
114 // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
117 AAIService aaiService = Mockito.mock(AAIService.class);;
118 PowerMockito.mockStatic(FrameworkUtil.class);
119 PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
120 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
121 PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
122 PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiService);
123 PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
125 public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
126 Object[] args = invocation.getArguments();
127 SvcLogicContext ctx =(SvcLogicContext)args[6];
128 String prefix = (String)args[4];
129 String key = (String)args[3];
130 if(key.contains("'28'")){
131 return SvcLogicResource.QueryStatus.FAILURE ;
132 }else if ( key.contains("'8'")) {
133 return SvcLogicResource.QueryStatus.NOT_FOUND ;
135 ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
136 ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
138 return SvcLogicResource.QueryStatus.SUCCESS ;
141 PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
142 //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
146 aaiAdapter = Mockito.mock(AAIService.class);
147 lifecyclemanager= Mockito.mock(LifecycleManager.class);
148 workflowManager= Mockito.mock(WorkFlowManager.class);
149 workingStateManager = Mockito.mock(WorkingStateManager.class);
151 // transactionRecorder= spy(TransactionRecorder.class);
152 requestValidator = new RequestValidatorImpl();
153 // requestValidator = Mockito.mock(RequestValidator.class);
154 requestValidator.setWorkflowManager(workflowManager);
155 requestValidator.setLifecyclemanager(lifecyclemanager);
156 requestValidator.setWorkingStateManager(workingStateManager);
159 /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
160 Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
161 // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
163 /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
164 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
165 PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
166 Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
167 PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
168 Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
169 PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
170 Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
171 PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
172 Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
173 PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
174 Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
175 PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
176 Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
177 PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
178 Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
179 PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
180 Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
181 PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
182 Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
183 PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
184 Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
185 PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
186 Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
188 /*for(Integer i=130; i<=140 ; i++)
190 PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
191 Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
193 PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
194 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
195 PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
196 Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
199 PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
200 Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
203 PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
204 Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
205 PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
206 Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
208 PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
209 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
211 PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
212 Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
214 PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
215 Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
217 PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
218 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
220 PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
221 Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
223 public AAIService getAaiadapter() {
224 return this.aaiAdapter;
226 /* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
227 GenericVnf genericVnf = new GenericVnf();
228 genericVnf.setVnfType(vnfType);
229 // genericVnf.setOperationalState(operationalState);
230 genericVnf.setOrchestrationStatus(operationalState);
233 private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){
234 String API_VERSION= "2.0.0";
235 RequestHandlerInput input = new RequestHandlerInput();
236 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
237 RequestContext requestContext = runtimeContext.getRequestContext();
238 input.setRequestContext(requestContext);
239 requestContext.getActionIdentifiers().setVnfId(vnfID);
240 requestContext.setAction(action);
241 if (action != null) {
242 input.setRpcName(convertActionNameToUrl(action.name()));
245 input.setRpcName(null);
247 requestContext.getCommonHeader().setRequestId(requestId);
248 requestContext.getCommonHeader().setSubRequestId(subRequestId);
249 requestContext.getCommonHeader().setOriginatorId(originatorId);
250 requestContext.getCommonHeader().setFlags(new Flags(null, force, ttl));
251 requestContext.getCommonHeader().getTimeStamp();
252 requestContext.getCommonHeader().setApiVer(API_VERSION);
253 requestContext.getCommonHeader().setTimestamp(timeStamp);
257 public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
258 logger.debug("=====================testNullVnfID=============================");
259 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
260 RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
261 false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
263 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
265 requestValidator.validateRequest(runtimeContext);
266 }catch(InvalidInputException e ) {
269 // assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
271 logger.debug("=====================testNullVnfID=============================");
275 public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
276 logger.debug("=====================testPositiveFlowWithConfigure=============================");
277 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
278 Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
279 RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
280 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
282 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
284 requestValidator.validateRequest(runtimeContext);
285 }catch(Exception e ) {
289 logger.debug("testPositiveFlowWithConfigure");
290 logger.debug("=====================testPositiveFlowWithConfigure=============================");
294 public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
295 logger.debug("=====================testVnfNotFound=============================");
296 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
297 RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
298 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
300 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
302 requestValidator.validateRequest(runtimeContext);
303 }catch(Exception e ) {
307 logger.debug("=====================testVnfNotFound=============================");
313 public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
314 logger.debug("=====================testNullCommand=============================");
315 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
316 RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
317 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
319 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
321 requestValidator.validateRequest(runtimeContext);
322 }catch(InvalidInputException e ) {
326 logger.debug("=====================testNullCommand=============================");
330 public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
331 logger.debug("=====================testNullVnfIDAndCommand=============================");
332 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
333 RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
334 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
336 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
338 requestValidator.validateRequest(runtimeContext);
339 }catch(InvalidInputException e ) {
343 logger.debug("=====================testNullVnfIDAndCommand=============================");
347 public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
348 logger.debug("=====================testWorkflowNotFound=============================");
349 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
350 RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
351 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
353 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
355 requestValidator.validateRequest(runtimeContext);
356 }catch(Exception e ) {
360 logger.debug("=====================testWorkflowNotFound=============================");
364 public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
365 logger.debug("=====================testUnstableVnfWithConfigure=============================");
366 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
367 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
369 RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
370 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
372 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
374 requestValidator.validateRequest(runtimeContext);
375 }catch(Exception e ) {
379 logger.debug("=====================testUnstableVnfWithConfigure=============================");
383 public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
384 logger.debug("=====================testUnstableVnfWithTest=============================");
385 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
386 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
387 RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
388 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
390 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
392 requestValidator.validateRequest(runtimeContext);
393 }catch(Exception e ) {
397 logger.debug("=====================testUnstableVnfWithTest=============================");
401 public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
402 logger.debug("=====================testUnstableVnfWithStart=============================");
403 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
405 RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
406 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
408 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
410 requestValidator.validateRequest(runtimeContext);
411 }catch(Exception e ) {
415 logger.debug("=====================testUnstableVnfWithStart=============================");
419 public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
420 logger.debug("=====================testUnstableVnfWithTerminate=============================");
421 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
422 RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
423 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
425 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
427 requestValidator.validateRequest(runtimeContext);
428 }catch(Exception e ) {
432 logger.debug("=====================testUnstableVnfWithTerminate=============================");
436 public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
437 logger.debug("=====================testUnstableVnfWithRestart=============================");
438 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
440 RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
441 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
443 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
445 requestValidator.validateRequest(runtimeContext);
446 }catch(Exception e ) {
450 logger.debug("=====================testUnstableVnfWithRestart=============================");
454 public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
455 logger.debug("=====================testUnstableVnfWithRebuild=============================");
456 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
458 // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
459 RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
460 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
462 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
464 requestValidator.validateRequest(runtimeContext);
465 }catch(Exception e ) {
469 logger.debug("=====================testUnstableVnfWithRebuild=============================");
476 public void testAAIDown() throws Exception {
477 logger.debug("=====================testAAIDown=============================");
478 // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
479 // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
480 // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
481 RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
482 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
484 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
486 requestValidator.validateRequest(runtimeContext);
488 }catch(Exception e ) {
492 logger.debug("=====================testAAIDown=============================");
496 public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
497 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
498 Instant now = Instant.now();
499 Instant past = now.minusMillis(1000000);
500 RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30,
501 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past);
503 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
506 requestValidator.validateRequest(runtimeContext);
507 }catch(Exception e ) {
511 logger.debug("testNegativeFlowWithTimeStamp");
512 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
517 public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
518 String originatorID = UUID.randomUUID().toString();
519 String requestID = UUID.randomUUID().toString();
520 String subRequestID = UUID.randomUUID().toString();
522 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
523 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
524 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
525 RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
527 RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
529 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
530 RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
533 requestValidator.validateRequest(runtimeContext);
534 }catch(Exception e ) {
540 requestValidator.validateRequest(runtimeContext1);
541 }catch(Exception e ) {
548 public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
549 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
550 testOperation("no-matter", VNFOperation.Lock);
554 public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
555 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
556 testOperation("no-matter", VNFOperation.Unlock);
560 public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
561 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
562 testOperation("no-matter", VNFOperation.CheckLock);
565 @Test(expected = NoTransitionDefinedException.class)
566 public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
567 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
568 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
569 testOperation("no-matter", VNFOperation.Lock);
572 @Test(expected = NoTransitionDefinedException.class)
573 public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
574 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
575 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
576 testOperation("no-matter", VNFOperation.Unlock);
579 @Test(expected = NoTransitionDefinedException.class)
580 public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
581 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
582 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
583 testOperation("no-matter", VNFOperation.CheckLock);
586 private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException {
587 String originatorID = UUID.randomUUID().toString();
588 String requestID = UUID.randomUUID().toString();
589 String subRequestID = UUID.randomUUID().toString();
591 RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now());
592 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
593 requestValidator.validateRequest(runtimeContext);
597 private RuntimeContext createRuntimeContextWithSubObjects() {
598 RuntimeContext runtimeContext = new RuntimeContext();
599 RequestContext requestContext = new RequestContext();
600 runtimeContext.setRequestContext(requestContext);
601 ResponseContext responseContext = createResponseContextWithSuObjects();
602 runtimeContext.setResponseContext(responseContext);
603 CommonHeader commonHeader = new CommonHeader();
604 requestContext.setCommonHeader(commonHeader);
605 commonHeader.setFlags(new Flags(null, false, 0));
606 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
607 requestContext.setActionIdentifiers(actionIdentifiers);
608 VNFContext vnfContext = new VNFContext();
609 runtimeContext.setVnfContext(vnfContext);
610 return runtimeContext;
614 private ResponseContext createResponseContextWithSuObjects(){
615 ResponseContext responseContext = new ResponseContext();
616 CommonHeader commonHeader = new CommonHeader();
617 responseContext.setCommonHeader(commonHeader);
618 responseContext.setStatus(new Status(0, null));
619 commonHeader.setFlags(new Flags(null, false, 0));
620 return responseContext;
623 private String convertActionNameToUrl(String action) {
624 String regex = "([a-z])([A-Z]+)";
625 String replacement = "$1-$2";
626 return action.replaceAll(regex, replacement)
630 private RuntimeContext putInputToRuntimeContext(RequestHandlerInput input) {
631 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
632 runtimeContext.setRequestContext(input.getRequestContext());
633 runtimeContext.setRpcName(input.getRpcName());
634 runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
635 //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
636 return runtimeContext;
638 //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp