diff options
author | Sunil Unnava <su622b@att.com> | 2018-03-06 19:38:54 -0500 |
---|---|---|
committer | Sunil Unnava <su622b@att.com> | 2018-03-06 19:39:05 -0500 |
commit | 63548522dfacfdc11826facecf6d2a06a95f8295 (patch) | |
tree | 3015b87ada318e553fbf61904f74bbd72ec0a1fc /src/main | |
parent | fbe26a20e749c3177f84cd05c67e757ac107b9a8 (diff) |
testcases for code coverage
Issue-ID: DMAAP-271
Change-Id: Ifacdeeaca0176bf3a5e509cb0d27e7ec1e89bd8c
Signed-off-by: Sunil Unnava <su622b@att.com>
Diffstat (limited to 'src/main')
3 files changed, 50 insertions, 20 deletions
diff --git a/src/main/java/com/att/nsa/dmaap/service/AdminRestService.java b/src/main/java/com/att/nsa/dmaap/service/AdminRestService.java index 5201dc8..2ab574d 100644 --- a/src/main/java/com/att/nsa/dmaap/service/AdminRestService.java +++ b/src/main/java/com/att/nsa/dmaap/service/AdminRestService.java @@ -91,6 +91,8 @@ public class AdminRestService { */ @Autowired private AdminService adminService; + + private DMaaPContext dmaaPContext; /** * Fetches a list of all the registered consumers along with their created @@ -107,7 +109,7 @@ public class AdminRestService { public void getConsumerCache() throws CambriaApiException, AccessDeniedException { LOGGER.info("Fetching list of registered consumers."); try { - adminService.showConsumerCache(getDMaaPContext()); + adminService.showConsumerCache(ServiceUtil.getDMaaPContext(configReader, request, response)); LOGGER.info("Fetching Consumer Cache Successfully"); } catch (IOException e) { LOGGER.error("Error while Fetching list of registered consumers : " @@ -136,7 +138,7 @@ public class AdminRestService { public void dropConsumerCache() throws CambriaApiException, AccessDeniedException { LOGGER.info("Dropping consumer cache"); try { - adminService.dropConsumerCache(getDMaaPContext()); + adminService.dropConsumerCache(ServiceUtil.getDMaaPContext(configReader, request, response)); LOGGER.info("Dropping Consumer Cache successfully"); } catch ( AccessDeniedException excp) { LOGGER.error("Error while dropConsumerCache : " @@ -170,14 +172,14 @@ public class AdminRestService { public void getBlacklist() throws CambriaApiException { LOGGER.info("Fetching list of blacklist ips."); try { - Enumeration headerNames = getDMaaPContext().getRequest().getHeaderNames(); + Enumeration headerNames = ServiceUtil.getDMaaPContext(configReader, request, response).getRequest().getHeaderNames(); while (headerNames.hasMoreElements()) { String key = (String) headerNames.nextElement(); String value = request.getHeader(key); } - adminService.getBlacklist(getDMaaPContext()); + adminService.getBlacklist(ServiceUtil.getDMaaPContext(configReader, request, response)); LOGGER.info("Fetching list of blacklist ips Successfully"); }catch ( AccessDeniedException excp) { LOGGER.error("Error while Fetching list of blacklist ips : " @@ -215,7 +217,7 @@ public class AdminRestService { { LOGGER.info("Adding ip to list of blacklist ips."); try { - adminService.addToBlacklist(getDMaaPContext(), ip); + adminService.addToBlacklist(ServiceUtil.getDMaaPContext(configReader, request, response), ip); LOGGER.info("Fetching list of blacklist ips Successfully"); } catch ( AccessDeniedException excp) { LOGGER.error("Error while blacklist : " @@ -253,7 +255,7 @@ public class AdminRestService { public void removeFromBlacklist(@PathParam("ip") String ip) throws CambriaApiException, AccessDeniedException, ConfigDbException { LOGGER.info("Fetching list of blacklist ips."); try { - adminService.removeFromBlacklist(getDMaaPContext(), ip); + adminService.removeFromBlacklist(ServiceUtil.getDMaaPContext(configReader, request, response), ip); LOGGER.info("Fetching list of blacklist ips Successfully"); }catch ( AccessDeniedException excp) { LOGGER.error("Error while blacklist : " @@ -278,16 +280,6 @@ public class AdminRestService { } } - /** - * Create a dmaap context - * @return DMaaPContext - */ - private DMaaPContext getDMaaPContext() { - DMaaPContext dmaaPContext = new DMaaPContext(); - dmaaPContext.setConfigReader(configReader); - dmaaPContext.setRequest(request); - dmaaPContext.setResponse(response); - return dmaaPContext; - } + } diff --git a/src/main/java/com/att/nsa/dmaap/service/MMRestService.java b/src/main/java/com/att/nsa/dmaap/service/MMRestService.java index a715e1f..d90d832 100644 --- a/src/main/java/com/att/nsa/dmaap/service/MMRestService.java +++ b/src/main/java/com/att/nsa/dmaap/service/MMRestService.java @@ -168,7 +168,7 @@ public class MMRestService { sendErrResponse(ctx, errorMessages.getIncorrectJson()); LOGGER.error("JsonSyntaxException: ", ex); } - String name = createMirrorMaker.getCreateMirrorMaker().getName(); + String name = createMirrorMaker.getCreateMirrorMaker()==null? "":createMirrorMaker.getCreateMirrorMaker().getName(); // send error message if it is not a CreateMirrorMaker request. if (createMirrorMaker.getCreateMirrorMaker() == null) { sendErrResponse(ctx, "This is not a CreateMirrorMaker request. Please try again."); @@ -318,8 +318,7 @@ public class MMRestService { LOGGER.error("JsonSyntaxException: ", ex); } - String name = updateMirrorMaker.getUpdateMirrorMaker().getName(); - + String name = updateMirrorMaker.getUpdateMirrorMaker()==null? "":updateMirrorMaker.getUpdateMirrorMaker().getName(); // send error message if it is not a UpdateMirrorMaker request. if (updateMirrorMaker.getUpdateMirrorMaker() == null) { sendErrResponse(ctx, "This is not a UpdateMirrorMaker request. Please try again."); diff --git a/src/main/java/com/att/nsa/dmaap/service/ServiceUtil.java b/src/main/java/com/att/nsa/dmaap/service/ServiceUtil.java new file mode 100644 index 0000000..928ab9f --- /dev/null +++ b/src/main/java/com/att/nsa/dmaap/service/ServiceUtil.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package com.att.nsa.dmaap.service; + +import com.att.nsa.cambria.beans.DMaaPContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import com.att.nsa.cambria.utils.ConfigurationReader; + +public class ServiceUtil { + private static DMaaPContext dmaaPContext; + + + public static DMaaPContext getDMaaPContext(ConfigurationReader configReader,HttpServletRequest request,HttpServletResponse response) { + dmaaPContext = new DMaaPContext(); + dmaaPContext.setConfigReader(configReader); + dmaaPContext.setRequest(request); + dmaaPContext.setResponse(response); + return dmaaPContext; + } + +} |