Skip to content

Commit

Permalink
Fix for wrong match assignment on Trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed Jul 28, 2015
1 parent 131720b commit e371d88
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Trigger(String id, String name) {

this.enabled = false;
this.mode = Mode.FIRING;
this.match = getFiringMatch();
this.match = Match.ALL;
}

public boolean isEnabled() {
Expand Down Expand Up @@ -111,6 +111,18 @@ public void setMatch(Match match) {
this.match = match;
}

@Override
public void setFiringMatch(Match firingMatch) {
super.setFiringMatch(firingMatch);
setMatch(this.mode == Mode.FIRING ? getFiringMatch() : getAutoResolveMatch());
}

@Override
public void setAutoResolveMatch(Match autoResolveMatch) {
super.setAutoResolveMatch(autoResolveMatch);
setMatch(this.mode == Mode.FIRING ? getFiringMatch() : getAutoResolveMatch());
}

public String getTenantId() {
return tenantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,42 @@ public void jsonTriggerTest() throws Exception {
assertTrue(!output.contains("mode"));
assertTrue(!output.contains("match"));
}

@Test
public void jsonTriggerMatchAnyTest() throws Exception {
String str = "{\"name\":\"test-name\",\"description\":\"test-description\"," +
"\"actions\":{\"plugin1\":[\"uno\",\"dos\",\"tres\"]}," +
"\"firingMatch\":\"ANY\"," +
"\"autoResolveMatch\":\"ALL\"," +
"\"id\":\"test\"," +
"\"enabled\":true," +
"\"autoDisable\":true," +
"\"autoEnable\":true," +
"\"autoResolve\":true," +
"\"autoResolveAlerts\":true," +
"\"severity\":\"HIGH\"}";
Trigger trigger = objectMapper.readValue(str, Trigger.class);

assertEquals(Match.ANY, trigger.getMatch());

assertTrue(trigger.getName().equals("test-name"));
assertTrue(trigger.getDescription().equals("test-description"));
assertEquals(1, trigger.getActions().size());
assertEquals(3, trigger.getActions().get("plugin1").size());
assertTrue(trigger.getFiringMatch().equals(Match.ANY));
assertTrue(trigger.getAutoResolveMatch().equals(Match.ALL));
assertTrue(trigger.getId().equals("test"));
assertTrue(trigger.isEnabled());
assertTrue(trigger.isAutoDisable());
assertTrue(trigger.isAutoEnable());
assertTrue(trigger.isAutoResolve());
assertTrue(trigger.isAutoResolveAlerts());
assertTrue(trigger.getSeverity() == Severity.HIGH);

String output = objectMapper.writeValueAsString(trigger);

assertTrue(!output.contains("mode"));
assertTrue(!output.contains("match"));
}

}

0 comments on commit e371d88

Please sign in to comment.