From f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 Mon Sep 17 00:00:00 2001 From: "Kishore Reddy, Gujja (kg811t)" Date: Fri, 8 Jun 2018 16:40:16 -0400 Subject: Junit Test Cases & Raptors Issue-ID: PORTAL-273. PORTAL-301 Covered JUNITS for sdk modules and RAPTOR reports fixes Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525 Signed-off-by: Kishore Reddy, Gujja (kg811t) --- .../analytics/model/pdf/PageEventTest.java | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java') 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(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + 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(""); + 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(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + 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(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + 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); + } +} -- cgit 1.2.3-korg