package com.capgemini.servlet.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import junit.framework.Assert;

/** JUnit test. **/
public class Report01Test {

    /** JUnit setup. **/
    @BeforeClass
    public static void setUpBeforeClass() {
        // Nothing to do
    }

    /** JUnit setup. **/
    @Before
    public void setUp() {
        // Nothing to do
    }

    /** JUnit cleanup. **/
    @After
    public void tearDown() {
        // Nothing to do
    }

    /** JUnit test. **/
    @Test
    public void testURLGetsUnits() {

        String url = "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getUnits&dataValues=p5bFrkT9hLofXA";

        Pattern p = Pattern.compile("action=(.*)&dataValues=(.*)");
        Matcher m = p.matcher(url);
        if (m.find()) {

            String action = m.group(1);
            String datavalues = m.group(2);

            Assert.assertEquals("Check action ", "getUnits", action);
            Assert.assertEquals("Check datavalues ", "p5bFrkT9hLofXA", datavalues);
        }
    }

    /** JUnit test. **/
    @Test
    public void testURLGetGenerics() {

        String url = "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getGenerics&dataValues=p5bFrkT9hLofXA&unit=20";

        Pattern p = Pattern.compile("action=(.*)&dataValues=(.*)&unit=(.*)");
        Matcher m = p.matcher(url);
        if (m.find()) {

            String action = m.group(1);
            String datavalues = m.group(2);
            String unit = m.group(3);

            Assert.assertEquals("Check action ", "getGenerics", action);
            Assert.assertEquals("Check datavalues ", "p5bFrkT9hLofXA", datavalues);
            Assert.assertEquals("Check unit ", "20", unit);
        }
    }

    /** JUnit test. **/
    @Test
    public void testGetParams() {

        String urlUnit = "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getUnits&dataValues=p5bFrkT9hLofXA";
        Assert.assertEquals("URL unit 1", "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getUnits&dataValues=p5bFrkT9hLofXA", urlUnit);

        String urlGenerics = "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getGenerics&dataValues=p5bFrkT9hLofXA&unit=20";
        Assert.assertEquals("URL unit 2",
                "http://localhost:8080/kurt-web/report_r01/obtain-data?action=getGenerics&dataValues=p5bFrkT9hLofXA&unit=20", urlGenerics);
    }

}
