mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testEventHandlerImpl_IllegalArgExceptionReset() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        Event event = new Event("EVENT", properties);
        
        EventRegistrationRequestData requestData = EventRegistrationRequestData.newBuilder()
                .setCanQueueEvent(false)
                .setExpirationTimeHours(1)
                .setObjectFormat(RemoteTypesGen.LexiconFormat.Enum.UUID_ONLY)
                .setFilter("(something.id=Ruby)")
                .addTopic("Sapphire")
                .build();   
        
        //conversion behavior
        List<ComplexTypesMapEntry> props = new ArrayList<ComplexTypesMapEntry>();
        when(m_ConversionService. mapToComplexTypesMap(anyMap(), 
                (RemoteTypesGen.LexiconFormat.Enum)any())).thenReturn(props);

        //exception behavior
        doThrow(new IllegalArgumentException("Exception!")).when(m_MessageWrapper).trySend(anyInt(), 
                Mockito.any(EncryptType.class));
        
        EventHandlerImpl handler = m_SUT.new EventHandlerImpl(200, EncryptType.AES_ECDH_ECDSA, requestData);
        //handle event 4 times, the fourth time should not throw exception
        int tries = 0;
        while (tries < 5)
        {
            handler.handleEvent(event);
            Thread.sleep(300);
            tries++;
            
            //verify
            assertThat("Failed attempts matches attempts.", handler.getFailedAttemptCount(), is(tries));
        }
        //verify exception logging only three times
        verify(m_Logger, times(3)).warning(anyString(), anyObject());
        
        //mock success
        doReturn(true).when(m_MessageWrapper).trySend(anyInt(), eq(EncryptType.AES_ECDH_ECDSA));
        
        //handle even again
        handler.handleEvent(event);
        Thread.sleep(300);
        
        //verify
        assertThat("Failed attempts does NOT match attempts.", handler.getFailedAttemptCount(), is(0));
    }
/**
     * Test if a channel to the remote system is not available that an error is thrown only three times.
     * Verify reset if successful.
     */
Test if a channel to the remote system is not available that an error is thrown only three times.
Verify reset if successful.
Test if a channel to the remote system is not available that an error is thrown only three times . Verify reset if successful .
@Test
    public void testEventHandlerImpl_IllegalArgExceptionReset() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        Event event = new Event("EVENT", properties);
        EventRegistrationRequestData requestData = EventRegistrationRequestData.newBuilder()
                .setCanQueueEvent(false)
                .setExpirationTimeHours(1)
                .setObjectFormat(RemoteTypesGen.LexiconFormat.Enum.UUID_ONLY)
                .setFilter("(something.id=Ruby)")
                .addTopic("Sapphire")
                .build();   
        List<ComplexTypesMapEntry> props = new ArrayList<ComplexTypesMapEntry>();
        when(m_ConversionService. mapToComplexTypesMap(anyMap(), 
                (RemoteTypesGen.LexiconFormat.Enum)any())).thenReturn(props);
        doThrow(new IllegalArgumentException("Exception!")).when(m_MessageWrapper).trySend(anyInt(), 
                Mockito.any(EncryptType.class));
        EventHandlerImpl handler = m_SUT.new EventHandlerImpl(200, EncryptType.AES_ECDH_ECDSA, requestData);
        int tries = 0;
        while (tries < 5)
        {
            handler.handleEvent(event);
            Thread.sleep(300);
            tries++;
            assertThat("Failed attempts matches attempts.", handler.getFailedAttemptCount(), is(tries));
        }
         exception logging only three times
        verify(m_Logger, times(3)).warning(anyString(), anyObject());
        doReturn(true).when(m_MessageWrapper).trySend(anyInt(), eq(EncryptType.AES_ECDH_ECDSA));
        handler.handleEvent(event);
        Thread.sleep(300);
        assertThat("Failed attempts does NOT match attempts.", handler.getFailedAttemptCount(), is(0));
    }
@ Test public void testEventHandlerImpl_IllegalArgExceptionReset ( ) throws Exception { Map < String , Object > properties = new HashMap < String , Object > ( ) ; Event event = new Event ( "EVENT" , properties ) ; EventRegistrationRequestData requestData = EventRegistrationRequestData . newBuilder ( ) . setCanQueueEvent ( false ) . setExpirationTimeHours ( 1 ) . setObjectFormat ( RemoteTypesGen . LexiconFormat . Enum . UUID_ONLY ) . setFilter ( "(something.id=Ruby)" ) . addTopic ( "Sapphire" ) . build ( ) ; List < ComplexTypesMapEntry > props = new ArrayList < ComplexTypesMapEntry > ( ) ; when ( m_ConversionService . mapToComplexTypesMap ( anyMap ( ) , ( RemoteTypesGen . LexiconFormat . Enum ) any ( ) ) ) . thenReturn ( props ) ; doThrow ( new IllegalArgumentException ( "Exception!" ) ) . when ( m_MessageWrapper ) . trySend ( anyInt ( ) , Mockito . any ( EncryptType . class ) ) ; EventHandlerImpl handler = m_SUT . new EventHandlerImpl ( 200 , EncryptType . AES_ECDH_ECDSA , requestData ) ; int tries = 0 ; while ( tries < 5 ) { handler . handleEvent ( event ) ; Thread . sleep ( 300 ) ; tries ++ ; assertThat ( "Failed attempts matches attempts." , handler . getFailedAttemptCount ( ) , is ( tries ) ) ; } verify ( m_Logger , times ( 3 ) ) . warning ( anyString ( ) , anyObject ( ) ) ; doReturn ( true ) . when ( m_MessageWrapper ) . trySend ( anyInt ( ) , eq ( EncryptType . AES_ECDH_ECDSA ) ) ; handler . handleEvent ( event ) ; Thread . sleep ( 300 ) ; assertThat ( "Failed attempts does NOT match attempts." , handler . getFailedAttemptCount ( ) , is ( 0 ) ) ; }
Test if a channel to the remote system is not available that an error is thrown only three times.
Test if a channel to the remote system is not available that an error is thrown only three times .
//conversion behavior //exception behavior //handle event 4 times, the fourth time should not throw exception //verify //verify exception logging only three times //mock success //handle even again //verify