Merge pull request #5747 from mbenson/notprofilesyamlbugfix
* pr/5747: Fix SpringProfileDocumentMatcher negation bug
This commit is contained in:
commit
f83cacdcd3
|
@ -68,10 +68,10 @@ public class SpringProfileDocumentMatcher implements DocumentMatcher {
|
|||
if (StringUtils.hasLength(negative)) {
|
||||
properties = new Properties(properties);
|
||||
properties.setProperty(SPRING_PROFILES, negative);
|
||||
switch (activeProfilesMatcher.matches(properties)) {
|
||||
case FOUND:
|
||||
if (activeProfilesMatcher.matches(properties) == MatchStatus.FOUND) {
|
||||
return MatchStatus.NOT_FOUND;
|
||||
case NOT_FOUND:
|
||||
}
|
||||
if (StringUtils.isEmpty(positive)) {
|
||||
return MatchStatus.FOUND;
|
||||
}
|
||||
properties.setProperty(SPRING_PROFILES, positive);
|
||||
|
|
|
@ -85,12 +85,19 @@ public class SpringProfileDocumentMatcherTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void negatedAndNonNegated() throws IOException {
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue