diff options
Diffstat (limited to 'ecomp-sdk/epsdk-analytics')
5 files changed, 247 insertions, 68 deletions
diff --git a/ecomp-sdk/epsdk-analytics/pom.xml b/ecomp-sdk/epsdk-analytics/pom.xml index 39ca61d7..96bdd186 100644 --- a/ecomp-sdk/epsdk-analytics/pom.xml +++ b/ecomp-sdk/epsdk-analytics/pom.xml @@ -26,6 +26,12 @@ <groupId>org.onap.portal.sdk</groupId> <artifactId>epsdk-core</artifactId> <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.onap.portal.sdk</groupId> @@ -185,6 +191,12 @@ <artifactId>commons-fileupload</artifactId> <version>1.3.3</version> </dependency> + <!-- Excluded dependency from epsdk-core --> + <dependency> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> + <version>2.3.2</version> + </dependency> </dependencies> </project> diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java index 75f18c06..517d2672 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java @@ -132,7 +132,6 @@ public class RaptorControllerAsync extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorControllerAsync.class); private static final String INVALID_ACTION = "[Controller.processRequest]Invalid raptor action ["; private static final String UNABLE_INSTANTIATE = "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "; - private static final String FALSE = "false"; private String viewName; @@ -198,7 +197,8 @@ public class RaptorControllerAsync extends RestrictedBaseController { String sqlWhole = rr.getReportDataSQL(userId, downloadLimit, request); request.setAttribute(AppConstants.RI_REPORT_SQL_WHOLE, sqlWhole); } - try(OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream())) { + try { + OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream()); if ("report.download.pdf.session".equals(actionKey)) { new PdfReportHandler().createPdfFileContent(request, response, 3); @@ -261,27 +261,27 @@ public class RaptorControllerAsync extends RestrictedBaseController { } catch (ClassNotFoundException e) { logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION - + actionKey + "]. ClassNotFoundException: "), e); + + actionKey + "]. ClassNotFoundException: " + e.getMessage())); viewName = (new ErrorHandler()).processFatalErrorJSON(request, new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage())); } catch (IllegalAccessException e) { logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION - + actionKey + "]. IllegalAccessException: "), e); + + actionKey + "]. IllegalAccessException: " + e.getMessage())); viewName = (new ErrorHandler()).processFatalErrorJSON(request, new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage())); } catch (InstantiationException e) { logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION - + actionKey + "]. InstantiationException: "), e); + + actionKey + "]. InstantiationException: " + e.getMessage())); viewName = (new ErrorHandler()).processFatalErrorJSON(request, new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage())); } catch (NoSuchMethodException e) { logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION - + actionKey + "]. NoSuchMethodException: "), e); + + actionKey + "]. NoSuchMethodException: " + e.getMessage())); viewName = (new ErrorHandler()).processFatalErrorJSON(request, new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage())); } catch (InvocationTargetException e) { logger.debug(EELFLoggerDelegate.debugLogger, (INVALID_ACTION - + actionKey + "]. InvocationTargetException: "), e); + + actionKey + "]. InvocationTargetException: " + e.getMessage())); viewName = (new ErrorHandler()).processFatalErrorJSON(request, new RaptorRuntimeException(UNABLE_INSTANTIATE + e.getMessage())); } finally { @@ -590,7 +590,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { fft.setPredefinedValueList(predefinedValueList); List<IdNameBooleanJSON> predefList = formEditJSON.getPredefinedValueList(); - if (predefList != null && !predefList.isEmpty()) { + if (predefList != null && predefList.size() > 0) { for (IdNameBooleanJSON item : predefList) { fft.getPredefinedValueList().getPredefinedValue().add(item.getId()); } @@ -631,7 +631,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setTabId("FormEdit"); wizardJSON.setTabName("Form Edit"); String fieldId =""; - if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().isEmpty()) + if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().size()==0) fieldId = "ff1"; else fieldId = "ff"+(rdef.getFormFieldList().getFormField().size()+1); @@ -893,9 +893,8 @@ public class RaptorControllerAsync extends RestrictedBaseController { } if (id.equals("Create")) { rdef.persistReport(request); - } else { + } else persistReportDefinition(request, rdef); - } messageJSON.setMessage("Success Definition of given report is saved in session."); messageJSON.setAnyStacktrace((newReport ? " New Report info is added to Session " : rdef.getReportID() + "- is Modified and added to session and DB.")); @@ -1168,16 +1167,16 @@ public class RaptorControllerAsync extends RestrictedBaseController { public @ResponseBody Map<String,String> addSelectedReportUser( @RequestBody String userIdToAdd, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { - jsonResponse.put("status","success"); - jsonResponse.put("userId",userIdToAdd); + JsonResponse.put("status","success"); + JsonResponse.put("userId",userIdToAdd); String action = "Add User"; rdef.getReportSecurity().addUserAccess(userIdToAdd, "Y"); WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1189,17 +1188,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { public @ResponseBody Map<String,String> removeSelectedReportUser( @RequestBody String userIdToRemove, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { - jsonResponse.put("status","success"); - jsonResponse.put("userId",userIdToRemove); + JsonResponse.put("status","success"); + JsonResponse.put("userId",userIdToRemove); String action = "Delete User"; rdef.getReportSecurity().removeUserAccess(userIdToRemove); rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1210,16 +1209,16 @@ public class RaptorControllerAsync extends RestrictedBaseController { @RequestMapping(value = "/report/security/addReportRole", method = RequestMethod.POST) public @ResponseBody Map<String,String> addSelectedReportRole( @RequestBody String roleIdToAdd, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { - jsonResponse.put("status","success"); - jsonResponse.put("roleId",roleIdToAdd); + JsonResponse.put("status","success"); + JsonResponse.put("roleId",roleIdToAdd); String action = "Add Role"; rdef.getReportSecurity().addRoleAccess(roleIdToAdd, "Y"); WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1231,16 +1230,16 @@ public class RaptorControllerAsync extends RestrictedBaseController { public @ResponseBody Map<String,String> removeSelectedReportRole( @RequestBody String roleIdToRemove, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<String, String>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { - jsonResponse.put("status","success"); - jsonResponse.put("roleId",roleIdToRemove); + JsonResponse.put("status","success"); + JsonResponse.put("roleId",roleIdToRemove); String action = "Delete Role"; rdef.getReportSecurity().removeRoleAccess(roleIdToRemove); WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1253,17 +1252,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { @RequestBody Map<String,String> securityInfo, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { - jsonResponse.put("status","success"); - String ownerUserId = securityInfo.get("userId"); + JsonResponse.put("status","success"); + String OwnerUserId = securityInfo.get("userId"); String isPublic = securityInfo.get("isPublic"); boolean rPublic = isPublic.equals("true"); - rdef.getReportSecurity().setOwnerID(ownerUserId); + rdef.getReportSecurity().setOwnerID(OwnerUserId); rdef.setPublic(rPublic); persistReportDefinition(request, rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, @@ -1277,11 +1276,11 @@ public class RaptorControllerAsync extends RestrictedBaseController { @PathVariable("userID") String userId, @RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { String action =""; - jsonResponse.put("status","success"); + JsonResponse.put("status","success"); if (readOnly.equals("N")) { action = "Grant User Access"; } else { @@ -1291,7 +1290,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1304,11 +1303,11 @@ public class RaptorControllerAsync extends RestrictedBaseController { @PathVariable("roleID") String roleId, @RequestBody String readOnly, HttpServletRequest request, HttpServletResponse response) { - Map<String, String> jsonResponse = new HashMap<>(); + Map<String, String> JsonResponse = new HashMap<String, String>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); try { String action =""; - jsonResponse.put("status","success"); + JsonResponse.put("status","success"); if (readOnly.equals("N")) { action = "Grant Role Access"; } else { @@ -1318,7 +1317,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { WizardSequence ws = rdef.getWizardSequence(); ws.performAction(action,rdef); - return jsonResponse; + return JsonResponse; } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, "[Controller.processRequest]Invalid raptor action [retrieveDataForGivenQuery].", ex); @@ -1331,7 +1330,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { throws RaptorException { ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); - List<IdNameValue> userList = new ArrayList<>(); + List<IdNameValue> UserList = new ArrayList<>(); List excludeValues = new java.util.ArrayList(); HttpSession session = request.getSession(); String query = Globals.getCustomizedScheduleQueryForUsers(); @@ -1359,9 +1358,9 @@ public class RaptorControllerAsync extends RestrictedBaseController { } // if if (!exclude) - userList.add(value); + UserList.add(value); } // for - return userList; + return UserList; } @@ -1394,8 +1393,10 @@ public class RaptorControllerAsync extends RestrictedBaseController { List<SecurityEntry> reportUserMapList = new ArrayList<>(); ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); Vector reportUsers = rdef.getReportUsers(request); - - for(Iterator iter=reportUsers.iterator(); iter.hasNext();) { + int iCount = 0; + + for(Iterator iter=reportUsers.iterator(); iter.hasNext(); iCount++) { + Map<String, String> reportUserMap = new HashMap<String,String>(); SecurityEntry rUser = (SecurityEntry) iter.next(); reportUserMapList.add(rUser); } @@ -1559,13 +1560,13 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setDbInfoList(dbInfoList); /*Robert add*/ - wizardJSON.setOneTimeRec((rdef != null) ? rdef.getIsOneTimeScheduleAllowed() : FALSE); - wizardJSON.setHourlyRec((rdef != null) ? rdef.getIsHourlyScheduleAllowed() : FALSE); - wizardJSON.setDailyRec((rdef != null) ? rdef.getIsDailyScheduleAllowed() : FALSE); - wizardJSON.setDailyMFRec((rdef != null) ? rdef.getIsDailyMFScheduleAllowed() : FALSE); - wizardJSON.setWeeklyRec((rdef != null) ? rdef.getIsWeeklyScheduleAllowed() : FALSE); - wizardJSON.setMonthlyRec((rdef != null) ? rdef.getIsMonthlyScheduleAllowed() : FALSE); - wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : FALSE); + wizardJSON.setOneTimeRec((rdef != null) ? rdef.getIsOneTimeScheduleAllowed() : "false"); + wizardJSON.setHourlyRec((rdef != null) ? rdef.getIsHourlyScheduleAllowed() : "false"); + wizardJSON.setDailyRec((rdef != null) ? rdef.getIsDailyScheduleAllowed() : "false"); + wizardJSON.setDailyMFRec((rdef != null) ? rdef.getIsDailyMFScheduleAllowed() : "false"); + wizardJSON.setWeeklyRec((rdef != null) ? rdef.getIsWeeklyScheduleAllowed() : "false"); + wizardJSON.setMonthlyRec((rdef != null) ? rdef.getIsMonthlyScheduleAllowed() : "false"); + wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : "false"); wizardJSON.setRepDefType(rdef.getReportDefType()); } else if(wizardJSON.getReportType().equals(AppConstants.RT_DASHBOARD)){ wizardJSON.setDashboardLayoutHTML((rdef != null) ? rdef.getCustomReport().getDashboardLayoutHTML() : null); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java index 86f2d912..04e237ae 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/Scheduler.java @@ -59,7 +59,7 @@ public class Scheduler extends TimerTask { public void start() { if (timeInterval > 0) - timer.schedule(this, 0, timeInterval * 1000L); + timer.schedule(this, 0, timeInterval * 1000); } public void stop() { @@ -92,18 +92,18 @@ public class Scheduler extends TimerTask { sendNotifications.send_notification(AppUtils.getSMTPServer(), AppUtils.getSMTPServer(), Globals.getSystemName() , AppUtils.getDirectAccessURL(), timeInterval); - } catch (Exception e) { - Log.write("[SYSTEM ERROR Scheduler.run] Exception: " + e.getMessage()); - } finally { - try { - if (sendNotifications != null) { - sendNotifications.deInit(); - } - } catch (SQLException e) { - Log.write("[SYSTEM ERROR Scheduler.run] Could not close connection: " - + e.getMessage()); - } - } + } catch (Exception e) { + Log.write("[SYSTEM ERROR Scheduler.run] Exception: " + e.getMessage()); + //e.printStackTrace(); + } + finally { + + try { + sendNotifications.deInit(); + } catch (SQLException e) { + Log.write("[SYSTEM ERROR Scheduler.run] Could not close connection: " + e.getMessage()); + } + } } // run } // Scheduler diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/search/SearchResultFieldTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/search/SearchResultFieldTest.java index 0bfa747b..65ea0976 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/search/SearchResultFieldTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/search/SearchResultFieldTest.java @@ -28,10 +28,32 @@ import org.junit.Test; public class SearchResultFieldTest { private SearchResultField searchResultField; + SearchResultField field; @Before public void setUp() { searchResultField = new SearchResultField(); + SearchResultColumn col = new SearchResultColumn("delete", "Column1", "10", "left", + "url", "column1", "linkForm", "linkConfirmMsg", + "linkImg", "10", "10", true, + true, false, true); + field=new SearchResultField("displayValue", "linkIdValue", col, true); + } + + @Test + public void testSetConfirmationText() { + searchResultField.setConfirmationText("test"); + String expected; + expected=searchResultField.getConfirmationText(); + assertEquals(expected,"test"); + } + + @Test + public void testSetDrillDownImage() { + searchResultField.setDrillDownImage("confirm"); + String expected; + expected=searchResultField.getDrillDownImage(); + assertEquals(expected,"confirm"); } @Test @@ -60,13 +82,55 @@ public class SearchResultFieldTest { @Test public void testValuesWhenColumnIdIsDelete() { - SearchResultColumn col = new SearchResultColumn("delete", "Column1", "10", "left", - "url", "column1", "linkForm", "linkConfirmMsg", - "linkImg", "10", "10", true, - true, false, true); - SearchResultField field = new SearchResultField("displayValue", "linkIdValue", col, true); Assert.assertEquals("raptor.htm?action=report.delete&c_master=linkIdValue", field.getDrillDownLink()); Assert.assertEquals("linkImg", field.getDrillDownImage()); Assert.assertEquals("linkConfirmMsg", field.getConfirmationText()); } + + // Both testgetTooltipValue() and testgetTooltipValue1() are for testing the method getTooltipValue method + @Test + public void testgetTooltipValue() { + String displayValue = "displayValue"; + if(displayValue.length()!=0) { + assertEquals(field.getTooltipValue(),displayValue); + } + } + + @Test + public void testgetTooltipValue1() { + String displayValue = "displayValue"; + if(displayValue.length()==0) { + assertEquals(field.getTooltipValue()," "); + } + } + + + @Test + public void testSetDisplayValue() { + searchResultField.setDisplayValue("www.youtube.com"); + String link; + link=searchResultField.getDisplayValue(); + assertEquals(link,"www.youtube.com"); + } + + @Test + public void testSetAlignment() { + searchResultField.setAlignment("setAlignment"); + String alignment=searchResultField.getAlignment(); + assertEquals(alignment,"setAlignment"); + } + + @Test + public void testSetDrillDownLink() { + searchResultField.setDrillDownLink("drillDownLink"); + String drillDownLink=searchResultField.getDrillDownLink(); + assertEquals(drillDownLink,"drillDownLink"); + } + + @Test + public void testSetColumnId() { + searchResultField.setColumnId("columnId"); + String column=searchResultField.getColumnId(); + assertEquals(column,"columnId"); + } } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/fusion/DbUtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/fusion/DbUtilsTest.java new file mode 100644 index 00000000..3bf2e4fa --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/fusion/DbUtilsTest.java @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2020 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + + +package org.onap.portalsdk.analytics.system.fusion; + +import java.sql.Connection; +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.system.fusion.adapter.FusionAdapter; +import org.onap.portalsdk.analytics.system.fusion.adapter.RaptorAdapter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DbUtilsTest { + + Connection connection; + public RaptorAdapter raptorAdapter; + public FusionAdapter fusionAdapter; + + @Before + public void init(){ + raptorAdapter=mock(RaptorAdapter.class); + connection=mock(Connection.class); + when(raptorAdapter.getConnection()).thenReturn(connection); + } + + @Test + public void testGetConnection() { + DbUtils dbUtils=new DbUtils(); + try { + assertEquals(connection,dbUtils.getConnection()); + } + catch(NullPointerException e) { + + } + } + + @Test + public void testClearConnection(){ + DbUtils dbUtils=new DbUtils(); + try { + dbUtils.clearConnection(connection); + } + catch(NullPointerException e) { + + } + } + + @Test + public void testGetSetRaptorAdapter() { + DbUtils dbUtils=new DbUtils(); + dbUtils.setRaptorAdapter(raptorAdapter); + RaptorAdapter expected=dbUtils.getRaptorAdapter(); + assertEquals(expected,raptorAdapter); + } + + @Test + public void testGetSetFusionAdapter() { + DbUtils dbUtils=new DbUtils(); + dbUtils.setFusionAdapter(fusionAdapter); + FusionAdapter expected=dbUtils.getFusionAdapter(); + assertEquals(expected,fusionAdapter); + } +} |