Package mykeynote.junit

Source Code of mykeynote.junit.ReportTest

package mykeynote.junit;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import junit.framework.TestCase;
import mykeynote.exceptions.configuration.ConfigurationUnacceptableValue;
import mykeynote.exceptions.configuration.MissingConfigOptionException;
import mykeynote.exceptions.configuration.UniqueFileException;
import mykeynote.exceptions.report.ReportFileCreationException;
import mykeynote.exceptions.report.ReportNotInitializedException;
import mykeynote.server.Report;
import mykeynote.server.configuration.Configuration;

public class ReportTest extends TestCase{
  private File configuration = null;
  private Configuration config = null;
  private String unique = "junit", message = "TEST";
  Report report = null;
 
  public void setUp() {
    configuration = new File("etc/mykeynote/MyKeyNote.conf.example");
    try {
      config = new Configuration(configuration, true);
      config.readConfigFile();
    } catch (FileNotFoundException e) {
      assertNull(e);
    } catch (IOException e) {
      assertNull(e);
    } catch (MissingConfigOptionException e) {
      assertNull(e);
    } catch (ReportFileCreationException e) {
      assertNull(e);
    } catch (ConfigurationUnacceptableValue e) {
      assertNull(e);
    } catch (UniqueFileException e) {
      assertNull(e);
    }
  }
 
 
  public void testReport(){
    try {
      report = config.getReport();
    } catch (ReportNotInitializedException e1) {
      assertNull(e1);
    }
    report.reportVerbouseLog(unique, message);
    report.reportErrorLog(unique, message);
    try {
      BufferedReader readVerbouse = new BufferedReader(new FileReader(config.getReport().getFileVerbouseLogFile()));
      String lastline = null, line;
      while((line = readVerbouse.readLine()) != null){
        lastline = line.trim();
      }
     
      assertNotNull("We wrote to this file, so there should be a last line.",lastline);
     
      line = (String) lastline.subSequence(lastline.indexOf(",") +2, lastline.length());
      //System.err.println(line);
      //System.err.println(unique + ", \"" + message +"\"");
      assertTrue(line.compareTo(unique + ", \"" + message +"\"") == 0);
    } catch (FileNotFoundException e) {
      assertNull(e);
    } catch (ReportNotInitializedException e) {
      assertNull(e);
    } catch (IOException e) {
      assertNull(e);
    }
  }
 
  public void tearDown() {
    try {
      config.finalizeConfiguration();
    } catch (IOException e) {
      assertNull(e);
    }
  }
}
TOP

Related Classes of mykeynote.junit.ReportTest

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.