/*******************************************************************************
 * Copyright (c) 2011 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
 * which accompanies this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 * Oracle = 2.2 - Initial implementation
 ******************************************************************************/
package org.eclipse.persistence.testing.jaxb.stax;

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

import junit.framework.TestCase;

public class XMLStreamWriterDefaultNamespaceTestCases extends TestCase {
    
    public void testDefaultNamespaceOverride() throws Exception {
        if(System.getProperty("java.version").contains("1.6")) {
        
            JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
            StringWriter writer = new StringWriter();
            XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
            streamWriter.writeStartElement("", "root", "someNamespace");
            streamWriter.writeDefaultNamespace("someNamespace");
            Marshaller marshaller = ctx.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, new Boolean(true));
        
            marshaller.marshal(new JAXBElement(new QName("employee"), Employee.class, new Employee()), streamWriter);
            streamWriter.writeEndElement();
            streamWriter.writeEndDocument();
            streamWriter.flush();
        
            String xml = "<root xmlns=\"someNamespace\"><employee xmlns=\"\"></employee></root>";
            assertTrue("Incorrect XML: " + writer.toString(), writer.toString().equals(xml));
        }
        
    }

}

@@ -1160,22 +1160,18 @@
 Case %7B%0D%0A
-    
 %0D%0A
+
     publ
@@ -1295,26 +1295,18 @@
 6%22)) %7B%0D%0A
-        
 %0D%0A
+
         
@@ -1837,34 +1837,26 @@
 an(true));%0D%0A
-        
 %0D%0A
+
             
@@ -2088,26 +2088,18 @@
 ush();%0D%0A
-        
 %0D%0A
+
         
@@ -2189,16 +2189,164 @@
 oot%3E%22;%0D%0A
+            String xml2 = %22%3Croot xmlns=%5C%22someNamespace%5C%22%3E%3Cemployee xmlns=%5C%22%5C%22/%3E%3C/root%3E%22;%0D%0A%0D%0A            String writerString = writer.toString();%0D%0A%0D%0A
         
@@ -2390,38 +2390,56 @@
 iter
-.toString(),
+String, writerString.equals(xml) %7C%7C
  writer
-.to
 String
-()
 .equ
@@ -2445,16 +2445,17 @@
 uals(xml
+2
 ));%0D%0A   
@@ -2462,24 +2462,16 @@
      %7D%0D%0A
-        
 %0D%0A    %7D%0D

Fix for bug 339765, reviewed by bdoughan.