diff options
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src')
84 files changed, 13884 insertions, 1135 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java index d8fa23e3..26f33a35 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java @@ -72,12 +72,12 @@ public class LineInfo { public LineInfo clone() { LineInfo lineInfo = new LineInfo(nodeID1, nodeID2); + lineInfo.setLineID(lineID); lineInfo.geoCoordinate1.longitude = geoCoordinate1.longitude; lineInfo.geoCoordinate1.latitude = geoCoordinate1.latitude; lineInfo.geoCoordinate2.longitude = geoCoordinate2.longitude; lineInfo.geoCoordinate2.latitude = geoCoordinate2.latitude; lineInfo.setDescription(lineDescription); - lineInfo.setLineID(lineID); lineInfo.setLineType(lineType); lineInfo.setMoveable(moveable); lineInfo.setDeleteable(deleteable); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java index 86f85be2..5c3f938a 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java index 378c6a87..66d6e965 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java @@ -583,7 +583,7 @@ public class ReportLoader extends org.onap.portalsdk.analytics.RaptorObject { String query = Globals.getLoadQuickLinks(); query = query.replace("[userID]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),userID)); - query = query.replace("[roleList.toString()]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),roleList.toString())); + query = query.replace("[roleList.toString()]", roleList.toString()); query = query.replace("[nvls(menuId)]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),nvls(menuId))); DataSet ds = DbUtils diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java index 44a05512..72eb64b8 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java @@ -1422,6 +1422,153 @@ public class ReportDefinition extends ReportWrapper implements Serializable { resetCache(false); } // parseReportSQL + public void parseReportSQL(String sql, boolean storeInSession) throws RaptorException { + StringBuffer parsedSQL = new StringBuffer(); + + Vector updatedReportCols = new Vector(); + + curSQLParsePos = 0; + int lastParsePos = curSQLParsePos; + String lastToken = null; + String nextToken = getNextSQLParseToken(sql, true); + + String dbInfo = getDBInfo(); + boolean isCYMBALScript = false; + if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) { + try { + org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo(); + String dbType = remDbInfo.getDBType(dbInfo); + if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) { + isCYMBALScript = true; + } + } catch (Exception ex) { + throw new RaptorException(ex); + } + } + if ( isCYMBALScript == false ) { + while (nextToken.length() > 0) { + if (parsedSQL.length() == 0) { + if (nextToken.toUpperCase().equals("SELECT")) + parsedSQL.append("SELECT "); + else + throw new org.onap.portalsdk.analytics.error.ValidationException( + "The SQL must start with the SELECT keyword."); + } else if (nextToken.toUpperCase().equals("DISTINCT") + && parsedSQL.toString().equals("SELECT ")) { + parsedSQL.append("DISTINCT "); + } else if (nextToken.equals("*") + && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals( + "SELECT DISTINCT "))) { + throw new org.onap.portalsdk.analytics.error.ValidationException( + "You cannot use \"SELECT *\". Please specify select columns/expressions."); + } else if (nextToken.toUpperCase().equals("FROM")) { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL, + updatedReportCols, false)); + lastToken = null; + } + + parsedSQL.append(" \n"); + while (lastParsePos < sql.length() + && Character.isWhitespace(sql.charAt(lastParsePos))) + lastParsePos++; + parsedSQL.append(sql.substring(lastParsePos)); + break; + } else { + if (nextToken.charAt(nextToken.length() - 1) == ',') { + // The token ends with , + nextToken = nextToken.substring(0, nextToken.length() - 1); + + if (nextToken.length() == 0) { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, null, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } // else just comma => ignore it + } else { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } else + updatedReportCols.add(getParseSQLDataColumn(nextToken, null, + parsedSQL, updatedReportCols, false)); + } + } else { + // The token doesn't end with , + if (lastToken == null) + lastToken = nextToken; + else { + String token = getNextSQLParseToken(sql, false); + if (!token.toUpperCase().equals("FROM")) + throw new org.onap.portalsdk.analytics.error.ValidationException( + "|FROM keyword or a comma expected after [" + nextToken + + "]."); + + updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } // else + } // else + } // else + + lastParsePos = curSQLParsePos; + nextToken = getNextSQLParseToken(sql, true); + } // while + } else { // if CYMBAL Script + curSQLParsePos = 0; + Pattern re = null; + Matcher matcher = null; + String extracted = null; + nextToken = getNextCYMBALSQLParseToken(sql,true); + while (nextToken.length() > 0) { + if (lastToken == null) lastToken = nextToken; + + if( lastToken.toUpperCase().startsWith("DO DISPLAY")) { + re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\] + matcher = re.matcher(nextToken); + if (matcher.find()) { + extracted = matcher.group(); + re = Pattern.compile("\\[(.*?)\\]"); + matcher = re.matcher(nextToken); + if(matcher.find()) { + extracted = matcher.group(); + extracted = extracted.substring(1,extracted.length()-1); + StringTokenizer sToken = new StringTokenizer(extracted, ","); + while(sToken.hasMoreTokens()) { + String str1 = sToken.nextToken().trim().substring(1); + updatedReportCols.add(getParseSQLDataColumn("", str1, + new StringBuffer(""), updatedReportCols, true)); + } + } + + } + + } + lastToken = nextToken; + nextToken = getNextCYMBALSQLParseToken(sql, true); + } + + } + if (updatedReportCols.size() == 0) + throw new org.onap.portalsdk.analytics.error.ValidationException( + "The SQL statement must have at least one column in the SELECT clause."); + if (getDataSourceList().getDataSource().size() == 0) + addDataSourceType(new ObjectFactory(), "du0", "DUAL", "", "DUAL", null, null, null); + DataSourceType dst = (DataSourceType) getDataSourceList().getDataSource().get(0); + dst.getDataColumnList().getDataColumn().clear(); + + for (int i = 0; i < updatedReportCols.size(); i++) { + DataColumnType dct = (DataColumnType) updatedReportCols.get(i); + dct.setTableId(dst.getTableId()); + dct.setOrderSeq(i + 1); + dst.getDataColumnList().getDataColumn().add(dct); + } // for + if(storeInSession) + setReportSQL(parsedSQL.toString()); + resetCache(false); + } // parseReportSQL + private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) { int braketCount = 0; boolean isInsideQuote = false; diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java index e5fc94ae..3281eee7 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java @@ -48,6 +48,14 @@ public class ColumnEditJSON implements WizardJSON { private String displayHeaderAlignment; private boolean sortable; private boolean visible; + private Integer displayWidth; + private Integer displayWidthInPixel; + private String colType; + private Integer groupByPos; + private Integer level; + private String dataType; + private String noWrap; + private Integer indentation; private String drilldownURL; private String drilldownParams; @@ -55,6 +63,13 @@ public class ColumnEditJSON implements WizardJSON { private String errorMessage; private String errorStackTrace; + private String depeondsOnForField; + private String subTotalCustomText; + private boolean hideRepeatedKey; + private Integer colspan; + private String displayName; + private String displayTotal; + public String getTabId() { return tabId; } @@ -133,5 +148,93 @@ public class ColumnEditJSON implements WizardJSON { public void setDrilldownType(String drilldownType) { this.drilldownType = drilldownType; } + + public Integer getDisplayWidth() { + return displayWidth; + } + public void setDisplayWidth(Integer displayWidth) { + this.displayWidth = displayWidth; + } + public Integer getDisplayWidthInPixel() { + return displayWidthInPixel; + } + public void setDisplayWidthInPixel(Integer displayWidthInPixel) { + this.displayWidthInPixel = displayWidthInPixel; + } + public Integer getGroupByPos() { + return groupByPos; + } + public void setGroupByPos(Integer groupByPos) { + this.groupByPos = groupByPos; + } + public Integer getLevel() { + return level; + } + public void setLevel(Integer level) { + this.level = level; + } + public String getDataType() { + return dataType; + } + public void setDataType(String dataType) { + this.dataType = dataType; + } + public String getNoWrap() { + return noWrap; + } + public void setNoWrap(String noWrap) { + this.noWrap = noWrap; + } + public Integer getIndentation() { + return indentation; + } + public void setIndentation(Integer indentation) { + this.indentation = indentation; + } + public String getColType() { + return colType; + } + public void setColType(String colType) { + this.colType = colType; + } + public String getDepeondsOnForField() { + return depeondsOnForField; + } + public void setDepeondsOnForField(String depeondsOnForField) { + this.depeondsOnForField = depeondsOnForField; + } + public String getSubTotalCustomText() { + return subTotalCustomText; + } + public void setSubTotalCustomText(String subTotalCustomText) { + this.subTotalCustomText = subTotalCustomText; + } + public boolean isHideRepeatedKey() { + return hideRepeatedKey; + } + public void setHideRepeatedKey(boolean hideRepeatedKey) { + this.hideRepeatedKey = hideRepeatedKey; + } + public Integer getColspan() { + return colspan; + } + public void setColspan(Integer colspan) { + this.colspan = colspan; + } + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + public String getDisplayTotal() { + return displayTotal; + } + public void setDisplayTotal(String displayTotal) { + this.displayTotal = displayTotal; + } + + + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java index 73ac97d8..47b1ef9e 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java @@ -64,7 +64,15 @@ public class DefinitionJSON implements WizardJSON { private Integer numFormCols; private String reportTitle; private String reportSubTitle; - + private String oneTimeRec; + private String hourlyRec; + private String dailyRec; + private String dailyMFRec; + private String weeklyRec; + private String monthlyRec; + private String allowScheduler; + private String sizedByContent; + private String repDefType; @Override public String getTabName() { return tabName; @@ -246,7 +254,78 @@ public class DefinitionJSON implements WizardJSON { public void setReportSubTitle(String reportSubTitle) { this.reportSubTitle = reportSubTitle; } + + public String getOneTimeRec() { + return oneTimeRec; + } + + public void setOneTimeRec(String oneTimeRec) { + this.oneTimeRec = oneTimeRec; + } + + public String getHourlyRec() { + return hourlyRec; + } + + public void setHourlyRec(String hourlyRec) { + this.hourlyRec = hourlyRec; + } + + public String getDailyRec() { + return dailyRec; + } + + public void setDailyRec(String dailyRec) { + this.dailyRec = dailyRec; + } + + public String getDailyMFRec() { + return dailyMFRec; + } + + public void setDailyMFRec(String dailyMFRec) { + this.dailyMFRec = dailyMFRec; + } + + public String getWeeklyRec() { + return weeklyRec; + } + + public void setWeeklyRec(String weeklyRec) { + this.weeklyRec = weeklyRec; + } + + public String getMonthlyRec() { + return monthlyRec; + } + + public void setMonthlyRec(String monthlyRec) { + this.monthlyRec = monthlyRec; + } + + public String getAllowScheduler() { + return allowScheduler; + } + + public void setAllowScheduler(String allowScheduler) { + this.allowScheduler = allowScheduler; + } + + public String getSizedByContent() { + return sizedByContent; + } + + public void setSizedByContent(String sizedByContent) { + this.sizedByContent = sizedByContent; + } + + public String getRepDefType() { + return repDefType; + } + + public void setRepDefType(String repDefType) { + this.repDefType = repDefType; + } - } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java index bc39006f..e8238534 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java @@ -48,6 +48,7 @@ public class FormEditJSON implements WizardJSON { private String fieldName; private String fieldType; private boolean visible; + private boolean groupFormField; private String defaultValue; private String fieldDefaultSQL; private String fieldSQL; @@ -56,7 +57,7 @@ public class FormEditJSON implements WizardJSON { private String message; private String errorMessage; private String errorStackTrace; - + private Integer orderSeq; public String getMessage() { return message; @@ -145,5 +146,19 @@ public class FormEditJSON implements WizardJSON { public void setFieldSQL(String fieldSQL) { this.fieldSQL = fieldSQL; } + public boolean isGroupFormField() { + return groupFormField; + } + public void setGroupFormField(boolean groupFormField) { + this.groupFormField = groupFormField; + } + public Integer getOrderSeq() { + return orderSeq; + } + public void setOrderSeq(Integer orderSeq) { + this.orderSeq = orderSeq; + } + + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java index b3cfe243..f80ba993 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java @@ -41,6 +41,7 @@ public class SearchFieldJSON implements ElementJSON { private String id; private String name; + private Integer orderSeq; public String getId() { return id; } @@ -53,6 +54,12 @@ public class SearchFieldJSON implements ElementJSON { public void setName(String name) { this.name = name; } + public Integer getOrderSeq() { + return orderSeq; + } + public void setOrderSeq(Integer orderSeq) { + this.orderSeq = orderSeq; + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java index cfae1ab3..5ed8f9f6 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java @@ -75,20 +75,6 @@ class PageEvent extends PdfPageEventHelper { public PageEvent(PdfBean pb) { this.pb = pb; } - - private int getWidthEntries(int howManyLogos){ - int widthEntries = 0; - - if(howManyLogos == 2) - widthEntries = 3; - else - if(howManyLogos == 1) - widthEntries = 2; - else - widthEntries = 0; - - return widthEntries; - } private int getHowManyLogos(){ int howManyLogos = 0; @@ -220,13 +206,6 @@ class PageEvent extends PdfPageEventHelper { table.addCell(new Paragraph(pb.getLeftFooter(), font)); } - private void addHeaderDummy(PdfPTable table, Font font) { - Font font1 = new Font(font); - font1.setSize(Globals.getPDFFooterFontSize()); - - table.addCell(new Paragraph("Header row", font1)); - } - private void addLogo(PdfPTable table, Font font, String imgSrc, int alignment, int absoluteSize) { Image img = null; @@ -243,7 +222,6 @@ class PageEvent extends PdfPageEventHelper { //log that the input file couldnt be loaded - } else{ - //img.scaleAbsolute(absoluteSize, absoluteSize); img.scalePercent(absoluteSize, absoluteSize); PdfPCell cell = new PdfPCell(img); cell.setBorderColor(Color.WHITE); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java index 80860912..ec83ffbf 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java @@ -47,6 +47,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -54,6 +55,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TimeZone; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,6 +70,7 @@ import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.base.ChartSeqComparator; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; import org.onap.portalsdk.analytics.util.HtmlStripper; @@ -1804,6 +1807,9 @@ public class ChartD3Helper { } wholeScript.append(" .tickFormat(function(d) { \n"); + wholeScript.append(" var local_dt = new Date(); \n var utc = d + (local_dt.getTimezoneOffset() * 60000);\n"); + wholeScript.append(" var nd = new Date(utc + (3600000*"+getCurrentTimezoneOffset()+")); "); + if(formatFlag==DAYFLAG) wholeScript.append(" return d3.time.format('%m/%d/%Y')(new Date(d)) }); \n"); else if(formatFlag==HOURFLAG) @@ -3569,6 +3575,11 @@ public class ChartD3Helper { return title; } + public java.util.Date timezoneConversion(SimpleDateFormat sdf, String dateStr) { + // sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + return sdf.parse(dateStr, new ParsePosition(0)); + } + public java.util.Date getDateFromDateStr(String dateStr) { SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00 @@ -3619,117 +3630,142 @@ public class ChartD3Helper { int flagDate = 10; */ - date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; if(date==null) { - date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(EEEMMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYOFTHEWEEKFLAG; } if(date==null) { - date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHFormat, dateStr); if(date!=null) formatFlag = HOURFLAG; } if(date==null) { - date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = timestampFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = timestampHrFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampHrFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampHrFormat, dateStr); if(date!=null) formatFlag = HOURFLAG; } if(date==null) { - date = timestampDayFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampDayFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampDayFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MONYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MONYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MONYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = MMYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMMMMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MONTHYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = MMDDYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = timestampFormat1.parse(dateStr, new ParsePosition(0)); + //date = timestampFormat1.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampFormat1, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMZFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = YYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYFormat, dateStr); /* Some random numbers should not satisfy this year format. */ if(dateStr.length()>4) date = null; if(date!=null) formatFlag = YEARFLAG; } if(date==null) { - date = timestamp_W_dash.parse(dateStr, new ParsePosition(0)); + //date = timestamp_W_dash.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestamp_W_dash, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) @@ -4085,6 +4121,23 @@ public class ChartD3Helper { return valuesMap; - } + } + + public static int getCurrentTimezoneOffset() { + + TimeZone tz = TimeZone.getDefault(); + java.util.Calendar cal = GregorianCalendar.getInstance(tz); + int offsetInMillis = tz.getOffset(cal.getTimeInMillis()); + int hourOffset = Math.abs(offsetInMillis / 3600000) * 60; + boolean isDST = tz.inDaylightTime(new java.util.Date()); + if(isDST){ + hourOffset += 60; + } + int offset = hourOffset + Math.abs((offsetInMillis / 60000) % 60); + if (offsetInMillis > 0) + offset *= -1; + + return Globals.getTimezoneOffset(); + } } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java index 529790e9..bb99318f 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java @@ -2895,6 +2895,7 @@ public List getMapMarkers(ReportData rd, org.onap.portalsdk.analytics.xmlobj.Rep reportJSONRuntime.setReportID(getReportID()); reportJSONRuntime.setReportName(getReportName()); reportJSONRuntime.setReportSubTitle(getReportSubTitle()); + reportJSONRuntime.setAllowEdit(isAllowEdit(request)); reportJSONRuntime.setNumFormCols(getNumFormColsAsInt()); ArrayList<IdNameValue> formFieldValues = new ArrayList<IdNameValue>(); ArrayList<FormFieldJSON> formFieldJSONList = new ArrayList<FormFieldJSON>(); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java index f0991e94..a1196808 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java @@ -1530,6 +1530,13 @@ public class Globals extends org.onap.portalsdk.analytics.RaptorObject { } } + public static int getTimezoneOffset() { + try { + return Integer.parseInt(nvls(raptorProperties.getProperty("time_zone_offset"), new Integer(0).toString()).trim()); + } catch (Exception ex) { return 0;} + } + + //new method added to get the help message for schedule tab public static String getScheduleHelpMessage() { return nvls(raptorProperties.getProperty("schedule_help_text"),"").trim(); 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 b2ce1b7d..e06a1765 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 @@ -66,9 +66,13 @@ import org.onap.portalsdk.analytics.error.RaptorRuntimeException; import org.onap.portalsdk.analytics.error.ReportSQLException; import org.onap.portalsdk.analytics.model.DataCache; import org.onap.portalsdk.analytics.model.ReportHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.base.IdNameList; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.base.ReportUserRole; +import org.onap.portalsdk.analytics.model.definition.DrillDownParamDef; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.ReportLogEntry; import org.onap.portalsdk.analytics.model.definition.SecurityEntry; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnEditJSON; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON; @@ -296,6 +300,20 @@ public class RaptorControllerAsync extends RestrictedBaseController { } } + @RequestMapping(value = "/report/wizard/drill_down_param/{parameter}", method = RequestMethod.GET, produces = "application/json") + public @ResponseBody List<DrillDownParamDef> getDrillDownParamDef (@PathVariable("parameter") String parameter, HttpServletRequest request, HttpServletResponse response) + throws IOException, RaptorException { + List<DrillDownParamDef> list = new ArrayList<>(); + String[] tmepArray = null; + if(parameter!=null){ + tmepArray = parameter.split("&"); + } + for(String str:tmepArray){ + list.add(new DrillDownParamDef(str)); + } + return list; + } + @RequestMapping(value = "/report/wizard/list_columns", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ArrayList<ColumnJSON> listColumns(HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException { @@ -307,7 +325,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { for (DataColumnType reportColumnType : reportColumnList) { columnJSON = new ColumnJSON(); columnJSON.setId(reportColumnType.getColId()); - columnJSON.setName(reportColumnType.getColName()); + columnJSON.setName(reportColumnType.getDisplayName()); listJSON.add(columnJSON); } return listJSON; @@ -375,6 +393,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { String fieldDisplay = fft.getFieldName(); fieldJSON.setId(fieldId); fieldJSON.setName(fieldDisplay); + fieldJSON.setOrderSeq(fft.getOrderBySeq()); listJSON.add(fieldJSON); } } @@ -501,20 +520,15 @@ public class RaptorControllerAsync extends RestrictedBaseController { fft.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL()); fft.setFieldSQL(formEditJSON.getFieldSQL()); fft.setValidationType(formEditJSON.getValidationType()); - + fft.setGroupFormField(formEditJSON.isGroupFormField()); + fft.setOrderBySeq(formEditJSON.getOrderSeq()); // clear predefined value - if (fft.getPredefinedValueList() != null) { - for (Iterator<String> iter = fft.getPredefinedValueList().getPredefinedValue() - .iterator(); iter.hasNext();) - iter.remove(); - } - + PredefinedValueList predefinedValueList = new ObjectFactory().createPredefinedValueList(); + fft.setPredefinedValueList(predefinedValueList); + List<IdNameBooleanJSON> predefList = formEditJSON.getPredefinedValueList(); if (predefList != null && predefList.size() > 0) { for (IdNameBooleanJSON item : predefList) { - PredefinedValueList predefinedValueList = new ObjectFactory() - .createPredefinedValueList(); - fft.setPredefinedValueList(predefinedValueList); fft.getPredefinedValueList().getPredefinedValue().add(item.getId()); } } @@ -540,6 +554,52 @@ public class RaptorControllerAsync extends RestrictedBaseController { return messageJSON; } + + @RequestMapping(value = "report/wizard/add_formfield_tab_data", method = RequestMethod.POST) + public @ResponseBody MessageJSON addFFTabWiseData(@RequestBody FormEditJSON formEditJSON, + HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException { + ReportDefinition rdef = null; + rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + MessageJSON messageJSON = new MessageJSON(); + try { + if (rdef != null) { + FormEditJSON wizardJSON = new FormEditJSON(); + wizardJSON.setTabId("FormEdit"); + wizardJSON.setTabName("Form Edit"); + String fieldId =""; + if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().size()==0) + fieldId = "ff1"; + else + fieldId = "ff"+(rdef.getFormFieldList().getFormField().size()+1); + FormFieldType currField = rdef.addFormFieldType(new ObjectFactory(), "", "", "", "", "", "", "", "", null, null, "",""); + currField.setFieldId(fieldId); + currField.setFieldName(formEditJSON.getFieldName()); + currField.setFieldType(formEditJSON.getFieldType()==null?null:formEditJSON.getFieldType()); + currField.setVisible(formEditJSON.isVisible()?"Y":"N"); + currField.setDefaultValue(formEditJSON.getDefaultValue()); + currField.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL()); + currField.setFieldSQL(formEditJSON.getFieldSQL()); + currField.setValidationType(formEditJSON.getValidationType()); + currField.setGroupFormField(formEditJSON.isGroupFormField()); + persistReportDefinition(request, rdef); + + messageJSON.setMessage("Success formfield Details of given report is saved in session."); + messageJSON.setAnyStacktrace(rdef.getReportID() + " is added to session and DB."); + + } else { + messageJSON.setMessage("Report Definition is not in session"); + messageJSON.setAnyStacktrace("Report Definition is not in session"); + + } + } catch (Exception ex) { + messageJSON.setMessage("Error occured while formfield details Tab"); + messageJSON.setAnyStacktrace(getStackTrace(ex)); + return messageJSON; + } + + return messageJSON; + } @RequestMapping(value = "report/wizard/save_col_tab_data", method = RequestMethod.POST) public @ResponseBody MessageJSON saveColTabWiseData(@RequestBody ColumnEditJSON columnEditJSON, @@ -558,6 +618,18 @@ public class RaptorControllerAsync extends RestrictedBaseController { // columnJSON = new ColumnJSON(); if (reportColumnType.getColId().equals(colId)) { reportColumnType.setColName(columnEditJSON.getColName()); + reportColumnType.setDependsOnFormField(columnEditJSON.getDepeondsOnForField()==null?"":columnEditJSON.getDepeondsOnForField()); + reportColumnType.setColType(columnEditJSON.getDataType()==null?"":columnEditJSON.getDataType()); + reportColumnType.setDbColName(columnEditJSON.getDataType()==null?"":columnEditJSON.getDataType()); + reportColumnType.setGroupByPos(columnEditJSON.getGroupByPos()); + reportColumnType.setSubTotalCustomText(columnEditJSON.getSubTotalCustomText()); + reportColumnType.setHideRepeatedKey(columnEditJSON.isHideRepeatedKey()); + reportColumnType.setLevel(columnEditJSON.getLevel()); + reportColumnType.setColspan(columnEditJSON.getColspan()); + reportColumnType.setDisplayName(columnEditJSON.getDisplayName()); + reportColumnType.setDisplayWidthInPxls(columnEditJSON.getDisplayWidthInPixel()==null?null:String.valueOf(columnEditJSON.getDisplayWidthInPixel())); + reportColumnType.setNowrap(columnEditJSON.getNoWrap()); + reportColumnType.setIndentation(columnEditJSON.getIndentation()); reportColumnType.setDisplayAlignment(columnEditJSON.getDisplayAlignment()); reportColumnType.setDisplayHeaderAlignment(columnEditJSON.getDisplayHeaderAlignment()); reportColumnType.setIsSortable(columnEditJSON.isSortable()); @@ -565,7 +637,9 @@ public class RaptorControllerAsync extends RestrictedBaseController { reportColumnType.setDrillDownURL(columnEditJSON.getDrilldownURL()); reportColumnType.setDrillDownParams(columnEditJSON.getDrilldownParams()); reportColumnType.setDrillDownType(columnEditJSON.getDrilldownType()); - + if(columnEditJSON.getDisplayTotal()!=null) + reportColumnType.setDisplayTotal(columnEditJSON.getDisplayTotal()); + } } @@ -650,22 +724,28 @@ public class RaptorControllerAsync extends RestrictedBaseController { rdef.setFormHelpText(formHelpText); Integer pageSize = definitionJSON.getPageSize(); - rdef.setPageSize(pageSize); + if(pageSize!=null) + rdef.setPageSize(pageSize); List<IdNameBooleanJSON> menuIds = definitionJSON.getDisplayArea(); - for (IdNameBooleanJSON menuId : menuIds) { - if (menuId.isSelected()) { - rdef.setMenuID(menuId.getName()); - } + if(menuIds!=null){ + for (IdNameBooleanJSON menuId : menuIds) { + if (menuId.isSelected()) { + rdef.setMenuID(menuId.getName()); + } + } } + Boolean hideFormFieldsAfterRun = definitionJSON.getHideFormFieldsAfterRun(); - rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun); + rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun==null?false:hideFormFieldsAfterRun); Integer maxRowsInExcelCSVDownload = definitionJSON.getMaxRowsInExcelCSVDownload(); - rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload); + if(maxRowsInExcelCSVDownload!=null) + rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload); Integer frozenColumns = definitionJSON.getFrozenColumns(); - rdef.setFrozenColumns(frozenColumns); + if(frozenColumns!=null) + rdef.setFrozenColumns(frozenColumns); String dataGridAlign = definitionJSON.getDataGridAlign(); rdef.setDataGridAlign(dataGridAlign); String emptyMessage = definitionJSON.getEmptyMessage(); @@ -674,10 +754,11 @@ public class RaptorControllerAsync extends RestrictedBaseController { rdef.setDataContainerHeight(dataContainerHeight); String dataContainerWidth = definitionJSON.getDataContainerWidth(); rdef.setDataContainerWidth(dataContainerWidth); - boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled(); - rdef.setRuntimeColSortDisabled(runtimeColSortDisabled); + Boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled(); + rdef.setRuntimeColSortDisabled(runtimeColSortDisabled==null?false:runtimeColSortDisabled); Integer numFormCols = definitionJSON.getNumFormCols(); - rdef.setNumFormCols(Integer.toString(numFormCols)); + if(numFormCols!=null) + rdef.setNumFormCols(Integer.toString(numFormCols)); String reportTitle = definitionJSON.getReportTitle(); rdef.setReportTitle(reportTitle); String reportSubTitle = definitionJSON.getReportSubTitle(); @@ -685,24 +766,45 @@ public class RaptorControllerAsync extends RestrictedBaseController { List<NameBooleanJSON> displayOptions = definitionJSON.getDisplayOptions(); StringBuffer displayOptionStr = new StringBuffer("NNNNNNN"); - for (NameBooleanJSON displayOption : displayOptions) { - if (displayOption.isSelected()) { - if (displayOption.getName().equals("HideFormFields")) { - displayOptionStr.setCharAt(0, 'Y'); - } else if (displayOption.getName().equals("HideChart")) { - displayOptionStr.setCharAt(1, 'Y'); - } else if (displayOption.getName().equals("HideReportData")) { - displayOptionStr.setCharAt(2, 'Y'); - } else if (displayOption.getName().equals("HideExcel")) { - displayOptionStr.setCharAt(5, 'Y'); - } else if (displayOption.getName().equals("HidePdf")) { - displayOptionStr.setCharAt(6, 'Y'); + if(displayOptions!=null){ + for (NameBooleanJSON displayOption : displayOptions) { + if (displayOption.isSelected()) { + if (displayOption.getName().equals("HideFormFields")) { + displayOptionStr.setCharAt(0, 'Y'); + } else if (displayOption.getName().equals("HideChart")) { + displayOptionStr.setCharAt(1, 'Y'); + } else if (displayOption.getName().equals("HideReportData")) { + displayOptionStr.setCharAt(2, 'Y'); + } else if (displayOption.getName().equals("HideExcel")) { + displayOptionStr.setCharAt(5, 'Y'); + } else if (displayOption.getName().equals("HidePdf")) { + displayOptionStr.setCharAt(6, 'Y'); + } } - } + } } - - rdef.setDisplayOptions(displayOptionStr.toString()); + + if(displayOptionStr!=null) + rdef.setDisplayOptions(displayOptionStr.toString()); + + if(definitionJSON.getAllowScheduler()!=null) + rdef.setAllowSchedule(definitionJSON.getAllowScheduler().equals("true")?"Y":"N"); + if(definitionJSON.getSizedByContent()!=null) + rdef.setSizedByContent(definitionJSON.getSizedByContent().equals("true")?"Y":"N"); + if(definitionJSON.getOneTimeRec()!=null) + rdef.setIsOneTimeScheduleAllowed(definitionJSON.getOneTimeRec().equals("true")?"Y":"N"); + if(definitionJSON.getHourlyRec()!=null) + rdef.setIsHourlyScheduleAllowed(definitionJSON.getHourlyRec().equals("true")?"Y":"N"); + if(definitionJSON.getDailyRec()!=null) + rdef.setIsDailyScheduleAllowed(definitionJSON.getDailyRec().equals("true")?"Y":"N"); + if(definitionJSON.getDailyMFRec()!=null) + rdef.setIsDailyMFScheduleAllowed(definitionJSON.getDailyMFRec().equals("true")?"Y":"N"); + if(definitionJSON.getWeeklyRec()!=null) + rdef.setIsWeeklyScheduleAllowed(definitionJSON.getWeeklyRec().equals("true")?"Y":"N"); + if(definitionJSON.getMonthlyRec()!=null) + rdef.setIsMonthlyScheduleAllowed(definitionJSON.getMonthlyRec().equals("true")?"Y":"N"); + } if (id.equals("Create")) { rdef.persistReport(request); @@ -779,7 +881,8 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setFieldDefaultSQL(fft.getFieldDefaultSQL()); wizardJSON.setFieldSQL(fft.getFieldSQL()); wizardJSON.setValidationType(fft.getValidationType()); - + wizardJSON.setGroupFormField(fft.isGroupFormField()); + wizardJSON.setOrderSeq(fft.getOrderBySeq()); PredefinedValueList preDefined = fft.getPredefinedValueList(); if (preDefined != null) { @@ -847,7 +950,20 @@ public class RaptorControllerAsync extends RestrictedBaseController { reportColumnType.getDrillDownParams() == null ? "" : reportColumnType.getDrillDownParams()); wizardJSON.setDrilldownType( reportColumnType.getDrillDownType() == null ? "" : reportColumnType.getDrillDownType()); - + wizardJSON.setDataType(reportColumnType.getDbColType() == null ? "" :reportColumnType.getDbColType()); + wizardJSON.setGroupByPos(reportColumnType.getGroupByPos()); + wizardJSON.setLevel(reportColumnType.getLevel()); + wizardJSON.setDisplayWidth(reportColumnType.getDisplayWidth()); + wizardJSON.setNoWrap(reportColumnType.getNowrap() == null ? "" : reportColumnType.getNowrap()); + wizardJSON.setIndentation(reportColumnType.getIndentation()); + + wizardJSON.setDepeondsOnForField(reportColumnType.getDependsOnFormField() ==null?"":reportColumnType.getDependsOnFormField()); + wizardJSON.setSubTotalCustomText(reportColumnType.getSubTotalCustomText()==null?"":reportColumnType.getSubTotalCustomText()); + + wizardJSON.setHideRepeatedKey(reportColumnType.isHideRepeatedKey()==null?false:reportColumnType.isHideRepeatedKey()); + wizardJSON.setColspan(reportColumnType.getColspan()==null?null:reportColumnType.getColspan()); + wizardJSON.setDisplayName(reportColumnType.getDisplayName()); + wizardJSON.setDisplayTotal(reportColumnType.getDisplayTotal()); } } } else { @@ -905,6 +1021,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { return wizardJSON; } + @RequestMapping(value = { "/report/wizard/retrieveTotalForTheColList" }, method = RequestMethod.GET) + public @ResponseBody List<IdNameValue> getTotalForTheCol(HttpServletRequest request) + throws IOException, RaptorException { + IdNameList idNameList = AppConstants.TOTAL_FUNCTIONS; + List<IdNameValue> list = new ArrayList<>(); + for(int i=0; i<idNameList.getCount(); i++) + list.add(idNameList.getValue(i)); + + return list; + } + @RequestMapping(value = { "/report/wizard/security/retrieveReportUserList" }, method = RequestMethod.GET) public @ResponseBody List<SecurityEntry> getReportUserList(HttpServletRequest request) throws IOException, RaptorException { @@ -1339,7 +1466,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setNumFormCols((rdef != null) ? rdef.getNumFormColsAsInt() : 1); wizardJSON.setReportTitle((rdef != null) ? rdef.getReportTitle() : ""); wizardJSON.setReportSubTitle((rdef != null) ? rdef.getReportSubTitle() : ""); - + + /*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.setAllowScheduler((rdef != null) ? rdef.getAllowSchedule() : "false"); + wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : "false"); + wizardJSON.setRepDefType(rdef.getReportDefType()); } ObjectMapper mapper = new ObjectMapper(); @@ -1357,7 +1494,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { RaptorResponse raptorResponse = new RaptorResponse(); String sql = queryJSON.getQuery(); String jsonInString = ""; - + ServletContext servletContext = request.getSession().getServletContext(); if (!Globals.isSystemInitialized()) { Globals.initializeSystem(servletContext); @@ -1440,7 +1577,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { QueryResultJSON queryResultJSON = new QueryResultJSON(); queryResultJSON.setQuery(queryJSON.getQuery()); String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery()); - rdef.parseReportSQL(query); + rdef.parseReportSQL(query,validate); queryResultJSON.setQuery(query); int numColumns = ds.getColumnCount(); @@ -1548,6 +1685,23 @@ public class RaptorControllerAsync extends RestrictedBaseController { return raptorResponse; } + + + @RequestMapping(value = "/report/wizard/get_report_log/{reportID}", method = RequestMethod.GET) + public @ResponseBody ArrayList<ReportLogEntry> getLogs(@PathVariable("reportID") String reportId, HttpServletRequest request, + HttpServletResponse ReportLogEntry) throws IOException { + ArrayList<ReportLogEntry> arrayList = new ArrayList<>(); + try { + Vector<ReportLogEntry> v = ReportLoader.loadReportLogEntries(reportId); + for(ReportLogEntry r:v ){ + arrayList.add(r); + } + } catch (RaptorException e) { + logger.error(EELFLoggerDelegate.errorLogger, + "RaptorControllerAsync getLogs.", e); + } + return arrayList; + } @RequestMapping(value = "save_chart", method = RequestMethod.POST) public void reportChartReceive(@RequestBody ChartJSON chartJSON, HttpServletRequest request, @@ -1627,7 +1781,12 @@ public class RaptorControllerAsync extends RestrictedBaseController { dct.setChartSeq(-1); // if we set it to -1, means this range axis will not be included else dct.setChartSeq(++r); - dct.setColOnChart("0"); + + if (!dct.getColId().equals(domainAxis)) { + dct.setColOnChart("0"); + }else{ + dct.setChartSeq(-1); + } dct.setYAxis(rangeYAxis); // +"|"+dct.getColId()); dct.setChartGroup(rangeChartGroup); // +"|"+dct.getColId()); dct.setChartColor(rangeColor); @@ -1646,7 +1805,6 @@ public class RaptorControllerAsync extends RestrictedBaseController { } } - reportRuntime.setChartLeftAxisLabel(chartJSON.getPrimaryAxisLabel()); reportRuntime.setChartRightAxisLabel(chartJSON.getSecondaryAxisLabel()); diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java new file mode 100644 index 00000000..9381f41c --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 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.controller; + +public abstract class AbstractDummyController { + +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java new file mode 100644 index 00000000..71d3a1b5 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java @@ -0,0 +1,1259 @@ +package org.onap.portalsdk.analytics.controller; +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.FilenameUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.DataCache; +import org.onap.portalsdk.analytics.model.ReportHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.SearchHandler; +import org.onap.portalsdk.analytics.model.base.IdNameColLookup; +import org.onap.portalsdk.analytics.model.base.IdNameList; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.ReportSchedule; +import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime; +import org.onap.portalsdk.analytics.model.runtime.FormField; +import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; +import org.onap.portalsdk.analytics.model.runtime.ReportJSONRuntime; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.model.runtime.VisualManager; +import org.onap.portalsdk.analytics.model.search.ReportSearchResultJSON; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.system.IAppUtils; +import org.onap.portalsdk.analytics.system.fusion.domain.QuickLink; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.Utils; +import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions; +import org.onap.portalsdk.analytics.xmlobj.CustomReportType; +import org.onap.portalsdk.analytics.xmlobj.DashboardReports; +import org.onap.portalsdk.analytics.xmlobj.DataColumnList; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; +import org.onap.portalsdk.analytics.xmlobj.DataSourceList; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormFieldList; +import org.onap.portalsdk.analytics.xmlobj.FormFieldType; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.analytics.xmlobj.Reports; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ AppUtils.class, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class, + ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class, ConnectionUtils.class, FilenameUtils.class, Utils.class, ReportRuntime.class, DataCache.class, ActionHandler.class}) +public class ActionHandlerTest { + + @InjectMocks + ActionHandler actionHandler = new ActionHandler(); + + @Mock + Connection connection; + @Mock + PreparedStatement stmt; + @Mock + ResultSet rs; + @Mock + java.sql.Clob clob; + @Mock + InputStream in; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest_WhenReportTypeIsNotEqualToDashboard() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(set.getString(Matchers.anyInt(), Matchers.any(String.class))).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration<String> enums; + Vector<String> attrs = new Vector<String>(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList<Reports>()); + String testHTML = "<table border=1><tr><td>[Report#123]</td><td>[Report#124]</td></tr><tr><td>[Report#125]</td><td>[Report#126]</td></tr></table>"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn("test"); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(rr.getDisplayContent()).thenReturn(true); + + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_VISUAL_ACTION)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(rr.isDisplayOptionHideMap()).thenReturn(true); + when(mockedRequest.getSession().getAttribute("isEmbedded")).thenReturn(true); + when(rr.isDrillDownURLInPopupPresent()).thenReturn(true); + ArrayList aL = new ArrayList<>(); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + when(rr1.getReportID()).thenReturn("test1"); + when(rr1.getReportType()).thenReturn("test"); + aL.add(rr1); + when(mockedRequest.getSession().getAttribute(AppConstants.DRILLDOWN_REPORTS_LIST)).thenReturn(aL); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_ACTION)).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_GO_BACK)).thenReturn(true); + + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunExceptionTest() { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(AppConstants.RT_DASHBOARD); + when(rr.getReportID()).thenReturn(AppConstants.RT_DASHBOARD); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration<String> enums; + Vector<String> attrs = new Vector<String>(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList<Reports>()); + String testHTML = "<table border=1><tr><td>[Report#123]</td><td>[Report#124]</td></tr><tr><td>[Report#125]</td><td>[Report#126]</td></tr></table>"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_DISPLAY_CONTENT)).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + + @SuppressWarnings("unchecked") + @Test + public void reportRunRaptorReportExceptionTest() throws Exception { + try { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration<String> enums; + Vector<String> attrs = new Vector<String>(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + }catch(Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void reportRunForCSVDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunForExcelDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.download.excel2007"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + public ReportRuntime mockReportRunTime1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + when(Globals.getReportUserAccess()).thenReturn("test"); + ResultSet rs = PowerMockito.mock(ResultSet.class); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + when(rsmd.getColumnCount()).thenReturn(1); + when(rs.getMetaData()).thenReturn(rsmd); + DataSet datset = PowerMockito.mock(DataSet.class); + // datset = new DataSet(rs); + when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); + when(Globals.getNewScheduleData()).thenReturn("test"); + CustomReportType customReportType = new CustomReportType(); + DataSourceList dataSourceList = new DataSourceList(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnTypeList.add(dataColumnType); + customReportType.setReportType("test"); + customReportType.setReportTitle("test"); + customReportType.setDataSourceList(dataSourceList); + ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); + chartAdditionalOptions.setLabelAngle("test"); + chartAdditionalOptions.setTimeSeriesRender("test"); + chartAdditionalOptions.setMultiSeries(false); + customReportType.setChartAdditionalOptions(chartAdditionalOptions); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + "1", true); + PowerMockito.mockStatic(UserUtils.class); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test12"); + ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest); + rr.setLegendLabelAngle("test"); + rr.setMultiSeries(false); + rr.setChartType("test"); + return rr; + } + + + @Test + public void reportRunTestCase1() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + @Test + public void reportDeleteTest() throws Exception { + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(AlarmSeverityEnum.class); + DataSet set = Mockito.mock(DataSet.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(Globals.getDeleteOnlyByOwner()).thenReturn(true); + when(Globals.getLogVariablesInSession()).thenReturn("test"); + HttpSession session = Mockito.mock(HttpSession.class); + when(session.getAttribute(Matchers.anyString())).thenReturn(rr); + when(session.getAttribute(Matchers.anyString())).thenReturn(rd); + assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class); + } + + + @Test + public void reportSearchTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + actionHandler.reportSearch(mockedRequest, "10"); + } + + + @Test + public void reportChartRunTest() throws Exception { + ChartWebRuntime cwr = PowerMockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest,false)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartRun(mockedRequest, "10")); + } + + @Test + public void reportSearchUserTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchUser(mockedRequest, "10")); + } + + @Test + public void reportSearchPublicTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchPublic(mockedRequest, "10")); + } + + @Test + public void reportSearchFavoritesTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchFavorites(mockedRequest, "10")); + } + + @Test + public void reportChartDataRunTest() throws Exception { + ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartDataRun(mockedRequest, "10")); + } + + + @Test + public void processScheduleDeleteTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(Globals.class); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.loadReportDefinition(mockedRequest, "test2")).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "myScheduleRepId")).thenReturn("test3"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + whenNew(ReportSchedule.class).withArguments(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)).thenReturn(rs); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + PowerMockito.doNothing().when(rs).deleteScheduleData(con); + PowerMockito.doNothing().when(DbUtils.class, "commitTransaction", new Object[]{con}); + PowerMockito.doNothing().when(DbUtils.class, "clearConnection", new Object[]{con}); + when(mockedRequest.getParameter("action")).thenReturn("report.download.excel2007"); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + PowerMockito.doNothing().when(rr).logReportExecutionTime(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)); + assertEquals(String.class, actionHandler.processScheduleDelete(mockedRequest, "10").getClass()); + } + + @Test + public void testFormFieldRun() { + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportJSONRuntime rjr = Mockito.mock(ReportJSONRuntime.class); + when(rr.createFormFieldJSONRuntime(mockedRequest)).thenReturn(rjr); + assertEquals(String.class, actionHandler.formFieldRun(mockedRequest, "10").getClass()); + } + + @Test + public void testGetReportData() throws RaptorException { + PowerMockito.mockStatic(ConnectionUtils.class); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + FormField ff = PowerMockito.mock(FormField.class); + SemaphoreType st = PowerMockito.mock(SemaphoreType.class); + FormatList fl = PowerMockito.mock(FormatList.class); + FormatType ft = PowerMockito.mock(FormatType.class); + VisualManager visualManager = PowerMockito.mock(VisualManager.class); + List<FormatType> ftList = new ArrayList<>(); + ftList.add(ft); + List<DataColumnType> dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setColId("1"); + dct.setDisplayName("testData"); + dct.setColType("DATE"); + dct.setDependsOnFormField("[testFieldDisplayName]"); + dct.setSemaphoreId("testSemaphoreId"); + dct.setColFormat("testColFormat"); + dct.setDrillDownURL("testDrillDownUrl"); + dct.setVisible(true); + dct.setDisplayWidthInPxls("testDisplayWidthInPxls"); + dct.setDisplayHeaderAlignment("testDisplayHeaderAlignment"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(rr.getReportFormFields()).thenReturn(rff); + when(rr.getDBInfo()).thenReturn("testDB"); + when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED); + when(rr.getSemaphoreById(Mockito.any())).thenReturn(st); + when(rr.getChildReportFormFields(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(rff); + when(rr.getVisualManager()).thenReturn(visualManager); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + when(rff.size()).thenReturn(1); + when(rff.getFormField(Mockito.any(Integer.class))).thenReturn(ff); + when(ff.getFieldDisplayName()).thenReturn("testFieldDisplayName"); + when(ff.getFieldName()).thenReturn("testFieldName"); + when(mockedRequest.getParameter("testFieldName")).thenReturn("testFieldValue"); + when(st.getFormatList()).thenReturn(fl); + when(st.getSemaphoreType()).thenReturn(AppConstants.ST_ROW); + when(fl.getFormat()).thenReturn(ftList); + when(ft.getLessThanValue()).thenReturn("10"); + when(visualManager.isColumnVisible(Mockito.any(String.class))).thenReturn(true); + when(visualManager.getSortByColId()).thenReturn("1"); + assertEquals(ReportData.class, actionHandler.getReportData(rr, mockedRequest, "test", 10).getClass()); + } + + @Test(expected = IOException.class) + public void testDownloadAll() throws InterruptedException, IOException, Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(FilenameUtils.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ReportRuntime.class); + when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + when(AppUtils.getUserEmail(mockedRequest)).thenReturn("test@mail.com"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, "log_id")).thenReturn("testLogID"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(Globals.getDownloadAllEmailSent()).thenReturn("testEmailSentQuery"); + when(Globals.getDownloadAllGenKey()).thenReturn("testGenerateKeyQuery"); + when(Globals.getShellScriptDir()).thenReturn("./"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(DbUtils.executeQuery(Mockito.any(String.class), Mockito.eq(1))).thenReturn(ds); + when(DbUtils.executeQuery(Mockito.any(String.class))).thenReturn(ds); + when(ds.isEmpty()).thenReturn(false); + when(ds.getString(0,"user_id")).thenReturn("testUserID"); + when(ds.getString(0,"rep_id")).thenReturn("testReportID"); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(0,0)).thenReturn("testScheduleId"); + when(FilenameUtils.normalize(Mockito.any(String.class))).thenReturn("testFile.txt"); + when(Utils.isDownloadFileExists(Mockito.any(String.class))).thenReturn(true); + when(Utils.getLatestDownloadableFile(Mockito.any(String.class))).thenReturn("testLastDownloadedFile.txt"); + List<DataColumnType> dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setDisplayName("testData"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(rr.getReportID()).thenReturn("testReportID"); + actionHandler.downloadAll(mockedRequest, "10"); + } + + @Test + public void testRunSQLPopup() throws ReportSQLException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ConnectionUtils.class); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("SELECT * FROM TEST"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_CHK_FIELD_SQL)).thenReturn("N"); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + formFieldList.getFormField().add(formFieldType); + when(rdef.getFormFieldList()).thenReturn(formFieldList); + when(rdef.getFormFieldDisplayName(formFieldType)).thenReturn("testField"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Utils.replaceInString(Mockito.any(String.class),Mockito.any(String.class),Mockito.any(String.class))).thenReturn("testString"); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + actionHandler.testRunSQLPopup(mockedRequest, "10"); + } + + @Test + public void testSchedCondPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("testSQL"); + when(Globals.getTestSchedCondPopup()).thenReturn("testQuery"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + actionHandler.testSchedCondPopup(mockedRequest, "10"); + } + + @Test + public void testReportShowSQLPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(rdef.generateSQL(Mockito.any(String.class),Mockito.any(HttpServletRequest.class))).thenReturn("testReportSQL"); + actionHandler.reportShowSQLPopup(mockedRequest, "10"); + } + + + @Test + public void testReportFilterDataPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_COLUMN_ID)).thenReturn("testColID"); + when(rdef.getDBInfo()).thenReturn(null); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(false); + IdNameColLookup lookUp = Mockito.mock(IdNameColLookup.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_COLUMN_LOOKUP)).thenReturn(lookUp); + when(lookUp.getColId()).thenReturn("testColID"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_SEARCH_STRING)).thenReturn("testSearchStr"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_CONTAIN_FLAG)).thenReturn(true); + actionHandler.reportFilterDataPopup(mockedRequest, "10"); + } + + @Test + public void testReportImportSave() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; + when(AppUtils.getRequestValue(mockedRequest, "reportXML")).thenReturn(str); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.createReportDefinition(mockedRequest, "-1", str)).thenReturn(rdef); + PowerMockito.doNothing().when(rdef).updateReportDefType(); + PowerMockito.doNothing().when(rdef).generateWizardSequence(mockedRequest); + when(rdef.getReportName()).thenReturn("test"); + PowerMockito.doNothing().when(rdef).setReportName("Import: test"); + PowerMockito.doNothing().when(rdef).clearAllDrillDowns(); + actionHandler.reportImportSave(mockedRequest, "10"); + } + + @Test + public void testProcessSchedule() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(DbUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_ACTION)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn(""); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(rs); + when(rs.getScheduleID()).thenReturn("testSchecduleID"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("testReportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(true); + when(rs.getFormFields()).thenReturn("testField"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test(expected=RuntimeException.class) + public void testProcessSchedule_WhenReportScheduleIsNull() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(null); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(""); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test + public void testReportValuesMapDefPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "colName")).thenReturn("testCol"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayName")).thenReturn("testDisplayName"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayFormat")).thenReturn("testDisplayFormat"); + when(AppUtils.getRequestNvlValue(mockedRequest, "tableId")).thenReturn("testTableId"); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(Globals.getReportValuesMapDefA()).thenReturn("testA"); + when(Globals.getReportValuesMapDefB()).thenReturn("testB"); + when(Globals.getReportValuesMapDefC()).thenReturn("testC"); + when(Globals.getReportValuesMapDefD()).thenReturn("testD"); + when(Globals.getDefaultPageSize()).thenReturn(10); + DataSourceType ds = Mockito.mock(DataSourceType.class); + when(ds.getTableName()).thenReturn("testTable"); + when(rdef.getTableById(Mockito.any(String.class))).thenReturn(ds); + DataSet data = Mockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(data); + actionHandler.reportValuesMapDefPopup(mockedRequest, "10"); + } + + @Test + public void testReportFormFieldPopup() { + PowerMockito.mockStatic(AppUtils.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", new ArrayList<>(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + when(rr.getFormField(Mockito.any(String.class))).thenReturn(formField); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + when(rr.getReportFormFields()).thenReturn(rff); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + IdNameList lookup = Mockito.mock(IdNameList.class); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_TEXTFIELD_POP)).thenReturn(true); + actionHandler.reportFormFieldPopup(mockedRequest, "10"); + } + + @Test + public void testReportCreate() throws Exception { + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(ReportDefinition.createBlank(mockedRequest)).thenReturn(rdef); + PowerMockito.doNothing().when(DataCache.class, "refreshReportTableSources", new Object[]{}); + actionHandler.reportCreate(mockedRequest, "10"); + } + + @Test + public void testRefreshCache() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration<String> enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + PowerMockito.doNothing().when(DataCache.class, "refreshAll", new Object[]{}); + IAppUtils iau = Mockito.mock(IAppUtils.class); + when(Globals.getAppUtils()).thenReturn(iau); + PowerMockito.doNothing().when(iau).resetUserCache(); + actionHandler.refreshCache(mockedRequest, "10"); + } + + @Test + public void testProcessScheduleReportListd() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + when(AppUtils.getRequestNvlValue(mockedRequest, "schedule_reports")).thenReturn("reportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(mockedRequest, null)).thenReturn(true); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(rdef.getReportID()).thenReturn("reportID"); + actionHandler.processScheduleReportList(mockedRequest, "10"); + } + + + @Test + public void testGetQuickLinksJSON() throws Exception { + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(ReportLoader.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + ArrayList<QuickLink> qList = new ArrayList<QuickLink>(); + qList.add(new QuickLink()); + when(ReportLoader.getQuickLinksJSON(Mockito.any(HttpServletRequest.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(qList); + actionHandler.getQuickLinksJSON(mockedRequest, "10"); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java new file mode 100644 index 00000000..ce883537 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ActionMappingTest { + + ActionMapping actionMapping; + Action action; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "testController"; + private String CONTROLLER_METHOD = "test"; + private String JSP_NAME = "testJsp"; + + @Before + public void init() { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + } + + @Test + public void testGetAction() { + Action localAction = (Action)actionMapping.get(ACTION); + assertEquals(ACTION, localAction.getAction()); + assertEquals(CONTROLLER_CLASS, localAction.getControllerClass()); + assertEquals(CONTROLLER_METHOD, localAction.getControllerMethod()); + assertEquals(JSP_NAME, localAction.getJspName()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java new file mode 100644 index 00000000..06fa42fe --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.analytics.controller.Action; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class ActionTest { + + Action action; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "testController"; + private String CONTROLLER_METHOD = "test"; + private String JSP_NAME = "testJsp"; + + @Before + public void init() { + action = new Action(ACTION, CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + } + + @Test + public void testNotNull() { + assertNotNull(action); + } + + @Test + public void testActionAttributes() { + assertEquals(ACTION, action.getAction()); + assertEquals(CONTROLLER_CLASS, action.getControllerClass()); + assertEquals(CONTROLLER_METHOD, action.getControllerMethod()); + assertEquals(JSP_NAME, action.getJspName()); + } + + @Test + public void testParse() { + String configFileEntry = "testAction testController test testJsp"; + Action localAction = action.parse(configFileEntry); + assertEquals(ACTION, localAction.getAction()); + assertEquals(CONTROLLER_CLASS, localAction.getControllerClass()); + assertEquals(CONTROLLER_METHOD, localAction.getControllerMethod()); + assertEquals(JSP_NAME, localAction.getJspName()); + } +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java new file mode 100644 index 00000000..0bcf8637 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java @@ -0,0 +1,262 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class}) +public class ControllerTest { + Controller controller; + String ACTION_KEY = "testAction"; + Action action; + ActionMapping actionMapping; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.DummyController"; + private String PRIVATE_CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.PrivateDummyController"; + private String ABSTRACT_CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.AbstractDummyController"; + private String CONTROLLER_METHOD = "view"; + private String JSP_NAME = "testJsp"; + private String ERROR_PAGE = "errorPage"; + private String ERROR_MESSAGE = "testErrorMessage"; + private String TEST_ID = "testID"; + private String REPORT_NAME = "testReport"; + private String REPORT_SQL = "testReportSQL"; + private String LOG_VAR_IN_SESSION = "test"; + + @Before + public void setup() { + controller = new Controller(); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void processRequestTest_WhenClassNotFoundException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, "AdminController", CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + @Test + public void processRequestTest_WhenActionIsNull() throws Exception { + actionMapping = new ActionMapping(); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + @Test + public void processRequestTest() throws Exception { + actionMapping = new ActionMapping(); + action = new Action("report.run", CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(JSP_NAME, controller.processRequest(mockedRequest)); + } + + + @Test + public void processRequestTest_WithNoSuchMethodException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, "viewHome", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void handleRequestTest() throws Exception { + actionMapping = new ActionMapping(); + action = new Action("report.run", CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + ServletContext sc= Mockito.mock(ServletContext.class); + RequestDispatcher mockedRequestDispatcher = Mockito.mock(RequestDispatcher.class); + when(sc.getRequestDispatcher(Mockito.any(String.class))).thenReturn(mockedRequestDispatcher); + Mockito.doNothing().when(mockedRequestDispatcher).forward(Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class)); + controller.handleRequest(mockedRequest, mockResponse,sc); + } + + @Test + public void processRequestTest_WithIllegalAccess() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, PRIVATE_CONTROLLER_CLASS, "", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void processRequestTest_WithInvocationTargetException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, "throwInvocationTarget", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void processRequestTest_WithInstantiationException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, ABSTRACT_CONTROLLER_CLASS, "throwInstantiation", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + + +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java new file mode 100644 index 00000000..94ec5dc9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import java.lang.reflect.InvocationTargetException; + +import javax.servlet.http.HttpServletRequest; + +class DummyController{ + public String view(HttpServletRequest request, String jspName) { + return jspName; + } + public void throwInvocationTarget(HttpServletRequest request, String jspName) throws InvocationTargetException { + throw new InvocationTargetException(null, ""); + } +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java new file mode 100644 index 00000000..6c84ce12 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java @@ -0,0 +1,191 @@ +package org.onap.portalsdk.analytics.controller; +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class}) +public class ErrorHandlerTest { + + ErrorHandler errorHandler; + private String ERROR_MESSAGE = "testErrorMessage"; + private String TEST_PAGE = "testPage"; + private String TEST_ID = "testID"; + private String REPORT_NAME = "testReport"; + private String REPORT_SQL = "testReportSQL"; + private String LOG_VAR_IN_SESSION = "test"; + + @Before + public void setup() { + errorHandler = new ErrorHandler(); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void processErrorTest() { + when(mockedRequest.getAttribute(AppConstants.RI_ERROR_LIST)).thenReturn(null); + errorHandler.processError(mockedRequest, ERROR_MESSAGE); + } + + @Test + public void processErrorRaptorExceptionTest() { + when(mockedRequest.getAttribute(AppConstants.RI_ERROR_LIST)).thenReturn(null); + RaptorException re = new RaptorException(ERROR_MESSAGE); + errorHandler.processError(mockedRequest, re); + } + + @Test + public void processFatalErrorTest_WhenReportWrapperIsNotNull() throws Exception{ + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalError(mockedRequest, rse)); + } + + @Test + public void processFatalErrorTest_WhenReportDefinitionIsNotNull() throws Exception{ + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalError(mockedRequest, rse)); + } + + @Test + public void processFatalErrorJSONTest_WhenReportWrapperIsNotNull() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + String jsonString = errorHandler.processFatalErrorJSON(mockedRequest, rse); + assertTrue(jsonString.contains(ERROR_MESSAGE)); + } + + @Test + public void processFatalErrorJSONTest_WhenReportDefinitionIsNotNull() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + String jsonString = errorHandler.processFatalErrorJSON(mockedRequest, rse); + assertTrue(jsonString.contains(ERROR_MESSAGE)); + } + + @Test + public void processFatalErrorWMenuTest_WhenReportWrapperIsNotNull() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + HttpSession session = mockedRequest.getSession(); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPageWMenu()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalErrorWMenu(mockedRequest, rse)); + } + + @Test + public void processFatalErrorWMenuTest_WhenReportDefinitionIsNotNull() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + HttpSession session = mockedRequest.getSession(); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPageWMenu()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalErrorWMenu(mockedRequest, rse)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java new file mode 100644 index 00000000..25e0b3d9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +public class PrivateDummyController { + private PrivateDummyController() {} +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java new file mode 100644 index 00000000..8b836554 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceCrossTabTest { + + WizardSequenceCrossTab wizardSequenceCrossTab; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceCrossTab = new WizardSequenceCrossTab(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceCrossTab); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceCrossTab.get(0)); + assertEquals(AppConstants.WS_TABLES,wizardSequenceCrossTab.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceCrossTab.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceCrossTab.get(3)); + assertEquals(AppConstants.WS_FILTERS, wizardSequenceCrossTab.get(4)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceCrossTab.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceCrossTab.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceCrossTab.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceCrossTab.get(8)); + } + + @Test + public void testSize() { + assertEquals(9,wizardSequenceCrossTab.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java new file mode 100644 index 00000000..f733c154 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceDashboardTest { + + WizardSequenceDashboard wizardSequenceDashboard; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceDashboard = new WizardSequenceDashboard(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceDashboard); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceDashboard.get(0)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceDashboard.get(1)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceDashboard.get(2)); + assertEquals(AppConstants.WS_RUN, wizardSequenceDashboard.get(3)); + } + + @Test + public void testSize() { + assertEquals(4, wizardSequenceDashboard.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java new file mode 100644 index 00000000..b5ae1488 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceLinearTest { + + WizardSequenceLinear wizardSequenceLinear; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceLinear = new WizardSequenceLinear(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceLinear); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceLinear.get(0)); + assertEquals(AppConstants.WS_TABLES,wizardSequenceLinear.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceLinear.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceLinear.get(3)); + assertEquals(AppConstants.WS_FILTERS, wizardSequenceLinear.get(4)); + assertEquals(AppConstants.WS_SORTING, wizardSequenceLinear.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceLinear.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceLinear.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceLinear.get(8)); + } + + @Test + public void testSize() { + assertEquals(9,wizardSequenceLinear.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java new file mode 100644 index 00000000..d4ceaff1 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedCrossTabTest { + + WizardSequenceSQLBasedCrossTab wizardSequenceSQLBasedCrossTab; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedCrossTab = new WizardSequenceSQLBasedCrossTab(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedCrossTab); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceSQLBasedCrossTab.get(0)); + assertEquals(AppConstants.WS_SQL,wizardSequenceSQLBasedCrossTab.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedCrossTab.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedCrossTab.get(3)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedCrossTab.get(4)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedCrossTab.get(5)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedCrossTab.get(6)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedCrossTab.get(7)); + } + + @Test + public void testSize() { + assertEquals(8,wizardSequenceSQLBasedCrossTab.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java new file mode 100644 index 00000000..d64738a2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedHiveTest { + + WizardSequenceSQLBasedHive wizardSequenceSQLBasedHive; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedHive = new WizardSequenceSQLBasedHive(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedHive); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceSQLBasedHive.get(0)); + assertEquals(AppConstants.WS_SQL, wizardSequenceSQLBasedHive.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedHive.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedHive.get(3)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedHive.get(4)); + assertEquals(AppConstants.WS_CHART, wizardSequenceSQLBasedHive.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedHive.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedHive.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedHive.get(8)); + } + + @Test + public void testSize() { + assertEquals(9, wizardSequenceSQLBasedHive.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java new file mode 100644 index 00000000..19c3e7e0 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedLinearDataminingTest { + + WizardSequenceSQLBasedLinearDatamining wizardSequenceSQLBasedLinearDatamining; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedLinearDatamining = new WizardSequenceSQLBasedLinearDatamining(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedLinearDatamining); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceSQLBasedLinearDatamining.get(0)); + assertEquals(AppConstants.WS_SQL, wizardSequenceSQLBasedLinearDatamining.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedLinearDatamining.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedLinearDatamining.get(3)); + assertEquals(AppConstants.WS_DATA_FORECASTING, wizardSequenceSQLBasedLinearDatamining.get(4)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedLinearDatamining.get(5)); + assertEquals(AppConstants.WS_CHART, wizardSequenceSQLBasedLinearDatamining.get(6)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedLinearDatamining.get(7)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedLinearDatamining.get(8)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedLinearDatamining.get(9)); + } + + @Test + public void testSize() { + assertEquals(10, wizardSequenceSQLBasedLinearDatamining.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java new file mode 100644 index 00000000..94d8e6b9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedLinearTest { + + WizardSequenceSQLBasedLinear wizardSequenceSQLBasedLinear; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedLinear = new WizardSequenceSQLBasedLinear(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedLinear); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceSQLBasedLinear.get(0)); + assertEquals(AppConstants.WS_SQL,wizardSequenceSQLBasedLinear.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedLinear.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedLinear.get(3)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedLinear.get(4)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedLinear.get(5)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedLinear.get(6)); + } + + @Test + public void testSize() { + assertEquals(7,wizardSequenceSQLBasedLinear.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java new file mode 100644 index 00000000..76842d05 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.controller; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.util.AppConstants; + +public class WizardSequenceTest { + WizardSequence wizardSequence; + + @Before + public void init() { + wizardSequence = new WizardSequence(); + } + + @Test + public void testPerformActionWithWABackAction() { + wizardSequence.performAction(AppConstants.WA_BACK, null); + assertEquals(1, wizardSequence.getCurrentStepIndex()); + } + + @Test + public void testPerformActionWithWAAddAction() { + wizardSequence.performAction(AppConstants.WA_ADD, null); + assertEquals(AppConstants.WA_ADD, wizardSequence.getCurrentSubStep()); + } + + + @Test + public void testPerformActionWithWANextAction() { + wizardSequence.performAction(AppConstants.WA_NEXT, null); + assertEquals("", wizardSequence.getCurrentSubStep()); + } + + @Test + public void testPerformGoToStep() { + wizardSequence.performGoToStep(AppConstants.WS_DEFINITION); + assertEquals("", wizardSequence.getCurrentSubStep()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java new file mode 100644 index 00000000..13b7fbfe --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; + +public class LineCollectionTest { + + LineCollection lineCollection; + LineInfo lineInfo; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; + + @Before + public void init() throws Exception { + lineCollection = new LineCollection(); + lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + } + + @Test + public void testGetLineCollection() { + List<LineInfo> lineInfoList = lineCollection.getLineCollection(); + assertNotNull(lineInfoList); + assertEquals(1,lineCollection.getSize()); + } + + @Test + public void testGetSelectedLine() { + Set<String> selectedLine = lineCollection.getSelectedLine(); + assertNotNull(selectedLine); + } + + @Test + public void testContainsSelectedLine() { + assertEquals(true,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testRemoveSelectedLine() { + lineCollection.removeSelectedLine(LINE_ID); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testClearAllCollection() { + lineCollection.addSelectedLine(LINE_ID); + lineCollection.clearAllCollection(); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testGetLineByLineID() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID); + assertEquals("lineID", lineInfo.getLineID()); + } + + @Test + public void testGetLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID,LINE_TYPE); + assertEquals("lineID", lineInfo.getLineID()); + assertEquals("test", lineInfo.getLineType()); + } + + @Test + public void testGetLineByNode() { + LineInfo lineInfo = lineCollection.getLine(NODE1,NODE2,true); + assertEquals("nodeID1", lineInfo.getNodeID1()); + assertEquals("nodeID2", lineInfo.getNodeID2()); + } + + @Test + public void testGetWildCardLine() { + String[] lineIDArr = lineCollection.getWildCardLine("li"); + assertEquals("lineID", lineIDArr[0]); + } + + @Test + public void testRemoveLineByLineID() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + lineCollection.addLine(lineInfo1); + assertNull(lineInfo1); + } + + @Test + public void testRemoveLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID,LINE_TYPE); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + assertNull(lineInfo1); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java new file mode 100644 index 00000000..5ff6e78b --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java @@ -0,0 +1,117 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class LineInfoTest { + + LineInfo lineInfo; + + private String NODE_ID1 = "nodeID1"; + private String NODE_ID2 = "nodeID2"; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "lineType"; + private String LINE_DESCRIPTION = "lineDescription"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + lineInfo = new LineInfo(NODE_ID1, NODE_ID2); + lineInfo.setNodeID1(NODE_ID1); + lineInfo.setNodeID2(NODE_ID2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineInfo.setDescription(LINE_DESCRIPTION); + lineInfo.setMoveable(MOVEABLE); + lineInfo.setDeleteable(DELETEABLE); + lineInfo.setState(STATE); + Map<String, String> lineAttributes = new HashMap<>(); + lineAttributes.put("x_length", "200cm"); + lineInfo.initializeAttributes(lineAttributes); + lineInfo.setAttribute("x_length", "300cm"); + } + + @Test + public void testNotNull() { + assertNotNull(lineInfo); + } + + @Test + public void testLineInfoProperties() { + assertEquals(NODE_ID1, lineInfo.getNodeID1()); + assertEquals(NODE_ID2, lineInfo.getNodeID2()); + assertEquals(LINE_ID, lineInfo.getLineID()); + assertEquals(LINE_TYPE, lineInfo.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo.getDescription()); + assertEquals(MOVEABLE, lineInfo.isMoveable()); + assertEquals(DELETEABLE, lineInfo.isDeleteable()); + assertEquals(STATE, lineInfo.getState()); + assertEquals("300cm", lineInfo.getAttribute("x_length")); + } + + @Test + public void testClone() { + LineInfo lineInfo2 = lineInfo.clone(); + assertEquals(NODE_ID1, lineInfo2.getNodeID1()); + assertEquals(NODE_ID2, lineInfo2.getNodeID2()); + assertEquals(LINE_ID, lineInfo2.getLineID()); + assertEquals(LINE_TYPE, lineInfo2.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo2.getDescription()); + assertEquals(MOVEABLE, lineInfo2.isMoveable()); + assertEquals(DELETEABLE, lineInfo2.isDeleteable()); + assertEquals(STATE, lineInfo2.getState()); + } + + @Test + public void getAttributeInternalKeys() { + List<String> list = lineInfo.getAttributeInternalKeys(); + assertEquals("length", list.get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java index c3ea5ead..dc4171ce 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java @@ -37,23 +37,55 @@ */ package org.onap.portalsdk.analytics.gmap.line; +import static org.junit.Assert.assertNotNull; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.onap.portalsdk.analytics.gmap.map.NovaMap; - +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.test.util.ReflectionTestUtils; +@RunWith(PowerMockRunner.class) +@PrepareForTest({Line.class}) public class LineTest { + Line line; + Point2D screenPoint; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; - public Line mockLineTest() - { + @Before + public void init() throws Exception{ NovaMap novaMap= new NovaMap(); novaMap.setDataLoaded("dataLoaded"); - Line line = new Line(novaMap); - return line; + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + LineCollection lineCollection = Mockito.mock(LineCollection.class); + ArrayList<LineInfo> list = new ArrayList<LineInfo>(); + LineInfo lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + list.add(lineInfo); + PowerMockito.whenNew(LineCollection.class).withNoArguments().thenReturn(lineCollection); + Mockito.when(lineCollection.getLineCollection()).thenReturn(list); + screenPoint = Mockito.mock(Point2D.class); + line = new Line(novaMap); } @Test - public void lineExistTest() - { - Line line = mockLineTest(); + public void lineExistTest(){ + assertNotNull(line); + line.lineExist(screenPoint); } } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java new file mode 100644 index 00000000..07d9a926 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.awt.Color; + +import org.junit.Before; +import org.junit.Test; + +public class ColorPropertiesTest { + + ColorProperties colorProperties; + private String TYPE = "type"; + private String COLOR = "10,10,10"; + private String SHAPE = "circle"; + private String SIZE = "100"; + private int NUMBER = 1; + + @Before + public void init() { + NovaMap map = new NovaMap(); + colorProperties = new ColorProperties(map); + colorProperties.setColor(TYPE, COLOR); + colorProperties.setShape(TYPE, SHAPE); + colorProperties.setSize(TYPE, SIZE); + colorProperties.setShape(TYPE, NUMBER, SHAPE); + } + + @Test + public void testNotNull() { + assertNotNull(colorProperties); + } + + @Test + public void testGetColor() { + Color color1 = new Color(10,10,10); + Color color2 = colorProperties.getColor(TYPE); + assertEquals(true, color1.equals(color2)); + } + + @Test + public void testGetShape() { + assertEquals(SHAPE, colorProperties.getShape(TYPE)); + } + + @Test + public void testGetShapeWithNumber() { + assertEquals(SHAPE, colorProperties.getShape(TYPE, NUMBER)); + } + + @Test + public void testGetSize() { + assertEquals(100, colorProperties.getSize(TYPE)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java new file mode 100644 index 00000000..7be34b74 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java @@ -0,0 +1,148 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.HashSet; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.layer.SwingLayer; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; + +public class NovaMapTest { + + NovaMap novaMap; + private SwingLayer swingLayer; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + } + + + @Test + public void testNotNull() { + assertNotNull(novaMap); + } + + @Test + public void testNovaMapProperties() { + assertEquals(Rectangle.class, novaMap.getBoundingBox().getClass()); + assertEquals(Node.class, novaMap.getNode().getClass()); + assertEquals(Line.class, novaMap.getLine().getClass()); + assertEquals(ColorProperties.class, novaMap.getColorProperties().getClass()); + assertEquals(10, novaMap.getZoomLevel()); + assertEquals(HashSet.class, novaMap.getShowList().getClass()); + assertEquals(SwingLayer.class, novaMap.getSwingLayers().get(0).getClass()); + assertEquals("2018/05", novaMap.getCurrentYearMonth()); + assertNotNull(novaMap.getDefaultBoundary()); + assertTrue(novaMap.isShowLegend()); + assertEquals(2, novaMap.getShowListSize()); + assertTrue(novaMap.containsShowList("test-1")); + assertTrue(novaMap.containsShowList("test-2", 10)); + novaMap.removeShowList("test-1"); + novaMap.removeShowList("test-2", 10); + novaMap.clearShowList(); + assertEquals(0, novaMap.getShowListSize()); + novaMap.removeSwingLayer(swingLayer); + novaMap.clearSwingLayers(); + assertNotEquals(null, novaMap.getTransform()); + } + + @Test + public void testGetBestZoomLevel() { + novaMap.getBestZoomLevel(13.13d, 28.28d, 23.13d, 38.28d, 10d, 10d); + } + + @Test + public void testGetPixelPos() { + novaMap.getPixelPos(13.13d, 28.28d); + } + + @Test + public void testGetLonLatFromPixel() { + novaMap.getLonLatFromPixel(10, 20); + } + + @Test + public void testGetImage() { + HttpServletRequest reuqest = Mockito.mock(HttpServletRequest.class); + novaMap.getImage(reuqest, new Rectangle2D.Double()); + } + + @Test + public void testSingleLeftClick() { + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + @Test(expected=NullPointerException.class) + public void testSingleLeftClick_WhenTransFormIsNull() { + ReflectionTestUtils.setField(novaMap, "transform", null); + Rectangle2D.Double rd =new Rectangle2D.Double(); + rd.setRect(10d, 10d, 10d, 10d); + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java new file mode 100644 index 00000000..e52d01b6 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java @@ -0,0 +1,112 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.map.layer; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; +import org.onap.portalsdk.analytics.gmap.map.NovaMap; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.springframework.test.util.ReflectionTestUtils; + +public class SwingLayerTest { + + SwingLayer swingLayer; + NovaMap novaMap; + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + Graphics2D g2d; + Graphics2D g2Legend; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + novaMap.setNode(nodeObj); + swingLayer = new SwingLayer(novaMap); + BufferedImage image = new BufferedImage(novaMap.getBoundingBox().width, novaMap.getBoundingBox().height, BufferedImage.TYPE_INT_ARGB); + g2d = image.createGraphics(); + BufferedImage legendImage = new BufferedImage(novaMap.getBoundingBox().width, (int) (20 * novaMap.getShowListSize()) + 20, + BufferedImage.TYPE_INT_ARGB); + g2Legend = legendImage.createGraphics(); + g2Legend.setBackground(Color.WHITE); + } + + @Test + public void teestPaintLayer_WhenID1NotEqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("2"); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), new Rectangle2D.Double(), g2Legend); + } + + @Test + public void teestPaintLayer_WhenID1EqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("1"); + Rectangle2D rd = new Rectangle2D.Double(); + rd.setFrame(14064d, 12366d, 10d, 10d); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), rd, g2Legend); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java new file mode 100644 index 00000000..1bd35c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java @@ -0,0 +1,122 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class NodeCollectionTest { + + NodeCollection nodeCollection; + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + + @Before + public void init() { + nodeCollection = new NodeCollection(); + NodeInfo nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeCollection.setNodeID(NODE_ID); + nodeCollection.addNode(nodeInfo); + nodeCollection.addSelectedNode(NODE_ID); + nodeCollection.addSelectedNode(NODE_ID, NODE_TYPE); + } + + @Test + public void testNotNull() { + assertNotNull(nodeCollection); + } + + @Test + public void testGetNode() { + NodeInfo nodeInfo = nodeCollection.getNode(NODE_ID+NODE_TYPE); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(NODE_ID, nodeInfo.getNodeID()); + } + + @Test + public void testContainSelectedNodeByNodeID() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testContainSelectedNodeByNodeIDAndType() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testRemoveSelectedNodeByNodeID() { + nodeCollection.removeSelectedNode(NODE_ID); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testRemoveSelectedNodeByNodeIDAndNodeType() { + nodeCollection.removeSelectedNode(NODE_ID, NODE_TYPE); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testGetNodeID() { + assertEquals(NODE_ID, nodeCollection.getNodeID()); + } + + @Test + public void testGetSelectedNode() { + assertEquals(2, nodeCollection.getSelectedNode().size()); + } + + @Test + public void testClearNode() { + nodeCollection.clearNode(); + } + + @Test + public void testClearAllCollection() { + nodeCollection.clearAllCollection(); + } + + @Test + public void testGetSize() { + nodeCollection.clearAllCollection(); + assertEquals(0, nodeCollection.getSize()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java new file mode 100644 index 00000000..bdc66784 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java @@ -0,0 +1,130 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class NodeInfoTest { + + NodeInfo nodeInfo; + + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeID(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeInfo.setMoveable(MOVEABLE); + nodeInfo.setDeleteable(DELETEABLE); + nodeInfo.setState(STATE); + List<String> lineIDs = new ArrayList<>(); + lineIDs.add("test"); + nodeInfo.setLineIDS(lineIDs); + } + + @Test + public void testNotNull() { + assertNotNull(nodeInfo); + } + + @Test + public void testNodeInfoProperties() { + assertEquals(NODE_ID, nodeInfo.getNodeID()); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(MOVEABLE, nodeInfo.isMoveable()); + assertEquals(DELETEABLE, nodeInfo.isDeleteable()); + assertEquals(STATE, nodeInfo.getState()); + } + + @Test + public void testAddLineID() { + nodeInfo.addLineID("test", "test"); + assertEquals("test>>test", nodeInfo.getLineID("test", "test")); + } + + @Test + public void testremoveLineID() { + nodeInfo.removeLineID("test", "test"); + assertEquals(null, nodeInfo.getLineID("test", "test")); + } + + @Test + public void testGetLineIDS() { + nodeInfo.getLineIDS(); + assertEquals("test", nodeInfo.getLineIDS().get(0)); + } + + @Test + public void testPrintLineIDS() { + nodeInfo.printLineIDS(); + } + + @Test + public void testCloneLineIDS() { + assertEquals("test",nodeInfo.cloneLineIDS().get(0)); + } + + @Test + public void testInitializeAttributes() { + Map<String,String >nodeAttributes = new HashMap<>(); + nodeAttributes.put("test", "test"); + nodeInfo.initializeAttributes(nodeAttributes); + assertEquals("test",nodeInfo.getAttribute("test")); + assertEquals("test",nodeInfo.getAttributeKeys().get(0)); + } + + @Test + public void testClone() { + assertEquals("test",nodeInfo.clone().cloneLineIDS().get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java index 1f7b710e..a6cd2933 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java @@ -1,5 +1,5 @@ /* - * ============LICENxSE_START========================================== + * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,13 +40,18 @@ package org.onap.portalsdk.analytics.gmap.node; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.awt.Point; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; import org.onap.portalsdk.analytics.gmap.map.NovaMap; import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; public class NodeTest { @@ -158,8 +163,12 @@ public class NodeTest { @Test public void testNodeExist() { - Node nodeObj = new Node(new NovaMap()); - + NovaMap novaMap = new NovaMap(); + novaMap.addShowList("nodeType"); + novaMap.addShowList("nodeType"); + novaMap.setColorProperties(new ColorProperties(novaMap)); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(novaMap); nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java new file mode 100644 index 00000000..a9b1bac2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java @@ -0,0 +1,328 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 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.model; + +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.pdf.PdfReportHandler; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, DbUtils.class, AppUtils.class }) +public class DataCacheTest { + @InjectMocks + DataCache dataCache = new DataCache(); + + @Before + public void init() throws Exception { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + DataSet ds; + + @SuppressWarnings("static-access") + @Test + public void getDataViewActionsTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheDataViewActions()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(1, 0)).thenReturn("test"); + dataCache.getDataViewActions(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getGroupAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheGroupAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getTheGroupAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getGroupAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void getTableSourceTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest2() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest3() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest1() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest2() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + dataCache.getReportTableJoins(vc); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest3() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest4() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java index 6a21dd10..77950ae7 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java @@ -36,11 +36,8 @@ * */ - package org.onap.portalsdk.analytics.model; - - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -52,6 +49,7 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -83,7 +81,10 @@ import org.onap.portalsdk.analytics.view.DataRow; import org.onap.portalsdk.analytics.view.DataValue; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.view.ReportDataRows; import org.onap.portalsdk.analytics.view.ReportRowHeaderCols; +import org.onap.portalsdk.analytics.view.RowHeader; +import org.onap.portalsdk.analytics.view.RowHeaderCol; import org.onap.portalsdk.analytics.xmlobj.DataColumnList; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.analytics.xmlobj.DataSourceList; @@ -98,43 +99,43 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - @RunWith(PowerMockRunner.class) -@PrepareForTest({Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class, ConnectionUtils.class}) +@PrepareForTest({ Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class, ConnectionUtils.class, + ReportLoader.class, HashMap.class }) public class ReportHandlerTest { private ReportHandler reportHandler; - + @Mock HttpServletRequest httpServletRequest; @Mock HttpServletResponse httpServletResponse; - + @Mock ServletOutputStream servletOutputStream; - + @Mock ServletContext servletContext; - + @Mock HttpSession httpSession; @Mock AppUtils appUtils; - + @Mock ReportRuntime reportRuntime; - + @Mock ReportDefinition reportDefinition; @Mock WizardSequence wizardSequence; - + @Mock Encoder encoder; - + @Mock IAppUtils iAppUtils; @@ -143,92 +144,74 @@ public class ReportHandlerTest { @Mock FileOutputStream fileOutputStream; - + @Mock PrintWriter printWriter; - + @Mock DataSourceList dataSourceList; - - @Mock + + @Mock ReportRowHeaderCols reportRowHeaderCols; - + @Mock ReportColumnHeaderRows reportColumnHeaderRows; - + @Mock + ReportDataRows reportDataRows; + @Mock Writer iowriter; - + @Mock File file; @Mock Connection connection; - + @Mock Statement statement; - + @Mock ResultSet resultSet; - + @Mock ResultSetMetaData resultSetMetaData; private String REPORT_ID = "1000"; - + @Before - public void setUp() throws Exception { - + public void setUp() throws Exception { + PowerMockito.mockStatic(DbUtils.class); PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(IAppUtils.class); PowerMockito.mockStatic(ESAPI.class); PowerMockito.mockStatic(AppUtils.class); PowerMockito.mockStatic(ConnectionUtils.class); - + PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file); - Mockito.when(file.createNewFile()).thenReturn(true); - - PowerMockito.whenNew(FileInputStream.class).withArguments(Matchers.anyString()).thenReturn(fileInputStream); - PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenReturn(fileOutputStream); + Mockito.when(file.createNewFile()).thenReturn(true); - /* - PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenAnswer( - - new Answer<FileOutputStream>() { - - @Override - public FileOutputStream answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - String string = (String)args[0]; - - System.out.println("------------------------------ callled -------------------------=============>>>>>>>>>>>>>>>> " + string); - - return fileOutputStream; - } - - - } - ); - */ + PowerMockito.whenNew(FileInputStream.class).withArguments(Matchers.anyString()).thenReturn(fileInputStream); + PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenReturn(fileOutputStream); Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime); - + Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); - + PowerMockito.when(ESAPI.encoder()).thenReturn(encoder); PowerMockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); - + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); - - //Mockito.when(appUtils.getUserID(httpServletRequest)).thenReturn("USER1"); + + // Mockito.when(appUtils.getUserID(httpServletRequest)).thenReturn("USER1"); reportHandler = Mockito.spy(ReportHandler.class); } - + @Test public void testSaveAsExcelFile_case1() { String saveOutput = ""; @@ -236,7 +219,7 @@ public class ReportHandlerTest { DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); @@ -246,19 +229,19 @@ public class ReportHandlerTest { PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + String para = ""; - - int i=1; - while(i<20) { - para = para + "<p>This is a paragraph.</p>" + "\n" + "<p>This is another paragraph.</p>" + "\n"; + + int i = 1; + while (i < 20) { + para = para + "<p>This is a paragraph.</p>" + "\n" + "<p>This is another paragraph.</p>" + "\n"; i++; } @@ -270,42 +253,27 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - //ReflectionTestUtils.setField(reportData, "reportRowHeaderCols", reportRowHeaderCols); saveOutput = reportHandler.saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); - //Assert.assertNotNull(saveOutput); - Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, + "Report 1", "Report 1 Desc"); } - - - - - @Test public void testSaveAsExcelFile_case2() throws Exception { String saveOutput = ""; ReportData reportData = prepareReportData(); DataSourceList dataSourceList = new DataSourceList(); - List<DataSourceType> listDataSourceType = dataSourceList.getDataSource(); - DataSourceType dataSourceType1 = new DataSourceType(); - DataColumnList dataColumnList1 = new DataColumnList(); - List<DataColumnType> listDataColumnType1 = dataColumnList1.getDataColumn(); - + List<DataColumnType> listDataColumnType1 = dataColumnList1.getDataColumn(); DataColumnType dataColumnType1 = new DataColumnType(); dataColumnType1.setSemaphoreId("Id1"); listDataColumnType1.add(dataColumnType1); - dataSourceType1.setDataColumnList(dataColumnList1); - listDataSourceType.add(dataSourceType1); - - reportData.setReportDataList(prepareDataRowList()); - PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); @@ -315,19 +283,19 @@ public class ReportHandlerTest { PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + String para = ""; - - int i=1; - while(i<20) { - para = para + "<p>This is a paragraph.</p>" + "\n" + "<p>This is another paragraph.</p>" + "\n"; + + int i = 1; + while (i < 20) { + para = para + "<p>This is a paragraph.</p>" + "\n" + "<p>This is another paragraph.</p>" + "\n"; i++; } @@ -339,23 +307,21 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - //ReflectionTestUtils.setField(reportData, "reportRowHeaderCols", reportRowHeaderCols); - - SemaphoreList semaphoreList = new SemaphoreList(); + SemaphoreList semaphoreList = new SemaphoreList(); List<SemaphoreType> listSemaphoreType = semaphoreList.getSemaphore(); - + SemaphoreType st1 = new SemaphoreType(); SemaphoreType st2 = new SemaphoreType(); FormatList formatList = new FormatList(); - + List<FormatType> listFormatType = formatList.getFormat(); - + FormatType formatType1 = new FormatType(); FormatType formatType2 = new FormatType(); - + listFormatType.add(formatType1); - + formatType2.setBgColor("blue"); formatType2.setFontColor("black"); formatType2.setBold(true); @@ -365,101 +331,80 @@ public class ReportHandlerTest { formatType2.setUnderline(true); formatType2.setUnderline(true); formatType2.setFontSize("20"); - + listFormatType.add(formatType2); - - + st1.setSemaphoreName("Name1"); - st1.setSemaphoreId("Id1"); - - st1.setFormatList(formatList); - + st1.setSemaphoreId("Id1"); + + st1.setFormatList(formatList); + st2.setSemaphoreName("Name2"); - st2.setSemaphoreId("Id2"); - - st2.setFormatList(formatList); - listSemaphoreType.add(st1); - listSemaphoreType.add(st2); - - mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID); - + st2.setSemaphoreId("Id2"); + + st2.setFormatList(formatList); + listSemaphoreType.add(st1); + listSemaphoreType.add(st2); + + mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList); Mockito.when(reportDefinition.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1); - - - + saveOutput = reportHandler.saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); - //Assert.assertNotNull(saveOutput); - Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, + "Report 1", "Report 1 Desc"); } - - + private ArrayList<DataRow> prepareDataRowList() { + ArrayList<DataRow> alDataRow = new ArrayList<DataRow>(); - - - - - - - - - - - - - - - private ArrayList<DataRow> prepareDataRowList(){ - ArrayList <DataRow> alDataRow = new ArrayList<DataRow>(); - DataRow dataRow = new DataRow(); - + dataRow.setRowNum(1); dataRow.setRowFormat(true); - + DataValue dataValue1 = new DataValue(); dataValue1.setColId("REPORT_ID"); dataValue1.setColName("REPORT_ID"); dataValue1.setDisplayName("REPORT ID"); - dataValue1.setVisible(true); - + dataValue1.setVisible(true); + DataValue dataValue2 = new DataValue(); dataValue2.setColId("ORDER_ID"); dataValue2.setColName("ORDER_ID"); dataValue2.setDisplayName("ORDER ID"); dataValue2.setVisible(true); - + dataRow.addDataValue(dataValue1); dataRow.addDataValue(dataValue2); - + alDataRow.add(dataRow); - + return alDataRow; } - + private ReportData prepareReportData() { - + ReportData reportData = new ReportData(1, true); reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); - + DataRow dataRow = new DataRow(); - + dataRow.setRowNum(1); dataRow.setRowFormat(true); - + reportData.addRowNumbers(1, prepareDataRowList()); - + return reportData; } - @Test public void testCreateExcelFileContent_case1() throws Exception { ReportData reportData = prepareReportData(); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); @@ -478,37 +423,38 @@ public class ReportHandlerTest { Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); - Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - } - + @Test public void testCreateExcelFileContent_case2() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -518,46 +464,37 @@ public class ReportHandlerTest { Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 1); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 1); } - @Test public void testCreateExcelFileContent_case3() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -567,54 +504,88 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - - + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); + } + + @Test + public void testCreateExcelFileContent_case4() throws Exception { + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); } - - @Test - public void testCreateExcel2007FileContent_case1() throws Exception { - - + public void testCreateExcelFileContent_case5() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -624,57 +595,1122 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - - + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test + public void testCreateExcelFileContent_case6() throws Exception { + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + private ReportData prepareReportData1() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData2() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + // value1.setColId("test"); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData3() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("date"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData4() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData5() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData6() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123"); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData7() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123."); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setDisplayValue("$Test123."); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + + private ReportData prepareReportData8() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName(null); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123"); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setBold(false); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + + @Test + public void testCreateExcelFileContent_case7() throws Exception { + ReportData reportData = prepareReportData1(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); - + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case8() throws Exception { + ReportData reportData = prepareReportData1(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case9() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case10() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$test"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case35() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("test."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + } - + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case36() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1,"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case11() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$1"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case12() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$.1"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test + public void testCreateExcel2007FileContent_case1() throws Exception { + + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + @Test public void testCreateExcel2007FileContent_case2() throws Exception { - - + ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - - Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); + Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -684,55 +1720,35 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn(REPORT_ID); - Map<String, ReportRuntime> mapReportRuntime = new TreeMap<String, ReportRuntime>(); Map<String, ReportData> mapReportData = new TreeMap<String, ReportData>(); - + mapReportRuntime.put("ReportRuntime#1", reportRuntime); mapReportData.put("ReportData#1", reportData); - - Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(mapReportRuntime); - + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)) + .thenReturn(mapReportRuntime); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(mapReportData); - + Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); Mockito.when(reportRuntime.getTemplateFile()).thenReturn(""); - + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); - - } - - - - - - - - - - - - @Test public void testCreateCSVFileContent_WithoutSql_case1() throws Exception { ReportData reportData = prepareReportData(); - + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); mockHttpAttribute("pdfAttachmentKey", "PdfKey"); @@ -743,17 +1759,16 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - ArrayList <IdNameValue> paramList = null; + + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); @@ -761,23 +1776,21 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); + + reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse); } @Test public void testCreateCSVFileContent_WithSql_case1() throws Exception { ReportData reportData = prepareReportData(); - + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); mockHttpAttribute("pdfAttachmentKey", "PdfKey"); @@ -788,15 +1801,15 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); Mockito.when(connection.createStatement()).thenReturn(statement); @@ -807,9 +1820,8 @@ public class ReportHandlerTest { Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); - - - ArrayList <IdNameValue> paramList = null; + + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); @@ -817,26 +1829,24 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); + + reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse); } - private void mockHttpAttribute(String attributeName, String attributeValue) { Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue); } - + @Test public void testCreateHTMLFileContent_WithoutSql_case1() throws Exception { - + ReportData reportData = prepareReportData(); - + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); mockHttpAttribute("pdfAttachmentKey", "PdfKey"); @@ -847,17 +1857,16 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - ArrayList <IdNameValue> paramList = null; + + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); @@ -865,26 +1874,24 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); - + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "", httpServletRequest, httpServletResponse); + + reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "", httpServletRequest, + httpServletResponse); } - - @Test(expected =RaptorException.class) + + @Test(expected = RaptorException.class) public void testCreateHTMLFileContent_WithSql_case1() throws Exception { - + ReportData reportData = prepareReportData(); - + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); mockHttpAttribute("pdfAttachmentKey", "PdfKey"); @@ -895,15 +1902,15 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); Mockito.when(connection.createStatement()).thenReturn(statement); @@ -914,8 +1921,8 @@ public class ReportHandlerTest { Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); - - ArrayList <IdNameValue> paramList = null; + + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); @@ -923,26 +1930,23 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); - + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "select column1 from table1 where column2='test'", httpServletRequest, httpServletResponse); + + reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, + "select column1 from table1 where column2='test'", httpServletRequest, httpServletResponse); } - @Test public void testCreateFlatFileContent_case1() throws IOException, Exception { ReportData reportData = prepareReportData(); - + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); mockHttpAttribute("pdfAttachmentKey", "PdfKey"); @@ -953,134 +1957,1152 @@ public class ReportHandlerTest { Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); Mockito.when(connection.createStatement()).thenReturn(statement); Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); - - ArrayList <IdNameValue> paramList = null; + ArrayList<IdNameValue> paramList = null; paramList = new ArrayList<IdNameValue>(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - Mockito.when(reportRuntime.loadReportData(Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(reportData); + Mockito.when(reportRuntime.loadReportData(Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(reportData); Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); DataColumnType dataColumnType1 = new DataColumnType(); - + dataColumnType1.setTableId("reportaccess"); dataColumnType1.setDbColName("REP_ID"); dataColumnType1.setColName("REP_ID"); dataColumnType1.setDbColType("INTEGER"); dataColumnType1.setDisplayName("Report Id"); - + DataColumnType dataColumnType2 = new DataColumnType(); - + dataColumnType2.setTableId("reportaccess"); dataColumnType2.setDbColName("ORDER_NO"); dataColumnType2.setColName("ORDER_NO"); dataColumnType2.setDbColType("INTEGER"); dataColumnType2.setDisplayName("Order No"); - + List<DataColumnType> listDataColumnType = new ArrayList<DataColumnType>(); listDataColumnType.add(dataColumnType1); listDataColumnType.add(dataColumnType2); - - Mockito.when(reportRuntime.getAllColumns()).thenReturn(listDataColumnType); - - - reportHandler.createFlatFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "USER#1"); + + Mockito.when(reportRuntime.getAllColumns()).thenReturn(listDataColumnType); + + reportHandler.createFlatFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "USER#1"); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case15() throws Exception { + ReportData reportData = prepareReportData3(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$test"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case16() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case17() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case18() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/11 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case19() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case25() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011 1:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + } - /* + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case26() throws Exception { + ReportData reportData = prepareReportData4(); - @Test + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011 1:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testSaveAsExcelFileHttpServletRequestReportDataArrayListStringStringInt() { - fail("Not yet implemented"); } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case27() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testCreateExcelFileContent() { - fail("Not yet implemented"); } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case28() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("2011/1/1"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testCreateFlatFileContent() { - fail("Not yet implemented"); } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case29() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("2011-1-1 1:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testSaveXMLFile() { - fail("Not yet implemented"); } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case30() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("111 2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testLoadReportRuntimeHttpServletRequestString() { - fail("Not yet implemented"); } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case31() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testLoadReportRuntimeHttpServletRequestStringBoolean() { - fail("Not yet implemented"); } + + + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case20() throws Exception { + ReportData reportData = prepareReportData5(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - @Test - public void testLoadReportRuntimeHttpServletRequestStringBooleanInt() { - fail("Not yet implemented"); } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case21() throws Exception { + ReportData reportData = prepareReportData6(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - @Test - public void testCreateReportDefinition() { - fail("Not yet implemented"); } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case22() throws Exception { + ReportData reportData = prepareReportData6(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - @Test - public void testLoadReportDefinition() { - fail("Not yet implemented"); } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case23() throws Exception { + ReportData reportData = prepareReportData7(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - @Test - public void testSetSheetName() { - fail("Not yet implemented"); } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case24() throws Exception { + ReportData reportData = prepareReportData8(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - @Test - public void testGetSheetName() { - fail("Not yet implemented"); } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case37() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testGetColumnCountForDownloadFile() { - fail("Not yet implemented"); } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case38() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList<IdNameValue> paramList = null; + paramList = new ArrayList<IdNameValue>(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("test,."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testCreateHTMLFileContent() { - fail("Not yet implemented"); } - */ } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java new file mode 100644 index 00000000..25b70b8b --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java @@ -0,0 +1,66 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertNotEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class ChartSeqComparatorTest { + + ChartSeqComparator chartSeqComparator; + + private Integer CHAR_SEQ = 1000; + + @Before + public void init() { + chartSeqComparator = new ChartSeqComparator(); + } + + + @Test + public void testCompare() { + DataColumnType dct1 = new DataColumnType(); + DataColumnType dct2 = new DataColumnType(); + dct1.setChartSeq(CHAR_SEQ); + dct2.setChartSeq(CHAR_SEQ); + assertNotEquals(true, chartSeqComparator.compare(dct1, dct2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java new file mode 100644 index 00000000..9269d240 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameColLookupTest { + + IdNameColLookup idNameColLookup; + + private String COL_ID = "colId"; + private String DB_TABLE_NAME = "dbTableName"; + private String DB_ID_FIELD = "dbIdField"; + private String DB_NAME_FIELD = "dbNameField"; + private String DB_SORT_BY_FIELD = "dbSortByField"; + + @Before + public void init() { + idNameColLookup = new IdNameColLookup(COL_ID, DB_TABLE_NAME, DB_ID_FIELD, DB_NAME_FIELD, DB_SORT_BY_FIELD); + } + + @Test + public void testNotNull() { + assertNotNull(idNameColLookup); + } + + @Test + public void testIdNameColLookupProperties() { + assertEquals(COL_ID, idNameColLookup.getColId()); + assertEquals(DB_TABLE_NAME, idNameColLookup.getDbTableName()); + assertEquals(DB_ID_FIELD, idNameColLookup.getDbIdField()); + assertEquals(DB_NAME_FIELD, idNameColLookup.getDbNameField()); + assertEquals(DB_SORT_BY_FIELD, idNameColLookup.getDbSortByField()); + } +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java new file mode 100644 index 00000000..cff2eb83 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class IdNameListTest { + + IdNameList idNameList; + + private String ID = "testID"; + private String NAME = "test"; + private boolean DEFAULT_VALUE = true; + private boolean READ_ONLY = true; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getFormFieldsListSize()).thenReturn(100); + idNameList = new IdNameList(); + idNameList.addValue(ID, NAME, DEFAULT_VALUE, READ_ONLY); + } + + @Test + public void testGetIdByName() { + assertEquals(ID, idNameList.getIdByName(NAME)); + } + + @Test + public void testGetNameById() { + assertEquals(NAME, idNameList.getNameById(ID)); + } + + + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java new file mode 100644 index 00000000..725d179d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameLookupTest { + + IdNameLookup idNameLookup; + + private String DB_TABLE_NAME = "dbTableName"; + private String DB_ID_FIELD = "dbIdField"; + private String DB_NAME_FIELD = "dbNameField"; + private String DB_SORT_BY_FIELD = "dbSortByField"; + private String DEFAULT_SQL = "defaultSQL"; + private boolean TEXT_FIELD = true; + + @Before + public void init() { + idNameLookup = new IdNameLookup(DB_TABLE_NAME, DB_ID_FIELD, DB_NAME_FIELD, DB_SORT_BY_FIELD, DEFAULT_SQL, TEXT_FIELD); + } + + @Test + public void testNotNull() { + assertNotNull(idNameLookup); + } + + @Test + public void testIdNameLookupProperties() { + assertEquals(DB_TABLE_NAME, idNameLookup.getDbTableName()); + assertEquals(DB_ID_FIELD, idNameLookup.getDbIdField()); + assertEquals(DB_NAME_FIELD, idNameLookup.getDbNameField()); + assertEquals(DB_SORT_BY_FIELD, idNameLookup.getDbSortByField()); + assertEquals(DEFAULT_SQL, idNameLookup.getDefaultSQL()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java new file mode 100644 index 00000000..78e8dffa --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java @@ -0,0 +1,80 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, IdNameSql.class, ConnectionUtils.class}) +public class IdNameSqlTest { + + IdNameSql idNameSql; + + @Before + public void init() { + idNameSql = new IdNameSql("select * from test", "select * from test"); + } + + @Test + public void testLoadData() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getDBType()).thenReturn("test"); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.anyString())).thenReturn("test"); + Mockito.when(Globals.getReportSqlForFormfield()).thenReturn("test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + idNameSql.loadData("select", 10, "testDB"); + } +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java new file mode 100644 index 00000000..0c798684 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java @@ -0,0 +1,69 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameValueTest { + + IdNameValue idNameValue; + + private String ID = "id"; + private String NMAE = "name"; + + @Before + public void init() { + idNameValue = new IdNameValue(ID, NMAE); + } + + @Test + public void testNotNull() { + assertNotNull(idNameValue); + } + + @Test + public void testIdNameValueProperties() { + assertEquals(ID, idNameValue.getId()); + assertEquals(NMAE, idNameValue.getName()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java new file mode 100644 index 00000000..8d9c3385 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class NameComparatorTest { + + NameComparator nameComparator; + private String NAME = "name"; + + @Before + public void init() { + nameComparator = new NameComparator(); + } + + @Test + public void testCompare() { + IdNameValue idNameValue1 = new IdNameValue(); + idNameValue1.setName(NAME); + IdNameValue idNameValue2 = new IdNameValue(); + idNameValue2.setName(NAME); + + assertEquals(0, nameComparator.compare(idNameValue1, idNameValue2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java new file mode 100644 index 00000000..cd403e7c --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class OrderBySeqComparatorTest { + + OrderBySeqComparator orderBySeqComparator; + private Integer CHAR_SEQ = 100; + + @Before + public void init() { + orderBySeqComparator = new OrderBySeqComparator(); + } + + @Test + public void testCompare() { + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setOrderBySeq(CHAR_SEQ); + DataColumnType dataColumnType2 = new DataColumnType(); + dataColumnType2.setOrderBySeq(CHAR_SEQ); + + assertEquals(0, orderBySeqComparator.compare(dataColumnType1, dataColumnType2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java new file mode 100644 index 00000000..dd6c7050 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class OrderSeqComparatorTest { + OrderSeqComparator orderSeqComparator; + private Integer CHAR_SEQ = 100; + + @Before + public void init() { + orderSeqComparator = new OrderSeqComparator(); + } + + @Test + public void testCompare() { + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setOrderSeq(CHAR_SEQ); + DataColumnType dataColumnType2 = new DataColumnType(); + dataColumnType2.setOrderSeq(CHAR_SEQ); + + assertEquals(0, orderSeqComparator.compare(dataColumnType1, dataColumnType2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java new file mode 100644 index 00000000..c8a2a97e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java @@ -0,0 +1,105 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({AppUtils.class, Globals.class, DbUtils.class}) +public class ReportSecurityTest { + + ReportSecurity reportSecurity; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Before + public void setUp() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getReportSecurity()).thenReturn("select * from test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(DbUtils.executeQuery(Mockito.anyString())).thenReturn(ds); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(Globals.getReportUserAccess()).thenReturn("select * test"); + reportSecurity = new ReportSecurity("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("USERID"); + Vector userRoles = new Vector(); + userRoles.add("test"); + Mockito.when(AppUtils.getUserRoles(Mockito.anyString())).thenReturn(userRoles); + Mockito.when(AppUtils.getUserName(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.getAdminRoleIDs()).thenReturn(userRoles); + Mockito.when(AppUtils.getUserRoles(mockedRequest)).thenReturn(userRoles); + Mockito.when(Globals.getDeleteOnlyByOwner()).thenReturn(false); + } + + @Test + public void testCheckUserReadAccess() throws RaptorException { + reportSecurity.checkUserReadAccess(mockedRequest, null); + } + + @Test + public void testCheckUserWriteAccess() throws RaptorException { + reportSecurity.checkUserWriteAccess(mockedRequest); + } + + @Test + public void testCheckUserDeleteAccess() throws RaptorException { + reportSecurity.checkUserWriteAccess(mockedRequest); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java new file mode 100644 index 00000000..19d1eddc --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportUserRoleTest { + + ReportUserRole reportUserRole; + private Long REP_ID = 1L; + private Long ORDER_NO = 2L; + private Long ROLE_ID = 3L; + private Long USER_ID = 4L; + private String READ_ONLY_YN = "Y"; + + @Before + public void init() { + reportUserRole = new ReportUserRole(REP_ID, ORDER_NO, ROLE_ID, USER_ID, READ_ONLY_YN); + } + + @Test + public void testNotNull() { + assertNotNull(reportUserRole); + } + + @Test + public void testReportUserRoleProperties() { + assertEquals(REP_ID, reportUserRole.getRepId()); + assertEquals(ORDER_NO, reportUserRole.getOrderNo()); + assertEquals(ROLE_ID, reportUserRole.getRoleId()); + assertEquals(USER_ID, reportUserRole.getUserId()); + assertEquals(READ_ONLY_YN, reportUserRole.getReadOnlyYn()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java new file mode 100644 index 00000000..c4e9d7f4 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class DBColumnInfoTest { + + DBColumnInfo dbColumnInfo; + + private String TABLE_NAME = "tableName"; + private String COL_NAME = "colName"; + private String COL_TYPE = "colType"; + private String LABEL = "label"; + + @Before + public void init() { + dbColumnInfo = new DBColumnInfo(TABLE_NAME, COL_NAME, COL_TYPE, LABEL); + } + + @Test + public void testNotNull() { + assertNotNull(dbColumnInfo); + } + + @Test + public void testDBColumnInfoProperties() { + assertEquals(TABLE_NAME, dbColumnInfo.getTableName()); + assertEquals(COL_NAME, dbColumnInfo.getColName()); + assertEquals(COL_TYPE, dbColumnInfo.getColType()); + assertEquals(LABEL, dbColumnInfo.getLabel()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java new file mode 100644 index 00000000..df1d5693 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java @@ -0,0 +1,62 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class DrillDownParamDefTest { + + DrillDownParamDef drillDownParamDef; + String DRILL_DOWN_PARAM_DEF_STR = "fieldName=[valColId!valFieldId]"; + + @Before + public void init() { + drillDownParamDef = new DrillDownParamDef(DRILL_DOWN_PARAM_DEF_STR); + } + + @Test + public void testDrillDownParamDefProperties() { + assertEquals("fieldName", drillDownParamDef.getFieldName()); + assertEquals("valColId", drillDownParamDef.getValColId()); + assertEquals("valFieldId", drillDownParamDef.getValFieldId()); + assertEquals("4", drillDownParamDef.getValType()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java new file mode 100644 index 00000000..3aa5d24e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class MarkerTest { + + Marker marker; + + private String MARKER_COLOR = "markerColor"; + private String ADDRESS_COLUMN = "addressColumn"; + private String DATA_COLUMN = "dataColumn"; + private String ADDRESS = "address"; + private String DATA = "data"; + private String COLOR = "color"; + + @Before + public void init() { + marker = new Marker(MARKER_COLOR, ADDRESS_COLUMN, DATA_COLUMN); + marker.setAddress(ADDRESS); + marker.setData(DATA); + marker.setColor(COLOR); + } + + @Test + public void testNotNull() { + assertNotNull(marker); + } + + @Test + public void testMarkerProperties() { + assertEquals(MARKER_COLOR, marker.getMarkerColor()); + assertEquals(ADDRESS_COLUMN, marker.getAddressColumn()); + assertEquals(DATA_COLUMN, marker.getDataColumn()); + assertEquals(DATA, marker.getData()); + assertEquals(COLOR, marker.getColor()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java new file mode 100644 index 00000000..d92f2565 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportLogEntryTest { + + ReportLogEntry reportlogEntry; + + private String LOGTIME = "logTime"; + private String USERNAME = "userName"; + private String ACTION = "action"; + private String TIME_TAKEN = "timeTaken"; + private String RUN_ICON = "runIcon"; + + @Before + public void init() { + reportlogEntry = new ReportLogEntry(LOGTIME, USERNAME, ACTION, TIME_TAKEN, RUN_ICON); + } + + @Test + public void testNotNull() { + assertNotNull(reportlogEntry); + } + + @Test + public void testReportLogEntryProperties() { + assertEquals(LOGTIME, reportlogEntry.getLogTime()); + assertEquals(USERNAME, reportlogEntry.getUserName()); + assertEquals(ACTION, reportlogEntry.getAction()); + assertEquals(TIME_TAKEN, reportlogEntry.getTimeTaken()); + assertEquals(RUN_ICON, reportlogEntry.getRunIcon()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java new file mode 100644 index 00000000..fcbae7bc --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportMapTest { + + ReportMap reportMap; + + private String MARKER_COLOR = "markerColor"; + private String ADDRESS_COLUMN = "addressColumn"; + private String DATA_COLUMN = "dataColumn"; + private String IS_MAP_ALLOWED_YN = "isMapAllowedYN"; + private String ADD_ADDRESS_IN_DATA_YN = "addAddressInDataYN"; + + @Before + public void init() { + reportMap = new ReportMap(MARKER_COLOR, ADDRESS_COLUMN, DATA_COLUMN, IS_MAP_ALLOWED_YN, ADD_ADDRESS_IN_DATA_YN); + } + + @Test + public void testNotNull() { + assertNotNull(reportMap); + } + + @Test + public void testReportMapProperties() { + assertEquals(MARKER_COLOR, reportMap.getMarkerColor()); + assertEquals(ADDRESS_COLUMN, reportMap.getAddressColumn()); + assertEquals(DATA_COLUMN, reportMap.getDataColumn()); + assertEquals(IS_MAP_ALLOWED_YN, reportMap.getIsMapAllowedYN()); + assertEquals(ADD_ADDRESS_IN_DATA_YN, reportMap.getAddAddressInDataYN()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java index 40ab05de..3ba80d9f 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java @@ -37,36 +37,56 @@ */ package org.onap.portalsdk.analytics.model.definition; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.FileInputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.base.IdNameValue; +import org.onap.portalsdk.analytics.model.runtime.FormField; +import org.onap.portalsdk.analytics.model.runtime.ReportParamValues; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormFieldList; +import org.onap.portalsdk.analytics.xmlobj.FormFieldType; import org.owasp.esapi.ESAPI; import org.owasp.esapi.Encoder; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import com.mchange.v2.debug.ThreadNameStackTraceRecorder; + @RunWith(PowerMockRunner.class) -@PrepareForTest({ AppUtils.class, Globals.class, DbUtils.class, AppUtils.class, ESAPI.class}) +@PrepareForTest({ AppUtils.class, Globals.class, DbUtils.class, AppUtils.class, ESAPI.class, ConnectionUtils.class, ReportSchedule.class}) public class ReportScheduleTest { @@ -116,7 +136,8 @@ public class ReportScheduleTest { PowerMockito.mockStatic(DbUtils.class); PowerMockito.mockStatic(AppUtils.class); PowerMockito.mockStatic(ESAPI.class); - + PowerMockito.mockStatic(ConnectionUtils.class); + MockitoAnnotations.initMocks(this); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime); @@ -166,7 +187,13 @@ public class ReportScheduleTest { Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyString())).thenReturn("Some Value2"); reportSchedule = new ReportSchedule(REPORT_ID, USER_ID, true, httpServletRequest); - + reportSchedule.setEncryptMode("test"); + reportSchedule.setEndAMPM("AM"); + reportSchedule.setEndHour("10"); + reportSchedule.setEndMin("00"); + reportSchedule.addZero("0"); + + /* Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyObject())).thenAnswer(new Answer<String>() { @@ -345,6 +372,353 @@ public class ReportScheduleTest { reportSchedule.persistScheduleData(connection, httpServletRequest); } + @Test + public void testPersistScheduleData_FormFieldList_case1() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("test"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn(""); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE AND [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case2() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("test"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case3() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_MIN); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [report_id] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case4() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_MIN); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [report_id] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case5() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_SEC); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("TESTDB"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + + @Test + public void testPersistScheduleData_WithRaptorException() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + String new_schedule_data = "select coalesce(max(schedule_id),0)+1 AS sequence from cr_report_schedule"; + String persist_cond_sql_set = "update cr_report_schedule set condition_sql = ? where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getPersistCondSqlSet()).thenReturn(persist_cond_sql_update); + + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + PowerMockito.when(Globals.getNewScheduleData()).thenReturn(new_schedule_data); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeUpdate()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(false); + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setStartDate("10/10/2018"); + reportSchedule.setEndDate("10/10/2019"); + reportSchedule.setRunDate("10/10/2019"); + reportSchedule.setRecurrence("Y"); + reportSchedule.addEmailToUser("UserID1", "UserName1"); + reportSchedule.addEmailToRole("roleId1", "roleName1"); + reportSchedule.setConditionSQL("SELECT coalesce(cr.owner_id, cr.create_id) owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '[Globals.getTimeFormat()]') create_date, maint_id, DATE_FORMAT(cr.maint_date, '[Globals.getTimeFormat()]') update_date, cr.menu_id, cr.menu_approved_yn FROM cr_report cr WHERE cr.rep_id= [reportID]"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + @Test public void testDeleteScheduleData_case1() throws RaptorException { @@ -416,10 +790,9 @@ public class ReportScheduleTest { ReportSchedule.loadConditionalSQL("scheduleId#123"); } - /* - @Test - public void testLoadConditionalSQL_Error_case2() throws Exception { + @Test(expected=RaptorException.class) + public void testLoadConditionalSQL_Error_case2() throws Exception { String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?"; Mockito.when(DbUtils.getConnection()).thenReturn(connection); Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); @@ -433,50 +806,73 @@ public class ReportScheduleTest { PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql); ReportSchedule.loadConditionalSQL("scheduleId#123"); - }*/ - + } - /* + @Test + public void testLoadConditionalSQL_Error_case3() throws Exception { + String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?"; + Mockito.when(DbUtils.getConnection()).thenReturn(connection); + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(Globals.isWeblogicServer()).thenReturn(false); + Mockito.when(Globals.isPostgreSQL()).thenReturn(false); + Mockito.when(Globals.isMySQL()).thenReturn(true); + + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(1)).thenThrow(new SQLException()); + PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql); + + ReportSchedule.loadConditionalSQL("scheduleId#123"); + } + @Test public void testAddEmailArrayToUser() { - fail("Not yet implemented"); + ArrayList<IdNameValue> allSelectedUsers= new ArrayList<>(); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + idNameValue.setName("test"); + idNameValue.setReadOnly(true); + idNameValue.setDefaultValue(true); + allSelectedUsers.add(idNameValue); + reportSchedule.addEmailArrayToUser(allSelectedUsers); + assertEquals("1",((IdNameValue)reportSchedule.getEmailToUsers().get(0)).getId()); } @Test public void testRemoveEmailToUser() { - fail("Not yet implemented"); + reportSchedule.removeEmailToUser("1"); } - @Test - public void testAddEmailToRole() { - fail("Not yet implemented"); - } @Test public void testAddEmailArrayToRole() { - fail("Not yet implemented"); + ArrayList<IdNameValue> allSelectedUsers= new ArrayList<>(); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("roleID1"); + idNameValue.setName("roleName1"); + idNameValue.setReadOnly(true); + idNameValue.setDefaultValue(true); + allSelectedUsers.add(idNameValue); + reportSchedule.addEmailArrayToRole(allSelectedUsers); + assertEquals("roleID1",((IdNameValue)reportSchedule.getEmailToRoles().get(0)).getId()); } - + @Test public void testRemoveEmailToRole() { - fail("Not yet implemented"); + reportSchedule.removeEmailToRole("roleID1"); } @Test - public void testPersistScheduleData() { - fail("Not yet implemented"); + public void testIsAttachmentMode() { + reportSchedule.setAttachmentMode("Y"); + assertTrue(reportSchedule.isAttachmentMode()); } @Test - public void testDeleteScheduleData() { - fail("Not yet implemented"); + public void testSetConditional() { + reportSchedule.setConditional("Y"); + assertEquals("Y",reportSchedule.getConditional()); } - - @Test - public void testLoadConditionalSQL() { - fail("Not yet implemented"); - } - */ - + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java new file mode 100644 index 00000000..156a2adf --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class SecurityEntryTest { + + SecurityEntry securityEntry; + + private String ID = "testID"; + private String NAME = "testName"; + private boolean READ_ONLY = true; + + @Before + public void init() { + securityEntry = new SecurityEntry(ID, NAME, READ_ONLY); + } + + @Test + public void testNotNull() { + assertNotNull(securityEntry); + } + + @Test + public void testTableJoinProperties() { + assertEquals(ID, securityEntry.getId()); + assertEquals(NAME, securityEntry.getName()); + assertEquals(READ_ONLY, securityEntry.isReadOnly()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java new file mode 100644 index 00000000..d7912415 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class TableJoinTest { + + TableJoin tableJoin; + + private String SRC_TABLE_NAME = "srcTableName"; + private String DEST_TABLE_NAME = "destTableName"; + private String JOIN_EXPR = "joinExpr"; + + @Before + public void init() { + tableJoin = new TableJoin(SRC_TABLE_NAME, DEST_TABLE_NAME, JOIN_EXPR); + } + + @Test + public void testNotNull() { + assertNotNull(tableJoin); + } + + @Test + public void testTableJoinProperties() { + assertEquals(SRC_TABLE_NAME, tableJoin.getSrcTableName()); + assertEquals(DEST_TABLE_NAME, tableJoin.getDestTableName()); + assertEquals(JOIN_EXPR, tableJoin.getJoinExpr()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java new file mode 100644 index 00000000..c6554c12 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class TableSourceTest { + + TableSource tableSource; + + private String TABLE_NAME = "tableName"; + private String DISPLAY_NAME = "displayName"; + private String PK_FIELDS = "pkFields"; + private String VIEW_ACTION = "viewAction"; + private String IS_LARGE_DATA = "isLargeData"; + private String FILTER_SQL = "filterSql"; + + @Before + public void init() { + tableSource = new TableSource(TABLE_NAME, DISPLAY_NAME, PK_FIELDS, VIEW_ACTION, IS_LARGE_DATA, FILTER_SQL); + } + + @Test + public void testNotNull() { + assertNotNull(tableSource); + } + + @Test + public void testTableSourceProperties() { + assertEquals(TABLE_NAME, tableSource.getTableName()); + assertEquals(DISPLAY_NAME, tableSource.getDisplayName()); + assertEquals(PK_FIELDS, tableSource.getPkFields()); + assertEquals(VIEW_ACTION, tableSource.getViewAction()); + assertEquals(IS_LARGE_DATA, tableSource.getIsLargeData()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java index 3bdb5bc1..e1f99ec0 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java new file mode 100644 index 00000000..da99f464 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition.wizard; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class MessageJSONTest { + + MessageJSON messageJSON; + private String MESSAGE = "testMessage"; + private String ANY_STACKTRACE = "testStacktrace"; + + @Before + public void init() { + messageJSON = new MessageJSON(); + messageJSON.setMessage(MESSAGE); + messageJSON.setAnyStacktrace(ANY_STACKTRACE); + } + + @Test + public void testNotNull() { + assertEquals(MESSAGE, messageJSON.getMessage()); + assertEquals(ANY_STACKTRACE, messageJSON.getAnyStacktrace()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java new file mode 100644 index 00000000..271e2d5a --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.definition.wizard; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class RaptorErrorTest { + + RaptorError raptorError1; + RaptorError raptorError2; + private String MESSAGE = "theMessage"; + private Throwable THROWABLE = new Throwable(MESSAGE); + + @Before + public void init() { + raptorError1 = new RaptorError(MESSAGE); + raptorError2 = new RaptorError(MESSAGE, THROWABLE); + } + + @Test + public void testRaptorErrorMessage() { + assertEquals(MESSAGE, raptorError1.error().get("message")); + } + + @Test + public void testRaptorErrorThrowable() { + assertEquals(THROWABLE.toString(), raptorError2.error().get("exception")); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java new file mode 100644 index 00000000..4b94657d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java @@ -0,0 +1,184 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.pdf; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.lowagie.text.Document; +import com.lowagie.text.Font; +import com.lowagie.text.Rectangle; +import com.lowagie.text.pdf.PdfContentByte; +import com.lowagie.text.pdf.PdfWriter; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, AppUtils.class, PdfReportHandler.class }) +public class PageEventTest { + + PdfBean pb = Mockito.mock(PdfBean.class); + PageEvent pageEvent = new PageEvent(pb); + @Mock + Document document; + @Mock + PdfWriter writer; + @Mock + Font font; + @Mock + PdfContentByte pdfContentByte; + + Rectangle rectangle = new Rectangle(1, 1, 1, 1); + + @Test + public void onStartPageTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn("<no logo>"); + Mockito.when(pb.getLogo2Url()).thenReturn("<no logo>"); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.RuntimeException.class) + public void onStartPage1Test() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn("test"); + Mockito.when(pb.getLogo2Url()).thenReturn("test"); + Mockito.when(AppUtils.getImgFolderURL()).thenReturn("test"); + Mockito.when(pb.getFullWebContextPath()).thenReturn("testpath"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(true); + Mockito.when(document.getPageSize()).thenReturn(rectangle); + Mockito.when(document.leftMargin()).thenReturn((float) 1.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.RuntimeException.class) + public void onStartPage2Test() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + + Mockito.when(pb.getLogo1Url()).thenReturn("<no logo>"); + Mockito.when(pb.getLogo2Url()).thenReturn("test"); + Mockito.when(AppUtils.getImgFolderURL()).thenReturn("test"); + Mockito.when(pb.getFullWebContextPath()).thenReturn("testpath"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(true); + Mockito.when(document.getPageSize()).thenReturn(rectangle); + Mockito.when(document.leftMargin()).thenReturn((float) 1.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.Exception.class) + public void onEndPageTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn("<no logo>"); + Mockito.when(pb.getLogo2Url()).thenReturn("<no logo>"); + pageEvent.onEndPage(writer, document); + } + + @Test(expected = java.lang.Exception.class) + public void onEndPage1Test() { + Rectangle rectangle1 = Mockito.mock(Rectangle.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn("<no logo>"); + Mockito.when(pb.getLogo2Url()).thenReturn("<no logo>"); + Mockito.when(pb.getTimestampPattern()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.mockStatic(PdfReportHandler.class); + Mockito.when(PdfReportHandler.currentTime(Matchers.anyString())).thenReturn("test"); + Mockito.when(document.getPageSize()).thenReturn(rectangle1); + Mockito.when(rectangle1.width()).thenReturn((float) 20); + Mockito.when(document.leftMargin()).thenReturn((float) 11.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onEndPage(writer, document); + } + + @SuppressWarnings("static-access") + @Test + public void getPageHeightTest() { + Rectangle rectangle1 = Mockito.mock(Rectangle.class); + Mockito.when(document.getPageSize()).thenReturn(rectangle1); + Mockito.when(rectangle1.width()).thenReturn((float) 20); + Mockito.when(document.leftMargin()).thenReturn((float) 11.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + pageEvent.getPageHeight(document); + } + + @Test + public void pdfbeanTest() { + PdfBean pb = new PdfBean(); + pb.setLeftFooter("leftFooter"); + assertEquals(pb.getLeftFooter(), "leftFooter"); + pb.setTitle("title"); + assertEquals(pb.getTitle(), "title"); + pb.setCurrentPage(1); + assertEquals(pb.getCurrentPage(), 1); + assertEquals(pb.getTimestampPattern(), null); + assertEquals(pb.getWhereToShowPageNumber(), 0); + assertTrue(pb.isPageNumberAtHeader()); + assertFalse(pb.isPageNumberAtFooter()); + assertEquals(pb.getLogo1Url(), null); + assertEquals(pb.getLogo2Url(), null); + assertEquals(pb.getLogo1Size(), null); + assertEquals(pb.getLogo2Size(), null); + assertEquals(pb.getFullWebContextPath(), null); + assertEquals(pb.toString(), "title 1 null null 0 false false"); + pb.setAttachmentOfEmail(false); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java new file mode 100644 index 00000000..a1db0d82 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class PdfBeanTest { + PdfBean pdfBean; + + public static final int NUMBER_IN_HEADER = 0; + public static final int NUMBER_IN_FOOTER = 1; + public static final int NUMBER_IN_BOTH = 2; + + private boolean ALTERNATE_COLOR = true; + private boolean IS_PORTRAIT = true; + private boolean IS_COVER_PAGE_INCLUDED = true; + private boolean IS_DISPLAY_CHART = true; + private int CURRENT_PAGE = 1; + private int WHERE_TO_SHOW_PAGE_NUMBER = 2; + private String USER_ID = "userID"; + private String TIMESTAMP_PATTERN = "timestampPattern"; + private String TITLE = "title"; + private String LEFT_FOOTER = "leftFooter"; + private String PAGE_SIZE = "pageSize"; + private boolean IS_ATTACHMENT_OF_EMAIL = true; + private String LOGO1_URL = "logo1Url"; + private Integer LOGO1_SIZE = 100; + private String LOGO2_URL= "logo2Url"; + private Integer LOGO2_SIZE = 200; + private String FULL_WEB_CONTEXT_PATH = "fullWebContextPath"; + + + @Before + public void init() { + pdfBean = new PdfBean(); + pdfBean.setAlternateColor(ALTERNATE_COLOR); + pdfBean.setPortrait(IS_PORTRAIT); + pdfBean.setCoverPageIncluded(IS_COVER_PAGE_INCLUDED); + pdfBean.setDisplayChart(IS_DISPLAY_CHART); + pdfBean.setCurrentPage(CURRENT_PAGE); + pdfBean.setWhereToShowPageNumber(WHERE_TO_SHOW_PAGE_NUMBER); + pdfBean.setUserId(USER_ID); + pdfBean.setTimestampPattern(TIMESTAMP_PATTERN); + pdfBean.setTitle(TITLE); + pdfBean.setLeftFooter(LEFT_FOOTER); + pdfBean.setPagesize(PAGE_SIZE); + pdfBean.setAttachmentOfEmail(IS_ATTACHMENT_OF_EMAIL); + pdfBean.setLogo1Url(LOGO1_URL); + pdfBean.setLogo1Size(LOGO1_SIZE); + pdfBean.setLogo2Url(LOGO2_URL); + pdfBean.setLogo2Size(LOGO2_SIZE); + pdfBean.setFullWebContextPath(FULL_WEB_CONTEXT_PATH); + } + + @Test + public void testPdfBeanProperties() { + assertEquals(ALTERNATE_COLOR, pdfBean.isAlternateColor()); + assertEquals(IS_PORTRAIT, pdfBean.isPortrait()); + assertEquals(IS_COVER_PAGE_INCLUDED, pdfBean.isCoverPageIncluded()); + assertEquals(IS_DISPLAY_CHART, pdfBean.isDisplayChart()); + assertEquals(CURRENT_PAGE, pdfBean.getCurrentPage()); + assertEquals(2, pdfBean.getWhereToShowPageNumber()); + assertEquals(USER_ID, pdfBean.getUserId()); + assertEquals(TIMESTAMP_PATTERN, pdfBean.getTimestampPattern()); + assertEquals(TITLE, pdfBean.getTitle()); + assertEquals(LEFT_FOOTER, pdfBean.getLeftFooter()); + assertEquals(PAGE_SIZE, pdfBean.getPagesize()); + assertEquals(IS_ATTACHMENT_OF_EMAIL, pdfBean.isAttachmentOfEmail()); + assertEquals(LOGO1_URL, pdfBean.getLogo1Url()); + assertEquals(LOGO1_SIZE, pdfBean.getLogo1Size()); + assertEquals(LOGO2_URL, pdfBean.getLogo2Url()); + assertEquals(LOGO2_SIZE, pdfBean.getLogo2Size()); + assertEquals(FULL_WEB_CONTEXT_PATH, pdfBean.getFullWebContextPath()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java new file mode 100644 index 00000000..d7422e94 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class BarChartOptionsTest { + BarChartOptions barChartOptions; + + private boolean VERTICAL_ORIENTATION = true; + private boolean STACKED_CHART = true; + private boolean DISPLAY_BAR_CONTROLS = true; + private boolean X_AXIS_DATE_TYPE = true; + private boolean MINIMIZE_X_AXIS_TICKERS = true; + private boolean TIME_AXIS = true; + private boolean Y_AXIS_LOG_SCALE = true; + + @Before + public void init() { + barChartOptions = new BarChartOptions(); + barChartOptions.setVerticalOrientation(VERTICAL_ORIENTATION); + barChartOptions.setStackedChart(STACKED_CHART); + barChartOptions.setDisplayBarControls(DISPLAY_BAR_CONTROLS); + barChartOptions.setxAxisDateType(X_AXIS_DATE_TYPE); + barChartOptions.setMinimizeXAxisTickers(MINIMIZE_X_AXIS_TICKERS); + barChartOptions.setTimeAxis(TIME_AXIS); + barChartOptions.setyAxisLogScale(Y_AXIS_LOG_SCALE); + } + + @Test + public void testBarChartOptionsProperties() { + assertEquals(VERTICAL_ORIENTATION, barChartOptions.isVerticalOrientation()); + assertEquals(STACKED_CHART, barChartOptions.isStackedChart()); + assertEquals(DISPLAY_BAR_CONTROLS, barChartOptions.isDisplayBarControls()); + assertEquals(X_AXIS_DATE_TYPE, barChartOptions.isxAxisDateType()); + assertEquals(MINIMIZE_X_AXIS_TICKERS, barChartOptions.isMinimizeXAxisTickers()); + assertEquals(TIME_AXIS, barChartOptions.isTimeAxis()); + assertEquals(Y_AXIS_LOG_SCALE, barChartOptions.isyAxisLogScale()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java new file mode 100644 index 00000000..2dce46c0 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java @@ -0,0 +1,117 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ UserUtils.class, AppUtils.class}) +public class ChartWebRuntimeTest { + ChartWebRuntime chartWebRuntime; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Before + public void init() { + chartWebRuntime = new ChartWebRuntime(); + ArrayList chartList = new ArrayList<>(); + chartList.add("test"); + ArrayList infoList = new ArrayList<>(); + infoList.add("test"); + chartWebRuntime.setChartList(chartList); + chartWebRuntime.setInfoList(infoList); + chartWebRuntime.setTotalSql("select * from test"); + } + + @Test + public void testBarChartOptionsProperties() throws RaptorException { + PowerMockito.mockStatic(UserUtils.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(mockedRequest.getParameter("action")).thenReturn("test"); + Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(10); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + Mockito.when(AppUtils.nvl(Mockito.anyString())).thenReturn("test"); + Mockito.when(mockedRequest.getParameter("refresh")).thenReturn("N"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + Mockito.when(AppUtils.getRequestNvlValue(Mockito.any(HttpServletRequest.class), Mockito.anyString())).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + Mockito.when(rr.getReportID()).thenReturn("1"); + Mockito.when(rr.getReportType()).thenReturn("Hive"); + Mockito.when(rr.getReportSQL()).thenReturn("select * from test"); + Mockito.when(rr.getLegendLabelAngle()).thenReturn("standard"); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + Mockito.when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED); + Mockito.when(rr.getReportTitle()).thenReturn("test"); + Mockito.when(mockedRequest.getParameterValues(Matchers.anyString())).thenReturn(new String[] { "test" }); + chartWebRuntime.generateChart(mockedRequest); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java new file mode 100644 index 00000000..c8bee8ec --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class CommonChartOptionsTest { + CommonChartOptions commonChartOptions; + + private String LEGEND_POSITION = "top"; + private String LEGEND_LABEL_ANGLE = "up45"; + private boolean HIDE_LEGEND = false; + private boolean ANIMATE_ANIMATED_CHART = true; + private int TOP_MARGIN = 30; + private int BOTTOM_MARGIN = 50; + private int LEFT_MARGIN = 100; + private int RIGHT_MARGIN = 60; + + @Before + public void init(){ + commonChartOptions = new CommonChartOptions(); + commonChartOptions.setLegendPosition(LEGEND_POSITION); + commonChartOptions.setLegendLabelAngle(LEGEND_LABEL_ANGLE); + commonChartOptions.setHideLegend(HIDE_LEGEND); + commonChartOptions.setAnimateAnimatedChart(ANIMATE_ANIMATED_CHART); + commonChartOptions.setTopMargin(TOP_MARGIN); + commonChartOptions.setBottomMargin(BOTTOM_MARGIN); + commonChartOptions.setLeftMargin(LEFT_MARGIN); + commonChartOptions.setRightMargin(RIGHT_MARGIN); + } + + @Test + public void testCommonChartOptionsProperties(){ + assertEquals(LEGEND_POSITION, commonChartOptions.getLegendPosition()); + assertEquals(LEGEND_LABEL_ANGLE, commonChartOptions.getLegendLabelAngle()); + assertEquals(HIDE_LEGEND, commonChartOptions.isHideLegend()); + assertEquals(ANIMATE_ANIMATED_CHART, commonChartOptions.isAnimateAnimatedChart()); + assertEquals(TOP_MARGIN, commonChartOptions.getTopMargin()); + assertEquals(BOTTOM_MARGIN, commonChartOptions.getBottomMargin()); + assertEquals(LEFT_MARGIN, commonChartOptions.getLeftMargin()); + assertEquals(RIGHT_MARGIN, commonChartOptions.getRightMargin()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java new file mode 100644 index 00000000..c5b42989 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ErrorJSONRuntimeTest { + ErrorJSONRuntime errorJSONRuntime; + + private String ERROR_MESSAGE = "testMesage"; + private String STACKTRACE = "testStacktrace"; + + @Before + public void init(){ + errorJSONRuntime = new ErrorJSONRuntime(); + errorJSONRuntime.setErrormessage(ERROR_MESSAGE); + errorJSONRuntime.setStacktrace(STACKTRACE); + } + + @Test + public void testErrorJSONRuntimeProperties(){ + assertEquals(ERROR_MESSAGE, errorJSONRuntime.getErrormessage()); + assertEquals(STACKTRACE, errorJSONRuntime.getStacktrace()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java new file mode 100644 index 00000000..85fede3e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class FlexTimeSeriesChartOptionsTest { + FlexTimeSeriesChartOptions flexTimeSeriesChartOptions; + + private int ZOOM_IN = 25; + private String TIME_AXIS_TYPE = ""; + + @Before + public void init(){ + flexTimeSeriesChartOptions = new FlexTimeSeriesChartOptions(); + flexTimeSeriesChartOptions.setZoomIn(ZOOM_IN); + flexTimeSeriesChartOptions.setTimeAxisType(TIME_AXIS_TYPE); + } + + @Test + public void testFlexTimeSeriesChartOptionsProperties(){ + assertEquals(ZOOM_IN, flexTimeSeriesChartOptions.getZoomIn()); + assertEquals(TIME_AXIS_TYPE, flexTimeSeriesChartOptions.getTimeAxisType()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java new file mode 100644 index 00000000..d89074cd --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; + +public class FormatProcessorTest { + FormatProcessor formatProcessor; + + @Before + public void init(){ + SemaphoreType semaphoreType = new SemaphoreType(); + semaphoreType.setSemaphoreName("semaphoreName"); + semaphoreType.setSemaphoreType("semaphoreType"); + semaphoreType.setComment("comment"); + semaphoreType.setTarget("target"); + FormatList formatList = new FormatList(); + FormatType formatType = new FormatType(); + formatType.setLessThanValue("lessThanValue"); + formatType.setExpression("expression"); + formatType.setBold(false); + formatType.setItalic(false); + formatType.setUnderline(false); + formatType.setBgColor("bgColor"); + formatType.setFontColor("fontColor"); + formatType.setFontFace("fontFace"); + formatType.setFontSize("fontSize"); + formatType.setAlignment("alignment"); + formatType.setComment("comment"); + formatType.setFormatId("formatId"); + formatList.getFormat().add(formatType); + semaphoreType.setFormatList(formatList); + semaphoreType.setSemaphoreId("semaphoreId"); + formatProcessor = new FormatProcessor(semaphoreType, "test", "test", true); + } + + @Test + public void testNotNull(){ + assertNotNull(formatProcessor); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java new file mode 100644 index 00000000..086b9d9d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ItemTest { + Item item; + + private String ID = "testID"; + private String NAME = "name"; + + @Before + public void init(){ + item = new Item(); + item.setId(ID); + item.setName(NAME); + } + + @Test + public void testItemProperties(){ + assertEquals(ID, item.getId()); + assertEquals(NAME, item.getName()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java new file mode 100644 index 00000000..71ad8c28 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class LookupDBInfoTest { + LookupDBInfo lookupDBInfo; + + private String TABLE_NAME = "tableName"; + private String FIELD_NAME = "fieldName"; + private String LOOKUP_TABLE = "lookupTable"; + private String LOOKUP_ID_FIELD = "lookupIdField"; + private String LOOKUP_NAME_FIELD = "lookupNameField"; + + @Before + public void init(){ + lookupDBInfo = new LookupDBInfo(TABLE_NAME, FIELD_NAME, LOOKUP_TABLE, LOOKUP_ID_FIELD, LOOKUP_NAME_FIELD); + } + + @Test + public void testItemProperties(){ + assertEquals(TABLE_NAME, lookupDBInfo.getTableName()); + assertEquals(FIELD_NAME, lookupDBInfo.getFieldName()); + assertEquals(LOOKUP_TABLE, lookupDBInfo.getLookupTable()); + assertEquals(LOOKUP_ID_FIELD, lookupDBInfo.getLookupIdField()); + assertEquals(LOOKUP_NAME_FIELD, lookupDBInfo.getLookupNameField()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java new file mode 100644 index 00000000..e0a9b371 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java @@ -0,0 +1,77 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class RangeAxisJSONTest { + RangeAxisJSON rangeAxisJSON; + + private RangeAxisLabelJSON rangeAxisLabelJSON; + private RangeColorJSON rangeColorJSON; + private RangeLineTypeJSON rangeLineTypeJSON; + private String RANGE_CHART_GROUP = "rangeChartGroup"; + private String RANGE_Y_AXIS = "rangeYAxis"; + private boolean SHOW_AS_AREA = true; + + @Before + public void init(){ + rangeAxisLabelJSON = new RangeAxisLabelJSON(); + rangeColorJSON = new RangeColorJSON(); + rangeLineTypeJSON = new RangeLineTypeJSON(); + rangeAxisJSON = new RangeAxisJSON(); + rangeAxisJSON.setRangeAxisLabelJSON(rangeAxisLabelJSON); + rangeAxisJSON.setRangeColorJSON(rangeColorJSON); + rangeAxisJSON.setRangeLineTypeJSON(rangeLineTypeJSON); + rangeAxisJSON.setRangeChartGroup(RANGE_CHART_GROUP); + rangeAxisJSON.setRangeYAxis(RANGE_Y_AXIS); + rangeAxisJSON.setShowAsArea(SHOW_AS_AREA); + } + + @Test + public void testItemProperties(){ + assertEquals(rangeAxisLabelJSON, rangeAxisJSON.getRangeAxisLabelJSON()); + assertEquals(rangeColorJSON, rangeAxisJSON.getRangeColorJSON()); + assertEquals(rangeLineTypeJSON, rangeAxisJSON.getRangeLineTypeJSON()); + assertEquals(RANGE_Y_AXIS, rangeAxisJSON.getRangeYAxis()); + assertEquals(SHOW_AS_AREA, rangeAxisJSON.isShowAsArea()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java index 07e1745b..c5010c1a 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java @@ -39,13 +39,16 @@ package org.onap.portalsdk.analytics.model.runtime; import static org.junit.Assert.assertEquals; +import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; import javax.servlet.ServletContext; @@ -71,6 +74,7 @@ import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.SecurityEntry; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON; import org.onap.portalsdk.analytics.model.definition.wizard.DefinitionJSON; import org.onap.portalsdk.analytics.system.AppUtils; @@ -104,7 +108,7 @@ import org.powermock.reflect.exceptions.MethodInvocationException; @RunWith(PowerMockRunner.class) @PrepareForTest({ AppConstants.class, Globals.class, AppUtils.class, ReportWrapper.class, DataCache.class, DbUtils.class, DataSet.class , ReportLoader.class ,ReportRuntime.class, Utils.class, ESAPI.class, - Codec.class,SecurityCodecUtil.class , ConnectionUtils.class, XSSFilter.class}) + Codec.class,SecurityCodecUtil.class , ConnectionUtils.class, XSSFilter.class, RaptorControllerAsync.class}) public class RaptorControllerAsyncTest { @InjectMocks @@ -617,4 +621,100 @@ public class RaptorControllerAsyncTest { return chartJSON; } + @Test + public void listChildReportColsTest() throws Exception { + ReportRuntime rr = Mockito.mock(ReportRuntime.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(rr); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setColName("test"); + dataColumnType.setColId("1"); + dataColumnTypeList.add(dataColumnType); + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + raptorControllerAsync.listChildReportCols("reportID", mockedRequest, mockedResponse); + } + + @Test + public void listChildReportFormFieldsTest() throws Exception { + ReportRuntime rr = Mockito.mock(ReportRuntime.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(rr); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + raptorControllerAsync.listChildReportFormFields("reportID", mockedRequest, mockedResponse); + } + + @Test + public void getReportSecurityUsersTest() throws Exception { + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Vector vc = new Vector<>(); + vc.add(new SecurityEntry("1", "test", true)); + Mockito.when(rdef.getReportUsers(mockedRequest)).thenReturn(vc); + raptorControllerAsync.getReportSecurityUsers(mockedRequest); + } + + @Test + public void getReportSecurityRolesTest() throws Exception { + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Vector vc = new Vector<>(); + vc.add(new SecurityEntry("1", "test", true)); + Mockito.when(rdef.getReportRoles(mockedRequest)).thenReturn(vc); + raptorControllerAsync.getReportSecurityRoles(mockedRequest); + } + + public ReportDefinition mockReportDefinition() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getReportUserAccess()).thenReturn("test"); + DataSet datset = PowerMockito.mock(DataSet.class); + Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); + CustomReportType customReportType = new CustomReportType(); + customReportType.setReportType("test"); + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + customReportType.setFormFieldList(formFieldList); + customReportType.setPublic(true); + customReportType.setReportType("test"); + customReportType.setReportTitle("test"); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + "1", true); + reportWrapper.setReportDefType("SQL-based"); + ReportDefinition reportDefinition = new ReportDefinition(reportWrapper, mockedRequest); + return reportDefinition; + } + @Test + public void retrieveDefTabWiseDataTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = mockReportDefinition(); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Map<String, String> pathVariables = new HashMap<>(); + pathVariables.put("id", "InSession"); + pathVariables.put("detailId", "test"); + Vector vc = new Vector<>(); + vc.add("test"); + PowerMockito.when(AppUtils.getQuickLinksMenuIDs()).thenReturn(vc); + raptorControllerAsync.retrieveDefTabWiseData(pathVariables, mockedRequest, mockedResponse); + } + + + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java new file mode 100644 index 00000000..88bcd6b9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ReportParamDateValueParserTest { + + @Test + public void testIsDateHrParam() { + assertFalse(ReportParamDateValueParser.isDateHrParam("29-MAY-2018")); + } + + @Test + public void testIsDateParam() { + assertTrue(ReportParamDateValueParser.isDateParam("29-MAY-2018")); + } + + @Test + public void testFormatDateParamValue() { + assertNotNull(ReportParamDateValueParser.formatDateParamValue("29-MAY-2018")); + } + + @Test + public void testFormatDateHrParamValue() { + assertNotNull(ReportParamDateValueParser.formatDateHrParamValue("29-MAY-2018")); + } +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java new file mode 100644 index 00000000..e9e43a7e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java @@ -0,0 +1,133 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, ESAPI.class, AppUtils.class, SecurityCodecUtil.class, ConnectionUtils.class}) +public class ReportParamValuesForPDFExcelTest { + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + ReportParamValuesForPDFExcel reportParamValuesForPDFExcel; + ReportFormFields reportFormFields; + ReportRuntime rr; + @Before + public void setUp() throws RaptorException { + rr = Mockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + reportFormFields = new ReportFormFields(rw, mockedRequest); + List predefinedValues = new ArrayList(); + FormField formField = Mockito.mock(FormField.class); + Mockito.when(formField.getFieldName()).thenReturn("fftest"); + Mockito.when(formField.getFieldDisplayName()).thenReturn("fieldDisplayName"); + Mockito.when(formField.getBaseSQLForPDFExcel()).thenReturn("select * from test"); + Mockito.when(formField.getFieldDefaultSQL()).thenReturn("select * from test"); + reportFormFields.add(formField); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(),Mockito.anyInt())).thenReturn("test"); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(),Mockito.anyString())).thenReturn(ds); + } + + @Test + public void testSetParamValues_WithCombo() throws Exception { + Mockito.when(reportFormFields.getFormField(0).getFieldType()).thenReturn(FormField.FFT_COMBO_BOX); + Mockito.when(reportFormFields.getFormField(0).getValidationType()).thenReturn(FormField.VT_TIMESTAMP_HR); + ReportParamValues params = new ReportParamValues(reportFormFields, "test"); + Mockito.when(rr.getParamKeys()).thenReturn(params.keys()); + reportParamValuesForPDFExcel = new ReportParamValuesForPDFExcel(reportFormFields, "test"); + reportParamValuesForPDFExcel.setParamValues(mockedRequest, true); + } + + @Test + public void testSetParamValues_WithCheckBox() throws Exception { + Mockito.when(reportFormFields.getFormField(0).getFieldType()).thenReturn(FormField.FFT_CHECK_BOX); + Mockito.when(reportFormFields.getFormField(0).getValidationType()).thenReturn(FormField.VT_TIMESTAMP_MIN); + ReportParamValues params = new ReportParamValues(reportFormFields, "test"); + Mockito.when(rr.getParamKeys()).thenReturn(params.keys()); + reportParamValuesForPDFExcel = new ReportParamValuesForPDFExcel(reportFormFields, "test"); + reportParamValuesForPDFExcel.setParamValues(mockedRequest, true); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java new file mode 100644 index 00000000..1d555574 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class TimeSeriesChartOptionsTest { + TimeSeriesChartOptions timeSeriesChartOptions; + + private String LINE_CHART_RENDERER = "lineChartRenderer"; + private boolean MULTI_SERIES = true; + private boolean NON_TIME_AXIS = true; + private boolean SHOW_X_AXIS_LABEL = true; + private boolean ADD_X_AXIS_TICKER = true; + + @Before + public void init() { + timeSeriesChartOptions = new TimeSeriesChartOptions(); + timeSeriesChartOptions.setLineChartRenderer(LINE_CHART_RENDERER); + timeSeriesChartOptions.setMultiSeries(MULTI_SERIES);; + timeSeriesChartOptions.setNonTimeAxis(NON_TIME_AXIS); + timeSeriesChartOptions.setShowXAxisLabel(SHOW_X_AXIS_LABEL); + timeSeriesChartOptions.setAddXAxisTicker(ADD_X_AXIS_TICKER); + } + + @Test + public void testBarChartOptionsProperties() { + assertEquals(LINE_CHART_RENDERER, timeSeriesChartOptions.getLineChartRenderer()); + assertEquals(MULTI_SERIES, timeSeriesChartOptions.isMultiSeries()); + assertEquals(NON_TIME_AXIS, timeSeriesChartOptions.isNonTimeAxis()); + assertEquals(SHOW_X_AXIS_LABEL, timeSeriesChartOptions.isShowXAxisLabel()); + assertEquals(ADD_X_AXIS_TICKER, timeSeriesChartOptions.isAddXAxisTicker()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java new file mode 100644 index 00000000..63a72c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java @@ -0,0 +1,192 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 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.util; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.IdNameValue; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class, Utils.class}) +public class UtilsTest { + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpSession session = mockedRequest.getSession(); + + @Test + public void getUsersNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInList(list, mockedRequest); + } + + @Test + public void getRolesNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInList(list, mockedRequest); + } + + @Test + public void getUsersNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInListLatest(list, mockedRequest); + } + + @Test + public void getRolesNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInListLatest(list, mockedRequest); + } + + @Test + public void isDownloadFileExistsTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.isDownloadFileExists("test"); + } + + @Test + public void getLatestDownloadableFileTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt","test1.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.getLatestDownloadableFile("test"); + } + + @Test + public void javaSafeTest() throws Exception { + Utils.javaSafe("Hel'oo world!"); + } + + @Test(expected=RuntimeException.class) + public void _assertTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getDebugLevel()).thenReturn(1); + Utils._assert(false, "errorMsg"); + } + + @Test + public void getCurrentDateTimeTest() { + Utils.getCurrentDateTime(); + } + + @Test + public void htmlEncodeTest() { + Utils.htmlEncode("<html>test</html>"); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java deleted file mode 100644 index 9abd87fe..00000000 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java +++ /dev/null @@ -1,547 +0,0 @@ -/* - * ============LICENSE_START========================================== - * ONAP Portal SDK - * =================================================================== - * Copyright © 2017 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.xmlobj; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; - -import java.io.InputStream; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.portalsdk.analytics.controller.ActionHandler; -import org.onap.portalsdk.analytics.model.ReportLoader; -import org.onap.portalsdk.analytics.model.SearchHandler; -import org.onap.portalsdk.analytics.model.base.ReportWrapper; -import org.onap.portalsdk.analytics.model.definition.ReportDefinition; -import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime; -import org.onap.portalsdk.analytics.model.runtime.FormField; -import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; -import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; -import org.onap.portalsdk.analytics.system.AppUtils; -import org.onap.portalsdk.analytics.system.DbUtils; -import org.onap.portalsdk.analytics.system.Globals; -import org.onap.portalsdk.analytics.util.AppConstants; -import org.onap.portalsdk.analytics.util.DataSet; -import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; -import org.onap.portalsdk.core.util.SecurityCodecUtil; -import org.onap.portalsdk.core.web.support.UserUtils; -import org.owasp.esapi.ESAPI; -import org.owasp.esapi.Encoder; -import org.owasp.esapi.codecs.Codec; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ AppUtils.class, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class, - ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class }) -public class ActionHandlerTest { - - @InjectMocks - ActionHandler actionHandler = new ActionHandler(); - - @Mock - Connection connection; - @Mock - PreparedStatement stmt; - @Mock - ResultSet rs; - @Mock - java.sql.Clob clob; - @Mock - InputStream in; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - - @Test - public void reportRunExceptionTest() { - when(mockedRequest.getParameter("action")).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - @SuppressWarnings("unchecked") - @Test - public void reportRunRaptorReportExceptionTest() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(ReportLoader.class); - PowerMockito.mockStatic(ReportWrapper.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mock(AppConstants.class); - PowerMockito.mockStatic(ReportDefinition.class); - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(mockedRequest.getParameter("action")).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); - when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = Mockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - when(DbUtils.getConnection()).thenReturn(connection); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); - when(rr.getReportID()).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); - when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); - String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; - when(connection.prepareStatement("1")).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(rs); - when(Globals.isWeblogicServer()).thenReturn(true); - when(rs.getClob(1)).thenReturn(clob); - when(rs.next()).thenReturn(true); - when(clob.getAsciiStream()).thenReturn(in); - when(in.read(Matchers.any())).thenReturn(1); - when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); - when(AppUtils.nvl("Y")).thenReturn("Y"); - when(AppUtils.nvl("bottom")).thenReturn("Y"); - when(AppUtils.nvl("test")).thenReturn("test|"); - when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); - when(ReportLoader.isDashboardType("-1")).thenReturn(false); - ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); - whenNew(ReportDefinition.class) - .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) - .thenReturn(rdf); - when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); - CustomReportType crType = Mockito.mock(CustomReportType.class); - when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); - when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); - when(Globals.getTimeFormat()).thenReturn("[reportID]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); - when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); - FormFieldType formFieldType = new FormFieldType(); - formFieldType.setFieldId("test"); - formFieldType.setColId("1"); - formFieldType.setFieldName("test"); - formFieldType.setFieldType("type"); - formFieldType.setValidationType("validation"); - formFieldType.setMandatory("Y"); - formFieldType.setDefaultValue("test"); - formFieldType.setGroupFormField(true); - List formFieldTypeList = new ArrayList<>(); - formFieldTypeList.add(formFieldType); - FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); - when(formFieldList.getFormField()).thenReturn(formFieldTypeList); - Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); - when(Globals.getRequestParams()).thenReturn("test,case"); - when( Globals.getSessionParams()).thenReturn("test,abc"); - when(Globals.getSessionParamsForScheduling()).thenReturn("test"); - - DataSourceList dataSourceList = new DataSourceList(); - List<DataSourceType> list = new ArrayList<>(); - DataSourceType dataSourceType = new DataSourceType(); - dataSourceType.setTableName("test"); - dataSourceType.setRefTableId("1"); - dataSourceType.setTableId("1"); - List<DataColumnType> dataColumnTypeList = new ArrayList<>(); - DataColumnType dataColumnType = new DataColumnType(); - dataColumnType.setChartGroup("test"); - dataColumnType.setYAxis("test"); - dataColumnType.setColName("[test"); - dataColumnType.setColOnChart("LEGEND"); - dataColumnType.setDisplayName("chart_total"); - dataColumnType.setColId("1"); - dataColumnType.setTableId("1"); - dataColumnType.setColType("DATE"); - dataColumnType.setCrossTabValue("ROW"); - dataColumnType.setPdfDisplayWidthInPxls("0.0"); - dataColumnType.setVisible(true); - dataColumnType.setCalculated(true); - dataColumnTypeList.add(dataColumnType); - DataColumnType dataColumnType1 = new DataColumnType(); - dataColumnType1.setCrossTabValue("COLUMN"); - dataColumnType1.setColId("1"); - dataColumnType1.setVisible(true); - dataColumnType1.setPdfDisplayWidthInPxls("1.0"); - dataColumnTypeList.add(dataColumnType1); - - DataColumnList dataColumnList = new DataColumnList(); - dataColumnList.dataColumn = dataColumnTypeList; - dataSourceType.setDataColumnList(dataColumnList); - list.add(dataSourceType); - dataSourceList.dataSource = list; - when(crType.getDataSourceList()).thenReturn(dataSourceList); - when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); - - List predefinedValues = new ArrayList<>(); - ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); - ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); - FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - - reportFormFields.add(formField); - reportFormFields.add(formField1); - reportFormFields.add(formField2); - rr.setReportFormFields(null); - rr.setReportFormFields(reportFormFields); - when(rr.getReportFormFields()).thenReturn(reportFormFields); - when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); - Enumeration<String> enums; - Vector<String> attrs = new Vector<String>(); - attrs.add("ff_test"); - enums = attrs.elements(); - when(rr.getParamKeys()).thenReturn(enums); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - - @Test - public void reportRunForCSVDownloadTest() throws Exception { - when(mockedRequest.getParameter("action")).thenReturn("test"); - when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download"); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true); - when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); - when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); - PowerMockito.mockStatic(ESAPI.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = new DataSet(); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - public ReportRuntime mockReportRunTime1() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - when(Globals.getReportUserAccess()).thenReturn("test"); - ResultSet rs = PowerMockito.mock(ResultSet.class); - ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); - when(rsmd.getColumnCount()).thenReturn(1); - when(rs.getMetaData()).thenReturn(rsmd); - DataSet datset = PowerMockito.mock(DataSet.class); - // datset = new DataSet(rs); - when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); - when(Globals.getNewScheduleData()).thenReturn("test"); - CustomReportType customReportType = new CustomReportType(); - DataSourceList dataSourceList = new DataSourceList(); - DataSourceType dataSourceType = new DataSourceType(); - dataSourceType.setTableName("test"); - dataSourceType.setRefTableId("1"); - dataSourceType.setTableId("1"); - List<DataColumnType> dataColumnTypeList = new ArrayList<>(); - DataColumnType dataColumnType = new DataColumnType(); - dataColumnType.setChartGroup("test"); - dataColumnType.setYAxis("test"); - dataColumnType.setColName("[test"); - dataColumnType.setColOnChart("LEGEND"); - dataColumnType.setDisplayName("chart_total"); - dataColumnType.setColId("1"); - dataColumnType.setTableId("1"); - dataColumnType.setColType("DATE"); - dataColumnTypeList.add(dataColumnType); - customReportType.setReportType("test"); - customReportType.setReportTitle("test"); - customReportType.setDataSourceList(dataSourceList); - ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); - chartAdditionalOptions.setLabelAngle("test"); - chartAdditionalOptions.setTimeSeriesRender("test"); - chartAdditionalOptions.setMultiSeries(false); - customReportType.setChartAdditionalOptions(chartAdditionalOptions); - ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", - "1", true); - PowerMockito.mockStatic(UserUtils.class); - when(Globals.getRequestParams()).thenReturn("test"); - when(Globals.getSessionParams()).thenReturn("test"); - when(Globals.getSessionParamsForScheduling()).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test12"); - ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest); - rr.setLegendLabelAngle("test"); - rr.setMultiSeries(false); - rr.setChartType("test"); - return rr; - } - - - @Test - public void reportRunTestCase1() throws Exception { - when(mockedRequest.getParameter("action")).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - - PowerMockito.mockStatic(ESAPI.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = PowerMockito.mock(DataSet.class); - when(set.isEmpty()).thenReturn(false); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); - PowerMockito.mockStatic(ReportLoader.class); - when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - - @Test - public void reportDeleteTest() throws Exception { - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(AlarmSeverityEnum.class); - DataSet set = Mockito.mock(DataSet.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1"); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(Globals.getDeleteOnlyByOwner()).thenReturn(true); - when(Globals.getLogVariablesInSession()).thenReturn("test"); - HttpSession session = Mockito.mock(HttpSession.class); - when(session.getAttribute(Matchers.anyString())).thenReturn(rr); - when(session.getAttribute(Matchers.anyString())).thenReturn(rd); - assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class); - } - - - @Test - public void reportSearchTest() throws Exception { - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - when(AppUtils.getImgFolderURL()).thenReturn("test"); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_ID)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_NAME)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SORT_ORDER)).thenReturn("f_owner_id"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_LIST_CATEGORY)).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_USER_REPORTS)).thenReturn(true); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_PUBLIC_REPORTS)).thenReturn(true); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_FAVORITE_REPORTS)).thenReturn(true); - when(AppUtils.nvl(Matchers.anyString())).thenReturn("te"); - when(Globals.getLoadReportSearchResult()).thenReturn("test"); - when(Globals.getLoadReportSearchRepIdSql()).thenReturn("test"); - when(Globals.getLoadReportSearchInstr()).thenReturn("test"); - when(Globals.getLoadReportSearchResultUser()).thenReturn("test"); - when(Globals.getLoadReportSearchResultPublic()).thenReturn("test"); - when(Globals.getLoadReportSearchResultFav()).thenReturn("test"); - when(Globals.getLoadReportSearchResultSort()).thenReturn("test"); - when(AppUtils.getRequestNvlValue(mockedRequest, "r_page")).thenReturn("10"); - Vector<String> vc = new Vector<>(); - vc.add("test"); - vc.add("test2"); - when(AppUtils.getUserRoles(mockedRequest)).thenReturn(vc); - when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); - DataSet set = Mockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - Enumeration<String> enums; - Vector<String> attrs = new Vector<String>(); - attrs.add("parent_test"); - attrs.add("child_test"); - enums = attrs.elements(); - when(mockedRequest.getSession().getAttributeNames()).thenReturn(enums); - when(mockedRequest.getParameter("rep_id")).thenReturn("test"); - when(mockedRequest.getParameter("rep_id_options")).thenReturn("test"); - when(mockedRequest.getParameter("rep_name_options")).thenReturn("test"); - when(mockedRequest.getParameter("rep_name")).thenReturn("test"); - SearchHandler sh = Mockito.mock(SearchHandler.class); - whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); - actionHandler.reportSearch(mockedRequest, "10"); - } - - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test(expected = NullPointerException.class) - public void reportChartRunTest() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(ReportLoader.class); - PowerMockito.mockStatic(ReportWrapper.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(ReportDefinition.class); - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - PowerMockito.mockStatic(UserUtils.class); - when(UserUtils.getUserId(mockedRequest)).thenReturn(1); - when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); - when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); - Map roles = new HashMap<>(); - roles.put("role1", "test1"); - roles.put("role2", "test2"); - when(UserUtils.getRoles(mockedRequest)).thenReturn(roles); - when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("chart.data.json"); - ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); - whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(DbUtils.getConnection()).thenReturn(connection); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); - when(rr.getReportID()).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); - when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); - String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportType>Hive</reportType><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>"; - when(connection.prepareStatement("1")).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(rs); - when(Globals.isWeblogicServer()).thenReturn(true); - when(rs.getClob(1)).thenReturn(clob); - when(rs.next()).thenReturn(true); - when(clob.getAsciiStream()).thenReturn(in); - when(in.read(Matchers.any())).thenReturn(1); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); - when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); - when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test"); - when(AppUtils.nvl("Y")).thenReturn("Y"); - when(AppUtils.nvl("bottom")).thenReturn("Y"); - when(AppUtils.nvl("test")).thenReturn("test|"); - when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); - when(ReportLoader.isDashboardType("-1")).thenReturn(false); - ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); - whenNew(ReportDefinition.class) - .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) - .thenReturn(rdf); - PowerMockito.mockStatic(ReportDefinition.class); - when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); - CustomReportType crType = Mockito.mock(CustomReportType.class); - when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); - when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); - when(Globals.getTimeFormat()).thenReturn("[reportID]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - DataSet set = PowerMockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); - whenNew(ReportRuntime.class).withArguments(Matchers.any(CustomReportType.class), Matchers.anyString(), - Matchers.any(HttpServletRequest.class), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyBoolean()).thenReturn(rr); - DataSourceList dsl = Mockito.mock(DataSourceList.class); - List<DataSourceType> list = new ArrayList<>(); - DataSourceType sr1 = new DataSourceType(); - sr1.setComment("test"); - sr1.setRefDefinition("test"); - sr1.setDataColumnList(new DataColumnList()); - sr1.setTableId("test"); - sr1.setTableName("test"); - list.add(sr1); - when(crType.getDataSourceList()).thenReturn(dsl); - when(dsl.getDataSource()).thenReturn(list); - DashboardReports rps = Mockito.mock(DashboardReports.class); - List<Reports> reportList = new ArrayList<>(); - Reports rp = new Reports(); - rp.setBgcolor("white"); - rp.setReportId("1"); - reportList.add(rp); - when(rdf.getDashBoardReports()).thenReturn(rps); - when(rps.getReportsList()).thenReturn(reportList); - when(ReportLoader.loadCustomReportXML("1")).thenReturn(str); - actionHandler.reportChartRun(mockedRequest, "10"); - } -} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java index f69c5dae..8901e73b 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java @@ -70,6 +70,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.runtime.ChartJSONHelper; @@ -89,7 +90,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(PowerMockRunner.class) -@PrepareForTest({UserUtils.class,AppUtils.class, DbUtils.class, ReportRuntime.class, Globals.class, UserUtils.class,ReportLoader.class}) +@PrepareForTest({UserUtils.class,AppUtils.class, DbUtils.class, ReportRuntime.class, Globals.class, UserUtils.class,ReportLoader.class,ChartJSONHelper.class}) public class ChartJSONHelperTest { @InjectMocks @@ -116,7 +117,7 @@ public class ChartJSONHelperTest { HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - @Test(expected = java.lang.ClassCastException.class) + @Test(expected = java.lang.NullPointerException.class) public void generateJSONTest() throws RaptorException, Exception { EcompRole role = new EcompRole(); @@ -142,6 +143,8 @@ public class ChartJSONHelperTest { rr.setChartType("BarChart3D"); rr.setMultiSeries(true); rr.setDashboardType(true); + rr.setLegendLabelAngle("standard"); + rr.setWholeSQL("SELECT * FROM test"); Mockito.when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); PowerMockito.mockStatic(Globals.class); @@ -165,7 +168,7 @@ public class ChartJSONHelperTest { Mockito.when(rs.next()).thenReturn(true); Mockito.when(clob.getAsciiStream()).thenReturn(in); Mockito.when(in.read(Matchers.any())).thenReturn(1); -// PowerMockito.mockStatic(ReportRuntime.class); + PowerMockito.mockStatic(ReportRuntime.class); Mockito.when(ReportRuntime.unmarshal(str, "1", mockedRequest)).thenReturn(rr); Mockito.when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); Mockito.when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); @@ -175,7 +178,10 @@ public class ChartJSONHelperTest { Mockito.when(AppUtils.nvl("test")).thenReturn("test|"); Mockito.when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); Mockito.when(ReportLoader.isDashboardType("-1")).thenReturn(false); - assertEquals(chartJSONHelper.generateJSON("1", mockedRequest, false).getClass(), String.class); + ReportHandler reportHandler = Mockito.mock(ReportHandler.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(rr); + assertEquals(chartJSONHelper.generateJSON("1", mockedRequest, true).getClass(), String.class); } @@ -368,6 +374,7 @@ public class ChartJSONHelperTest { dataColumnType.setColId("1"); dataColumnType.setTableId("1"); dataColumnType.setColType("DATE"); + dataColumnType.setColOnChart("LEGEND"); dataColumnTypeList.add(dataColumnType); DataColumnList dataColumnList = new DataColumnList(); dataColumnList.dataColumn = dataColumnTypeList; diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java index c94dd41a..76dd83ed 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.TreeMap; +import java.util.Vector; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -60,11 +61,12 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Matchers; +import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalsdk.analytics.model.DataCache; +import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; @@ -83,6 +85,8 @@ import org.onap.portalsdk.analytics.util.XSSFilter; import org.onap.portalsdk.analytics.view.ColumnHeader; import org.onap.portalsdk.analytics.view.ColumnHeaderRow; import org.onap.portalsdk.analytics.view.DataRow; +import org.onap.portalsdk.analytics.view.DataValue; +import org.onap.portalsdk.analytics.view.HtmlFormatter; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; import org.onap.portalsdk.analytics.view.ReportDataRows; @@ -99,33 +103,38 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.lowagie.text.Document; import com.lowagie.text.Image; +import com.lowagie.text.Rectangle; @RunWith(PowerMockRunner.class) -@PrepareForTest({ PdfReportHandler.class, PdfReportHandlerTest.class, AppConstants.class, Globals.class, AppUtils.class, ReportWrapper.class, DataCache.class, - DbUtils.class, DataSet.class, Font.class, ReportLoader.class, ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, - SecurityCodecUtil.class, ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class}) +@PrepareForTest({ PdfReportHandler.class, PdfReportHandlerTest.class, AppConstants.class, Globals.class, AppUtils.class, + ReportWrapper.class, DataCache.class, DbUtils.class, DataSet.class, Font.class, ReportLoader.class, + ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, SecurityCodecUtil.class, ConnectionUtils.class, + XSSFilter.class, ReportDefinition.class, UserUtils.class, Color.class }) public class PdfReportHandlerTest { - @InjectMocks - PdfReportHandler pdfReportHandler; - + PdfReportHandler pdfReportHandler = new PdfReportHandler(); + @Mock + ReportHandler reportHandler; + @Mock + ReportDefinition rdef; + @Before - public void init() throws Exception { + public void init() throws Exception { PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(DbUtils.class); MockitoAnnotations.initMocks(this); } - + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - @Ignore + + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void createPdfFileContentTest() throws Exception { - Document doc = mock(Document.class); + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -160,7 +169,7 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } - + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test @@ -173,8 +182,8 @@ public class PdfReportHandlerTest { ReportRuntime rr = mock(ReportRuntime.class); ReportData rd = mock(ReportData.class); - ReportDataRows rdr = new ReportDataRows(); - CustomReportType crType = mock(CustomReportType.class); + ReportDataRows rdr = new ReportDataRows(); + CustomReportType crType = mock(CustomReportType.class); Connection conn = mock(Connection.class); Statement st = mock(Statement.class); ResultSet resSet = mock(ResultSet.class); @@ -222,12 +231,12 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(st); - when( st.executeQuery(Matchers.anyString())).thenReturn(resSet); + when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); when(resSet.getMetaData()).thenReturn(resSetMD); - + when(mockedRequest.getParameter("parent")).thenReturn("parent_test"); when(mockedRequest.getSession().getAttribute("parent_test_rr")).thenReturn(rr); when(mockedRequest.getSession().getAttribute("parent_test_rd")).thenReturn(rd); @@ -242,7 +251,7 @@ public class PdfReportHandlerTest { columnHeaderRow.add(columnHeader); reportColumnHeaderRows.add(columnHeaderRow); rd.reportColumnHeaderRows = reportColumnHeaderRows; - + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); RowHeaderCol rowHeaderCol = new RowHeaderCol(); RowHeader rowHeader = new RowHeader(); @@ -258,14 +267,13 @@ public class PdfReportHandlerTest { when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.edit"); when(mockedRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("test"); - when(mockedRequest.getSession().getAttribute( - AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); Mockito.when(Globals.getNewScheduleData()).thenReturn("test"); DataSet datset = PowerMockito.mock(DataSet.class); when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - - Document doc = mock(Document.class); + + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -297,7 +305,7 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } - + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test @@ -313,8 +321,8 @@ public class PdfReportHandlerTest { when(htmlStr.stripHtml(Matchers.anyString())).thenReturn("test"); ReportRuntime rr = mock(ReportRuntime.class); ReportData rd = mock(ReportData.class); - ReportDataRows rdr = new ReportDataRows(); - CustomReportType crType = mock(CustomReportType.class); + ReportDataRows rdr = new ReportDataRows(); + CustomReportType crType = mock(CustomReportType.class); Connection conn = mock(Connection.class); Statement st = mock(Statement.class); ResultSet resSet = mock(ResultSet.class); @@ -362,12 +370,12 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(st); - when( st.executeQuery(Matchers.anyString())).thenReturn(resSet); + when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); when(resSet.getMetaData()).thenReturn(resSetMD); - + when(mockedRequest.getParameter("parent")).thenReturn("parent_test"); when(mockedRequest.getSession().getAttribute("parent_test_rr")).thenReturn(rr); when(mockedRequest.getSession().getAttribute("parent_test_rd")).thenReturn(rd); @@ -382,20 +390,19 @@ public class PdfReportHandlerTest { columnHeaderRow.add(columnHeader); reportColumnHeaderRows.add(columnHeaderRow); rd.reportColumnHeaderRows = reportColumnHeaderRows; - + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); rd.reportRowHeaderCols = reportRowHeaderCols; when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.edit"); when(mockedRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("test"); - when(mockedRequest.getSession().getAttribute( - AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); Mockito.when(Globals.getNewScheduleData()).thenReturn("test"); DataSet datset = PowerMockito.mock(DataSet.class); when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - - Document doc = mock(Document.class); + + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -427,13 +434,13 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 2); } - + @SuppressWarnings({ "rawtypes", "unchecked", "static-access" }) @Test public void createPdfFileContent2Test() throws Exception { PowerMockito.mockStatic(Image.class); - Document doc = mock(Document.class); - CustomReportType crType = mock(CustomReportType.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); DataSet ds = mock(DataSet.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); @@ -472,13 +479,13 @@ public class PdfReportHandlerTest { when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); List chartGroups = new ArrayList<>(); when(rr.getAllChartGroups()).thenReturn(chartGroups); - ReportParamValues reportValues= new ReportParamValues(); + ReportParamValues reportValues = new ReportParamValues(); when(rr.getReportParamValues()).thenReturn(reportValues); when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); HashMap requestParams = new HashMap<>(); requestParams.put("", "test"); - + DataSourceList dataSourceList = new DataSourceList(); List<DataSourceType> list = new ArrayList<>(); @@ -515,7 +522,1828 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case5Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case6Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case7Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void createPdfFileContent_case8Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + List<DataColumnType> dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(true); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void createPdfFileContent_case9Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataRow dataRow2 = new DataRow(); + + ArrayList dataValueList = new ArrayList<>(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setVisible(true); + DataValue value1 = new DataValue(); + DataValue value2 = new DataValue(); + + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + + dataRow2.addDataValue(value); + dataRow2.addDataValue(value1); + dataRow2.addDataValue(value2); + dataRow2.setDataValueList(dataValueList); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + dataRow1.addDataValue(value2); + dataRow1.setDataValueList(dataValueList); + + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow2); + reportDataRows.add(dataRow2); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + List<DataColumnType> dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(true); + Mockito.when(resSetMD.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(resSet.getString(Matchers.anyInt())).thenReturn("test"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent10Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("TimeSeriesChart"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent11Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("BarChart3D"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent12Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("BarChart3D"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = java.lang.NullPointerException.class) + public void createPdfFileContent13Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataRow dataRow2 = new DataRow(); + + ArrayList dataValueList = new ArrayList<>(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setVisible(true); + value.setBold(true); + HtmlFormatter cfmt = new HtmlFormatter(); + value.setCellFormatter(cfmt); + DataValue value1 = new DataValue(); + HtmlFormatter cfmt1 = new HtmlFormatter(); + cfmt1.setBold(true); + cfmt1.setItalic(true); + cfmt1.setUnderline(true); + cfmt1.setFontColor("red"); + cfmt1.setFontSize("1.1"); + value1.setRowFormatter(cfmt1); + + DataValue value2 = new DataValue(); + value2.setColId("test"); + value2.setVisible(true); + value2.setBold(true); + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + + dataRow2.addDataValue(value); + dataRow2.addDataValue(value1); + dataRow2.addDataValue(value2); + dataRow2.setDataValueList(dataValueList); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + dataRow1.addDataValue(value2); + dataRow1.setDataValueList(dataValueList); + + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow2); + reportDataRows.add(dataRow2); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent14Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + ReportDataRows reportDataRows1 = new ReportDataRows(); + + rd.reportDataRows = reportDataRows1; + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent15Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Cross-Tab"); + + ReportDataRows reportDataRows1 = new ReportDataRows(); + + rd.reportDataRows = reportDataRows1; + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + + List getReportDataList = new ArrayList<>(); + getReportDataList.add(dataRow); + getReportDataList.add(dataRow1); + Mockito.when(rd.getReportDataList()).thenReturn(getReportDataList); + + Vector<DataValue> rowValues = new Vector(); + rowValues.add(value1); + rowValues.add(value1); + + ArrayList dataValueList = new ArrayList<>(); + value.setColId("test"); + value.setVisible(true); + DataValue value2 = new DataValue(); + HtmlFormatter cfmt = new HtmlFormatter(); + value.setCellFormatter(cfmt); + + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + dataRow1.setDataValueList(dataValueList); + + dataRow.setRowValues(rowValues); + dataRow1.setRowValues(rowValues); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case15Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); ds.set(0, "test"); when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); @@ -529,7 +2357,259 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List<DataColumnType> dataColumnTypeList = mockDataList(); + List<DataColumnType> dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(false); + + rd.reportDataTotalRow = reportDataRows; pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } + + @Test + public void currentTimeTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getTimeZone()).thenReturn("EST"); + pdfReportHandler.currentTime("11/11/2011 11:11:11"); + } + + public List<DataColumnType> mockDataList() { + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + return dataColumnTypeList; + } + + + @Test(expected = java.lang.NullPointerException.class) + public void createPdfFileContent17Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test123"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List<DataSourceType> list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List<DataColumnType> dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 2); + } + + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java index 668304fd..0bdaeb0f 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java @@ -37,9 +37,15 @@ */ package org.onap.portalsdk.analytics.xmlobj; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; import java.util.Vector; @@ -57,7 +63,9 @@ import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.runtime.FormField; import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; +import org.onap.portalsdk.analytics.model.runtime.ReportJSONRuntime; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.model.runtime.VisualManager; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.DbUtils; @@ -69,10 +77,16 @@ import org.onap.portalsdk.analytics.util.Utils; import org.onap.portalsdk.analytics.util.XSSFilter; import org.onap.portalsdk.analytics.view.ColumnHeader; import org.onap.portalsdk.analytics.view.ColumnHeaderRow; +import org.onap.portalsdk.analytics.view.ColumnVisual; +import org.onap.portalsdk.analytics.view.DataRow; +import org.onap.portalsdk.analytics.view.DataValue; +import org.onap.portalsdk.analytics.view.HtmlFormatter; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.view.ReportDataRows; import org.onap.portalsdk.analytics.view.ReportRowHeaderCols; import org.onap.portalsdk.analytics.view.RowHeaderCol; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SecurityCodecUtil; import org.onap.portalsdk.core.web.support.UserUtils; import org.owasp.esapi.ESAPI; @@ -123,10 +137,13 @@ public class ReportRuntimeTest { dataColumnType.setColId("1"); dataColumnType.setTableId("1"); dataColumnType.setColType("DATE"); - dataColumnType.setDependsOnFormField("tes[t"); + dataColumnType.setDependsOnFormField("[test]"); dataColumnType.setDrillDownParams("drilldown[#]"); dataColumnType.setCrossTabValue("VALUE"); - dataColumnType.setDrillDownURL("url"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setOrderBySeq(10); + dataColumnType.setVisible(true); dataColumnTypeList.add(dataColumnType); DataColumnList dataColumnList = new DataColumnList(); dataColumnList.dataColumn = dataColumnTypeList; @@ -176,8 +193,46 @@ public class ReportRuntimeTest { rr.setLegendLabelAngle("test"); rr.setMultiSeries(false); rr.setChartType("test"); + rr.setXmlFileName("test"); + rr.setXmlFileURL("test"); + rr.setFlatFileName("test"); + rr.setExcelPageFileName("test"); + rr.setTotalSql("test"); + rr.setDisplayMode(10); + rr.setDateOption(10); return rr; } + + @Test + public void testReportRuntimeProperties() throws Exception { + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.isDashboardType(Mockito.any(String.class))).thenReturn(true); + ReportRuntime rr = mockReportRunTime1(); + assertEquals("test", rr.getXmlFileURL()); + assertEquals("test", rr.getXmlFileName()); + assertEquals("test", rr.getFlatFileName()); + assertEquals("test", rr.getExcelPageFileName()); + assertTrue(rr.getDisplayForm()); + assertTrue(rr.getDisplayContent()); + assertEquals(-1, rr.getCachedPageNo()); + assertEquals(null, rr.getCachedSQL()); + assertTrue(rr.isDashboardType()); + assertEquals("test", rr.getParamValue("test")); + assertEquals("test", rr.getParamDisplayValue("test")); + rr.getParamKeys(); + rr.getParamKeysForPDFExcel(); + assertEquals("test", rr.getParamValueForPDFExcel("test")); + assertEquals(FormField.class, rr.getFormField("test").getClass()); + assertEquals("test", rr.getTotalSql()); + assertEquals(VisualManager.class, rr.getVisualManager().getClass()); + assertEquals(" null) x ", rr.getReportSQLWithRowNum("test", true)); + assertEquals(10, rr.getDisplayMode()); + assertEquals(10, rr.getDateOption()); + assertFalse(rr.isDisplayColTotals()); + assertFalse(rr.isDisplayRowTotals()); + rr.showColVisual("test"); + rr.sortColVisual("test"); + } @Test public void getParamNameValuePairsTest() throws Exception { @@ -188,13 +243,53 @@ public class ReportRuntimeTest { @Test public void getParamNameValuePairsforPDFExcelTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); - rr.setReportFormFields(null); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); List predefinedValues = new ArrayList<>(); ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + + + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("test"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2); + + } + + @Test + public void getParamNameValuePairsforPDFExcelTest_WhenIsScheduleFlagTrue() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); @@ -208,17 +303,23 @@ public class ReportRuntimeTest { rr.setReportFormFields(null); rr.setReportFormFields(reportFormFields); - PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); HttpSession session = mockedRequest.getSession(); Mockito.when(session.getAttribute("test")).thenReturn("test"); Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("test"); rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2); } - @Test(expected = java.lang.ArrayIndexOutOfBoundsException.class) + @Test public void getParamNameValuePairsforPDFExcel1Test() throws Exception { ReportRuntime rr = mockReportRunTime1(); rr.setReportFormFields(null); @@ -226,7 +327,7 @@ public class ReportRuntimeTest { ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", true, - "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", @@ -241,15 +342,65 @@ public class ReportRuntimeTest { reportFormFields.add(formField2); reportFormFields.add(formField3); - rr.setReportFormFields(null); rr.setReportFormFields(reportFormFields); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn(";test,;test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); + } + + @Test + public void getParamNameValuePairsforPDFExcel1Test_WhenIsScheduleFlagTrue() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.setReportFormFields(null); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", true, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField3 = PowerMockito.mock(FormField.class); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + reportFormFields.add(formField3); + + rr.setReportFormFields(reportFormFields); PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ESAPI.class); Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); - Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn(";test,;test"); + Mockito.when(Globals.getDisplayScheduleSessionParamInPDFEXCEL()).thenReturn(";test,;test"); HttpSession session = mockedRequest.getSession(); Mockito.when(session.getAttribute("test")).thenReturn("test"); Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("DATE"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); + + } + + @Test + public void getParamNameValuePairsforPDFExcelTest_WhenValueExistInSession() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + List paramList = new ArrayList<>(); + paramList.add("test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)).thenReturn(paramList); rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); } @@ -257,7 +408,40 @@ public class ReportRuntimeTest { @Test public void getFormFieldCommentsTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); - rr.getCustomReport().getFormFieldList().setComment(""); + rr.getCustomReport().getFormFieldList().setComment("test"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + + + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("DATE"); rr.getFormFieldComments(mockedRequest); } @@ -265,8 +449,7 @@ public class ReportRuntimeTest { public void loadChartDataTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); rr.getCustomReport().getFormFieldList().setComment(""); - DataSet ds = PowerMockito.mock(DataSet.class); - rr.setChartDataCache(ds); + rr.setChartDataCache(null); rr.loadChartData("test", mockedRequest); } @@ -304,6 +487,40 @@ public class ReportRuntimeTest { rr.getCustomReport().getFormFieldList().setComment(""); rr.getCustomReport().setReportType("Linear"); rr.setWholeSQL("testFROMORDERBY"); + rr.getFormFieldList().getFormField().get(0).setGroupFormField(true); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); DataSet ds = PowerMockito.mock(DataSet.class); rr.setChartDataCache(ds); PowerMockito.mockStatic(AppUtils.class); @@ -312,13 +529,156 @@ public class ReportRuntimeTest { Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getColumnCount()).thenReturn(1); + Mockito.when(ds.getColumnName(Mockito.anyInt())).thenReturn("1"); Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); Mockito.when(Globals.getDBType()).thenReturn("db"); - rr.loadReportData(1, "userId", 1, mockedRequest, false); + + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); + ReportData rd = PowerMockito.mock(ReportData.class); + PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); + ReportDataRows reportDataRows = new ReportDataRows(); + rd.reportDataRows= reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("lDownUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getCacheCurPageData()).thenReturn(true); + Mockito.when(mockedRequest.getParameter(Mockito.anyString())).thenReturn("test"); + rr.loadReportData(1, "userId", 1, mockedRequest, true); + } + + @Test(expected=RuntimeException.class) + public void loadReportData1Test_WhenReportDataSizeIsLessThanZero() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.getCustomReport().getFormFieldList().setComment(""); + rr.getCustomReport().setReportType("Linear"); + rr.setWholeSQL("SELECT report_id test FROM WHERE ORDER BY"); + rr.setPageSize(-2); + rr.getFormFieldList().getFormField().get(0).setGroupFormField(true); + rr.setDBInfo("DEV"); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + DataSet ds = PowerMockito.mock(DataSet.class); + rr.setChartDataCache(ds); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_GO_BACK)).thenReturn(false); + Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); + Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(-1); + Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); + Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); + Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); + Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); + Mockito.when(Globals.getDBType()).thenReturn("db"); + + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); + ReportData rd = PowerMockito.mock(ReportData.class); + PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); + ReportDataRows reportDataRows = new ReportDataRows(); + rd.reportDataRows= reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("lDownUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getCacheCurPageData()).thenReturn(true); + Mockito.when(mockedRequest.getParameter(Mockito.anyString())).thenReturn("test"); + rr.getCustomReport().setDbInfo("DAYTONA"); + RemDbInfo rdemo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(rdemo); + Mockito.when(rdemo.getDBType(Matchers.anyString())).thenReturn("DAYTONA"); + rr.loadReportData(1, "userId", 1, mockedRequest, true); } @Test @@ -356,6 +716,39 @@ public class ReportRuntimeTest { rr.getCustomReport().getFormFieldList().setComment(""); rr.getCustomReport().setReportType("Cross-Tab"); rr.setWholeSQL("testFROMORDERBY"); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); DataSet ds = PowerMockito.mock(DataSet.class); rr.setChartDataCache(ds); PowerMockito.mockStatic(AppUtils.class); @@ -364,10 +757,13 @@ public class ReportRuntimeTest { Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getColumnCount()).thenReturn(1); + Mockito.when(ds.getColumnName(Mockito.anyInt())).thenReturn("1"); Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); + Mockito.when(Globals.getMergeCrosstabRowHeadings()).thenReturn(true); Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); Mockito.when(Globals.getDBType()).thenReturn("db"); PowerMockito.mockStatic(ESAPI.class); @@ -377,7 +773,7 @@ public class ReportRuntimeTest { Codec codec = PowerMockito.mock(Codec.class); Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("reportdata"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); ReportData rd = PowerMockito.mock(ReportData.class); PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); @@ -397,6 +793,14 @@ public class ReportRuntimeTest { reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("nUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getMergeCrosstabRowHeadings()).thenReturn(true); rr.loadReportData(1, "userId", 1, mockedRequest, false); } @@ -512,6 +916,49 @@ public class ReportRuntimeTest { Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyString())).thenReturn("test"); rr.parseDrillDownURL(1, ds, dataColumnType, mockedRequest, reportFormFields); } + + @Test + public void parseDrillDownURL2Test() throws Exception { + DataSet ds = PowerMockito.mock(DataSet.class); + ReportRuntime rr = mockReportRunTime1(); + DataColumnType dataColumnType = rr.getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().get(0); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("test"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("tes[t"); + dataColumnType.setDrillDownParams("drilldown[test!test]"); + dataColumnType.setCrossTabValue("VALUE"); + dataColumnType.setDrillDownURL("testutilstest1"); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "testLEGEND", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + reportFormFields.add(formField); + PowerMockito.mockStatic(DataCache.class); + PowerMockito.mockStatic(AppUtils.class); + + Vector vc = new Vector<>(); + vc.add("test"); + Mockito.when(DataCache.getDataViewActions()).thenReturn(vc); + Mockito.when(Globals.getPassRequestParamInDrilldown()).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("FFtest,1"); + Mockito.when(Globals.getRequestParams()).thenReturn("test,1"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,2"); + Mockito.when(Globals.getSessionParams()).thenReturn("FFtest,2"); + + Mockito.when(mockedRequest.getParameter(Matchers.anyString())).thenReturn("test"); + Mockito.when(AppUtils.getBaseActionURL()).thenReturn("testutils"); + Mockito.when(AppUtils.getBaseActionParam()).thenReturn("utils"); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyString())).thenReturn("test"); + Mockito.when(mockedRequest.getSession().getAttribute("FFTEST")).thenReturn("test"); + rr.parseDrillDownURL(1, ds, dataColumnType, mockedRequest, reportFormFields); + } @Test public void parseReportSQLTest() throws Exception { @@ -537,6 +984,13 @@ public class ReportRuntimeTest { rr.getCustomReport().setDbInfo("test"); rr.parseReportSQL("select * from test"); } + + @Test + public void parseReportSQL5Test() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.getCustomReport().setDbInfo("test"); + rr.parseReportSQL("select id,report_id from test"); + } @Test(expected = org.onap.portalsdk.analytics.error.ValidationException.class) public void parseReportSQL4Test() throws Exception { @@ -547,6 +1001,7 @@ public class ReportRuntimeTest { Mockito.when(rdemo.getDBType(Matchers.anyString())).thenReturn("DAYTONA"); rr.parseReportSQL(""); } + @Test public void setDisplayFlagsTest() throws Exception { @@ -912,4 +1367,212 @@ public class ReportRuntimeTest { rr.parseAndFillWithCurrentValues(mockedRequest, "test", formField); } + + @Test + public void testParseAndFillReq_Session_UserValues_WhenStartWithff() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + Mockito.when(Globals.getRequestParams()).thenReturn("fftest"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn(""); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getAttribute(Mockito.any(String.class))).thenReturn("test"); + rr.parseAndFillReq_Session_UserValues(mockedRequest, "SELECT FROM test", "userID"); + } + + @Test + public void testCreateFormFieldJSONRuntime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + rr.createFormFieldJSONRuntime(mockedRequest); + } + + + + @Test + public void testCreateReportJSONRuntime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + ReportData rd = mockReportData(); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + rr.createReportJSONRuntime(mockedRequest, rd); + } + + @Test + public void testPersistLinearReport() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(Utils.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(Utils.getCurrentDateTime()).thenReturn("20/05/2018"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "updateCustomReportRec", new Object[] {Mockito.any(Connection.class), Mockito.any(ReportRuntime.class), Mockito.any(String.class)}); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)}); + rr.persistLinearReport(mockedRequest); + } + + @Test + public void testPersistDashboardReport() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(Utils.getCurrentDateTime()).thenReturn("10/05/2018"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + PowerMockito.doNothing().when(ReportLoader.class, "updateCustomReportRec", new Object[] {Mockito.any(Connection.class), Mockito.any(ReportRuntime.class), Mockito.any(String.class)}); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)}); + rr.persistDashboardReport(mockedRequest); + } + + public ReportData mockReportData() { + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ReportDataRows reportDataRows = new ReportDataRows(); + + DataRow dataRow = new DataRow(); + DataValue dataValue = new DataValue(); + dataValue.setDisplayName("displayName"); + dataValue.setDisplayCalculatedValue("displayCalculatedValue"); + dataValue.setDrillDownURL("drillDownURL"); + dataValue.setDrillDowninPoPUp(false); + dataValue.setIndentation("indentation"); + dataValue.setAlignment("alignment"); + dataValue.setVisible(false); + dataValue.setHidden(false); + HtmlFormatter formatter = new HtmlFormatter(); + dataValue.setCellFormatter(formatter); + dataValue.setBold(false); + dataValue.setRowFormatter(formatter); + dataValue.setFormatId("formatId"); + dataValue.setCellFormat(false); + dataValue.setColId("colId"); + dataValue.setDisplayName("displayName"); + dataValue.setNowrap("nowrap"); + dataValue.setHyperlinkURL("hyperlinkURL"); + dataValue.setDisplayType("displayType"); + dataValue.setActionImg("actionImg"); + dataRow.addDataValue(dataValue); + reportDataRows.addDataRow(dataRow); + ArrayList<DataValue> list = new ArrayList<>(); + list.add(dataValue); + dataRow.setDataValueList(list); + ReportData reportData = new ReportData(1, true); + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportData.reportColumnHeaderRows = reportColumnHeaderRows; + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + reportData.reportDataRows = reportDataRows; + + Vector vc = new Vector<>(); + ColumnVisual col = new ColumnVisual("colId", "colDisplay", true, "sortType"); + vc.add(col); + reportData.setColumnVisuals(vc); + return reportData; + } + + public ReportMap mockReportMap() { + ReportMap reportMap = new ReportMap(); + reportMap.setMarkerColor("test"); + reportMap.setUseDefaultSize("size"); + reportMap.setHeight("height"); + reportMap.setWidth("width"); + reportMap.setIsMapAllowedYN("isMapAllowedYN"); + reportMap.setAddAddressInDataYN("addAddressInDataYN"); + reportMap.setAddressColumn("column"); + reportMap.setDataColumn("data"); + reportMap.setDefaultMapType("dafaultType"); + reportMap.setLatColumn("latColumn"); + reportMap.setLongColumn("longColumn"); + reportMap.setColorColumn("colorColumn"); + reportMap.setLegendColumn("legendColumn"); + Marker marker = new Marker(); + marker.setMarkerColor("markerColor"); + marker.setDataHeader("dataHeader"); + marker.setAddressColumn("addressColumn"); + marker.setDataColumn("dataColumn"); + reportMap.getMarkers().add(marker); + return reportMap; + } + + @Test + public void testGetMapMarkers() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + ReportData rd = mockReportData(); + ReportMap rm = mockReportMap(); + rr.getMapMarkers(rd, rm); + } + + @Test + public void testHideColVisual() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.hideColVisual("test"); + } + + @Test + public void testResetVisualSettings() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.resetVisualSettings(); + } + + @Test + public void testLogReportRun() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()}); + rr.logReportRun("userID", "100 ms", "formFields"); + } + + @Test + public void testLogReportExecutionTime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntryForExecutionTime", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()} ); + rr.logReportExecutionTime("userID", "100 ms", "test", "formFields"); + } + + @Test + public void testLogReportExecutionTimeFromLogList() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntryForExecutionTime", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()} ); + rr.logReportExecutionTimeFromLogList("userID", "100 ms", "formFields"); + } + + @Test + public void testGenerateColumnDataTotalsLinear() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ConnectionUtils.class); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(),Mockito.anyString())).thenReturn(ds); + ArrayList list = (ArrayList) rr.getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn(); + rr.generateColumnDataTotalsLinear(list, "userID", "dbInfo", "reportSQL"); + } + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java index ece90c8c..de3f4fff 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java @@ -37,11 +37,12 @@ */ package org.onap.portalsdk.analytics.xmlobj; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.sql.ResultSet; import java.sql.ResultSetMetaData; -import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -54,12 +55,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; -import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.model.DataCache; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.definition.TableSource; +import org.onap.portalsdk.analytics.model.runtime.FormField; import org.onap.portalsdk.analytics.model.runtime.ReportParamValues; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; @@ -68,6 +69,7 @@ import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; import org.onap.portalsdk.analytics.util.SQLCorrector; import org.onap.portalsdk.analytics.util.Utils; import org.onap.portalsdk.analytics.util.XSSFilter; @@ -83,7 +85,7 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) @PrepareForTest({ AppConstants.class, Globals.class, AppUtils.class, DataCache.class, DbUtils.class, DataSet.class, ReportLoader.class, ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, SecurityCodecUtil.class, - ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class }) + ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class, ReportWrapper.class }) public class ReportWrapperTest { MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); @@ -93,7 +95,10 @@ public class ReportWrapperTest { public ReportWrapper mockReportWrapper() throws Exception { PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(DbUtils.class); + PowerMockito.when(Globals.getReportWrapperFormat()).thenReturn("test"); + PowerMockito.when(Globals.getTimeFormat()).thenReturn("test"); Mockito.when(Globals.getReportUserAccess()).thenReturn("test"); + Mockito.when(Globals.getReportSecurity()).thenReturn("test"); ResultSet rs = PowerMockito.mock(ResultSet.class); ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); Mockito.when(rsmd.getColumnCount()).thenReturn(1); @@ -132,16 +137,8 @@ public class ReportWrapperTest { dataSourceType.setDataColumnList(dataColumnList); list.add(dataSourceType); dataSourceList.dataSource = list; - customReportType.setReportType("test"); - customReportType.setReportTitle("test"); - customReportType.setChartMultiSeries("Y"); customReportType.setDataSourceList(dataSourceList); - customReportType.setChartMultiSeries("Y"); - customReportType.setChartRightAxisLabel("test"); - customReportType.setChartLeftAxisLabel("test"); ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); - chartAdditionalOptions.setLabelAngle("test"); - chartAdditionalOptions.setTimeSeriesRender("test"); chartAdditionalOptions.setMultiSeries(false); customReportType.setChartAdditionalOptions(chartAdditionalOptions); FormFieldList formFieldList = new FormFieldList(); @@ -159,16 +156,383 @@ public class ReportWrapperTest { // FormFieldType formFieldType1 = new FormFieldType(); formFields.add(formFieldType); // formFields.add(formFieldType1); - formFieldList.formField = formFields; customReportType.setFormFieldList(formFieldList); - ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + DashboardReports dr = new DashboardReports(); + customReportType.setDashBoardReports(dr); + customReportType.setDrillURLInPoPUpPresent(true); + List<JavascriptItemType> javascriptItem = new ArrayList<>(); + JavascriptItemType ji = new JavascriptItemType(); + ji.setId("1"); + ji.setCallText("test"); + ji.setFieldId("2"); + JavascriptList javascriptList = new JavascriptList(); + javascriptList.setJavascriptItem(javascriptItem); + customReportType.setJavascriptList(javascriptList); + FormatType ft = new FormatType(); + ft.setAlignment("left"); + FormatList fl = new FormatList(); + fl.getFormat().add(ft); + SemaphoreType st = new SemaphoreType(); + st.setComment("test"); + st.setFormatList(fl); + st.setSemaphoreId("1"); + st.setSemaphoreName("test"); + st.setTarget("test"); + SemaphoreList smlist = new SemaphoreList(); + smlist.getSemaphore().add(st); + customReportType.setSemaphoreList(smlist); + chartAdditionalOptions.setChartOrientation("test"); + chartAdditionalOptions.setSecondaryChartRenderer("test"); + chartAdditionalOptions.setHideToolTips("test"); + chartAdditionalOptions.setHidechartLegend("test"); + chartAdditionalOptions.setLegendPosition("test"); + chartAdditionalOptions.setLabelAngle("test"); + chartAdditionalOptions.setIntervalFromdate("test"); + chartAdditionalOptions.setIntervalTodate("test"); + chartAdditionalOptions.setIntervalLabel("test"); + chartAdditionalOptions.setLastSeriesALineChart("test"); + chartAdditionalOptions.setLastSeriesABarChart("test"); + chartAdditionalOptions.setMaxLabelsInDomainAxis("test"); + chartAdditionalOptions.setLinearRegression("test"); + chartAdditionalOptions.setLinearRegressionColor("test"); + chartAdditionalOptions.setExponentialRegressionColor("test"); + chartAdditionalOptions.setMaxRegression("test"); + chartAdditionalOptions.setRangeAxisUpperLimit("test"); + chartAdditionalOptions.setRangeAxisLowerLimit("test"); + chartAdditionalOptions.setOverlayItemValueOnStackBar("test"); + chartAdditionalOptions.setAnimate(true); + chartAdditionalOptions.setKeepDomainAxisValueAsString("test"); + chartAdditionalOptions.setAnimateAnimatedChart(true); + chartAdditionalOptions.setStacked(true); + chartAdditionalOptions.setBarControls(true); + chartAdditionalOptions.setXAxisDateType(true); + chartAdditionalOptions.setLessXaxisTickers(true); + chartAdditionalOptions.setTimeAxis(true); + chartAdditionalOptions.setTimeSeriesRender("test"); + chartAdditionalOptions.setLeftMargin(10); + chartAdditionalOptions.setRightMargin(10); + chartAdditionalOptions.setTopMargin(10); + chartAdditionalOptions.setBottomMargin(10); + ReportMap rm = new ReportMap(); + rm.setMarkerColor("test"); + rm.setUseDefaultSize("10"); + rm.setHeight("10cm"); + rm.setWidth("10cm"); + rm.setIsMapAllowedYN("Y"); + rm.setAddAddressInDataYN("Y"); + rm.setAddressColumn("test"); + rm.setDataColumn("test"); + rm.setDefaultMapType("test"); + rm.setLatColumn("test"); + rm.setLegendColumn("test"); + rm.setLongColumn("test"); + rm.setColorColumn("test"); + Marker marker = new Marker(); + marker.setAddressColumn("test"); + marker.setDataColumn("test"); + marker.setDataHeader("test"); + marker.setMarkerColor("test"); + rm.getMarkers().add(marker); + customReportType.setReportMap(rm); + ChartDrillOptions chartDrillOptions = new ChartDrillOptions(); + ChartDrillFormfield cdff = new ChartDrillFormfield(); + cdff.setFormfield("test"); + chartDrillOptions.getTargetFormfield().add(cdff); + customReportType.setChartDrillOptions(chartDrillOptions); + customReportType.setReportSQL("test"); + dataSourceType.setRefDefinition("test"); + dataSourceType.setComment("test"); + dataColumnType.setDisplayWidthInPxls("test"); + dataColumnType.setDisplayAlignment("test"); + dataColumnType.setDisplayHeaderAlignment("test"); + dataColumnType.setColType(AppConstants.CT_HYPERLINK); + dataColumnType.setHyperlinkType("IMAGE"); + dataColumnType.setIndentation(10); + dataColumnType.setColFormat("test"); + dataColumnType.setOrderBySeq(10); + dataColumnType.setOrderByAscDesc("test"); + dataColumnType.setDisplayTotal("test"); + dataColumnType.setChartColor("test"); + dataColumnType.setChartLineType("test"); + dataColumnType.setIsRangeAxisFilled(true); + dataColumnType.setChartSeries(true); + dataColumnType.setCreateInNewChart(true); + dataColumnType.setDrillDownType("test"); + dataColumnType.setDrillinPoPUp(true); + dataColumnType.setComment("test"); + dataColumnType.setSemaphoreId("test"); + dataColumnType.setDbColType("test"); + dataColumnType.setNowrap("test"); + dataColumnType.setEnhancedPagination(true); + dataColumnType.setDataMiningCol("test"); + ColFilterList colFilterList = new ColFilterList(); + ColFilterType colFilterType = new ColFilterType(); + colFilterType.setArgValue("[test]"); + colFilterType.setCloseBrackets("test"); + colFilterType.setColId("test"); + colFilterType.setComment("test"); + colFilterType.setExpression("test"); + colFilterType.setFilterSeq(10); + colFilterType.setJoinCondition("test"); + colFilterType.setOpenBrackets("test"); + colFilterType.setArgType("FORM"); + colFilterList.getColFilter().add(colFilterType); + dataColumnType.setColFilterList(colFilterList); + formFieldType.setVisible("test"); + formFieldType.setFieldSQL("test"); + formFieldType.setFieldDefaultSQL("test"); + //fft.setRangeStartDate(); + formFieldType.setRangeEndDateSQL("test"); + formFieldType.setRangeStartDateSQL("test"); + //fft.setRangeEndDate(value); + formFieldType.setComment("test"); + formFieldType.setDependsOn("test"); + formFieldType.setGroupFormField(true); + formFieldType.setMultiSelectListSize("test"); + PredefinedValueList predefinedValueList = new PredefinedValueList(); + List<String> values = new ArrayList<>(); + values.add("test"); + predefinedValueList.predefinedValue= values; + formFieldType.setPredefinedValueList(predefinedValueList); + DataminingOptions dataminingOptions = new DataminingOptions(); + customReportType.setDataminingOptions(dataminingOptions); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "1", null, "testId", "test", "test", "1", "1", true); - reportWrapper.setWholeSQL("test"); + reportWrapper.setWholeSQL("test"); + reportWrapper.setPdfImg("testLogo"); + reportWrapper.setEmptyMessage("test"); + reportWrapper.setDrillReportIdForChart("test"); + reportWrapper.setDrillXAxisFormField("test"); + reportWrapper.setDrillYAxisFormField("test"); + reportWrapper.setDrillYAxisFormField("test"); + reportWrapper.setDrillSeriesFormField("test"); + reportWrapper.setDataGridAlign("test"); + reportWrapper.setWidthNoColumn("test"); + reportWrapper.setClassifier("test"); + reportWrapper.setForecastingPeriod("10"); + reportWrapper.setForecastingTimeFormat("test"); + reportWrapper.setReportSQLOnlyFirstPart("test"); + reportWrapper.setReportSQLWithRowNum("test"); + reportWrapper.setIsWeeklyScheduleAllowed("true"); + reportWrapper.setIsOneTimeScheduleAllowed("true"); + reportWrapper.setIsMonthlyScheduleAllowed("true"); + reportWrapper.setIsHourlyScheduleAllowed("true"); + reportWrapper.setIsDailyScheduleAllowed("true"); + reportWrapper.setIsDailyMFScheduleAllowed("true"); + reportWrapper.setHideFormFieldAfterRun(true); + reportWrapper.setChartTypeFixed("test"); + reportWrapper.setDrillDownURLInPopupPresent(true); + reportWrapper.setLinearRegression("test"); + reportWrapper.setCustomizedRegressionPoint("test"); + reportWrapper.setLinearRegressionColor("test"); + reportWrapper.setExponentialRegressionColor("test"); + reportWrapper.setTimeSeriesRender("test"); + reportWrapper.setShowXAxisLabel(true); + reportWrapper.setAddXAxisTickers(true); + reportWrapper.setZoomIn(10); + reportWrapper.setTimeAxisType("test"); + reportWrapper.setToggleLayout(true); + reportWrapper.setShowPageSize(true); + reportWrapper.setChartToolTips("test"); + reportWrapper.setDomainAxisValuesAsString("test"); + reportWrapper.setJumpTo(10); + reportWrapper.setSearchPageSize(10); + reportWrapper.setShowGotoOption(true); + reportWrapper.setShowNavPos(true); + reportWrapper.setPageNav(true); + reportWrapper.setNavPosition("test"); + reportWrapper.setDashboardEditor("test"); + DashboardEditorReport dashboardEditorReport =new DashboardEditorReport(); + dashboardEditorReport.setDataType("test"); + dashboardEditorReport.setPosition("test"); + dashboardEditorReport.setReportId("test"); + dashboardEditorReport.setReportName("test"); + DashboardEditorList deList = new DashboardEditorList(); + deList.getEditorList().add(dashboardEditorReport); + reportWrapper.setDashboardEditorList(deList); + reportWrapper.setPDFFont("test"); + reportWrapper.setPDFFontSize(10); + reportWrapper.setPDFOrientation("test"); + reportWrapper.setPDFLogo1("test"); + reportWrapper.setPDFLogo1Size(10); + reportWrapper.setPDFLogo2("test"); + reportWrapper.setPDFLogo2Size(10); + reportWrapper.setPDFCoverPage(true); + reportWrapper.setPDFFooter1("test"); + reportWrapper.setPDFFooter2("test"); + reportWrapper.setMultiGroupColumn("test"); + reportWrapper.setTopDown("test"); + reportWrapper.setSizedByContent("test"); + reportWrapper.setPageSize(10); + reportWrapper.setAllowSchedule("test"); + reportWrapper.setMaxRowsInExcelDownload (10); + reportWrapper.setReportInNewWindow(true); + reportWrapper.setDisplayFolderTree(true); + reportWrapper.setReportDescr("test"); + reportWrapper.setChartMultiplePieOrder("test"); + reportWrapper.setChartMultiplePieLabelDisplay("test"); + reportWrapper.setSecondaryChartRenderer("test"); + reportWrapper.setOverlayItemValueOnStackBar("test"); + reportWrapper.setIntervalFromdate("test"); + reportWrapper.setIntervalLabel("test"); + reportWrapper.setIntervalTodate("test"); + reportWrapper.setMaxLabelsInDomainAxis("test"); + reportWrapper.setLastSeriesALineChart("test"); + reportWrapper.setLastSeriesABarChart("test"); + reportWrapper.setChartDisplay("test"); + ObjectFactory objFactory = new ObjectFactory(); + reportWrapper.addDashboardReportsNew(objFactory); + reportWrapper.addPDFAdditionalOptions(objFactory); + reportWrapper.setChartTypeFixed("test"); + reportWrapper.setChartMultiSeries("test"); + reportWrapper.setReportTitle("test"); + reportWrapper.setReportSubTitle("test"); + reportWrapper.setReportHeader("test"); + reportWrapper.setReportFooter("test"); + reportWrapper.setNumFormCols("test"); + reportWrapper.setNumDashCols("test"); + reportWrapper.setDisplayOptions("test"); + reportWrapper.setDataContainerHeight("test"); + reportWrapper.setDataContainerWidth("test"); + reportWrapper.setDashboardOptions("test"); + reportWrapper.setDashboardLayoutHTML("testHTML"); + reportWrapper.setReportType("test"); + reportWrapper.setChartRightAxisLabel("test"); + reportWrapper.setChartLeftAxisLabel("test"); + reportWrapper.setDBInfo("testDB"); + reportWrapper.setChartWidth("100 cm"); + reportWrapper.setChartHeight("100 cm"); + reportWrapper.setFrozenColumns(10); + reportWrapper.setComment("test"); + reportWrapper.setDashboardType(true); + reportWrapper.setJavascriptElement("test"); + reportWrapper.setFolderId("1"); + reportWrapper.setReportMap(rm); + reportWrapper.setReportChartDrillOptions(chartDrillOptions); + reportWrapper.setFormHelpText("test"); + DataSet ds= Mockito.mock(DataSet.class); + PowerMockito.when(DbUtils.executeQuery(Mockito.any(String.class))).thenReturn(ds); + PowerMockito.when(ds.getString(Mockito.anyInt(),Mockito.anyInt())).thenReturn("test"); + PowerMockito.when(ds.getRowCount()).thenReturn(1); + return reportWrapper; } @Test + public void testReportWrapperProperties() throws Exception { + ReportWrapper rw = mockReportWrapper(); + assertTrue(rw.isDisplayFolderTree()); + assertTrue(rw.isHideFormFieldAfterRun()); + assertTrue(rw.isReportInNewWindow()); + assertTrue(rw.isDrillDownURLInPopupPresent()); + assertFalse(rw.isChartTypeFixed()); + assertFalse(rw.displayPieOrderinRunPage()); + assertFalse(rw.isMultiplePieOrderByRow()); + assertFalse(rw.isMultiplePieOrderByColumn()); + assertFalse(rw.displayPieLabelDisplayinRunPage()); + assertEquals("test", rw.getMultiplePieLabelDisplay()); + assertFalse(rw.displayChartDisplayinRunPage()); + assertFalse(rw.isChartDisplayIn3D()); + assertTrue(rw.isChartAnimate()); + assertTrue(rw.isXAxisDateType()); + assertFalse(rw.displayChartOrientationInRunPage()); + assertFalse(rw.isVerticalOrientation()); + assertFalse(rw.displaySecondaryChartRendererInRunPage()); + assertFalse(rw.displayIntervalInputInRunPage()); + assertFalse(rw.showLegendDisplayOptionsInRunPage()); + assertFalse(rw.isLastSeriesALineChart()); + assertFalse(rw.hideChartToolTips()); + assertFalse(rw.keepDomainAxisValueInChartAsString()); + assertTrue(rw.isDashboardType()); + assertTrue(rw.isToggleLayout()); + assertTrue(rw.isShowPageSize()); + assertTrue(rw.isShowNavPos()); + assertTrue(rw.isShowGotoOption()); + assertTrue(rw.isPageNav()); + assertTrue(rw.isPDFCoverPage()); + assertFalse(rw.isAllowSchedule()); + assertFalse(rw.isMultiGroupColumn()); + assertFalse(rw.isTopDown()); + assertFalse(rw.isSizedByContent()); + assertFalse(rw.isDashboardOptionHideChart()); + assertFalse(rw.isDashboardOptionHideData()); + assertFalse(rw.isDashboardOptionHideBtns()); + assertFalse(rw.isDisplayOptionHideForm()); + assertFalse(rw.isDisplayOptionHideData()); + assertFalse(rw.isDisplayOptionHideBtns()); + assertFalse(rw.isDisplayOptionHideMap()); + assertFalse(rw.isDisplayOptionHideExcelIcons()); + assertFalse(rw.isDisplayOptionHidePDFIcons()); + assertEquals("test", rw.getChartTypeFixed()); + assertEquals("test", rw.getLinearRegression()); + assertEquals("test", rw.getCustomizedRegressionPoint()); + assertEquals("test", rw.getLinearRegressionColor()); + assertEquals(0, rw.getChartWidthAsInt()); + assertEquals("test", rw.getExponentialRegressionColor()); + assertEquals("test", rw.getSecondaryChartRenderer()); + assertEquals("test", rw.getOverlayItemValueOnStackBar()); + assertEquals("test", rw.getIntervalFromdate()); + assertEquals("test", rw.getIntervalTodate()); + assertEquals("test", rw.getIntervalLabel()); + assertEquals("test", rw.getMaxLabelsInDomainAxis()); + assertEquals(0, rw.getChartHeightAsInt()); + assertEquals("test", rw.getReportHeader()); + assertEquals("test", rw.getReportFooter()); + assertEquals("test", rw.getNumDashCols()); + assertEquals(1, rw.getNumDashColsAsInt()); + assertEquals("test", rw.getNumFormCols()); + assertEquals(5, rw.getNumFormColsAsInt()); + assertEquals(10, rw.getJumpTo()); + assertEquals("test", rw.getNavPosition()); + assertEquals(null, rw.getDashboardEditorList()); + assertEquals(PDFAdditionalOptions.class, rw.getPDFAdditionalOptions().getClass()); + assertEquals(null, rw.getPDFFont()); + assertEquals(9, rw.getPDFFontSize()); + assertEquals("landscape", rw.getPDFOrientation()); + assertEquals(null, rw.getPDFLogo1()); + assertEquals(0, rw.getPDFLogo1Size()); + assertEquals(null, rw.getPDFLogo2()); + assertEquals(0, rw.getPDFLogo2Size()); + assertEquals(null, rw.getPDFFooter1()); + assertEquals(null, rw.getPDFFooter2()); + assertEquals("test", rw.getDataContainerHeight()); + assertEquals("test", rw.getDataContainerWidth()); + assertEquals("test", rw.getAllowSchedule()); + assertEquals("test", rw.getMultiGroupColumn()); + assertEquals(0, rw.getMaxGroupLevel()); + assertEquals(ChartAdditionalOptions.class, rw.getChartAdditionalOptions().getClass()); + assertEquals(DataminingOptions.class, rw.getDataminingOptions().getClass()); + assertEquals(DashboardReports.class, rw.getDashBoardReports().getClass()); + assertEquals(DashboardReportsNew.class, rw.getDashBoardReportsNew().getClass()); + assertEquals("test", rw.getClassifier()); + assertEquals(10, rw.getForecastingPeriod()); + assertEquals("test", rw.getForecastingTimeFormat()); + assertEquals(10, rw.getFrozenColumns()); + assertEquals("testLogo", rw.getPdfImg()); + assertEquals("test", rw.getEmptyMessage()); + assertEquals("test", rw.getDrillReportIdForChart()); + assertEquals("test", rw.getDrillXAxisFormField()); + assertEquals("test", rw.getDrillYAxisFormField()); + assertEquals("test", rw.getDrillSeriesFormField()); + assertEquals("test", rw.getDataGridAlign()); + assertEquals("test", rw.getWidthNoColumn()); + assertEquals(10, rw.getSearchPageSize()); + assertEquals(null, rw.getDashboardEditor()); + assertEquals(ReportMap.class, rw.getReportMap().getClass()); + assertEquals(ChartDrillOptions.class, rw.getReportChartDrillOptions().getClass()); + assertEquals("test", rw.getFormHelpText()); + assertEquals("test", rw.getReportSQLWithRowNum()); + assertEquals("true", rw.getIsWeeklyScheduleAllowed()); + assertEquals("true", rw.getIsOneTimeScheduleAllowed()); + assertEquals("true", rw.getIsMonthlyScheduleAllowed()); + assertEquals("true", rw.getIsHourlyScheduleAllowed()); + assertEquals("true", rw.getIsDailyScheduleAllowed()); + assertEquals("true", rw.getIsDailyMFScheduleAllowed()); + assertEquals("1", rw.getFolderId()); + } + + @Test public void cloneCustomReportTest() throws Exception { ReportWrapper rw = mockReportWrapper(); rw.cloneCustomReport(); @@ -237,16 +601,16 @@ public class ReportWrapperTest { public void rwTest() throws Exception { ReportWrapper rw = new ReportWrapper(mockReportWrapper()); assertEquals(rw.getCustomReport().getClass(), CustomReportType.class); - assertEquals(rw.getReportID(), "-1"); - assertEquals(rw.getMenuID(), "1"); + assertEquals(rw.getReportID(), "1"); + assertEquals(rw.getMenuID(), ""); assertFalse(rw.checkMenuIDSelected("test")); - assertTrue(rw.isMenuApproved()); - assertEquals(rw.getReportDefType(), ""); + assertFalse(rw.isMenuApproved()); + assertEquals(rw.getReportDefType(), "SQL-based"); rw.setMenuID("test"); rw.setMenuApproved(false); rw.setReportDefType("test"); rw.updateReportDefType(); - assertEquals(rw.getJavascriptElement(), null); + assertEquals(rw.getJavascriptElement(), "test"); } @Test @@ -727,6 +1091,166 @@ public class ReportWrapperTest { Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); } + + @Test + public void generateSQLSQLBased2Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] AND ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased3Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased4Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_HR); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased5Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_MIN); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased6Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_SEC); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased7Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + //Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn(""); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } @Test public void generateSQLVisualTest() throws Exception { @@ -853,7 +1377,7 @@ public class ReportWrapperTest { @Test public void getFrozenColumnId1Test() throws Exception { ReportWrapper rw = mockReportWrapper(); - rw.getCustomReport().setFrozenColumns(1); + rw.setFrozenColumns(1); rw.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().get(0) .setVisible(true); rw.getFrozenColumnId(); @@ -1146,4 +1670,55 @@ public class ReportWrapperTest { DataSourceType dataSourceType = new DataSourceType(); rw.formatListValue("[MAX_VALUE]", "[MAX_VALUE]", dataColumnType, false, false, dataSourceType, "listBaseSQL"); } + + @Test + public void testIsChartDrillDownContainsName() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.isChartDrillDownContainsName("test"); + } + + @Test + public void testCloneChartDrillFormfield() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + ChartDrillFormfield cdff = new ChartDrillFormfield(); + cdff.setFormfield("test"); + rw.cloneChartDrillFormfield(objFactory, cdff); + } + + @Test + public void testCloneMarkerType() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + Marker marker = new Marker(); + marker.setAddressColumn("test"); + marker.setDataColumn("test"); + marker.setDataHeader("test"); + marker.setMarkerColor("test"); + rw.cloneMarkerType(objFactory, marker); + } + + @Test + public void testCloneDashboardType() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + Reports reports = new Reports(); + reports.setBgcolor("test"); + reports.setReportId("1"); + rw.cloneDashboardType(objFactory, reports); + } + + @Test + public void testIsEnhancedPaginationNeeded() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.isEnhancedPaginationNeeded(); + } + + @Test + public void testGetColumnWhichNeedEnhancedPagination() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.getColumnWhichNeedEnhancedPagination(); + } + + }
\ No newline at end of file |