mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestRemoteChannelLookupImpl.java
@Test
    public void testPersistenceDataStoreException() throws PersistenceFailedException, IllegalArgumentException,
        ValidationFailedException
    {
        int systemId = 300;
        
        // mock data store to throw exception, should still be able to add item, just won't be persisted
        when(m_PersistentDataStore.persist(Mockito.any(Class.class), Mockito.any(UUID.class), anyString(),
                Mockito.any(Serializable.class))).thenThrow(new PersistenceFailedException());
        doThrow(new PersistenceFailedException()).when(m_PersistentDataStore).merge(Mockito.any(PersistentData.class));
        
        stubSocketChannel(m_ClientSocketChannel, "host", 100, false);
        
        // sync channel to see if it is added even if not persisted
        m_SUT.syncClientSocketChannel("host", 100, systemId);
        
        RemoteChannel channel = m_SUT.getChannel(systemId);
        assertThat(channel, is(notNullValue()));
        
        // mock existing entry in data store
        Collection<PersistentData> channelDataList = new ArrayList<PersistentData>();
        when(m_PersistentDataStore.query(RemoteChannelLookupImpl.class, new Integer(systemId).toString()))
            .thenReturn(channelDataList);
        PersistentData channelData = mock(PersistentData.class);
        channelDataList.add(channelData);
        
        // sync channel again, should hit merge failure this time
        m_SUT.syncClientSocketChannel("host", 100, systemId);   
    }
/**
     * Verify {@link PersistentDataStore} exceptions thrown are handled properly.  If there is a failure, the channel 
     * will not be persisted, but the channel should still be available locally in memory.
     */
Verify  PersistentDataStore exceptions thrown are handled properly.  If there is a failure, the channel
will not be persisted, but the channel should still be available locally in memory.
Verify PersistentDataStore exceptions thrown are handled properly . If there is a failure the channel will not be persisted but the channel should still be available locally in memory .
@Test
    public void testPersistenceDataStoreException() throws PersistenceFailedException, IllegalArgumentException,
        ValidationFailedException
    {
        int systemId = 300;
        when(m_PersistentDataStore.persist(Mockito.any(Class.class), Mockito.any(UUID.class), anyString(),
                Mockito.any(Serializable.class))).thenThrow(new PersistenceFailedException());
        doThrow(new PersistenceFailedException()).when(m_PersistentDataStore).merge(Mockito.any(PersistentData.class));
        stubSocketChannel(m_ClientSocketChannel, "host", 100, false);
        m_SUT.syncClientSocketChannel("host", 100, systemId);
        RemoteChannel channel = m_SUT.getChannel(systemId);
        assertThat(channel, is(notNullValue()));
        Collection<PersistentData> channelDataList = new ArrayList<PersistentData>();
        when(m_PersistentDataStore.query(RemoteChannelLookupImpl.class, new Integer(systemId).toString()))
            .thenReturn(channelDataList);
        PersistentData channelData = mock(PersistentData.class);
        channelDataList.add(channelData);
        m_SUT.syncClientSocketChannel("host", 100, systemId);   
    }
@ Test public void testPersistenceDataStoreException ( ) throws PersistenceFailedException , IllegalArgumentException , ValidationFailedException { int systemId = 300 ; when ( m_PersistentDataStore . persist ( Mockito . any ( Class . class ) , Mockito . any ( UUID . class ) , anyString ( ) , Mockito . any ( Serializable . class ) ) ) . thenThrow ( new PersistenceFailedException ( ) ) ; doThrow ( new PersistenceFailedException ( ) ) . when ( m_PersistentDataStore ) . merge ( Mockito . any ( PersistentData . class ) ) ; stubSocketChannel ( m_ClientSocketChannel , "host" , 100 , false ) ; m_SUT . syncClientSocketChannel ( "host" , 100 , systemId ) ; RemoteChannel channel = m_SUT . getChannel ( systemId ) ; assertThat ( channel , is ( notNullValue ( ) ) ) ; Collection < PersistentData > channelDataList = new ArrayList < PersistentData > ( ) ; when ( m_PersistentDataStore . query ( RemoteChannelLookupImpl . class , new Integer ( systemId ) . toString ( ) ) ) . thenReturn ( channelDataList ) ; PersistentData channelData = mock ( PersistentData . class ) ; channelDataList . add ( channelData ) ; m_SUT . syncClientSocketChannel ( "host" , 100 , systemId ) ; }
Verify {@link PersistentDataStore} exceptions thrown are handled properly.
Verify { @link PersistentDataStore } exceptions thrown are handled properly .
// mock data store to throw exception, should still be able to add item, just won't be persisted // sync channel to see if it is added even if not persisted // mock existing entry in data store // sync channel again, should hit merge failure this time