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.resources;
17  
18  import org.fourthline.cling.UpnpService;
19  import org.fourthline.cling.binding.xml.DescriptorBindingException;
20  import org.fourthline.cling.binding.xml.DeviceDescriptorBinder;
21  import org.fourthline.cling.binding.xml.RecoveringUDA10DeviceDescriptorBinderImpl;
22  import org.fourthline.cling.binding.xml.UDA10DeviceDescriptorBinderSAXImpl;
23  import org.fourthline.cling.mock.MockUpnpService;
24  import org.fourthline.cling.mock.MockUpnpServiceConfiguration;
25  import org.fourthline.cling.model.meta.RemoteDevice;
26  import org.fourthline.cling.test.data.SampleData;
27  import org.seamless.util.io.IO;
28  import org.testng.annotations.DataProvider;
29  import org.testng.annotations.Test;
30  
31  import static org.testng.Assert.*;
32  
33  /**
34   * @author Christian Bauer
35   */
36  public class InvalidUDA10DeviceDescriptorParsingTest {
37  
38      @DataProvider(name = "strict")
39      public String[][] getStrict() throws Exception {
40          return new String[][]{
41              {"/invalidxml/device/atb_miviewtv.xml"},
42              {"/invalidxml/device/doubletwist.xml"},
43              {"/invalidxml/device/eyetv_netstream_sat.xml"},
44              {"/invalidxml/device/makemkv.xml"},
45              {"/invalidxml/device/tpg.xml"},
46              {"/invalidxml/device/ceton_infinitv.xml"},
47              {"/invalidxml/device/zyxel_miviewtv.xml"},
48              {"/invalidxml/device/perfectwave.xml"},
49              {"/invalidxml/device/escient.xml"},
50              {"/invalidxml/device/eyecon.xml"},
51              {"/invalidxml/device/kodak.xml"},
52              {"/invalidxml/device/plutinosoft.xml"},
53              {"/invalidxml/device/samsung.xml"},
54              {"/invalidxml/device/philips_hue.xml"},
55          };
56      }
57  
58      @DataProvider(name = "recoverable")
59      public String[][] getRecoverable() throws Exception {
60          return new String[][]{
61              {"/invalidxml/device/missing_namespaces.xml"},
62              {"/invalidxml/device/ushare.xml"},
63              {"/invalidxml/device/lg.xml"},
64              {"/invalidxml/device/readydlna.xml"},
65          };
66      }
67  
68      @DataProvider(name = "unrecoverable")
69      public String[][] getUnrecoverable() throws Exception {
70          return new String[][]{
71              {"/invalidxml/device/unrecoverable/pms.xml"},
72              {"/invalidxml/device/unrecoverable/awox.xml"},
73              {"/invalidxml/device/philips.xml"},
74              {"/invalidxml/device/simplecenter.xml"},
75              {"/invalidxml/device/ums.xml"},
76          };
77      }
78  
79      /* ############################## TEST FAILURE ############################ */
80  
81      @Test(dataProvider = "recoverable", expectedExceptions = DescriptorBindingException.class)
82      public void readFailure(String recoverable) throws Exception {
83          readDevice(recoverable, new MockUpnpService());
84      }
85  
86      @Test(dataProvider = "unrecoverable", expectedExceptions = Exception.class)
87      public void readRecoveringFailure(String unrecoverable) throws Exception {
88          readDevice(
89              unrecoverable,
90              new MockUpnpService(new MockUpnpServiceConfiguration() {
91                  @Override
92                  public DeviceDescriptorBinder getDeviceDescriptorBinderUDA10() {
93                      return new RecoveringUDA10DeviceDescriptorBinderImpl();
94                  }
95              })
96          );
97      }
98  
99      /* ############################## TEST SUCCESS ############################ */
100 
101     @Test(dataProvider = "strict")
102     public void readDefault(String strict) throws Exception {
103         readDevice(strict, new MockUpnpService());
104     }
105 
106     @Test(dataProvider = "strict")
107     public void readSAX(String strict) throws Exception {
108         readDevice(
109             strict,
110             new MockUpnpService(new MockUpnpServiceConfiguration() {
111                 @Override
112                 public DeviceDescriptorBinder getDeviceDescriptorBinderUDA10() {
113                     return new UDA10DeviceDescriptorBinderSAXImpl();
114                 }
115             })
116         );
117     }
118 
119     @Test(dataProvider = "strict")
120     public void readRecoveringStrict(String strict) throws Exception {
121         readDevice(
122             strict,
123             new MockUpnpService(new MockUpnpServiceConfiguration() {
124                 @Override
125                 public DeviceDescriptorBinder getDeviceDescriptorBinderUDA10() {
126                     return new RecoveringUDA10DeviceDescriptorBinderImpl();
127                 }
128             })
129         );
130     }
131 
132     @Test(dataProvider = "recoverable")
133     public void readRecovering(String recoverable) throws Exception {
134         readDevice(
135             recoverable,
136             new MockUpnpService(new MockUpnpServiceConfiguration() {
137                 @Override
138                 public DeviceDescriptorBinder getDeviceDescriptorBinderUDA10() {
139                     return new RecoveringUDA10DeviceDescriptorBinderImpl();
140                 }
141             })
142         );
143     }
144 
145 	protected void readDevice(String invalidXMLFile, UpnpService upnpService) throws Exception {
146 		RemoteDevice device = new RemoteDevice(SampleData.createRemoteDeviceIdentity());
147 		upnpService.getConfiguration().getDeviceDescriptorBinderUDA10()
148             .describe(device, IO.readLines(getClass().getResourceAsStream(invalidXMLFile)));
149 	}
150 
151 }
152