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  package org.fourthline.cling.test.model.profile;
16  
17  import org.fourthline.cling.model.meta.DeviceDetails;
18  import org.fourthline.cling.model.profile.RemoteClientInfo;
19  import org.fourthline.cling.model.profile.HeaderDeviceDetailsProvider;
20  import org.testng.Assert;
21  import org.testng.annotations.Test;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  /**
27   * @author Mario Franco
28   */
29  public class DeviceDetailsProviderTest {
30  
31      @Test
32      public void headerRegexMatch() throws Exception {
33  
34          RemoteClientInfo clientInfo = new RemoteClientInfo();
35  
36          DeviceDetails dd1 = new DeviceDetails("My Testdevice 1");
37          DeviceDetails dd2 = new DeviceDetails("My Testdevice 2");
38  
39          Map<HeaderDeviceDetailsProvider.Key, DeviceDetails> headerDetails = new HashMap<>();
40  
41          headerDetails.put(new HeaderDeviceDetailsProvider.Key("User-Agent", "Xbox.*"), dd1);
42          headerDetails.put(new HeaderDeviceDetailsProvider.Key("X-AV-Client-Info", ".*PLAYSTATION 3.*"), dd2);
43  
44          HeaderDeviceDetailsProvider provider = new HeaderDeviceDetailsProvider(dd1, headerDetails);
45  
46          // No match, test default behavior
47          clientInfo.getRequestHeaders().clear();
48          clientInfo.getRequestHeaders().add(
49                  "User-Agent",
50                  "Microsoft-Windows/6.1 UPnP/1.0 Windows-Media-Player-DMS/12.0.7600.16385 DLNADOC/1.50"
51          );
52          Assert.assertEquals(provider.provide(clientInfo), dd1);
53  
54          clientInfo.getRequestHeaders().clear();
55          clientInfo.getRequestHeaders().add(
56                  "User-Agent",
57                  "UPnP/1.0"
58          );
59          clientInfo.getRequestHeaders().add(
60                  "X-AV-Client-Info",
61                  "av=5.0; cn=\"Sony Computer Entertainment Inc.\"; mn=\"PLAYSTATION 3\"; mv=\"1.0\";"
62          );
63          Assert.assertEquals(provider.provide(clientInfo), dd2);
64  
65          clientInfo.getRequestHeaders().clear();
66          clientInfo.getRequestHeaders().add(
67                  "User-Agent",
68                  "Xbox/2.0.4548.0 UPnP/1.0 Xbox/2.0.4548.0"
69          );
70          Assert.assertEquals(provider.provide(clientInfo), dd1);
71      }
72  }