mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testRegisterForEvent_PersistFail() throws Exception
    {
        //mock datastore exception
        when(m_DataStore.persist(eq(EventAdminMessageService.class), Mockito.any(UUID.class), anyString(), 
                Mockito.any(Serializable.class))).thenThrow(new PersistenceFailedException("failed"));
        //construct message
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
                
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        // verify exception
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.PERSIST_ERROR, 
                "Failed persisting the remote registration, the registration will not be known if the system restarts." 
                + "failed");
        verify(m_ResponseWrapper).queue(channel);
    }
/**
     * Test if remote event is unable to be persisted that an Exception message is sent.
     * 
     */
Test if remote event is unable to be persisted that an Exception message is sent.
Test if remote event is unable to be persisted that an Exception message is sent .
@Test
    public void testRegisterForEvent_PersistFail() throws Exception
    {
        when(m_DataStore.persist(eq(EventAdminMessageService.class), Mockito.any(UUID.class), anyString(), 
                Mockito.any(Serializable.class))).thenThrow(new PersistenceFailedException("failed"));
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.PERSIST_ERROR, 
                "Failed persisting the remote registration, the registration will not be known if the system restarts." 
                + "failed");
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public void testRegisterForEvent_PersistFail ( ) throws Exception { when ( m_DataStore . persist ( eq ( EventAdminMessageService . class ) , Mockito . any ( UUID . class ) , anyString ( ) , Mockito . any ( Serializable . class ) ) ) . thenThrow ( new PersistenceFailedException ( "failed" ) ) ; EventRegistrationRequestData . Builder requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "test-topic" ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; EventAdminNamespace eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . EventRegistrationRequest ) . setData ( requestMessage . build ( ) . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createEventAdminMessage ( eventAdminMessage ) ; TerraHarvestPayload payload = createPayload ( eventAdminMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . PERSIST_ERROR , "Failed persisting the remote registration, the registration will not be known if the system restarts." + "failed" ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; }
Test if remote event is unable to be persisted that an Exception message is sent.
Test if remote event is unable to be persisted that an Exception message is sent .
//mock datastore exception //construct message // add required fields // mock the channel the message came from // replay // verify exception