Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-1985

Test Scenario fails to populate Date field

    XMLWordPrintable

Details

    Description

      Under the conditions:

      • Model A has a Date field
      • Model B extends Model A
      • All rules have "java" dialect

      When you set a value to the Date field of Model B in a Test Scenario, the Test scenario fails to run and throws the Exception.

      20:59:23,323 INFO  [stdout] (http--127.0.0.1-8080-1) ERROR 14-11 20:59:23,322 (LoggingHelper.java:error:74) 	 Unable to run the scenario.
      20:59:23,323 INFO  [stdout] (http--127.0.0.1-8080-1) [Error: could not access/write property (dateTime) in: defaultPackage.SubModel]
      20:59:23,323 INFO  [stdout] (http--127.0.0.1-8080-1) [Near : {... __fact__.dateTime= __val__ ....}]
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1)              ^
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) [Line: 1, Column: 1]
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.PropertyAccessor.set(PropertyAccessor.java:372)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.PropertyAccessor.set(PropertyAccessor.java:139)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.ast.DeepAssignmentNode.getReducedValue(DeepAssignmentNode.java:97)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:106)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.mvel2.MVEL.eval(MVEL.java:165)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.ide.common.server.testscenarios.populators.FieldPopulator.populateField(FieldPopulator.java:47)
      20:59:23,324 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.ide.common.server.testscenarios.populators.SimpleFieldPopulator.populate(SimpleFieldPopulator.java:35)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.ide.common.server.testscenarios.populators.FactPopulator.populate(FactPopulator.java:52)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.ide.common.server.testscenarios.ScenarioRunner.applyFixtures(ScenarioRunner.java:119)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.ide.common.server.testscenarios.ScenarioRunner.run(ScenarioRunner.java:82)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.guvnor.server.TestScenarioServiceImplementation.runScenario(TestScenarioServiceImplementation.java:160)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.guvnor.server.TestScenarioServiceImplementation.runScenario(TestScenarioServiceImplementation.java:111)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.guvnor.server.TestScenarioServiceImplementation.runScenario(TestScenarioServiceImplementation.java:101)
      20:59:23,325 INFO  [stdout] (http--127.0.0.1-8080-1) 	at org.drools.guvnor.server.TestScenarioServiceServlet.runScenario(TestScenarioServiceServlet.java:39)
      

      This is because org.drools.ide.common.server.testscenarios.populators.FieldPopulatorFactory.isDate() uses Class.getDeclaredMethods which doesn't return super class methods.

          private boolean isDate(String fieldName) {
              for (Method method : factObject.getClass().getDeclaredMethods()) {
                  if (hasMutator(fieldName, method)) {
                      if (java.util.Date.class.isAssignableFrom(method.getParameterTypes()[0])) {
                          return true;
                      }
                  }
              }
              return false;
          }
      

      BTW, if your rules use "mvel" dialect, Guvnor will load org.drools.base.mvel.MVELCompilationUnit class and its static block registers for Date and Calendar org.mvel2.DataConversion. Hence this issue will not occur.

          static {
              //for handling dates as string literals
              DataConversion.addConversionHandler( Date.class,
                                                   new MVELDateCoercion() );
              DataConversion.addConversionHandler( Calendar.class,
                                                   new MVELCalendarCoercion() );
          }
      

      Attachments

        Activity

          People

            docmrc97 Mark Coble (Inactive)
            rhn-support-tkobayas Toshiya Kobayashi
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: