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.binding.xml.ServiceDescriptorBinder;
19  import org.fourthline.cling.binding.xml.UDA10ServiceDescriptorBinderImpl;
20  import org.fourthline.cling.binding.xml.UDA10ServiceDescriptorBinderSAXImpl;
21  import org.fourthline.cling.model.meta.RemoteDevice;
22  import org.fourthline.cling.model.meta.RemoteService;
23  import org.fourthline.cling.test.data.SampleData;
24  import org.fourthline.cling.test.data.SampleServiceOne;
25  import org.seamless.util.io.IO;
26  import org.testng.annotations.Test;
27  
28  
29  public class UDA10ServiceDescriptorParsingTest {
30  
31      @Test
32      public void readUDA10DescriptorDOM() throws Exception {
33  
34          ServiceDescriptorBinder binder = new UDA10ServiceDescriptorBinderImpl();
35  
36          RemoteService service = SampleData.createUndescribedRemoteService();
37  
38          service = binder.describe(service, IO.readLines(getClass().getResourceAsStream("/descriptors/service/uda10.xml")));
39  
40          SampleServiceOne.assertMatch(service, SampleData.getFirstService(SampleData.createRemoteDevice()));
41      }
42  
43      @Test
44      public void readUDA10DescriptorSAX() throws Exception {
45  
46          ServiceDescriptorBinder binder = new UDA10ServiceDescriptorBinderSAXImpl();
47  
48          RemoteService service = SampleData.createUndescribedRemoteService();
49  
50          service = binder.describe(service, IO.readLines(getClass().getResourceAsStream("/descriptors/service/uda10.xml")));
51  
52          SampleServiceOne.assertMatch(service, SampleData.getFirstService(SampleData.createRemoteDevice()));
53      }
54  
55      @Test
56      public void writeUDA10Descriptor() throws Exception {
57  
58          ServiceDescriptorBinder binder = new UDA10ServiceDescriptorBinderImpl();
59  
60          RemoteDevice rd = SampleData.createRemoteDevice();
61          String descriptorXml = binder.generate(SampleData.getFirstService(rd));
62  
63  /*
64          System.out.println("#######################################################################################");
65          System.out.println(descriptorXml);
66          System.out.println("#######################################################################################");
67  
68  */
69  
70          RemoteService service = SampleData.createUndescribedRemoteService();
71          service = binder.describe(service, descriptorXml);
72          SampleServiceOne.assertMatch(service, SampleData.getFirstService(rd));
73      }
74  
75  }