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));
}
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("");
}
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();
}
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));
}
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"));
}
Aggregations