* 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.
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;
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 {
logger.info("Initializing RequestValidatorImpl.");
String endpoint = null;
String user = null;
- String pass =null;
+ String pass = null;
String transactionWindow = null;
Properties properties = configuration.getProperties();
* ================================================================================
* 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.
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;
private LockManager lockManager;
private LCMStateManager lcmStateManager;
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
@Before
public void setUp() throws Exception {
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());
.thenReturn(workflowExistsOutput);
impl.setWorkflowManager(workflowManager);
ResponseContext responseContext = runtimeContext.getResponseContext();
- CommonHeader commonHeader = returnResponseContextCommonHeader(responseContext);
+ returnResponseContextCommonHeader(responseContext);
impl.validateRequest(runtimeContext);
}
.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());
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());
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());
@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));
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\"}");
}