package test.abnahme.A;

import test.abnahme.AbnahmeTestCase;
import at.gv.egovernment.moa.id.AuthenticationException;
import at.gv.egovernment.moa.id.auth.WrongParametersException;

/**
 * @author Stefan Knirsch
 * @version $Id$
 * 
 */
public class Test100StartAuthentication extends AbnahmeTestCase {

  public Test100StartAuthentication(String name) {
    super(name);
  }

  public void testA101() throws Exception {
    try {
      String htmlForm = server.startAuthentication("https://localhost:8443/auth", //authURL
        "gb", //target
        "http://localhost:9080/", //oaURL
        "file:" + findXmldata("AuthTemplate.html"), 
        "http://localhost:3495/http-security-layer-request",
         null);
      htmlForm = killExclusive(htmlForm, "MOASessionID=","\"","DELETED");
      //writeXmldata("htmlForm_out.html",htmlForm.getBytes("UTF-8"));
      assertEquals(readXmldata("htmlForm.html"),htmlForm);
      System.out.println("-----------------------\nTestfall " + this.getName() + " erfolgreich abgearbeitet! \n-----------------------");
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }

  public void testA102() throws Exception {
    try {
      String htmlForm = server.startAuthentication("https://localhost:8443/auth", //authURL
        "gb", //target
        "http://localhost:9080/", //oaURL
        null, 
        "http://localhost:3495/http-security-layer-request", null);
      htmlForm = killExclusive(htmlForm, "MOASessionID=","\"","DELETED");
      //writeXmldata("htmlForm_out.html",htmlForm.getBytes("UTF-8"));
      assertEquals(readXmldata("htmlForm.html"),htmlForm);

      System.out.println("-----------------------\nTestfall " + this.getName() + " erfolgreich abgearbeitet! \n-----------------------");
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }
 public void testA103() throws Exception {
    try {
      String htmlForm = server.startAuthentication("https://localhost:8443/auth", //authURL
        "gb", //target
        "http://localhost:9080/", //oaURL
        "file:" + findXmldata("AuthTemplate.html"), 
         null,
         null);
      htmlForm = killExclusive(htmlForm, "MOASessionID=","\"","DELETED");
      //writeXmldata("htmlForm_out.html",htmlForm.getBytes("UTF-8"));
      assertEquals(readXmldata("htmlForm.html"),htmlForm);
      System.out.println("-----------------------\nTestfall " + this.getName() + " erfolgreich abgearbeitet! \n-----------------------");
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }

  public void testA151() throws Exception {
    try {
      try {
        server.startAuthentication(null, //authURL
        "gb", //target
        "http://localhost:9080/", //oaURL
        null, null, null);
        //assertEquals("",htmlForm);  
        System.err.println(this.getName() + " hat KEINE FEHLER geworfen");
        fail(this.getName() + " hat KEINE FEHLER geworfen");
      }
      catch (WrongParametersException e) {
        System.out.println("-----------------------\nFehler in " + this.getName() + " erfolgreich abgefangen: " + e.getLocalizedMessage() + "\n-----------------------");
      }

    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }
  public void testA152() throws Exception {
    try {
      try {
        server.startAuthentication("http://localhost:8080/auth", //authURL
        "gb", "http://localhost:9080/", //oaURL
        null, null, null);
        System.err.println(this.getName() + " hat KEINE FEHLER geworfen");
        fail(this.getName() + " hat KEINE FEHLER geworfen");
      }
      catch (AuthenticationException e) {
        System.out.println("-----------------------\nFehler in " + this.getName() + " erfolgreich abgefangen: " + e.getLocalizedMessage() + "\n-----------------------");
      }
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }
  public void testA153() throws Exception {
    try {
      try {
        server.startAuthentication("https://localhost:8443/auth", //authURL
        "gb", "http://host_not_in_config/", //oaURL
        null, null, null);
        System.err.println(this.getName() + " hat KEINE FEHLER geworfen");
        fail(this.getName() + " hat KEINE FEHLER geworfen");
      }
      catch (AuthenticationException e) {
        System.out.println("-----------------------\nFehler in " + this.getName() + " erfolgreich abgefangen: " + e.getLocalizedMessage() + "\n-----------------------");
      }

    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }
  public void testA154() throws Exception {
    try {
      try {
        server.startAuthentication("https://localhost:8443/auth", //authURL
        "gb", null, //oaURL
        null, null, null);
        System.err.println(this.getName() + " hat KEINE FEHLER geworfen");
        fail(this.getName() + " hat KEINE FEHLER geworfen");
      }
      catch (WrongParametersException e) {
        System.out.println("-----------------------\nFehler in " + this.getName() + " erfolgreich abgefangen: " + e.getLocalizedMessage() + "\n-----------------------");
      }
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }

  public void testA155() throws Exception {
    try {
      try {
        server.startAuthentication("https://localhost:8443/auth", //authURL
        null, "http://localhost:9080/", //oaURL
        null, null, null);
        System.err.println(this.getName() + " hat KEINE FEHLER geworfen");
        fail(this.getName() + " hat KEINE FEHLER geworfen");
      }
      catch (WrongParametersException e) {
        System.out.println("-----------------------\nFehler in " + this.getName() + " erfolgreich abgefangen: " + e.getLocalizedMessage() + "\n-----------------------");
      }
      //assertEquals("",htmlForm);  
    }
    catch (Exception e) {
      System.err.println("------ FEHLER IN " + this.getName() + ":" + e.getLocalizedMessage());
      throw e;
    }
  }

}