public void testFailOnSecondErrorNodeWithClass() throws Exception {
   unmarshaller.setEventHandler(new CustomErrorValidationEventHandler());
   InputStream stream = ClassLoader.getSystemResourceAsStream(DOUBLE_ERROR_XML);
   XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
   XMLParser xmlParser = xmlPlatform.newXMLParser();
   xmlParser.setNamespaceAware(true);
   Node node = xmlParser.parse(stream);
   try {
     unmarshaller.setSchema(this.schema);
     unmarshaller.unmarshal(node, Employee.class);
   } catch (UnmarshalException ex) {
     assertTrue(true);
     return;
   } catch (UnsupportedOperationException uoe) {
     // XDK does not support setSchema, so just pass in this case
     assertTrue(true);
     return;
   }
   fail("No Exceptions thrown.");
 }
  public void testDeploymentXmlConversion() {
    XMLProjectReader reader = new XMLProjectReader();
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    XMLParser parser = xmlPlatform.newXMLParser();
    InputStream stream =
        ClassLoader.getSystemResourceAsStream(
            "org/eclipse/persistence/testing/oxm/deploymentxml/db-adapter-toplink-mapping-file.xml");
    Project proj = reader.read(new InputStreamReader(stream));

    StringWriter writer = new StringWriter();
    new XMLProjectWriter().write(proj, writer);

    parser.setNamespaceAware(true);
    parser.setWhitespacePreserving(false);
    String schema = XMLProjectReader.SCHEMA_DIR + XMLProjectReader.ECLIPSELINK_SCHEMA;
    parser.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    URL eclipselinkSchemaURL = getClass().getClassLoader().getResource(schema);
    parser.setEntityResolver(
        new EntityResolver() {

          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            if (XMLProjectReader.OPM_SCHEMA.equals(systemId)) {
              URL url =
                  getClass()
                      .getClassLoader()
                      .getResource(XMLProjectReader.SCHEMA_DIR + XMLProjectReader.OPM_SCHEMA);
              if (null == url) {
                return null;
              }
              return new InputSource(url.openStream());
            }
            return null;
          }
        });
    parser.setXMLSchema(eclipselinkSchemaURL);
    parser.parse(new StringReader(writer.toString()));
  }
@WebServiceProvider(
    targetNamespace = OPTLOCK_SERVICE_NAMESPACE,
    serviceName = OPTLOCK_SERVICE,
    portName = OPTLOCK_PORT)
@ServiceMode(MESSAGE)
public class OptLockTestSuite extends ProviderHelper implements Provider<SOAPMessage> {

  static final String CREATE_OPTLOCK_TABLE =
      "CREATE TABLE IF NOT EXISTS optlock ("
          + "\nID NUMERIC NOT NULL,"
          + "\nNAME VARCHAR(25),"
          + "\nDESCRIPT VARCHAR(20),"
          + "\nVERSION NUMERIC,"
          + "\nPRIMARY KEY (ID)"
          + "\n)";
  static final String[] POPULATE_OPTLOCK_TABLE =
      new String[] {
        "insert into optlock (ID, NAME, DESCRIPT, VERSION) values (1, 'name', 'this is ver 3', 3)"
      };
  static final String DROP_OPTLOCK_TABLE = "DROP TABLE optlock";

  static final String ENDPOINT_ADDRESS = "http://localhost:9999/" + OPTLOCK_TEST;

