use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpMessageDelegateTest method getScopeId_インターフェースに紐付くIPv6ならその値.
@Test
public void getScopeId_インターフェースに紐付くIPv6ならその値() throws Exception {
final int scopeId = 1;
final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
final HttpRequest request = new HttpRequest().readData(new ByteArrayInputStream(data, 0, data.length));
final Inet6Address address = Inet6Address.getByAddress(null, InetAddress.getByName("fe80::a831:801b:8dc6:421f").getAddress(), scopeId);
final InterfaceAddress ifa = TestUtils.createInterfaceAddress(address, "255.255.255.0", 0);
final SsdpMessageDelegate delegate = new SsdpMessageDelegate(request, ifa);
assertThat(delegate.getScopeId(), is(scopeId));
}
use of java.net.InterfaceAddress 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"));
}
use of java.net.InterfaceAddress 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));
}
use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpNotifyReceiverTest method onReceive_Listenerがnullでもクラッシュしない.
@Test
public void onReceive_Listenerがnullでもクラッシュしない() 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 byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
receiver.onReceive(InetAddress.getByName("192.0.2.2"), data, data.length);
}
use of java.net.InterfaceAddress 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));
}
Aggregations