Package metrics4Asterisk.parse

Source Code of metrics4Asterisk.parse.QueueLogParserTest

package metrics4Asterisk.parse;

import metrics4Asterisk.metrics.CallMetric;
import metrics4Asterisk.util.DateMaker;
import com.csvreader.CsvReader;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
import metrics4Asterisk.util.Constants;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* A test class for controlled and easily predicatable use of the QueueLogParser
* @author lstine
*/
public class QueueLogParserTest extends TestCase {

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    /**
     * A test with few calls within the parser's date ranges
     * @throws Exception
     */
    @Test
    public void testQueueBasic() throws Exception {

        InputStream fstream = null;
        BufferedReader in = null;
        CsvReader reader = null;

        try {

            fstream = this.getClass().getClassLoader().getResourceAsStream("agent6005mini");
            in = new BufferedReader(new InputStreamReader(fstream));
            reader = new CsvReader(in, Constants.ASTERISK_LOG_SPERATOR);

            Set<String> queuenames = new HashSet<String>();
            queuenames.add("superqueue");
            queuenames.add("NONE");
           
            CallMapper mapperc = new CallMapper(queuenames);

            LogParser<LogMapper<CallMetric>> queueLogParser = new LogParser<LogMapper<CallMetric>>();
            queueLogParser.setLogMapper(mapperc);

            Calendar cFromDate = DateMaker.makeFromString("06/15/2008");
            Calendar cToDate = DateMaker.makeFromString("06/20/2008");
            cToDate.add(Calendar.SECOND, -1); //make end date exclusive

            queueLogParser.parse(cFromDate, cToDate, reader);

            //total number of calls to test
            LogMapper<CallMetric> mapper = queueLogParser.getLogMapper();
            assertEquals(4, mapper.getMap().size());

            //test the individual calls
            CallMetric call1 = mapper.getMap().get("1213780184.0");
            //test wait time before pickup
            assertEquals(call1.getWaitTime(), 6);
            //test total call time
            assertEquals(call1.getTalkTime(), 4873);
            //test the correct queuename is used
            assertEquals(call1.getQueueName(), "superqueue");
            //test that the correct extension is recorded
            assertEquals(call1.getExtension(), "Local/6005@internal/n");
           
        } catch (Exception e) {
            fail("no exceptions expected");
        }
    }

    /**
     * A test with a call entering the queue prior to the date range
     * @throws Exception
     */
    @Test
    public void testQueueEdgeCaseFront() throws Exception {

        InputStream fstream = null;
        BufferedReader in = null;
        CsvReader reader = null;

        try {

            fstream = this.getClass().getClassLoader().getResourceAsStream("agent6005mini");
            in = new BufferedReader(new InputStreamReader(fstream));
            reader = new CsvReader(in, Constants.ASTERISK_LOG_SPERATOR);

            Set<String> queuenames = new HashSet<String>();
            queuenames.add("superqueue");
            queuenames.add("NONE");

            CallMapper mapperc = new CallMapper(queuenames);

            LogParser<LogMapper<CallMetric>> queueLogParser = new LogParser<LogMapper<CallMetric>>();
            queueLogParser.setLogMapper(mapperc);

            Calendar cFromDate = DateMaker.makeFromLong(1213780199000L);
            Calendar cToDate = DateMaker.makeFromLong(12137868400000L);

            queueLogParser.parse(cFromDate, cToDate, reader);

            //total number of calls to test
            LogMapper<CallMetric> mapper = queueLogParser.getLogMapper();
            assertEquals(3, mapper.getMap().size());

            //test the call that entered teh queue before the date range
            CallMetric call1 = mapper.getMap().get("1213780184.0");
            assertNull(call1);

        } catch (Exception e) {
            fail("no exceptions expected");
        }
    }

    /**
     * A test with a call leaves the queue after to the date range
     * @throws Exception
     */
    @Test
    public void testQueueEdgeCaseEnd() throws Exception {

        InputStream fstream = null;
        BufferedReader in = null;
        CsvReader reader = null;

        try {

            fstream = this.getClass().getClassLoader().getResourceAsStream("agent6005mini");
            in = new BufferedReader(new InputStreamReader(fstream));
            reader = new CsvReader(in, Constants.ASTERISK_LOG_SPERATOR);

            Set<String> queuenames = new HashSet<String>();
            queuenames.add("superqueue");
            queuenames.add("NONE");

            CallMapper mapperc = new CallMapper(queuenames);

            LogParser<LogMapper<CallMetric>> queueLogParser = new LogParser<LogMapper<CallMetric>>();
            queueLogParser.setLogMapper(mapperc);

            Calendar cFromDate = DateMaker.makeFromString("06/15/2008");
            Calendar cToDate = DateMaker.makeFromLong(1213785870000L);

            queueLogParser.parse(cFromDate, cToDate, reader);

            //total number of calls to test
            LogMapper<CallMetric> mapper = queueLogParser.getLogMapper();
            assertEquals(4, mapper.getMap().size());

            //test the call that left the queue after the date range
            CallMetric call1 = mapper.getMap().get("1213785844.23");
            assertNotNull(call1);
            //this should register 0 for talk and wait time
            //test wait time before pickup
            assertEquals(call1.getWaitTime(), 0);
            //test total call time
            assertEquals(call1.getTalkTime(), 0);
            //test the correct queuename is used
            assertEquals(call1.getQueueName(), "superqueue");
            //test that the correct extension is recorded
            assertEquals(call1.getExtension(), "Local/6005@internal/n");

        } catch (Exception e) {
            fail("no exceptions expected");
        }
    }

}
TOP

Related Classes of metrics4Asterisk.parse.QueueLogParserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.