Search in sources :

Example 1 with ManagedItemProvider

use of org.openhab.core.items.ManagedItemProvider in project openhab-core by openhab.

the class ItemResourceOSGiTest method beforeEach.

@BeforeEach
public void beforeEach() {
    registerVolatileStorageService();
    itemResource = getService(RESTResource.class, ItemResource.class);
    assertNotNull(itemResource);
    managedItemProvider = getService(ManagedItemProvider.class);
    assertNotNull(managedItemProvider);
    item1 = new SwitchItem(ITEM_NAME1);
    item2 = new SwitchItem(ITEM_NAME2);
    item3 = new DimmerItem(ITEM_NAME3);
    item4 = new StringItem(ITEM_NAME4);
    when(itemProviderMock.getAll()).thenReturn(List.of(item1, item2, item3, item4));
    registerService(itemProviderMock);
    when(uriBuilderMock.build(any())).thenReturn(URI.create(""));
    when(uriBuilderMock.path(anyString())).thenReturn(uriBuilderMock);
    when(uriInfoMock.getAbsolutePathBuilder()).thenReturn(uriBuilderMock);
    when(uriInfoMock.getBaseUriBuilder()).thenReturn(uriBuilderMock);
    when(uriInfoMock.getPath()).thenReturn("");
    when(httpHeadersMock.getHeaderString(anyString())).thenReturn(null);
}
Also used : ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) RESTResource(org.openhab.core.io.rest.RESTResource) DimmerItem(org.openhab.core.library.items.DimmerItem) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ManagedItemProvider

use of org.openhab.core.items.ManagedItemProvider 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 3 with ManagedItemProvider

use of org.openhab.core.items.ManagedItemProvider in project openhab-addons by openhab.

the class AbstractModbusOSGiTest method setUpAbstractModbusOSGiTest.

/**
 * Before each test, configure mocked services
 */
@BeforeEach
public void setUpAbstractModbusOSGiTest() {
    logger.debug("setUpAbstractModbusOSGiTest BEGIN");
    registerVolatileStorageService();
    registerService(mockedModbusManager);
    registerService(stateSubscriber);
    swapModbusManagerToMocked();
    thingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertThat("Could not get ManagedThingProvider", thingProvider, is(notNullValue()));
    itemProvider = getService(ItemProvider.class, ManagedItemProvider.class);
    assertThat("Could not get ManagedItemProvider", itemProvider, is(notNullValue()));
    itemChannelLinkProvider = getService(ItemChannelLinkProvider.class, ManagedItemChannelLinkProvider.class);
    assertThat("Could not get ManagedItemChannelLinkProvider", itemChannelLinkProvider, is(notNullValue()));
    itemRegistry = getService(ItemRegistry.class);
    assertThat("Could not get ItemRegistry", itemRegistry, is(notNullValue()));
    coreItemFactory = new CoreItemFactory();
    // Clean slate for all tests
    reset(mockedModbusManager);
    stateSubscriber.stateUpdates.clear();
    logger.debug("setUpAbstractModbusOSGiTest END");
}
Also used : ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) ItemProvider(org.openhab.core.items.ItemProvider) ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) CoreItemFactory(org.openhab.core.library.CoreItemFactory) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ItemChannelLinkProvider(org.openhab.core.thing.link.ItemChannelLinkProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)3 ManagedItemProvider (org.openhab.core.items.ManagedItemProvider)3 StringItem (org.openhab.core.library.items.StringItem)2 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)2 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)2 ConfigDescriptionProvider (org.openhab.core.config.core.ConfigDescriptionProvider)1 ConfigDescriptionRegistry (org.openhab.core.config.core.ConfigDescriptionRegistry)1 RESTResource (org.openhab.core.io.rest.RESTResource)1 ItemProvider (org.openhab.core.items.ItemProvider)1 ItemRegistry (org.openhab.core.items.ItemRegistry)1 CoreItemFactory (org.openhab.core.library.CoreItemFactory)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 ThingProvider (org.openhab.core.thing.ThingProvider)1 ItemChannelLinkProvider (org.openhab.core.thing.link.ItemChannelLinkProvider)1 ChannelGroupTypeProvider (org.openhab.core.thing.type.ChannelGroupTypeProvider)1 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)1 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)1 ComponentContext (org.osgi.service.component.ComponentContext)1