mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestRemoteChannelLookupImpl.java
@Test
    public void testPersistenceExistingChannel() throws PersistenceFailedException, InvalidProtocolBufferException, 
        IllegalArgumentException, ValidationFailedException
    {
        int systemId = 300;
        
        // mock channel that will be created
        when(m_TransportChannel.getTransportLayerName()).thenReturn("tl");
        when(m_TransportChannel.getLocalMessageAddress()).thenReturn("l-a");
        when(m_TransportChannel.getRemoteMessageAddress()).thenReturn("r-a");
        
        // 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 transport channel to see if it is persisted, original socket channel should be part of the model still
        m_SUT.syncTransportChannel("tl", "l-a", "r-a", systemId);
        
        // construct the expected model object that will be created based on the current list
        SystemChannels expectedChannels = SystemChannels.newBuilder().setSysId(systemId)
                .addTransportChannel(TransportChannelType.newBuilder()
                .setTransportName("tl")
                .setLocalAddress("l-a")
                .setRemoteAddress("r-a").build()).build();
        
        // verify channel data is merged with existing data
        ArgumentCaptor<byte[]> byteCapture = ArgumentCaptor.forClass(byte[].class);
        verify(channelData).setEntity(byteCapture.capture());
        SystemChannels actualChannels = SystemChannels.parseFrom(byteCapture.getValue());
        assertThat(expectedChannels, is(actualChannels));
        
        verify(m_PersistentDataStore).merge(channelData);
    }
/**
     * Verify a channel is persisted if it is the 2nd in the channel set (and that the first one is still in the list of
     * channels to persist).
     * 
     * Verify transport channel can be persisted.
     */
Verify a channel is persisted if it is the 2nd in the channel set (and that the first one is still in the list of
channels to persist).

Verify transport channel can be persisted.
Verify a channel is persisted if it is the 2nd in the channel set ( and that the first one is still in the list of channels to persist ) . Verify transport channel can be persisted .
@Test
    public void testPersistenceExistingChannel() throws PersistenceFailedException, InvalidProtocolBufferException, 
        IllegalArgumentException, ValidationFailedException
    {
        int systemId = 300;
        when(m_TransportChannel.getTransportLayerName()).thenReturn("tl");
        when(m_TransportChannel.getLocalMessageAddress()).thenReturn("l-a");
        when(m_TransportChannel.getRemoteMessageAddress()).thenReturn("r-a");
        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.syncTransportChannel("tl", "l-a", "r-a", systemId);
        SystemChannels expectedChannels = SystemChannels.newBuilder().setSysId(systemId)
                .addTransportChannel(TransportChannelType.newBuilder()
                .setTransportName("tl")
                .setLocalAddress("l-a")
                .setRemoteAddress("r-a").build()).build();
        ArgumentCaptor<byte[]> byteCapture = ArgumentCaptor.forClass(byte[].class);
        verify(channelData).setEntity(byteCapture.capture());
        SystemChannels actualChannels = SystemChannels.parseFrom(byteCapture.getValue());
        assertThat(expectedChannels, is(actualChannels));
        verify(m_PersistentDataStore).merge(channelData);
    }
@ Test public void testPersistenceExistingChannel ( ) throws PersistenceFailedException , InvalidProtocolBufferException , IllegalArgumentException , ValidationFailedException { int systemId = 300 ; when ( m_TransportChannel . getTransportLayerName ( ) ) . thenReturn ( "tl" ) ; when ( m_TransportChannel . getLocalMessageAddress ( ) ) . thenReturn ( "l-a" ) ; when ( m_TransportChannel . getRemoteMessageAddress ( ) ) . thenReturn ( "r-a" ) ; 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 . syncTransportChannel ( "tl" , "l-a" , "r-a" , systemId ) ; SystemChannels expectedChannels = SystemChannels . newBuilder ( ) . setSysId ( systemId ) . addTransportChannel ( TransportChannelType . newBuilder ( ) . setTransportName ( "tl" ) . setLocalAddress ( "l-a" ) . setRemoteAddress ( "r-a" ) . build ( ) ) . build ( ) ; ArgumentCaptor < byte [ ] > byteCapture = ArgumentCaptor . forClass ( byte [ ] . class ) ; verify ( channelData ) . setEntity ( byteCapture . capture ( ) ) ; SystemChannels actualChannels = SystemChannels . parseFrom ( byteCapture . getValue ( ) ) ; assertThat ( expectedChannels , is ( actualChannels ) ) ; verify ( m_PersistentDataStore ) . merge ( channelData ) ; }
Verify a channel is persisted if it is the 2nd in the channel set (and that the first one is still in the list of
 channels to persist).
Verify a channel is persisted if it is the 2nd in the channel set ( and that the first one is still in the list of channels to persist ) .
// mock channel that will be created // mock existing entry in data store // sync transport channel to see if it is persisted, original socket channel should be part of the model still // construct the expected model object that will be created based on the current list // verify channel data is merged with existing data