EventBaseCheck implements Checker { @Override public ImportSummary check( ImmutableEvent event, WorkContext ctx ) { ImportSummary importSummary = new ImportSummary(); List<String> errors = validate( event, ctx ); if ( !errors.isEmpty() ) { importSummary.setStatus( ERROR ); importSummary.setReference( event.getEvent() ); importSummary.getConflicts() .addAll( errors.stream().map( s -> new ImportConflict( "Event", s ) ).collect( Collectors.toList() ) ); importSummary.incrementIgnored(); } return importSummary; }  @Override ImportSummary check( ImmutableEvent event, WorkContext ctx );  }
@Test public void verifyErrorOnInvalidDueDate() { event.setEvent( event.getUid() ); event.setDueDate( "111-12-122" ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); assertHasConflict( importSummary, event, "Invalid event due date: " + event.getDueDate() ); }
@Test public void verifyErrorOnInvalidEventDate() { event.setEvent( event.getUid() ); event.setEventDate( "111-12-122" ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); assertHasConflict( importSummary, event, "Invalid event date: " + event.getEventDate() ); }
@Test public void verifyErrorOnInvalidCreatedAtClientDate() { event.setEvent( event.getUid() ); event.setCreatedAtClient( "111-12-122" ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); assertHasConflict( importSummary, event, "Invalid event created at client date: " + event.getCreatedAtClient() ); }
@Test public void verifyErrorOnInvalidLastUpdatedAtClientDate() { event.setEvent( event.getUid() ); event.setLastUpdatedAtClient( "111-12-122" ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); assertHasConflict( importSummary, event, "Invalid event last updated at client date: " + event.getLastUpdatedAtClient() ); }
@Test public void verifyErrorOnMissingProgramInstance() { event.setEvent( event.getUid() ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); assertHasConflict( importSummary, event, "No program instance found for event: " + event.getEvent() ); }
@Test public void verifyNoErrorOnNonCompletedProgramInstance() { event.setEvent( event.getUid() ); Map<String, ProgramInstance> programInstanceMap = new HashMap<>(); ProgramInstance programInstance = new ProgramInstance(); programInstanceMap.put( event.getUid(), programInstance ); when( workContext.getProgramInstanceMap() ).thenReturn( programInstanceMap ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertNoError( importSummary ); }
@Test public void verifyErrorOnEventWithDateNewerThanCompletedProgramInstance() { ImportOptions importOptions = ImportOptions.getDefaultImportOptions(); importOptions.setUser( new User() ); event.setEvent( event.getUid() ); Map<String, ProgramInstance> programInstanceMap = new HashMap<>(); ProgramInstance programInstance = new ProgramInstance(); programInstance.setStatus( ProgramStatus.COMPLETED ); programInstance.setEndDate( Date.from( ZonedDateTime.now().minusMonths( 1 ).toInstant() ) ); programInstanceMap.put( event.getUid(), programInstance ); when( workContext.getProgramInstanceMap() ).thenReturn( programInstanceMap ); when( workContext.getImportOptions() ).thenReturn( importOptions ); ImportSummary importSummary = rule.check( new ImmutableEvent( event ), workContext ); assertHasError( importSummary, event, null ); }