Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

[i18n] Added translation feature for label and description of channels inside a channel-group-type #5751

Merged
merged 6 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.core.thing.type;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

/**
* Tests the {@link ChannelGroupTypeBuilder}.
*
* @author Christoph Weitkamp - initial contribution
*/
public class ChannelGroupTypeBuilderTest {

private static final String DESCRIPTION = "description";
private static final String CATEGORY = "category";
private static final String LABEL = "label";
private static final ChannelGroupTypeUID CHANNEL_GROUP_TYPE_UID = new ChannelGroupTypeUID("bindingId",
"channelGroupId");

private ChannelGroupTypeBuilder builder;

@Before
public void setup() {
// set up a valid basic ChannelGroupTypeBuilder
builder = ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, LABEL);
}

@Test(expected = IllegalArgumentException.class)
public void whenLabelIsBlankForState_shouldFail() {
ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, "");
}

@Test
public void withLabelAndChannelGroupTypeUID_shouldCreateChannelGroupType() {
ChannelGroupType channelGroupType = builder.build();

assertEquals(CHANNEL_GROUP_TYPE_UID, channelGroupType.getUID());
assertEquals(LABEL, channelGroupType.getLabel());
}

@Test
public void withDefaultAdvancedIsFalse() {
ChannelGroupType channelGroupType = builder.build();

assertFalse(channelGroupType.isAdvanced());
}

@Test
public void isAdvanced_shouldSetAdvanced() {
ChannelGroupType channelGroupType = builder.isAdvanced(true).build();

assertTrue(channelGroupType.isAdvanced());
}

@Test
public void withDescription_shouldSetDescription() {
ChannelGroupType channelGroupType = builder.withDescription(DESCRIPTION).build();

assertEquals(DESCRIPTION, channelGroupType.getDescription());
}

@Test
public void withCategory_shouldSetCategory() {
ChannelGroupType channelGroupType = builder.withCategory(CATEGORY).build();

assertEquals(CATEGORY, channelGroupType.getCategory());
}

@Test
public void withChannelDefinitions_shouldSetUnmodifiableChannelDefinitions() {
ChannelGroupType channelGroupType = builder.withChannelDefinitions(mockList(ChannelDefinition.class, 2))
.build();

assertEquals(2, channelGroupType.getChannelDefinitions().size());
try {
channelGroupType.getChannelDefinitions().add(mock(ChannelDefinition.class));
fail();
} catch (UnsupportedOperationException e) {
// expected
}
}

private <T> List<T> mockList(Class<T> entityClass, int size) {
List<T> result = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
result.add(mock(entityClass));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<groupId>${tycho-groupid}</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<environments combine.self="override"></environments>
<dependency-resolution>
<extraRequirements>
<requirement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
package org.eclipse.smarthome.core.thing.xml.test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

import java.util.Collection;
import java.util.Locale;
Expand Down Expand Up @@ -42,10 +42,10 @@ public class ThingTypeI18nTest extends JavaOSGiTest {
@Before
public void setUp() {
thingTypeProvider = getService(ThingTypeProvider.class);
assertThat(thingTypeProvider, is(notNullValue()));
assertNotNull(thingTypeProvider);

channelTypeRegistry = getService(ChannelTypeRegistry.class);
assertThat(channelTypeRegistry, is(notNullValue()));
assertNotNull(channelTypeRegistry);
}

@After
Expand All @@ -59,17 +59,17 @@ public void thingTypeShouldBeLocalized() throws Exception {

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));

ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertThat(weatherType, is(notNullValue()));
assertNotNull(weatherType);

assertThat(weatherType.getLabel(), is("Wetterinformation"));
assertThat(weatherType.getDescription(), is("Stellt verschiedene Wetterdaten vom yahoo Wetterdienst bereit"));
assertThat(weatherType.getDescription(), is("Stellt verschiedene Wetterdaten vom Yahoo Wetterdienst bereit"));
}

@Test
Expand All @@ -78,18 +78,18 @@ public void channelGroupTypeShouldBeLocalized() throws Exception {

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));

ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertThat(weatherGroupType, is(notNullValue()));
assertNotNull(weatherGroupType);

ChannelGroupType channelGroupType = channelTypeRegistry
.getChannelGroupType(weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
assertThat(channelGroupType, is(notNullValue()));
assertNotNull(channelGroupType);

assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe"));
assertThat(channelGroupType.getDescription(), is("Wetterinformation mit Gruppe Beschreibung."));
Expand All @@ -101,56 +101,106 @@ public void channelGroupsShouldBeLocalized() throws Exception {

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));

ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertThat(weatherGroupType, is(notNullValue()));
assertNotNull(weatherGroupType);
assertThat(weatherGroupType.getChannelGroupDefinitions().size(), is(2));

ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertThat(forecastTodayChannelGroupDefinition, is(notNullValue()));
assertNotNull(forecastTodayChannelGroupDefinition);

assertThat(forecastTodayChannelGroupDefinition.getLabel(), is("Wettervorhersage heute"));
assertThat(forecastTodayChannelGroupDefinition.getDescription(), is("Wettervorhersage für den heutigen Tag."));

