diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-07 08:35:37 +0000 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-07 08:38:19 +0000 |
commit | fbb02159b84435cf37221ae8ae5e0045167be15a (patch) | |
tree | 78196f6a3e5e4d0b1e5ca6ecadec0f9e9a623303 /aai-els-onap-logging | |
parent | 58f0fd2f6ef58de52e1f9a73540c1bb895c0d6e6 (diff) |
Reduce the number of problems in aai-common by removing unused imports
- run mvn spotless:apply across aai-commmon to remove unused imports
- run mvn formatter:format across aai-common
Issue-ID: AAI-3583
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I2dfeb395eafa2824ce8369bba3a18db3e1845522
Diffstat (limited to 'aai-els-onap-logging')
74 files changed, 687 insertions, 569 deletions
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilter.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilter.java index c826df3d..cddf953c 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilter.java @@ -20,13 +20,6 @@ package org.onap.aai.aailog.filter; -import org.onap.aai.aailog.logs.ServiceName; -import org.onap.logging.filter.base.AuditLogContainerFilter; -import org.onap.logging.filter.base.Constants; -import org.onap.logging.filter.base.SimpleMap; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.MDC; - import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.ContainerRequestContext; @@ -34,6 +27,13 @@ import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriInfo; +import org.onap.aai.aailog.logs.ServiceName; +import org.onap.logging.filter.base.AuditLogContainerFilter; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.filter.base.SimpleMap; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.MDC; + @PreMatching @Priority(1) public class AaiAuditLogContainerFilter extends AuditLogContainerFilter { @@ -43,7 +43,7 @@ public class AaiAuditLogContainerFilter extends AuditLogContainerFilter { String partnerName = headers.get(ONAPLogConstants.Headers.PARTNER_NAME); if (partnerName == null || partnerName.isEmpty()) { logger.trace("No valid X-ONAP-PartnerName header value. Checking X-FromAppId header for partnerName."); - partnerName = headers.get (Constants.HttpHeaders.HEADER_FROM_APP_ID); + partnerName = headers.get(Constants.HttpHeaders.HEADER_FROM_APP_ID); if (partnerName == null || partnerName.isEmpty()) { logger.trace("No valid X-FromAppId header value. Checking User-Agent header for partnerName."); partnerName = headers.get(HttpHeaders.USER_AGENT); @@ -59,6 +59,7 @@ public class AaiAuditLogContainerFilter extends AuditLogContainerFilter { } MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName); } + @Override protected void setServiceName(ContainerRequestContext containerRequest) { UriInfo uriInfo = containerRequest.getUriInfo(); diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java index 629587d5..348aaa2e 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java @@ -17,11 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.filter; import java.io.IOException; import java.util.List; import java.util.UUID; + import org.onap.aai.aailog.logs.ServiceName; import org.onap.logging.filter.base.AbstractMetricLogFilter; import org.onap.logging.filter.base.Constants; @@ -33,11 +35,11 @@ import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; -public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRequest, ClientHttpResponse, HttpHeaders> implements ClientHttpRequestInterceptor { +public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRequest, ClientHttpResponse, HttpHeaders> + implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) - throws IOException - { + throws IOException { this.setInvocationId(request.getHeaders()); pre(request, request.getHeaders()); ClientHttpResponse resp = execution.execute(request, body); @@ -45,6 +47,7 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe return resp; } + protected void pre(HttpRequest request, HttpHeaders requestHeaders) { try { setupMDC(request); @@ -54,6 +57,7 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe logger.warn("Error in RestClientLoggingInterceptor pre", e); } } + protected void setupHeaders(HttpRequest clientRequest, HttpHeaders requestHeaders) { String requestId = extractRequestID(requestHeaders); addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId); @@ -69,6 +73,7 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe addHeader(requestHeaders, ONAPLogConstants.Headers.PARTNER_NAME, pName); } } + protected String extractRequestID(HttpHeaders requestHeaders) { String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID); if (requestId == null || requestId.isEmpty()) { @@ -80,13 +85,14 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe } return requestId; } + public void setInvocationId(HttpHeaders headers) { String invocationId = null; List<String> headerList = headers.get(ONAPLogConstants.Headers.INVOCATION_ID); if (headerList != null && (!headerList.isEmpty())) { for (String h : headerList) { - if ( h != null && (!h.isEmpty()) ) { + if (h != null && (!h.isEmpty())) { invocationId = h; break; } @@ -98,6 +104,7 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe } MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); } + @Override protected void addHeader(HttpHeaders requestHeaders, String headerName, String headerValue) { requestHeaders.add(headerName, headerValue); @@ -106,18 +113,18 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe protected String getTargetServiceName(HttpRequest request) { return (getServiceName(request)); } - protected String getServiceName(HttpRequest request){ + + protected String getServiceName(HttpRequest request) { String path = request.getURI().getRawPath(); - return(ServiceName.extractServiceName(path)); + return (ServiceName.extractServiceName(path)); } protected int getHttpStatusCode(ClientHttpResponse response) { int result = 0; - if (response != null ) { + if (response != null) { try { result = response.getStatusCode().value(); - } - catch (IOException e) { + } catch (IOException e) { logger.warn("Error in RestClientLoggingInterceptor getHttpStatusCode {}", e.getMessage()); } } @@ -126,11 +133,10 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe protected String getResponseCode(ClientHttpResponse response) { String result = ""; - if (response != null ) { + if (response != null) { try { result = response.getStatusCode().toString(); - } - catch (IOException e) { + } catch (IOException e) { logger.warn("Error in RestClientLoggingInterceptor getResponseCode {}", e.getMessage()); } } @@ -138,7 +144,7 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe } protected String getTargetEntity(HttpRequest request) { - //TODO where do we get this from? + // TODO where do we get this from? return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY; } } diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java index 7e332ec5..c09023d1 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.filter; import com.sun.jersey.api.client.ClientHandler; @@ -24,25 +25,27 @@ import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientRequest; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.filter.ClientFilter; -import org.onap.aai.aailog.logs.ServiceName; -import org.onap.logging.filter.base.Constants; -import org.onap.logging.filter.base.MDCSetup; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.*; -import javax.ws.rs.core.MultivaluedMap; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.UUID; +import javax.ws.rs.core.MultivaluedMap; + +import org.onap.aai.aailog.logs.ServiceName; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.filter.base.MDCSetup; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.*; + public class RestControllerClientLoggingInterceptor extends ClientFilter { private static final Logger logger = LoggerFactory.getLogger(RestControllerClientLoggingInterceptor.class); private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN"); private final MDCSetup mdcSetup; private final String partnerName; - public RestControllerClientLoggingInterceptor () { + public RestControllerClientLoggingInterceptor() { mdcSetup = new MDCSetup(); partnerName = getPartnerName(); } @@ -62,11 +65,11 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { return clientResponse; } - protected String getTargetServiceName(ClientRequest clientRequest) { + protected String getTargetServiceName(ClientRequest clientRequest) { return getServiceName(clientRequest); } - protected String getServiceName(ClientRequest clientRequest) { + protected String getServiceName(ClientRequest clientRequest) { String path = clientRequest.getURI().getRawPath(); return ServiceName.extractServiceName(path); } @@ -75,12 +78,11 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { return response.getStatus(); } - protected String getResponseCode(ClientResponse clientResponse) { + protected String getResponseCode(ClientResponse clientResponse) { return String.valueOf(clientResponse.getStatus()); } - - protected String getTargetEntity(ClientRequest ClientRequest) { + protected String getTargetEntity(ClientRequest ClientRequest) { return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY; }; @@ -94,12 +96,13 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { logger.warn("Error in RestControllerClientLoggingInterceptor pre", e.getMessage()); } } + public void setInvocationId(ClientRequest clientRequest) { String invocationId = null; MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders(); Object id = requestHeaders.get(ONAPLogConstants.Headers.INVOCATION_ID); if (id != null) { - invocationId = (String)id; + invocationId = (String) id; } requestHeaders.remove(ONAPLogConstants.Headers.INVOCATION_ID); if (invocationId == null) { @@ -107,6 +110,7 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { } MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); } + protected void setupHeaders(ClientRequest clientRequest) { String requestId = extractRequestID(clientRequest); MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders(); @@ -118,14 +122,14 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { } addHeader(requestHeaders, Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId); addHeader(requestHeaders, ONAPLogConstants.Headers.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - if (partnerName != null && (!partnerName.isEmpty())){ + if (partnerName != null && (!partnerName.isEmpty())) { addHeader(requestHeaders, ONAPLogConstants.Headers.PARTNER_NAME, partnerName); } } protected void setupMDC(ClientRequest clientRequest) { MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(clientRequest)); MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); mdcSetup.setInvocationIdFromMDC(); @@ -151,15 +155,15 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders(); Object requestIdObj = requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID); if (requestIdObj != null) { - requestId = (String)requestIdObj; + requestId = (String) requestIdObj; } - if ( requestId == null || requestId.isEmpty() ) { + if (requestId == null || requestId.isEmpty()) { requestId = UUID.randomUUID().toString(); } mdcSetup.setLogTimestamp(); mdcSetup.setElapsedTimeInvokeTimestamp(); logger.warn("No value found in MDC when checking key {} value will be set to {}", - ONAPLogConstants.MDCs.REQUEST_ID, requestId); + ONAPLogConstants.MDCs.REQUEST_ID, requestId); MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); } return requestId; @@ -178,6 +182,7 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter { logger.warn("Error in RestControllerClientLoggingInterceptor post", e.getMessage()); } } + protected String getPartnerName() { return mdcSetup.getProperty(Constants.Property.PARTNER_NAME); } diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDBMetricLog.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDBMetricLog.java index 0269943b..da5923d6 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDBMetricLog.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDBMetricLog.java @@ -20,14 +20,14 @@ package org.onap.aai.aailog.logs; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + import org.onap.logging.filter.base.AbstractMetricLogFilter; import org.onap.logging.filter.base.ONAPComponents; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.*; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - public class AaiDBMetricLog extends AbstractMetricLogFilter<DBRequestWrapper, Response, MultivaluedMap<String, Object>> { @@ -35,6 +35,7 @@ public class AaiDBMetricLog private final String partnerName; private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN"); private static final String TARGET_ENTITY = ONAPComponents.AAI.toString() + ".DB"; + public AaiDBMetricLog(String subcomponent) { partnerName = getPartnerName(subcomponent); } @@ -85,6 +86,7 @@ public class AaiDBMetricLog logger.warn("Error in AaiDBMetricLog pre", e); } } + public void post(DBRequestWrapper request, Response response) { try { setLogTimestamp(); @@ -98,13 +100,13 @@ public class AaiDBMetricLog logger.warn("Error in AaiDBMetricLog post", e); } } + @Override public void setResponseStatusCode(int code) { String statusCode; if (code / 100 == 2) { statusCode = ONAPLogConstants.ResponseStatus.COMPLETE.toString(); - } - else { + } else { statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString(); setErrorCode(code); setErrorDesc(code); diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDebugLog.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDebugLog.java index ef11f08e..60d90a9c 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDebugLog.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDebugLog.java @@ -20,12 +20,12 @@ package org.onap.aai.aailog.logs; +import java.util.UUID; + import org.onap.logging.filter.base.MDCSetup; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; -import java.util.UUID; - public class AaiDebugLog extends MDCSetup { public void setupMDC() { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java index 35d206f0..0d3a573d 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java @@ -20,16 +20,15 @@ package org.onap.aai.aailog.logs; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + import org.onap.aai.logging.AaiElsErrorCode; import org.onap.logging.filter.base.MDCSetup; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.*; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.regex.PatternSyntaxException; - public class AaiDmaapMetricLog extends MDCSetup { protected static final Logger logger = LoggerFactory.getLogger(AaiDmaapMetricLog.class); @@ -37,15 +36,16 @@ public class AaiDmaapMetricLog extends MDCSetup { private static final String TARGET_ENTITY = "DMaaP"; public AaiDmaapMetricLog() { - if(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN) == null) { - setServerFQDN(); - } + if (MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN) == null) { + setServerFQDN(); + } } + public void pre(String targetServiceName, String event, String transactionId, String serviceName) { try { MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); setLogTimestamp(); setElapsedTimeInvokeTimestamp(); MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, targetServiceName); @@ -58,7 +58,7 @@ public class AaiDmaapMetricLog extends MDCSetup { MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName); } setInvocationIdFromMDC(); - logger.info(ONAPLogConstants.Markers.INVOKE, event ); + logger.info(ONAPLogConstants.Markers.INVOKE, event); } catch (Exception e) { logger.warn("Error in AaiDmaapMetricLog pre", e.getMessage()); @@ -82,8 +82,7 @@ public class AaiDmaapMetricLog extends MDCSetup { String statusCode; if (AaiElsErrorCode.SUCCESS.equals(aaiElsErrorCode)) { statusCode = ONAPLogConstants.ResponseStatus.COMPLETE.toString(); - } - else { + } else { statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString(); MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, aaiElsErrorCode); MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription); diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiScheduledTaskAuditLog.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiScheduledTaskAuditLog.java index 60460fff..75b602ec 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiScheduledTaskAuditLog.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiScheduledTaskAuditLog.java @@ -18,8 +18,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.logs; +import java.util.UUID; + +import javax.ws.rs.core.Response; + import org.onap.logging.filter.base.MDCSetup; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; @@ -29,9 +34,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import javax.ws.rs.core.Response; -import java.util.UUID; - @Component @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class AaiScheduledTaskAuditLog extends MDCSetup { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/DBRequestWrapper.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/DBRequestWrapper.java index 2b78613d..19a11999 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/DBRequestWrapper.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/DBRequestWrapper.java @@ -17,7 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.logs; + import java.net.URI; public interface DBRequestWrapper { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/ServiceName.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/ServiceName.java index 97f042f0..3f34081b 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/ServiceName.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/ServiceName.java @@ -17,16 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.logs; public class ServiceName { /** * Extract the service name from a URI path * Service name should be the URI path up to two levels down from the version or less + * * @param path the URI path * @return the service name */ - public static String extractServiceName (String path) { + public static String extractServiceName(String path) { StringBuilder sBuilder = new StringBuilder(); String[] parts = path.split("/"); String part = ""; @@ -38,8 +40,8 @@ public class ServiceName { break; } } - if ((sBuilder.length() > 0) && (sBuilder.charAt(sBuilder.length()-1) == '/')) { - sBuilder.deleteCharAt(sBuilder.length()-1); + if ((sBuilder.length() > 0) && (sBuilder.charAt(sBuilder.length() - 1) == '/')) { + sBuilder.deleteCharAt(sBuilder.length() - 1); } String serviceName = sBuilder.toString(); if (serviceName != null && (!serviceName.isEmpty())) { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/Fault.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/Fault.java index fe51ab05..f356275e 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/Fault.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/Fault.java @@ -26,10 +26,11 @@ package org.onap.aai.domain.restPolicyException; -import javax.xml.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.annotation.*; + /** * <p> * Java class for anonymous complex type. diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/ObjectFactory.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/ObjectFactory.java index d7837f9f..613c76d8 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/ObjectFactory.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/ObjectFactory.java @@ -54,8 +54,9 @@ public class ObjectFactory { public ObjectFactory() { } - /**a - * * Create an instance of {@link Fult }. + /** + * a + * * Create an instance of {@link Fult }. * * @return the fault */ diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/PolicyException.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/PolicyException.java index ae6b6da1..16f52ef2 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/PolicyException.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/PolicyException.java @@ -22,12 +22,13 @@ package org.onap.aai.domain.restPolicyException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"messageId", "text", "variables"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RESTResponse.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RESTResponse.java index e1df4512..708a1117 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RESTResponse.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RESTResponse.java @@ -22,10 +22,11 @@ package org.onap.aai.domain.restPolicyException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.HashMap; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"requestError"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RequestError.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RequestError.java index 2b041840..717c1059 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RequestError.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restPolicyException/RequestError.java @@ -22,10 +22,11 @@ package org.onap.aai.domain.restPolicyException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.HashMap; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"policyException"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restResponseInfo/Info.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restResponseInfo/Info.java index f4a4b47f..3685e5aa 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restResponseInfo/Info.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restResponseInfo/Info.java @@ -26,10 +26,11 @@ package org.onap.aai.domain.restResponseInfo; -import javax.xml.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.annotation.*; + /** * <p> * Java class for anonymous complex type. diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/Fault.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/Fault.java index 09558455..36a8cb79 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/Fault.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/Fault.java @@ -26,10 +26,11 @@ package org.onap.aai.domain.restServiceException; -import javax.xml.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.annotation.*; + /** * <p> * Java class for anonymous complex type. diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RESTResponse.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RESTResponse.java index d812c37b..a0687637 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RESTResponse.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RESTResponse.java @@ -22,10 +22,11 @@ package org.onap.aai.domain.restServiceException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.HashMap; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"requestError"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RequestError.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RequestError.java index 79fca83f..cff5f69d 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RequestError.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/RequestError.java @@ -22,10 +22,11 @@ package org.onap.aai.domain.restServiceException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.HashMap; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"serviceException"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/ServiceException.java b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/ServiceException.java index f215bd58..e3339fae 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/ServiceException.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/domain/restServiceException/ServiceException.java @@ -22,12 +22,13 @@ package org.onap.aai.domain.restServiceException; import com.fasterxml.jackson.annotation.*; -import javax.annotation.Generated; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Generated; + @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({"messageId", "text", "variables"}) diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/exceptions/AAIException.java b/aai-els-onap-logging/src/main/java/org/onap/aai/exceptions/AAIException.java index 24228e83..320d5630 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/exceptions/AAIException.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/exceptions/AAIException.java @@ -22,13 +22,13 @@ package org.onap.aai.exceptions; +import java.util.Collection; +import java.util.LinkedList; + import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.logging.ErrorObject; import org.onap.aai.logging.ErrorObjectNotFoundException; -import java.util.Collection; -import java.util.LinkedList; - public class AAIException extends Exception { private static final String UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE = diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/CNName.java b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/CNName.java index 10e4782e..bdf5346d 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/CNName.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/CNName.java @@ -20,16 +20,18 @@ package org.onap.aai.logging; +import static java.util.Base64.getDecoder; + import ch.qos.logback.access.pattern.AccessConverter; import ch.qos.logback.access.spi.IAccessEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.security.cert.X509Certificate; import javax.security.auth.x500.X500Principal; import javax.servlet.http.HttpServletRequest; -import java.security.cert.X509Certificate; -import static java.util.Base64.getDecoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class CNName extends AccessConverter { protected static final Logger LOGGER = LoggerFactory.getLogger(CNName.class); diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorLogHelper.java b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorLogHelper.java index 1bc33f49..1cdee738 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorLogHelper.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorLogHelper.java @@ -69,6 +69,7 @@ public class ErrorLogHelper { /** * Load properties. + * * @throws IOException the exception * @throws ErrorObjectFormatException */ @@ -78,9 +79,10 @@ public class ErrorLogHelper { final Properties properties = new Properties(); try (final FileInputStream fis = new FileInputStream(filePath)) { - LOGGER.info("Found the error.properties in the following location: {}", AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + LOGGER.info("Found the error.properties in the following location: {}", + AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); properties.load(fis); - } catch(Exception ex){ + } catch (Exception ex) { LOGGER.info("Unable to find the error.properties from filesystem so using file in jar"); if (is != null) { properties.load(is); @@ -572,16 +574,16 @@ public class ErrorLogHelper { public static void logException(AAIException e) { final ErrorObject errorObject = e.getErrorObject(); /* - String severityCode = errorObject.getSeverityCode(errorObject.getSeverity()); - - Severify should be left empty per Logging Specification 2019.11 - if (!StringUtils.isEmpty(severityCode)) { - int sevCode = Integer.parseInt(severityCode); - if (sevCode > 0 && sevCode <= 3) { - LoggingContext.severity(sevCode); - } - } - */ + * String severityCode = errorObject.getSeverityCode(errorObject.getSeverity()); + * + * Severify should be left empty per Logging Specification 2019.11 + * if (!StringUtils.isEmpty(severityCode)) { + * int sevCode = Integer.parseInt(severityCode); + * if (sevCode > 0 && sevCode <= 3) { + * LoggingContext.severity(sevCode); + * } + * } + */ String stackTrace = ""; try { stackTrace = LogFormatTools.getStackTop(e); diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorObject.java b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorObject.java index 2e849d25..20068e9e 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorObject.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/ErrorObject.java @@ -75,6 +75,7 @@ public class ErrorObject { /** * Instantiates a new error object. + * * @param severity the severity * @param errorCode the error code * @param errorText the error text @@ -305,6 +306,7 @@ public class ErrorObject { public void setDetails(String details) { this.details = details == null ? "" : details; } + /** * Sets the aai els error code. * @@ -313,6 +315,7 @@ public class ErrorObject { public void setAaiElsErrorCode(String elsErrorCode) { aaiElsErrorCode = elsErrorCode; } + /** * Gets the aai els error code. * @@ -321,6 +324,7 @@ public class ErrorObject { public String getAaiElsErrorCode() { return (aaiElsErrorCode); } + /** * Gets the error code string. This is also the string * configured in Nagios to alert on diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/LoggingContext.java b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/LoggingContext.java index 13f324ec..97288af8 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/logging/LoggingContext.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/logging/LoggingContext.java @@ -20,14 +20,14 @@ package org.onap.aai.logging; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + public class LoggingContext { private static final Logger logger = LoggerFactory.getLogger(LoggingContext.class); @@ -43,7 +43,6 @@ public class LoggingContext { public static final Map<String, String> responseMap = new HashMap(); - // Specific Log Event Fields public static enum LoggingField { START_TIME("startTime"), REQUEST_ID("requestId"), SERVICE_INSTANCE_ID("serviceInstanceId"), SERVER_NAME( diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java index 93969795..a7a87dca 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java @@ -88,7 +88,8 @@ public class AAIApplicationConfig { TRUSTSTORE_PASSWORD = retrieveTruststorePassword(); KEYSTORE_PASSWORD = retrieveKeystorePassword(); } catch (Exception fnfe) { - final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"); + final InputStream is = + Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"); LOGGER.info("Unable to find the application.properties from filesystem so using file in jar"); if (is != null) { try { @@ -108,7 +109,7 @@ public class AAIApplicationConfig { /** * Gets the key value * - * @param key the key + * @param key the key * @param defaultValue the default value * @return the string */ @@ -165,6 +166,7 @@ public class AAIApplicationConfig { public static String getKeystore() throws AAIException { return (get(SERVER_SSL_KEYSTORE_PROP_NAME)); } + /** * Gets the PKCS12 keystore path * @@ -174,6 +176,7 @@ public class AAIApplicationConfig { public static String getKeystorePkcs12() throws AAIException { return (get(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME)); } + /** * Gets the keystore path * @@ -196,12 +199,12 @@ public class AAIApplicationConfig { } try { certPath = replaceProperties(certPath); - } - catch (AAIException e) { + } catch (AAIException e) { return null; } return (retrieveKeystorePasswordWithCertPath(certPath)); } + /** * Retrieve the keystore password * @@ -236,6 +239,7 @@ public class AAIApplicationConfig { } return keystorePassword; } + /** * Get the keystore password * @@ -244,6 +248,7 @@ public class AAIApplicationConfig { public static String getKeystorePassword() { return (KEYSTORE_PASSWORD); } + /** * Gets the truststore password * @@ -258,7 +263,6 @@ public class AAIApplicationConfig { passphrasesFile = new File(certPath + PASSPHRASSES_FILENAME); passphrasesStream = new FileInputStream(passphrasesFile); - Properties passphrasesProps = new Properties(); passphrasesProps.load(passphrasesStream); truststorePassword = passphrasesProps.getProperty(TRUSTSTORE_PASSWORD_PROP_NAME); @@ -281,6 +285,7 @@ public class AAIApplicationConfig { return truststorePassword; } + /** * Gets the truststore password * @@ -293,8 +298,7 @@ public class AAIApplicationConfig { } try { certPath = replaceProperties(certPath); - } - catch (AAIException e) { + } catch (AAIException e) { return null; } return (retrieveTruststorePasswordWithCertPath(certPath)); @@ -352,17 +356,19 @@ public class AAIApplicationConfig { private static String replaceProperties(String originalValue) throws AAIException { final Pattern p = Pattern.compile(PROPERTY_REGEX); Matcher m = p.matcher(originalValue); - /*if (!m.matches()) { - return originalValue; - }*/ + /* + * if (!m.matches()) { + * return originalValue; + * } + */ StringBuffer sb = new StringBuffer(); - while(m.find()) { + while (m.find()) { String text = m.group(1); String replacement = get(text); m.appendReplacement(sb, replacement); } m.appendTail(sb); - return(sb.toString()); + return (sb.toString()); } public static Properties retrieveKeystoreProps() throws AAIException { @@ -374,7 +380,7 @@ public class AAIApplicationConfig { String keystorePassword = System.getProperty(KEYSTORE_PASSWORD_NAME); String certLocation = System.getProperty(SERVER_CERTS_LOCATION_PROP_NAME); - if (truststorePath == null || truststorePath.isEmpty()){ + if (truststorePath == null || truststorePath.isEmpty()) { truststorePath = AAIApplicationConfig.getTruststore(); } if (truststorePath != null) { @@ -383,8 +389,7 @@ public class AAIApplicationConfig { if (truststorePassword == null || truststorePassword.isEmpty()) { if (certLocation != null && (!certLocation.isEmpty())) { truststorePassword = AAIApplicationConfig.retrieveTruststorePasswordWithCertPath(certLocation); - } - else { + } else { truststorePassword = AAIApplicationConfig.getTruststorePassword(); } @@ -392,23 +397,22 @@ public class AAIApplicationConfig { if (truststorePassword != null) { props.setProperty(TRUSTSTORE_PASSWORD_NAME, truststorePassword); } - if (keystorePath == null || keystorePath.isEmpty()){ + if (keystorePath == null || keystorePath.isEmpty()) { keystorePath = AAIApplicationConfig.getKeystorePkcs12(); } if (keystorePath != null) { props.setProperty(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME, keystorePath); } - if (keystorePassword == null || keystorePassword.isEmpty()){ + if (keystorePassword == null || keystorePassword.isEmpty()) { if (certLocation != null && (!certLocation.isEmpty())) { keystorePassword = AAIApplicationConfig.retrieveKeystorePasswordWithCertPath(certLocation); - } - else { + } else { keystorePassword = AAIApplicationConfig.getKeystorePassword(); } } if (keystorePassword != null) { props.setProperty(KEYSTORE_PASSWORD_NAME, keystorePassword); } - return(props); + return (props); } } diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java index 2428f1e9..106640d8 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java @@ -20,15 +20,15 @@ package org.onap.aai.util; -import org.eclipse.jetty.util.security.Password; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.util.Properties; + +import org.eclipse.jetty.util.security.Password; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,7 +90,8 @@ public class AAIConfig { propsInitialized = true; serverProps = newServerProps; } catch (Exception fnfe) { - final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("aaiconfig.properties"); + final InputStream is = + Thread.currentThread().getContextClassLoader().getResourceAsStream("aaiconfig.properties"); LOGGER.info("Unable to find the aaiconfig.properties from filesystem so using file in jar"); if (is != null) { try { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfigProxy.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfigProxy.java index faacc527..e79bfec9 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfigProxy.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfigProxy.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.util; /** @@ -31,11 +32,11 @@ package org.onap.aai.util; // TODO - Find an better name for this interface name public interface AAIConfigProxy { - default String get(String key, String defaultValue){ + default String get(String key, String defaultValue) { return AAIConfig.get(key, defaultValue); } - default int getInt(String key, String defaultValue){ + default int getInt(String key, String defaultValue) { return AAIConfig.getInt(key, defaultValue); } } diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java index 95f9c1b7..1708b8c7 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java @@ -27,7 +27,7 @@ package org.onap.aai.util; * as these keys are generated in a couple places, I made a class to contain that logic */ public class HbaseSaltPrefixer { - // the number of hbase region servers per cluster + // the number of hbase region servers per cluster private static int NUM_REGION_BUCKETS = 3; private static class SingletonHolder { diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/MapperUtil.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/MapperUtil.java index d856999e..9373eb71 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/MapperUtil.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/MapperUtil.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; + import org.onap.aai.exceptions.AAIException; public class MapperUtil { diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java index ce2f4489..222b98c2 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java @@ -21,6 +21,7 @@ package org.onap.logging.filter.base; import javax.servlet.http.HttpServletRequest; + import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java index ab1daab5..dea496a5 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java @@ -24,6 +24,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.UUID; + import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java index 28495c84..7f8017f7 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java @@ -21,6 +21,7 @@ package org.onap.logging.filter.base; import java.util.Enumeration; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.HttpHeaders; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java index a0194850..530d53b3 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java @@ -21,15 +21,14 @@ package org.onap.logging.filter.base; import java.io.IOException; + import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.*; import javax.ws.rs.core.Context; -import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Providers; + import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.slf4j.MDC; @Priority(1) diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogServletFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogServletFilter.java index a8f5eae9..c2d8a96f 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogServletFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/AuditLogServletFilter.java @@ -23,6 +23,7 @@ package org.onap.logging.filter.base; import java.io.IOException; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -31,6 +32,7 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java index 369a9f20..9b2503b7 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java @@ -27,9 +27,11 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.UUID; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; + import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,7 +88,7 @@ public class MDCSetup { return requestId; } if (requestId != null && !requestId.isEmpty()) { - //invalid + // invalid return UUID.randomUUID().toString(); } logger.trace("No valid X-ONAP-RequestID header value. Checking X-RequestID header for requestId."); @@ -95,7 +97,7 @@ public class MDCSetup { return requestId; } if (requestId != null && !requestId.isEmpty()) { - //invalid + // invalid return UUID.randomUUID().toString(); } logger.trace("No valid X-RequestID header value. Checking X-TransactionID header for requestId."); @@ -104,7 +106,7 @@ public class MDCSetup { return requestId; } if (requestId != null && !requestId.isEmpty()) { - //invalid + // invalid return UUID.randomUUID().toString(); } logger.trace("No valid X-TransactionID header value. Checking X-ECOMP-RequestID header for requestId."); @@ -113,11 +115,12 @@ public class MDCSetup { return requestId; } if (requestId != null && !requestId.isEmpty()) { - //invalid + // invalid return UUID.randomUUID().toString(); } return requestId; } + protected boolean isValidUUID(String transId) { try { UUID.fromString(transId); @@ -126,6 +129,7 @@ public class MDCSetup { } return true; } + public void setInvocationId(SimpleMap headers) { String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID); if (invocationId == null || invocationId.isEmpty()) @@ -200,7 +204,7 @@ public class MDCSetup { } public void clearClientMDCs() { - //MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID); + // MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID); MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION); MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE); MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE); @@ -230,7 +234,7 @@ public class MDCSetup { logger.info("System property was null or empty. Checking environment variable for: {}", property); propertyValue = System.getenv(property); if (propertyValue == null || propertyValue.isEmpty()) { - logger.info("Environment variable: {} was null or empty", property ); + logger.info("Environment variable: {} was null or empty", property); } } return propertyValue; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MetricLogClientFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MetricLogClientFilter.java index da4d9827..986d1895 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MetricLogClientFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MetricLogClientFilter.java @@ -25,10 +25,8 @@ import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; -import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Providers; @Priority(0) diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/ONAPComponents.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/ONAPComponents.java index 06fbba9a..5465b7ce 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/ONAPComponents.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/ONAPComponents.java @@ -24,35 +24,7 @@ import java.util.EnumSet; import java.util.Set; public enum ONAPComponents implements ONAPComponentsList { - OPENSTACK_ADAPTER, - BPMN, - GRM, - AAI, - DMAAP, - POLICY, - CATALOG_DB, - REQUEST_DB, - SNIRO, - SDC, - EXTERNAL, - VNF_ADAPTER, - SDNC_ADAPTER, - MULTICLOUD, - CLAMP, - PORTAL, - VID, - APPC, - DCAE, - HOLMES, - SDNC, - SO, - VFC, - ESR, - DBC, - DR, - MR, - OPTF; - + OPENSTACK_ADAPTER, BPMN, GRM, AAI, DMAAP, POLICY, CATALOG_DB, REQUEST_DB, SNIRO, SDC, EXTERNAL, VNF_ADAPTER, SDNC_ADAPTER, MULTICLOUD, CLAMP, PORTAL, VID, APPC, DCAE, HOLMES, SDNC, SO, VFC, ESR, DBC, DR, MR, OPTF; public static Set<ONAPComponents> getSOInternalComponents() { return EnumSet.of(OPENSTACK_ADAPTER, BPMN, CATALOG_DB, REQUEST_DB, VNF_ADAPTER, SDNC_ADAPTER); diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java index 88c95aa4..1908d45f 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; + import javax.ws.rs.WebApplicationException; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; @@ -38,6 +39,7 @@ import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.WriterInterceptor; import javax.ws.rs.ext.WriterInterceptorContext; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java index fa8533a7..cae4ebd6 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java @@ -30,6 +30,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.zip.GZIPInputStream; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java index aafc74d4..4670f500 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogAdapter.java @@ -37,48 +37,56 @@ import org.slf4j.event.Level; * Extensible adapter for cheaply meeting ONAP logging obligations using * an SLF4J facade. * - * <p>This can be used with any SLF4J-compatible logging provider, with - * appropriate provider configuration.</p> + * <p> + * This can be used with any SLF4J-compatible logging provider, with + * appropriate provider configuration. + * </p> * - * <p>The basics are that: + * <p> + * The basics are that: * <ul> - * <li>{@link #entering} sets all MDCs.</li> - * <li>{@link #exiting} unsets all MDCs *and* logs response information.</li> - * <li>{@link #invoke} logs and returns a UUID to passed during invocation, - * and optionally sets these for you on your downstream request by way of - * an adapter.</li> - * <li>Call {@link #getServiceDescriptor()} and its setters to set service-related MDCs.</li> - * <li>Call {@link #getResponseDescriptor()} and its setters to set response-related MDCs.</li> + * <li>{@link #entering} sets all MDCs.</li> + * <li>{@link #exiting} unsets all MDCs *and* logs response information.</li> + * <li>{@link #invoke} logs and returns a UUID to passed during invocation, + * and optionally sets these for you on your downstream request by way of + * an adapter.</li> + * <li>Call {@link #getServiceDescriptor()} and its setters to set service-related MDCs.</li> + * <li>Call {@link #getResponseDescriptor()} and its setters to set response-related MDCs.</li> * </ul> * </p> * - * <p>Minimal usage is: + * <p> + * Minimal usage is: * <ol> - * <li>#entering(RequestAdapter)</li> - * <li>#invoke, #invoke, ...</li> - * <li>#getResponse + setters (or #setResponse)</li> - * <li>#exiting</li> + * <li>#entering(RequestAdapter)</li> + * <li>#invoke, #invoke, ...</li> + * <li>#getResponse + setters (or #setResponse)</li> + * <li>#exiting</li> * </ol> * </p> * - * <p> ... if you're happy for service information to be automatically derived as follows: + * <p> + * ... if you're happy for service information to be automatically derived as follows: * <ul> - * <li><tt>ServiceName</tt> - from <tt>HttpServletRequest#getRequestURI()</tt></li> - * <li><tt>InstanceUUID</tt> - classloader-scope UUID.</li> + * <li><tt>ServiceName</tt> - from <tt>HttpServletRequest#getRequestURI()</tt></li> + * <li><tt>InstanceUUID</tt> - classloader-scope UUID.</li> * </ul> * </p> * - * <p>... and if those defaults don't suit, then you can override using properties on + * <p> + * ... and if those defaults don't suit, then you can override using properties on * {@link #getServiceDescriptor()}, or by injecting your own adapter using * {@link #setServiceDescriptor(ServiceDescriptor)}, or by overriding - * a <tt>protected</tt> methods like{@link #setEnteringMDCs}.</p> + * a <tt>protected</tt> methods like{@link #setEnteringMDCs}. + * </p> * - * <p>For everything else: + * <p> + * For everything else: * <ul> - * <li>The underlying SLF4J {@link Logger} can be retrieved using {@link #unwrap}. - * Use this or create your own using the usual SLF4J factor.</li> - * <li>Set whatever MDCs you like.</li> - * <li>Log whatever else you like.</li> + * <li>The underlying SLF4J {@link Logger} can be retrieved using {@link #unwrap}. + * Use this or create your own using the usual SLF4J factor.</li> + * <li>Set whatever MDCs you like.</li> + * <li>Log whatever else you like.</li> * </ul> * </p> */ @@ -178,8 +186,7 @@ public class ONAPLogAdapter { try { this.mResponseDescriptor.setMDCs(); this.mLogger.info(ONAPLogConstants.Markers.EXIT, EMPTY_MESSAGE); - } - finally { + } finally { MDC.clear(); } return this; @@ -188,8 +195,10 @@ public class ONAPLogAdapter { /** * Report pending invocation with <tt>INVOKE</tt> marker. * - * <p>If you call this variant, then YOU are assuming responsibility for - * setting the requisite ONAP headers.</p> + * <p> + * If you call this variant, then YOU are assuming responsibility for + * setting the requisite ONAP headers. + * </p> * * @param sync whether synchronous. * @return invocation ID to be passed with invocation. @@ -218,8 +227,7 @@ public class ONAPLogAdapter { * @param sync whether synchronous, nullable. * @return invocation ID to be passed with invocation. */ - public UUID invoke(final RequestBuilder builder, - final ONAPLogConstants.InvocationMode sync) { + public UUID invoke(final RequestBuilder builder, final ONAPLogConstants.InvocationMode sync) { // Sync can be defaulted. Builder cannot. @@ -233,8 +241,7 @@ public class ONAPLogAdapter { builder.setHeader(ONAPLogConstants.Headers.REQUEST_ID, defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID))); - builder.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, - defaultToEmpty(invocationID)); + builder.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, defaultToEmpty(invocationID)); builder.setHeader(ONAPLogConstants.Headers.PARTNER_NAME, defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME))); @@ -245,15 +252,16 @@ public class ONAPLogAdapter { * Report vanilla <tt>INVOKE</tt> marker. * * @param builder builder for downstream requests, if you want the - * standard ONAP headers to be added automatically. + * standard ONAP headers to be added automatically. * @return invocation ID to be passed with invocation. */ public UUID invoke(final RequestBuilder builder) { - return this.invoke(builder, (ONAPLogConstants.InvocationMode)null); + return this.invoke(builder, (ONAPLogConstants.InvocationMode) null); } /** * Get descriptor, for overriding service details. + * * @return non-null descriptor. */ public ServiceDescriptor getServiceDescriptor() { @@ -262,6 +270,7 @@ public class ONAPLogAdapter { /** * Override {@link ServiceDescriptor}. + * * @param d non-null override. * @return this. */ @@ -272,6 +281,7 @@ public class ONAPLogAdapter { /** * Get descriptor, for setting response details. + * * @return non-null descriptor. */ public ResponseDescriptor getResponseDescriptor() { @@ -280,6 +290,7 @@ public class ONAPLogAdapter { /** * Override {@link ResponseDescriptor}. + * * @param d non-null override. * @return this. */ @@ -297,9 +308,11 @@ public class ONAPLogAdapter { /** * Set MDCs that persist for the duration of an invocation. * - * <p>It would be better to roll this into {@link #entering}, like + * <p> + * It would be better to roll this into {@link #entering}, like * with {@link #exiting}. Then it would be easier to do, but it - * would mean more work. </p> + * would mean more work. + * </p> * * @param request incoming HTTP request. * @return this. @@ -318,8 +331,7 @@ public class ONAPLogAdapter { // ServiceDescriptor to add them. MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC) - .format(DateTimeFormatter.ISO_INSTANT)); + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestID); MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationID); MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName); @@ -333,8 +345,8 @@ public class ONAPLogAdapter { // Default the service name to the requestURI, in the event that // no value has been provided. - if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null || - MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) { + if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null + || MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) { MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI()); } @@ -390,7 +402,9 @@ public class ONAPLogAdapter { /** * Extensible descriptor for reporting service details. * - * <p>In most cases extension isn't required. </p> + * <p> + * In most cases extension isn't required. + * </p> */ public static class ServiceDescriptor { @@ -402,6 +416,7 @@ public class ONAPLogAdapter { /** * Set name. + * * @param name <tt>ServiceName</tt>. * @return this. */ @@ -412,6 +427,7 @@ public class ONAPLogAdapter { /** * Set name. + * * @param uuid <tt>InstanceUUID</tt>. * @return this. */ @@ -507,11 +523,15 @@ public class ONAPLogAdapter { /** * Adapter for reading information from an incoming HTTP request. * - * <p>Incoming is generally easy, because in most cases you'll be able to - * get your hands on the <tt>HttpServletRequest</tt>.</p> + * <p> + * Incoming is generally easy, because in most cases you'll be able to + * get your hands on the <tt>HttpServletRequest</tt>. + * </p> * - * <p>Perhaps should be generalized to refer to constants instead of - * requiring the implementation of specific methods.</p> + * <p> + * Perhaps should be generalized to refer to constants instead of + * requiring the implementation of specific methods. + * </p> * * @param <T> type, for chaining. */ @@ -519,6 +539,7 @@ public class ONAPLogAdapter { /** * Get header by name. + * * @param name header name. * @return header value, or null. */ @@ -526,18 +547,21 @@ public class ONAPLogAdapter { /** * Get client address. + * * @return address, if available. */ String getClientAddress(); /** * Get server address. + * * @return address, if available. */ String getServerAddress(); /** * Get default service name, from service URI. + * * @return service name default. */ String getRequestURI(); @@ -554,6 +578,7 @@ public class ONAPLogAdapter { /** * Construct adapter for HTTP request. + * * @param request to be wrapped; */ public HttpServletRequestAdapter(final HttpServletRequest request) { @@ -598,8 +623,10 @@ public class ONAPLogAdapter { * vary a lot from caller to caller, since they each get to choose their * own REST (or HTTP, or whatever) client APIs. * - * <p>No default implementation, because there's no HTTP client that's - * sufficiently ubiquitous to warrant incurring a mandatory dependency.</p> + * <p> + * No default implementation, because there's no HTTP client that's + * sufficiently ubiquitous to warrant incurring a mandatory dependency. + * </p> * * @param <T> type, for chaining. */ @@ -607,6 +634,7 @@ public class ONAPLogAdapter { /** * Set HTTP header. + * * @param name header name. * @param value header value. * @return this. diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java index 77ca084d..027a99db 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java @@ -27,7 +27,9 @@ import org.slf4j.MarkerFactory; /** * Constants for standard ONAP headers, MDCs, etc. * - * <p>See <tt>package-info.java</tt>.</p> + * <p> + * See <tt>package-info.java</tt>. + * </p> */ public final class ONAPLogConstants { @@ -57,7 +59,7 @@ public final class ONAPLogConstants { /** Marker reporting invocation. */ public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); - + /** Marker reporting invocation return. */ public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN"); @@ -75,6 +77,7 @@ public final class ONAPLogConstants { /** * Build nested, detached marker. + * * @param m1 top token. * @param m2 sub-token. * @return detached Marker. @@ -114,7 +117,7 @@ public final class ONAPLogConstants { /** MDC recording target service. */ public static final String TARGET_SERVICE_NAME = "TargetServiceName"; - + /** MDC recording target entity. */ public static final String TARGET_ENTITY = "TargetEntity"; @@ -124,7 +127,7 @@ public final class ONAPLogConstants { /** MDC recording current service instance id. */ public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID"; - /** MDC recording current instance id. */ + /** MDC recording current instance id. */ public static final String INSTANCE_UUID = "InstanceID"; // Network. //////////////////////////////////////////////////////////// @@ -148,14 +151,21 @@ public final class ONAPLogConstants { * MDC recording timestamp at the start of the current request, * with the same scope as {@link #REQUEST_ID}. * - * <p>Open issues: + * <p> + * Open issues: + * <ul> * <ul> - * <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul> - * <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul> - * <ul>Whatever mechanism we define, it's going to be costly.</ul> + * Easily confused with {@link #INVOKE_TIMESTAMP}. + * </ul> + * <ul> + * No mechanism for propagation between components, e.g. via HTTP headers. + * </ul> + * <ul> + * Whatever mechanism we define, it's going to be costly. + * </ul> * </ul> * </p> - * */ + */ public static final String ENTRY_TIMESTAMP = "EntryTimestamp"; /** MDC recording timestamp at the start of the current invocation. */ @@ -164,7 +174,7 @@ public final class ONAPLogConstants { /** MDC recording elapsed time. */ public static final String ELAPSED_TIME = "ElapsedTime"; - /** MDC recording log timestamp. */ + /** MDC recording log timestamp. */ public static final String LOG_TIMESTAMP = "LogTimestamp"; // Outcomes. /////////////////////////////////////////////////////////// @@ -182,8 +192,8 @@ public final class ONAPLogConstants { public static final String RESPONSE_STATUS_CODE = "StatusCode"; /** MDC recording error code. */ - public static final String ERROR_CODE = "ErrorCode"; - + public static final String ERROR_CODE = "ErrorCode"; + /** MDC recording error description. */ public static final String ERROR_DESC = "ErrorDesc"; @@ -235,7 +245,7 @@ public final class ONAPLogConstants { /** Not. */ ERROR, - + /** In Progress. */ INPROGRESS } diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java index d9a62472..561cc94b 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/ref/slf4j/package-info.java @@ -9,7 +9,7 @@ * 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 + * 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, @@ -22,11 +22,12 @@ package org.onap.logging.ref.slf4j; /** - * <p>Code in here has potential application outside this reference + * <p> + * Code in here has potential application outside this reference * example, and accordingly: * <ul> - * <li>Packaged in <tt>common</tt>.</li> - * <li>Has minimal dependencies.</li> + * <li>Packaged in <tt>common</tt>.</li> + * <li>Has minimal dependencies.</li> * </ul> * </p> - */
\ No newline at end of file + */ diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilterTest.java index 5f23e668..246586d0 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/AaiAuditLogContainerFilterTest.java @@ -17,8 +17,20 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.filter; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import java.net.URI; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,16 +42,6 @@ import org.onap.logging.filter.base.Constants; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.UriInfo; -import java.net.URI; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class AaiAuditLogContainerFilterTest { @Mock @@ -59,6 +61,7 @@ public class AaiAuditLogContainerFilterTest { public void tearDown() { MDC.clear(); } + @Test public void partnerAndServiceNameValueTest() throws java.net.URISyntaxException { @@ -69,8 +72,7 @@ public class AaiAuditLogContainerFilterTest { URI uri = null; try { uri = new URI("https://localhost:9999/onap/aai/network/logical-link"); - } - catch (java.net.URISyntaxException e) { + } catch (java.net.URISyntaxException e) { throw e; } when(uriInfo.getAbsolutePath()).thenReturn(uri); @@ -82,4 +84,3 @@ public class AaiAuditLogContainerFilterTest { } } - diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptorTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptorTest.java index 601a13be..f8d23f39 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptorTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptorTest.java @@ -17,8 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.filter; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; + +import java.net.InetAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,75 +42,66 @@ import org.slf4j.MDC; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; -import java.net.InetAddress; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.doReturn; - @RunWith(MockitoJUnitRunner.class) public class RestClientLoggingInterceptorTest { - @Mock - private HttpRequest httpRequest; + @Mock + private HttpRequest httpRequest; - @Spy - @InjectMocks - private RestClientLoggingInterceptor restClientLoggingInterceptor; + @Spy + @InjectMocks + private RestClientLoggingInterceptor restClientLoggingInterceptor; - @After - public void tearDown() { - MDC.clear(); - } + @After + public void tearDown() { + MDC.clear(); + } - @Test - public void setupHeadersTest() { - String transId="37b3ab2a-e57e-4fe8-8d8f-eee3019efce6"; - HttpHeaders headers = new HttpHeaders(); - headers.add(Constants.HttpHeaders.TRANSACTION_ID, transId); - restClientLoggingInterceptor.setupHeaders(httpRequest, headers); + @Test + public void setupHeadersTest() { + String transId = "37b3ab2a-e57e-4fe8-8d8f-eee3019efce6"; + HttpHeaders headers = new HttpHeaders(); + headers.add(Constants.HttpHeaders.TRANSACTION_ID, transId); + restClientLoggingInterceptor.setupHeaders(httpRequest, headers); - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID)); - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID)); - assertEquals(transId, headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID)); - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID)); - } + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID)); + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID)); + assertEquals(transId, headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID)); + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID)); + } - @Test - public void getServiceNameTest() throws URISyntaxException { - URI uri = null; - try { - uri = new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"); - } catch (URISyntaxException e) { - throw e; - } - doReturn(uri).when(httpRequest).getURI(); - String serviceName = restClientLoggingInterceptor.getServiceName(httpRequest); - - assertEquals("/aai/v1/cloud-infrastructure/complexes", serviceName); + @Test + public void getServiceNameTest() throws URISyntaxException { + URI uri = null; + try { + uri = new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"); + } catch (URISyntaxException e) { + throw e; } + doReturn(uri).when(httpRequest).getURI(); + String serviceName = restClientLoggingInterceptor.getServiceName(httpRequest); + + assertEquals("/aai/v1/cloud-infrastructure/complexes", serviceName); + } - @Test - public void setupMDCTest() throws URISyntaxException { - URI uri = new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"); - doReturn(uri).when(httpRequest).getURI(); - HttpHeaders headers = new HttpHeaders(); - restClientLoggingInterceptor.pre(httpRequest, headers); - assertEquals("/aai/v1/cloud-infrastructure/complexes", MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME) ); - assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - String serverFQDN = ""; - InetAddress addr = null; - try { - addr = InetAddress.getLocalHost(); - serverFQDN = addr.getCanonicalHostName(); + @Test + public void setupMDCTest() throws URISyntaxException { + URI uri = new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"); + doReturn(uri).when(httpRequest).getURI(); + HttpHeaders headers = new HttpHeaders(); + restClientLoggingInterceptor.pre(httpRequest, headers); + assertEquals("/aai/v1/cloud-infrastructure/complexes", MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + String serverFQDN = ""; + InetAddress addr = null; + try { + addr = InetAddress.getLocalHost(); + serverFQDN = addr.getCanonicalHostName(); - } catch (UnknownHostException e) { - serverFQDN = ""; - } - assertEquals(serverFQDN, MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); - assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)); + } catch (UnknownHostException e) { + serverFQDN = ""; } + assertEquals(serverFQDN, MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)); + } } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java index 48cb3efc..9c4b2655 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java @@ -17,91 +17,91 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.aailog.filter; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import com.sun.jersey.api.client.ClientRequest; + +import java.net.InetAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; + +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; + import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.logging.filter.base.Constants; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; -import java.net.InetAddress; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.doReturn; - @RunWith(MockitoJUnitRunner.class) public class RestControllerClientLoggingInterceptorTest { - private ClientRequest clientRequest; + private ClientRequest clientRequest; - @Spy - @InjectMocks - private RestControllerClientLoggingInterceptor restControllerClientLoggingInterceptor; + @Spy + @InjectMocks + private RestControllerClientLoggingInterceptor restControllerClientLoggingInterceptor; - @Before - public void init() throws URISyntaxException { - System.setProperty("javax.ws.rs.ext.RuntimeDelegate", "com.sun.ws.rs.ext.RuntimeDelegateImpl"); - clientRequest = ClientRequest.create().build(new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"), - "GET"); - } + @Before + public void init() throws URISyntaxException { + System.setProperty("javax.ws.rs.ext.RuntimeDelegate", "com.sun.ws.rs.ext.RuntimeDelegateImpl"); + clientRequest = ClientRequest.create().build( + new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"), "GET"); + } - @After - public void tearDown() { - MDC.clear(); - } + @After + public void tearDown() { + MDC.clear(); + } - @Test - public void setupHeadersTest() throws java.net.URISyntaxException { - - String transId="37b3ab2a-e57e-4fe8-8d8f-eee3019efce6"; - MultivaluedMap<String, Object> requestHeaders = new MultivaluedHashMap<String, Object>(); - requestHeaders.add(Constants.HttpHeaders.TRANSACTION_ID, transId); - clientRequest.getHeaders().putAll(requestHeaders); - restControllerClientLoggingInterceptor.pre(clientRequest); - MultivaluedMap<String, Object> headers = clientRequest.getHeaders(); - - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID)); - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID)); - assertEquals(transId, headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID)); - assertEquals(transId, headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID)); - assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)); - } + @Test + public void setupHeadersTest() throws java.net.URISyntaxException { - @Test - public void getServiceNameTest() { - String serviceName = restControllerClientLoggingInterceptor.getServiceName(clientRequest); - assertEquals("/aai/v1/cloud-infrastructure/complexes", serviceName); - } + String transId = "37b3ab2a-e57e-4fe8-8d8f-eee3019efce6"; + MultivaluedMap<String, Object> requestHeaders = new MultivaluedHashMap<String, Object>(); + requestHeaders.add(Constants.HttpHeaders.TRANSACTION_ID, transId); + clientRequest.getHeaders().putAll(requestHeaders); + restControllerClientLoggingInterceptor.pre(clientRequest); + MultivaluedMap<String, Object> headers = clientRequest.getHeaders(); + + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID)); + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID)); + assertEquals(transId, headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID)); + assertEquals(transId, headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID)); + assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID)); + } + + @Test + public void getServiceNameTest() { + String serviceName = restControllerClientLoggingInterceptor.getServiceName(clientRequest); + assertEquals("/aai/v1/cloud-infrastructure/complexes", serviceName); + } + + @Test + public void setupMDCTest() throws URISyntaxException { + restControllerClientLoggingInterceptor.pre(clientRequest); + assertEquals("/aai/v1/cloud-infrastructure/complexes", MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + String serverFQDN = ""; + InetAddress addr = null; + try { + addr = InetAddress.getLocalHost(); + serverFQDN = addr.getCanonicalHostName(); - @Test - public void setupMDCTest() throws URISyntaxException { - restControllerClientLoggingInterceptor.pre(clientRequest); - assertEquals("/aai/v1/cloud-infrastructure/complexes", MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME) ); - assertEquals("INPROGRESS", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - String serverFQDN = ""; - InetAddress addr = null; - try { - addr = InetAddress.getLocalHost(); - serverFQDN = addr.getCanonicalHostName(); - - } catch (UnknownHostException e) { - serverFQDN = ""; - } - assertEquals(serverFQDN, MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + } catch (UnknownHostException e) { + serverFQDN = ""; } + assertEquals(serverFQDN, MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + } } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/InfoTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/InfoTest.java index 1d19e5bf..6e1b0ea4 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/InfoTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/InfoTest.java @@ -26,11 +26,11 @@ package org.onap.aai.domain.restResponseInfo; -import org.junit.Test; +import static org.junit.Assert.assertTrue; import java.util.List; -import static org.junit.Assert.assertTrue; +import org.junit.Test; public class InfoTest { private Info info = new Info(); @@ -38,7 +38,8 @@ public class InfoTest { @Test public void infoTest() { Info.ResponseMessages responseMessages = info.getResponseMessages(); - if (responseMessages == null) responseMessages = new Info.ResponseMessages(); + if (responseMessages == null) + responseMessages = new Info.ResponseMessages(); List<Info.ResponseMessages.ResponseMessage> list = responseMessages.getResponseMessage(); Info.ResponseMessages.ResponseMessage respMsg = new Info.ResponseMessages.ResponseMessage(); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/ObjectFactoryTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/ObjectFactoryTest.java index 55205794..fe95d183 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/ObjectFactoryTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/domain/restResponseInfo/ObjectFactoryTest.java @@ -26,17 +26,19 @@ package org.onap.aai.domain.restResponseInfo; -import org.junit.Test; - import static org.junit.Assert.assertNotNull; +import org.junit.Test; + public class ObjectFactoryTest { private ObjectFactory objectFactory = new ObjectFactory(); @Test public void objectFactoryTest() { - Info.ResponseMessages.ResponseMessage.Variables variables = objectFactory.createInfoResponseMessagesResponseMessageVariables(); - Info.ResponseMessages.ResponseMessage responseMessage = objectFactory.createInfoResponseMessagesResponseMessage(); + Info.ResponseMessages.ResponseMessage.Variables variables = + objectFactory.createInfoResponseMessagesResponseMessageVariables(); + Info.ResponseMessages.ResponseMessage responseMessage = + objectFactory.createInfoResponseMessagesResponseMessage(); Info.ResponseMessages responseMessages = objectFactory.createInfoResponseMessages(); Info info = objectFactory.createInfo(); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java index 4f08607f..b489a0ab 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java @@ -17,25 +17,26 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.exceptions; -import org.junit.Test; -import org.onap.aai.logging.AaiElsErrorCode; -import org.onap.aai.logging.ErrorObject; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -import javax.ws.rs.core.Response; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import javax.ws.rs.core.Response; +import org.junit.Test; +import org.onap.aai.logging.AaiElsErrorCode; +import org.onap.aai.logging.ErrorObject; public class AAIExceptionTest { private AAIException aaiException; @Test public void defaultAAIExceptionTest() { - //AAI_4000=5:4:ERROR:4000:500:3002:Internal Error:900 + // AAI_4000=5:4:ERROR:4000:500:3002:Internal Error:900 aaiException = new AAIException(); assertEquals(AAIException.DEFAULT_EXCEPTION_CODE, aaiException.getCode()); @@ -53,7 +54,8 @@ public class AAIExceptionTest { @Test public void aaiExceptionTest() { - //5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry:500 + // 5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and + // retry:500 aaiException = new AAIException("AAI_3303"); assertEquals("AAI_3303", aaiException.getCode()); @@ -65,13 +67,15 @@ public class AAIExceptionTest { assertEquals(errorObject.getRESTErrorCode(), "3300"); assertEquals(errorObject.getErrorCode(), "3303"); assertEquals(errorObject.getAaiElsErrorCode(), AaiElsErrorCode.BUSINESS_PROCESS_ERROR); - assertEquals(errorObject.getErrorText(), "Too many objects would be returned by this request, please refine your request and retry"); + assertEquals(errorObject.getErrorText(), + "Too many objects would be returned by this request, please refine your request and retry"); assertNotNull(aaiException.getTemplateVars()); } @Test public void aaiExceptionTestWithDetails() { - //5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry:500 + // 5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and + // retry:500 final String testDetails = "Test details"; aaiException = new AAIException("AAI_3303", testDetails); assertEquals(testDetails, aaiException.getMessage()); @@ -98,4 +102,3 @@ public class AAIExceptionTest { assertNotNull(aaiException.getTemplateVars()); } } - diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java index dbfe60d5..84284ec5 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java @@ -17,15 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.exceptions; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.util.HashMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.Test; public class AAIExceptionWithInfoTest { @@ -36,7 +37,7 @@ public class AAIExceptionWithInfoTest { @Test public void aaiExceptionWithInfoTest() { - aaiException = new AAIExceptionWithInfo(new HashMap<String, Object>(), testInfo ); + aaiException = new AAIExceptionWithInfo(new HashMap<String, Object>(), testInfo); assertEquals(testInfo, aaiException.getInfo()); assertNotNull(aaiException.getInfoHash()); @@ -44,7 +45,7 @@ public class AAIExceptionWithInfoTest { @Test public void aaiExceptionWithCodeInfoTest() { - aaiException = new AAIExceptionWithInfo("AAI_3300", new HashMap<String, Object>(), testInfo ); + aaiException = new AAIExceptionWithInfo("AAI_3300", new HashMap<String, Object>(), testInfo); assertEquals(testInfo, aaiException.getInfo()); assertEquals("AAI_3300", aaiException.getCode()); @@ -54,7 +55,7 @@ public class AAIExceptionWithInfoTest { @Test public void aaiExceptionWithCodeDetailsInfoTest() { - aaiException = new AAIExceptionWithInfo("AAI_3300", testDetails, new HashMap<String, Object>(), testInfo ); + aaiException = new AAIExceptionWithInfo("AAI_3300", testDetails, new HashMap<String, Object>(), testInfo); assertEquals(testInfo, aaiException.getInfo()); assertEquals("AAI_3300", aaiException.getCode()); @@ -65,7 +66,8 @@ public class AAIExceptionWithInfoTest { @Test public void aaiExceptionWithCodeThrowableDetailsInfoTest() { - aaiException = new AAIExceptionWithInfo("AAI_3300", new IOException("File not found"), testDetails, new HashMap<String, Object>(), testInfo ); + aaiException = new AAIExceptionWithInfo("AAI_3300", new IOException("File not found"), testDetails, + new HashMap<String, Object>(), testInfo); assertEquals(testInfo, aaiException.getInfo()); assertEquals("AAI_3300", aaiException.getCode()); @@ -76,4 +78,3 @@ public class AAIExceptionWithInfoTest { } } - diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CNNameTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CNNameTest.java index 01b7bda1..d95aefa0 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CNNameTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CNNameTest.java @@ -20,7 +20,15 @@ package org.onap.aai.logging; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + import ch.qos.logback.access.spi.IAccessEvent; + +import java.security.cert.X509Certificate; + +import javax.security.auth.x500.X500Principal; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,12 +38,6 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; -import javax.security.auth.x500.X500Principal; -import java.security.cert.X509Certificate; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class CNNameTest { @Mock @@ -52,8 +54,9 @@ public class CNNameTest { public void setup() { when(cnName.isStarted()).thenReturn(true); } + @Test - public void basicAuthTest(){ + public void basicAuthTest() { MockHttpServletRequest https = new MockHttpServletRequest(); https.addHeader("Authorization", "Basic dXNlcjpwYXNzd29yZA=="); @@ -64,8 +67,9 @@ public class CNNameTest { assertEquals("user", cnName.convert(accessEvent)); } + @Test - public void incorrectHeaderBasicAuthTest(){ + public void incorrectHeaderBasicAuthTest() { MockHttpServletRequest https = new MockHttpServletRequest(); @@ -77,8 +81,9 @@ public class CNNameTest { assertEquals("-", cnName.convert(accessEvent)); } + @Test - public void noCipherSuiteTest(){ + public void noCipherSuiteTest() { MockHttpServletRequest https = new MockHttpServletRequest(); @@ -90,17 +95,18 @@ public class CNNameTest { assertEquals("-", cnName.convert(accessEvent)); } + @Test - public void certificateTest(){ + public void certificateTest() { String testSubject = "CN=TestName, OU=TestOU, O=TestOrg, C=Country"; - X509Certificate[] certChain = { cert }; + X509Certificate[] certChain = {cert}; MockHttpServletRequest https = new MockHttpServletRequest(); https.setAttribute("javax.servlet.request.cipher_suite", ""); - https.setAttribute("javax.servlet.request.X509Certificate", certChain ); + https.setAttribute("javax.servlet.request.X509Certificate", certChain); when(accessEvent.getRequest()).thenReturn(https); - when(cert.getSubjectX500Principal()).thenReturn(new X500Principal(testSubject) ); + when(cert.getSubjectX500Principal()).thenReturn(new X500Principal(testSubject)); assertEquals(testSubject, cnName.convert(accessEvent)); } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java index 71a07aa1..28be0bf0 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java @@ -20,16 +20,16 @@ package org.onap.aai.logging; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class CustomLogPatternLayoutTest { private CustomLogPatternLayout customLogPatternLayout = new CustomLogPatternLayout(); @Test - public void defaultConverterTest(){ + public void defaultConverterTest() { assertEquals(customLogPatternLayout.getDefaultConverterMap().get("z"), CNName.class.getName()); assertEquals(customLogPatternLayout.getDefaultConverterMap().get("y"), DME2RestFlag.class.getName()); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java index 737cb624..c29e29d6 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java @@ -20,7 +20,11 @@ package org.onap.aai.logging; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + import ch.qos.logback.access.spi.IAccessEvent; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,9 +33,6 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class DME2RestFlagTest { @@ -46,8 +47,9 @@ public class DME2RestFlagTest { public void setup() { when(dme2RestFlag.isStarted()).thenReturn(true); } + @Test - public void dme2Test(){ + public void dme2Test() { String[] contextArray = {"a", "b", "c"}; String[] routeOfferArray = {"d", "e", "f"}; String[] versionArray = {"1", "2", "3"}; @@ -56,8 +58,9 @@ public class DME2RestFlagTest { when(accessEvent.getRequestParameter("version")).thenReturn(versionArray); assertEquals("DME2", dme2RestFlag.convert(accessEvent)); } + @Test - public void restTest(){ + public void restTest() { String[] contextArray = {""}; String[] routeOfferArray = {""}; String[] versionArray = {""}; diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorLogHelperTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorLogHelperTest.java index ae174691..99522771 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorLogHelperTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorLogHelperTest.java @@ -20,6 +20,16 @@ package org.onap.aai.logging; +import static java.lang.Thread.sleep; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.core.MediaType; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,15 +42,6 @@ import org.onap.aai.util.LogFile; import org.onap.aai.util.MapperUtil; import org.slf4j.MDC; -import javax.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static java.lang.Thread.sleep; -import static org.junit.Assert.*; - public class ErrorLogHelperTest { private static final String ErrorLogFileName = "error.log"; @@ -50,14 +51,16 @@ public class ErrorLogHelperTest { System.setProperty("AJSC_HOME", "."); } + @After - public void cleanup() throws IOException{ + public void cleanup() throws IOException { MDC.clear(); LogFile.deleteContents(ErrorLogFileName); } + @Test public void logErrorTest() throws IOException, InterruptedException { - //||main|UNKNOWN||||ERROR|500|Node cannot be deleted:3100:Bad Request:|ERR.5.4.6110 + // ||main|UNKNOWN||||ERROR|500|Node cannot be deleted:3100:Bad Request:|ERR.5.4.6110 ErrorLogHelper.logError("AAI_6110"); sleep(5000); String logContents = LogFile.getContents(ErrorLogFileName); @@ -66,15 +69,15 @@ public class ErrorLogHelperTest { String logContentParts[] = logContents.split("\\|"); - assertTrue(logContentParts.length >= 11 ); - assertEquals ("ERROR", logContentParts[7]); - assertEquals (AaiElsErrorCode.BUSINESS_PROCESS_ERROR, logContentParts[8]); - assertTrue (logContentParts[10].startsWith("ERR.5.4.6110")); + assertTrue(logContentParts.length >= 11); + assertEquals("ERROR", logContentParts[7]); + assertEquals(AaiElsErrorCode.BUSINESS_PROCESS_ERROR, logContentParts[8]); + assertTrue(logContentParts[10].startsWith("ERR.5.4.6110")); } @Test public void logErrorWithMessageTest() throws IOException, InterruptedException { - //||main|UNKNOWN||||ERROR|500|Node cannot be deleted:3100:Bad Request:|ERR.5.4.6110 message + // ||main|UNKNOWN||||ERROR|500|Node cannot be deleted:3100:Bad Request:|ERR.5.4.6110 message String errorMessage = "Object is referenced by additional objects"; ErrorLogHelper.logError("AAI_6110", errorMessage); sleep(5000); @@ -84,14 +87,14 @@ public class ErrorLogHelperTest { String logContentParts[] = logContents.split("\\|"); - assertTrue(logContentParts.length >= 11 ); - assertTrue (logContentParts[9].contains(errorMessage)); - assertTrue (logContentParts[10].startsWith("ERR.5.4.6110")); + assertTrue(logContentParts.length >= 11); + assertTrue(logContentParts[9].contains(errorMessage)); + assertTrue(logContentParts[10].startsWith("ERR.5.4.6110")); } @Test - public void getRESTAPIPolicyErrorResponseTest() throws AAIException{ - //AAI_3002=5:1:WARN:3002:400:3002:Error writing output performing %1 on %2:300 + public void getRESTAPIPolicyErrorResponseTest() throws AAIException { + // AAI_3002=5:1:WARN:3002:400:3002:Error writing output performing %1 on %2:300 ArrayList<MediaType> headers = new ArrayList<MediaType>(Arrays.asList(MediaType.APPLICATION_JSON_TYPE)); ArrayList<String> args = new ArrayList<String>(Arrays.asList("PUT", "resource")); @@ -110,9 +113,10 @@ public class ErrorLogHelperTest { assertTrue(vars.contains("PUT")); assertTrue(vars.contains("resource")); } + @Test - public void getRESTAPIServiceErrorResponseTest() throws AAIException{ - //AAI_3009=5:6:WARN:3009:400:3009:Malformed URL:300 + public void getRESTAPIServiceErrorResponseTest() throws AAIException { + // AAI_3009=5:6:WARN:3009:400:3009:Malformed URL:300 ArrayList<MediaType> headers = new ArrayList<MediaType>(Arrays.asList(MediaType.APPLICATION_JSON_TYPE)); ArrayList<String> args = new ArrayList<String>(); @@ -120,7 +124,8 @@ public class ErrorLogHelperTest { String errorResponse = ErrorLogHelper.getRESTAPIErrorResponse(headers, aaie, args); assertNotNull(errorResponse); - org.onap.aai.domain.restServiceException.RESTResponse resp = MapperUtil.readAsObjectOf(org.onap.aai.domain.restServiceException.RESTResponse.class, errorResponse); + org.onap.aai.domain.restServiceException.RESTResponse resp = + MapperUtil.readAsObjectOf(org.onap.aai.domain.restServiceException.RESTResponse.class, errorResponse); org.onap.aai.domain.restServiceException.RequestError requestError = resp.getRequestError(); assertNotNull(requestError); ServiceException serviceException = requestError.getServiceException(); @@ -128,9 +133,10 @@ public class ErrorLogHelperTest { assertEquals("SVC3009", serviceException.getMessageId()); } + @Test - public void getRESTAPIServiceErrorResponseWithLoggingTest() throws IOException, InterruptedException{ - //AAI_3009=5:6:WARN:3009:400:3009:Malformed URL:300 + public void getRESTAPIServiceErrorResponseWithLoggingTest() throws IOException, InterruptedException { + // AAI_3009=5:6:WARN:3009:400:3009:Malformed URL:300 ArrayList<MediaType> headers = new ArrayList<MediaType>(Arrays.asList(MediaType.APPLICATION_JSON_TYPE)); ArrayList<String> args = new ArrayList<String>(); @@ -143,8 +149,8 @@ public class ErrorLogHelperTest { assertNotNull(logContents); String logContentParts[] = logContents.split("\\|"); - assertTrue(logContentParts.length >= 11 ); - assertTrue (logContentParts[10].startsWith("ERR.5.6.3009")); + assertTrue(logContentParts.length >= 11); + assertTrue(logContentParts[10].startsWith("ERR.5.6.3009")); } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectFormatExceptionTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectFormatExceptionTest.java index a5a8e496..97934723 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectFormatExceptionTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectFormatExceptionTest.java @@ -20,10 +20,10 @@ package org.onap.aai.logging; -import org.junit.Test; - import static org.junit.Assert.assertTrue; +import org.junit.Test; + public class ErrorObjectFormatExceptionTest { @Test diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectNotFoundExceptionTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectNotFoundExceptionTest.java index 8bffe4ff..6be89425 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectNotFoundExceptionTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectNotFoundExceptionTest.java @@ -20,11 +20,11 @@ package org.onap.aai.logging; -import org.junit.Test; +import static org.junit.Assert.*; import java.io.IOException; -import static org.junit.Assert.*; +import org.junit.Test; public class ErrorObjectNotFoundExceptionTest { @@ -33,18 +33,21 @@ public class ErrorObjectNotFoundExceptionTest { ErrorObjectNotFoundException e = new ErrorObjectNotFoundException(); assertTrue(e instanceof Exception); } + @Test public void errorObjectNotFoundExceptionWithMessageTest() { ErrorObjectNotFoundException e = new ErrorObjectNotFoundException("Error Message"); assertTrue(e instanceof Exception); assertEquals("Error Message", e.getMessage()); } + @Test public void errorObjectNotFoundExceptionWithCauseTest() { ErrorObjectNotFoundException e = new ErrorObjectNotFoundException(new ArithmeticException()); assertTrue(e instanceof Exception); assertTrue(e.getCause() instanceof ArithmeticException); } + @Test public void errorObjectNotFoundExceptionWithMsgCauseTest() { ErrorObjectNotFoundException e = new ErrorObjectNotFoundException("Error Message", new ArithmeticException()); @@ -52,10 +55,12 @@ public class ErrorObjectNotFoundExceptionTest { assertTrue(e.getCause() instanceof ArithmeticException); assertEquals("Error Message", e.getMessage()); } + @Test public void errorObjectNotFoundExceptionTest() { - ErrorObjectNotFoundException e = new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, true); + ErrorObjectNotFoundException e = + new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, true); assertTrue(e instanceof Exception); assertTrue(e.getCause() instanceof ArithmeticException); assertEquals("Error Message", e.getMessage()); @@ -63,7 +68,8 @@ public class ErrorObjectNotFoundExceptionTest { assertTrue((e.getSuppressed())[0] instanceof IOException); assertEquals("Test IO Exception", (e.getSuppressed())[0].getMessage()); - ErrorObjectNotFoundException e1 = new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), false, true); + ErrorObjectNotFoundException e1 = + new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), false, true); e1.addSuppressed(new IOException("Test IO Exception")); assertTrue((e1.getSuppressed() == null) || e1.getSuppressed().length == 0); @@ -72,29 +78,31 @@ public class ErrorObjectNotFoundExceptionTest { @Test public void errorObjectNotFoundExceptionStackTraceTest() { - ErrorObjectNotFoundException e1 = new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, true); + ErrorObjectNotFoundException e1 = + new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, true); try { throw e1; - } - catch (ErrorObjectNotFoundException e) { + } catch (ErrorObjectNotFoundException e) { StackTraceElement[] stackTrace = e.getStackTrace(); assertNotNull(stackTrace); assertTrue(stackTrace.length > 0); } - ErrorObjectNotFoundException e2 = new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, false); + ErrorObjectNotFoundException e2 = + new ErrorObjectNotFoundException("Error Message", new ArithmeticException(), true, false); try { throw e2; - } - catch (ErrorObjectNotFoundException e) { + } catch (ErrorObjectNotFoundException e) { StackTraceElement[] stackTrace = e.getStackTrace(); assertTrue(stackTrace == null || stackTrace.length == 0); } } - /*public ErrorObjectNotFoundException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - // TODO Auto-generated constructor stub - }*/ + /* + * public ErrorObjectNotFoundException(String message, Throwable cause, boolean enableSuppression, + * boolean writableStackTrace) { + * super(message, cause, enableSuppression, writableStackTrace); + * // TODO Auto-generated constructor stub + * } + */ } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectTest.java index ff20105c..a0fcf655 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/ErrorObjectTest.java @@ -20,11 +20,11 @@ package org.onap.aai.logging; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import javax.ws.rs.core.Response; -import static org.junit.Assert.assertEquals; +import org.junit.Test; public class ErrorObjectTest { private ErrorObject errorObject; @@ -37,18 +37,21 @@ public class ErrorObjectTest { private static final String ERROR_TEXT = "Test data error"; private static final String ERROR_PATTERN = "ERR.5.4.4000"; private static final String ERROR_SEVERITY_CODE = "2"; + @Test public void errorObjectDefaultConstructorTest() { errorObject = new ErrorObject(); assertEquals("3002", errorObject.getRESTErrorCode()); - assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()), errorObject.getHTTPResponseCode()); - assertEquals(AaiElsErrorCode.UNKNOWN_ERROR,errorObject.getAaiElsErrorCode()); + assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()), + errorObject.getHTTPResponseCode()); + assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode()); assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY)); } + @Test public void errorObjectConstructor7Test() { errorObject = new ErrorObject(ERROR_DISPOSITION, ERROR_CATEGORY, ERROR_SEVERITY, ERROR_HTTP_RESPONSE_CODE, - ERROR_REST_CODE, ERROR_CODE, ERROR_TEXT); + ERROR_REST_CODE, ERROR_CODE, ERROR_TEXT); assertEquals(ERROR_DISPOSITION, errorObject.getDisposition()); assertEquals(ERROR_SEVERITY, errorObject.getSeverity()); assertEquals(ERROR_CATEGORY, errorObject.getCategory()); @@ -56,7 +59,7 @@ public class ErrorObjectTest { assertEquals(ERROR_REST_CODE, errorObject.getRESTErrorCode()); assertEquals(ERROR_CODE, errorObject.getErrorCode()); assertEquals(ERROR_TEXT, errorObject.getErrorText()); - assertEquals(AaiElsErrorCode.UNKNOWN_ERROR,errorObject.getAaiElsErrorCode()); + assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode()); assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY)); } @@ -66,18 +69,20 @@ public class ErrorObjectTest { assertEquals(ERROR_DISPOSITION, errorObject.getDisposition()); assertEquals(ERROR_SEVERITY, errorObject.getSeverity()); assertEquals(ERROR_CATEGORY, errorObject.getCategory()); - assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()), errorObject.getHTTPResponseCode()); + assertEquals(Response.Status.fromStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()), + errorObject.getHTTPResponseCode()); assertEquals("3002", errorObject.getRESTErrorCode()); assertEquals(ERROR_CODE, errorObject.getErrorCode()); assertEquals(ERROR_TEXT, errorObject.getErrorText()); - assertEquals(AaiElsErrorCode.UNKNOWN_ERROR,errorObject.getAaiElsErrorCode()); + assertEquals(AaiElsErrorCode.UNKNOWN_ERROR, errorObject.getAaiElsErrorCode()); assertEquals(ERROR_PATTERN, errorObject.getErrorCodeString()); assertEquals(ERROR_SEVERITY_CODE, errorObject.getSeverityCode(ERROR_SEVERITY)); } @Test public void errorObjectConstructor6Test() { - errorObject = new ErrorObject(ERROR_SEVERITY, ERROR_HTTP_RESPONSE_CODE, ERROR_CODE, ERROR_TEXT, ERROR_DISPOSITION, ERROR_CATEGORY); + errorObject = new ErrorObject(ERROR_SEVERITY, ERROR_HTTP_RESPONSE_CODE, ERROR_CODE, ERROR_TEXT, + ERROR_DISPOSITION, ERROR_CATEGORY); assertEquals(ERROR_DISPOSITION, errorObject.getDisposition()); assertEquals(ERROR_SEVERITY, errorObject.getSeverity()); assertEquals(ERROR_CATEGORY, errorObject.getCategory()); @@ -91,5 +96,4 @@ public class ErrorObjectTest { } - } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LogFormatToolsTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LogFormatToolsTest.java index 695d7c08..b352cb14 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LogFormatToolsTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LogFormatToolsTest.java @@ -20,12 +20,12 @@ package org.onap.aai.logging; -import org.junit.Test; -import org.onap.aai.exceptions.AAIException; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; + public class LogFormatToolsTest { @Test diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java index 4fe60315..d793eb77 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java @@ -20,20 +20,21 @@ package org.onap.aai.logging; -import org.junit.After; -import org.junit.Test; -import org.slf4j.MDC; +import static org.junit.Assert.*; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Test; +import org.slf4j.MDC; public class LoggingContextTest { @After - public void cleanup(){ + public void cleanup() { MDC.clear(); } + @Test public void elapsedTimeTest() { LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS); @@ -41,6 +42,7 @@ public class LoggingContextTest { LoggingContext.init(); assertNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString())); } + @Test public void stopWatchTest() { LoggingContext.init(); @@ -53,6 +55,7 @@ public class LoggingContextTest { assertFalse(LoggingContext.isStopWatchStarted()); assertTrue(elapsedTime > 0); } + @Test public void putClearTest() { String testServiceName = "TEST-SVC-NAME"; diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchNotStartedExceptionTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchNotStartedExceptionTest.java index 8a4123f0..2c9c52c5 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchNotStartedExceptionTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchNotStartedExceptionTest.java @@ -20,31 +20,33 @@ package org.onap.aai.logging; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class StopWatchNotStartedExceptionTest { +import org.junit.Test; +public class StopWatchNotStartedExceptionTest { @Test public void stopWatchNotStartedExceptionTest() { StopWatchNotStartedException e = new StopWatchNotStartedException(); assertTrue(e instanceof RuntimeException); } + @Test public void stopWatchNotStartedExceptionWithMessageTest() { StopWatchNotStartedException e = new StopWatchNotStartedException("Error Message"); assertTrue(e instanceof RuntimeException); assertEquals("Error Message", e.getMessage()); } + @Test public void stopWatchNotStartedExceptionWithCauseTest() { StopWatchNotStartedException e = new StopWatchNotStartedException(new ArithmeticException()); assertTrue(e instanceof RuntimeException); assertTrue(e.getCause() instanceof ArithmeticException); } + @Test public void stopWatchNotStartedExceptionWithMsgCauseTest() { StopWatchNotStartedException e = new StopWatchNotStartedException("Error Message", new ArithmeticException()); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchTest.java index 50a2d053..34aecd56 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/StopWatchTest.java @@ -20,19 +20,20 @@ package org.onap.aai.logging; +import static java.lang.Thread.sleep; +import static org.junit.Assert.*; + import org.junit.After; import org.junit.Test; import org.slf4j.MDC; -import static java.lang.Thread.sleep; -import static org.junit.Assert.*; - public class StopWatchTest { @After public void cleanup() { MDC.clear(); } + @Test public void elapsedTimeTest() throws InterruptedException { StopWatch.start(); @@ -40,6 +41,7 @@ public class StopWatchTest { StopWatch.stop(); assertTrue(Long.parseLong(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString())) >= 1000L); } + @Test public void elapsedTimeConditionalTest() throws InterruptedException { StopWatch.conditionalStart(); @@ -49,12 +51,13 @@ public class StopWatchTest { long elapsedTime = Long.parseLong(elapsedTimeStr); assertTrue(elapsedTime >= 1000L); } + @Test public void clearTest() throws InterruptedException { StopWatch.start(); sleep(1010); StopWatch.stop(); - assertNotNull( MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString())); + assertNotNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString())); StopWatch.clear(); assertNull(MDC.get(LoggingContext.LoggingField.STOP_WATCH_START.toString())); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java index 24efee3d..7d51ccc2 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java @@ -19,15 +19,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.junit.Before; import org.junit.Test; import org.onap.aai.exceptions.AAIException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class AAIApplicationConfigTest { @Before @@ -39,6 +40,7 @@ public class AAIApplicationConfigTest { public void truststoreTest() throws AAIException { assertEquals("truststore.jks", AAIApplicationConfig.getTruststore()); } + @Test public void keystoreTest() throws AAIException { assertEquals("keystore.jks", AAIApplicationConfig.getKeystore()); @@ -58,6 +60,7 @@ public class AAIApplicationConfigTest { public void getValueTest() throws AAIException { assertEquals("certificates", AAIApplicationConfig.get("server.certs.location")); } + @Test public void getIntValueTest() throws AAIException { assertTrue(8446 == AAIApplicationConfig.getInt("server.port")); @@ -70,6 +73,7 @@ public class AAIApplicationConfigTest { @Test public void getValueWithReplacementTest() throws AAIException { - assertEquals("/opt/app/aai/etc/auth/aai-client-cert.p12", AAIApplicationConfig.get("schema.service.ssl.key-store")); + assertEquals("/opt/app/aai/etc/auth/aai-client-cert.p12", + AAIApplicationConfig.get("schema.service.ssl.key-store")); } } diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIConfigTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIConfigTest.java index 86d6c202..dad8c351 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIConfigTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIConfigTest.java @@ -19,14 +19,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.util; +import static org.junit.Assert.*; + import org.junit.Before; import org.junit.Test; import org.onap.aai.exceptions.AAIException; -import static org.junit.Assert.*; - public class AAIConfigTest { @Before @@ -43,6 +44,7 @@ public class AAIConfigTest { public void getValueTest() throws AAIException { assertEquals("10", AAIConfig.get("aai.logging.maxStackTraceEntries")); } + @Test public void getIntValueTest() throws AAIException { assertTrue(10 == AAIConfig.getInt("aai.logging.maxStackTraceEntries")); diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/util/FormatDateTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/util/FormatDateTest.java index 38ac5de5..b1be62a1 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/util/FormatDateTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/util/FormatDateTest.java @@ -19,13 +19,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.util; +import static org.junit.Assert.assertNotNull; + import org.junit.Test; import org.onap.aai.exceptions.AAIException; -import static org.junit.Assert.assertNotNull; - public class FormatDateTest { private FormatDate formatDate = null; diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/util/LogFile.java b/aai-els-onap-logging/src/test/java/org/onap/aai/util/LogFile.java index b94686bb..3ace6f01 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/util/LogFile.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/util/LogFile.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.util; import java.io.File; @@ -31,7 +32,7 @@ import org.apache.commons.io.IOUtils; * Utility class to read/delete contents of log file */ public class LogFile { - + public static String getContents(String fileName) throws IOException { FileInputStream fileInputStream = null; @@ -39,12 +40,13 @@ public class LogFile { try { fileInputStream = new FileInputStream("logs/" + fileName); contents = IOUtils.toString(fileInputStream, "UTF-8"); - } - finally { - if (fileInputStream != null) fileInputStream.close(); + } finally { + if (fileInputStream != null) + fileInputStream.close(); } return contents; } + public static void deleteContents(String fileName) throws IOException { FileUtils.write(new File("logs/" + fileName), "", Charset.defaultCharset()); } diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogContainerFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogContainerFilterTest.java index 119bdf1e..8ac9f12d 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogContainerFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogContainerFilterTest.java @@ -22,11 +22,13 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; + import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,7 +63,6 @@ public class AuditLogContainerFilterTest { MDC.clear(); } - @Test public void filterTest() { MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>(); diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogServletFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogServletFilterTest.java index d3f0f9f5..afdfe059 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogServletFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/AuditLogServletFilterTest.java @@ -21,12 +21,13 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.when; + import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/LoggingContainerFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/LoggingContainerFilterTest.java index 4d1f102a..6390c8ea 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/LoggingContainerFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/LoggingContainerFilterTest.java @@ -21,8 +21,10 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; + import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; + import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java index 9c89da5a..e47db8ce 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java @@ -24,11 +24,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; + import java.util.HashMap; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java index 6f6a0ff1..daa57625 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java @@ -23,16 +23,17 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.doReturn; + import java.net.URI; import java.net.URISyntaxException; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.Map; + import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java index c2446a3f..61e7014b 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java @@ -22,11 +22,14 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; + import java.io.IOException; import java.net.URISyntaxException; + import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleJaxrsHeadersMapTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleJaxrsHeadersMapTest.java index e2c5da9c..0ae919fc 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleJaxrsHeadersMapTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleJaxrsHeadersMapTest.java @@ -21,8 +21,10 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; + import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; + import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleServletHeadersMapTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleServletHeadersMapTest.java index fff67768..ccde0000 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleServletHeadersMapTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/filter/base/SimpleServletHeadersMapTest.java @@ -22,7 +22,9 @@ package org.onap.logging.filter.base; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; + import javax.servlet.http.HttpServletRequest; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java index 9549eaa9..f6ed9614 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java @@ -21,20 +21,6 @@ package org.onap.logging.ref.slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; -import org.slf4j.event.Level; -import org.springframework.mock.web.MockHttpServletRequest; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; - -import javax.xml.bind.DatatypeConverter; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; @@ -44,6 +30,21 @@ import static org.hamcrest.core.IsSame.sameInstance; import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.number.OrderingComparison.lessThan; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.xml.bind.DatatypeConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.event.Level; +import org.springframework.mock.web.MockHttpServletRequest; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; + /** * Tests for {@link ONAPLogAdapter}. */ @@ -68,8 +69,7 @@ public class ONAPLogAdapterTest { try { ONAPLogAdapter.checkNotNull(null); Assert.fail("Should throw NullPointerException"); - } - catch (final NullPointerException e) { + } catch (final NullPointerException e) { } } @@ -126,12 +126,11 @@ public class ONAPLogAdapterTest { assertThat(invokeTimestampString, endsWith("Z")); final long invokeTimestamp = DatatypeConverter.parseDateTime(invokeTimestampString).getTimeInMillis(); assertThat(Math.abs(System.currentTimeMillis() - invokeTimestamp), lessThan(5000L)); - } - finally { + } finally { MDC.clear(); } } - + /** * Test ENTERING with an EMPTY_STRING serviceName. */ @@ -166,8 +165,7 @@ public class ONAPLogAdapterTest { assertThat(invokeTimestampString, endsWith("Z")); final long invokeTimestamp = DatatypeConverter.parseDateTime(invokeTimestampString).getTimeInMillis(); assertThat(Math.abs(System.currentTimeMillis() - invokeTimestamp), lessThan(5000L)); - } - finally { + } finally { MDC.clear(); } } @@ -217,8 +215,7 @@ public class ONAPLogAdapterTest { assertThat(MDC.get("somekey"), is("somevalue")); adapter.exiting(); assertThat(MDC.get("somekey"), nullValue()); - } - finally { + } finally { MDC.clear(); } } @@ -238,7 +235,7 @@ public class ONAPLogAdapterTest { final UUID asyncUUID = adapter.invoke(ONAPLogConstants.InvocationMode.SYNCHRONOUS); assertThat(asyncUUID, notNullValue()); - final UUID agnosticUUID = adapter.invoke((ONAPLogConstants.InvocationMode)null); + final UUID agnosticUUID = adapter.invoke((ONAPLogConstants.InvocationMode) null); assertThat(agnosticUUID, notNullValue()); } @@ -253,13 +250,14 @@ public class ONAPLogAdapterTest { final ONAPLogAdapter adapter = new ONAPLogAdapter(logger); final Map<String, String> headers = new HashMap<>(); - final ONAPLogAdapter.RequestBuilder builder = new ONAPLogAdapter.RequestBuilder<ONAPLogAdapter.RequestBuilder>() { - @Override - public ONAPLogAdapter.RequestBuilder setHeader(final String name, final String value) { - headers.put(name, value); - return this; - } - }; + final ONAPLogAdapter.RequestBuilder builder = + new ONAPLogAdapter.RequestBuilder<ONAPLogAdapter.RequestBuilder>() { + @Override + public ONAPLogAdapter.RequestBuilder setHeader(final String name, final String value) { + headers.put(name, value); + return this; + } + }; try { final UUID uuid = adapter.invoke(builder, ONAPLogConstants.InvocationMode.SYNCHRONOUS); @@ -267,8 +265,7 @@ public class ONAPLogAdapterTest { assertThat(headers.get(ONAPLogConstants.Headers.INVOCATION_ID), is(uuid.toString())); assertThat(headers.containsKey(ONAPLogConstants.Headers.PARTNER_NAME), is(true)); assertThat(headers.containsKey(ONAPLogConstants.Headers.REQUEST_ID), is(true)); - } - finally { + } finally { MDC.clear(); } } @@ -283,13 +280,14 @@ public class ONAPLogAdapterTest { final ONAPLogAdapter adapter = new ONAPLogAdapter(logger); final Map<String, String> headers = new HashMap<>(); - final ONAPLogAdapter.RequestBuilder builder = new ONAPLogAdapter.RequestBuilder<ONAPLogAdapter.RequestBuilder>() { - @Override - public ONAPLogAdapter.RequestBuilder setHeader(final String name, final String value) { - headers.put(name, value); - return this; - } - }; + final ONAPLogAdapter.RequestBuilder builder = + new ONAPLogAdapter.RequestBuilder<ONAPLogAdapter.RequestBuilder>() { + @Override + public ONAPLogAdapter.RequestBuilder setHeader(final String name, final String value) { + headers.put(name, value); + return this; + } + }; try { final UUID uuid = adapter.invoke(builder); @@ -297,8 +295,7 @@ public class ONAPLogAdapterTest { assertThat(headers.get(ONAPLogConstants.Headers.INVOCATION_ID), is(uuid.toString())); assertThat(headers.containsKey(ONAPLogConstants.Headers.PARTNER_NAME), is(true)); assertThat(headers.containsKey(ONAPLogConstants.Headers.REQUEST_ID), is(true)); - } - finally { + } finally { MDC.clear(); } } @@ -312,8 +309,7 @@ public class ONAPLogAdapterTest { request.setRequestURI("/ctx0"); request.setServerName("srv0"); - final ONAPLogAdapter.HttpServletRequestAdapter adapter - = new ONAPLogAdapter.HttpServletRequestAdapter(request); + final ONAPLogAdapter.HttpServletRequestAdapter adapter = new ONAPLogAdapter.HttpServletRequestAdapter(request); assertThat(adapter.getHeader("uuid"), is(uuid.toString())); assertThat(adapter.getRequestURI(), is("/ctx0")); assertThat(adapter.getServerAddress(), is("srv0")); @@ -323,8 +319,7 @@ public class ONAPLogAdapterTest { public void testServiceDescriptor() { final String uuid = UUID.randomUUID().toString(); - final ONAPLogAdapter.ServiceDescriptor adapter - = new ONAPLogAdapter.ServiceDescriptor(); + final ONAPLogAdapter.ServiceDescriptor adapter = new ONAPLogAdapter.ServiceDescriptor(); adapter.setServiceUUID(uuid); adapter.setServiceName("name0"); @@ -341,8 +336,7 @@ public class ONAPLogAdapterTest { public void testResponseDescriptor() { final String uuid = UUID.randomUUID().toString(); - final ONAPLogAdapter.ResponseDescriptor adapter - = new ONAPLogAdapter.ResponseDescriptor(); + final ONAPLogAdapter.ResponseDescriptor adapter = new ONAPLogAdapter.ResponseDescriptor(); adapter.setResponseCode("code0"); adapter.setResponseDescription("desc0"); adapter.setResponseSeverity(Level.INFO); @@ -385,20 +379,17 @@ public class ONAPLogAdapterTest { // Generate (and log) an invocationID, then use it to // invoke another component. - final RESTClient client = new RESTClient(); // implements ONAPLogAdapter.RequestBuilder<RESTClient>. + final RESTClient client = new RESTClient(); // implements ONAPLogAdapter.RequestBuilder<RESTClient>. adapter.invoke(client, ONAPLogConstants.InvocationMode.SYNCHRONOUS); - final RESTRequest request = null; // TODO: build real request. - final RESTResponse response = client.execute(request); // TODO: handle real response. + final RESTRequest request = null; // TODO: build real request. + final RESTResponse response = client.execute(request); // TODO: handle real response. // Set response details prior to #exiting. // (Obviously there'd be errorhandling, etc. IRL). - adapter.getResponseDescriptor() - .setResponseCode((String)null) - .setResponseSeverity(Level.INFO) + adapter.getResponseDescriptor().setResponseCode((String) null).setResponseSeverity(Level.INFO) .setResponseStatus(ONAPLogConstants.ResponseStatus.COMPLETE); - } - finally { + } finally { // Return, logging EXIT marker, with response MDCs. diff --git a/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogConstantsTest.java b/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogConstantsTest.java index 9a46f05b..6dc5e59c 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogConstantsTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/logging/ref/slf4j/ONAPLogConstantsTest.java @@ -21,16 +21,16 @@ package org.onap.logging.ref.slf4j; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsInstanceOf.instanceOf; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import org.testng.Assert; import org.testng.annotations.Test; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsInstanceOf.instanceOf; - /** * Tests for {@link ONAPLogConstants}. */ @@ -51,8 +51,7 @@ public class ONAPLogConstantsTest { c.setAccessible(true); c.newInstance(); Assert.fail("Should fail for hidden constructor."); - } - catch (final InvocationTargetException e) { + } catch (final InvocationTargetException e) { assertThat(e.getCause(), instanceOf(UnsupportedOperationException.class)); } } @@ -82,8 +81,7 @@ public class ONAPLogConstantsTest { @Test public void testInvocationModeToString() { - assertThat(ONAPLogConstants.InvocationMode.SYNCHRONOUS.toString(), - is("SYNCHRONOUS")); + assertThat(ONAPLogConstants.InvocationMode.SYNCHRONOUS.toString(), is("SYNCHRONOUS")); } @Test @@ -114,8 +112,7 @@ public class ONAPLogConstantsTest { try { c.getDeclaredConstructors()[0].newInstance(); Assert.fail("Should fail for hidden constructor."); - } - catch (final IllegalAccessException e) { + } catch (final IllegalAccessException e) { } @@ -124,8 +121,7 @@ public class ONAPLogConstantsTest { constructor.setAccessible(true); constructor.newInstance(); Assert.fail("Should fail even when invoked."); - } - catch (final InvocationTargetException e) { + } catch (final InvocationTargetException e) { assertThat(e.getCause(), instanceOf(UnsupportedOperationException.class)); } } |