package com.capgemini.reports.formatting;

import com.capgemini.framework.common.SettingsHelper;
import com.capgemini.framework.common.StringHelper;
import com.capgemini.reports.exceptions.InvalidInputException;
import junit.framework.Assert;
import org.junit.Test;


public class MyReportsTest {

    /**
     * JUnit test.
     * 
     * @throws InvalidInputException Should not happen
     */
    @Test
    public void obtainIntegerPageParamTestSuccess() throws InvalidInputException {
        Assert.assertEquals(25, MyReports.obtainIntegerPageParam("25"));
    }

    /**
     * JUnit test.
     * 
     * @throws InvalidInputException Should not happen
     */
    @Test(expected = InvalidInputException.class)
    public void obtainIntegerPageParamTestFailed() throws InvalidInputException {
        Assert.assertEquals(1, MyReports.obtainIntegerPageParam("sgr<sdgdfhhdfhjfd"));
    }


  @Test
    public void pageCountTest() {
        Assert.assertEquals(1L, MyReports.pageCount(1L));
        int paging = SettingsHelper.getJspPaging();
        Assert.assertEquals(1L, MyReports.pageCount(paging));
        Assert.assertEquals(2L, MyReports.pageCount(paging + 1));
        Assert.assertEquals(3L, MyReports.pageCount(paging * 2 + 1));
    }


  @Test
    public void makePagingTest() {
        Assert.assertEquals(StringHelper.EMPTY, MyReports.makePaging(1, 1));
        Assert.assertEquals(
                "<div width=\"90%\" style=\"border-bottom:3px double #EEEEFF;margin-bottom:3px;\"/>&nbsp;</div>" + "<b>Pages:</b> "
                        + "<BUTTON class=\"formButton\" style=\"color:#22AA22;border:1px solid #338833;width:28px;padding:1px;\">1</BUTTON> - "
                        + "<BUTTON class=\"formButton\" style=\"color:#333355;border:1px solid #333355;width:28px;padding:1px;\" onclick=\"GoPage(2)\">2</BUTTON>",
                MyReports.makePaging(1, 2));
        Assert.assertEquals(
                "<div width=\"90%\" style=\"border-bottom:3px double #EEEEFF;margin-bottom:3px;\"/>&nbsp;</div>" + "<b>Pages:</b> "
                        + "<BUTTON class=\"formButton\" style=\"color:#333355;border:1px solid #333355;width:28px;padding:1px;\" onclick=\"GoPage(1)\">1</BUTTON> - "
                        + "<BUTTON class=\"formButton\" style=\"color:#22AA22;border:1px solid #338833;width:28px;padding:1px;\">2</BUTTON> - "
                        + "<BUTTON class=\"formButton\" style=\"color:#333355;border:1px solid #333355;width:28px;padding:1px;\" onclick=\"GoPage(3)\">3</BUTTON>",
                MyReports.makePaging(2, 3));
    }
}
