Search in sources :

Example 1 with SafeCaller

use of org.eclipse.smarthome.core.common.SafeCaller in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method setup.

@Before
public void setup() {
    initMocks(this);
    Map<String, String> props1 = new HashMap<>();
    props1.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
    props1.put(Thing.PROPERTY_MODEL_ID, MODEL1);
    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, MODEL2);
    thing2 = ThingBuilder.create(THING_TYPE_UID1, THING2_ID).withProperties(props2).build();
    Map<String, String> props3 = new HashMap<>();
    props3.put(Thing.PROPERTY_FIRMWARE_VERSION, VALPHA);
    thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build();
    firmwareUpdateService = new FirmwareUpdateService();
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    firmwareUpdateService.setSafeCaller(safeCaller);
    handler1 = addHandler(thing1);
    handler2 = addHandler(thing2);
    handler3 = addHandler(thing3);
    firmwareUpdateService.setEventPublisher(mockPublisher);
    when(mockLocaleProvider.getLocale()).thenReturn(Locale.ENGLISH);
    firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
    firmwareRegistry = new FirmwareRegistry();
    firmwareUpdateService.setFirmwareRegistry(firmwareRegistry);
    firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
    firmwareRegistry.setLocaleProvider(mockLocaleProvider);
    when(mockProvider.getFirmware(eq(FW009_EN.getUID()), any())).thenReturn(FW009_EN);
    when(mockProvider.getFirmware(eq(FW111_EN.getUID()), any())).thenReturn(FW111_EN);
    when(mockProvider.getFirmware(eq(FW112_EN.getUID()), any())).thenReturn(FW112_EN);
    when(mockProvider.getFirmware(eq(FWALPHA_EN.getUID()), any())).thenReturn(FWALPHA_EN);
    when(mockProvider.getFirmwares(any(ThingTypeUID.class), any())).then(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID) || THING_TYPE_UID3.equals(thingTypeUID)) {
            return Collections.emptySet();
        } else {
            return Stream.of(FW009_EN, FW111_EN, FW112_EN).collect(Collectors.toSet());
        }
    });
    firmwareRegistry.addFirmwareProvider(mockProvider);
    firmwareUpdateService.setTranslationProvider(mockTranslationProvider);
    firmwareUpdateService.setConfigDescriptionValidator(getService(ConfigDescriptionValidator.class));
}
Also used : SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) HashMap(java.util.HashMap) ConfigDescriptionValidator(org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Before(org.junit.Before)

Example 2 with SafeCaller

use of org.eclipse.smarthome.core.common.SafeCaller in project smarthome by eclipse.

the class CommunicationManagerTest method setup.

@Before
public void setup() {
    initMocks(this);
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    manager = new CommunicationManager();
    manager.setEventPublisher(eventPublisher);
    manager.setDefaultProfileFactory(new SystemProfileFactory());
    manager.setSafeCaller(safeCaller);
    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(mockProfileAdvisor).getSuggestedProfileTypeUID(isA(Channel.class), isA(String.class));
    doAnswer(invocation -> {
        switch(((ProfileTypeUID) invocation.getArguments()[0]).toString()) {
            case "test:state":
                return stateProfile;
            case "test:trigger":
                return triggerProfile;
        }
        return null;
    }).when(mockProfileFactory).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class));
    when(mockProfileFactory.getSupportedProfileTypeUIDs()).thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
    manager.addProfileFactory(mockProfileFactory);
    manager.addProfileAdvisor(mockProfileAdvisor);
    ItemChannelLinkRegistry iclRegistry = new ItemChannelLinkRegistry() {

        @Override
        public Stream<ItemChannelLink> stream() {
            return Arrays.asList(LINK_1_S1, LINK_1_S2, LINK_2_S2, LINK_1_T1, LINK_1_T2, LINK_2_T2).stream();
        }
    };
    manager.setItemChannelLinkRegistry(iclRegistry);
    when(itemRegistry.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
    when(itemRegistry.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
    manager.setItemRegistry(itemRegistry);
    THING.setHandler(mockHandler);
    when(thingRegistry.get(eq(THING_UID))).thenReturn(THING);
    manager.setThingRegistry(thingRegistry);
    manager.addItemFactory(new CoreItemFactory());
}
Also used : CoreItemFactory(org.eclipse.smarthome.core.library.CoreItemFactory) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) SystemProfileFactory(org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory) ProfileCallback(org.eclipse.smarthome.core.thing.profiles.ProfileCallback) ProfileContext(org.eclipse.smarthome.core.thing.profiles.ProfileContext) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Before(org.junit.Before)

Aggregations

SafeCaller (org.eclipse.smarthome.core.common.SafeCaller)2 Before (org.junit.Before)2 HashMap (java.util.HashMap)1 ConfigDescriptionValidator (org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator)1 CoreItemFactory (org.eclipse.smarthome.core.library.CoreItemFactory)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)1 SystemProfileFactory (org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory)1 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)1 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)1 ProfileCallback (org.eclipse.smarthome.core.thing.profiles.ProfileCallback)1 ProfileContext (org.eclipse.smarthome.core.thing.profiles.ProfileContext)1 ProfileTypeUID (org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)1