diff options
author | Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com> | 2019-02-13 10:05:13 -0500 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-14 14:16:04 +0000 |
commit | b186a6a5c746c660a885492f421c29224f56b310 (patch) | |
tree | a065db0f15326c551d0489fa45fbbdaf9d242047 /appc-inbound/appc-design-services/provider/src/main/java | |
parent | 29039d7e4abee0419cf07714dac8f85efdf51b61 (diff) |
Added test case for DesignServiceImpl Class
Increased the coverage from 0% to 97.5%
Issue-ID: APPC-1420
Change-Id: Iea12e07e91f6d84645dbbc060518c26c1695fd40
Signed-off-by: Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
Diffstat (limited to 'appc-inbound/appc-design-services/provider/src/main/java')
3 files changed, 92 insertions, 80 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java index bef8ce4d2..890f40d3d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Modifications Copyright (C) 2019 Ericsson + * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -99,8 +101,8 @@ public class DesignServicesImpl implements DesignServicesService { StatusBuilder statusBuilder = new StatusBuilder(); try { - XInterfaceService xInterfaceService = new XInterfaceService(); - XResponseProcessor responseProcessor = new XResponseProcessor(); + XInterfaceService xInterfaceService = XInterfaceService.getInstance(); + XResponseProcessor responseProcessor = XResponseProcessor.getInstance(); String response = responseProcessor.parseResponse( xInterfaceService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload()), input.getDesignRequest().getAction()); diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java index 51ff09c46..42f13243d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Modifications Copyright (C) 2019 Ericsson + * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,32 +26,36 @@ package org.onap.appc.design.xinterface; import org.onap.appc.design.services.util.DesignServiceConstants; -import org.onap.appc.design.xinterface.XResponseProcessor; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.google.common.base.Strings; public class XInterfaceService { - - private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); - public String execute(String action, String payload) throws Exception { - //File targetFile = new File("/tmp/" + action + "-response.txt" ); - String interfaceResponse = null; - try{ - if(Strings.isNullOrEmpty(payload)) - throw new Exception("Payload is null or empty.."); - if(DesignServiceConstants.GETINSTARDATA.equalsIgnoreCase(action)){ - XResponseProcessor xResponseProcessor = new XResponseProcessor(); - interfaceResponse = xResponseProcessor.parseResponse(payload, DesignServiceConstants.GETINSTARDATA); - } else { - throw new Exception("No Such Action, Please enter valid Action"); - } - }catch(Exception e){ - e.printStackTrace(); - throw e; - } - return interfaceResponse; + + private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); + + public static XInterfaceService getInstance() { + return new XInterfaceService(); + } + + public String execute(String action, String payload) throws Exception { + // File targetFile = new File("/tmp/" + action + "-response.txt" ); + String interfaceResponse = null; + try { + if (Strings.isNullOrEmpty(payload)) + throw new Exception("Payload is null or empty.."); + if (DesignServiceConstants.GETINSTARDATA.equalsIgnoreCase(action)) { + XResponseProcessor xResponseProcessor = new XResponseProcessor(); + interfaceResponse = + xResponseProcessor.parseResponse(payload, DesignServiceConstants.GETINSTARDATA); + } else { + throw new Exception("No Such Action, Please enter valid Action"); + } + } catch (Exception e) { + e.printStackTrace(); + throw e; } + return interfaceResponse; + } } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java index 813d50495..4340acca9 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Modifications Copyright (C) 2019 Ericsson + * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,10 +26,8 @@ package org.onap.appc.design.xinterface; import java.util.HashMap; - import org.onap.appc.design.services.util.DesignServiceConstants; import org.onap.appc.instar.dme2client.Dme2Client; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; @@ -35,60 +35,64 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class XResponseProcessor { - private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); - Dme2Client dme2Client; - - public String parseResponse(String execute, String action) throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(execute); - log.info("payloadObject " + payloadObject); - - //String queryParam = null; - String instarResponse = null; - HashMap<String, String> payload = null; - String ipAddress = null; - String mask = null; - - try { - - // check the payload whether its having ipaddr along with subnet - ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null - ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) !=null) - ?payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase() - :null; - - mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null - ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) - ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() - : null; - - // TODO -short format - - /*if (mask != null) { - queryParam = ipAddress + "," +mask ; - log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); - } else { - queryParam = "ipAddress "+ipAddress ; - log.info("Calling Instar with IpAddress "+ ipAddress); - }*/ - - payload = new HashMap<String, String>(); - payload.put("ipAddress", ipAddress); - payload.put("mask", mask); - log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); - dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); - - instarResponse = dme2Client.send(); - - log.debug("Resposne from Instar = " + instarResponse); - if (instarResponse == null || instarResponse.length() < 0) - throw new Exception("No Data received from Instar for this action " + action); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - return instarResponse; + private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); + Dme2Client dme2Client; + + public static XResponseProcessor getInstance() { + return new XResponseProcessor(); + } + + public String parseResponse(String execute, String action) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(execute); + log.info("payloadObject " + payloadObject); + + // String queryParam = null; + String instarResponse = null; + HashMap<String, String> payload = null; + String ipAddress = null; + String mask = null; + + try { + + // check the payload whether its having ipaddr along with subnet + ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue() + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue() + .toUpperCase() + : null; + + mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() + : null; + + // TODO -short format + + /* + * if (mask != null) { queryParam = ipAddress + "," +mask ; + * log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); } else { + * queryParam = "ipAddress "+ipAddress ; log.info("Calling Instar with IpAddress "+ + * ipAddress); } + */ + + payload = new HashMap<String, String>(); + payload.put("ipAddress", ipAddress); + payload.put("mask", mask); + log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); + dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); + + instarResponse = dme2Client.send(); + + log.debug("Resposne from Instar = " + instarResponse); + if (instarResponse == null || instarResponse.length() < 0) + throw new Exception("No Data received from Instar for this action " + action); + } catch (Exception e) { + e.printStackTrace(); + throw e; } + return instarResponse; + } } |