Search in sources :

Example 1 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.

the class SysteminfoOSGiTest method intializeItem.

private void intializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {
    if (acceptedItemType.equals("Number")) {
        testItem = new NumberItem(itemName);
    } else if (acceptedItemType.equals("String")) {
        testItem = new StringItem(itemName);
    }
    itemRegistry.add(testItem);
    ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(itemChannelLinkProvider, is(notNullValue()));
    itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) StringItem(org.openhab.core.library.items.StringItem)

Example 2 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.

the class ItemChannelLinkResourceOSGiTest method beforeEach.

@BeforeEach
public void beforeEach() {
    registerVolatileStorageService();
    itemChannelLinkResource = getService(RESTResource.class, ItemChannelLinkResource.class);
    assertNotNull(itemChannelLinkResource);
    itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
    assertNotNull(itemChannelLinkRegistry);
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertNotNull(managedItemChannelLinkProvider);
    link1 = new ItemChannelLink(ITEM_NAME1, new ChannelUID(CHANNEL_UID1));
    link2 = new ItemChannelLink(ITEM_NAME2, new ChannelUID(CHANNEL_UID2));
    link3 = new ItemChannelLink(ITEM_NAME3, new ChannelUID(THING_TYPE_UID + ":" + UID + ":3"));
    when(itemChannelLinkProviderMock.getAll()).thenReturn(List.of(link1, link2, link3));
    registerService(itemChannelLinkProviderMock);
    waitForAssert(() -> {
        assertThat(itemChannelLinkRegistry.getAll(), hasSize(3));
    });
    when(uriBuilderMock.build(any())).thenReturn(URI.create(""));
    when(uriInfoMock.getAbsolutePathBuilder()).thenReturn(uriBuilderMock);
    when(uriInfoMock.getPath()).thenReturn("");
    when(httpHeadersMock.getHeaderString(anyString())).thenReturn(null);
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.openhab.core.thing.ChannelUID) RESTResource(org.openhab.core.io.rest.RESTResource) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.

the class ChangeThingTypeOSGiTest method setup.

@BeforeEach
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 = Map.ofEntries(entry(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE));
    Map<String, String> thingTypeSpecificProperties = Map.ofEntries(entry(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE), entry(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.openhab.core.items.ManagedItemProvider) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ComponentContext(org.osgi.service.component.ComponentContext) StringItem(org.openhab.core.library.items.StringItem) ChannelGroupTypeProvider(org.openhab.core.thing.type.ChannelGroupTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) ConfigDescriptionProvider(org.openhab.core.config.core.ConfigDescriptionProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.

the class ThingManagerOSGiTest method setUp.

@BeforeEach
@SuppressWarnings("null")
public void setUp() {
    thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withKind(ChannelKind.STATE).withType(CHANNEL_TYPE_UID).build()).build();
    registerVolatileStorageService();
    configurationAdmin = getService(ConfigurationAdmin.class);
    assertNotNull(configurationAdmin);
    channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenReturn(ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
    registerService(channelTypeProvider);
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    managedThingProvider = getService(ManagedThingProvider.class);
    eventPublisher = getService(EventPublisher.class);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
    assertNotNull(itemChannelLinkRegistry);
    readyService = getService(ReadyService.class);
    assertNotNull(readyService);
    waitForAssert(() -> {
        try {
            assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(" + ThingManagerImpl.XML_THING_TYPE + "=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
        } catch (InvalidSyntaxException e) {
            fail("Failed to get service reference: " + e.getMessage());
        }
    });
    Bundle bundle = mock(Bundle.class);
    when(bundle.getSymbolicName()).thenReturn("org.openhab.core.thing");
    BundleResolver bundleResolver = mock(BundleResolver.class);
    when(bundleResolver.resolveBundle(any())).thenReturn(bundle);
    ThingManagerImpl thingManager = (ThingManagerImpl) getService(ThingTypeMigrationService.class);
    thingManager.setBundleResolver(bundleResolver);
}
Also used : Locale(java.util.Locale) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) EventPublisher(org.openhab.core.events.EventPublisher) Bundle(org.osgi.framework.Bundle) ReadyService(org.openhab.core.service.ReadyService) ItemRegistry(org.openhab.core.items.ItemRegistry) BundleResolver(org.openhab.core.util.BundleResolver) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ThingTypeMigrationService(org.openhab.core.thing.ThingTypeMigrationService) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReadyMarker(org.openhab.core.service.ReadyMarker) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.

the class FeedHandlerTest method initializeItem.

private void initializeItem(ChannelUID channelUID) {
    // Create new item
    ItemRegistry itemRegistry = getService(ItemRegistry.class);
    assertThat(itemRegistry, is(notNullValue()));
    StringItem newItem = new StringItem(ITEM_NAME);
    // Add item state change listener
    StateChangeListener updateListener = new StateChangeListener() {

        @Override
        public void stateChanged(Item item, State oldState, State newState) {
        }

        @Override
        public void stateUpdated(Item item, State state) {
            currentItemState = (StringType) state;
        }
    };
    newItem.addStateChangeListener(updateListener);
    itemRegistry.add(newItem);
    // Add item channel link
    ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(itemChannelLinkProvider, is(notNullValue()));
    itemChannelLinkProvider.add(new ItemChannelLink(ITEM_NAME, channelUID));
}
Also used : Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) State(org.openhab.core.types.State) StateChangeListener(org.openhab.core.items.StateChangeListener) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemRegistry(org.openhab.core.items.ItemRegistry) StringItem(org.openhab.core.library.items.StringItem)

Aggregations

ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)5 ItemRegistry (org.openhab.core.items.ItemRegistry)4 StringItem (org.openhab.core.library.items.StringItem)4 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)4 EventPublisher (org.openhab.core.events.EventPublisher)2 ManagedItemProvider (org.openhab.core.items.ManagedItemProvider)2 ChannelUID (org.openhab.core.thing.ChannelUID)2 ThingProvider (org.openhab.core.thing.ThingProvider)2 ItemChannelLinkRegistry (org.openhab.core.thing.link.ItemChannelLinkRegistry)2 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)2 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)2 ComponentContext (org.osgi.service.component.ComponentContext)2 Locale (java.util.Locale)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Test (org.junit.jupiter.api.Test)1 WWNTestAccountHandler (org.openhab.binding.nest.internal.wwn.test.WWNTestAccountHandler)1 WWNTestHandlerFactory (org.openhab.binding.nest.internal.wwn.test.WWNTestHandlerFactory)1 NtpHandler (org.openhab.binding.ntp.internal.handler.NtpHandler)1