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.colorpicker;
18 import org.junit.Test;
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;
26 * Abstract test class which contains tests for declarative format for
27 * properties that are common for AbstractColorPicker.
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.
37 public abstract class AbstractColorPickerDeclarativeTest<T extends AbstractColorPicker>
38 extends AbstractFieldDeclarativeTest<T, Color> {
41 public void testAllAbstractColorPickerFeatures()
42 throws InstantiationException, IllegalAccessException {
43 boolean defaultCaption = true;
44 PopupStyle popupStyle = PopupStyle.POPUP_SIMPLE;
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);
59 T colorPicker = getComponentClass().newInstance();
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);
70 testWrite(design, colorPicker);
71 testRead(design, colorPicker);
75 public void valueDeserialization()
76 throws InstantiationException, IllegalAccessException {
77 String rgb = "fafafa";
78 String design = String.format("<%s color='#%s'/>", getComponentTag());
80 T colorPicker = getComponentClass().newInstance();
81 int colorInt = Integer.parseInt(rgb, 16);
83 colorPicker.setValue(new Color(colorInt));
85 testWrite(design, colorPicker);
86 testRead(design, colorPicker);
90 public void readOnlyValue()
91 throws InstantiationException, IllegalAccessException {
92 String rgb = "fafafa";
93 String design = String.format("<%s color='#%s' readonly/>",
96 T colorPicker = getComponentClass().newInstance();
97 int colorInt = Integer.parseInt(rgb, 16);
99 colorPicker.setValue(new Color(colorInt));
100 colorPicker.setReadOnly(true);
102 testWrite(design, colorPicker);
103 testRead(design, colorPicker);