Search in sources :

Example 6 with NotifyListener

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

the class SsdpNotifyReceiverListTest method openAndStart.

@Test
public void openAndStart() throws Exception {
    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.openAndStart();
    verify(receiver, times(1)).open();
    verify(receiver, times(1)).start();
}
Also used : NetworkInterface(java.net.NetworkInterface) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 7 with NotifyListener

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

the class SsdpNotifyReceiverTest method setNotifyListener_受信メッセージが通知されること.

@Test
public void setNotifyListener_受信メッセージが通知されること() throws Exception {
    final NetworkInterface networkInterface = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final SsdpServerDelegate delegate = spy(new SsdpServerDelegate(mock(Receiver.class), Address.IP_V4, networkInterface));
    final InterfaceAddress interfaceAddress = TestUtils.createInterfaceAddress("192.0.2.2", "255.255.255.0", 16);
    doReturn(interfaceAddress).when(delegate).getInterfaceAddress();
    final SsdpNotifyReceiver receiver = spy(new SsdpNotifyReceiver(delegate));
    final ArgumentCaptor<SsdpRequest> captor = ArgumentCaptor.forClass(SsdpRequest.class);
    final NotifyListener listener = mock(NotifyListener.class);
    doNothing().when(listener).onReceiveNotify(captor.capture());
    receiver.setNotifyListener(listener);
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
    final InetAddress address = InetAddress.getByName("192.0.2.2");
    receiver.onReceive(address, data, data.length);
    assertThat(captor.getValue().getUuid(), is("uuid:01234567-89ab-cdef-0123-456789abcdef"));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 8 with NotifyListener

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

the class SsdpNotifyReceiverTest method onReceive_M_SEARCHパケットは無視する.

@Test
public void onReceive_M_SEARCHパケットは無視する() 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 SsdpRequest message = new SsdpRequest();
    message.setMethod(SsdpMessage.M_SEARCH);
    message.setUri("*");
    message.setHeader(Http.HOST, Address.IP_V4.getAddressString());
    message.setHeader(Http.MAN, SsdpMessage.SSDP_DISCOVER);
    message.setHeader(Http.MX, "1");
    message.setHeader(Http.ST, SsdpSearchServer.ST_ALL);
    final byte[] data = message.getMessage().getMessageString().getBytes();
    receiver.onReceive(InetAddress.getByName("192.0.2.2"), 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 9 with NotifyListener

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

the class SsdpNotifyReceiverTest method onReceive_ByeByeパケットは通知する.

@Test
public void onReceive_ByeByeパケットは通知する() 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-byebye0.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 10 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.1.2.2"), 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)

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