aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/tests/design/EmbeddedsTest.java
blob: 962614683c3cab3b8b44a56e9839c72e81804c23 (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
83
84
85
86
87
88
89
90
package com.vaadin.tests.design;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.junit.Test;

import com.vaadin.server.ExternalResource;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.AbstractEmbedded;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Flash;
import com.vaadin.ui.Image;
import com.vaadin.ui.declarative.Design;

/**
 * Tests declarative support for implementations of {@link AbstractEmbedded} and
 * {@link Embedded}.
 *
 * @since 7.4
 * @author Vaadin Ltd
 */
public class EmbeddedsTest {

    public static final boolean equals(ExternalResource obj,
            ExternalResource other) {
        return SharedUtil.equals(obj.getURL(), other.getURL())
                && SharedUtil.equals(obj.getMIMEType(), other.getMIMEType());
    }

    @Test
    public void testAbstractEmbeddedsToFromDesign() throws Exception {
        for (AbstractEmbedded ae : new AbstractEmbedded[] { new Image(),
                new Flash(), new BrowserFrame() }) {
            ae.setSource(new ExternalResource("http://www.example.org"));
            ae.setAlternateText("some alternate text");
            ae.setCaption("some <b>caption</b>");
            ae.setCaptionAsHtml(true);
            ae.setDescription("some description");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Design.write(ae, bos);
            AbstractEmbedded result = (AbstractEmbedded) Design
                    .read(new ByteArrayInputStream(bos.toByteArray()));
            assertTrue(equals((ExternalResource) ae.getSource(),
                    (ExternalResource) result.getSource()));
            assertEquals(ae.getAlternateText(), result.getAlternateText());
            assertEquals(ae.getCaption(), result.getCaption());
            assertEquals(ae.isCaptionAsHtml(), result.isCaptionAsHtml());
            assertEquals(ae.getDescription(), result.getDescription());
        }
    }

    @Test
    public void testFlashToFromDesign() throws Exception {
        Flash ae = new Flash();
        ae.setSource(new ExternalResource("http://www.example.org"));
        ae.setAlternateText("some alternate text");
        ae.setCaption("some <b>caption</b>");
        ae.setCaptionAsHtml(true);
        ae.setDescription("some description");
        ae.setCodebase("codebase");
        ae.setArchive("archive");
        ae.setCodetype("codetype");
        ae.setParameter("foo", "bar");
        ae.setParameter("something", "else");
        ae.setStandby("foobar");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Design.write(ae, bos);
        Flash result = (Flash) Design
                .read(new ByteArrayInputStream(bos.toByteArray()));
        assertTrue(equals((ExternalResource) ae.getSource(),
                (ExternalResource) result.getSource()));
        assertEquals(ae.getAlternateText(), result.getAlternateText());
        assertEquals(ae.getCaption(), result.getCaption());
        assertEquals(ae.isCaptionAsHtml(), result.isCaptionAsHtml());
        assertEquals(ae.getDescription(), result.getDescription());
        assertEquals(ae.getCodebase(), result.getCodebase());
        assertEquals(ae.getArchive(), result.getArchive());
        assertEquals(ae.getCodetype(), result.getCodetype());
        assertEquals(ae.getParameter("foo"), result.getParameter("foo"));
        assertEquals(ae.getParameter("something"),
                result.getParameter("something"));
        assertEquals(ae.getStandby(), result.getStandby());
    }

}