AutomaticInboxProcessor extends AbstractTypedEventSubscriber<ThingStatusInfoChangedEvent> implements InboxListener, RegistryChangeListener<Thing> { @Override public void removed(Thing element) { removePossiblyIgnoredResultInInbox(element); } @Activate  AutomaticInboxProcessor(final @Reference ThingTypeRegistry thingTypeRegistry,
            final @Reference ThingRegistry thingRegistry, final @Reference Inbox inbox); @Override void receiveTypedEvent(ThingStatusInfoChangedEvent event); @Override void thingAdded(Inbox inbox, DiscoveryResult result); @Override void thingUpdated(Inbox inbox, DiscoveryResult result); @Override void thingRemoved(Inbox inbox, DiscoveryResult result); @Override void added(Thing element); @Override void removed(Thing element); @Override void updated(Thing oldElement, Thing element); static final String AUTO_IGNORE_CONFIG_PROPERTY; static final String ALWAYS_AUTO_APPROVE_CONFIG_PROPERTY; }
@Test public void testThingIsBeingRemoved() { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); inbox.setFlag(THING_UID, DiscoveryResultFlag.IGNORED); List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); automaticInboxProcessor.removed(thing); results = inbox.getAll(); assertThat(results.size(), is(0)); }
@Test public void testOneThingOutOfTwoWithSameRepresentationPropertyButDifferentBindingIdIsBeingRemoved() { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); inbox.setFlag(THING_UID, DiscoveryResultFlag.IGNORED); inbox.add(DiscoveryResultBuilder.create(THING_UID3).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); inbox.setFlag(THING_UID3, DiscoveryResultFlag.IGNORED); List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); assertThat(results.size(), is(2)); automaticInboxProcessor.removed(thing); results = inbox.getAll(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID3))); }
@Test public void testThingWithConfigIsBeingRemoved() { inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(OTHER_KEY, OTHER_VALUE) .withRepresentationProperty(OTHER_KEY).build()); inbox.setFlag(THING_UID2, DiscoveryResultFlag.IGNORED); List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); automaticInboxProcessor.removed(thing2); results = inbox.getAll(); assertThat(results.size(), is(0)); }