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);
}
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);
}
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);
}
Aggregations