Package mykeynote.junit

Source Code of mykeynote.junit.NormalizePemTest

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.configuration.ConfigurationUnacceptableValue;
import mykeynote.exceptions.configuration.MissingConfigOptionException;
import mykeynote.exceptions.configuration.UniqueFileException;
import mykeynote.exceptions.keynote.MalformedKeyException;
import mykeynote.exceptions.report.ReportFileCreationException;
import mykeynote.exceptions.report.ReportNotInitializedException;
import mykeynote.keynote.KeyNoteCommon;
import mykeynote.server.Report;
import mykeynote.server.configuration.Configuration;

import junit.framework.TestCase;

public class NormalizePemTest extends TestCase {
  File configuration = new File(new File("etc", "mykeynote"), "MyKeyNote.conf.example");
  File base = new File(new File("mykeynote", "junit"), "keynote");
 
  //Configuration conf = new Configuration(configuration,true);
 
  File keyfile = new File(base, "test.cert.pem");
  File normalized = new File(base, "normalized.test.cert.pem");
 
  KeyNoteCommon kt = new KeyNoteCommon();
  String actualNormalizedKey = null;
  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 e1) {
      assertNull(e1);
    }
  }
 
  public void testKey(){
    try {
      actualNormalizedKey = kt.getNormalizedKey("100", report, keyfile);
    } catch (FileNotFoundException e) {
      assertNull(e);
    } catch (IOException e) {
      assertNull(e);
    } catch (MalformedKeyException e) {
      assertNull(e);
    }
   
    BufferedReader read = null;
    try {
      read = new BufferedReader(new FileReader(normalized));
    } catch (FileNotFoundException e) {
      assertNull(e);
    }
   
    String expectedNormalizedKey = null;
    try {
      expectedNormalizedKey = read.readLine();
    } catch (IOException e) {
      assertNull(e);
    }
    actualNormalizedKey = "authorizer: \"" + actualNormalizedKey + "\"";
    System.out.println(actualNormalizedKey);
    assertEquals(expectedNormalizedKey, actualNormalizedKey);
  }
 
  public void tearDown() {
    try {
      config.finalizeConfiguration();
    } catch (IOException e) {
      assertNull(e);
    }
  }
}
TOP

Related Classes of mykeynote.junit.NormalizePemTest

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.