Debian Codegraph @

src/test/java/jnr/netdb/NativeServicesDBTest.java

raw
1
2 package jnr.netdb;
3
4 import jnr.ffi.Platform;
5 import org.junit.After;
6 import org.junit.AfterClass;
7 import org.junit.Before;
8 import org.junit.BeforeClass;
9 import org.junit.Test;
10 import static org.junit.Assert.*;
11
12 /**
13 *
14 */
15 public class NativeServicesDBTest {
16
17 public NativeServicesDBTest() {
18 }
19
20 @BeforeClass
21 public static void setUpClass() throws Exception {
22 }
23
24 @AfterClass
25 public static void tearDownClass() throws Exception {
26 }
27
28 @Before
29 public void setUp() {
30 }
31
32 @After
33 public void tearDown() {
34 }
35
36 @Test public void canLookupServiceThan32768ByName() {
37 if (Platform.getNativePlatform().getOS().equals(Platform.OS.DARWIN)) {
38 ServicesDB db = NativeServicesDB.load();
39 Service s = db.getServiceByName("blp5", "udp");
40 assertNotNull("could not lookup blp5 service", s);
41 assertEquals("incorrect port", 48129, s.getPort());
42 assertEquals("incorrect name", "blp5", s.getName());
43 }
44 }
45
46 @Test public void canLookupServiceLargerThan32768ByPort() {
47 if (Platform.getNativePlatform().getOS().equals(Platform.OS.DARWIN)) {
48 ServicesDB db = NativeServicesDB.load();
49 Service s = db.getServiceByPort(48129, "udp");
50 assertNotNull("could not lookup blp5 service", s);
51 assertEquals("incorrect port", 48129, s.getPort());
52 assertEquals("incorrect name", "blp5", s.getName());
53 }
54 }
55
56 @Test public void canLookupServiceWithAliasByName() {
57 ServicesDB db = NativeServicesDB.load();
58 Service s = db.getServiceByName("comsat", "udp");
59 assertNotNull("could not lookup comsat/biff service", s);
60 assertEquals("incorrect port", 512, s.getPort());
61 assertTrue(s.getName().equals("biff") || s.getName().equals("comsat"));
62 assertTrue(s.getAliases().contains("biff") || s.getAliases().contains("comsat"));
63 }
64
65 @Test public void canLookupServiceWithAliasByPort() {
66 ServicesDB db = NativeServicesDB.load();
67 Service s = db.getServiceByPort(512, "udp");
68 assertNotNull("could not lookup comsat/biff service", s);
69 assertEquals("incorrect port", 512, s.getPort());
70 assertTrue(s.getName().equals("biff") || s.getName().equals("comsat"));
71 assertTrue(s.getAliases().contains("biff") || s.getAliases().contains("comsat"));
72 }
73
74 @Test public void getAllServicesReturnsNonEmptyList() {
75 ServicesDB db = NativeServicesDB.load();
76 assertFalse(db.getAllServices().isEmpty());
77 }
78
79 @Test public void getAllServicesContainsFtp() {
80 ServicesDB db = NativeServicesDB.load();
81 boolean ftpFound = false;
82 for (Service s : db.getAllServices()) {
83 if (s.getName().equals("ftp") || s.getAliases().contains("ftp")) {
84 ftpFound = true;
85 break;
86 }
87 }
88 assertTrue(ftpFound);
89 }
90 }