mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/TestCustomCommsServiceImpl_LinkLayer.java
@Test
    public void testCreateLinkLayer_Named() throws Exception 
    {
        //test to see if you get a LinkLayer with the specified name
        String name = "name";
        String linkName = "CreationName";
        
        when(m_PhysInternal.getName()).thenReturn(name);
        PhysicalLink physicalLink = m_SUT.createPhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT);

        LinkLayer layer = m_SUT.createLinkLayer(LL_PRODUCT_TYPE, linkName, physicalLink.getName());
        
        assertThat(layer, is((LinkLayer)m_LinkInternal));
        
        //add mocking behavior for next layer
        when(m_LinkInternal.getPhysicalLink()).thenReturn(m_PhysInternal);
        
        //verify
        Map<String, Object> props = new HashMap<>();
        props.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, name);
        verify(m_LinkRegistry).createNewObject(m_LinkFactory, linkName, props);
        
        //reg mock
        Set<LinkLayerInternal> links = new HashSet<>();
        links.add(m_LinkInternal);
        when(m_LinkRegistry.getObjects()).thenReturn(links);
        
        //mock another physical link
        UUID uuidDos = UUID.randomUUID();
        PhysicalLinkInternal physInternal = mock(PhysicalLinkInternal.class);
        when(physInternal.getUuid()).thenReturn(uuidDos);
        when(m_PhysRegistry.createNewObject(eq(m_PhysFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(physInternal);
        
        //create phys
        String physName2 = "name2";
        when(physInternal.getName()).thenReturn(physName2);
        PhysicalLink physicalLink2 = m_SUT.createPhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT);

        String linkName2 = "OriginalName";
        LinkLayerInternal linkInternal = mock(LinkLayerInternal.class);
        when(linkInternal.getName()).thenReturn(linkName2);
        when(linkInternal.getPhysicalLink()).thenReturn(physicalLink2);
        when(linkInternal.getFactory()).thenReturn(m_LinkFactory);
        when(m_LinkRegistry.createNewObject(eq(m_LinkFactory), eq(linkName2), Mockito.any(Map.class))).
            thenReturn(linkInternal);
        
        //act
        LinkLayer layer2 = m_SUT.createLinkLayer(LL_PRODUCT_TYPE, linkName2, physicalLink2.getName());

        assertThat(layer2, is(notNullValue()));
        
        //add to mock reg list
        links.add(linkInternal);
        
        //verify
        Map<String, Object> props2 = new HashMap<>();
        props2.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, physName2);
        verify(m_LinkRegistry).createNewObject(m_LinkFactory, linkName2, props2);
        verify(m_WakeLock, times(4)).activate();
        verify(m_WakeLock, times(4)).cancel();
    }
/**
     * Verify that a newly created link layer with a specified name is correctly created.
     * Verify multiples can be created as long as the physical link name is different.
     */
Verify that a newly created link layer with a specified name is correctly created.
Verify multiples can be created as long as the physical link name is different.
Verify that a newly created link layer with a specified name is correctly created . Verify multiples can be created as long as the physical link name is different .
@Test
    public void testCreateLinkLayer_Named() throws Exception 
    {
        String name = "name";
        String linkName = "CreationName";
        when(m_PhysInternal.getName()).thenReturn(name);
        PhysicalLink physicalLink = m_SUT.createPhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT);
        LinkLayer layer = m_SUT.createLinkLayer(LL_PRODUCT_TYPE, linkName, physicalLink.getName());
        assertThat(layer, is((LinkLayer)m_LinkInternal));
        when(m_LinkInternal.getPhysicalLink()).thenReturn(m_PhysInternal);
        Map<String, Object> props = new HashMap<>();
        props.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, name);
        verify(m_LinkRegistry).createNewObject(m_LinkFactory, linkName, props);
        Set<LinkLayerInternal> links = new HashSet<>();
        links.add(m_LinkInternal);
        when(m_LinkRegistry.getObjects()).thenReturn(links);
        UUID uuidDos = UUID.randomUUID();
        PhysicalLinkInternal physInternal = mock(PhysicalLinkInternal.class);
        when(physInternal.getUuid()).thenReturn(uuidDos);
        when(m_PhysRegistry.createNewObject(eq(m_PhysFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(physInternal);
        String physName2 = "name2";
        when(physInternal.getName()).thenReturn(physName2);
        PhysicalLink physicalLink2 = m_SUT.createPhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT);
        String linkName2 = "OriginalName";
        LinkLayerInternal linkInternal = mock(LinkLayerInternal.class);
        when(linkInternal.getName()).thenReturn(linkName2);
        when(linkInternal.getPhysicalLink()).thenReturn(physicalLink2);
        when(linkInternal.getFactory()).thenReturn(m_LinkFactory);
        when(m_LinkRegistry.createNewObject(eq(m_LinkFactory), eq(linkName2), Mockito.any(Map.class))).
            thenReturn(linkInternal);
        LinkLayer layer2 = m_SUT.createLinkLayer(LL_PRODUCT_TYPE, linkName2, physicalLink2.getName());
        assertThat(layer2, is(notNullValue()));
        links.add(linkInternal);
        Map<String, Object> props2 = new HashMap<>();
        props2.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, physName2);
        verify(m_LinkRegistry).createNewObject(m_LinkFactory, linkName2, props2);
        verify(m_WakeLock, times(4)).activate();
        verify(m_WakeLock, times(4)).cancel();
    }
@ Test public void testCreateLinkLayer_Named ( ) throws Exception { String name = "name" ; String linkName = "CreationName" ; when ( m_PhysInternal . getName ( ) ) . thenReturn ( name ) ; PhysicalLink physicalLink = m_SUT . createPhysicalLink ( PhysicalLinkTypeEnum . SERIAL_PORT ) ; LinkLayer layer = m_SUT . createLinkLayer ( LL_PRODUCT_TYPE , linkName , physicalLink . getName ( ) ) ; assertThat ( layer , is ( ( LinkLayer ) m_LinkInternal ) ) ; when ( m_LinkInternal . getPhysicalLink ( ) ) . thenReturn ( m_PhysInternal ) ; Map < String , Object > props = new HashMap < > ( ) ; props . put ( LinkLayerAttributes . CONFIG_PROP_PHYSICAL_LINK_NAME , name ) ; verify ( m_LinkRegistry ) . createNewObject ( m_LinkFactory , linkName , props ) ; Set < LinkLayerInternal > links = new HashSet < > ( ) ; links . add ( m_LinkInternal ) ; when ( m_LinkRegistry . getObjects ( ) ) . thenReturn ( links ) ; UUID uuidDos = UUID . randomUUID ( ) ; PhysicalLinkInternal physInternal = mock ( PhysicalLinkInternal . class ) ; when ( physInternal . getUuid ( ) ) . thenReturn ( uuidDos ) ; when ( m_PhysRegistry . createNewObject ( eq ( m_PhysFactory ) , Mockito . anyString ( ) , Mockito . any ( Map . class ) ) ) . thenReturn ( physInternal ) ; String physName2 = "name2" ; when ( physInternal . getName ( ) ) . thenReturn ( physName2 ) ; PhysicalLink physicalLink2 = m_SUT . createPhysicalLink ( PhysicalLinkTypeEnum . SERIAL_PORT ) ; String linkName2 = "OriginalName" ; LinkLayerInternal linkInternal = mock ( LinkLayerInternal . class ) ; when ( linkInternal . getName ( ) ) . thenReturn ( linkName2 ) ; when ( linkInternal . getPhysicalLink ( ) ) . thenReturn ( physicalLink2 ) ; when ( linkInternal . getFactory ( ) ) . thenReturn ( m_LinkFactory ) ; when ( m_LinkRegistry . createNewObject ( eq ( m_LinkFactory ) , eq ( linkName2 ) , Mockito . any ( Map . class ) ) ) . thenReturn ( linkInternal ) ; LinkLayer layer2 = m_SUT . createLinkLayer ( LL_PRODUCT_TYPE , linkName2 , physicalLink2 . getName ( ) ) ; assertThat ( layer2 , is ( notNullValue ( ) ) ) ; links . add ( linkInternal ) ; Map < String , Object > props2 = new HashMap < > ( ) ; props2 . put ( LinkLayerAttributes . CONFIG_PROP_PHYSICAL_LINK_NAME , physName2 ) ; verify ( m_LinkRegistry ) . createNewObject ( m_LinkFactory , linkName2 , props2 ) ; verify ( m_WakeLock , times ( 4 ) ) . activate ( ) ; verify ( m_WakeLock , times ( 4 ) ) . cancel ( ) ; }
Verify that a newly created link layer with a specified name is correctly created.
Verify that a newly created link layer with a specified name is correctly created .
//test to see if you get a LinkLayer with the specified name //add mocking behavior for next layer //verify //reg mock //mock another physical link //create phys //act //add to mock reg list //verify