@Override public MatchStatus matches(Properties properties) { DocumentMatcher activeProfilesMatcher = getActiveProfilesDocumentMatcher(); String profiles = properties.getProperty(SPRING_PROFILES); String negative = extractProfiles(profiles, ProfileType.NEGATIVE); String positive = extractProfiles(profiles, ProfileType.POSITIVE); if (StringUtils.hasLength(negative)) { properties = new Properties(properties); properties.setProperty(SPRING_PROFILES, negative); if (activeProfilesMatcher.matches(properties) == MatchStatus.FOUND) { return MatchStatus.NOT_FOUND; } if (StringUtils.isEmpty(positive)) { return MatchStatus.FOUND; } properties.setProperty(SPRING_PROFILES, positive); } return activeProfilesMatcher.matches(properties); }
@Override public MatchStatus matches(Properties properties) { if (!properties.containsKey(this.key)) { return MatchStatus.ABSTAIN; } Set<String> values = StringUtils .commaDelimitedListToSet(properties.getProperty(this.key)); if (values.isEmpty()) { values = Collections.singleton(""); } for (String pattern : this.patterns) { for (String value : values) { if (value.matches(pattern)) { return MatchStatus.FOUND; } } } return MatchStatus.NOT_FOUND; }
@Override public MatchStatus matches(Properties properties) { if (!properties.containsKey("spring.profiles")) { return MatchStatus.FOUND; } return MatchStatus.NOT_FOUND; }
@Override public MatchStatus matches(Properties properties) { String[] profiles = this.activeProfiles; if (profiles.length == 0) { profiles = DEFAULT_PROFILES; } return new ArrayDocumentMatcher("spring.profiles", profiles).matches(properties); }
@Test public void matchesSingleProfile() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("spring.profiles: foo"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); }
@Test public void abstainNoConfiguredProfiles() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("some.property: spam"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.ABSTAIN); }
@Test public void noActiveProfiles() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher(); Properties properties = getProperties("spring.profiles: bar,spam"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.NOT_FOUND); }
@Test public void matchesCommaSeparatedArray() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("spring.profiles: bar,spam"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); }
@Test public void noMatchingProfiles() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("spring.profiles: baz,blah"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.NOT_FOUND); }
@Test public void inverseMatchSingle() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("spring.profiles: !baz"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); }
@Test public void testInverseMatchMulti() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar"); Properties properties = getProperties("spring.profiles: !baz,!blah"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); }
@Test public void negatedWithMatch() throws Exception { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah"); Properties properties = getProperties("spring.profiles: !baz,blah"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); }
@Test public void negatedWithNoMatch() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah"); Properties properties = getProperties("spring.profiles: !baz,another"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.NOT_FOUND); }
@Test public void negatedTrumpsMatching() throws IOException { DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "baz", "blah"); Properties properties = getProperties("spring.profiles: !baz,blah"); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.NOT_FOUND); }
@Test public void testMatchesSingleValue() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertThat(matcher.matches(getProperties("foo: bar"))) .isEqualTo(MatchStatus.FOUND); }
@Test public void testDoesNotMatchesIndexedArray() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertThat(matcher.matches(getProperties("foo[0]: bar\nfoo[1]: spam"))) .isEqualTo(MatchStatus.ABSTAIN); }
@Test public void testMatchesCommaSeparatedArray() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertThat(matcher.matches(getProperties("foo: bar,spam"))) .isEqualTo(MatchStatus.FOUND); }
@Test public void testMatchesSingleValue() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertEquals(MatchStatus.FOUND, matcher.matches(getProperties("foo: bar"))); }
@Test public void testDoesNotMatchesIndexedArray() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertEquals(MatchStatus.ABSTAIN, matcher.matches(getProperties("foo[0]: bar\nfoo[1]: spam"))); }
@Test public void testMatchesCommaSeparatedArray() throws IOException { ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar"); assertEquals(MatchStatus.FOUND, matcher.matches(getProperties("foo: bar,spam"))); }