diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-02-22 16:17:28 +0000 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-25 14:36:12 +0000 |
commit | 356dba9fb407b1df3fe89a4c8f082a09aa564d36 (patch) | |
tree | 6d95340b783748f35b86e25ee4659217bdd0a51f /appc-dispatcher/appc-request-handler | |
parent | 3cef43b0cf7244d26aab5d9752fde518f0970d47 (diff) |
Test coverage in RequestValidatorImpl
Increased coverage from 78% to 89%
Issue-ID: APPC-1485
Change-Id: I2b4e87d0ae9b344ef59005bc19cd2600e4e041e8
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dispatcher/appc-request-handler')
2 files changed, 51 insertions, 26 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java index da571bd15..a0b27462d 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +25,18 @@ package org.onap.appc.requesthandler.impl; -import com.att.eelf.i18n.EELFResourceManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import jline.internal.Log; - +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpResponse; -import org.json.JSONObject; import org.onap.appc.domainmodel.lcm.Flags; import org.onap.appc.domainmodel.lcm.RequestContext; import org.onap.appc.domainmodel.lcm.RuntimeContext; @@ -68,22 +70,16 @@ import org.onap.appc.validationpolicy.objects.RuleResult; import org.onap.appc.workflow.WorkFlowManager; import org.onap.appc.workflow.objects.WorkflowExistsOutput; import org.onap.appc.workflow.objects.WorkflowRequest; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Properties; -import java.util.stream.Collectors; +import com.att.eelf.i18n.EELFResourceManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; public class RequestValidatorImpl extends AbstractRequestValidatorImpl { @@ -104,7 +100,7 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { logger.info("Initializing RequestValidatorImpl."); String endpoint = null; String user = null; - String pass =null; + String pass = null; String transactionWindow = null; Properties properties = configuration.getProperties(); 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 8e3d77cd3..ba2915189 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 @@ -6,7 +6,7 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ - * Copyright (C) 2018 Ericsson. All rights reserved. + * Copyright (C) 2018-2019 Ericsson. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,9 @@ import org.apache.http.entity.BasicHttpEntity; import org.apache.http.message.BasicHttpResponse; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.internal.util.reflection.Whitebox; @@ -110,6 +112,8 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { private LockManager lockManager; private LCMStateManager lcmStateManager; + @Rule + public ExpectedException expectedEx = ExpectedException.none(); @Before public void setUp() throws Exception { @@ -213,7 +217,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { Mockito.when(workflowManager.workflowExists(Mockito.any(WorkflowRequest.class))).thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); - CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext); + returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); @@ -268,7 +272,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { .thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); - CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext); + returnResponseContextCommonHeader(responseContext); impl.validateRequest(runtimeContext); } @@ -309,7 +313,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { .thenReturn(workflowExistsOutput); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); - CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext); + returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); @@ -351,7 +355,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { Mockito.when(workflowExistsOutput.isMappingExist()).thenReturn(false); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); - CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext); + returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED");; httpResponse.setEntity(getHttpEntity()); @@ -384,7 +388,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { Mockito.when(workflowExistsOutput.isDgExist()).thenReturn(false); impl.setWorkflowManager(workflowManager); ResponseContext responseContext = runtimeContext.getResponseContext(); - CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext); + returnResponseContextCommonHeader(responseContext); RestClientInvoker client = mock(RestClientInvoker.class); HttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP",1,0), 200, "ACCEPTED"); httpResponse.setEntity(getHttpEntity()); @@ -402,7 +406,7 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { @Test public void testLogInProgressTransactions() { - ArrayList<TransactionRecord> trArray = new ArrayList(); + ArrayList<TransactionRecord> trArray = new ArrayList<>(); TransactionRecord tr = new TransactionRecord(); tr.setRequestState(RequestStatus.ACCEPTED); tr.setStartTime(Instant.now().minus(48, ChronoUnit.HOURS)); @@ -413,6 +417,31 @@ public class RequestValidatorImplTest implements LocalRequestHanlderTestHelper { assertTrue(StringUtils.contains(loggedMessage, partMessage)); } + @Test + public void testWithTransactionWindowNumberFormatException() throws APPCException { + Properties properties = new Properties(); + properties.put(RequestValidatorImpl.TRANSACTION_WINDOW_HOURS, "TEST"); + properties.put(RequestValidatorImpl.SCOPE_OVERLAP_ENDPOINT, "TEST"); + Configuration config = Mockito.mock(Configuration.class); + Mockito.when(config.getProperties()).thenReturn(properties); + Whitebox.setInternalState(impl, "configuration", config); + expectedEx.expect(APPCException.class); + expectedEx.expectMessage("RequestValidatorImpl:::Error parsing transaction window interval!"); + impl.initialize(); + } + + @Test + public void testWithTransactionWindow() throws APPCException { + Properties properties = new Properties(); + properties.put(RequestValidatorImpl.TRANSACTION_WINDOW_HOURS, "1"); + properties.put(RequestValidatorImpl.SCOPE_OVERLAP_ENDPOINT, "http://server:80"); + Configuration config = Mockito.mock(Configuration.class); + Mockito.when(config.getProperties()).thenReturn(properties); + Whitebox.setInternalState(impl, "configuration", config); + impl.initialize(); + assertTrue(Whitebox.getInternalState(impl, "client") instanceof RestClientInvoker); + } + private RuntimeContext createRequestValidatorInput() { return createRequestHandlerRuntimeContext("VSCP", "{\"request-id\":\"request-id\"}"); } |