aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java34
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/impl/RequestValidatorImplTest.java43
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\"}");
}