01: /*
02: * TestXMLSchemaSerializer.java
03: *
04: * Created on October 6, 2006, 4:47 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: /*
11: * Licensed to the Apache Software Foundation (ASF) under one
12: * or more contributor license agreements. See the NOTICE file
13: * distributed with this work for additional information
14: * regarding copyright ownership. The ASF licenses this file
15: * to you under the Apache License, Version 2.0 (the
16: * "License"); you may not use this file except in compliance
17: * with the License. You may obtain a copy of the License at
18: *
19: * http://www.apache.org/licenses/LICENSE-2.0
20: *
21: * Unless required by applicable law or agreed to in writing,
22: * software distributed under the License is distributed on an
23: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24: * KIND, either express or implied. See the License for the
25: * specific language governing permissions and limitations
26: * under the License.
27: */
28: package org.apache.openjpa.persistence.jdbc.schema;
29:
30: import java.io.ByteArrayInputStream;
31: import java.io.ByteArrayOutputStream;
32: import java.io.InputStreamReader;
33: import java.io.OutputStreamWriter;
34: import java.util.*;
35: import org.apache.openjpa.jdbc.schema.SchemaGroup;
36: import org.apache.openjpa.jdbc.schema.SchemaParser;
37: import org.apache.openjpa.jdbc.schema.SchemaSerializer;
38: import org.apache.openjpa.jdbc.schema.XMLSchemaParser;
39: import org.apache.openjpa.jdbc.schema.XMLSchemaSerializer;
40:
41: import org.apache.openjpa.persistence.jdbc.common.apps.*;
42:
43: import java.lang.annotation.Annotation;
44: import junit.framework.*;
45: import javax.persistence.EntityManager;
46: import javax.persistence.EntityManagerFactory;
47: import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
48: import org.apache.openjpa.persistence.OpenJPAEntityManager;
49:
50: public class TestXMLSchemaSerializer extends TestXMLSchemaParser {
51:
52: /** Creates a new instance of TestXMLSchemaSerializer */
53: public TestXMLSchemaSerializer() {
54: }
55:
56: public TestXMLSchemaSerializer(String test) {
57: super (test);
58: }
59:
60: protected SchemaGroup getSchemaGroup() throws Exception {
61: // parse in the schema group, then serialize it to a buffer, then
62: // recreate it and test againt that to make sure it's the same as the
63: // original
64: SchemaGroup group = parseSchemaGroup();
65: SchemaSerializer ser = new XMLSchemaSerializer(this .conf);
66: ser.addAll(group);
67:
68: ByteArrayOutputStream out = new ByteArrayOutputStream();
69: ser.serialize(new OutputStreamWriter(out), ser.PRETTY);
70: byte[] bytes = out.toByteArray();
71:
72: SchemaParser parser = new XMLSchemaParser(this .conf);
73: parser.parse(new InputStreamReader(new ByteArrayInputStream(
74: bytes)), "bytes");
75: return parser.getSchemaGroup();
76: }
77:
78: public static void main(String[] args) {
79: // main(TestXMLSchemaSerializer.class);
80: }
81: }
|