2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.server.component.abstractorderedlayout;
18 import java.util.Arrays;
19 import java.util.List;
21 import org.junit.Test;
23 import com.vaadin.shared.ui.label.ContentMode;
24 import com.vaadin.tests.server.component.DeclarativeMarginTestBase;
25 import com.vaadin.ui.AbstractOrderedLayout;
26 import com.vaadin.ui.Alignment;
27 import com.vaadin.ui.Button;
28 import com.vaadin.ui.Label;
29 import com.vaadin.ui.VerticalLayout;
32 * Tests declarative support for AbstractOrderedLayout.
37 public class AbstractOrderedLayoutDeclarativeTest
38 extends DeclarativeMarginTestBase<AbstractOrderedLayout> {
40 private List<String> defaultAlignments = Arrays.asList(":top", ":left");
43 public void testMargins() {
44 testMargins("vaadin-vertical-layout");
48 public void testExpandRatio() {
49 String design = getDesign(1);
50 AbstractOrderedLayout layout = getLayout(1, null);
51 testRead(design, layout);
52 testWrite(design, layout);
53 design = getDesign(0.25f);
54 layout = getLayout(0.25f, null);
55 testRead(design, layout);
56 testWrite(design, layout);
60 public void testAlignment() {
61 String design = getDesign(0, ":top", ":left");
62 AbstractOrderedLayout layout = getLayout(0, Alignment.TOP_LEFT);
63 testRead(design, layout);
64 testWrite(design, layout);
65 design = getDesign(0, ":middle", ":center");
66 layout = getLayout(0, Alignment.MIDDLE_CENTER);
67 testRead(design, layout);
68 testWrite(design, layout);
69 design = getDesign(0, ":bottom", ":right");
70 layout = getLayout(0, Alignment.BOTTOM_RIGHT);
71 testRead(design, layout);
72 testWrite(design, layout);
75 private String getDesign(float expandRatio, String... alignments) {
76 String result = "<vaadin-vertical-layout caption=test-layout>";
77 result += "<vaadin-label caption=test-label ";
78 String ratioString = expandRatio == 1.0f ? null
79 : String.valueOf(expandRatio);
80 if (expandRatio != 0) {
81 if (ratioString == null) {
84 result += ":expand=" + ratioString;
87 for (String alignment : alignments) {
88 if (!defaultAlignments.contains(alignment)) {
89 result += " " + alignment;
92 result += "></vaadin-label><vaadin-button ";
93 if (expandRatio != 0) {
94 if (ratioString == null) {
97 result += ":expand=" + ratioString;
100 for (String alignment : alignments) {
101 if (!defaultAlignments.contains(alignment)) {
102 result += " " + alignment;
105 result += "></vaadin-button></vaadin-vertical-layout>";
109 private AbstractOrderedLayout getLayout(float expandRatio,
110 Alignment alignment) {
111 VerticalLayout layout = new VerticalLayout();
112 layout.setCaption("test-layout");
113 Label l = new Label();
114 l.setCaption("test-label");
115 l.setContentMode(ContentMode.HTML);
116 layout.addComponent(l);
117 layout.setExpandRatio(l, expandRatio);
118 Button b = new Button();
119 b.setCaptionAsHtml(true);
120 layout.addComponent(b);
121 layout.setExpandRatio(b, expandRatio);
122 if (alignment != null) {
123 layout.setComponentAlignment(l, alignment);
124 layout.setComponentAlignment(b, alignment);