aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/tests/design/FieldNameWhichConflictsWithGettersTest.java
blob: b2aa689c6e2c5eeff8827674c448754fa2af8017 (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
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright 2000-2014 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.tests.design;

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.Assert;
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();
        Assert.assertNotNull(v.caption);
        Assert.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");

        Document doc = Jsoup.parse(str);
        Element body = doc.body();
        Element captionElement = body.getElementById("caption");
        Assert.assertNotNull(captionElement);
        Assert.assertEquals("vaadin-label", captionElement.tagName());

        Element descriptionElement = captionElement.nextElementSibling();
        Assert.assertNotNull(descriptionElement);
        Assert.assertEquals("vaadin-text-field", descriptionElement.tagName());
        Assert.assertEquals("description", descriptionElement.attr("_id"));

    }
}