2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.requesthandler;
26 import static junit.framework.TestCase.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.mockito.Matchers.anyBoolean;
29 import static org.mockito.Matchers.anyObject;
30 import static org.mockito.Matchers.anyString;
31 import static org.mockito.Matchers.eq;
33 import java.time.Instant;
35 import java.util.UUID;
37 import org.junit.Before;
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.*;
44 import org.openecomp.appc.executor.UnstableVNFException;
45 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
46 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
47 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
48 import org.openecomp.appc.requesthandler.exceptions.*;
49 import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
50 import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
51 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
52 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
53 import org.openecomp.appc.workflow.WorkFlowManager;
54 import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
55 import org.openecomp.appc.workflow.objects.WorkflowRequest;
56 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
57 import org.openecomp.sdnc.sli.SvcLogicContext;
58 import org.openecomp.sdnc.sli.SvcLogicResource;
59 import org.openecomp.sdnc.sli.aai.AAIService;
60 import org.osgi.framework.Bundle;
61 import org.osgi.framework.BundleContext;
62 import org.osgi.framework.FrameworkUtil;
63 import org.osgi.framework.ServiceReference;
64 import org.powermock.api.mockito.PowerMockito;
65 import org.powermock.core.classloader.annotations.PrepareForTest;
66 import org.powermock.modules.junit4.PowerMockRunner;
68 import com.att.eelf.configuration.EELFLogger;
69 import com.att.eelf.configuration.EELFManager;
72 @RunWith(PowerMockRunner.class)
73 @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
74 public class TestRequestValidator {
76 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
78 private static final String TTL_FLAG= "TTL";
80 private RequestValidatorImpl requestValidator;
82 AAIService aaiAdapter ;
83 LifecycleManager lifecyclemanager;
84 WorkFlowManager workflowManager;
85 WorkingStateManager workingStateManager ;
86 LCMStateManager lcmStateManager;
89 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
90 private final Bundle bundleService=Mockito.mock(Bundle.class);
91 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
96 public void init() throws Exception {
98 // dao = Mockito.mock(AppcDAOImpl.class);
99 // PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
100 // Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
101 // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
104 AAIService aaiService = Mockito.mock(AAIService.class);;
105 PowerMockito.mockStatic(FrameworkUtil.class);
106 PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
107 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
108 PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
109 PowerMockito.when(bundleContext.<AAIService>getService(sref)).thenReturn(aaiService);
110 PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
112 public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
113 Object[] args = invocation.getArguments();
114 SvcLogicContext ctx =(SvcLogicContext)args[6];
115 String prefix = (String)args[4];
116 String key = (String)args[3];
117 if(key.contains("'28'")){
118 return SvcLogicResource.QueryStatus.FAILURE ;
119 }else if ( key.contains("'8'")) {
120 return SvcLogicResource.QueryStatus.NOT_FOUND ;
122 ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
123 ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
125 return SvcLogicResource.QueryStatus.SUCCESS ;
128 PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
129 //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
133 aaiAdapter = Mockito.mock(AAIService.class);
134 lifecyclemanager= Mockito.mock(LifecycleManager.class);
135 workflowManager= Mockito.mock(WorkFlowManager.class);
136 workingStateManager = Mockito.mock(WorkingStateManager.class);
137 lcmStateManager = Mockito.mock(LCMStateManager.class);
139 // transactionRecorder= spy(TransactionRecorder.class);
140 requestValidator = new RequestValidatorImpl();
141 // requestValidator = Mockito.mock(RequestValidator.class);
142 requestValidator.setWorkflowManager(workflowManager);
143 requestValidator.setLifecyclemanager(lifecyclemanager);
144 requestValidator.setWorkingStateManager(workingStateManager);
145 requestValidator.setLcmStateManager(lcmStateManager);
147 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
148 /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
149 Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
150 // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
152 /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
153 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
154 PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
155 Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
156 PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
157 Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
158 PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
159 Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
160 PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
161 Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
162 PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
163 Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
164 PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
165 Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
166 PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
167 Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
168 PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
169 Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
170 PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
171 Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
172 PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
173 Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
174 PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
175 Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
177 /*for(Integer i=130; i<=140 ; i++)
179 PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
180 Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
182 PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
183 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
184 PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
185 Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
188 PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
189 Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
192 PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
193 Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
194 PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
195 Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
197 PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
198 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
200 PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
201 Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
203 PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
204 Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
206 PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
207 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
209 PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
210 Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
212 public AAIService getAaiadapter() {
213 return this.aaiAdapter;
215 /* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
216 GenericVnf genericVnf = new GenericVnf();
217 genericVnf.setVnfType(vnfType);
218 // genericVnf.setOperationalState(operationalState);
219 genericVnf.setOrchestrationStatus(operationalState);
222 private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){
223 String API_VERSION= "2.0.0";
224 RequestHandlerInput input = new RequestHandlerInput();
225 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
226 RequestContext requestContext = runtimeContext.getRequestContext();
227 input.setRequestContext(requestContext);
228 requestContext.getActionIdentifiers().setVnfId(vnfID);
229 requestContext.setAction(action);
230 if (action != null) {
231 input.setRpcName(convertActionNameToUrl(action.name()));
234 input.setRpcName(null);
236 requestContext.getCommonHeader().setRequestId(requestId);
237 requestContext.getCommonHeader().setSubRequestId(subRequestId);
238 requestContext.getCommonHeader().setOriginatorId(originatorId);
239 requestContext.getCommonHeader().setFlags(new Flags(null, force, ttl));
240 requestContext.getCommonHeader().getTimeStamp();
241 requestContext.getCommonHeader().setApiVer(API_VERSION);
242 requestContext.getCommonHeader().setTimestamp(timeStamp);
246 public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
247 logger.debug("=====================testNullVnfID=============================");
248 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
249 RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
250 false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
252 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
254 requestValidator.validateRequest(runtimeContext);
255 }catch(InvalidInputException e ) {
258 // assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
260 logger.debug("=====================testNullVnfID=============================");
264 public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
265 logger.debug("=====================testPositiveFlowWithConfigure=============================");
266 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
267 Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
268 RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
269 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
271 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
273 requestValidator.validateRequest(runtimeContext);
274 }catch(Exception e ) {
278 logger.debug("testPositiveFlowWithConfigure");
279 logger.debug("=====================testPositiveFlowWithConfigure=============================");
283 public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
284 logger.debug("=====================testVnfNotFound=============================");
285 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
286 RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
287 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
289 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
291 requestValidator.validateRequest(runtimeContext);
292 }catch(Exception e ) {
296 logger.debug("=====================testVnfNotFound=============================");
302 public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
303 logger.debug("=====================testNullCommand=============================");
304 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
305 RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
306 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
308 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
310 requestValidator.validateRequest(runtimeContext);
311 }catch(InvalidInputException e ) {
315 logger.debug("=====================testNullCommand=============================");
319 public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
320 logger.debug("=====================testNullVnfIDAndCommand=============================");
321 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
322 RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
323 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
325 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
327 requestValidator.validateRequest(runtimeContext);
328 }catch(InvalidInputException e ) {
332 logger.debug("=====================testNullVnfIDAndCommand=============================");
336 public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
337 logger.debug("=====================testWorkflowNotFound=============================");
338 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
339 RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
340 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
342 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
344 requestValidator.validateRequest(runtimeContext);
345 }catch(Exception e ) {
349 logger.debug("=====================testWorkflowNotFound=============================");
353 public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
354 logger.debug("=====================testUnstableVnfWithConfigure=============================");
355 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
356 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
358 RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
359 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
361 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
363 requestValidator.validateRequest(runtimeContext);
364 }catch(Exception e ) {
368 logger.debug("=====================testUnstableVnfWithConfigure=============================");
372 public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
373 logger.debug("=====================testUnstableVnfWithTest=============================");
374 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
375 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
376 RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
377 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
379 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
381 requestValidator.validateRequest(runtimeContext);
382 }catch(Exception e ) {
386 logger.debug("=====================testUnstableVnfWithTest=============================");
390 public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
391 logger.debug("=====================testUnstableVnfWithStart=============================");
392 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
394 RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
395 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
397 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
399 requestValidator.validateRequest(runtimeContext);
400 }catch(Exception e ) {
404 logger.debug("=====================testUnstableVnfWithStart=============================");
408 public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
409 logger.debug("=====================testUnstableVnfWithTerminate=============================");
410 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
411 RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
412 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
414 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
416 requestValidator.validateRequest(runtimeContext);
417 }catch(Exception e ) {
421 logger.debug("=====================testUnstableVnfWithTerminate=============================");
425 public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
426 logger.debug("=====================testUnstableVnfWithRestart=============================");
427 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
429 RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
430 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
432 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
434 requestValidator.validateRequest(runtimeContext);
435 }catch(Exception e ) {
439 logger.debug("=====================testUnstableVnfWithRestart=============================");
443 public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
444 logger.debug("=====================testUnstableVnfWithRebuild=============================");
445 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
447 // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
448 RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
449 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
451 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
453 requestValidator.validateRequest(runtimeContext);
454 }catch(Exception e ) {
458 logger.debug("=====================testUnstableVnfWithRebuild=============================");
465 public void testAAIDown() throws Exception {
466 logger.debug("=====================testAAIDown=============================");
467 // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
468 // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
469 // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
470 RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
471 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now());
473 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
475 requestValidator.validateRequest(runtimeContext);
477 }catch(Exception e ) {
481 logger.debug("=====================testAAIDown=============================");
485 public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
486 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
487 Instant now = Instant.now();
488 Instant past = now.minusMillis(1000000);
489 RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30,
490 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past);
492 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
495 requestValidator.validateRequest(runtimeContext);
496 }catch(Exception e ) {
500 logger.debug("testNegativeFlowWithTimeStamp");
501 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
506 public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
507 String originatorID = UUID.randomUUID().toString();
508 String requestID = UUID.randomUUID().toString();
509 String subRequestID = UUID.randomUUID().toString();
511 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
512 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
513 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
514 RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
516 RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now());
518 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
519 RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
522 requestValidator.validateRequest(runtimeContext);
523 }catch(Exception e ) {
529 requestValidator.validateRequest(runtimeContext1);
530 }catch(Exception e ) {
537 public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
538 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
539 testOperation("no-matter", VNFOperation.Lock);
543 public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
544 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
545 testOperation("no-matter", VNFOperation.Unlock);
549 public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
550 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
551 testOperation("no-matter", VNFOperation.CheckLock);
554 @Test(expected = NoTransitionDefinedException.class)
555 public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
556 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
557 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
558 testOperation("no-matter", VNFOperation.Lock);
561 @Test(expected = NoTransitionDefinedException.class)
562 public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
563 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
564 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
565 testOperation("no-matter", VNFOperation.Unlock);
568 @Test(expected = NoTransitionDefinedException.class)
569 public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
570 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
571 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
572 testOperation("no-matter", VNFOperation.CheckLock);
575 @Test(expected = LCMOperationsDisabledException.class)
576 public void testLCMOperationsDisabled() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
577 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
578 testOperation("no-matter", VNFOperation.Configure);
580 private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
581 String originatorID = UUID.randomUUID().toString();
582 String requestID = UUID.randomUUID().toString();
583 String subRequestID = UUID.randomUUID().toString();
585 RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now());
586 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
587 requestValidator.validateRequest(runtimeContext);
591 private RuntimeContext createRuntimeContextWithSubObjects() {
592 RuntimeContext runtimeContext = new RuntimeContext();
593 RequestContext requestContext = new RequestContext();
594 runtimeContext.setRequestContext(requestContext);
595 ResponseContext responseContext = createResponseContextWithSuObjects();
596 runtimeContext.setResponseContext(responseContext);
597 CommonHeader commonHeader = new CommonHeader();
598 requestContext.setCommonHeader(commonHeader);
599 commonHeader.setFlags(new Flags(null, false, 0));
600 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
601 requestContext.setActionIdentifiers(actionIdentifiers);
602 VNFContext vnfContext = new VNFContext();
603 runtimeContext.setVnfContext(vnfContext);
604 return runtimeContext;
608 private ResponseContext createResponseContextWithSuObjects(){
609 ResponseContext responseContext = new ResponseContext();
610 CommonHeader commonHeader = new CommonHeader();
611 responseContext.setCommonHeader(commonHeader);
612 responseContext.setStatus(new Status(0, null));
613 commonHeader.setFlags(new Flags(null, false, 0));
614 return responseContext;
617 private String convertActionNameToUrl(String action) {
618 String regex = "([a-z])([A-Z]+)";
619 String replacement = "$1-$2";
620 return action.replaceAll(regex, replacement)
624 private RuntimeContext putInputToRuntimeContext(RequestHandlerInput input) {
625 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
626 runtimeContext.setRequestContext(input.getRequestContext());
627 runtimeContext.setRpcName(input.getRpcName());
628 runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
629 //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
630 return runtimeContext;
632 //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp