use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class Service method getCallback.
// VisibleForTesting
@Nonnull
String getCallback() {
final StringBuilder sb = new StringBuilder();
sb.append("<http://");
final SsdpMessage ssdp = mDevice.getSsdpMessage();
final InterfaceAddress ifa = ssdp.getInterfaceAddress();
final int port = mControlPoint.getEventPort();
// noinspection ConstantConditions : 受信したメッセージの場合はnullではない
sb.append(NetworkUtils.getAddressString(ifa.getAddress(), port));
sb.append("/>");
return sb.toString();
}
use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpSearchServerTest method search_ST_ALLでのサーチ.
@Test
public void search_ST_ALLでのサーチ() 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 MockMulticastSocket socket = new MockMulticastSocket();
doReturn(socket).when(delegate).createMulticastSocket(anyInt());
final SsdpSearchServer server = spy(new SsdpSearchServer(delegate));
server.open();
server.start();
server.search();
server.stop();
server.close();
final DatagramPacket packet = socket.getSendPacket();
final SsdpRequest message = new SsdpRequest(mock(InterfaceAddress.class), packet.getData(), packet.getLength());
assertThat(message.getMethod(), is(SsdpMessage.M_SEARCH));
assertThat(message.getHeader(Http.ST), is(SsdpSearchServer.ST_ALL));
assertThat(message.getHeader(Http.MAN), is(SsdpMessage.SSDP_DISCOVER));
}
use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpServerDelegateTest method findInet6Address_見つからなければException1.
@Test(expected = IllegalArgumentException.class)
public void findInet6Address_見つからなければException1() throws Exception {
final InterfaceAddress ipv4 = TestUtils.createInterfaceAddress("192.168.0.1", "255.255.255.0", 24);
SsdpServerDelegate.findInet6Address(Arrays.asList(ipv4));
}
use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpServerDelegateTest method findInet4Address_見つからなければException1.
@Test(expected = IllegalArgumentException.class)
public void findInet4Address_見つからなければException1() throws Exception {
final InterfaceAddress ipv6 = TestUtils.createInterfaceAddress("fe80::a831:801b:8dc6:421f", "255.255.0.0", 16);
SsdpServerDelegate.findInet4Address(Arrays.asList(ipv6, ipv6));
}
use of java.net.InterfaceAddress 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