https://github.com/sandesh300/Rule-Engine-Application
RuleServiceTestThis document outlines the test cases covered in the RuleServiceTest class, which tests the RuleService for creating, modifying, combining, evaluating, and deleting rules, as well as handling exceptions. The service interacts with the RuleRepository to perform the operations.
createRule_ValidRuleString_Success"age > 30 AND department = 'Sales'".createRule method."operator" and value "AND".@Test
void createRule_ValidRuleString_Success() {
String ruleString = "age > 30 AND department = 'Sales'";
when(ruleRepository.save(any(Rule.class))).thenAnswer(i -> i.getArguments()[0]);
Rule result = ruleService.createRule(ruleString, "Senior Sales Rule");
assertNotNull(result);
assertEquals("operator", result.getRootNode().getType());
verify(ruleRepository).save(any(Rule.class));
}
createRule_InvalidRuleString_ThrowsExceptionCustomException."age > 30 AND".createRule method.CustomException is thrown.@Test
void createRule_InvalidRuleString_ThrowsException() {
String invalidRuleString = "age > 30 AND";
assertThrows(CustomException.class, () -> ruleService.createRule(invalidRuleString, "Invalid Rule"));
}
createRule_UnbalancedParentheses_ThrowsException