Search in sources :

Example 1 with ResponseListener

use of net.mm2d.upnp.SsdpSearchServer.ResponseListener in project mmupnp by ohmae.

the class SsdpSearchServerTest method onReceive_listenerがコールされる.

@Test
public void onReceive_listenerがコールされる() throws Exception {
    final NetworkInterface networkInterface = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final SsdpSearchServer server = new SsdpSearchServer(Address.IP_V4, networkInterface);
    final ResponseListener listener = mock(ResponseListener.class);
    server.setResponseListener(listener);
    final InetAddress address = InetAddress.getByName("192.0.2.2");
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-search-response0.bin");
    server.onReceive(address, data, data.length);
    verify(listener, times(1)).onReceiveResponse(ArgumentMatchers.any(SsdpResponse.class));
}
Also used : NetworkInterface(java.net.NetworkInterface) ResponseListener(net.mm2d.upnp.SsdpSearchServer.ResponseListener) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with ResponseListener

use of net.mm2d.upnp.SsdpSearchServer.ResponseListener in project mmupnp by ohmae.

the class SsdpSearchServerListTest method search.

@Test
public void search() {
    final SsdpSearchServerList list = spy(new SsdpSearchServerList());
    final SsdpSearchServer server = mock(SsdpSearchServer.class);
    final ResponseListener listener = mock(ResponseListener.class);
    doReturn(server).when(list).newSsdpSearchServer(eq(Address.IP_V4), any(NetworkInterface.class), eq(listener));
    final NetworkInterface nif = NetworkUtils.getAvailableInet4Interfaces().get(0);
    list.init(Protocol.DEFAULT, Arrays.asList(nif), listener);
    list.search("");
    verify(server, times(1)).search("");
}
Also used : NetworkInterface(java.net.NetworkInterface) ResponseListener(net.mm2d.upnp.SsdpSearchServer.ResponseListener) Test(org.junit.Test)

Example 3 with ResponseListener

use of net.mm2d.upnp.SsdpSearchServer.ResponseListener in project mmupnp by ohmae.

the class SsdpSearchServerListTest method openAndStart_Exceptionが発生しても無視する.

@Test
public void openAndStart_Exceptionが発生しても無視する() throws Exception {
    final SsdpSearchServerList list = spy(new SsdpSearchServerList());
    final SsdpSearchServer server = mock(SsdpSearchServer.class);
    final ResponseListener listener = mock(ResponseListener.class);
    doReturn(server).when(list).newSsdpSearchServer(eq(Address.IP_V4), any(NetworkInterface.class), eq(listener));
    final NetworkInterface nif = NetworkUtils.getAvailableInet4Interfaces().get(0);
    list.init(Protocol.DEFAULT, Arrays.asList(nif), listener);
    doThrow(new IOException()).when(server).open();
    list.openAndStart();
}
Also used : NetworkInterface(java.net.NetworkInterface) ResponseListener(net.mm2d.upnp.SsdpSearchServer.ResponseListener) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ResponseListener

use of net.mm2d.upnp.SsdpSearchServer.ResponseListener in project mmupnp by ohmae.

the class SsdpSearchServerTest method onReceive_アドレス不一致ならlistenerコールされない.

@Test
public void onReceive_アドレス不一致ならlistenerコールされない() throws Exception {
    final NetworkInterface networkInterface = NetworkUtils.getAvailableInet4Interfaces().get(0);
    final SsdpSearchServer server = new SsdpSearchServer(Address.IP_V4, networkInterface);
    final ResponseListener listener = mock(ResponseListener.class);
    server.setResponseListener(listener);
    final InetAddress address = InetAddress.getByName("192.0.2.3");
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-search-response0.bin");
    server.onReceive(address, data, data.length);
    verify(listener, never()).onReceiveResponse(ArgumentMatchers.any(SsdpResponse.class));
}
Also used : NetworkInterface(java.net.NetworkInterface) ResponseListener(net.mm2d.upnp.SsdpSearchServer.ResponseListener) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 5 with ResponseListener

use of net.mm2d.upnp.SsdpSearchServer.ResponseListener in project mmupnp by ohmae.

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

@Test
public void setResponseListener_受信メッセージが通知されること() throws Exception {
    final SsdpServerDelegate delegate = mock(SsdpServerDelegate.class);
    final InterfaceAddress interfaceAddress = TestUtils.createInterfaceAddress("192.0.2.2", "255.255.255.0", 16);
    doReturn(interfaceAddress).when(delegate).getInterfaceAddress();
    final SsdpSearchServer server = spy(new SsdpSearchServer(delegate));
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-search-response0.bin");
    final InetAddress address = InetAddress.getByName("192.0.2.2");
    final ArgumentCaptor<SsdpResponse> captor = ArgumentCaptor.forClass(SsdpResponse.class);
    final ResponseListener listener = mock(ResponseListener.class);
    doNothing().when(listener).onReceiveResponse(captor.capture());
    server.setResponseListener(listener);
    server.onReceive(address, data, data.length);
    SsdpResponse response = captor.getValue();
    assertThat(response.getStatus(), is(Http.Status.HTTP_OK));
    assertThat(response.getUuid(), is("uuid:01234567-89ab-cdef-0123-456789abcdef"));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) ResponseListener(net.mm2d.upnp.SsdpSearchServer.ResponseListener) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

ResponseListener (net.mm2d.upnp.SsdpSearchServer.ResponseListener)9 Test (org.junit.Test)9 NetworkInterface (java.net.NetworkInterface)8 InetAddress (java.net.InetAddress)4 IOException (java.io.IOException)1 InterfaceAddress (java.net.InterfaceAddress)1