Search in sources :

Example 1 with CoreItemFactory

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));
}
Also used : CoreItemFactory(org.openhab.core.library.CoreItemFactory) GenericItem(org.openhab.core.items.GenericItem) GroupItem(org.openhab.core.items.GroupItem) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 2 with CoreItemFactory

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;
        }
    });
}
Also used : CoreItemFactory(org.openhab.core.library.CoreItemFactory) PersistenceService(org.openhab.core.persistence.PersistenceService) Set(java.util.Set) PersistenceServiceRegistry(org.openhab.core.persistence.PersistenceServiceRegistry) Nullable(org.eclipse.jdt.annotation.Nullable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CoreItemFactory

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");
}
Also used : CoreItemFactory(org.openhab.core.library.CoreItemFactory) GroupItem(org.openhab.core.items.GroupItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CoreItemFactory

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);
}
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 5 with CoreItemFactory

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));
        }
    };
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) CoreItemFactory(org.openhab.core.library.CoreItemFactory) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ItemBuilderFactoryImpl(org.openhab.core.internal.items.ItemBuilderFactoryImpl) ItemRegistryImpl(org.openhab.core.internal.items.ItemRegistryImpl) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CoreItemFactory (org.openhab.core.library.CoreItemFactory)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 GroupItem (org.openhab.core.items.GroupItem)5 ItemChannelLinkProvider (org.openhab.core.thing.link.ItemChannelLinkProvider)2 Collection (java.util.Collection)1 Set (java.util.Set)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1 SafeCaller (org.openhab.core.common.SafeCaller)1 UnitProvider (org.openhab.core.i18n.UnitProvider)1 ItemBuilderFactoryImpl (org.openhab.core.internal.items.ItemBuilderFactoryImpl)1 ItemRegistryImpl (org.openhab.core.internal.items.ItemRegistryImpl)1 GenericItem (org.openhab.core.items.GenericItem)1 ItemProvider (org.openhab.core.items.ItemProvider)1 ItemRegistry (org.openhab.core.items.ItemRegistry)1 ManagedItemProvider (org.openhab.core.items.ManagedItemProvider)1 NumberItem (org.openhab.core.library.items.NumberItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 SemanticsActionService (org.openhab.core.model.script.internal.engine.action.SemanticsActionService)1 PersistenceService (org.openhab.core.persistence.PersistenceService)1