use of org.openhab.core.i18n.TranslationProvider in project openhab-addons by openhab.
the class NetatmoModuleDiscoveryServiceTest method before.
@BeforeEach
public void before() {
Bridge bridgeMock = mock(Bridge.class);
when(bridgeMock.getUID()).thenReturn(new ThingUID("netatmo", "bridge"));
bridgeHandlerSpy = spy(new NetatmoBridgeHandler(bridgeMock, null));
LocaleProvider localeProviderMock = mock(LocaleProvider.class);
TranslationProvider translationProvider = mock(TranslationProvider.class);
service = new NetatmoModuleDiscoveryServiceAccessible(bridgeHandlerSpy, localeProviderMock, translationProvider);
}
use of org.openhab.core.i18n.TranslationProvider in project openhab-core by openhab.
the class ProgressCallbackTest method setUp.
@BeforeEach
public void setUp() {
expectedFirmware = FirmwareBuilder.create(THING_TYPE, "1").build();
postedEvents.clear();
EventPublisher publisher = new EventPublisher() {
@Override
public void post(Event event) throws IllegalArgumentException, IllegalStateException {
postedEvents.add(event);
}
};
TranslationProvider i18nProvider = new TranslationProvider() {
@Override
@Nullable
public String getText(@Nullable Bundle bundle, @Nullable String key, @Nullable String defaultText, @Nullable Locale locale, @Nullable Object@Nullable ... arguments) {
usedMessagedKey = key;
return "Dummy Message";
}
@Override
@Nullable
public String getText(@Nullable Bundle bundle, @Nullable String key, @Nullable String defaultText, @Nullable Locale locale) {
usedMessagedKey = key;
return "Dummy Message";
}
};
Bundle bundle = mock(Bundle.class);
when(bundle.getSymbolicName()).thenReturn("");
BundleResolver bundleResolver = mock(BundleResolver.class);
when(bundleResolver.resolveBundle(any(Class.class))).thenReturn(bundle);
sut = new ProgressCallbackImpl(new DummyFirmwareHandler(), publisher, i18nProvider, bundleResolver, EXPECTED_THING_UID, expectedFirmware, null);
}
use of org.openhab.core.i18n.TranslationProvider in project openhab-core by openhab.
the class BindingBaseClassesOSGiTest method assertConfigStatusIsPropagated.
@Test
public void assertConfigStatusIsPropagated() throws Exception {
ConfigStatusProviderThingHandlerFactory thingHandlerFactory = new ConfigStatusProviderThingHandlerFactory();
thingHandlerFactory.activate(componentContextMock);
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId:type");
ThingUID thingUID = new ThingUID("bindingId:type:thingId");
Thing thing = ThingBuilder.create(thingTypeUID, thingUID).build();
managedThingProvider.add(thing);
ConfigStatusService service = getService(ConfigStatusService.class);
TranslationProvider translationProvider = mock(TranslationProvider.class);
when(translationProvider.getText(nullable(Bundle.class), nullable(String.class), nullable(String.class), nullable(Locale.class), nullable(Object[].class))).then(new Answer<String>() {
@Override
@Nullable
public String answer(InvocationOnMock invocation) throws Throwable {
String key = (String) invocation.getArgument(1);
return key.endsWith("param.invalid") ? "param invalid" : "param ok";
}
});
Field field = service.getClass().getDeclaredField("translationProvider");
field.setAccessible(true);
field.set(service, translationProvider);
ConfigStatusInfoEventSubscriber eventSubscriber = new ConfigStatusInfoEventSubscriber(thingUID);
registerService(eventSubscriber, EventSubscriber.class.getName());
Thread.sleep(2000);
thing.getHandler().handleConfigurationUpdate(Map.of("param", "invalid"));
waitForAssert(() -> {
Event event = eventSubscriber.getReceivedEvent();
assertThat(event, is(notNullValue()));
assertThat(event.getPayload(), CoreMatchers.containsString("\"parameterName\":\"param\",\"type\":\"ERROR\",\"message\":\"param invalid\"}"));
eventSubscriber.resetReceivedEvent();
}, 2500, DFL_SLEEP_TIME);
thing.getHandler().handleConfigurationUpdate(Map.of("param", "ok"));
waitForAssert(() -> {
Event event = eventSubscriber.getReceivedEvent();
assertThat(event, is(notNullValue()));
assertThat(event.getPayload(), CoreMatchers.containsString("\"parameterName\":\"param\",\"type\":\"INFORMATION\",\"message\":\"param ok\"}"));
}, 2500, DFL_SLEEP_TIME);
}
use of org.openhab.core.i18n.TranslationProvider in project openhab-core by openhab.
the class TranslationProviderOSGiTest method setup.
@BeforeEach
public void setup() {
translationProvider = getService(TranslationProvider.class);
LocaleProvider localeProvider = getService(LocaleProvider.class);
Map<String, Object> localeCfg = new HashMap<>();
localeCfg.put("language", "de");
localeCfg.put("region", "DE");
((I18nProviderImpl) localeProvider).modified(localeCfg);
}
use of org.openhab.core.i18n.TranslationProvider in project openhab-core by openhab.
the class ConfigStatusServiceTest method getTranslationProvider.
private TranslationProvider getTranslationProvider() {
TranslationProvider translationProvider = mock(TranslationProvider.class);
when(translationProvider.getText(any(), anyString(), eq(null), any(), any())).thenAnswer(invocation -> {
String key = invocation.getArgument(1);
Locale locale = invocation.getArgument(3);
if (LOCALE_DE.equals(locale)) {
if (key.endsWith(MSG_KEY1)) {
return MSG1_DE;
} else if (key.endsWith(MSG_KEY2)) {
return MessageFormat.format(MSG2_DE, ARGS);
} else if (key.endsWith(MSG_KEY3)) {
return MessageFormat.format(MSG3_DE, ARGS);
}
} else {
if (key.endsWith(MSG_KEY1)) {
return MSG1_EN;
} else if (key.endsWith(MSG_KEY2)) {
return MessageFormat.format(MSG2_EN, ARGS);
} else if (key.endsWith(MSG_KEY3)) {
return MessageFormat.format(MSG3_EN, ARGS);
}
}
return null;
});
return translationProvider;
}
Aggregations