@Test public void testMatches() throws Exception { NoteData note = new NoteData(); note.setId(0L); String keyGroup = UUID.randomUUID().toString(); String key = UUID.randomUUID().toString(); String valuePrefix = UUID.randomUUID().toString(); String valueCore = UUID.randomUUID().toString(); String valueSuffix = UUID.randomUUID().toString(); String value = valuePrefix + valueCore + valueSuffix; StringPropertyTO property = new StringPropertyTO(value, keyGroup, key, new Date()); Set<StringPropertyTO> properties = new HashSet<StringPropertyTO>(); properties.add(property); PropertyManagement propertyManagement = EasyMock.createMock(PropertyManagement.class); EasyMock.expect(propertyManagement.getAllObjectProperties(PropertyType.NoteProperty, 0L)) .andReturn(properties).anyTimes(); EasyMock.replay(propertyManagement); Matcher<NoteData> matcher = new PropertyFilterMatcher(propertyManagement); Assert.assertTrue(matcher.matches(note)); PropertyFilter filter; testContains(propertyManagement, note, keyGroup, key, valueCore); filter = new PropertyFilter(keyGroup, Note.class); filter.addProperty(key, valuePrefix, MatchMode.STARTS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertTrue(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class, true); filter.addProperty(key, valuePrefix, MatchMode.STARTS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertFalse(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class); filter.addProperty(key, valueSuffix, MatchMode.ENDS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertTrue(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class, true); filter.addProperty(key, valueSuffix, MatchMode.ENDS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertFalse(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class); filter.addProperty(key, value, MatchMode.EQUALS); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertTrue(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class, true); filter.addProperty(key, value, MatchMode.EQUALS); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertFalse(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class); filter.addProperty(key, value, MatchMode.NOT_EQUALS); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertFalse(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class, true); filter.addProperty(key, value, MatchMode.NOT_EQUALS); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertTrue(matcher.matches(note)); PropertyFilter filter1 = new PropertyFilter(keyGroup, Note.class); filter1.addProperty(key, valueCore, MatchMode.CONTAINS); PropertyFilter filter2 = new PropertyFilter(keyGroup, Note.class); filter2.addProperty(key, valuePrefix, MatchMode.STARTS_WITH); PropertyFilter filter3 = new PropertyFilter(keyGroup, Note.class); filter3.addProperty(key, valueSuffix, MatchMode.ENDS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter1, filter2, filter3); Assert.assertTrue(matcher.matches(note)); filter1 = new PropertyFilter(keyGroup, Note.class); filter1.addProperty(key, valueCore, MatchMode.CONTAINS); filter2 = new PropertyFilter(keyGroup, Note.class); filter2.addProperty(key, UUID.randomUUID().toString(), MatchMode.STARTS_WITH); matcher = new PropertyFilterMatcher(propertyManagement, filter1, filter2); Assert.assertFalse(matcher.matches(note)); filter = new PropertyFilter(keyGroup, Note.class); filter.addProperty(key, UUID.randomUUID().toString(), MatchMode.EQUALS); matcher = new PropertyFilterMatcher(propertyManagement, filter); Assert.assertFalse(matcher.matches(note)); filter.addProperty(key, value, MatchMode.EQUALS); Assert.assertTrue(matcher.matches(note)); testExists(propertyManagement, note, keyGroup, key); }
@Override public boolean matches(NoteData entity) { if (filters.isEmpty()) { return true; } try { Set<StringPropertyTO> noteProperties = propertyManagement.getAllObjectProperties( PropertyType.NoteProperty, entity.getId()); boolean result = true; outer: for (PropertyFilter filter : filters) { for (StringPropertyTO noteProperty : noteProperties) { if (filter.matches(noteProperty.getKeyGroup(), noteProperty.getPropertyKey(), noteProperty.getPropertyValue())) { continue outer; } } result = false; break outer; } return result; } catch (NotFoundException e) { LOGGER.warn("The note with id {} can't be found. It might have been deleted.", entity.getId()); } catch (AuthorizationException e) { LOGGER.error(e.getMessage(), e); } return false; }
PropertyFilterMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (filters.isEmpty()) { return true; } try { Set<StringPropertyTO> noteProperties = propertyManagement.getAllObjectProperties( PropertyType.NoteProperty, entity.getId()); boolean result = true; outer: for (PropertyFilter filter : filters) { for (StringPropertyTO noteProperty : noteProperties) { if (filter.matches(noteProperty.getKeyGroup(), noteProperty.getPropertyKey(), noteProperty.getPropertyValue())) { continue outer; } } result = false; break outer; } return result; } catch (NotFoundException e) { LOGGER.warn("The note with id {} can't be found. It might have been deleted.", entity.getId()); } catch (AuthorizationException e) { LOGGER.error(e.getMessage(), e); } return false; } }
PropertyFilterMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (filters.isEmpty()) { return true; } try { Set<StringPropertyTO> noteProperties = propertyManagement.getAllObjectProperties( PropertyType.NoteProperty, entity.getId()); boolean result = true; outer: for (PropertyFilter filter : filters) { for (StringPropertyTO noteProperty : noteProperties) { if (filter.matches(noteProperty.getKeyGroup(), noteProperty.getPropertyKey(), noteProperty.getPropertyValue())) { continue outer; } } result = false; break outer; } return result; } catch (NotFoundException e) { LOGGER.warn("The note with id {} can't be found. It might have been deleted.", entity.getId()); } catch (AuthorizationException e) { LOGGER.error(e.getMessage(), e); } return false; } PropertyFilterMatcher(PropertyManagement propertyManagement,
            Collection<PropertyFilter> filters);  PropertyFilterMatcher(PropertyManagement propertyManagement, PropertyFilter... filters); }
PropertyFilterMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (filters.isEmpty()) { return true; } try { Set<StringPropertyTO> noteProperties = propertyManagement.getAllObjectProperties( PropertyType.NoteProperty, entity.getId()); boolean result = true; outer: for (PropertyFilter filter : filters) { for (StringPropertyTO noteProperty : noteProperties) { if (filter.matches(noteProperty.getKeyGroup(), noteProperty.getPropertyKey(), noteProperty.getPropertyValue())) { continue outer; } } result = false; break outer; } return result; } catch (NotFoundException e) { LOGGER.warn("The note with id {} can't be found. It might have been deleted.", entity.getId()); } catch (AuthorizationException e) { LOGGER.error(e.getMessage(), e); } return false; } PropertyFilterMatcher(PropertyManagement propertyManagement,
            Collection<PropertyFilter> filters);  PropertyFilterMatcher(PropertyManagement propertyManagement, PropertyFilter... filters); @Override boolean matches(NoteData entity); }
PropertyFilterMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (filters.isEmpty()) { return true; } try { Set<StringPropertyTO> noteProperties = propertyManagement.getAllObjectProperties( PropertyType.NoteProperty, entity.getId()); boolean result = true; outer: for (PropertyFilter filter : filters) { for (StringPropertyTO noteProperty : noteProperties) { if (filter.matches(noteProperty.getKeyGroup(), noteProperty.getPropertyKey(), noteProperty.getPropertyValue())) { continue outer; } } result = false; break outer; } return result; } catch (NotFoundException e) { LOGGER.warn("The note with id {} can't be found. It might have been deleted.", entity.getId()); } catch (AuthorizationException e) { LOGGER.error(e.getMessage(), e); } return false; } PropertyFilterMatcher(PropertyManagement propertyManagement,
            Collection<PropertyFilter> filters);  PropertyFilterMatcher(PropertyManagement propertyManagement, PropertyFilter... filters); @Override boolean matches(NoteData entity);  }