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/15 17:52:56 UTC

svn commit: r1446684 - in /incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test: TestDeviceDataQueries.java TestSimpleQueries.java Util.java

Author: bdelacretaz
Date: Fri Feb 15 16:52:55 2013
New Revision: 1446684

URL: http://svn.apache.org/r1446684
Log:
DMAP-17 - cleanup/refactor

Added:
    incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java   (with props)
Modified:
    incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDeviceDataQueries.java
    incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestSimpleQueries.java

Modified: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDeviceDataQueries.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDeviceDataQueries.java?rev=1446684&r1=1446683&r2=1446684&view=diff
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDeviceDataQueries.java (original)
+++ incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestDeviceDataQueries.java Fri Feb 15 16:52:55 2013
@@ -20,49 +20,17 @@ package org.apache.devicemap.simpleddr.t
 
 import static org.apache.devicemap.simpleddr.test.DeviceMapService.DEVICEMAP_SERVICE;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import org.junit.Test;
 import org.w3c.ddr.simple.PropertyRef;
-import org.w3c.ddr.simple.PropertyValue;
 import org.w3c.ddr.simple.PropertyValues;
-import org.w3c.ddr.simple.exception.NameException;
-import org.w3c.ddr.simple.exception.ValueException;
 
 /** Test a simple DDR query */
 public class TestDeviceDataQueries {
     
-    public static final String [] PROP_NAMES = { "vendor", "model", "displayWidth", "displayHeight" };
-    public static final PropertyRef [] PROP_REFS = new PropertyRef[PROP_NAMES.length];
-    
-    static {
-        try {
-            for(int i=0; i < PROP_NAMES.length; i++) {
-                PROP_REFS[i] = DEVICEMAP_SERVICE.newPropertyRef(PROP_NAMES[i]);
-            }
-        } catch(Exception e) {
-            throw new RuntimeException("Exception while creating PropertyRefs", e);
-        }
-    }
-    
-    private void assertProperties(String [] expected, PropertyValues actual, PropertyRef [] refs) throws NameException, ValueException {
-        assertNotNull("Expecting non-null PropertyValues", actual);
-        for(int i=0; i < refs.length; i++) {
-            final PropertyValue pv = actual.getValue(PROP_REFS[i]);
-            assertNotNull("Expecting non-null PropertyValue for " 
-                    + refs[i].getLocalPropertyName(), pv);
-            if(expected[i] == null) {
-                assertFalse("Expecting property to have exist==false: " + PROP_REFS[i].getLocalPropertyName(), pv.exists());
-            } else {
-                assertTrue("Expecting property to exist:" + PROP_REFS[i].getLocalPropertyName(), pv.exists());
-                assertEquals("Expecting value " + expected[i] + " for " 
-                        + refs[i].getLocalPropertyName(), expected[i], pv.getString());
-            }
-        }
-    }
+    public static final PropertyRef [] PROP_REFS = 
+            Util.getPropertyRefs(
+                    DEVICEMAP_SERVICE, 
+                    "vendor", "model", "displayWidth", "displayHeight");
     
     @Test
     public void SamsungGtIsFound() throws Exception {
@@ -70,7 +38,7 @@ public class TestDeviceDataQueries {
         final String UA = "SAMSUNG-GT-B7610/1.0 Browser/Opera/9.5 Profile/MIDP-2.0 Configuration/CLDC-1.1 UNTRUSTED/1.0";
         
         final PropertyValues pvs = DEVICEMAP_SERVICE.getPropertyValues(new UserAgentEvidence(UA));
-        assertProperties(expected, pvs, PROP_REFS);
+        Util.assertProperties(expected, pvs, PROP_REFS);
     }
     
     @Test
@@ -79,6 +47,6 @@ public class TestDeviceDataQueries {
         final String UA = "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";
         
         final PropertyValues pvs = DEVICEMAP_SERVICE.getPropertyValues(new UserAgentEvidence(UA));
-        assertProperties(expected, pvs, PROP_REFS);
+        Util.assertProperties(expected, pvs, PROP_REFS);
     }
 }
\ No newline at end of file

Modified: incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestSimpleQueries.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestSimpleQueries.java?rev=1446684&r1=1446683&r2=1446684&view=diff
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestSimpleQueries.java (original)
+++ incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/TestSimpleQueries.java Fri Feb 15 16:52:55 2013
@@ -20,49 +20,17 @@ package org.apache.devicemap.simpleddr.t
 
 import static org.apache.devicemap.simpleddr.test.TestDataService.TEST_DATA_SERVICE;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import org.junit.Test;
 import org.w3c.ddr.simple.PropertyRef;
-import org.w3c.ddr.simple.PropertyValue;
 import org.w3c.ddr.simple.PropertyValues;
-import org.w3c.ddr.simple.exception.NameException;
-import org.w3c.ddr.simple.exception.ValueException;
 
 /** Test a simple DDR query */
 public class TestSimpleQueries {
     
-    public static final String [] PROP_NAMES = { "vendor", "model", "displayWidth", "displayHeight", "playback_3gpp" };
-    public static final PropertyRef [] PROP_REFS = new PropertyRef[PROP_NAMES.length];
-    
-    static {
-        try {
-            for(int i=0; i < PROP_NAMES.length; i++) {
-                PROP_REFS[i] = TEST_DATA_SERVICE.newPropertyRef(PROP_NAMES[i]);
-            }
-        } catch(Exception e) {
-            throw new RuntimeException("Exception while creating PropertyRefs", e);
-        }
-    }
-    
-    private void assertProperties(String [] expected, PropertyValues actual, PropertyRef [] refs) throws NameException, ValueException {
-        assertNotNull("Expecting non-null PropertyValues", actual);
-        for(int i=0; i < refs.length; i++) {
-            final PropertyValue pv = actual.getValue(PROP_REFS[i]);
-            assertNotNull("Expecting non-null PropertyValue for " 
-                    + refs[i].getLocalPropertyName(), pv);
-            if(expected[i] == null) {
-                assertFalse("Expecting property to have exist==false: " + PROP_REFS[i].getLocalPropertyName(), pv.exists());
-            } else {
-                assertTrue("Expecting property to exist:" + PROP_REFS[i].getLocalPropertyName(), pv.exists());
-                assertEquals("Expecting value " + expected[i] + " for " 
-                        + refs[i].getLocalPropertyName(), expected[i], pv.getString());
-            }
-        }
-    }
+    public static final PropertyRef [] PROP_REFS = 
+            Util.getPropertyRefs(
+                    TEST_DATA_SERVICE, 
+                    "vendor", "model", "displayWidth", "displayHeight", "playback_3gpp");
     
     @Test
     public void nexusOneIsFound() throws Exception {
@@ -70,7 +38,7 @@ public class TestSimpleQueries {
         final String nexusUA = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
         
         final PropertyValues pvs = TEST_DATA_SERVICE.getPropertyValues(new UserAgentEvidence(nexusUA));
-        assertProperties(expected, pvs, PROP_REFS);
+        Util.assertProperties(expected, pvs, PROP_REFS);
     }
     
     @Test
@@ -81,6 +49,6 @@ public class TestSimpleQueries {
         final String [] expected = new String[PROP_REFS.length];
         
         final PropertyValues pvs = TEST_DATA_SERVICE.getPropertyValues(new UserAgentEvidence("foo"));
-        assertProperties(expected, pvs, PROP_REFS);
+        Util.assertProperties(expected, pvs, PROP_REFS);
     }
 }
\ No newline at end of file

Added: 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=1446684&view=auto
==============================================================================
--- incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java (added)
+++ incubator/devicemap/trunk/openddr/java/src/test/java/org/apache/devicemap/simpleddr/test/Util.java Fri Feb 15 16:52:55 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.w3c.ddr.simple.PropertyRef;
+import org.w3c.ddr.simple.PropertyValue;
+import org.w3c.ddr.simple.PropertyValues;
+import org.w3c.ddr.simple.Service;
+import org.w3c.ddr.simple.exception.NameException;
+import org.w3c.ddr.simple.exception.ValueException;
+
+public class Util {
+    
+    static void assertProperties(String [] expected, PropertyValues actual, PropertyRef [] refs) throws NameException, ValueException {
+        assertNotNull("Expecting non-null PropertyValues", actual);
+        for(int i=0; i < refs.length; i++) {
+            final PropertyValue pv = actual.getValue(refs[i]);
+            assertNotNull("Expecting non-null PropertyValue for " 
+                    + refs[i].getLocalPropertyName(), pv);
+            if(expected[i] == null) {
+                assertFalse("Expecting property to have exist==false: " + refs[i].getLocalPropertyName(), pv.exists());
+            } else {
+                assertTrue("Expecting property to exist:" + refs[i].getLocalPropertyName(), pv.exists());
+                assertEquals("Expecting value " + expected[i] + " for " 
+                        + refs[i].getLocalPropertyName(), expected[i], pv.getString());
+            }
+        }
+    }
+    
+    static PropertyRef [] getPropertyRefs(Service s, String ... names) {
+        final PropertyRef [] result = new PropertyRef[names.length];
+        try {
+            for(int i=0; i < names.length; i++) {
+                result[i] = s.newPropertyRef(names[i]);
+            }
+        } catch(Exception e) {
+            throw new RuntimeException("Exception while creating PropertyRefs", e);
+        }
+        return result;
+    }
+}

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

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