diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2018-12-18 14:59:41 +0000 |
---|---|---|
committer | Joss Armstrong <joss.armstrong@ericsson.com> | 2018-12-18 15:00:42 +0000 |
commit | 6feb765e31634cb1041df521b3e8a034223cabab (patch) | |
tree | fb941daf92c7de8fc95b1d3080b42014e8d5913c /appc-oam/appc-oam-bundle/src/main/java | |
parent | 74553eb3428822f57b868e3769ac23d2e7394df4 (diff) |
Fix for APPC-1286
Increased test coverage from 49% to 73% for package.
Added coverage for 4 classes that were previously at 0% coverage.
Refactored slow running code into a method that can be mocked
to speed up execution of unit tests.
Issue-ID: APPC-1286
Change-Id: I3ebe5f6bfbc59228b57d20a3c45081e40ee8e31e
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-oam/appc-oam-bundle/src/main/java')
-rw-r--r-- | appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java b/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java index 47f9c9e49..735116d09 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2018 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +44,7 @@ import org.onap.appc.oam.util.StateHelper; import org.slf4j.MDC; import java.net.InetAddress; +import java.net.UnknownHostException; import java.time.Instant; import java.util.Arrays; import java.util.Date; @@ -129,9 +132,9 @@ public abstract class BaseCommon { try { //!!!Don't change the following to a .getHostName() again please. It's wrong!MDC.put(MDC_SERVER_FQDN, // InetAddress.getLocalHost().getCanonicalHostName()); - MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); - MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress()); - MDC.put(LoggingConstants.MDCKeys.SERVER_NAME, InetAddress.getLocalHost().getHostName()); + MDC.put(MDC_SERVER_FQDN, getHostInfo("canonicalHostName")); + MDC.put(MDC_SERVER_IP_ADDRESS, getHostInfo("hostName")); + MDC.put(LoggingConstants.MDCKeys.SERVER_NAME, getHostInfo("hostName")); } catch (Exception e) { logger.error("MDC constant error", e); } @@ -261,4 +264,20 @@ public abstract class BaseCommon { logger.debug(String.format(message, args)); } } + + protected String getHostInfo(String type) throws UnknownHostException { + InetAddress inetAddress = InetAddress.getLocalHost(); + String returnValue = ""; + switch(type) { + case "canonicalHostName": returnValue = inetAddress.getCanonicalHostName(); + break; + case "hostName": returnValue = inetAddress.getHostName(); + break; + case "hostAddress": returnValue = inetAddress.getHostAddress(); + break; + default: returnValue = "Invalid operation"; + break; + } + return returnValue; + } } |