Package mykeynote.junit

Source Code of mykeynote.junit.SignTest

package mykeynote.junit;

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

import mykeynote.exceptions.FileCreateException;
import mykeynote.exceptions.FileDeleteException;
import mykeynote.exceptions.FileNotWritableException;
import mykeynote.exceptions.FileWriteException;
import mykeynote.exceptions.configuration.ConfigurationUnacceptableValue;
import mykeynote.exceptions.configuration.MissingConfigOptionException;
import mykeynote.exceptions.configuration.UniqueFileException;
import mykeynote.exceptions.keynote.MalformedKeyException;
import mykeynote.exceptions.keynote.cl.KeyNoteCLException;
import mykeynote.exceptions.report.ReportFileCreationException;
import mykeynote.exceptions.report.ReportNotInitializedException;
import mykeynote.keynote.KeyNoteCL;
import mykeynote.server.Report;
import mykeynote.server.configuration.Configuration;

import junit.framework.TestCase;

public class SignTest extends TestCase{
  File configuration = new File(new File("etc", "mykeynote"), "MyKeyNote.conf.example");
  File base = new File(new File("mykeynote", "junit"), "keynote");
  File testToOk = new File(base, "test-assertion1");
  File testToOkOut = new File(base, "test-assertion1.out");
  File testOk = new File(base, "test-assertion1-signed.ok");
  private Configuration config = null;
  private 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);
    }
   
    try {
      report = config.getReport();
    } catch (ReportNotInitializedException e) {
      assertNull(e);
    }
  }
 
 
  public void testSign(){
    KeyNoteCL cl = new KeyNoteCL(config, report);
   
    File base = new File(new File("mykeynote", "junit"), "keynote");
   
    File fileToSign = new File(base, "test-assertion1");
    File outputFile = new File(base, "test-assertion1-signed.out");
    File okFile = new File(base, "test-assertion1-signed.ok");
    File keyFile = new File(base, "test.key.pem");
    String i = "100";
    try {
      cl.sign(i, report, fileToSign, keyFile,outputFile);
    } catch (FileNotFoundException e) {
      assertNull(e);
    } catch (InterruptedException e) {
      assertNull(e);
    } catch (IOException e) {
      assertNull(e);
    } catch (KeyNoteCLException e) {
      assertNull(e);
    } catch (FileDeleteException e) {
      e.printStackTrace();
      assertNull(e);
    } catch (FileCreateException e) {
      e.printStackTrace();
      assertNull(e);
    } catch (FileNotWritableException e) {
      assertNull(e);
    } catch (FileWriteException e) {
      assertNull(e);
    } catch (MalformedKeyException e) {
      e.printStackTrace();
      assertNull(e);
    }
   
    compareFiles(okFile, outputFile);
   
  }
 
  public void compareFiles(File file1, File file2) {
    String file1In = null, file2In = null;
    try {
      file1In = readFile(file1);
      file2In = readFile(file2);
    } catch (IOException e) {
      assertNull(e);
    }
   
   
    assertEquals(file1In, file2In);
  }
 
  public String readFile(File file) throws IOException{
    String line;
    String out = "";
    BufferedReader read = new BufferedReader(new FileReader(file));
   
    while((line = read.readLine()) != null){
      out +=line + "\n";
    }
    return out;
     
  }
 
  public void tearDown() {
    try {
      config.finalizeConfiguration();
    } catch (IOException e) {
      assertNull(e);
    }
  }
}
TOP

Related Classes of mykeynote.junit.SignTest

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.