// Path: workspace/partitioner/src/solution/CountReducer.java
// public class CountReducer extends Reducer<Text, Text, Text, IntWritable> {
// 
//   @Override
//   public void reduce(Text key, Iterable<Text> values, Context context)
//       throws IOException, InterruptedException
//   {
// 	  int count = Iterables.size(values);
// 	  context.write(key, new IntWritable(count));
//   }
// }
// 
// Path: workspace/partitioner/src/solution/LogMonthMapper.java
// public class LogMonthMapper extends Mapper<LongWritable, Text, Text, Text> {
// 
//   /**
//    * Example input line:
//    * 96.7.4.14 - - [24/Apr/2011:04:20:11 -0400] "GET /cat.jpg HTTP/1.1" 200 12433
//    *
//    */
//   @Override
//   public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
//   {
// 	  	String line = value.toString();
// 	  	//pattern test in TestStringRegEx (package test)
// 	  	Pattern ipPattern = Pattern.compile("(\\A|\\s)(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\s|\\z)");
// 	  	Pattern monthPattern = Pattern.compile("(?<=\\[(([0-2]?\\d)|([3][0-2]))/)([A-Z][a-z]{2})(?=/(([1][9]{2}\\d)|([2][0][01]\\d)).*\\])");
// 	  	Matcher ip = ipPattern.matcher(line);
// 		Matcher month = monthPattern.matcher(line);
// 		if(ip.find() && month.find())
//         {
// 			//String key = ip.group().trim();
// 			//String value = month.group().toUpperCase().trim();
// 			 context.write(new Text(ip.group().trim()), new Text(month.group().toLowerCase().trim()));
//         }
// 		else
// 		{
// 			//add wrong line counter
// 			context.getCounter("LogMonthMapper", "skippedLines").increment(1);
// 		}
//   }
// }


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
import org.junit.Before;
import org.junit.Test;
import solution.CountReducer;
import solution.LogMonthMapper;
package test;



// needed for list

public class TestProcessLogs 
{
	MapReduceDriver<LongWritable, Text, Text, Text, Text, IntWritable> mapReduceDriver;
  /*
   * Set up the test. This method will be called before every test.
   */
  @Before
  public void setUp()
  {

    mapReduceDriver = new MapReduceDriver<LongWritable, Text,  Text, Text, Text, IntWritable>();
    mapReduceDriver.withMapper(new LogMonthMapper());
    mapReduceDriver.withReducer(new CountReducer());
  }

  /*
   * Test the mapper.
   */
  @Test
  public void testMonthPartitionerFail()
  {
	  mapReduceDriver.withInput(new LongWritable(1), new Text("96.7.4.14 psodfkspo - - [24/Apasdr/2011:04:20:11 -0400] \"GET /cat.jpg HTTP/1.1\" 200 12433"));
// Path: workspace/partitioner/src/solution/CountReducer.java
// public class CountReducer extends Reducer<Text, Text, Text, IntWritable> {
// 
//   @Override
//   public void reduce(Text key, Iterable<Text> values, Context context)
//       throws IOException, InterruptedException
//   {
// 	  int count = Iterables.size(values);
// 	  context.write(key, new IntWritable(count));
//   }
// }
// 
// Path: workspace/partitioner/src/solution/LogMonthMapper.java
// public class LogMonthMapper extends Mapper<LongWritable, Text, Text, Text> {
// 
//   /**
//    * Example input line:
//    * 96.7.4.14 - - [24/Apr/2011:04:20:11 -0400] "GET /cat.jpg HTTP/1.1" 200 12433
//    *
//    */
//   @Override
//   public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
//   {
// 	  	String line = value.toString();
// 	  	//pattern test in TestStringRegEx (package test)
// 	  	Pattern ipPattern = Pattern.compile("(\\A|\\s)(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})(\\s|\\z)");
// 	  	Pattern monthPattern = Pattern.compile("(?<=\\[(([0-2]?\\d)|([3][0-2]))/)([A-Z][a-z]{2})(?=/(([1][9]{2}\\d)|([2][0][01]\\d)).*\\])");
// 	  	Matcher ip = ipPattern.matcher(line);
// 		Matcher month = monthPattern.matcher(line);
// 		if(ip.find() && month.find())
//         {
// 			//String key = ip.group().trim();
// 			//String value = month.group().toUpperCase().trim();
// 			 context.write(new Text(ip.group().trim()), new Text(month.group().toLowerCase().trim()));
//         }
// 		else
// 		{
// 			//add wrong line counter
// 			context.getCounter("LogMonthMapper", "skippedLines").increment(1);
// 		}
//   }
// }


// Path: workspace/partitioner/src/test/TestProcessLogs.java
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mrunit.mapreduce.MapReduceDriver;
import org.junit.Before;
import org.junit.Test;
import solution.CountReducer;
import solution.LogMonthMapper;

package test;



// needed for list

public class TestProcessLogs 
{
	MapReduceDriver<LongWritable, Text, Text, Text, Text, IntWritable> mapReduceDriver;
  /*
   * Set up the test. This method will be called before every test.
   */
  @Before
  public void setUp()
  {

    mapReduceDriver = new MapReduceDriver<LongWritable, Text,  Text, Text, Text, IntWritable>();
    mapReduceDriver.withMapper(new LogMonthMapper());
    mapReduceDriver.withReducer(new CountReducer());
  }

  /*
   * Test the mapper.
   */
  @Test
  public void testMonthPartitionerFail()
  {
	  mapReduceDriver.withInput(new LongWritable(1), new Text("96.7.4.14 psodfkspo - - [24/Apasdr/2011:04:20:11 -0400] \"GET /cat.jpg HTTP/1.1\" 200 12433"));
	  mapReduceDriver.withOutput(new Text("96.7.4.14"), new IntWritable(1));