devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1649961 - in /devicemap/trunk/devicemap/java/classifier_w3c_simple/src: main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
Date Tue, 06 Jan 2015 22:18:00 GMT
Author: rezan
Date: Tue Jan  6 22:18:00 2015
New Revision: 1649961

URL: http://svn.apache.org/r1649961
Log:
w3c ddr simple enhancements

Modified:
    devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
    devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java

Modified: devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java?rev=1649961&r1=1649960&r2=1649961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
(original)
+++ devicemap/trunk/devicemap/java/classifier_w3c_simple/src/main/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimple.java
Tue Jan  6 22:18:00 2015
@@ -15,11 +15,11 @@
  */
 package org.apache.devicemap.w3csimple;
 
+import java.io.IOException;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.devicemap.DeviceMapClient;
-import org.apache.devicemap.DeviceMapFactory;
 import org.apache.devicemap.loader.LoaderOption;
 import org.apache.devicemap.w3csimple.model.DeviceMapEvidence;
 import org.apache.devicemap.w3csimple.model.DeviceMapPropertyName;
@@ -39,13 +39,43 @@ public class DeviceMapW3CSimple implemen
 
   public final static String VERSION = "1.0.0";
   public final static String NAMESPACE = "org.apache.devicemap";
+  public final static String VOCABULARY = "org.apache.devicemap";
   public final static String EVIDENCE = "User-Agent";
+  public final static String LOADER_OPTION = "loaderOption";
+  public final static String LOADER_OPTION_PATH = "loaderOptionPath";
 
   private DeviceMapClient client;
 
   @Override
   public void initialize(String defaultVocabularyIRI, Properties props) throws NameException,
InitializationException {
-    client = DeviceMapFactory.getClient(LoaderOption.JAR);
+
+    if(!VOCABULARY.equals(defaultVocabularyIRI)) {
+      throw new NameException(NameException.VOCABULARY_NOT_RECOGNIZED, defaultVocabularyIRI);
+    }
+
+    LoaderOption loaderOption = LoaderOption.JAR;
+    String path = null;
+
+    if(props != null && props.containsKey(LOADER_OPTION)) {
+      try {
+        loaderOption = LoaderOption.valueOf(props.getProperty(LOADER_OPTION));
+      } catch(IllegalArgumentException ex) {
+        throw new InitializationException(InitializationException.INITIALIZATION_ERROR,
+                "Invalid loader option: " + props.getProperty(LOADER_OPTION));
+      }
+
+      if(props.containsKey(LOADER_OPTION_PATH)) {
+        path = props.getProperty(LOADER_OPTION_PATH);
+      }
+    }
+
+    client = new DeviceMapClient();
+
+    try {
+      client.initDeviceData(loaderOption, path);
+    } catch(IOException ex) {
+      throw new InitializationException(InitializationException.INITIALIZATION_ERROR, ex);
+    }
   }
 
   @Override

Modified: devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java?rev=1649961&r1=1649960&r2=1649961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
(original)
+++ devicemap/trunk/devicemap/java/classifier_w3c_simple/src/test/java/org/apache/devicemap/w3csimple/DeviceMapW3CSimpleTest.java
Tue Jan  6 22:18:00 2015
@@ -15,10 +15,14 @@
  */
 package org.apache.devicemap.w3csimple;
 
+import java.util.Properties;
+import org.apache.devicemap.loader.LoaderOption;
 import org.junit.Assert;
 import org.junit.Test;
 
 import org.w3c.ddr.simple.Evidence;
+import org.w3c.ddr.simple.Service;
+import org.w3c.ddr.simple.ServiceFactory;
 
 public class DeviceMapW3CSimpleTest {
 
@@ -26,8 +30,7 @@ public class DeviceMapW3CSimpleTest {
   public void testDeviceMapW3CSimple() throws Exception {
     //System.out.println("DeviceMapW3CSimple test");
 
-    DeviceMapW3CSimple simple = new DeviceMapW3CSimple();
-    simple.initialize(DeviceMapW3CSimple.NAMESPACE, null);
+    Service simple = ServiceFactory.newService(DeviceMapW3CSimple.class.getName() , DeviceMapW3CSimple.VOCABULARY,
null);
 
     String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27)
AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
 
@@ -46,4 +49,22 @@ public class DeviceMapW3CSimpleTest {
 
     Assert.assertEquals("test ua not htc aria", "HTC Aria", simple.getPropertyValue(e, "id").getString());
   }
+
+  //@Test
+  //This test requires internet, so its optional
+  public void testDeviceMapW3CSimpleURL() throws Exception {
+    Properties props = new Properties();
+
+    props.put(DeviceMapW3CSimple.LOADER_OPTION, LoaderOption.URL.name());
+    props.put(DeviceMapW3CSimple.LOADER_OPTION_PATH, "http://devicemap-vm.apache.org/data/latest/");
+
+    Service simple = ServiceFactory.newService(DeviceMapW3CSimple.class.getName() , DeviceMapW3CSimple.VOCABULARY,
props);
+
+    String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27)
AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
+
+    Evidence e = simple.newHTTPEvidence();
+    e.put(DeviceMapW3CSimple.EVIDENCE, userAgent);
+
+    Assert.assertEquals("test ua not htc aria", "HTC Aria", simple.getPropertyValue(e, "id").getString());
+  }
 }



Mime
View raw message