01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.jee.wls;
17:
18: import junit.framework.TestCase;
19:
20: import javax.xml.bind.JAXBElement;
21:
22: import org.custommonkey.xmlunit.Diff;
23:
24: import java.io.InputStream;
25: import java.io.ByteArrayInputStream;
26: import java.io.IOException;
27: import java.io.BufferedInputStream;
28:
29: /**
30: * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
31: */
32: public class JaxbWlsTest extends TestCase {
33:
34: public void testVersion9() throws Exception {
35: marshallAndUnmarshall("wls-ejb-jar.xml");
36: }
37:
38: public void testVersion8() throws Exception {
39: marshallAndUnmarshall("wls-v81-ejb-jar.xml");
40: }
41:
42: public void marshallAndUnmarshall(String xmlFile) throws Exception {
43:
44: InputStream in = this .getClass().getClassLoader()
45: .getResourceAsStream(xmlFile);
46: String expected = readContent(in);
47:
48: Object object = JaxbWls.unmarshal(WeblogicEjbJar.class,
49: new ByteArrayInputStream(expected.getBytes()));
50:
51: JAXBElement element = (JAXBElement) object;
52:
53: assertTrue(element.getValue() instanceof WeblogicEjbJar);
54:
55: String actual = JaxbWls.marshal(WeblogicEjbJar.class, element);
56:
57: Diff myDiff = new Diff(expected, actual);
58: assertTrue("Files are similar " + myDiff, myDiff.similar());
59: }
60:
61: private String readContent(InputStream in) throws IOException {
62: StringBuffer sb = new StringBuffer();
63: in = new BufferedInputStream(in);
64: int i = in.read();
65: while (i != -1) {
66: sb.append((char) i);
67: i = in.read();
68: }
69: String content = sb.toString();
70: return content;
71: }
72: }
|