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.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mockito;
40 import org.mockito.invocation.InvocationOnMock;
41 import org.mockito.stubbing.Answer;
42 import org.openecomp.appc.domainmodel.lcm.*;
43 import org.openecomp.appc.executor.UnstableVNFException;
44 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
45 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
46 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
47 import org.openecomp.appc.requesthandler.exceptions.*;
48 import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
49 import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
50 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
51 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
52 import org.openecomp.appc.workflow.WorkFlowManager;
53 import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
54 import org.openecomp.appc.workflow.objects.WorkflowRequest;
55 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
56 import org.openecomp.sdnc.sli.SvcLogicContext;
57 import org.openecomp.sdnc.sli.SvcLogicResource;
58 import org.openecomp.sdnc.sli.aai.AAIService;
59 import org.osgi.framework.Bundle;
60 import org.osgi.framework.BundleContext;
61 import org.osgi.framework.FrameworkUtil;
62 import org.osgi.framework.ServiceReference;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PrepareForTest;
65 import org.powermock.modules.junit4.PowerMockRunner;
67 import com.att.eelf.configuration.EELFLogger;
68 import com.att.eelf.configuration.EELFManager;
71 @RunWith(PowerMockRunner.class)
72 @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
73 public class TestRequestValidator {
75 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
77 private static final String TTL_FLAG= "TTL";
79 private RequestValidatorImpl requestValidator;
81 AAIService aaiAdapter ;
82 LifecycleManager lifecyclemanager;
83 WorkFlowManager workflowManager;
84 WorkingStateManager workingStateManager ;
85 LCMStateManager lcmStateManager;
88 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
89 private final Bundle bundleService=Mockito.mock(Bundle.class);
90 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
95 public void init() throws Exception {
97 // dao = Mockito.mock(AppcDAOImpl.class);
98 // PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
99 // Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
100 // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
103 AAIService aaiService = Mockito.mock(AAIService.class);;
104 PowerMockito.mockStatic(FrameworkUtil.class);
105 PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
106 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
107 PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
108 PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
109 PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
111 public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
112 Object[] args = invocation.getArguments();
113 SvcLogicContext ctx =(SvcLogicContext)args[6];
114 String prefix = (String)args[4];
115 String key = (String)args[3];
116 if(key.contains("'28'")){
117 return SvcLogicResource.QueryStatus.FAILURE ;
118 }else if ( key.contains("'8'")) {
119 return SvcLogicResource.QueryStatus.NOT_FOUND ;
121 ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
122 ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
124 return SvcLogicResource.QueryStatus.SUCCESS ;
127 PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
128 //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
132 aaiAdapter = Mockito.mock(AAIService.class);
133 lifecyclemanager= Mockito.mock(LifecycleManager.class);
134 workflowManager= Mockito.mock(WorkFlowManager.class);
135 workingStateManager = Mockito.mock(WorkingStateManager.class);
136 lcmStateManager = Mockito.mock(LCMStateManager.class);
138 // transactionRecorder= spy(TransactionRecorder.class);
139 requestValidator = new RequestValidatorImpl();
140 // requestValidator = Mockito.mock(RequestValidator.class);
141 requestValidator.setWorkflowManager(workflowManager);
142 requestValidator.setLifecyclemanager(lifecyclemanager);
143 requestValidator.setWorkingStateManager(workingStateManager);
144 requestValidator.setLcmStateManager(lcmStateManager);
146 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
147 /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
148 Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
149 // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
151 /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
152 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
153 PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
154 Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
155 PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
156 Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
157 PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
158 Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
159 PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
160 Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
161 PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
162 Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
163 PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
164 Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
165 PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
166 Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
167 PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
168 Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
169 PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
170 Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
171 PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
172 Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
173 PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
174 Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
176 /*for(Integer i=130; i<=140 ; i++)
178 PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
179 Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
181 PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
182 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
183 PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
184 Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
187 PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
188 Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
191 PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
192 Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
193 PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
194 Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
196 PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
197 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
199 PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
200 Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
202 PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
203 Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
205 PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
206 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
208 PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
209 Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
211 public AAIService getAaiadapter() {
212 return this.aaiAdapter;
214 /* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
215 GenericVnf genericVnf = new GenericVnf();
216 genericVnf.setVnfType(vnfType);
217 // genericVnf.setOperationalState(operationalState);
218 genericVnf.setOrchestrationStatus(operationalState);
221 private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){
222 String API_VERSION= "2.0.0";
223 RequestHandlerInput input = new RequestHandlerInput();
224 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
225 RequestContext requestContext = runtimeContext.getRequestContext();
226 input.setRequestContext(requestContext);
227 requestContext.getActionIdentifiers().setVnfId(vnfID);
228 requestContext.setAction(action);
229 if (action != null) {
230 input.setRpcName(convertActionNameToUrl(action.name()));
233 input.setRpcName(null);
235 requestContext.getCommonHeader().setRequestId(requestId);
236 requestContext.getCommonHeader().setSubRequestId(subRequestId);
237 requestContext.getCommonHeader().setOriginatorId(originatorId);
238 requestContext.getCommonHeader().setFlags(new Flags(null, force, ttl));
239 requestContext.getCommonHeader().getTimeStamp();
240 requestContext.getCommonHeader().setApiVer(API_VERSION);
241 requestContext.getCommonHeader().setTimestamp(timeStamp);
245 public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
246 logger.debug("=====================testNullVnfID=============================");
247 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
248 RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
249 false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
251 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
253 requestValidator.validateRequest(runtimeContext);
254 }catch(InvalidInputException e ) {
257 // assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
259 logger.debug("=====================testNullVnfID=============================");
263 public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
264 logger.debug("=====================testPositiveFlowWithConfigure=============================");
265 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
266 Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
267 RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
268 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
270 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
272 requestValidator.validateRequest(runtimeContext);
273 }catch(Exception e ) {
277 logger.debug("testPositiveFlowWithConfigure");
278 logger.debug("=====================testPositiveFlowWithConfigure=============================");
282 public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
283 logger.debug("=====================testVnfNotFound=============================");
284 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
285 RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
286 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
288 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
290 requestValidator.validateRequest(runtimeContext);
291 }catch(Exception e ) {
295 logger.debug("=====================testVnfNotFound=============================");
301 public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
302 logger.debug("=====================testNullCommand=============================");
303 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
304 RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
305 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
307 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
309 requestValidator.validateRequest(runtimeContext);
310 }catch(InvalidInputException e ) {
314 logger.debug("=====================testNullCommand=============================");
318 public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
319 logger.debug("=====================testNullVnfIDAndCommand=============================");
320 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
321 RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
322 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
324 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
326 requestValidator.validateRequest(runtimeContext);
327 }catch(InvalidInputException e ) {
331 logger.debug("=====================testNullVnfIDAndCommand=============================");
335 public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
336 logger.debug("=====================testWorkflowNotFound=============================");
337 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
338 RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
339 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
341 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
343 requestValidator.validateRequest(runtimeContext);
344 }catch(Exception e ) {
348 logger.debug("=====================testWorkflowNotFound=============================");
352 public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
353 logger.debug("=====================testUnstableVnfWithConfigure=============================");
354 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
355 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
357 RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
358 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
360 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
362 requestValidator.validateRequest(runtimeContext);
363 }catch(Exception e ) {
367 logger.debug("=====================testUnstableVnfWithConfigure=============================");
371 public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
372 logger.debug("=====================testUnstableVnfWithTest=============================");
373 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
374 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
375 RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
376 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
378 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
380 requestValidator.validateRequest(runtimeContext);
381 }catch(Exception e ) {
385 logger.debug("=====================testUnstableVnfWithTest=============================");
389 public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
390 logger.debug("=====================testUnstableVnfWithStart=============================");
391 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
393 RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
394 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
396 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
398 requestValidator.validateRequest(runtimeContext);
399 }catch(Exception e ) {
403 logger.debug("=====================testUnstableVnfWithStart=============================");
407 public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
408 logger.debug("=====================testUnstableVnfWithTerminate=============================");
409 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
410 RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
411 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
413 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
415 requestValidator.validateRequest(runtimeContext);
416 }catch(Exception e ) {
420 logger.debug("=====================testUnstableVnfWithTerminate=============================");
424 public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
425 logger.debug("=====================testUnstableVnfWithRestart=============================");
426 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
428 RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
429 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
431 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
433 requestValidator.validateRequest(runtimeContext);
434 }catch(Exception e ) {
438 logger.debug("=====================testUnstableVnfWithRestart=============================");
442 public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
443 logger.debug("=====================testUnstableVnfWithRebuild=============================");
444 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
446 // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
447 RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
448 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
450 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
452 requestValidator.validateRequest(runtimeContext);
453 }catch(Exception e ) {
457 logger.debug("=====================testUnstableVnfWithRebuild=============================");
464 public void testAAIDown() throws Exception {
465 logger.debug("=====================testAAIDown=============================");
466 // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
467 // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
468 // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
469 RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
470 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
472 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
474 requestValidator.validateRequest(runtimeContext);
476 }catch(Exception e ) {
480 logger.debug("=====================testAAIDown=============================");
484 public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
485 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
486 Instant now = Instant.now();
487 Instant past = now.minusMillis(1000000);
488 RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30,
489 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past);
491 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
494 requestValidator.validateRequest(runtimeContext);
495 }catch(Exception e ) {
499 logger.debug("testNegativeFlowWithTimeStamp");
500 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
505 public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
506 String originatorID = UUID.randomUUID().toString();
507 String requestID = UUID.randomUUID().toString();
508 String subRequestID = UUID.randomUUID().toString();
510 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
511 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
512 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
513 RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
515 RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
517 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
518 RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
521 requestValidator.validateRequest(runtimeContext);
522 }catch(Exception e ) {
528 requestValidator.validateRequest(runtimeContext1);
529 }catch(Exception e ) {
536 public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
537 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
538 testOperation("no-matter", VNFOperation.Lock);
542 public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
543 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
544 testOperation("no-matter", VNFOperation.Unlock);
548 public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
549 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
550 testOperation("no-matter", VNFOperation.CheckLock);
553 @Test(expected = NoTransitionDefinedException.class)
554 public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
555 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
556 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
557 testOperation("no-matter", VNFOperation.Lock);
560 @Test(expected = NoTransitionDefinedException.class)
561 public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
562 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
563 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
564 testOperation("no-matter", VNFOperation.Unlock);
567 @Test(expected = NoTransitionDefinedException.class)
568 public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
569 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
570 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
571 testOperation("no-matter", VNFOperation.CheckLock);
574 @Test(expected = LCMOperationsDisabledException.class)
575 public void testLCMOperationsDisabled() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
576 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
577 testOperation("no-matter", VNFOperation.Configure);
579 private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
580 String originatorID = UUID.randomUUID().toString();
581 String requestID = UUID.randomUUID().toString();
582 String subRequestID = UUID.randomUUID().toString();
584 RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now());
585 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
586 requestValidator.validateRequest(runtimeContext);
590 private RuntimeContext createRuntimeContextWithSubObjects() {
591 RuntimeContext runtimeContext = new RuntimeContext();
592 RequestContext requestContext = new RequestContext();
593 runtimeContext.setRequestContext(requestContext);
594 ResponseContext responseContext = createResponseContextWithSuObjects();
595 runtimeContext.setResponseContext(responseContext);
596 CommonHeader commonHeader = new CommonHeader();
597 requestContext.setCommonHeader(commonHeader);
598 commonHeader.setFlags(new Flags(null, false, 0));
599 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
600 requestContext.setActionIdentifiers(actionIdentifiers);
601 VNFContext vnfContext = new VNFContext();
602 runtimeContext.setVnfContext(vnfContext);
603 return runtimeContext;
607 private ResponseContext createResponseContextWithSuObjects(){
608 ResponseContext responseContext = new ResponseContext();
609 CommonHeader commonHeader = new CommonHeader();
610 responseContext.setCommonHeader(commonHeader);
611 responseContext.setStatus(new Status(0, null));
612 commonHeader.setFlags(new Flags(null, false, 0));
613 return responseContext;
616 private String convertActionNameToUrl(String action) {
617 String regex = "([a-z])([A-Z]+)";
618 String replacement = "$1-$2";
619 return action.replaceAll(regex, replacement)
623 private RuntimeContext putInputToRuntimeContext(RequestHandlerInput input) {
624 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
625 runtimeContext.setRequestContext(input.getRequestContext());
626 runtimeContext.setRpcName(input.getRpcName());
627 runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
628 //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
629 return runtimeContext;
631 //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp