ProgramStageCheck implements Checker { @Override public ImportSummary check(ImmutableEvent event, WorkContext ctx ) { IdScheme programStageIdScheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme(); final String programStageId = StringUtils.isEmpty( event.getProgramStage() ) ? "-" : event.getProgramStage(); ProgramStage programStage = ctx.getProgramStage( programStageIdScheme, programStageId ); if ( programStage == null ) { return error( "Event.programStage does not point to a valid programStage: " + event.getProgramStage(), event.getEvent() ); } return success(); }  @Override ImportSummary check(ImmutableEvent event, WorkContext ctx );  }
@Test public void failOnNullProgramStage() { Program program = new Program(); program.setUid( CodeGenerator.generateUid() ); program.setProgramType( ProgramType.WITH_REGISTRATION ); Map<String, Program> programMap = new HashMap<>(); programMap.put( program.getUid(), program ); event.setProgram( program.getUid() ); when( workContext.getProgramsMap() ).thenReturn( programMap ); ImportSummary summary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( summary, event, "Event.programStage does not point to a valid programStage: " + event.getProgramStage() ); }