View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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   * @author Christian Bauer
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          // TODO: UPNP VIOLATION: Onkyo devices send event messages with trailing garbage characters
61          // dev/1234/svc/upnp-org/MyService/event/callback192%2e168%2e10%2e38
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  }