1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.client.webdav.binding.facets;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.InputStream;
20
21 import nl.hippo.client.api.ClientException;
22 import nl.hippo.client.api.content.FacetCollection;
23 import nl.hippo.client.webdav.binding.facets.FacetCollectionImpl;
24
25 import org.jibx.runtime.BindingDirectory;
26 import org.jibx.runtime.IBindingFactory;
27 import org.jibx.runtime.IMarshallingContext;
28 import org.jibx.runtime.IUnmarshallingContext;
29 import org.jibx.runtime.JiBXException;
30
31 import junit.framework.TestCase;
32
33
34
35 public class FacetsResultBindingTest extends TestCase {
36
37 private InputStream in;
38
39
40 public void setUp() {
41 in = FacetsResultBindingTest.class.getResourceAsStream("resources/facets.xml");
42 }
43
44 /**
45 * Unmarshal the sample document from a file, then marshal it back out to
46 * a Stream
47 * @throws ClientException
48 */
49 public void test() throws JiBXException, ClientException {
50
51
52
53
54 IBindingFactory bfact = BindingDirectory.getFactory(FacetCollectionImpl.class);
55
56
57 IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
58 FacetCollection facetCollection = (FacetCollection) uctx.unmarshalDocument(in, null);
59
60
61
62
63
64 IMarshallingContext mctx = bfact.createMarshallingContext();
65 mctx.setIndent(2);
66
67 ByteArrayOutputStream out = new ByteArrayOutputStream();
68 mctx.marshalDocument(facetCollection, "UTF-8", null, out);
69
70
71 String result = new String(out.toByteArray());
72 System.out.println(result);
73 }
74 }