Search in sources :

Example 1 with SafeCaller

use of org.openhab.core.common.SafeCaller in project openhab-core by openhab.

the class CommunicationManagerOSGiTest method beforeEach.

@BeforeEach
public void beforeEach() {
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    SystemProfileFactory profileFactory = getService(ProfileTypeProvider.class, SystemProfileFactory.class);
    assertNotNull(profileFactory);
    if (profileFactory == null) {
        throw new IllegalStateException("thing is null");
    }
    manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry, itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock);
    doAnswer(invocation -> {
        switch(((Channel) invocation.getArguments()[0]).getKind()) {
            case STATE:
                return new ProfileTypeUID("test:state");
            case TRIGGER:
                return new ProfileTypeUID("test:trigger");
        }
        return null;
    }).when(profileAdvisorMock).getSuggestedProfileTypeUID(isA(Channel.class), isA(String.class));
    doAnswer(invocation -> {
        switch(((ProfileTypeUID) invocation.getArguments()[0]).toString()) {
            case "test:state":
                return stateProfileMock;
            case "test:trigger":
                return triggerProfileMock;
        }
        return null;
    }).when(profileFactoryMock).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class));
    when(profileFactoryMock.getSupportedProfileTypeUIDs()).thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
    manager.addProfileFactory(profileFactoryMock);
    manager.addProfileAdvisor(profileAdvisorMock);
    iclRegistry.addProvider(new ItemChannelLinkProvider() {

        @Override
        public void addProviderChangeListener(ProviderChangeListener<ItemChannelLink> listener) {
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<ItemChannelLink> listener) {
        }

        @Override
        public Collection<ItemChannelLink> getAll() {
            return List.of(LINK_1_S1, LINK_1_S2, LINK_2_S2, LINK_1_T1, LINK_1_T2, LINK_2_T2, LINK_3_S3, LINK_4_S4);
        }
    });
    when(itemRegistryMock.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
    when(itemRegistryMock.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
    when(itemRegistryMock.get(eq(ITEM_NAME_3))).thenReturn(ITEM_3);
    when(itemRegistryMock.get(eq(ITEM_NAME_4))).thenReturn(ITEM_4);
    ChannelType channelType4 = mock(ChannelType.class);
    when(channelType4.getItemType()).thenReturn("Number:Temperature");
    when(channelTypeRegistryMock.getChannelType(CHANNEL_TYPE_UID_4)).thenReturn(channelType4);
    THING.setHandler(thingHandlerMock);
    when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);
    manager.addItemFactory(new CoreItemFactory());
    UnitProvider unitProvider = mock(UnitProvider.class);
    when(unitProvider.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
    ITEM_3.setUnitProvider(unitProvider);
    ITEM_4.setUnitProvider(unitProvider);
}
Also used : ProfileCallback(org.openhab.core.thing.profiles.ProfileCallback) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID) CoreItemFactory(org.openhab.core.library.CoreItemFactory) SafeCaller(org.openhab.core.common.SafeCaller) SystemProfileFactory(org.openhab.core.thing.internal.profiles.SystemProfileFactory) ProfileContext(org.openhab.core.thing.profiles.ProfileContext) UnitProvider(org.openhab.core.i18n.UnitProvider) Collection(java.util.Collection) ChannelType(org.openhab.core.thing.type.ChannelType) ItemChannelLinkProvider(org.openhab.core.thing.link.ItemChannelLinkProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SafeCaller

use of org.openhab.core.common.SafeCaller in project openhab-core by openhab.

the class FirmwareUpdateServiceTest method beforeEach.

@BeforeEach
public void beforeEach() {
    Map<String, String> props1 = new HashMap<>();
    props1.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
    props1.put(Thing.PROPERTY_MODEL_ID, MODEL1);
    props1.put(Thing.PROPERTY_VENDOR, VENDOR1);
    thing1 = ThingBuilder.create(THING_TYPE_UID1, THING1_ID).withProperties(props1).build();
    Map<String, String> props2 = new HashMap<>();
    props2.put(Thing.PROPERTY_FIRMWARE_VERSION, V112);
    props2.put(Thing.PROPERTY_MODEL_ID, MODEL1);
    props2.put(Thing.PROPERTY_VENDOR, VENDOR1);
    thing2 = ThingBuilder.create(THING_TYPE_UID1, THING2_ID).withProperties(props2).build();
    Map<String, String> props3 = new HashMap<>();
    props3.put(Thing.PROPERTY_FIRMWARE_VERSION, VALPHA);
    props3.put(Thing.PROPERTY_MODEL_ID, MODEL2);
    props3.put(Thing.PROPERTY_VENDOR, VENDOR2);
    thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build();
    SafeCaller safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    firmwareUpdateService = new FirmwareUpdateServiceImpl(bundleResolverMock, configDescriptionValidatorMock, eventPublisherMock, firmwareRegistryMock, translationProviderMock, localeProviderMock, safeCaller);
    handler1Mock = addHandler(thing1);
    handler2Mock = addHandler(thing2);
    handler3Mock = addHandler(thing3);
    when(localeProviderMock.getLocale()).thenReturn(Locale.ENGLISH);
    initialFirmwareRegistryMocking();
    when(bundleResolverMock.resolveBundle(any())).thenReturn(mock(Bundle.class));
}
Also used : SafeCaller(org.openhab.core.common.SafeCaller) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)2 SafeCaller (org.openhab.core.common.SafeCaller)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 UnitProvider (org.openhab.core.i18n.UnitProvider)1 CoreItemFactory (org.openhab.core.library.CoreItemFactory)1 Channel (org.openhab.core.thing.Channel)1 SystemProfileFactory (org.openhab.core.thing.internal.profiles.SystemProfileFactory)1 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)1 ItemChannelLinkProvider (org.openhab.core.thing.link.ItemChannelLinkProvider)1 ProfileCallback (org.openhab.core.thing.profiles.ProfileCallback)1 ProfileContext (org.openhab.core.thing.profiles.ProfileContext)1 ProfileTypeUID (org.openhab.core.thing.profiles.ProfileTypeUID)1 ChannelType (org.openhab.core.thing.type.ChannelType)1 Bundle (org.osgi.framework.Bundle)1