01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.meta;
20:
21: import java.io.ByteArrayInputStream;
22: import java.io.ByteArrayOutputStream;
23: import java.io.InputStreamReader;
24: import java.io.OutputStreamWriter;
25:
26: import org.apache.openjpa.persistence.meta.common.apps.MetaTest1;
27: import org.apache.openjpa.persistence.meta.common.apps.MetaTest2;
28: import org.apache.openjpa.persistence.meta.common.apps.MetaTest3;
29: import org.apache.openjpa.persistence.meta.common.apps.MetaTest5;
30: import org.apache.openjpa.persistence.meta.common.apps.MetaTest6;
31: import org.apache.openjpa.conf.OpenJPAConfiguration;
32: import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
33: import org.apache.openjpa.meta.MetaDataRepository;
34: import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser;
35: import org.apache.openjpa.persistence.XMLPersistenceMetaDataSerializer;
36:
37: /**
38: * <p>Tests the {@link MetaDataSerializer} by parsing all the metadata
39: * files, serializing them to a buffer, then deserializing them from the
40: * buffer and invoking the tests defined by {@link TestClassMetaData}.</p>
41: *
42: * @author Abe White
43: */
44: public class TestXMLPersistenceMetaDataSerializer extends
45: TestClassMetaData {
46:
47: public TestXMLPersistenceMetaDataSerializer(String test) {
48: super (test);
49: }
50:
51: protected MetaDataRepository getRepository() throws Exception {
52: OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
53: MetaDataRepository repos = conf.newMetaDataRepositoryInstance();
54: repos.getMetaData(MetaTest5.class, null, true);
55: repos.getMetaData(MetaTest3.class, null, true);
56: repos.getMetaData(MetaTest2.class, null, true);
57: repos.getMetaData(MetaTest1.class, null, true);
58: repos.getMetaData(MetaTest6.class, null, true);
59:
60: XMLPersistenceMetaDataSerializer ser = new XMLPersistenceMetaDataSerializer(
61: conf);
62: ser.addAll(repos);
63: ByteArrayOutputStream out = new ByteArrayOutputStream();
64: ser.serialize(new OutputStreamWriter(out), ser.PRETTY);
65: byte[] bytes = out.toByteArray();
66:
67: XMLPersistenceMetaDataParser parser = new XMLPersistenceMetaDataParser(
68: conf);
69: parser.parse(new InputStreamReader(new ByteArrayInputStream(
70: bytes)), "bytes");
71: return parser.getRepository();
72: }
73: }
|