https://github.com/sandesh300/Rule-Engine-Application


Test Cases Documentation for RuleServiceTest

This 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.


1. Test Case: createRule_ValidRuleString_Success

@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));
}


2. Test Case: createRule_InvalidRuleString_ThrowsException

@Test
void createRule_InvalidRuleString_ThrowsException() {
    String invalidRuleString = "age > 30 AND";
    assertThrows(CustomException.class, () -> ruleService.createRule(invalidRuleString, "Invalid Rule"));
}


3. Test Case: createRule_UnbalancedParentheses_ThrowsException