Search code examples
javajbossdroolsguvnor

Guvnor test scenario: instantiating fact with arguments in constructor


I've imported to my Guvnor repository the .jar with the Pojo model of what I want to be the facts. One of these classes has a constructor with arguments, and it's the only Fact I can't instantiate on the Test Scenario, in the Given section. I get an InstantiationException pointing to the class.

I've tried adding the fields to the fact and filling them with the input values I want but still nothing.

My question is if there's any special way I should be doing this for a fact that has arguments in its constructor, since I can test my rules with any of the other objects.

Thanks


Solution

  • It would be better if your facts do not have constructor arguments, but you can use the following workaround:

    Create a rule that asserts your Fact with constructor arguments, and make sure it only works on test cases

    when
        MyBreadcrumbThatDefinesTestRuns()
    then
        MyFactWithConstructorArgs f = new MyFactWithConstructorArgs("arrgh")
        insert(f)
    end
    

    now, you need to define a fact in your model named MyBreadcrumbThatDefinesTestRuns and insert it into your session on the Given section of the test definition.