Search in sources :

Example 1 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverListTest method stop.

@Test
public void stop() {
    final SsdpNotifyReceiver receiver = mock(SsdpNotifyReceiver.class);
    final SsdpNotifyReceiverList list = spy(new SsdpNotifyReceiverList());
    final NetworkInterface nif = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final NotifyListener listener = mock(NotifyListener.class);
    doReturn(receiver).when(list).newSsdpNotifyReceiver(Address.IP_V4, nif, listener);
    list.init(Protocol.DEFAULT, Collections.singletonList(nif), listener);
    list.stop();
    verify(receiver, times(1)).stop();
}
Also used : NetworkInterface(java.net.NetworkInterface) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 2 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverTest method onReceive_LocationとSourceが不一致のメッセージは無視する.

@Test
public void onReceive_LocationとSourceが不一致のメッセージは無視する() throws Exception {
    final SsdpNotifyReceiver receiver = spy(new SsdpNotifyReceiver(Address.IP_V4, NetworkUtils.getAvailableInet4Interfaces().get(0)));
    final InterfaceAddress address = TestUtils.createInterfaceAddress("192.0.2.1", "255.255.0.0", 24);
    doReturn(address).when(receiver).getInterfaceAddress();
    final NotifyListener listener = mock(NotifyListener.class);
    receiver.setNotifyListener(listener);
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
    receiver.onReceive(InetAddress.getByName("192.0.2.3"), data, data.length);
    verify(listener, never()).onReceiveNotify(ArgumentMatchers.any(SsdpRequest.class));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 3 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverTest method onReceive_同一セグメントからのメッセージは通知する.

@Test
public void onReceive_同一セグメントからのメッセージは通知する() throws Exception {
    final SsdpNotifyReceiver receiver = spy(new SsdpNotifyReceiver(Address.IP_V4, NetworkUtils.getAvailableInet4Interfaces().get(0)));
    final InterfaceAddress address = TestUtils.createInterfaceAddress("192.0.2.1", "255.255.0.0", 24);
    doReturn(address).when(receiver).getInterfaceAddress();
    final NotifyListener listener = mock(NotifyListener.class);
    receiver.setNotifyListener(listener);
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
    receiver.onReceive(InetAddress.getByName("192.0.2.2"), data, data.length);
    verify(listener).onReceiveNotify(ArgumentMatchers.any(SsdpRequest.class));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 4 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverListTest method openAndStart_Exceptionが発生しても後続の処理は実行する.

@Test
public void openAndStart_Exceptionが発生しても後続の処理は実行する() throws Exception {
    final SsdpNotifyReceiver receiver1 = mock(SsdpNotifyReceiver.class);
    final SsdpNotifyReceiver receiver2 = mock(SsdpNotifyReceiver.class);
    final SsdpNotifyReceiverList list = spy(new SsdpNotifyReceiverList());
    final NetworkInterface nif = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final NotifyListener listener = mock(NotifyListener.class);
    when(list.newSsdpNotifyReceiver(Address.IP_V4, nif, listener)).thenReturn(receiver1).thenReturn(receiver2);
    doThrow(new IOException()).when(receiver1).open();
    list.init(Protocol.DEFAULT, Arrays.asList(nif, nif), listener);
    list.openAndStart();
    verify(receiver2, times(1)).open();
    verify(receiver2, times(1)).start();
}
Also used : NetworkInterface(java.net.NetworkInterface) IOException(java.io.IOException) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 5 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverListTest method close.

@Test
public void close() {
    final SsdpNotifyReceiver receiver = mock(SsdpNotifyReceiver.class);
    final SsdpNotifyReceiverList list = spy(new SsdpNotifyReceiverList());
    final NetworkInterface nif = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final NotifyListener listener = mock(NotifyListener.class);
    doReturn(receiver).when(list).newSsdpNotifyReceiver(Address.IP_V4, nif, listener);
    list.init(Protocol.DEFAULT, Collections.singletonList(nif), listener);
    list.close();
    verify(receiver, times(1)).close();
}
Also used : NetworkInterface(java.net.NetworkInterface) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Aggregations

NotifyListener (net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener)11 Test (org.junit.Test)11 InterfaceAddress (java.net.InterfaceAddress)7 NetworkInterface (java.net.NetworkInterface)5 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)1