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));
}
Aggregations