Search in sources :

Example 1 with ChannelGroupTypeProvider

use of org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method registerChannelGroupTypeProvider.

private void registerChannelGroupTypeProvider() throws Exception {
    ChannelGroupType channelGroupType = ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, "Test Group Label").withDescription("Test Group Description").withCategory("Test Group Category").withChannelDefinitions(Collections.singletonList(new ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
    ChannelGroupTypeProvider mockChannelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
    when(mockChannelGroupTypeProvider.getChannelGroupType(eq(CHANNEL_GROUP_TYPE_UID), any())).thenReturn(channelGroupType);
    registerService(mockChannelGroupTypeProvider);
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider)

Example 2 with ChannelGroupTypeProvider

use of org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider in project smarthome by eclipse.

the class ChangeThingTypeOSGiTest method setup.

@Before
public void setup() throws URISyntaxException {
    registerVolatileStorageService();
    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));
    configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
    assertThat(configDescriptionRegistry, is(notNullValue()));
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(managedItemChannelLinkProvider, is(notNullValue()));
    managedItemProvider = getService(ManagedItemProvider.class);
    assertThat(managedItemProvider, is(notNullValue()));
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    thingHandlerFactory = new SampleThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    Map<String, String> thingTypeGenericProperties = new HashMap<>();
    thingTypeGenericProperties.put(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE);
    thingTypeGenericProperties.put(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE);
    Map<String, String> thingTypeSpecificProperties = new HashMap<>();
    thingTypeSpecificProperties.put(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE);
    thingTypeSpecificProperties.put(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, SPECIFIC_VALUE);
    thingTypeGeneric = registerThingTypeAndConfigDescription(THING_TYPE_GENERIC_UID, thingTypeGenericProperties);
    thingTypeSpecific = registerThingTypeAndConfigDescription(THING_TYPE_SPECIFIC_UID, thingTypeSpecificProperties);
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
    registerService(thingTypeProvider);
    ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
    when(thingTypeRegistry.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
    registerService(thingTypeRegistry);
    ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
    when(configDescriptionProvider.getConfigDescription(any(), any())).thenAnswer(invocation -> configDescriptions.get(invocation.getArgument(0)));
    registerService(configDescriptionProvider);
    ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
    when(channelTypeProvider.getChannelType(any(), any())).thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
    registerService(channelTypeProvider);
    ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
    when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
    when(channelGroupTypeProvider.getChannelGroupType(any(), any())).thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));
    registerService(channelGroupTypeProvider);
    managedItemProvider.add(new StringItem(ITEM_GENERIC));
    managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_GENERIC);
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_SPECIFIC);
}
Also used : ManagedItemProvider(org.eclipse.smarthome.core.items.ManagedItemProvider) ManagedItemChannelLinkProvider(org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider) ComponentContext(org.osgi.service.component.ComponentContext) HashMap(java.util.HashMap) StringItem(org.eclipse.smarthome.core.library.items.StringItem) ChannelGroupTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingTypeRegistry(org.eclipse.smarthome.core.thing.type.ThingTypeRegistry) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) ConfigDescriptionProvider(org.eclipse.smarthome.config.core.ConfigDescriptionProvider) Before(org.junit.Before)

Example 3 with ChannelGroupTypeProvider

use of org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider in project smarthome by eclipse.

the class ThingFactoryTest method registerChannelTypes.

private void registerChannelTypes(Collection<ChannelType> channelTypes, Collection<ChannelGroupType> channelGroupTypes) {
    ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelTypes(nullable(Locale.class))).thenReturn(channelTypes);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenAnswer(new Answer<@Nullable ChannelType>() {

        @Override
        @Nullable
        public ChannelType answer(InvocationOnMock invocation) throws Throwable {
            ChannelTypeUID uid = (ChannelTypeUID) invocation.getArgument(0);
            return channelTypes.stream().filter(t -> t.getUID().equals(uid)).findFirst().get();
        }
    });
    registerService(channelTypeProvider);
    ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
    when(channelGroupTypeProvider.getChannelGroupTypes(nullable(Locale.class))).thenReturn(channelGroupTypes);
    when(channelGroupTypeProvider.getChannelGroupType(any(ChannelGroupTypeUID.class), nullable(Locale.class))).thenAnswer(new Answer<@Nullable ChannelGroupType>() {

        @Override
        @Nullable
        public ChannelGroupType answer(InvocationOnMock invocation) throws Throwable {
            ChannelGroupTypeUID uid = (ChannelGroupTypeUID) invocation.getArgument(0);
            return channelGroupTypes.stream().filter(t -> t.getUID().equals(uid)).findFirst().get();
        }
    });
    registerService(channelGroupTypeProvider);
}
Also used : Locale(java.util.Locale) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CoreMatchers(org.hamcrest.CoreMatchers) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition) ChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder) HashMap(java.util.HashMap) ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable) Locale(java.util.Locale) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) URI(java.net.URI) ConfigDescriptionParameterBuilder(org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Collection(java.util.Collection) Bridge(org.eclipse.smarthome.core.thing.Bridge) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ConfigDescriptionRegistry(org.eclipse.smarthome.config.core.ConfigDescriptionRegistry) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) Mockito(org.mockito.Mockito) ChannelGroupTypeBuilder(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeBuilder) List(java.util.List) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Stream(java.util.stream.Stream) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Collections(java.util.Collections) ChannelGroupTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ChannelGroupTypeProvider (org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider)3 HashMap (java.util.HashMap)2 ConfigDescriptionRegistry (org.eclipse.smarthome.config.core.ConfigDescriptionRegistry)2 ChannelDefinitionBuilder (org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder)2 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)2 ChannelTypeProvider (org.eclipse.smarthome.core.thing.type.ChannelTypeProvider)2 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)1 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)1 ConfigDescriptionParameterBuilder (org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder)1 ConfigDescriptionProvider (org.eclipse.smarthome.config.core.ConfigDescriptionProvider)1