|
20 | 20 | import static org.junit.Assert.*; |
21 | 21 |
|
22 | 22 | import java.io.IOException; |
| 23 | +import java.net.Inet6Address; |
23 | 24 |
|
24 | 25 | import org.junit.Before; |
25 | 26 | import org.junit.Rule; |
|
37 | 38 | import com.digi.xbee.api.exceptions.InvalidOperatingModeException; |
38 | 39 | import com.digi.xbee.api.exceptions.TimeoutException; |
39 | 40 | import com.digi.xbee.api.exceptions.XBeeException; |
| 41 | +import com.digi.xbee.api.models.IPProtocol; |
40 | 42 | import com.digi.xbee.api.models.ThreadAssociationIndicationStatus; |
41 | 43 | import com.digi.xbee.api.models.XBee64BitAddress; |
42 | 44 |
|
@@ -408,4 +410,92 @@ public void testIsConnectedSuccessDisconnected() throws XBeeException, IOExcepti |
408 | 410 | // Check the connection. |
409 | 411 | assertFalse(threadDevice.isConnected()); |
410 | 412 | } |
| 413 | + |
| 414 | + /** |
| 415 | + * Test method for {@link com.digi.xbee.api.ThreadDevice#sendIPData(Inet6Address, int, IPProtocol, byte[]) |
| 416 | + * |
| 417 | + * <p>Verify that TCP protocol is not supported when sending IPv6 data synchronously.</p> |
| 418 | + * |
| 419 | + * @throws Exception |
| 420 | + */ |
| 421 | + @Test |
| 422 | + public void testSendIPDataProtocolIllegalTCP() throws Exception { |
| 423 | + // Set up the resources for the test. |
| 424 | + Inet6Address address = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007"); |
| 425 | + byte[] data = "Hello XBee".getBytes(); |
| 426 | + int destPort = 1234; |
| 427 | + |
| 428 | + exception.expect(IllegalArgumentException.class); |
| 429 | + exception.expectMessage(is(equalTo(String.format("Protocol must be %s or %s.", |
| 430 | + IPProtocol.UDP.getName(), IPProtocol.COAP.getName())))); |
| 431 | + |
| 432 | + // Call the method under test that should throw an IllegalArgumentException. |
| 433 | + threadDevice.sendIPData(address, destPort, IPProtocol.TCP, data); |
| 434 | + } |
| 435 | + |
| 436 | + /** |
| 437 | + * Test method for {@link com.digi.xbee.api.ThreadDevice#sendIPData(Inet6Address, int, IPProtocol, byte[]) |
| 438 | + * |
| 439 | + * <p>Verify that TCP SSL protocol is not supported when sending IPv6 data synchronously.</p> |
| 440 | + * |
| 441 | + * @throws Exception |
| 442 | + */ |
| 443 | + @Test |
| 444 | + public void testSendIPDataProtocolIllegalTCPSSL() throws Exception { |
| 445 | + // Set up the resources for the test. |
| 446 | + Inet6Address address = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007"); |
| 447 | + byte[] data = "Hello XBee".getBytes(); |
| 448 | + int destPort = 1234; |
| 449 | + |
| 450 | + exception.expect(IllegalArgumentException.class); |
| 451 | + exception.expectMessage(is(equalTo(String.format("Protocol must be %s or %s.", |
| 452 | + IPProtocol.UDP.getName(), IPProtocol.COAP.getName())))); |
| 453 | + |
| 454 | + // Call the method under test that should throw an IllegalArgumentException. |
| 455 | + threadDevice.sendIPData(address, destPort, IPProtocol.TCP_SSL, data); |
| 456 | + } |
| 457 | + |
| 458 | + /** |
| 459 | + * Test method for {@link com.digi.xbee.api.ThreadDevice#sendIPDataAsync(Inet6Address, int, IPProtocol, byte[]) |
| 460 | + * |
| 461 | + * <p>Verify that TCP protocol is not supported when sending IPv6 data asynchronously.</p> |
| 462 | + * |
| 463 | + * @throws Exception |
| 464 | + */ |
| 465 | + @Test |
| 466 | + public void testSendIPDataAsyncProtocolIllegalTCP() throws Exception { |
| 467 | + // Set up the resources for the test. |
| 468 | + Inet6Address address = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007"); |
| 469 | + byte[] data = "Hello XBee".getBytes(); |
| 470 | + int destPort = 1234; |
| 471 | + |
| 472 | + exception.expect(IllegalArgumentException.class); |
| 473 | + exception.expectMessage(is(equalTo(String.format("Protocol must be %s or %s.", |
| 474 | + IPProtocol.UDP.getName(), IPProtocol.COAP.getName())))); |
| 475 | + |
| 476 | + // Call the method under test that should throw an IllegalArgumentException. |
| 477 | + threadDevice.sendIPDataAsync(address, destPort, IPProtocol.TCP, data); |
| 478 | + } |
| 479 | + |
| 480 | + /** |
| 481 | + * Test method for {@link com.digi.xbee.api.ThreadDevice#sendIPDataAsync(Inet6Address, int, IPProtocol, byte[]) |
| 482 | + * |
| 483 | + * <p>Verify that TCP SSL protocol is not supported when sending IPv6 data asynchronously.</p> |
| 484 | + * |
| 485 | + * @throws Exception |
| 486 | + */ |
| 487 | + @Test |
| 488 | + public void testSendIPDataAsyncProtocolIllegalTCPSSL() throws Exception { |
| 489 | + // Set up the resources for the test. |
| 490 | + Inet6Address address = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007"); |
| 491 | + byte[] data = "Hello XBee".getBytes(); |
| 492 | + int destPort = 1234; |
| 493 | + |
| 494 | + exception.expect(IllegalArgumentException.class); |
| 495 | + exception.expectMessage(is(equalTo(String.format("Protocol must be %s or %s.", |
| 496 | + IPProtocol.UDP.getName(), IPProtocol.COAP.getName())))); |
| 497 | + |
| 498 | + // Call the method under test that should throw an IllegalArgumentException. |
| 499 | + threadDevice.sendIPDataAsync(address, destPort, IPProtocol.TCP_SSL, data); |
| 500 | + } |
411 | 501 | } |
0 commit comments