summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/pom.xml30
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIVersion.java2
-rw-r--r--common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java2
-rw-r--r--common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java16
-rw-r--r--common/src/main/java/org/onap/so/logger/ErrorCode.java2
-rw-r--r--common/src/main/java/org/onap/so/logger/ScheduledTasksMDCSetup.java75
-rw-r--r--common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java3
-rw-r--r--common/src/main/java/org/onap/so/security/WebSecurityConfig.java8
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/RequestError.java11
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/RequestInfo.java13
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/ServiceException.java3
-rw-r--r--common/src/main/java/org/onap/so/utils/Components.java18
-rw-r--r--common/src/main/java/org/onap/so/utils/CryptoUtils.java4
-rw-r--r--common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java1
-rw-r--r--common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java118
-rw-r--r--common/src/test/java/org/onap/so/logger/ScheduledTasksMDCSetupTest.java83
-rw-r--r--common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java61
17 files changed, 325 insertions, 125 deletions
diff --git a/common/pom.xml b/common/pom.xml
index cd6f01641a..94b28e91bd 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -58,7 +58,7 @@
<dependency>
<groupId>org.onap.aai.schema-service</groupId>
<artifactId>aai-schema</artifactId>
- <version>1.0.5</version>
+ <version>1.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
@@ -131,6 +131,17 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.onap.aaf.authz</groupId>
+ <artifactId>aaf-cadi-aaf</artifactId>
+ <version>2.1.9</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
@@ -245,6 +256,23 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <executions>
+ <execution>
+ <id>tests-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIVersion.java b/common/src/main/java/org/onap/so/client/aai/AAIVersion.java
index 3a59b2b337..4f06b787f7 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIVersion.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIVersion.java
@@ -23,7 +23,7 @@ package org.onap.so.client.aai;
import org.onap.so.client.graphinventory.GraphInventoryVersion;
public enum AAIVersion implements GraphInventoryVersion {
- V13("v13"), V14("v14"), V15("v15"), V16("v16"), V17("v17");
+ V13("v13"), V14("v14"), V15("v15"), V16("v16"), V17("v17"), V18("v18"), V19("v19");
public static final AAIVersion LATEST = AAIVersion.values()[AAIVersion.values().length - 1];
private final String value;
diff --git a/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java b/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java
index ccfd2f4de6..641bbb28c7 100644
--- a/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java
+++ b/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java
@@ -21,5 +21,5 @@
package org.onap.so.constants;
public enum OrchestrationRequestFormat {
- DETAIL, STATUSDETAIL
+ DETAIL, STATUSDETAIL, SIMPLE
}
diff --git a/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java b/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java
index 14f2f5e9b7..40acac57aa 100644
--- a/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java
+++ b/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java
@@ -8,6 +8,11 @@ import javax.management.JMX;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
+import org.jboss.logging.MDC;
+import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.logger.ErrorCode;
+import org.onap.so.logger.ScheduledTasksMDCSetup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,16 +32,22 @@ public class ScheduledDnsLookup {
@Autowired
private DbDnsIpAddress dnsIpAddress;
+ @Autowired
+ private ScheduledTasksMDCSetup scheduledMDCSetup;
+
private static Logger logger = LoggerFactory.getLogger(ScheduledDnsLookup.class);
@Scheduled(fixedRate = 15000)
public void performDnsLookup() {
-
+ scheduledMDCSetup.mdcSetup(ONAPComponents.SO, "performDnsLookup");
String dnsUrl = System.getenv(DB_HOST);
try {
if (dnsUrl == null) {
+ scheduledMDCSetup.errorMDCSetup(ErrorCode.DataError, "Database DNS is not provided.");
logger.error("Database DNS is not provided. Please verify the configuration");
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ scheduledMDCSetup.exitAndClearMDC();
return;
}
@@ -46,6 +57,7 @@ public class ScheduledDnsLookup {
/* This is in initial state */
if (currentIpAddress == null) {
dnsIpAddress.setIpAddress(ipAddress);
+ scheduledMDCSetup.exitAndClearMDC();
return;
}
@@ -57,7 +69,7 @@ public class ScheduledDnsLookup {
} catch (UnknownHostException e) {
logger.warn("Database DNS %s is not resolvable to an IP Address", dnsUrl);
}
-
+ scheduledMDCSetup.exitAndClearMDC();
}
private void softEvictConnectionPool() {
diff --git a/common/src/main/java/org/onap/so/logger/ErrorCode.java b/common/src/main/java/org/onap/so/logger/ErrorCode.java
index 7fb9522b7c..a57ed99f2b 100644
--- a/common/src/main/java/org/onap/so/logger/ErrorCode.java
+++ b/common/src/main/java/org/onap/so/logger/ErrorCode.java
@@ -25,7 +25,7 @@ public enum ErrorCode {
AvailabilityError(200),
DataError(300),
SchemaError(400),
- BusinessProcesssError(500),
+ BusinessProcessError(500),
UnknownError(900);
private int value;
diff --git a/common/src/main/java/org/onap/so/logger/ScheduledTasksMDCSetup.java b/common/src/main/java/org/onap/so/logger/ScheduledTasksMDCSetup.java
new file mode 100644
index 0000000000..41c4b4bfae
--- /dev/null
+++ b/common/src/main/java/org/onap/so/logger/ScheduledTasksMDCSetup.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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=========================================================
+ */
+
+package org.onap.so.logger;
+
+import java.util.UUID;
+import org.onap.logging.filter.base.Constants;
+import org.onap.logging.filter.base.MDCSetup;
+import org.onap.logging.filter.base.ONAPComponentsList;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ScheduledTasksMDCSetup extends MDCSetup {
+
+ public void mdcSetup(ONAPComponentsList targetEntity, String serviceName) {
+ try {
+ setEntryTimeStamp();
+ setServerFQDN();
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity.toString());
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, Constants.DefaultValues.UNKNOWN);
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
+ setLogTimestamp();
+ setElapsedTime();
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, getProperty(Constants.Property.PARTNER_NAME));
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup mdcSetup: {}", e.getMessage());
+ }
+ }
+
+ public void errorMDCSetup(ErrorCode errorCode, String errorDescription) {
+ MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(errorCode.getValue()));
+ MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription);
+ }
+
+ public void exitAndClearMDC() {
+ try {
+ setStatusCode();
+ setLogTimestamp();
+ setElapsedTime();
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup clear MDC: {}", e.getMessage());
+ }
+ MDC.clear();
+ }
+
+ public void setStatusCode() {
+ String currentStatusCode = MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
+ if (currentStatusCode == null || !currentStatusCode.equals(ONAPLogConstants.ResponseStatus.ERROR.toString())) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETE.toString());
+ }
+ }
+}
diff --git a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
index d8ce17a277..cf826d6350 100644
--- a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
+++ b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
@@ -21,7 +21,6 @@
package org.onap.so.logging.jaxrs.filter;
import java.io.IOException;
-import java.util.UUID;
import org.onap.logging.filter.spring.SpringClientFilter;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.logger.MdcConstants;
@@ -51,7 +50,7 @@ public class SOSpringClientFilter extends SpringClientFilter implements ClientHt
MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(statusCode));
setResponseDescription(statusCode);
} catch (IOException e) {
- logger.error("Unable to get statusCode from response");
+ logger.error("Unable to get statusCode from response", e);
}
diff --git a/common/src/main/java/org/onap/so/security/WebSecurityConfig.java b/common/src/main/java/org/onap/so/security/WebSecurityConfig.java
index 635784c642..44ac62d14f 100644
--- a/common/src/main/java/org/onap/so/security/WebSecurityConfig.java
+++ b/common/src/main/java/org/onap/so/security/WebSecurityConfig.java
@@ -32,7 +32,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@ConfigurationProperties(prefix = "spring.security")
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfig {
private List<UserCredentials> credentials;
private List<String> roles = new ArrayList<>();
@@ -65,10 +65,4 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
-
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
- }
-
}
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestError.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestError.java
index 121fd4a1a5..33678b336f 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestError.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestError.java
@@ -33,7 +33,12 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang3.builder.ToStringBuilder;
-import com.fasterxml.jackson.annotation.JsonRootName;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+import com.fasterxml.jackson.annotation.JsonTypeName;
/**
@@ -63,7 +68,9 @@ import com.fasterxml.jackson.annotation.JsonRootName;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"policyException", "serviceException"})
@XmlRootElement(name = "requestError")
-@JsonRootName(value = "requestError")
+@JsonTypeName("requestError")
+@JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME)
+@JsonInclude(Include.NON_NULL)
public class RequestError {
protected PolicyException policyException;
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestInfo.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestInfo.java
index 61192c3147..250c5df5ce 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestInfo.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestInfo.java
@@ -55,6 +55,8 @@ public class RequestInfo implements Serializable {
protected boolean suppressRollback;
@JsonProperty("requestorId")
protected String requestorId;
+ @JsonProperty("applicationId")
+ protected String applicationId;
/**
* Gets the value of the callbackUrl property.
@@ -201,12 +203,21 @@ public class RequestInfo implements Serializable {
this.requestorId = requestorId;
}
+ public String getApplicationId() {
+ return applicationId;
+ }
+
+ public void setApplicationId(String applicationId) {
+ this.applicationId = applicationId;
+ }
+
@Override
public String toString() {
return "RequestInfo [billingAccountNumber=" + billingAccountNumber + ", callbackUrl=" + callbackUrl
+ ", correlator=" + correlator + ", orderNumber=" + orderNumber + ", productFamilyId=" + productFamilyId
+ ", orderVersion=" + orderVersion + ", source=" + source + ", instanceName=" + instanceName
- + ", suppressRollback=" + suppressRollback + ", requestorId=" + requestorId + "]";
+ + ", suppressRollback=" + suppressRollback + ", requestorId=" + requestorId + ", applicationId="
+ + applicationId + "]";
}
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/ServiceException.java b/common/src/main/java/org/onap/so/serviceinstancebeans/ServiceException.java
index f2976136e9..cbbc7f61c1 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/ServiceException.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/ServiceException.java
@@ -31,6 +31,8 @@ package org.onap.so.serviceinstancebeans;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonRootName;
@@ -55,6 +57,7 @@ import com.fasterxml.jackson.annotation.JsonRootName;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "serviceException")
@JsonRootName(value = "serviceException")
+@JsonInclude(Include.NON_EMPTY)
public class ServiceException extends ExceptionType {
diff --git a/common/src/main/java/org/onap/so/utils/Components.java b/common/src/main/java/org/onap/so/utils/Components.java
index 0713723264..5af8c5aa56 100644
--- a/common/src/main/java/org/onap/so/utils/Components.java
+++ b/common/src/main/java/org/onap/so/utils/Components.java
@@ -1,7 +1,23 @@
package org.onap.so.utils;
+import java.util.EnumSet;
+import java.util.Set;
+import org.onap.logging.filter.base.ONAPComponents;
import org.onap.logging.filter.base.ONAPComponentsList;
public enum Components implements ONAPComponentsList {
- OPENSTACK, UNKNOWN;
+ OPENSTACK, UNKNOWN, ASDC_CONTROLLER, APIH, SDNC_ADAPTER;
+
+
+ public static Set<Components> getSOInternalComponents() {
+ return EnumSet.of(ASDC_CONTROLLER, APIH, SDNC_ADAPTER);
+ }
+
+ @Override
+ public String toString() {
+ if (getSOInternalComponents().contains(this))
+ return ONAPComponents.SO + "." + this.name();
+ else
+ return this.name();
+ }
}
diff --git a/common/src/main/java/org/onap/so/utils/CryptoUtils.java b/common/src/main/java/org/onap/so/utils/CryptoUtils.java
index 640660e97c..ff69e3e4b1 100644
--- a/common/src/main/java/org/onap/so/utils/CryptoUtils.java
+++ b/common/src/main/java/org/onap/so/utils/CryptoUtils.java
@@ -91,7 +91,7 @@ public final class CryptoUtils {
return CryptoUtils.encrypt(message, CLOUD_KEY);
} catch (GeneralSecurityException e) {
logger.error(LoggingAnchor.THREE, MessageEnum.RA_GENERAL_EXCEPTION.toString(),
- ErrorCode.BusinessProcesssError.getValue(), "Exception in encryptPassword ", e);
+ ErrorCode.BusinessProcessError.getValue(), "Exception in encryptPassword ", e);
return null;
}
}
@@ -101,7 +101,7 @@ public final class CryptoUtils {
return CryptoUtils.decrypt(message, CLOUD_KEY);
} catch (GeneralSecurityException e) {
logger.error(LoggingAnchor.THREE, MessageEnum.RA_GENERAL_EXCEPTION.toString(),
- ErrorCode.BusinessProcesssError.getValue(), "Exception in encryptPassword ", e);
+ ErrorCode.BusinessProcessError.getValue(), "Exception in encryptPassword ", e);
return null;
}
}
diff --git a/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java b/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
index 8006423e75..ca5b5da2da 100644
--- a/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
@@ -85,6 +85,7 @@ public class DMaaPRestClientTest {
throw new RuntimeException(e);
}
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, null);
DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
Map<String, String> map = new HashMap<>();
client.initializeHeaderMap(map);
diff --git a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
index ad22c65248..3323fd8409 100644
--- a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
+++ b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Copyright (C) 2019 Nokia.
+ * ================================================================================
* 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
@@ -23,32 +25,50 @@ package org.onap.so.client.policy;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
+import org.onap.so.client.RestClient;
import org.onap.so.client.defaultproperties.PolicyRestPropertiesImpl;
+import org.onap.so.client.policy.entities.AllowedTreatments;
+import org.onap.so.client.policy.entities.Bbid;
import org.onap.so.client.policy.entities.Config;
import org.onap.so.client.policy.entities.ConfigRequestParameters;
+import org.onap.so.client.policy.entities.DecisionAttributes;
import org.onap.so.client.policy.entities.DictionaryData;
+import org.onap.so.client.policy.entities.DictionaryItemsRequest;
+import org.onap.so.client.policy.entities.DictionaryJson;
import org.onap.so.client.policy.entities.PolicyConfig;
import org.onap.so.client.policy.entities.PolicyDecision;
+import org.onap.so.client.policy.entities.PolicyDecisionRequest;
import org.onap.so.client.policy.entities.PolicyServiceType;
-import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+import org.onap.so.client.policy.entities.Workstep;
public class PolicyClientImplTest {
+ private static final String SERVICE_TYPE = "serviceTest";
+ private static final String VNF_TYPE = "vTypeTest";
+ private static final String BB_ID = "bbTest";
+ private static final String WORK_STEP = "wStepTest";
+ private static final String ERROR_CODE = "errCodeTest";
+
@BeforeClass
public static void setUp() {
System.setProperty("mso.config.path", "src/test/resources");
@@ -67,53 +87,65 @@ public class PolicyClientImplTest {
}
@Test
- @Ignore
- public void getDecisionTest() {
- PolicyClient client = new PolicyClientImpl();
- PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123");
- assertEquals("Decision is correct", decision.getDecision(), "PERMIT");
- assertEquals("Decision details is correct", decision.getDetails(), "Retry");
+ public void getDecision_success() {
+ // given
+ PolicyClientImpl testedObject = Mockito.spy(PolicyClientImpl.class);
+ PolicyRestClient policyRestClientMock = Mockito.mock(PolicyRestClient.class);
+ when(testedObject.getPolicyRestClient(PolicyServiceType.GET_DECISION)).thenReturn(policyRestClientMock);
+ // when
+ testedObject.getDecision(SERVICE_TYPE, VNF_TYPE, BB_ID, WORK_STEP, ERROR_CODE);
+ // then
+ ArgumentCaptor<PolicyDecisionRequest> captor1 = ArgumentCaptor.forClass(PolicyDecisionRequest.class);
+ verify(policyRestClientMock).post(captor1.capture(), eq(PolicyDecision.class));
+ verifyPolicyDecisionRequestArg(captor1.getValue());
}
- @Test
- @Ignore
- public void getAllowedTreatmentsTest() {
- PolicyClient client = new PolicyClientImpl();
- DictionaryData dictClient = client.getAllowedTreatments("BB1", "1");
- final String dictBbidString = dictClient.getBbid().getString();
- final String dictWorkStepString = dictClient.getWorkstep().getString();
- assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1");
- assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1");
+ private void verifyPolicyDecisionRequestArg(PolicyDecisionRequest actual) {
+ assertThat(actual.getEcompcomponentName()).isEqualTo(RestClient.ECOMP_COMPONENT_NAME);
+ DecisionAttributes decisionAttributes = actual.getDecisionAttributes();
+ assertThat(decisionAttributes.getServiceType()).isEqualTo(SERVICE_TYPE);
+ assertThat(decisionAttributes.getvNFType()).isEqualTo(VNF_TYPE);
+ assertThat(decisionAttributes.getBbID()).isEqualTo(BB_ID);
+ assertThat(decisionAttributes.getWorkStep()).isEqualTo(WORK_STEP);
+ assertThat(decisionAttributes.getErrorCode()).isEqualTo(ERROR_CODE);
}
@Test
- public void getDecisionMockTest() {
- String serviceType = "S";
- String vnfType = "V";
- String bbID = "BB1";
- String workStep = "1";
- String errorCode = "123";
-
- PolicyDecision expected = new PolicyDecision();
- expected.setDecision("PERMIT");
- expected.setDetails("Retry");
-
- DecisionAttributes decisionAttributes = new DecisionAttributes();
- decisionAttributes.setServiceType(serviceType);
- decisionAttributes.setVNFType(vnfType);
- decisionAttributes.setBBID(bbID);
- decisionAttributes.setWorkStep(workStep);
- decisionAttributes.setErrorCode(errorCode);
- PolicyClient client = Mockito.spy(PolicyClientImpl.class);
-
- doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode);
-
- PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode);
- assertThat(actual, sameBeanAs(expected));
+ public void getAllowedTreatments_success() {
+ // given
+ PolicyClientImpl testedObject = Mockito.spy(PolicyClientImpl.class);
+ PolicyRestClient policyRestClientMock = Mockito.mock(PolicyRestClient.class);
+ when(testedObject.getPolicyRestClient(PolicyServiceType.GET_DICTIONARY_ITEMS)).thenReturn(policyRestClientMock);
+ when(policyRestClientMock.post(any(DictionaryItemsRequest.class), eq(AllowedTreatments.class)))
+ .thenReturn(createAllowedTreatments());
+ // when
+ DictionaryData dictionaryDataResult = testedObject.getAllowedTreatments(BB_ID, WORK_STEP);
+ // then
+ assertThat(dictionaryDataResult.getBbid().getString()).isEqualTo(BB_ID);
+ assertThat(dictionaryDataResult.getWorkstep().getString()).isEqualTo(WORK_STEP);
+ }
+
+ private AllowedTreatments createAllowedTreatments() {
+ AllowedTreatments allowedTreatments = new AllowedTreatments();
+ DictionaryJson dictionaryJson = new DictionaryJson();
+ dictionaryJson.setDictionaryDatas(createDictionaryDataList());
+ allowedTreatments.setDictionaryJson(dictionaryJson);
+ return allowedTreatments;
+ }
+
+ private List<DictionaryData> createDictionaryDataList() {
+ DictionaryData dictionaryData = new DictionaryData();
+ Bbid bbid = new Bbid();
+ bbid.setString(BB_ID);
+ dictionaryData.setBbid(bbid);
+ Workstep workstep = new Workstep();
+ workstep.setString(WORK_STEP);
+ dictionaryData.setWorkstep(workstep);
+ return Arrays.asList(dictionaryData, new DictionaryData());
}
@Test
- public void getConfigFromStringJsonTest() throws JsonParseException, JsonMappingException, IOException {
+ public void getConfigFromStringJsonTest() throws IOException {
PolicyClientImpl client = new PolicyClientImpl();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
@@ -128,7 +160,7 @@ public class PolicyClientImplTest {
}
@Test
- public void getConfigWithPolicyNameTest() throws JsonParseException, JsonMappingException, IOException {
+ public void getConfigWithPolicyNameTest() throws IOException {
PolicyClientImpl client = Mockito.spy(PolicyClientImpl.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
diff --git a/common/src/test/java/org/onap/so/logger/ScheduledTasksMDCSetupTest.java b/common/src/test/java/org/onap/so/logger/ScheduledTasksMDCSetupTest.java
new file mode 100644
index 0000000000..f232781871
--- /dev/null
+++ b/common/src/test/java/org/onap/so/logger/ScheduledTasksMDCSetupTest.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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=========================================================
+ */
+
+package org.onap.so.logger;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.After;
+import org.junit.Test;
+import org.onap.logging.filter.base.Constants;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.utils.Components;
+import org.onap.so.utils.UUIDChecker;
+import org.slf4j.MDC;
+
+public class ScheduledTasksMDCSetupTest {
+ private ScheduledTasksMDCSetup tasksMDCSetup = new ScheduledTasksMDCSetup();
+
+ @After
+ public void tearDown() {
+ MDC.clear();
+ System.clearProperty("partnerName");
+ }
+
+ @Test
+ public void mdcSetupTest() {
+ System.setProperty("partnerName", Components.APIH.toString());
+ tasksMDCSetup.mdcSetup(Components.APIH, "mdcSetupTest");
+
+ assertTrue(UUIDChecker.isValidUUID(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
+ assertEquals(Components.APIH.toString(), MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY));
+ assertEquals(Components.APIH.toString(), MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
+ assertEquals("mdcSetupTest", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));
+ assertEquals(Constants.DefaultValues.UNKNOWN, MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN));
+ }
+
+ @Test
+ public void errorMDCSetupTest() {
+ tasksMDCSetup.errorMDCSetup(ErrorCode.UnknownError, "Error");
+
+ assertEquals("900", MDC.get(ONAPLogConstants.MDCs.ERROR_CODE));
+ assertEquals("Error", MDC.get(ONAPLogConstants.MDCs.ERROR_DESC));
+ }
+
+ @Test
+ public void setStatusCodeTest() {
+ tasksMDCSetup.setStatusCode();
+
+ assertEquals(ONAPLogConstants.ResponseStatus.COMPLETE.toString(),
+ MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }
+
+ @Test
+ public void setStatusCodeErrorTest() {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ tasksMDCSetup.setStatusCode();
+
+ assertEquals(ONAPLogConstants.ResponseStatus.ERROR.toString(),
+ MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }
+}
diff --git a/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java b/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java
deleted file mode 100644
index b2db986d02..0000000000
--- a/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.onap.so.utils;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.doReturn;
-import org.camunda.bpm.client.ExternalTaskClient;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.springframework.core.env.Environment;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ExternalTaskServiceUtilsTest {
-
- @Spy
- @InjectMocks
- private ExternalTaskServiceUtils utils = new ExternalTaskServiceUtils();
-
- @Mock
- private Environment mockEnv;
-
- @Mock
- private ExternalTaskClient mockClient;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- doReturn("3").when(mockEnv).getProperty("workflow.topics.maxClients", "3");
- doReturn("07a7159d3bf51a0e53be7a8f89699be7").when(mockEnv).getRequiredProperty("mso.msoKey");
- doReturn("6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436").when(mockEnv)
- .getRequiredProperty("mso.auth");
- doReturn("someid").when(mockEnv).getRequiredProperty("mso.config.cadi.aafId");
- doReturn("http://camunda.com").when(mockEnv).getRequiredProperty("mso.workflow.endpoint");
- }
-
- @Test
- public void testCreateExternalTaskClient() throws Exception {
- ExternalTaskClient actualClient = utils.createExternalTaskClient();
- Assert.assertNotNull(actualClient);
- }
-
- @Test
- public void testGetAuth() throws Exception {
- String actual = utils.getAuth();
- String expected = "Att32054Life!@";
- assertEquals(expected, actual);
- }
-
- @Test
- public void testGetMaxClients() throws Exception {
- int actual = utils.getMaxClients();
- int expected = 3;
- assertEquals(expected, actual);
- }
-
-}