/*******************************************************************************
 * 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:
 *     Blaise Doughan - 2.2 - initial implementation
 ******************************************************************************/
package org.eclipse.persistence.testing.jaxb.xmlmarshaller;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.ValidationException;
import javax.xml.bind.Validator;

import junit.framework.TestCase;

import org.eclipse.persistence.exceptions.XMLMarshalException;
import org.eclipse.persistence.jaxb.JAXBContextFactory;

public class NoSchemaRefTestCases extends TestCase {

    public void testValidateRootNoSchemaReference() {
        try {
            Class[] classes = {Address.class};
            JAXBContext jc = JAXBContextFactory.createContext(classes, null);
            Validator validator = jc.createValidator();
            validator.validateRoot(new Address());
        } catch(ValidationException e) {
            XMLMarshalException xme = (XMLMarshalException) e.getLinkedException();
            assertEquals(XMLMarshalException.ERROR_RESOLVING_XML_SCHEMA, xme.getErrorCode());
            return;
        } catch(JAXBException e) {
            fail("A JAXBException was thrown instead of the expected ValidationException.");
        }
        fail("No exception was thrown instead of the expected ValidationException.");
    }

    public void testValidateNoSchemaReference() throws JAXBException {
        Class[] classes = {Address.class};
        JAXBContext jc = JAXBContextFactory.createContext(classes, null);
        Validator validator = jc.createValidator();
        // We currently always return true for validate
        assertTrue(validator.validate(new Address()));
    }

}
@@ -1061,16 +1061,83 @@
 actory;%0D
+%0Aimport org.eclipse.persistence.platform.xml.XMLPlatformException;%0D
 %0A%0D%0Apubli
@@ -2041,24 +2041,43 @@
 xception %7B%0D%0A
+        try %7B%0D%0A    
         Clas
@@ -2100,32 +2100,36 @@
 ddress.class%7D;%0D%0A
+    
         JAXBCont
@@ -2187,32 +2187,36 @@
 null);%0D%0A        
+    
 Validator valida
@@ -2256,55 +2256,355 @@
     
-// We currently always return true for validate
+    validator.validate(new Address());%0D%0A        %7D catch (ValidationException e) %7B%0D%0A            XMLMarshalException xme = (XMLMarshalException) e.getLinkedException();%0D%0A            XMLPlatformException xpe = (XMLPlatformException) xme.getInternalException();%0D%0A            XMLMarshalException xme2 = (XMLMarshalException) xpe.getInternalException();
 %0D%0A  
@@ -2613,54 +2613,126 @@
     
+ 
+   
 assert
-True(validator.validate(new Address()));
+Equals(XMLMarshalException.ERROR_RESOLVING_XML_SCHEMA, xme2.getErrorCode());%0D%0A            return;%0D%0A        %7D
 %0D%0A  

Test case fix for bug 338820, reviewed by bdoughan