You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by bd...@apache.org on 2013/02/25 22:20:47 UTC

svn commit: r1449905 - in /incubator/devicemap/trunk: ./ openddr/java/ openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/ openddr/test-data/ openddr/test-data/src/ openddr/test-data/src/main/ openddr/test-data/src/main/resources/ openddr/t...

Author: bdelacretaz
Date: Mon Feb 25 21:20:46 2013
New Revision: 1449905

URL: http://svn.apache.org/r1449905
Log:
DMAP-18 - use neutral format ua-to-properties.txt to drive tests of the UA->properties mapping

Added:
    incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java   (with props)
    incubator/devicemap/trunk/openddr/test-data/   (with props)
    incubator/devicemap/trunk/openddr/test-data/pom.xml   (with props)
    incubator/devicemap/trunk/openddr/test-data/src/
    incubator/devicemap/trunk/openddr/test-data/src/main/
    incubator/devicemap/trunk/openddr/test-data/src/main/resources/
    incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/
    incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt   (with props)
Modified:
    incubator/devicemap/trunk/   (props changed)
    incubator/devicemap/trunk/openddr/java/pom.xml
    incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java
    incubator/devicemap/trunk/pom.xml

Propchange: incubator/devicemap/trunk/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 25 21:20:46 2013
@@ -0,0 +1,14 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+
+

Modified: incubator/devicemap/trunk/openddr/java/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/pom.xml?rev=1449905&r1=1449904&r2=1449905&view=diff
==============================================================================
--- incubator/devicemap/trunk/openddr/java/pom.xml (original)
+++ incubator/devicemap/trunk/openddr/java/pom.xml Mon Feb 25 21:20:46 2013
@@ -61,6 +61,16 @@
           <target>1.5</target>
         </configuration>
       </plugin>
+    <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.13</version>
+        <configuration>
+            <systemPropertyVariables>
+                <devicemap.test.data.file>${project.build.directory}/devicemap/test-data/ua-to-properties.txt</devicemap.test.data.file>
+            </systemPropertyVariables>
+        </configuration>
+    </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
@@ -73,7 +83,7 @@
               <goal>unpack-dependencies</goal>
             </goals>
             <configuration>
-              <includes>**/*.xml</includes>
+              <includes>**/*.xml,**/*.txt</includes>
               <outputDirectory>${project.build.directory}/devicemap</outputDirectory>
               <overWriteReleases>false</overWriteReleases>
               <overWriteSnapshots>true</overWriteSnapshots>
@@ -120,6 +130,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.devicemap</groupId>
+      <artifactId>devicemap-test-data</artifactId>
+      <version>0.9.9-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.11</version>

Added: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java?rev=1449905&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java Mon Feb 25 21:20:46 2013
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.devicemap.simpleddr.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.apache.devicemap.simpleddr.test.DeviceMapService.DEVICEMAP_SERVICE;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.w3c.ddr.simple.PropertyRef;
+import org.w3c.ddr.simple.PropertyValues;
+
+/** Run tests defined by the test-data module */
+public class TestDataFileEntries {
+    
+    public static final String TEST_FILE_PROP = "devicemap.test.data.file";
+    public static final String DMAP_EXPECT = "DMAP_EXPECT";
+    
+    // TODO this should contain all property names that are
+    // present in the test file
+    public static final PropertyRef [] PROP_REFS = 
+            Util.getPropertyRefs(
+                    DEVICEMAP_SERVICE, 
+                    "vendor", "model", "displayWidth", "displayHeight");
+    
+    static private class TestEntry {
+        String userAgent;
+        Properties expected;
+    };
+    
+    private final File getDataFile() throws IOException {
+        final String filename = System.getProperty(TEST_FILE_PROP);
+        assertNotNull("Expecting non-null system property " + TEST_FILE_PROP, filename);
+        final File f = new File(filename);
+        if(!f.canRead()) {
+            throw new IOException("File not found:" 
+                    + f.getAbsolutePath() 
+                    + " (defined by system property " + TEST_FILE_PROP + ")");
+        }
+        return f;
+    }
+
+    private TestEntry parseLine(String line) {
+        line = line.trim();
+        if(line.startsWith("#") || line.length() == 0) {
+            return null;
+        }
+        
+        final TestEntry result = new TestEntry();
+        // Parse test line which is in a format like
+        // UA DMAP_EXPECT vendor:foo model:bar
+        // where UA is the User-Agent
+        // DMAP_EXPECT is a constant separator
+        // and the test is name/value pairs of properties
+        final String [] mainParts = line.split(DMAP_EXPECT);
+        assertEquals("Expecting " + DMAP_EXPECT + " separator", 2, mainParts.length);
+        result.userAgent = mainParts[0].trim();
+        result.expected = new Properties();
+        final String [] kvParts = mainParts[1].split(" ");
+        for(String part : kvParts) {
+            part = part.trim();
+            if(part.length() == 0) {
+                continue;
+            }
+            String [] kvPair = part.split(":");
+            assertEquals("Expecting 2 parts in kvPair '" + part + "'", 2, kvPair.length);
+            result.expected.put(kvPair[0].trim(), kvPair[1].trim());
+        }
+        
+        return result;
+    }
+    
+    @Test
+    public void testDataFileEntries() throws Exception {
+        String line = null;
+        final BufferedReader r = new BufferedReader(new FileReader(getDataFile()));
+        try {
+            while( (line = r.readLine()) != null) {
+                final TestEntry te = parseLine(line);
+                if(te == null) {
+                    continue;
+                }
+                final PropertyValues pvs = DEVICEMAP_SERVICE.getPropertyValues(new UserAgentEvidence(te.userAgent));
+                Util.assertProperties(te.expected, pvs, PROP_REFS);
+            }
+        } finally {
+            r.close();
+        }
+   }
+}
\ No newline at end of file

