@Test
public void verifyValidationFailOnJsonSerializationError()
    throws JsonProcessingException
{

    ObjectMapper localObjectMapper = mock( ObjectMapper.class );
    when( serviceDelegator.getJsonMapper() ).thenReturn( localObjectMapper );
    when( localObjectMapper.writeValueAsString( Mockito.any() ) )
        .thenThrow( new JsonProcessingException( "Error" )
        {
        } );
    event.setProgramStage( "prgstg1" );
    DataElement de1 = addToDataElementMap( createDataElement( 'A' ) );
    final Program programA = createProgram( 'A' );
    final ProgramStage programStageA = createProgramStage( 'A', programA );
    programStageA.setValidationStrategy( ValidationStrategy.ON_UPDATE_AND_INSERT );
    programStageA.setProgramStageDataElements( Sets.newHashSet(
        createProgramStageDataElement( programStageA, de1, 1, true ) ) );
    when( workContext.getProgramStage( IdScheme.UID, "prgstg1" ) ).thenReturn( programStageA );
    addToDataValueMap( event.getUid(),
        createEventDataValue( de1.getUid(), "1" ) );
    DataValue dv1 = createDataValue( de1.getUid(), "1" );
    event.setDataValues( Sets.newHashSet( dv1 ) );
    final ImportSummary summary = rule.check( new ImmutableEvent( event ), this.workContext );
    assertHasError( summary, event, null );
    assertThat( summary.getConflicts(), hasSize( 1 ) );
    assertThat( summary.getConflicts().iterator().next().getValue(), is( "Invalid data value found." ) );
    assertThat( summary.getConflicts().iterator().next().getObject(), is( de1.getUid() ) );
}