use of org.openhab.core.library.CoreItemFactory in project openhab-core by openhab.
the class EnrichedItemDTOMapperTest method testFiltering.
@Test
public void testFiltering() {
CoreItemFactory itemFactory = new CoreItemFactory();
GroupItem group = new GroupItem("TestGroup");
GroupItem subGroup = new GroupItem("TestSubGroup");
GenericItem switchItem = itemFactory.createItem(CoreItemFactory.SWITCH, "TestSwitch");
GenericItem numberItem = itemFactory.createItem(CoreItemFactory.NUMBER, "TestNumber");
GenericItem stringItem = itemFactory.createItem(CoreItemFactory.STRING, "TestString");
if (switchItem != null && numberItem != null && stringItem != null) {
group.addMember(subGroup);
group.addMember(switchItem);
group.addMember(numberItem);
subGroup.addMember(stringItem);
}
EnrichedGroupItemDTO dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, false, null, null, null);
assertThat(dto.members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, null, null, null);
assertThat(dto.members.length, is(3));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> CoreItemFactory.NUMBER.equals(i.getType()), null, null);
assertThat(dto.members.length, is(1));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> CoreItemFactory.NUMBER.equals(i.getType()) || i instanceof GroupItem, null, null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> CoreItemFactory.NUMBER.equals(i.getType()) || i instanceof GroupItem, null, null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> CoreItemFactory.NUMBER.equals(i.getType()) || i.getType().equals(CoreItemFactory.STRING) || i instanceof GroupItem, null, null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
}
use of org.openhab.core.library.CoreItemFactory in project openhab-core by openhab.
the class PersistenceExtensionsTest method setUp.
@BeforeEach
public void setUp() {
when(unitProviderMock.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
CoreItemFactory itemFactory = new CoreItemFactory();
numberItem = itemFactory.createItem(CoreItemFactory.NUMBER, TEST_NUMBER);
quantityItem = itemFactory.createItem(CoreItemFactory.NUMBER + ItemUtil.EXTENSION_SEPARATOR + "Temperature", TEST_QUANTITY_NUMBER);
quantityItem.setUnitProvider(unitProviderMock);
switchItem = itemFactory.createItem(CoreItemFactory.SWITCH, TEST_SWITCH);
when(itemRegistryMock.get(TEST_NUMBER)).thenReturn(numberItem);
when(itemRegistryMock.get(TEST_QUANTITY_NUMBER)).thenReturn(quantityItem);
when(itemRegistryMock.get(TEST_SWITCH)).thenReturn(switchItem);
new PersistenceExtensions(new PersistenceServiceRegistry() {
private final PersistenceService testPersistenceService = new TestPersistenceService(itemRegistryMock);
@Override
@Nullable
public String getDefaultId() {
// not available
return null;
}
@Override
@Nullable
public PersistenceService getDefault() {
// not available
return null;
}
@Override
public Set<PersistenceService> getAll() {
return Set.of(testPersistenceService);
}
@Override
@Nullable
public PersistenceService get(@Nullable String serviceId) {
return TestPersistenceService.ID.equals(serviceId) ? testPersistenceService : null;
}
});
}
use of org.openhab.core.library.CoreItemFactory in project openhab-core by openhab.
the class SemanticTagsTest method setup.
@BeforeEach
public void setup() {
CoreItemFactory itemFactory = new CoreItemFactory();
locationItem = new GroupItem("TestBathRoom");
locationItem.addTag("Bathroom");
equipmentItem = new GroupItem("Test08");
equipmentItem.addTag("CleaningRobot");
pointItem = itemFactory.createItem(CoreItemFactory.NUMBER, "TestTemperature");
pointItem.addTag("Measurement");
pointItem.addTag("Temperature");
}
use of org.openhab.core.library.CoreItemFactory 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);
}
use of org.openhab.core.library.CoreItemFactory in project openhab-core by openhab.
the class ItemRegistryImplTest method beforeEach.
@BeforeEach
public void beforeEach() {
GenericItem cameraItem1 = new SwitchItem(CAMERA_ITEM_NAME1);
GenericItem cameraItem2 = new SwitchItem(CAMERA_ITEM_NAME2);
GenericItem cameraItem3 = new NumberItem(CAMERA_ITEM_NAME3);
GenericItem cameraItem4 = new NumberItem(CAMERA_ITEM_NAME4);
cameraItem1.addTag(CAMERA_TAG);
cameraItem2.addTag(CAMERA_TAG);
cameraItem2.addTag(SENSOR_TAG);
cameraItem3.addTag(CAMERA_TAG);
cameraItem4.addTag(CAMERA_TAG_UPPERCASE);
// setup ManageItemProvider with necessary dependencies:
itemProvider = new ManagedItemProvider(new VolatileStorageService(), new ItemBuilderFactoryImpl(new CoreItemFactory()));
itemProvider.add(new SwitchItem(ITEM_NAME));
itemProvider.add(cameraItem1);
itemProvider.add(cameraItem2);
itemProvider.add(cameraItem3);
itemProvider.add(cameraItem4);
// setup ItemRegistryImpl with necessary dependencies:
itemRegistry = new ItemRegistryImpl(mock(MetadataRegistry.class)) {
{
addProvider(itemProvider);
setManagedProvider(itemProvider);
setEventPublisher(ItemRegistryImplTest.this.eventPublisherMock);
setStateDescriptionService(mock(StateDescriptionService.class));
setUnitProvider(mock(UnitProvider.class));
setItemStateConverter(mock(ItemStateConverter.class));
}
};
}
Aggregations