blob: cf493fc56ec2dc230657b6a58eba834b4a57e923 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package com.vaadin.tests.design;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.Test;
import com.vaadin.annotations.DesignRoot;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.Design;
import com.vaadin.ui.declarative.DesignContext;
public class FieldNameWhichConflictsWithGettersTest {
@DesignRoot("MyVerticalLayout.html")
public static class MyVerticalLayout extends VerticalLayout {
private Label caption;
private TextField description;
public MyVerticalLayout() {
Design.read(this);
}
}
@Test
public void readWithConflictingFields() {
MyVerticalLayout v = new MyVerticalLayout();
assertNotNull(v.caption);
assertNotNull(v.description);
}
@Test
public void writeWithConflictingFields() throws IOException {
VerticalLayout v = new VerticalLayout();
Label l = new Label();
l.setId("caption");
TextField tf = new TextField();
v.addComponents(l, tf);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DesignContext context = new DesignContext();
context.setComponentLocalId(tf, "description");
context.setRootComponent(v);
Design.write(context, baos);
String str = baos.toString(UTF_8.name());
Document doc = Jsoup.parse(str);
Element body = doc.body();
Element captionElement = body.getElementById("caption");
assertNotNull(captionElement);
assertEquals("vaadin-label", captionElement.tagName());
Element descriptionElement = captionElement.nextElementSibling();
assertNotNull(descriptionElement);
assertEquals("vaadin-text-field", descriptionElement.tagName());
assertEquals("description", descriptionElement.attr("_id"));
}
}
|