package org.eclipse.persistence.testing.jaxb.namespaceuri.schemacontext;

import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.QName;

import junit.framework.TestCase;

import org.eclipse.persistence.jaxb.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.oxm.XMLContext;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference;
import org.eclipse.persistence.oxm.schema.XMLSchemaReference;

public class SchemaContextAsQNameTest extends TestCase {
	private static String NAMESPACE_URI = "urn:org.eclipse.persistence.testing.jaxb.namespaceuri.schemacontext";
	private static String LOCAL_PART = "root";
	private static QName qName = new QName(NAMESPACE_URI, LOCAL_PART);
	
	public void testSchemaContextAsQName() {
		try {
			JAXBContext ctx = (JAXBContext) JAXBContextFactory.createContext(new Class[] { Root.class }, new HashMap());
			assertTrue("JAXBContext creation failed", ctx != null);
			XMLContext xCtx = ctx.getXMLContext();
			assertTrue("XMLContext is null", xCtx != null);
			XMLDescriptor xDesc = xCtx.getDescriptor(qName);
			assertTrue("No descriptor found for '{"+NAMESPACE_URI+"}"+LOCAL_PART+"'", xDesc != null);
			XMLSchemaReference sRef = xDesc.getSchemaReference();
			assertTrue("Expected SchemaContextAsQName [{"+NAMESPACE_URI+"}"+LOCAL_PART+"] but was was ["+sRef.getSchemaContextAsQName()+"]", sRef.getSchemaContextAsQName().equals(qName));
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}

@@ -117,24 +117,62 @@
 til.Map;%0D%0A%0D%0A
+import javax.xml.bind.JAXBException;%0D%0A
 import javax
@@ -228,24 +228,84 @@
 estCase;%0D%0A%0D%0A
+import org.eclipse.persistence.internal.oxm.XPathFragment;%0D%0A
 import org.e
@@ -965,21 +965,28 @@
 e() 
-%7B%0D%0A%09%09try
+throws Exception
  %7B%0D%0A
-%09
 %09%09JA
@@ -1091,25 +1091,24 @@
 hMap());%0D%0A%09%09
-%09
 assertTrue(%22
@@ -1148,25 +1148,24 @@
  != null);%0D%0A
-%09
 %09%09XMLContext
@@ -1192,25 +1192,24 @@
 ntext();%0D%0A%09%09
-%09
 assertTrue(%22
@@ -1242,24 +1242,198 @@
 != null);%0D%0A%09
+%09XPathFragment typeFragment = new XPathFragment();%0D%0A        typeFragment.setLocalName(qName.getLocalPart());%0D%0A        typeFragment.setNamespaceURI(qName.getNamespaceURI());%0D%0A
 %09%09XMLDescrip
@@ -1466,19 +1466,37 @@
 ptor
-(qName
+ByGlobalType(typeFragment
 );%0D%0A
-%09
 %09%09as
@@ -1586,17 +1586,16 @@
 ll);%0D%0A%09%09
-%09
 XMLSchem
@@ -1641,17 +1641,16 @@
 nce();%0D%0A
-%09
 %09%09assert
@@ -1824,65 +1824,8 @@
 );%0D%0A
-%09%09%7D catch (Throwable e) %7B%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A

Fix for bug# 289934 (MOXy Test: SchemaContextAsQName test doesn't work) Reviewed by: matt.macivor@oracle.com Test: actually works now