View Javadoc

1   /**
2    *
3    */
4   package javax.jmdns.test;
5   
6   import static junit.framework.Assert.assertEquals;
7   
8   import java.util.Map;
9   
10  import javax.jmdns.ServiceInfo.Fields;
11  import javax.jmdns.impl.ServiceInfoImpl;
12  
13  import org.junit.Before;
14  import org.junit.Test;
15  
16  /**
17   *
18   */
19  public class ServiceInfoTest {
20  
21      @Before
22      public void setup() {
23          // Placeholder
24      }
25  
26      @Test
27      public void testDecodeQualifiedNameMap() {
28          String domain = "test.com";
29          String protocol = "udp";
30          String application = "ftp";
31          String name = "My Service";
32          String subtype = "printer";
33  
34          String type = "_" + application + "._" + protocol + "." + domain + ".";
35  
36          Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMap(type, name, subtype);
37  
38          assertEquals("We did not get the right domain:", domain, map.get(Fields.Domain));
39          assertEquals("We did not get the right protocol:", protocol, map.get(Fields.Protocol));
40          assertEquals("We did not get the right application:", application, map.get(Fields.Application));
41          assertEquals("We did not get the right name:", name, map.get(Fields.Instance));
42          assertEquals("We did not get the right subtype:", subtype, map.get(Fields.Subtype));
43      }
44  
45      @Test
46      public void testDecodeQualifiedNameMapDefaults() {
47          String domain = "local";
48          String protocol = "tcp";
49          String application = "ftp";
50          String name = "My Service";
51          String subtype = "";
52  
53          Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMap(application, name, subtype);
54  
55          assertEquals("We did not get the right domain:", domain, map.get(Fields.Domain));
56          assertEquals("We did not get the right protocol:", protocol, map.get(Fields.Protocol));
57          assertEquals("We did not get the right application:", application, map.get(Fields.Application));
58          assertEquals("We did not get the right name:", name, map.get(Fields.Instance));
59          assertEquals("We did not get the right subtype:", subtype, map.get(Fields.Subtype));
60      }
61  
62      @Test
63      public void testDecodeServiceType() {
64          String type = "_home-sharing._tcp.local.";
65  
66          Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
67  
68          assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
69          assertEquals("We did not get the right protocol:", "tcp", map.get(Fields.Protocol));
70          assertEquals("We did not get the right application:", "home-sharing", map.get(Fields.Application));
71          assertEquals("We did not get the right name:", "", map.get(Fields.Instance));
72          assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
73  
74      }
75  
76      @Test
77      public void testDecodeServiceTCPType() {
78          String type = "_afpovertcp._tcp.local.";
79  
80          Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
81  
82          assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
83          assertEquals("We did not get the right protocol:", "tcp", map.get(Fields.Protocol));
84          assertEquals("We did not get the right application:", "afpovertcp", map.get(Fields.Application));
85          assertEquals("We did not get the right name:", "", map.get(Fields.Instance));
86          assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
87      }
88  
89      @Test
90      public void testDecodeServiceTypeWithSubType() {
91          String type = "_00000000-0b44-f234-48c8-071c565644b3._sub._home-sharing._tcp.local.";
92  
93          Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
94  
95          assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
96          assertEquals("We did not get the right protocol:", "tcp", map.get(Fields.Protocol));
97          assertEquals("We did not get the right application:", "home-sharing", map.get(Fields.Application));
98          assertEquals("We did not get the right name:", "", map.get(Fields.Instance));
99          assertEquals("We did not get the right subtype:", "00000000-0b44-f234-48c8-071c565644b3", map.get(Fields.Subtype));
100     }
101 
102     @Test
103     public void testDecodeServiceName() {
104         String type = "My New Itunes Service._home-sharing._tcp.local.";
105 
106         Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
107 
108         assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
109         assertEquals("We did not get the right protocol:", "tcp", map.get(Fields.Protocol));
110         assertEquals("We did not get the right application:", "home-sharing", map.get(Fields.Application));
111         assertEquals("We did not get the right name:", "My New Itunes Service", map.get(Fields.Instance));
112         assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
113     }
114 
115     @Test
116     public void testDecodeDNSMetaQuery() {
117         String type = "_services._dns-sd._udp.local.";
118 
119         Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
120 
121         assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
122         assertEquals("We did not get the right protocol:", "udp", map.get(Fields.Protocol));
123         assertEquals("We did not get the right application:", "dns-sd", map.get(Fields.Application));
124         assertEquals("We did not get the right name:", "_services", map.get(Fields.Instance));
125         assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
126     }
127 
128     @Test
129     public void testReverseDNSQuery() {
130         String type = "100.50.168.192.in-addr.arpa.";
131 
132         Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
133 
134         assertEquals("We did not get the right domain:", "in-addr.arpa", map.get(Fields.Domain));
135         assertEquals("We did not get the right protocol:", "", map.get(Fields.Protocol));
136         assertEquals("We did not get the right application:", "", map.get(Fields.Application));
137         assertEquals("We did not get the right name:", "100.50.168.192", map.get(Fields.Instance));
138         assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
139     }
140 
141     @Test
142     public void testAddress() {
143         String type = "panoramix.local.";
144 
145         Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
146 
147         assertEquals("We did not get the right domain:", "local", map.get(Fields.Domain));
148         assertEquals("We did not get the right protocol:", "", map.get(Fields.Protocol));
149         assertEquals("We did not get the right application:", "", map.get(Fields.Application));
150         assertEquals("We did not get the right name:", "panoramix", map.get(Fields.Instance));
151         assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
152     }
153 
154     @Test
155     public void testCasePreserving() {
156         String type = "My New Itunes Service._Home-Sharing._TCP.Panoramix.local.";
157 
158         Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(type);
159 
160         assertEquals("We did not get the right domain:", "Panoramix.local", map.get(Fields.Domain));
161         assertEquals("We did not get the right protocol:", "TCP", map.get(Fields.Protocol));
162         assertEquals("We did not get the right application:", "Home-Sharing", map.get(Fields.Application));
163         assertEquals("We did not get the right name:", "My New Itunes Service", map.get(Fields.Instance));
164         assertEquals("We did not get the right subtype:", "", map.get(Fields.Subtype));
165     }
166 
167 }