use of org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry 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());
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method setUp.
@Before
public void setUp() throws Exception {
CONFIG_DESCRIPTION_THING = new URI("test:test");
CONFIG_DESCRIPTION_CHANNEL = new URI("test:channel");
THING = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
Collections.singletonList(//
ChannelBuilder.create(CHANNEL_UID, "Switch").withType(CHANNEL_TYPE_UID).build())).build();
registerVolatileStorageService();
configureAutoLinking(false);
managedThingProvider = getService(ManagedThingProvider.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, "(esh.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ChannelItemProvider.class, null), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
}
Aggregations