-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JSR-303 does not seems to validate
PostPosted: Mon Feb 06, 2012 7:12 pm 
Newbie

Joined: Mon Feb 06, 2012 6:56 pm
Posts: 2
Thanks in advance for any help. I am using drools with hibernate validator to validate our domain objects. The test class to test validation is:

public void validateAccountWithAddressMissingStreet() {

Account acc = new Account();
final EmailAddress emailAddress = new EmailAddress();
emailAddress.setLocalPart("local");
emailAddress.setDomainPart("domain");
acc.getEmailAddressList().add(emailAddress);
final Address[] addresses = {new Address(),new Address()};
//Good address
addresses[0].setStreetLine1("Test street");
addresses[0].setCity("City");
addresses[0].setState(State.CO);
addresses[0].setCountry(Country.AD);

//Bad address
addresses[1].setCity("City");
addresses[1].setState(State.CO);
addresses[1].setCountry(Country.AD);

acc.getAddressList().add(addresses[0]);
acc.getAddressList().add(addresses[1]);

Set<ConstraintViolation<Account>> constraintViolations = droolsValidator.validate(acc);

assertValidationFailure(constraintViolations);

The constraintViolations comes back as empty. The drools drl file is:

rule "Address StreetLine1 Required"
salience 10
when
$errorHolder : RulesValidationErrorHolder ()
$account : Account()
$badAddresses : ArrayList(size > 0) from collect(Address ( streetLine1 == null || == "") from $account.addressList)
then
$errorHolder.addError("{csp.core.address.streetLine1.notnull}",
"streetLine1", $badAddresses);
end

The validator does not seems to cascade validate the address collection.


Top
 Profile  
 
 Post subject: Re: JSR-303 does not seems to validate
PostPosted: Mon Feb 06, 2012 11:23 pm 
Newbie

Joined: Thu Feb 02, 2012 11:28 pm
Posts: 13
Location: shenzhen china
thinking ,thinking


Top
 Profile  
 
 Post subject: Re: JSR-303 does not seems to validate
PostPosted: Tue Feb 07, 2012 5:31 pm 
Newbie

Joined: Mon Feb 06, 2012 6:56 pm
Posts: 2
Here is more info. The rule is firing by drool and the collection is being validated correctly. That is, here is the console log output:

2012-02-07 13:22:17,437 [main] INFO o.hibernate.validator.util.Version - Hibernate Validator 4.1.0.Final
2012-02-07 13:22:17,444 [main] INFO o.h.v.e.r.DefaultTraversableResolver - Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
2012-02-07 13:22:19,350 [main] DEBUG c.b.csp.core.drools.DroolsValidator - Performing validations on PlatformEntity : com.betfair.csp.core.model.Account using Drools rules.
==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:1519302:1519302:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6], getObject()=com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6, getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@fe7f80, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:1519302:1519302:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]OBJECT ASSERTED value:com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6 factId: 2

==>[ActivationCreatedEvent: getActivation()=[Activation rule=Address StreetLine1 Required, act#=0, salience=10, tuple=[fact 0:11:18628673:1772750:11:null:[com.betfair.csp.core.model.Address@1b0caf]]
[fact 0:3:3306125:3306125:3:DEFAULT:com.betfair.csp.core.model.Account@32728d]
[fact 0:2:1519302:1519302:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6]
], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@fe7f80]
ACTIVATION CREATED rule:Address StreetLine1 Required activationId:Address StreetLine1 Required [11, 3, 2] declarations: $errorHolder=com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6(2); $account=com.betfair.csp.core.model.Account@32728d(3); $badAddresses=[com.betfair.csp.core.model.Address@1b0caf](11)
==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:3:3306125:3306125:3:DEFAULT:com.betfair.csp.core.model.Account@32728d], getObject()=com.betfair.csp.core.model.Account@32728d, getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@fe7f80, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:3:3306125:3306125:3:DEFAULT:com.betfair.csp.core.model.Account@32728d], leftTuple=null, originOffset=-1, propagationNumber=3, rule=null, type=0]]
OBJECT ASSERTED value:com.betfair.csp.core.model.Account@32728d factId: 3
==>[BeforeActivationFiredEvent: getActivation()=[Activation rule=Address StreetLine1 Required, act#=0, salience=10, tuple=[fact 0:11:18628673:1772750:11:null:[com.betfair.csp.core.model.Address@1b0caf]]
[fact 0:3:3306125:3306125:3:DEFAULT:com.betfair.csp.core.model.Account@32728d]
[fact 0:2:1519302:1519302:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6]
], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@fe7f80]
BEFORE ACTIVATION FIRED rule:Address StreetLine1 Required activationId:Address StreetLine1 Required [11, 3, 2] declarations: $errorHolder=com.betfair.csp.core.drools.RulesValidationErrorHolder@172ec6(2); $account=com.betfair.csp.core.model.Account@32728d(3); $badAddresses=[com.betfair.csp.core.model.Address@1b0caf](11)

However, the validation seems to continue or attempt to validate the collection without activating the drools rule. Maybe I am misinterpreting the output. Here is the rest of the log with the test being ran fully.

2012-02-07 14:27:38,944 [main] DEBUG c.b.csp.core.drools.DroolsValidator - Validations on PlatformEntity : com.betfair.csp.core.model.Account using Drools FAILED. Constraint Violations are RulesValidationError[
message={csp.core.address.streetLine1.notnull}
field=streetLine1
payload=Address[
id=<null>
streetLine1=<null>
streetLine2=<null>
city=City
state=State[
value=Colorado
name=CO
ordinal=5
]
zipCode=<null>
zipExt=<null>
country=Country[
value=Andorra
name=AD
ordinal=4
]
verified=<null>
addressType=<null>
description=<null>
additionalInfo=<null>
creatorApplicationId=<null>
creatorUserCredentialId=<null>
modifierUserCredentialId=<null>
createTime=<null>
modifierApplicationId=<null>
lastUpdateTime=<null>
entityState=<null>
className=<null>
]
]
2012-02-07 14:27:39,113 [main] DEBUG c.b.csp.core.drools.DroolsValidator - Performing validations on PlatformEntity : com.betfair.csp.core.model.Address using Drools rules.
==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:7384438:7384438:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@70ad76], getObject()=com.betfair.csp.core.drools.RulesValidationErrorHolder@70ad76, getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@18c2354, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:7384438:7384438:2:DEFAULT:com.betfair.csp.core.drools.RulesValidationErrorHolder@70ad76], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]
OBJECT ASSERTED value:com.betfair.csp.core.drools.RulesValidationErrorHolder@70ad76 factId: 2
==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:3:5709968:5709968:3:DEFAULT:com.betfair.csp.core.model.Address@572090], getObject()=com.betfair.csp.core.model.Address@572090, getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@18c2354, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:3:5709968:5709968:3:DEFAULT:com.betfair.csp.core.model.Address@572090], leftTuple=null, originOffset=-1, propagationNumber=3, rule=null, type=0]]
OBJECT ASSERTED value:com.betfair.csp.core.model.Address@572090 factId: 3
2012-02-07 14:27:42,182 [main] DEBUG c.b.csp.core.drools.DroolsValidator - Validation on PlatformEntity : com.betfair.csp.core.model.Address using Drools SUCCEEDED (3069 msec)
2012-02-07 14:27:42,182 [main] DEBUG c.b.csp.core.drools.DroolsValidator - Performing validations on PlatformEntity : com.betfair.csp.core.model.Address using Drools rules.

To tomyun-what is thinking,thinking?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.