]> source.dussan.org Git - vaadin-framework.git/blob
990121e7045b4beb4f9266a3d8f99050572332d4
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
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
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
14  * the License.
15  */
16 package com.vaadin.tests.server.component.colorpicker;
17
18 import org.junit.Test;
19
20 import com.vaadin.shared.ui.colorpicker.Color;
21 import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest;
22 import com.vaadin.ui.AbstractColorPicker;
23 import com.vaadin.ui.AbstractColorPicker.PopupStyle;
24
25 /**
26  * Abstract test class which contains tests for declarative format for
27  * properties that are common for AbstractColorPicker.
28  * <p>
29  * It's an abstract so it's not supposed to be run as is. Instead each
30  * declarative test for a real component should extend it and implement abstract
31  * methods to be able to test the common properties. Components specific
32  * properties should be tested additionally in the subclasses implementations.
33  *
34  * @author Vaadin Ltd
35  *
36  */
37 public abstract class AbstractColorPickerDeclarativeTest<T extends AbstractColorPicker>
38         extends AbstractFieldDeclarativeTest<T, Color> {
39
40     @Test
41     public void testAllAbstractColorPickerFeatures()
42             throws InstantiationException, IllegalAccessException {
43         boolean defaultCaption = true;
44         PopupStyle popupStyle = PopupStyle.POPUP_SIMPLE;
45         int x = 79;
46         int y = 91;
47         boolean rgbVisibility = false;
48         boolean hsvVisibility = false;
49         boolean swatchesVisibility = true;
50         boolean historyVisibility = false;
51         boolean textFieldVisibility = false;
52         String design = String.format(
53                 "<%s default-caption-enabled position='%s,%s'"
54                         + " popup-style='%s' rgb-visibility='%s' hsv-visibility='%s' "
55                         + "history-visibility='%s' textfield-visibility='%s'/>",
56                 getComponentTag(), x, y, popupStyle.toString(), rgbVisibility,
57                 hsvVisibility, historyVisibility, textFieldVisibility);
58
59         T colorPicker = getComponentClass().newInstance();
60
61         colorPicker.setDefaultCaptionEnabled(defaultCaption);
62         colorPicker.setPosition(x, y);
63         colorPicker.setPopupStyle(popupStyle);
64         colorPicker.setRGBVisibility(rgbVisibility);
65         colorPicker.setHSVVisibility(hsvVisibility);
66         colorPicker.setSwatchesVisibility(swatchesVisibility);
67         colorPicker.setHistoryVisibility(historyVisibility);
68         colorPicker.setTextfieldVisibility(textFieldVisibility);
69
70         testWrite(design, colorPicker);
71         testRead(design, colorPicker);
72     }
73
74     @Override
75     public void valueDeserialization()
76             throws InstantiationException, IllegalAccessException {
77         String rgb = "fafafa";
78         String design = String.format("<%s color='#%s'/>", getComponentTag());
79
80         T colorPicker = getComponentClass().newInstance();
81         int colorInt = Integer.parseInt(rgb, 16);
82
83         colorPicker.setValue(new Color(colorInt));
84
85         testWrite(design, colorPicker);
86         testRead(design, colorPicker);
87     }
88
89     @Override
90     public void readOnlyValue()
91             throws InstantiationException, IllegalAccessException {
92         String rgb = "fafafa";
93         String design = String.format("<%s color='#%s' readonly/>",
94                 getComponentTag());
95
96         T colorPicker = getComponentClass().newInstance();
97         int colorInt = Integer.parseInt(rgb, 16);
98
99         colorPicker.setValue(new Color(colorInt));
100         colorPicker.setReadOnly(true);
101
102         testWrite(design, colorPicker);
103         testRead(design, colorPicker);
104     }
105
106 }