/* * ============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); } }