use of org.openhab.core.automation.type.ModuleTypeProvider in project openhab-core by openhab.
the class AutomationIntegrationTest method testModuleTypeProviderAndTemplateProvider.
@Test
public void testModuleTypeProviderAndTemplateProvider() {
logger.info("test ModuleTypeProvider and TemplateProvider");
TemplateRegistry<RuleTemplate> templateRegistry = getService(TemplateRegistry.class);
ModuleTypeRegistry moduleTypeRegistry = getService(ModuleTypeRegistry.class);
String templateUID = "testTemplate1";
Set<String> tags = Stream.of("test", "testTag").collect(toSet());
List<Trigger> templateTriggers = Collections.emptyList();
List<Condition> templateConditions = Collections.emptyList();
List<Action> templateActions = Collections.emptyList();
List<ConfigDescriptionParameter> templateConfigDescriptionParameters = List.of(ConfigDescriptionParameterBuilder.create("param", ConfigDescriptionParameter.Type.TEXT).build());
RuleTemplate template = new RuleTemplate(templateUID, "Test template Label", "Test template description", tags, templateTriggers, templateConditions, templateActions, templateConfigDescriptionParameters, Visibility.VISIBLE);
String triggerTypeUID = "testTrigger1";
TriggerType triggerType = new TriggerType(triggerTypeUID, templateConfigDescriptionParameters, null);
String actionTypeUID = "testAction1";
ActionType actionType = new ActionType(actionTypeUID, templateConfigDescriptionParameters, null);
RuleTemplateProvider templateProvider = new RuleTemplateProvider() {
@Override
@Nullable
public RuleTemplate getTemplate(String UID, @Nullable Locale locale) {
if (UID.equals(templateUID)) {
return template;
} else {
return null;
}
}
@Override
public Collection<RuleTemplate> getTemplates(@Nullable Locale locale) {
return Set.of(template);
}
@Override
public void addProviderChangeListener(ProviderChangeListener<RuleTemplate> listener) {
}
@Override
public Collection<RuleTemplate> getAll() {
return Set.of(template);
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<RuleTemplate> listener) {
}
};
ModuleTypeProvider moduleTypeProvider = new ModuleTypeProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
}
@Override
public Collection<ModuleType> getAll() {
return Stream.of(triggerType, actionType).collect(toSet());
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
}
@Override
@Nullable
public <T extends ModuleType> T getModuleType(String UID, @Nullable Locale locale) {
if (UID.equals(triggerTypeUID)) {
return (T) triggerType;
} else if (UID.equals(actionTypeUID)) {
return (T) actionType;
} else {
return null;
}
}
@Override
public <T extends ModuleType> Collection<T> getModuleTypes(@Nullable Locale locale) {
return (Collection<T>) Stream.of(triggerType, actionType).collect(toSet());
}
};
registerService(templateProvider);
assertThat(templateRegistry.get(templateUID), is(notNullValue()));
unregisterService(templateProvider);
assertThat(templateRegistry.get(templateUID), is(nullValue()));
registerService(moduleTypeProvider);
assertThat(moduleTypeRegistry.get(actionTypeUID), is(notNullValue()));
assertThat(moduleTypeRegistry.get(triggerTypeUID), is(notNullValue()));
unregisterService(moduleTypeProvider);
assertThat(moduleTypeRegistry.get(actionTypeUID), is(nullValue()));
assertThat(moduleTypeRegistry.get(triggerTypeUID), is(nullValue()));
}
Aggregations