Search in sources :

Example 1 with EnrichedGroupItemDTO

use of org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO in project smarthome by eclipse.

the class EnrichedItemDTOMapperTest method testFiltering.

@Test
public void testFiltering() {
    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, URI.create(""), null);
    assertThat(dto.members.length, is(0));
    dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, null, URI.create(""), null);
    assertThat(dto.members.length, is(3));
    assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
    dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER), URI.create(""), null);
    assertThat(dto.members.length, is(1));
    dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i instanceof GroupItem, URI.create(""), null);
    assertThat(dto.members.length, is(2));
    assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
    dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i instanceof GroupItem, URI.create(""), null);
    assertThat(dto.members.length, is(2));
    assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
    dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i.getType().equals(CoreItemFactory.STRING) || i instanceof GroupItem, URI.create(""), null);
    assertThat(dto.members.length, is(2));
    assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) EnrichedGroupItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Aggregations

GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 GroupItem (org.eclipse.smarthome.core.items.GroupItem)1 EnrichedGroupItemDTO (org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO)1 JavaTest (org.eclipse.smarthome.test.java.JavaTest)1 Test (org.junit.Test)1