mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/controller/TestControllerHistoryMgr.java
@Test
    public void testControllerInfoHelper() throws IllegalArgumentException, PersistenceFailedException, 
        ValidationFailedException
    {
        final String hostname = "100.200.300.400";
        final int port = 99;
        final int systemId = 123;
        final long initialTime = System.currentTimeMillis();
        
        final ControllerHistory initialController = new ControllerHistory();
        initialController.setControllerId(systemId);
        initialController.setHostName(hostname);
        initialController.setPort(port);
        initialController.setLastConnected(initialTime);
        
        final UUID uuid = UUID.randomUUID();
        final PersistentData data = new PersistentData(uuid, hostname, ControllerHistory.class.toString(), 
                initialController);
        
        final Collection<PersistentData> collection = new HashSet<>();
        collection.add(data);
        when(m_DataStore.query(eq(ControllerHistory.class), Mockito.anyString())).thenReturn(collection);
        
        final RemoteChannel remoteChannel = mock(RemoteChannel.class, 
                withSettings().extraInterfaces(SocketChannel.class));
        when(((SocketChannel)remoteChannel).getHost()).thenReturn(hostname);
        when(((SocketChannel)remoteChannel).getPort()).thenReturn(port);
        
        final ControllerInfoData dataMsg = ControllerInfoData.newBuilder().setName("Dart").build();
        
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put(RemoteConstants.EVENT_PROP_SYS_ID, systemId);
        props.put(RemoteConstants.EVENT_PROP_CHANNEL, remoteChannel);
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, dataMsg);
        final Event controllerInfoEvent = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);
        
        m_ControllerInfoHelper.handleEvent(controllerInfoEvent);
        
        final ArgumentCaptor<PersistentData> dataCaptor = ArgumentCaptor.forClass(PersistentData.class);
        verify(m_DataStore).merge(dataCaptor.capture());
        final PersistentData updatedData = dataCaptor.getValue();
        final ControllerHistory updatedController = (ControllerHistory)updatedData.getEntity();
        assertThat(updatedController.getControllerId(), is(systemId));
        assertThat(updatedController.getControllerName(), is("Dart"));
        assertThat(updatedController.getHostName(), is(hostname));
        assertThat(updatedController.getPort(), is(port));
        assertThat(updatedController.getLastConnected(), is(initialTime));
    }
/**
     * Tests the controller info helper and verifies that the persistent data for the controller history is updated 
     * and merged.
     */
Tests the controller info helper and verifies that the persistent data for the controller history is updated
and merged.
Tests the controller info helper and verifies that the persistent data for the controller history is updated and merged .
@Test
    public void testControllerInfoHelper() throws IllegalArgumentException, PersistenceFailedException, 
        ValidationFailedException
    {
        final String hostname = "100.200.300.400";
        final int port = 99;
        final int systemId = 123;
        final long initialTime = System.currentTimeMillis();
        final ControllerHistory initialController = new ControllerHistory();
        initialController.setControllerId(systemId);
        initialController.setHostName(hostname);
        initialController.setPort(port);
        initialController.setLastConnected(initialTime);
        final UUID uuid = UUID.randomUUID();
        final PersistentData data = new PersistentData(uuid, hostname, ControllerHistory.class.toString(), 
                initialController);
        final Collection<PersistentData> collection = new HashSet<>();
        collection.add(data);
        when(m_DataStore.query(eq(ControllerHistory.class), Mockito.anyString())).thenReturn(collection);
        final RemoteChannel remoteChannel = mock(RemoteChannel.class, 
                withSettings().extraInterfaces(SocketChannel.class));
        when(((SocketChannel)remoteChannel).getHost()).thenReturn(hostname);
        when(((SocketChannel)remoteChannel).getPort()).thenReturn(port);
        final ControllerInfoData dataMsg = ControllerInfoData.newBuilder().setName("Dart").build();
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put(RemoteConstants.EVENT_PROP_SYS_ID, systemId);
        props.put(RemoteConstants.EVENT_PROP_CHANNEL, remoteChannel);
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, dataMsg);
        final Event controllerInfoEvent = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);
        m_ControllerInfoHelper.handleEvent(controllerInfoEvent);
        final ArgumentCaptor<PersistentData> dataCaptor = ArgumentCaptor.forClass(PersistentData.class);
        verify(m_DataStore).merge(dataCaptor.capture());
        final PersistentData updatedData = dataCaptor.getValue();
        final ControllerHistory updatedController = (ControllerHistory)updatedData.getEntity();
        assertThat(updatedController.getControllerId(), is(systemId));
        assertThat(updatedController.getControllerName(), is("Dart"));
        assertThat(updatedController.getHostName(), is(hostname));
        assertThat(updatedController.getPort(), is(port));
        assertThat(updatedController.getLastConnected(), is(initialTime));
    }
@ Test public void testControllerInfoHelper ( ) throws IllegalArgumentException , PersistenceFailedException , ValidationFailedException { final String hostname = "100.200.300.400" ; final int port = 99 ; final int systemId = 123 ; final long initialTime = System . currentTimeMillis ( ) ; final ControllerHistory initialController = new ControllerHistory ( ) ; initialController . setControllerId ( systemId ) ; initialController . setHostName ( hostname ) ; initialController . setPort ( port ) ; initialController . setLastConnected ( initialTime ) ; final UUID uuid = UUID . randomUUID ( ) ; final PersistentData data = new PersistentData ( uuid , hostname , ControllerHistory . class . toString ( ) , initialController ) ; final Collection < PersistentData > collection = new HashSet < > ( ) ; collection . add ( data ) ; when ( m_DataStore . query ( eq ( ControllerHistory . class ) , Mockito . anyString ( ) ) ) . thenReturn ( collection ) ; final RemoteChannel remoteChannel = mock ( RemoteChannel . class , withSettings ( ) . extraInterfaces ( SocketChannel . class ) ) ; when ( ( ( SocketChannel ) remoteChannel ) . getHost ( ) ) . thenReturn ( hostname ) ; when ( ( ( SocketChannel ) remoteChannel ) . getPort ( ) ) . thenReturn ( port ) ; final ControllerInfoData dataMsg = ControllerInfoData . newBuilder ( ) . setName ( "Dart" ) . build ( ) ; final Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( RemoteConstants . EVENT_PROP_SYS_ID , systemId ) ; props . put ( RemoteConstants . EVENT_PROP_CHANNEL , remoteChannel ) ; props . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , dataMsg ) ; final Event controllerInfoEvent = new Event ( RemoteConstants . TOPIC_MESSAGE_RECEIVED , props ) ; m_ControllerInfoHelper . handleEvent ( controllerInfoEvent ) ; final ArgumentCaptor < PersistentData > dataCaptor = ArgumentCaptor . forClass ( PersistentData . class ) ; verify ( m_DataStore ) . merge ( dataCaptor . capture ( ) ) ; final PersistentData updatedData = dataCaptor . getValue ( ) ; final ControllerHistory updatedController = ( ControllerHistory ) updatedData . getEntity ( ) ; assertThat ( updatedController . getControllerId ( ) , is ( systemId ) ) ; assertThat ( updatedController . getControllerName ( ) , is ( "Dart" ) ) ; assertThat ( updatedController . getHostName ( ) , is ( hostname ) ) ; assertThat ( updatedController . getPort ( ) , is ( port ) ) ; assertThat ( updatedController . getLastConnected ( ) , is ( initialTime ) ) ; }
Tests the controller info helper and verifies that the persistent data for the controller history is updated
 and merged.
Tests the controller info helper and verifies that the persistent data for the controller history is updated and merged .