  // JUnit test fixtures
  static Connection conn = null;
  static ByteArrayOutputStream DBWS_SERVICE_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_SCHEMA_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_OR_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_OX_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_WSDL_STREAM = new ByteArrayOutputStream();
  static XMLComparer comparer = new XMLComparer();
  static XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
  static XMLParser xmlParser = xmlPlatform.newXMLParser();
  static Endpoint endpoint = null;
  static QName portQName = null;
  static Service testService = null;
  static DBWSBuilder builder = new DBWSBuilder();
  static final String username =
      System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
  static final String password =
      System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
  static final String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);

  static boolean ddlCreate = false;
  static boolean ddlDrop = false;
  static boolean ddlDebug = false;

  @BeforeClass
  public static void setUp() throws WSDLException {
    try {
      conn = buildConnection();
    } catch (Exception e) {
      e.printStackTrace();
    }
    String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
      ddlCreate = true;
    }
    String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
      ddlDrop = true;
    }
    String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
      ddlDebug = true;
    }
    if (ddlCreate) {
      runDdl(conn, CREATE_OPTLOCK_TABLE, ddlDebug);
      try {
        Statement stmt = conn.createStatement();
        for (int i = 0; i < POPULATE_OPTLOCK_TABLE.length; i++) {
          stmt.addBatch(POPULATE_OPTLOCK_TABLE[i]);
        }
        stmt.executeBatch();
      } catch (SQLException e) {
        if (ddlDebug) {
          e.printStackTrace();
        }
      }
    }
    builder.setProjectName(OPTLOCK_TEST);
    builder.setTargetNamespace(OPTLOCK_NAMESPACE);
    TableOperationModel tModel = new TableOperationModel();
    tModel.setName(OPTLOCK);
    tModel.setTablePattern(OPTLOCK);
    builder.getOperations().add(tModel);
    builder.quiet = true;
    // builder.setLogLevel(SessionLog.FINE_LABEL);
    builder.setLogLevel(SessionLog.OFF_LABEL);
    builder.setDriver(DATABASE_DRIVER);
    builder.setPlatformClassname(DATABASE_PLATFORM);
    builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
    builder.setUsername(username);
    builder.setPassword(password);
    builder.setUrl(url);
    builder.setPackager(
        new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {
          @Override
          public void start() {}
        });
    builder.build(
        DBWS_SCHEMA_STREAM,
        __nullStream,
        DBWS_SERVICE_STREAM,
        DBWS_OR_STREAM,
        DBWS_OX_STREAM,
        __nullStream,
        __nullStream,
        DBWS_WSDL_STREAM,
        __nullStream,
        __nullStream,
        __nullStream,
        __nullStream,
        null);
    endpoint = Endpoint.create(new OptLockTestSuite());
    endpoint.publish(ENDPOINT_ADDRESS);
    QName serviceQName = new QName(OPTLOCK_SERVICE_NAMESPACE, OPTLOCK_SERVICE);
    portQName = new QName(OPTLOCK_SERVICE_NAMESPACE, OPTLOCK_PORT);
    testService = Service.create(serviceQName);
    testService.addPort(portQName, SOAP11HTTP_BINDING, ENDPOINT_ADDRESS);
  }

  @AfterClass
  public static void teardown() {
    if (endpoint != null) {
      endpoint.stop();
    }
    if (ddlDrop) {
      runDdl(conn, DROP_OPTLOCK_TABLE, ddlDebug);
    }
  }

  @PreDestroy
  public void destroy() {
    super.destroy();
  }

  @Override
  protected InputStream initXRServiceStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_SERVICE_STREAM.toByteArray());
  }

  @Override
  protected InputStream initXRSchemaStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_SCHEMA_STREAM.toByteArray());
  }

  @Override
  protected InputStream initWSDLInputStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_WSDL_STREAM.toByteArray());
  }

  @PostConstruct
  public void init() {
    super.init(
        new XRDynamicClassLoader(Thread.currentThread().getContextClassLoader()), null, false);
  }

  @Override
  public void logoutSessions() {
    if (xrService.getORSession() != null) {
      ((DatabaseSession) xrService.getORSession()).logout();
    }
    if (xrService.getOXSession() != null) {
      ((DatabaseSession) xrService.getOXSession()).logout();
    }
  }

  @Override
  public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
      conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);

    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
      MetadataProcessor processor =
          new MetadataProcessor(
              new XRPersistenceUnitInfo(xrdecl),
              new DatabaseSessionImpl(login),
              xrdecl,
              false,
              true,
              false,
              false,
              false,
              null,
              null);
      processor.setMetadataSource(
          new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
      PersistenceUnitProcessor.processORMetadata(
          processor, true, PersistenceUnitProcessor.Mode.ALL);
      processor.addNamedQueries();
      orProject = processor.getProject().getProject();
    } else {
      orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
      databaseSession.dontLogMessages();
    } else {
      databaseSession.setLogLevel(
          AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);

    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
      JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
      Unmarshaller unmarshaller = jc.createUnmarshaller();

      JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
      XmlBindingsModel model = jaxbElt.getValue();
      for (XmlBindings xmlBindings : model.getBindingsList()) {
        metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
      }
    } catch (JAXBException jaxbex) {
      jaxbex.printStackTrace();
    }

    Map<String, Map<String, OXMMetadataSource>> properties =
        new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
      org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx =
          org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(
              parentClassLoader, properties);
      oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
      e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);

    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
  }

  static final String THE_INSTANCE =
      "<optlockType>"
          + "<id>1</id>"
          + "<name>name</name>"
          + "<descript>this is ver 2</descript>"
          + "<version>1</version>"
          + "</optlockType>";

  static final String REQUEST_MSG =
      "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" "
          + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
          + "<env:Header/>"
          + "<env:Body>"
          + "<srvc:update_OptlockType xmlns:srvc=\""
          + OPTLOCK_SERVICE_NAMESPACE
          + "\" "
          + "xmlns=\""
          + OPTLOCK_NAMESPACE
          + "\">"
          + "<srvc:theInstance>"
          + THE_INSTANCE
          + "</srvc:theInstance>"
          + "</srvc:update_OptlockType>"
          + "</env:Body>"
          + "</env:Envelope>";

  @Test
  public void updateinstanceTest()
      throws SOAPException, IOException, SAXException, ParserConfigurationException,
          TransformerException {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage request = factory.createMessage();
    SOAPPart part = request.getSOAPPart();
    DOMSource domSource =
        new DOMSource(getDocumentBuilder().parse(new InputSource(new StringReader(REQUEST_MSG))));
    part.setContent(domSource);
    Dispatch<SOAPMessage> dispatch =
        testService.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
    try {
      dispatch.invoke(request);
    } catch (SOAPFaultException sfe) {
      assertTrue("incorrect SOAPFaultException", sfe.getMessage().contains("EclipseLink-5010"));
    }
  }
}
 public NamespaceCollisionTestCases() {
   XMLPlatform platform = XMLPlatformFactory.getInstance().getXMLPlatform();
   parser = platform.newXMLParser();
 }