Propchange: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDataFileEntries.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java?rev=1449905&r1=1449904&r2=1449905&view=diff
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java (original)
+++ incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java Mon Feb 25 21:20:46 2013
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Properties;
+
 import org.w3c.ddr.simple.PropertyRef;
 import org.w3c.ddr.simple.PropertyValue;
 import org.w3c.ddr.simple.PropertyValues;
@@ -48,6 +50,28 @@ public class Util {
         }
     }
     
+    static void assertProperties(Properties expected, PropertyValues actual, PropertyRef [] refs) throws NameException, ValueException {
+        assertNotNull("Expecting non-null PropertyValues", actual);
+        assertFalse("Expected properties should not be empty", expected.isEmpty());
+        for(Object k : expected.keySet()) {
+            final String name = k.toString();
+            PropertyRef ref = null;
+            for(PropertyRef pr : refs) {
+                if(pr.getLocalPropertyName().equals(name)) {
+                    ref = pr;
+                    break;
+                }
+            }
+            assertNotNull("ref '" + name + "' should be found", ref);
+            final PropertyValue pv = actual.getValue(ref);
+            assertTrue("Expecting property '" + name + "' to be found for current device", pv.exists());
+            final String value = pv.getString();
+            final String expectedValue = expected.getProperty(name);
+            assertEquals("Expecting value " + expectedValue + " for " 
+                    + name, expectedValue, value);
+        }
+    }
+    
     static PropertyRef [] getPropertyRefs(Service s, String ... names) {
         final PropertyRef [] result = new PropertyRef[names.length];
         try {

Propchange: incubator/devicemap/trunk/openddr/test-data/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 25 21:20:46 2013
@@ -0,0 +1,14 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+
+

Added: incubator/devicemap/trunk/openddr/test-data/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/test-data/pom.xml?rev=1449905&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/test-data/pom.xml (added)
+++ incubator/devicemap/trunk/openddr/test-data/pom.xml Mon Feb 25 21:20:46 2013
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or
+    more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information regarding
+    copyright ownership. The ASF licenses this file to you under the
+    Apache License, Version 2.0 (the "License"); you may not use
+    this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+    applicable law or agreed to in writing, software distributed
+    under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions
+    and limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>9</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.apache.devicemap</groupId>
+  <artifactId>devicemap-test-data</artifactId>
+  <packaging>jar</packaging>
+  <version>0.9.9-SNAPSHOT</version>
+  <name>Apache DeviceMap Test Data</name>
+  <inceptionYear>2013</inceptionYear>
+  <url>http://incubator.apache.org/devicemap</url>
+
+  <prerequisites>
+    <maven>3.0.2</maven>
+  </prerequisites>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/devicemap/trunk/openddr/test-data</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/devicemap/trunk/openddr/test-data</developerConnection>
+    <url>http://svn.apache.org/repos/asf/incubator/devicemap/trunk/openddr/test-data</url>
+  </scm>
+ </project> 

Propchange: incubator/devicemap/trunk/openddr/test-data/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt?rev=1449905&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt (added)
+++ incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt Mon Feb 25 21:20:46 2013
@@ -0,0 +1,10 @@
+# User-Agent to properties test file, see DMAP-18
+# Comments like this are ignored, as are blank lines
+
+# each line describes a User-Agent to properties mapping,
+# that's meant to be tested by various DeviceMap implementations
+# DMAP_EXPECT separates the User-Agent and expected property values
+SAMSUNG-GT-B7610/1.0 Browser/Opera/9.5 Profile/MIDP-2.0 Configuration/CLDC-1.1 UNTRUSTED/1.0 DMAP_EXPECT vendor:Samsung model:GT-B7610
+
+# test lines can have varying sets of properties
+Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 DMAP_EXPECT vendor:Apple model:iPhone displayHeight:480

Propchange: incubator/devicemap/trunk/openddr/test-data/src/main/resources/test-data/ua-to-properties.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/devicemap/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/pom.xml?rev=1449905&r1=1449904&r2=1449905&view=diff
==============================================================================
--- incubator/devicemap/trunk/pom.xml (original)
+++ incubator/devicemap/trunk/pom.xml Mon Feb 25 21:20:46 2013
@@ -39,6 +39,7 @@
   <modules>
     <module>openddr/data</module>
     <module>openddr/java</module>
+    <module>openddr/test-data</module>
   </modules>
 </project>