use of org.commonjava.indy.promote.model.ValidationRuleDTO in project indy by Commonjava.
the class RuleAndRuleSetGetTest method run.
@Test
public void run() throws Exception {
getRuleScriptFiles().forEach((name, content) -> {
ValidationRuleDTO rule = null;
try {
rule = module.getRuleByName(name);
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(rule);
assertThat(rule.getName(), equalTo(name));
assertNotNull(rule.getSpec());
assertThat(rule.getSpec().length() > 0, equalTo(true));
});
getRuleSets().forEach((name, set) -> {
ValidationRuleSet ruleSet = null;
try {
ruleSet = module.getRuleSetByName(name);
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(ruleSet);
assertThat(ruleSet.getName(), containsString(name));
assertThat(ruleSet.getStoreKeyPattern(), equalTo(RULESET_TEST_STOREKEY));
});
ValidationRuleSet ruleSet = null;
try {
ruleSet = module.getRuleSetByStoreKey(StoreKey.fromString(RULESET_TEST_STOREKEY));
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(ruleSet);
assertThat(ruleSet.getName(), containsString(RULESET_TEST_NAME));
assertThat(ruleSet.getStoreKeyPattern(), equalTo(RULESET_TEST_STOREKEY));
List<String> ruleNames = module.getAllRules();
assertThat(ruleNames.size(), equalTo(2));
assertThat(ruleNames, CoreMatchers.hasItems(RULE1, RULE2));
List<String> ruleSetNames = module.getAllRuleSets();
assertThat(ruleSetNames.size(), equalTo(1));
assertThat(ruleSetNames.get(0), containsString("test"));
}
use of org.commonjava.indy.promote.model.ValidationRuleDTO in project indy by Commonjava.
the class RuleReloadTest method run.
@Test
public void run() throws Exception {
List<String> allRules = module.getAllRules();
assertNotNull(allRules);
assertThat(allRules.size(), equalTo(1));
assertThat(allRules, hasItem(RULE_CHNAGE));
assertThat(allRules.contains(RULE_NEW), equalTo(false));
ValidationRuleDTO rule = module.getRuleByName(RULE_CHNAGE);
assertThat(rule.getName(), equalTo(RULE_CHNAGE));
assertThat(rule.getSpec(), containsString(RULE_CHANGE_INIT_CONTENT_STR));
assertThat(rule.getSpec().contains(RULE_CHANGE_CHANGED_CONTENT_STR), equalTo(false));
rule = module.getRuleByName(RULE_NEW);
assertThat(rule, nullValue());
deployRule(RULE_NEW, getNewRuleContent());
deployRule(RULE_CHNAGE, getChangedRuleContent());
module.reloadRules();
allRules = module.getAllRules();
assertThat(allRules.size(), equalTo(2));
assertThat(allRules, hasItems(RULE_NEW, RULE_CHNAGE));
rule = module.getRuleByName(RULE_NEW);
assertThat(rule.getName(), equalTo(RULE_NEW));
assertThat(rule.getSpec(), containsString("This is a new test rule"));
rule = module.getRuleByName(RULE_CHNAGE);
assertThat(rule.getName(), equalTo(RULE_CHNAGE));
assertThat(rule.getSpec(), containsString(RULE_CHANGE_CHANGED_CONTENT_STR));
assertThat(rule.getSpec().contains(RULE_CHANGE_INIT_CONTENT_STR), equalTo(false));
deleteRule(RULE_NEW);
module.reloadRules();
allRules = module.getAllRules();
assertNotNull(allRules);
assertThat(allRules.size(), equalTo(1));
assertThat(allRules, hasItem(RULE_CHNAGE));
assertThat(allRules.contains(RULE_NEW), equalTo(false));
rule = module.getRuleByName(RULE_NEW);
assertThat(rule, nullValue());
rule = module.getRuleByName(RULE_CHNAGE);
assertThat(rule.getName(), equalTo(RULE_CHNAGE));
assertThat(rule.getSpec(), containsString(RULE_CHANGE_CHANGED_CONTENT_STR));
assertThat(rule.getSpec().contains(RULE_CHANGE_INIT_CONTENT_STR), equalTo(false));
}
use of org.commonjava.indy.promote.model.ValidationRuleDTO in project indy by Commonjava.
the class PromoteValidationsManager method getNamedRuleAsDTO.
public Optional<ValidationRuleDTO> getNamedRuleAsDTO(final String name) {
final Map<String, ValidationRuleDTO> rules = toDTO().getRules();
ValidationRuleDTO dto = rules.get(name);
if (dto == null) {
dto = rules.get(name + ".groovy");
}
return dto == null ? Optional.empty() : Optional.of(dto);
}
Aggregations