SetMandatoryFieldImplementer implements RuleActionValidator { @Override public Map<String, List<String>> validateEvents( TrackerBundle bundle ) { Map<String, List<RuleEffect>> effects = getEffects( bundle.getEventRuleEffects() ); return effects.entrySet().stream() .collect( Collectors.toMap( e -> e.getKey(), e -> getEvent( bundle, e.getKey() ) .map( tei -> checkMandatoryDataElement( tei, e.getValue() ) ).orElse( Lists.newArrayList() ) ) ); }  @Override Class getActionClass(); @Override Map<String, List<String>> validateEnrollments( TrackerBundle bundle ); @Override Map<String, List<String>> validateEvents( TrackerBundle bundle ); @Override boolean isWarning();  }
@Test public void testValidateOkMandatoryFieldsForEvents() throws IOException { TrackerBundleParams bundleParams = createBundleFromJson( "tracker/event_events_and_enrollment.json" ); TrackerBundle trackerBundle = trackerBundleService.create( bundleParams ); trackerBundle = trackerBundleService.runRuleEngine( trackerBundle ); Map<String, List<String>> errors = implementerToTest.validateEvents( trackerBundle ); assertFalse( errors.isEmpty() ); errors.entrySet().stream() .forEach( e -> assertTrue( e.getValue().isEmpty() ) ); }
@Test public void testValidateWithErrorMandatoryFieldsForEvents() throws IOException { TrackerBundleParams bundleParams = createBundleFromJson( "tracker/event_events_and_enrollment_with_null_data_element.json" ); TrackerBundle trackerBundle = trackerBundleService.create( bundleParams ); trackerBundle = trackerBundleService.runRuleEngine( trackerBundle ); Map<String, List<String>> errors = implementerToTest.validateEvents( trackerBundle ); assertFalse( errors.isEmpty() ); errors.entrySet().stream() .filter( e -> !e.getKey().equals( "D9PbzJY8bJO" ) ) .forEach( e -> assertTrue( e.getValue().isEmpty() ) ); errors.entrySet().stream() .filter( e -> e.getKey().equals( "D9PbzJY8bJO" ) ) .forEach( e -> assertTrue( e.getValue().size() == 1 ) ); }