/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.dynamic.data.mapping.type.grid.internal;
import com.liferay.dynamic.data.mapping.model.DDMFormFieldOptions;
import com.liferay.portal.kernel.util.LocaleUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Pedro Queiroz
*/
public class GridDDMFormFieldContextHelperTest {
@Test
public void testGetOptions() {
List<Object> expectedOptions = new ArrayList<>();
expectedOptions.add(createOption("Label 1", "value 1"));
expectedOptions.add(createOption("Label 2", "value 2"));
expectedOptions.add(createOption("Label 3", "value 3"));
DDMFormFieldOptions ddmFormFieldOptions = createDDMFormFieldOptions();
List<Object> actualOptions = getActualOptions(
ddmFormFieldOptions, LocaleUtil.US);
Assert.assertEquals(expectedOptions, actualOptions);
}
protected DDMFormFieldOptions createDDMFormFieldOptions() {
DDMFormFieldOptions ddmFormFieldOptions = new DDMFormFieldOptions();
ddmFormFieldOptions.addOptionLabel("value 1", LocaleUtil.US, "Label 1");
ddmFormFieldOptions.addOptionLabel("value 2", LocaleUtil.US, "Label 2");
ddmFormFieldOptions.addOptionLabel("value 3", LocaleUtil.US, "Label 3");
return ddmFormFieldOptions;
}
protected Map<String, String> createOption(String label, String value) {
Map<String, String> option = new HashMap<>();
option.put("label", label);
option.put("value", value);
return option;
}
protected List<Object> getActualOptions(
DDMFormFieldOptions ddmFormFieldOptions, Locale locale) {
GridDDMFormFieldContextHelper gridDDMFormFieldContextHelper =
new GridDDMFormFieldContextHelper(ddmFormFieldOptions, locale);
return gridDDMFormFieldContextHelper.getOptions();
}
}