@Test public void testAggregatingMap() { group.addMember(entity); group.enrichers().add(Enrichers.builder() .aggregating(STR1, STR2) .publishing(MAP1) .fromMembers() .excludingBlank() .build()); EntityAsserts.assertAttributeEqualsEventually(group, MAP1, ImmutableMap.<String, String>of()); entity.sensors().set(STR1, "a"); EntityAsserts.assertAttributeEqualsEventually(group, MAP1, ImmutableMap.<String, String>of()); entity.sensors().set(STR2, "b"); EntityAsserts.assertAttributeEqualsEventually(group, MAP1, ImmutableMap.<String, String>of("a", "b")); entity.sensors().set(STR2, "c"); EntityAsserts.assertAttributeEqualsEventually(group, MAP1, ImmutableMap.<String, String>of("a", "c")); }
@Test public void testAggregatingExcludingNull() { group.addMember(entity); group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .publishing(SET1) .fromMembers() .excludingBlank() .computing(new Function<Collection<?>, Set<Object>>() { @Override public Set<Object> apply(Collection<?> input) { // accept null values, so don't use ImmutableSet return (input == null) ? ImmutableSet.<Object>of() : MutableSet.<Object>copyOf(input); }}) .build()); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of()); entity.sensors().set(NUM1, 1); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of(1)); entity.sensors().set(NUM1, null); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of()); entity.sensors().set(NUM1, 2); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of(2)); }
@Test public void testAggregatingExcludingBlankString() { group.addMember(entity); group.addMember(entity2); group.enrichers().add(Enrichers.builder() .aggregating(STR1) .publishing(SET1) .fromMembers() .excludingBlank() .computing(new Function<Collection<?>, Set<Object>>() { @Override public Set<Object> apply(Collection<?> input) { // accept null values, so don't use ImmutableSet return (input == null) ? ImmutableSet.<Object>of() : MutableSet.<Object>copyOf(input); }}) .build()); entity.sensors().set(STR1, "1"); entity2.sensors().set(STR1, "2"); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("1", "2")); entity.sensors().set(STR1, "3"); entity2.sensors().set(STR1, null); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("3")); entity.sensors().set(STR1, ""); entity2.sensors().set(STR1, "4"); EntityAsserts.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("4")); }