Search in sources :

Example 1 with ModuleTypeProvider

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()));
}
Also used : Condition(org.openhab.core.automation.Condition) Locale(java.util.Locale) TriggerType(org.openhab.core.automation.type.TriggerType) Action(org.openhab.core.automation.Action) ActionType(org.openhab.core.automation.type.ActionType) ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) RuleTemplate(org.openhab.core.automation.template.RuleTemplate) ModuleType(org.openhab.core.automation.type.ModuleType) Trigger(org.openhab.core.automation.Trigger) RuleTemplateProvider(org.openhab.core.automation.template.RuleTemplateProvider) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ModuleTypeProvider(org.openhab.core.automation.type.ModuleTypeProvider) Collection(java.util.Collection) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Nullable(org.eclipse.jdt.annotation.Nullable) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Aggregations

Collection (java.util.Collection)1 Locale (java.util.Locale)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1 Action (org.openhab.core.automation.Action)1 Condition (org.openhab.core.automation.Condition)1 Trigger (org.openhab.core.automation.Trigger)1 RuleTemplate (org.openhab.core.automation.template.RuleTemplate)1 RuleTemplateProvider (org.openhab.core.automation.template.RuleTemplateProvider)1 ActionType (org.openhab.core.automation.type.ActionType)1 ModuleType (org.openhab.core.automation.type.ModuleType)1 ModuleTypeProvider (org.openhab.core.automation.type.ModuleTypeProvider)1 ModuleTypeRegistry (org.openhab.core.automation.type.ModuleTypeRegistry)1 TriggerType (org.openhab.core.automation.type.TriggerType)1 ProviderChangeListener (org.openhab.core.common.registry.ProviderChangeListener)1 ConfigDescriptionParameter (org.openhab.core.config.core.ConfigDescriptionParameter)1 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)1