summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java184
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java113
2 files changed, 297 insertions, 0 deletions
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());
+ }
+}