This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 789
/
BindingInfoI18nTest.groovy
145 lines (119 loc) · 6 KB
/
BindingInfoI18nTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.core.binding.xml.test
import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.*
import static org.junit.matchers.JUnitMatchers.*
import org.eclipse.smarthome.core.binding.BindingInfo
import org.eclipse.smarthome.core.binding.BindingInfoRegistry
import org.eclipse.smarthome.core.i18n.LocaleProvider
import org.eclipse.smarthome.test.OSGiTest
import org.eclipse.smarthome.test.SyntheticBundleInstaller
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.osgi.framework.Bundle
import org.osgi.service.cm.Configuration
import org.osgi.service.cm.ConfigurationAdmin
class BindingInfoI18nTest extends OSGiTest {
static final String TEST_BUNDLE_NAME = "yahooweather.bundle"
BindingInfoRegistry bindingInfoRegistry
@Before
void setUp() {
bindingInfoRegistry = getService(BindingInfoRegistry)
assertThat bindingInfoRegistry, is(notNullValue())
}
@After
void tearDown() {
SyntheticBundleInstaller.uninstall(getBundleContext(), TEST_BUNDLE_NAME)
}
@Test
void 'assert binding infos were localized in German'() {
def bundleContext = getBundleContext()
def initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size()
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME)
assertThat bundle, is(notNullValue())
def bindingInfos = bindingInfoRegistry.getBindingInfos(Locale.GERMAN)
assertThat bindingInfos.size(), is(initialNumberOfBindingInfos + 1)
BindingInfo bindingInfo = bindingInfos.first()
assertThat bindingInfo, is(notNullValue())
assertEquals("""
name = Yahoo Wetter Binding
description = Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit
""", asString(bindingInfo))
}
@Test
void 'assert binding infos were localized in Dutch'() {
def bundleContext = getBundleContext()
def initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size()
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME)
assertThat bundle, is(notNullValue())
def bindingInfos = bindingInfoRegistry.getBindingInfos(new Locale("nl"))
assertThat bindingInfos.size(), is(initialNumberOfBindingInfos + 1)
BindingInfo bindingInfo = bindingInfos.first()
assertThat bindingInfo, is(notNullValue())
assertEquals("""
name = Yahoo Weer Binding
description = De Yahoo Weer Binding biedt verschillende meteorologische gegevens zoals temperatuur, vochtigheid en luchtdruk voor configureerbare locaties uit yahoo weerdienst klaar
""", asString(bindingInfo))
}
@Test
void 'assert using original binding infos, if provided locale is not supported'() {
def bundleContext = getBundleContext()
def initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size()
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME)
assertThat bundle, is(notNullValue())
def bindingInfos = bindingInfoRegistry.getBindingInfos(Locale.FRENCH)
assertThat bindingInfos.size(), is(initialNumberOfBindingInfos + 1)
BindingInfo bindingInfo = bindingInfos.first()
assertThat bindingInfo, is(notNullValue())
assertEquals("""
name = YahooWeather Binding
description = The Yahoo Weather Binding requests the Yahoo Weather Service to show the current temperature, humidity and pressure.
""", asString(bindingInfo))
}
@Test
void 'assert using default locale'() {
// Set german locale
ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class);
Configuration config = configAdmin.getConfiguration("org.eclipse.smarthome.core.i18nprovider");
Dictionary<String, String> localeCfg = new Hashtable<String, String>();
localeCfg.put("language", "de");
localeCfg.put("country", "DE");
config.update(localeCfg);
//before running the test with a default locale make sure the locale has been set
LocaleProvider localeProvider = getService(LocaleProvider.class);
waitForAssert {
assertThat localeProvider.getLocale().toString(), is("de")
}
def bundleContext = getBundleContext()
def initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size()
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME)
assertThat bundle, is(notNullValue())
def bindingInfos = bindingInfoRegistry.getBindingInfos(/*use default locale*/ null)
assertThat bindingInfos.size(), is(initialNumberOfBindingInfos + 1)
BindingInfo bindingInfo = bindingInfos.first()
assertThat bindingInfo, is(notNullValue())
assertEquals("""
name = Yahoo Wetter Binding
description = Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit
""", asString(bindingInfo))
}
String asString(final BindingInfo self) {
def name = self.getName()
def description = self.getDescription()
return """
name = ${name}
description = ${description}
"""
}
}