1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.xml;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.apache.juneau.xml.annotation.XmlFormat.*;
21 import static org.junit.jupiter.api.Assertions.*;
22
23 import java.net.*;
24
25 import org.apache.juneau.*;
26 import org.apache.juneau.annotation.*;
27 import org.apache.juneau.xml.annotation.*;
28 import org.junit.jupiter.api.*;
29
30 class CommonXml_Test extends TestBase {
31
32
33
34
35 @Test void a01_beanUriAnnotation() throws Exception {
36 var p = XmlParser.DEFAULT;
37 var s = XmlSerializer.DEFAULT_SQ;
38
39 var t = new A("http://foo", 123, "bar");
40 var xml = s.serialize(t);
41 assertEquals("<object url='http://foo' id='123'><name>bar</name></object>", xml);
42
43 t = p.parse(xml, A.class);
44 assertEquals("http://foo", t.url.toString());
45 assertEquals(123, t.id);
46 assertEquals("bar", t.name);
47
48 validateXml(t, s);
49 }
50
51 @Bean(p="url,id,name")
52 public static class A {
53 @Xml(format=XmlFormat.ATTR) public URL url;
54 @Xml(format=ATTR) public int id;
55 public String name;
56 public A() {}
57 public A(String url, int id, String name) {
58 this.url = url(url);
59 this.id = id;
60 this.name = name;
61 }
62 }
63
64
65
66
67 @Test void a02_beanUriAnnotationOnlyUriProperty() throws Exception {
68 var s = XmlSerializer.create().sq().build();
69
70 var t = new B("http://foo");
71 var xml = s.serialize(t);
72 assertEquals("<object url='http://foo'><url2>http://foo/2</url2></object>", xml);
73 }
74
75 public static class B {
76 @Xml(format=XmlFormat.ATTR) public URL url;
77 public URL url2;
78 public B() {}
79 public B(String url) {
80 this.url = url(url);
81 this.url2 = url(url+"/2");
82 }
83 }
84 }