| 1 |
|
| 2 |
package jnr.netdb; |
| 3 |
|
| 4 |
import org.junit.After; |
| 5 |
import org.junit.AfterClass; |
| 6 |
import org.junit.Before; |
| 7 |
import org.junit.BeforeClass; |
| 8 |
import org.junit.Test; |
| 9 |
import static org.junit.Assert.*; |
| 10 |
|
| 11 |
/** |
| 12 |
* |
| 13 |
*/ |
| 14 |
public class FileServicesDBTest { |
| 15 |
|
| 16 |
public FileServicesDBTest() { |
| 17 |
} |
| 18 |
|
| 19 |
@BeforeClass |
| 20 |
public static void setUpClass() throws Exception { |
| 21 |
} |
| 22 |
|
| 23 |
@AfterClass |
| 24 |
public static void tearDownClass() throws Exception { |
| 25 |
} |
| 26 |
|
| 27 |
@Before |
| 28 |
public void setUp() { |
| 29 |
} |
| 30 |
|
| 31 |
@After |
| 32 |
public void tearDown() { |
| 33 |
} |
| 34 |
|
| 35 |
@Test public void canLookupBootpServiceByName() { |
| 36 |
FileServicesDB db = new FileServicesDB(); |
| 37 |
Service s = db.getServiceByName("bootps", "udp"); |
| 38 |
assertNotNull("could not lookup bootps service", s); |
| 39 |
assertEquals("incorrect port", 67, s.getPort()); |
| 40 |
assertEquals("incorrect name", "bootps", s.getName()); |
| 41 |
} |
| 42 |
|
| 43 |
@Test public void canLookupBootpServiceByPort() { |
| 44 |
FileServicesDB db = new FileServicesDB(); |
| 45 |
Service s = db.getServiceByPort(67, "udp"); |
| 46 |
assertNotNull("could not lookup bootps service", s); |
| 47 |
assertEquals("incorrect port", 67, s.getPort()); |
| 48 |
assertEquals("incorrect name", "bootps", s.getName()); |
| 49 |
} |
| 50 |
|
| 51 |
@Test public void canLookupServiceWithAliasByName() { |
| 52 |
ServicesDB db = new FileServicesDB(); |
| 53 |
Service s = db.getServiceByName("comsat", "udp"); |
| 54 |
assertNotNull("could not lookup comsat/biff service", s); |
| 55 |
assertEquals("incorrect port", 512, s.getPort()); |
| 56 |
assertTrue(s.getName().equals("biff") || s.getName().equals("comsat")); |
| 57 |
assertTrue(s.getAliases().contains("biff") || s.getAliases().contains("comsat")); |
| 58 |
} |
| 59 |
|
| 60 |
@Test public void canLookupServiceWithAliasByPort() { |
| 61 |
ServicesDB db = new FileServicesDB(); |
| 62 |
Service s = db.getServiceByPort(512, "udp"); |
| 63 |
assertNotNull("could not lookup comsat/biff service", s); |
| 64 |
assertEquals("incorrect port", 512, s.getPort()); |
| 65 |
assertTrue(s.getName().equals("biff") || s.getName().equals("comsat")); |
| 66 |
assertTrue(s.getAliases().contains("biff") || s.getAliases().contains("comsat")); |
| 67 |
} |
| 68 |
|
| 69 |
} |