1 /*
   2  * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package test.astro;
  24 
  25 import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX;
  26 import static javax.xml.XMLConstants.NULL_NS_URI;
  27 import static org.testng.Assert.assertEquals;
  28 
  29 import javax.xml.namespace.QName;
  30 
  31 import jaxp.library.JAXPBaseTest;
  32 
  33 import org.testng.annotations.Test;
  34 
  35 /*
  36  * @summary javax.xml.namespace.QName  tests
  37  */
  38 public class NamespaceContextTest extends JAXPBaseTest {
  39     private static final String PREFIX = "astro";
  40     private static final String LOCAL_PART = "stardb";
  41     private static final String NS_URI = "http://www.astro.com";
  42 
  43     @Test
  44     public void testQNameConstructor() {
  45         QName qname = new QName(NS_URI, LOCAL_PART, PREFIX);
  46         assertEquals(qname.getNamespaceURI(), NS_URI);
  47         assertEquals(qname.getLocalPart(), LOCAL_PART);
  48         assertEquals(qname.getPrefix(), PREFIX);
  49     }
  50 
  51     @Test
  52     public void testDefaultFields() {
  53         QName qname = new QName(LOCAL_PART); // just the local part specified
  54         assertEquals(qname.getNamespaceURI(), NULL_NS_URI);
  55         assertEquals(qname.getLocalPart(), LOCAL_PART);
  56         assertEquals(qname.getPrefix(), DEFAULT_NS_PREFIX);
  57     }
  58 
  59     @Test
  60     public void testDefaultPrefix() {
  61         QName qname = new QName(NS_URI, LOCAL_PART); // no pref
  62         assertEquals(qname.getNamespaceURI(), NS_URI);
  63         assertEquals(qname.getLocalPart(), LOCAL_PART);
  64         assertEquals(qname.getPrefix(), DEFAULT_NS_PREFIX);
  65     }
  66 
  67     @Test
  68     public void testQNameString() {
  69         QName qname = new QName(NS_URI, LOCAL_PART, PREFIX);
  70         assertEquals(QName.valueOf(qname.toString()), qname);
  71     }
  72 }