package org.jdom.tests;

import junit.framework.Test;
import junit.framework.TestSuite;
import junit.ui.LoadingTestRunner;

import org.jdom.IllegalNameException;
import org.jdom.Namespace;


public class NamespaceTest extends junit.framework.TestCase {
   

  public NamespaceTest(String name) {
    super(name); 
  }

  public void testDefaultNamespace() {
    
    String uri = "http://www.w3.org/TR/1999/Transform";
    Namespace ns = Namespace.getNamespace(uri);
    assertEquals(ns.getPrefix(), "");
    assertEquals(uri, ns.getURI());
    
  }
  
  public void testPrefixedNamespace() {
    
    String uri = "http://www.w3.org/TR/1999/Transform";
    String prefix = "xsl";
    Namespace ns = Namespace.getNamespace(prefix, uri);
    assertEquals(uri, ns.getURI());
    
  }
  
  public void testNoNamespace() {
    
    Namespace ns = Namespace.NO_NAMESPACE;
    assertNotNull(ns);
    assertEquals(ns.getPrefix(), "");
    assertEquals(ns.getURI(), "");
    
  }

  public void testEquals() {
    
    Namespace ns1A = Namespace.getNamespace("http://www.shty.com/sfdlhkakj");
    Namespace ns1B = Namespace.getNamespace("prefix", "http://www.shty.com/sfdlhkakj");
    Namespace ns1C = Namespace.getNamespace("another_prefix", "http://www.shty.com/sfdlhkakj");
    Namespace ns2B = Namespace.getNamespace("prefix", "http://www.shty.com/sfdlhkakj2");
    Namespace ns2C = Namespace.getNamespace("another_prefix", "http://www.shty.com/sfdlhkakj2");

    assertEquals(ns1A, ns1B);
    assertEquals(ns1B, ns1B);
    assertEquals(ns1C, ns1B);
    assertEquals(ns1C, ns1A);
    assert(!ns1B.equals(ns2B));
    assert(!ns1C.equals(ns2C));
    
  }
    
  public void testToString() {
    
    Namespace ns1A = Namespace.getNamespace("http://www.shty.com/sfdlhkakj");
    Namespace ns1B = Namespace.getNamespace("prefix", "http://www.shty.com/sfdlhkakj");

    assertNotNull(ns1A.toString());
    assertNotNull(ns1B.toString());
    assertNotNull(Namespace.NO_NAMESPACE.toString());
    
  }
    
  public void testHashCode() {
    
    Namespace ns1A = Namespace.getNamespace("http://www.shty.com/sfdlhkakj");
    Namespace ns1B = Namespace.getNamespace("prefix", "http://www.shty.com/sfdlhkakj");
    Namespace ns1C = Namespace.getNamespace("another_prefix", "http://www.shty.com/sfdlhkakj");

    assert(ns1A.hashCode() == ns1B.hashCode());
    assert(ns1B.hashCode() == ns1C.hashCode());
    assert(ns1A.hashCode() == ns1C.hashCode());
    
  }
  
  public static Test suite() { 
    return new TestSuite(NamespaceTest.class); 
  }

  public static void main (String[] args) {
    String[] tests = {"org.jdom.tests.NamespaceTest"};
    LoadingTestRunner.main(tests);
  }

}