[rules-users] Drools verifier - redundancy detection

bitter rgorzkow at gmail.com
Sun May 20 15:13:37 EDT 2012


I would like to use drools-verifier to detect redundancy in my drl files. But
drools-verifier can not detect redundancy even in simple drl. Maybe I do
something wrong ;/. 
  
*Simple drl file:*

rule "rule 1"
when
   	$person: Person(age==16, name=="Anna")
then
	retract($person);
end

rule "rule 4"
when
   	$person: Person(age==16, name=="Anna")
then
	retract($person);
end

*And my test:*

@Test
	public void verifyRules() {
		//given
		VerifierBuilder vbuilder = VerifierBuilderFactory.newVerifierBuilder();
		Verifier verifier = vbuilder.newVerifier();

		verifier.addResourcesToVerify(new
ClassPathResource("qualityVerification.drl", getClass()), ResourceType.DRL);

		if (verifier.hasErrors()) {
			for(VerifierError ve : verifier.getErrors()) {
				System.out.println(ve.getMessage());
			}
			throw new RuntimeException("ERRORS ");
		}

		//when
		verifier.fireAnalysis();

		//then
		VerifierReport report = verifier.getResult();

		System.out.println(">>>>>>>>> ERRORS: ");
		for(VerifierMessageBase vmb : report.getBySeverity(Severity.ERROR)) {
			System.out.println(vmb + ". Type: " + vmb.getMessageType());
		}

		System.out.println(">>>>>>>>> WARNINGS: ");
		for(VerifierMessageBase vmb : report.getBySeverity(Severity.WARNING)) {
			System.out.println(vmb + ". Type: " + vmb.getMessageType());
		}

		System.out.println(">>>>>>>>> NOTES: ");
		for(VerifierMessageBase vmb : report.getBySeverity(Severity.NOTE)) {
			System.out.println(vmb + ". Type: " + vmb.getMessageType());
		}

		System.out.println(">>>>>>>>> MISSING RANGE: ");
		for(MissingRange mr : report.getRangeCheckCauses()) {
			System.out.println(mr);
		}

	}

*OUTPUT:*

>>>>>>>>> ERRORS: 
>>>>>>>>> WARNINGS: 
Warning id = 0:
faulty : LiteralRestriction from rule [rule 4] value '== Anna'
Rule base covers == Anna, but it is missing != Anna 
	Cause trace: 
. Type: MISSING_EQUALITY
Warning id = 1:
faulty : LiteralRestriction from rule [rule 4] value '== 16'
Rule base covers == 16, but it is missing != 16 
	Cause trace: 
. Type: MISSING_EQUALITY
Warning id = 2:
faulty : LiteralRestriction from rule [rule 1] value '== Anna'
Rule base covers == Anna, but it is missing != Anna 
	Cause trace: 
. Type: MISSING_EQUALITY
Warning id = 3:
faulty : LiteralRestriction from rule [rule 1] value '== 16'
Rule base covers == 16, but it is missing != 16 
	Cause trace: 
. Type: MISSING_EQUALITY
>>>>>>>>> NOTES: 
>>>>>>>>> MISSING RANGE: 
Gap: (Field 'age' from object type 'Person') Operator = '<' 16 from rule:
[rule 4]
Gap: (Field 'age' from object type 'Person') Operator = '>' 16 from rule:
[rule 4]
Gap: (Field 'age' from object type 'Person') Operator = '<' 16 from rule:
[rule 1]
Gap: (Field 'age' from object type 'Person') Operator = '>' 16 from rule:
[rule 1]

Is it a bug or I do something wrong?


--
View this message in context: http://drools.46999.n3.nabble.com/Drools-verifier-redundancy-detection-tp4003736.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list