1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.test.protocol;
17
18 import org.fourthline.cling.mock.MockUpnpService;
19 import org.fourthline.cling.model.Namespace;
20 import org.fourthline.cling.model.message.StreamRequestMessage;
21 import org.fourthline.cling.model.message.UpnpRequest;
22 import org.fourthline.cling.protocol.ReceivingSync;
23 import org.fourthline.cling.protocol.sync.ReceivingEvent;
24 import org.testng.annotations.Test;
25
26 import java.net.URI;
27
28 import static org.testng.Assert.*;
29
30
31
32
33 public class ProtocolFactoryTest {
34
35 @Test(expectedExceptions = org.fourthline.cling.protocol.ProtocolCreationException.class)
36 public void noSyncProtocol() throws Exception {
37 MockUpnpService upnpService = new MockUpnpService();
38
39 ReceivingSync protocol = upnpService.getProtocolFactory().createReceivingSync(
40 new StreamRequestMessage(
41 UpnpRequest.Method.NOTIFY,
42 URI.create("/dev/1234/upnp-org/SwitchPower/invalid"),
43 ""
44 )
45 );
46 }
47
48 @Test
49 public void receivingEvent() throws Exception {
50 MockUpnpService upnpService = new MockUpnpService();
51
52 StreamRequestMessage message = new StreamRequestMessage(
53 UpnpRequest.Method.NOTIFY,
54 URI.create("/dev/1234/upnp-org/SwitchPower" + Namespace.EVENTS + Namespace.CALLBACK_FILE),
55 ""
56 );
57 ReceivingSync protocol = upnpService.getProtocolFactory().createReceivingSync(message);
58 assertTrue(protocol instanceof ReceivingEvent);
59
60
61
62 message = new StreamRequestMessage(
63 UpnpRequest.Method.NOTIFY,
64 URI.create("/dev/1234/upnp-org/SwitchPower" + Namespace.EVENTS + Namespace.CALLBACK_FILE + "192%2e168%2e10%2e38"),
65 ""
66 );
67 protocol = upnpService.getProtocolFactory().createReceivingSync(message);
68 assertTrue(protocol instanceof ReceivingEvent);
69
70 }
71 }