ChannelGroupDefinition forecastTomorrowChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastTomorrow")).findFirst().get();
assertThat(forecastTomorrowChannelGroupDefinition, is(notNullValue()));
assertNotNull(forecastTomorrowChannelGroupDefinition);

assertThat(forecastTomorrowChannelGroupDefinition.getLabel(), is("Wettervorhersage morgen"));
assertThat(forecastTomorrowChannelGroupDefinition.getDescription(),
is("Wettervorhersage für den morgigen Tag."));
}

@Test
public void channelsInGroupTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertEquals(initialNumberOfThingTypes + 2, thingTypes.size());

ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
assertEquals(2, weatherGroupType.getChannelGroupDefinitions().size());

ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);

ChannelGroupType forecastTodayChannelGroupType = channelTypeRegistry
.getChannelGroupType(forecastTodayChannelGroupDefinition.getTypeUID(), Locale.GERMAN);
assertNotNull(forecastTodayChannelGroupType);
assertEquals(3, forecastTodayChannelGroupType.getChannelDefinitions().size());

ChannelDefinition temperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("temperature")).findFirst().get();
assertNotNull(temperatureChannelDefinition);

assertEquals("Temperatur", temperatureChannelDefinition.getLabel());
assertEquals("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
temperatureChannelDefinition.getDescription());

ChannelDefinition minTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);

assertEquals("Min. Temperatur", minTemperatureChannelDefinition.getLabel());
assertEquals("Minimale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
minTemperatureChannelDefinition.getDescription());

ChannelDefinition maxTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("maxTemperature")).findFirst().get();
assertNotNull(maxTemperatureChannelDefinition);

assertEquals("Max. Temperatur", maxTemperatureChannelDefinition.getLabel());
assertEquals("Maximale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
maxTemperatureChannelDefinition.getDescription());
}

@Test
public void channelTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));

ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertThat(weatherType, is(notNullValue()));
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));

ChannelType temperatureChannelType = channelTypeRegistry.getChannelType(weatherType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("temperature")).findFirst().get().getChannelTypeUID(),
Locale.GERMAN);
assertThat(temperatureChannelType, is(notNullValue()));
assertNotNull(temperatureChannelType);

assertThat(temperatureChannelType.getLabel(), is("Temperatur"));
assertThat(temperatureChannelType.getDescription(),
is("Aktuelle Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
assertThat(temperatureChannelType.getState().getPattern(), is("%d Grad Celsius"));
assertThat(temperatureChannelType.getState().getOptions().get(0).getLabel(), is("Mein String"));
}
Expand All @@ -161,31 +211,30 @@ public void channelsShouldBeLocalized() throws Exception {

// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertNotNull(bundle);

Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));

ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertThat(weatherType, is(notNullValue()));
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));

ChannelDefinition temperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("temperature")).findFirst().get();
assertThat(temperatureChannelDefinition, is(notNullValue()));
assertNotNull(temperatureChannelDefinition);

assertThat(temperatureChannelDefinition.getLabel(), is("Temperatur"));
assertThat(temperatureChannelDefinition.getDescription(),
is("Aktuelle Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));

ChannelDefinition minTemperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertThat(minTemperatureChannelDefinition, is(notNullValue()));
assertNotNull(minTemperatureChannelDefinition);

assertThat(minTemperatureChannelDefinition.getLabel(), is("Min. Temperatur"));
assertThat(minTemperatureChannelDefinition.getDescription(),
is("Minimale Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
thing-type.yahooweather.weather.label = Wetterinformation

channel-group-type.yahooweather.forecast.label = Wetterinformation mit Gruppe
channel-group-type.yahooweather.forecast.description = Wetterinformation mit Gruppe Beschreibung.

thing-type.yahooweather.weather-with-group.group.forecastToday.label = Wettervorhersage heute
thing-type.yahooweather.weather-with-group.group.forecastToday.description = Wettervorhersage f�r den heutigen Tag.
thing-type.yahooweather.weather-with-group.group.forecastTomorrow.label = Wettervorhersage morgen
thing-type.yahooweather.weather-with-group.group.forecastTomorrow.description = Wettervorhersage f�r den morgigen Tag.

channel-type.yahooweather.temperature.label = Temperatur
channel-type.yahooweather.temperature.description = Aktuelle Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).
channel-type.yahooweather.temperature.description = Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).
channel-type.yahooweather.temperature.state.pattern = %d Grad Celsius
channel-type.yahooweather.temperature.state.option.VALUE = Mein String

thing-type.yahooweather.weather.channel.minTemperature.label = Min. Temperatur
thing-type.yahooweather.weather.channel.minTemperature.description = Minimale Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).
CUSTOM_KEY= Stellt verschiedene Wetterdaten vom yahoo Wetterdienst bereit

channel-group-type.yahooweather.forecast.channel.minTemperature.label = Min. Temperatur
channel-group-type.yahooweather.forecast.channel.minTemperature.description = Minimale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).
channel-group-type.yahooweather.forecast.channel.maxTemperature.label = Max. Temperatur
channel-group-type.yahooweather.forecast.channel.maxTemperature.description = Maximale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).

CUSTOM_KEY= Stellt verschiedene Wetterdaten vom Yahoo Wetterdienst bereit
Loading