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 org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mockito;
29 import org.mockito.invocation.InvocationOnMock;
30 import org.mockito.stubbing.Answer;
31 import org.openecomp.appc.domainmodel.lcm.*;
32 import org.openecomp.appc.executor.UnstableVNFException;
33 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
34 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
35 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
36 import org.openecomp.appc.requesthandler.exceptions.*;
37 import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl;
38 import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl;
39 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
40 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
41 import org.openecomp.appc.workflow.WorkFlowManager;
42 import org.openecomp.appc.workflow.objects.WorkflowExistsOutput;
43 import org.openecomp.appc.workflow.objects.WorkflowRequest;
44 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
45 import com.att.eelf.configuration.EELFLogger;
46 import com.att.eelf.configuration.EELFManager;
47 import org.openecomp.sdnc.sli.SvcLogicContext;
48 import org.openecomp.sdnc.sli.SvcLogicResource;
49 import org.openecomp.sdnc.sli.aai.AAIService;
50 import org.osgi.framework.Bundle;
51 import org.osgi.framework.BundleContext;
52 import org.osgi.framework.FrameworkUtil;
53 import org.osgi.framework.ServiceReference;
54 import org.powermock.api.mockito.PowerMockito;
55 import org.powermock.core.classloader.annotations.PrepareForTest;
56 import org.powermock.modules.junit4.PowerMockRunner;
58 import java.util.Date;
60 import java.util.UUID;
62 import static junit.framework.TestCase.assertNotNull;
63 import static org.junit.Assert.assertNull;
64 import static org.mockito.Matchers.*;
67 @RunWith(PowerMockRunner.class)
68 @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class})
69 public class TestRequestValidator {
71 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestRequestHandler.class);
73 private static final String TTL_FLAG= "TTL";
75 private RequestValidatorImpl requestValidator;
77 AAIService aaiAdapter ;
78 LifecycleManager lifecyclemanager;
79 WorkFlowManager workflowManager;
80 WorkingStateManager workingStateManager ;
83 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
84 private final Bundle bundleService=Mockito.mock(Bundle.class);
85 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
90 public void init() throws Exception {
92 // dao = Mockito.mock(AppcDAOImpl.class);
93 // PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
94 // Mockito.doNothing().when(dao).storeTransactionRecord((TransactionRecord)anyObject());
95 // PowerMockito.when(dao.queryWorkflow(anyString(),anyString())).thenReturn(true);
98 AAIService aaiService = Mockito.mock(AAIService.class);;
99 PowerMockito.mockStatic(FrameworkUtil.class);
100 PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService);
101 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
102 PowerMockito.when(bundleContext.getServiceReference(AAIService.class.getName())).thenReturn(sref);
103 PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiService);
104 PowerMockito.when(aaiService.query(anyString(),anyBoolean(),anyString(),anyString(),anyString(),anyString(),(SvcLogicContext)anyObject())).thenAnswer(new Answer<SvcLogicResource.QueryStatus>() {
106 public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Throwable {
107 Object[] args = invocation.getArguments();
108 SvcLogicContext ctx =(SvcLogicContext)args[6];
109 String prefix = (String)args[4];
110 String key = (String)args[3];
111 if(key.contains("'28'")){
112 return SvcLogicResource.QueryStatus.FAILURE ;
113 }else if ( key.contains("'8'")) {
114 return SvcLogicResource.QueryStatus.NOT_FOUND ;
116 ctx.setAttribute(prefix + ".vnf-type", "FIREWALL");
117 ctx.setAttribute(prefix + ".orchestration-status", "Instantiated");
119 return SvcLogicResource.QueryStatus.SUCCESS ;
122 PowerMockito.when(aaiService.update(anyString(),anyString(),(Map)anyObject(),anyString(),(SvcLogicContext)anyObject())).thenReturn(SvcLogicResource.QueryStatus.SUCCESS);
123 //PowerMockito.when(requestHandler.getVnfdata(anyString(), anyString(), (SvcLogicContext)anyObject())).thenReturn()
127 aaiAdapter = Mockito.mock(AAIService.class);
128 lifecyclemanager= Mockito.mock(LifecycleManager.class);
129 workflowManager= Mockito.mock(WorkFlowManager.class);
130 workingStateManager = Mockito.mock(WorkingStateManager.class);
132 // transactionRecorder= spy(TransactionRecorder.class);
133 requestValidator = new RequestValidatorImpl();
134 // requestValidator = Mockito.mock(RequestValidator.class);
135 requestValidator.setWorkflowManager(workflowManager);
136 requestValidator.setLifecyclemanager(lifecyclemanager);
137 requestValidator.setWorkingStateManager(workingStateManager);
140 /* Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
141 Mockito.when(aaiAdapter.requestGenericVnfData("1")).thenReturn(getGenericVnf("FIREWALL","INSTNATIATED"));*/
142 // Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(true);
144 /*PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
145 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
146 PowerMockito.when(getAaiadapter().requestGenericVnfData("8")).thenThrow(new AAIAdapterException("404"));
147 Mockito.when(workingStateManager.isVNFStable("8")).thenReturn(true);
148 PowerMockito.when(getAaiadapter().requestGenericVnfData("9")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
149 Mockito.when(workingStateManager.isVNFStable("9")).thenReturn(true);
150 PowerMockito.when(getAaiadapter().requestGenericVnfData("10")).thenReturn(getGenericVnf("WrongRouter","INSTANTIATED"));
151 Mockito.when(workingStateManager.isVNFStable("10")).thenReturn(true);
152 PowerMockito.when(getAaiadapter().requestGenericVnfData("11")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
153 Mockito.when(workingStateManager.isVNFStable("11")).thenReturn(true);
154 PowerMockito.when(getAaiadapter().requestGenericVnfData("12")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
155 Mockito.when(workingStateManager.isVNFStable("12")).thenReturn(true);
156 PowerMockito.when(getAaiadapter().requestGenericVnfData("13")).thenReturn(getGenericVnf("FIREWALL","TESTING"));
157 Mockito.when(workingStateManager.isVNFStable("13")).thenReturn(true);
158 PowerMockito.when(getAaiadapter().requestGenericVnfData("14")).thenReturn(getGenericVnf("FIREWALL","REBUILDING"));
159 Mockito.when(workingStateManager.isVNFStable("14")).thenReturn(true);
160 PowerMockito.when(getAaiadapter().requestGenericVnfData("26")).thenReturn(getGenericVnf("FIREWALL","NOT_INSTANTIATED"));
161 Mockito.when(workingStateManager.isVNFStable("26")).thenReturn(true);
162 PowerMockito.when(getAaiadapter().requestGenericVnfData("27")).thenReturn(getGenericVnf("FIREWALL","RESTARTING"));
163 Mockito.when(workingStateManager.isVNFStable("27")).thenReturn(true);
164 PowerMockito.when(getAaiadapter().requestGenericVnfData("28")).thenThrow(new RuntimeException("AAI Down Excpetion"));
165 Mockito.when(workingStateManager.isVNFStable("28")).thenReturn(true);
166 PowerMockito.when(getAaiadapter().requestGenericVnfData("35")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
167 Mockito.when(workingStateManager.isVNFStable("35")).thenReturn(true);*/
169 /*for(Integer i=130; i<=140 ; i++)
171 PowerMockito.when(getAaiadapter().requestGenericVnfData(i.toString())).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
172 Mockito.when(workingStateManager.isVNFStable(i.toString())).thenReturn(true);
174 PowerMockito.when(getAaiadapter().requestGenericVnfData("39")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
175 Mockito.when(workingStateManager.isVNFStable("39")).thenReturn(true);
176 PowerMockito.when(getAaiadapter().requestGenericVnfData("40")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
177 Mockito.when(workingStateManager.isVNFStable("40")).thenReturn(true).thenReturn(false);
180 PowerMockito.when(getAaiadapter().requestGenericVnfData("38")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
181 Mockito.when(workingStateManager.isVNFStable("38")).thenReturn(true).thenReturn(false);
184 PowerMockito.when(getAaiadapter().requestGenericVnfData("201")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","CONFIGURED"));
185 Mockito.when(workingStateManager.isVNFStable("201")).thenReturn(true);
186 PowerMockito.when(getAaiadapter().requestGenericVnfData("202")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED")).thenReturn(getGenericVnf("FIREWALL","ERROR"));
187 Mockito.when(workingStateManager.isVNFStable("202")).thenReturn(true).thenReturn(false);
189 PowerMockito.when(getAaiadapter().requestGenericVnfData("301")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
190 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true).thenReturn(false);
192 PowerMockito.when(getAaiadapter().requestGenericVnfData("302")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
193 Mockito.when(workingStateManager.isVNFStable("302")).thenReturn(true).thenReturn(true);
195 PowerMockito.when(getAaiadapter().requestGenericVnfData("303")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
196 Mockito.when(workingStateManager.isVNFStable("303")).thenReturn(true).thenReturn(true);
198 PowerMockito.when(getAaiadapter().requestGenericVnfData("309")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
199 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true).thenReturn(true);
201 PowerMockito.when(getAaiadapter().requestGenericVnfData("310")).thenReturn(getGenericVnf("FIREWALL","INSTANTIATED"));
202 Mockito.when(workingStateManager.isVNFStable("310")).thenReturn(true).thenReturn(true);*/
204 public AAIService getAaiadapter() {
205 return this.aaiAdapter;
207 /* public GenericVnf getGenericVnf(String vnfType, String operationalState) {
208 GenericVnf genericVnf = new GenericVnf();
209 genericVnf.setVnfType(vnfType);
210 // genericVnf.setOperationalState(operationalState);
211 genericVnf.setOrchestrationStatus(operationalState);
214 private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp){
215 String API_VERSION= "2.0.0";
216 RequestHandlerInput input = new RequestHandlerInput();
217 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
218 RequestContext requestContext = runtimeContext.getRequestContext();
219 input.setRequestContext(requestContext);
220 requestContext.getActionIdentifiers().setVnfId(vnfID);
221 requestContext.setAction(action);
222 if (action != null) {
223 input.setRpcName(convertActionNameToUrl(action.name()));
226 input.setRpcName(null);
228 requestContext.getCommonHeader().setRequestId(requestId);
229 requestContext.getCommonHeader().setSubRequestId(subRequestId);
230 requestContext.getCommonHeader().setOriginatorId(originatorId);
231 requestContext.getCommonHeader().getFlags().setTtl(ttl);
232 requestContext.getCommonHeader().getFlags().setForce(force);
233 requestContext.getCommonHeader().getTimeStamp();
234 requestContext.getCommonHeader().setApiVer(API_VERSION);
235 requestContext.getCommonHeader().setTimestamp(timeStamp);
239 public void testNullVnfID() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
240 logger.debug("=====================testNullVnfID=============================");
241 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
242 RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30,
243 false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
245 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
247 requestValidator.validateRequest(runtimeContext);
248 }catch(InvalidInputException e ) {
251 // assertEquals(new InvalidInputException("vnfID or command is null") ,ex);
253 logger.debug("=====================testNullVnfID=============================");
257 public void testPositiveFlowWithConfigure() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
258 logger.debug("=====================testPositiveFlowWithConfigure=============================");
259 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
260 Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true);
261 RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30,
262 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
264 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
266 requestValidator.validateRequest(runtimeContext);
267 }catch(Exception e ) {
271 logger.debug("testPositiveFlowWithConfigure");
272 logger.debug("=====================testPositiveFlowWithConfigure=============================");
276 public void testVnfNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
277 logger.debug("=====================testVnfNotFound=============================");
278 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
279 RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30,
280 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
282 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
284 requestValidator.validateRequest(runtimeContext);
285 }catch(Exception e ) {
289 logger.debug("=====================testVnfNotFound=============================");
295 public void testNullCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
296 logger.debug("=====================testNullCommand=============================");
297 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
298 RequestHandlerInput input = this.getRequestHandlerInput("7", null,30,
299 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
301 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
303 requestValidator.validateRequest(runtimeContext);
304 }catch(InvalidInputException e ) {
308 logger.debug("=====================testNullCommand=============================");
312 public void testNullVnfIDAndCommand() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
313 logger.debug("=====================testNullVnfIDAndCommand=============================");
314 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
315 RequestHandlerInput input = this.getRequestHandlerInput(null, null,30,
316 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
318 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
320 requestValidator.validateRequest(runtimeContext);
321 }catch(InvalidInputException e ) {
325 logger.debug("=====================testNullVnfIDAndCommand=============================");
329 public void testWorkflowNotFound() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
330 logger.debug("=====================testWorkflowNotFound=============================");
331 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false));
332 RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30,
333 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
335 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
337 requestValidator.validateRequest(runtimeContext);
338 }catch(Exception e ) {
342 logger.debug("=====================testWorkflowNotFound=============================");
346 public void testUnstableVnfWithConfigure() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
347 logger.debug("=====================testUnstableVnfWithConfigure=============================");
348 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
349 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
351 RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30,
352 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
354 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
356 requestValidator.validateRequest(runtimeContext);
357 }catch(Exception e ) {
361 logger.debug("=====================testUnstableVnfWithConfigure=============================");
365 public void testUnstableVnfWithTest() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
366 logger.debug("=====================testUnstableVnfWithTest=============================");
367 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
368 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
369 RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30,
370 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
372 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
374 requestValidator.validateRequest(runtimeContext);
375 }catch(Exception e ) {
379 logger.debug("=====================testUnstableVnfWithTest=============================");
383 public void testUnstableVnfWithStart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
384 logger.debug("=====================testUnstableVnfWithStart=============================");
385 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
387 RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30,
388 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
390 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
392 requestValidator.validateRequest(runtimeContext);
393 }catch(Exception e ) {
397 logger.debug("=====================testUnstableVnfWithStart=============================");
401 public void testUnstableVnfWithTerminate() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
402 logger.debug("=====================testUnstableVnfWithTerminate=============================");
403 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
404 RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30,
405 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
407 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
409 requestValidator.validateRequest(runtimeContext);
410 }catch(Exception e ) {
414 logger.debug("=====================testUnstableVnfWithTerminate=============================");
418 public void testUnstableVnfWithRestart() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
419 logger.debug("=====================testUnstableVnfWithRestart=============================");
420 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
422 RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30,
423 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
425 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
427 requestValidator.validateRequest(runtimeContext);
428 }catch(Exception e ) {
432 logger.debug("=====================testUnstableVnfWithRestart=============================");
436 public void testUnstableVnfWithRebuild() throws LifecycleException, NoTransitionDefinedException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
437 logger.debug("=====================testUnstableVnfWithRebuild=============================");
438 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","",""));
440 // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8");
441 RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30,
442 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
444 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
446 requestValidator.validateRequest(runtimeContext);
447 }catch(Exception e ) {
451 logger.debug("=====================testUnstableVnfWithRebuild=============================");
458 public void testAAIDown() throws Exception {
459 logger.debug("=====================testAAIDown=============================");
460 // AAIAdapter aaiAdapter = Mockito.mock(AAIAdapterImpl.class);
461 // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
462 // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl());
463 RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30,
464 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date());
466 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
468 requestValidator.validateRequest(runtimeContext);
470 }catch(Exception e ) {
474 logger.debug("=====================testAAIDown=============================");
478 public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
479 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
480 Date now = new Date();
481 Date past = new Date();
482 past.setTime(now.getTime() -1000000 );
483 RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30,
484 false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past);
486 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
489 requestValidator.validateRequest(runtimeContext);
490 }catch(Exception e ) {
494 logger.debug("testNegativeFlowWithTimeStamp");
495 logger.debug("=====================testNegativeFlowWithTimeStamp=============================");
500 public void rejectDuplicateRequest() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException {
501 String originatorID = UUID.randomUUID().toString();
502 String requestID = UUID.randomUUID().toString();
503 String subRequestID = UUID.randomUUID().toString();
505 Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true));
506 Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true);
507 Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true);
508 RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date());
510 RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date());
512 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
513 RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1);
516 requestValidator.validateRequest(runtimeContext);
517 }catch(Exception e ) {
523 requestValidator.validateRequest(runtimeContext1);
524 }catch(Exception e ) {
531 public void testLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
532 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
533 testOperation("no-matter", VNFOperation.Lock);
537 public void testUnlockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
538 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
539 testOperation("no-matter", VNFOperation.Unlock);
543 public void testCheckLockOperation() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
544 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
545 testOperation("no-matter", VNFOperation.CheckLock);
548 @Test(expected = NoTransitionDefinedException.class)
549 public void testLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
550 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Lock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
551 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
552 testOperation("no-matter", VNFOperation.Lock);
555 @Test(expected = NoTransitionDefinedException.class)
556 public void testUnlockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
557 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.Unlock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
558 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
559 testOperation("no-matter", VNFOperation.Unlock);
562 @Test(expected = NoTransitionDefinedException.class)
563 public void testCheckLockOperationNegative() throws RequestExpiredException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, WorkflowNotFoundException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, InvalidInputException {
564 Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(), eq(VNFOperation.CheckLock.toString()))).thenThrow(new NoTransitionDefinedException("", "", ""));
565 Mockito.when(workingStateManager.isVNFStable("no-matter")).thenReturn(true);
566 testOperation("no-matter", VNFOperation.CheckLock);
569 private void testOperation(String resource, VNFOperation operation) throws WorkflowNotFoundException, DuplicateRequestException, DGWorkflowNotFoundException, VNFNotFoundException, InvalidInputException, LifecycleException, UnstableVNFException, NoTransitionDefinedException, RequestExpiredException {
570 String originatorID = UUID.randomUUID().toString();
571 String requestID = UUID.randomUUID().toString();
572 String subRequestID = UUID.randomUUID().toString();
574 RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, new Date());
575 RuntimeContext runtimeContext = putInputToRuntimeContext(input);
576 requestValidator.validateRequest(runtimeContext);
580 private RuntimeContext createRuntimeContextWithSubObjects() {
581 RuntimeContext runtimeContext = new RuntimeContext();
582 RequestContext requestContext = new RequestContext();
583 runtimeContext.setRequestContext(requestContext);
584 ResponseContext responseContext = createResponseContextWithSuObjects();
585 runtimeContext.setResponseContext(responseContext);
586 CommonHeader commonHeader = new CommonHeader();
587 requestContext.setCommonHeader(commonHeader);
588 Flags flags = new Flags();
589 commonHeader.setFlags(flags);
590 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
591 requestContext.setActionIdentifiers(actionIdentifiers);
592 VNFContext vnfContext = new VNFContext();
593 runtimeContext.setVnfContext(vnfContext);
594 return runtimeContext;
598 private ResponseContext createResponseContextWithSuObjects(){
599 ResponseContext responseContext = new ResponseContext();
600 CommonHeader commonHeader = new CommonHeader();
601 Flags flags = new Flags();
602 Status status = new Status();
603 responseContext.setCommonHeader(commonHeader);
604 responseContext.setStatus(status);
605 commonHeader.setFlags(flags);
606 return responseContext;
609 private String convertActionNameToUrl(String action) {
610 String regex = "([a-z])([A-Z]+)";
611 String replacement = "$1-$2";
612 return action.replaceAll(regex, replacement)
616 private RuntimeContext putInputToRuntimeContext(RequestHandlerInput input) {
617 RuntimeContext runtimeContext = createRuntimeContextWithSubObjects();
618 runtimeContext.setRequestContext(input.getRequestContext());
619 runtimeContext.setRpcName(input.getRpcName());
620 runtimeContext.getVnfContext().setId(input.getRequestContext().getActionIdentifiers().getVnfId());
621 //runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(input.getRequestContext().getActionIdentifiers().getVnfId());
622 return runtimeContext;
624 //String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp