diff options
author | 2020-01-16 15:13:14 -0500 | |
---|---|---|
committer | 2020-01-29 19:44:48 +0000 | |
commit | b5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch) | |
tree | 3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test | |
parent | 9b32cb60360a2a2973c621053510718de0072111 (diff) |
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting.
Issue-ID: APPC-1789
Signed-off-by: Dunietz, Irwin <id1681@att.com>
Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test')
3 files changed, 68 insertions, 50 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImplTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImplTest.java index a2c3ec360..89d34111a 100755 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImplTest.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImplTest.java @@ -2,6 +2,8 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018-2019 Ericsson. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at * @@ -97,7 +99,8 @@ public class AbstractRequestHandlerImplTest implements LocalRequestHanlderTestHe recorder = mock(TransactionRecorder.class); requestHandler.setTransactionRecorder(recorder); List<RequestStatus> result = Arrays.asList(RequestStatus.ACCEPTED); - PowerMockito.when(recorder.getRecords(anyString(), anyString(), anyString(), anyString())).thenReturn(result); + PowerMockito.when(recorder.getRecords(anyString(), anyString(), anyString(), anyString())) + .thenReturn(result); final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractRequestHandlerImpl.class); logger.setLevel(Level.TRACE); Whitebox.setInternalState(requestHandler, "logger", logger); @@ -210,14 +213,21 @@ public class AbstractRequestHandlerImplTest implements LocalRequestHanlderTestHe PowerMockito.when(bundleContext.getService(sref)).thenReturn(metricService); MetricRegistry metricRegistry = Mockito.mock(MetricRegistry.class); DispatchingFuntionMetric dispatchingFunctionMetric = Mockito.mock(DispatchingFuntionMetric.class); - DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder = Mockito.mock(DispatchingFunctionCounterBuilder.class); + DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder = + Mockito.mock(DispatchingFunctionCounterBuilder.class); MetricBuilderFactory metricBuilderFactory = Mockito.mock(MetricBuilderFactory.class); - Mockito.when(dispatchingFunctionCounterBuilder.withName("DISPATCH_FUNCTION")).thenReturn(dispatchingFunctionCounterBuilder); - Mockito.when(dispatchingFunctionCounterBuilder.withType(MetricType.COUNTER)).thenReturn(dispatchingFunctionCounterBuilder); - Mockito.when(dispatchingFunctionCounterBuilder.withAcceptRequestValue(0)).thenReturn(dispatchingFunctionCounterBuilder); - Mockito.when(dispatchingFunctionCounterBuilder.withRejectRequestValue(0)).thenReturn(dispatchingFunctionCounterBuilder); - Mockito.when(dispatchingFunctionCounterBuilder.build()).thenReturn(dispatchingFunctionMetric); - Mockito.when(metricBuilderFactory.dispatchingFunctionCounterBuilder()).thenReturn(dispatchingFunctionCounterBuilder); + Mockito.when(dispatchingFunctionCounterBuilder.withName("DISPATCH_FUNCTION")) + .thenReturn(dispatchingFunctionCounterBuilder); + Mockito.when(dispatchingFunctionCounterBuilder.withType(MetricType.COUNTER)) + .thenReturn(dispatchingFunctionCounterBuilder); + Mockito.when(dispatchingFunctionCounterBuilder.withAcceptRequestValue(0)) + .thenReturn(dispatchingFunctionCounterBuilder); + Mockito.when(dispatchingFunctionCounterBuilder.withRejectRequestValue(0)) + .thenReturn(dispatchingFunctionCounterBuilder); + Mockito.when(dispatchingFunctionCounterBuilder.build()). + thenReturn(dispatchingFunctionMetric); + Mockito.when(metricBuilderFactory.dispatchingFunctionCounterBuilder()) + .thenReturn(dispatchingFunctionCounterBuilder); Mockito.when(metricRegistry.metricBuilderFactory()).thenReturn(metricBuilderFactory); Mockito.when(metricService.createRegistry("APPC")).thenReturn(metricRegistry); Mockito.when(metricRegistry.register(dispatchingFunctionMetric)).thenReturn(true); @@ -237,8 +247,8 @@ public class AbstractRequestHandlerImplTest implements LocalRequestHanlderTestHe @Test public void testMetricNullMetricService() throws Exception { expectedEx.expect(NullPointerException.class); - expectedEx.expectMessage("org.onap.appc.metricservice.MetricService is null. " + - "Failed to init Metric"); + expectedEx.expectMessage("org.onap.appc.metricservice.MetricService is null. " + + "Failed to init Metric"); Whitebox.invokeMethod(requestHandler, "initMetric"); } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestHandlerImplTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestHandlerImplTest.java index f163c6eab..437cd5d4b 100755 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestHandlerImplTest.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestHandlerImplTest.java @@ -2,6 +2,8 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of the License at * @@ -84,7 +86,8 @@ public class RequestHandlerImplTest implements LocalRequestHanlderTestHelper { lockManager = mock(LockManager.class); requestHandler.setLockManager(lockManager); List<RequestStatus> result = Arrays.asList(RequestStatus.ACCEPTED); - PowerMockito.when(recorder.getRecords(anyString(), anyString(), anyString(), anyString())).thenReturn(result); + PowerMockito.when(recorder.getRecords(anyString(), anyString(), anyString(), anyString())) + .thenReturn(result); final EELFLogger logger = EELFManager.getInstance().getLogger(RequestHandlerImpl.class); logger.setLevel(Level.TRACE); Whitebox.setInternalState(requestHandler, "logger", logger); @@ -142,7 +145,7 @@ public class RequestHandlerImplTest implements LocalRequestHanlderTestHelper { doNothing().when(requestHandler).fillStatus(Mockito.any(RuntimeContext.class), Mockito.any(LCMCommandStatus.class), Mockito.any()); doThrow(new APPCException("TEST_APPC_EXCEPTION")).when(commandExecutor) - .executeCommand(Mockito.any(CommandExecutorInput.class)); + .executeCommand(Mockito.any(CommandExecutorInput.class)); doNothing().when(requestHandler).storeErrorMessageToLog(Mockito.any(RuntimeContext.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); requestHandler.handleRequest(runtimeContext); diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestValidatorImplTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestValidatorImplTest.java index ba2915189..bb713cdc9 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestValidatorImplTest.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestValidatorImplTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -19,7 +19,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -127,24 +126,24 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { AAIService aaiService = Mockito.mock(AAIService.class); PowerMockito.when(aaiService.query( anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), anyObject())) - .thenAnswer(new Answer<SvcLogicResource.QueryStatus>() { - @Override - public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Exception { - Object[] args = invocation.getArguments(); - SvcLogicContext ctx = (SvcLogicContext) args[6]; - String prefix = (String) args[4]; - String key = (String) args[3]; - if (key.contains("'28'")) { - return SvcLogicResource.QueryStatus.FAILURE; - } else if (key.contains("'8'")) { - return SvcLogicResource.QueryStatus.NOT_FOUND; - } else { - ctx.setAttribute(prefix + ".vnf-type", "FIREWALL"); - ctx.setAttribute(prefix + ".orchestration-status", "Instantiated"); + .thenAnswer(new Answer<SvcLogicResource.QueryStatus>() { + @Override + public SvcLogicResource.QueryStatus answer(InvocationOnMock invocation) throws Exception { + Object[] args = invocation.getArguments(); + SvcLogicContext ctx = (SvcLogicContext) args[6]; + String prefix = (String) args[4]; + String key = (String) args[3]; + if (key.contains("'28'")) { + return SvcLogicResource.QueryStatus.FAILURE; + } else if (key.contains("'8'")) { + return SvcLogicResource.QueryStatus.NOT_FOUND; + } else { + ctx.setAttribute(prefix + ".vnf-type", "FIREWALL"); + ctx.setAttribute(prefix + ".orchestration-status", "Instantiated"); + } + return SvcLogicResource.QueryStatus.SUCCESS; } - return SvcLogicResource.QueryStatus.SUCCESS; - } - }); + }); PowerMockito.mockStatic(FrameworkUtil.class); PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(bundleService); PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); @@ -209,17 +208,19 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { transactionRecord.setRequestState(RequestStatus.ACCEPTED); runtimeContext.setTransactionRecord(transactionRecord); transactionRecordList.add(transactionRecord); - Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class),Mockito.any(int.class))) - .thenReturn(transactionRecordList); + Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class), + Mockito.any(int.class))) + .thenReturn(transactionRecordList); impl.setTransactionRecorder(transactionRecorder); WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(true, true); WorkFlowManager workflowManager = Mockito.mock(WorkFlowManagerImpl.class); - Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))).thenReturn(workflowExistsOutput); + Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))) + .thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); - HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); + HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); Mockito.when(client.doPost(Mockito.anyString(), Mockito.anyString())).thenReturn(httpResponse); impl.setClient(client); @@ -227,7 +228,8 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { RuleExecutor ruleExecutor = Mockito.mock(RuleExecutor.class); RuleResult ruleResult = RuleResult.REJECT; Mockito.when(requestValidationPolicy.getInProgressRuleExecutor()).thenReturn(ruleExecutor); - Mockito.when(ruleExecutor.executeRule(Mockito.anyString(), Mockito.anyListOf(VNFOperation.class))).thenReturn(ruleResult); + Mockito.when(ruleExecutor.executeRule(Mockito.anyString(), Mockito.anyListOf(VNFOperation.class))) + .thenReturn(ruleResult); impl.setRequestValidationPolicy(requestValidationPolicy); impl.validateRequest(runtimeContext); } @@ -262,14 +264,15 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { inProgressTransaction.setStartTime(Instant.now().minus(5, ChronoUnit.HOURS)); inProgressTransaction.setRequestState(RequestStatus.ACCEPTED); transactionRecordList.add(inProgressTransaction); - Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class),Mockito.any(int.class))) + Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class), + Mockito.any(int.class))) .thenReturn(transactionRecordList); runtimeContext.setTransactionRecord(inProgressTransaction); impl.setTransactionRecorder(transactionRecorder); WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(true, true); WorkFlowManager workflowManager = Mockito.mock(WorkFlowManagerImpl.class); Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))) - .thenReturn(workflowExistsOutput); + .thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); returnResponseContextCommonHeader(responseContext); @@ -302,20 +305,21 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { inProgressTransaction.setRequestState(RequestStatus.ACCEPTED); inProgressTransaction.setStartTime(Instant.now().minus(48, ChronoUnit.HOURS)); transactionRecordList.add(inProgressTransaction); - Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class),Mockito.any(int.class))) - .thenReturn(transactionRecordList); + Mockito.when(transactionRecorder.getInProgressRequests(Mockito.any(TransactionRecord.class), + Mockito.any(int.class))) + .thenReturn(transactionRecordList); Mockito.when(transactionRecorder.isTransactionDuplicate(anyObject())).thenReturn(false); impl.setTransactionRecorder(transactionRecorder); runtimeContext.setTransactionRecord(inProgressTransaction); WorkFlowManager workflowManager = Mockito.mock(WorkFlowManagerImpl.class); WorkflowExistsOutput workflowExistsOutput = Mockito.spy(new WorkflowExistsOutput(true, true)); Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))) - .thenReturn(workflowExistsOutput); + .thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); - HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); + HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); Mockito.when(client.doPost(Mockito.anyString(), Mockito.anyString())).thenReturn(httpResponse); impl.setClient(client); @@ -324,7 +328,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { RuleResult ruleResult = RuleResult.ACCEPT; Mockito.when(requestValidationPolicy.getInProgressRuleExecutor()).thenReturn(ruleExecutor); Mockito.when(ruleExecutor.executeRule(Mockito.anyString(), Mockito.anyListOf(VNFOperation.class))) - .thenReturn(ruleResult); + .thenReturn(ruleResult); impl.setRequestValidationPolicy(requestValidationPolicy); RequestContext requestContext = new RequestContext(); ActionIdentifiers actionIdentifiers = new ActionIdentifiers(); @@ -351,13 +355,13 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { WorkflowExistsOutput workflowExistsOutput = Mockito.spy(new WorkflowExistsOutput(true, true)); WorkFlowManager workflowManager = Mockito.mock(WorkFlowManagerImpl.class); Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))) - .thenReturn(workflowExistsOutput); + .thenReturn(workflowExistsOutput); Mockito.when(workflowExistsOutput.isMappingExist()).thenReturn(false); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); - HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED");; + HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); Mockito.when(client.doPost(Mockito.anyString(), Mockito.anyString())).thenReturn(httpResponse); impl.setClient(client); @@ -366,7 +370,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { RuleResult ruleResult = RuleResult.REJECT; Mockito.when(requestValidationPolicy.getInProgressRuleExecutor()).thenReturn(ruleExecutor); Mockito.when(ruleExecutor.executeRule(Mockito.anyString(), Mockito.anyListOf(VNFOperation.class))) - .thenReturn(ruleResult); + .thenReturn(ruleResult); impl.setRequestValidationPolicy(requestValidationPolicy); impl.validateRequest(runtimeContext); } @@ -384,13 +388,13 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { WorkflowExistsOutput workflowExistsOutput = Mockito.spy(new WorkflowExistsOutput(true, true)); WorkFlowManager workflowManager = Mockito.mock(WorkFlowManagerImpl.class); Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))) - .thenReturn(workflowExistsOutput); + .thenReturn(workflowExistsOutput); Mockito.when(workflowExistsOutput.isDgExist()).thenReturn(false); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); - HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); + HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); Mockito.when(client.doPost(Mockito.anyString(), Mockito.anyString())).thenReturn(httpResponse); impl.setClient(client); @@ -399,7 +403,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { RuleResult ruleResult = RuleResult.REJECT; Mockito.when(requestValidationPolicy.getInProgressRuleExecutor()).thenReturn(ruleExecutor); Mockito.when(ruleExecutor.executeRule(Mockito.anyString(), Mockito.anyListOf(VNFOperation.class))) - .thenReturn(ruleResult); + .thenReturn(ruleResult); impl.setRequestValidationPolicy(requestValidationPolicy); impl.validateRequest(runtimeContext); } @@ -458,7 +462,8 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { private BasicHttpEntity getHttpEntity() { BasicHttpEntity httpEntity = new BasicHttpEntity(); InputStream inputStream = new ByteArrayInputStream( - "{\"output\": {\"status\": {\"message\": \"test_messge\",\"code\": \"400\",\"status\":\"test_status\"},\"response-info\": { \"block\": \"true\"}}}".getBytes()); + "{\"output\": {\"status\": {\"message\": \"test_messge\",\"code\": \"400\",\"status\":\"test_status\"},\"response-info\": { \"block\": \"true\"}}}" + .getBytes()); httpEntity.setContent(inputStream); return httpEntity; } |