You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2014/07/17 04:49:06 UTC
svn commit: r1611239 [6/7] - in /incubator/devicemap/tags/releases:
devicemap-data-1.0.0/ devicemap-data-1.0.0/src/
devicemap-data-1.0.0/src/main/ devicemap-data-1.0.0/src/main/resources/
devicemap-data-1.0.0/src/main/resources/devicedata/ devicemap-ja...
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/FileResource.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/FileResource.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/FileResource.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/FileResource.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,50 @@
+/*
+ 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.loader.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.devicemap.loader.Resource;
+
+public class FileResource implements Resource {
+
+ private static final String DEFAULT_PATH = "";
+
+ private final String path;
+
+ public FileResource(String path) {
+ if (path == null) {
+ this.path = DEFAULT_PATH;
+ } else if (path.isEmpty()) {
+ this.path = "";
+ } else {
+ this.path = path + File.separatorChar;
+ }
+ }
+
+ @Override
+ public InputStream getResource(String file) throws IOException {
+ String rpath = path + file;
+ return new FileInputStream(rpath);
+ }
+
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/JarResource.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/JarResource.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/JarResource.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/JarResource.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,53 @@
+/*
+ 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.loader.resource;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.devicemap.loader.Resource;
+
+public class JarResource implements Resource {
+
+ private static final String DEFAULT_PATH = "/devicedata/";
+
+ private final String path;
+
+ public JarResource(String path) {
+ if (path == null) {
+ this.path = DEFAULT_PATH;
+ } else {
+ this.path = path;
+ }
+ }
+
+ @Override
+ public InputStream getResource(String file) throws IOException {
+ String rpath = path + file;
+
+ InputStream in = JarResource.class.getResourceAsStream(rpath);
+
+ if (in == null) {
+ throw new FileNotFoundException("Jar resource not found: " + path);
+ }
+
+ return in;
+ }
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/URLResource.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/URLResource.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/URLResource.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/main/java/org/apache/devicemap/loader/resource/URLResource.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,48 @@
+/*
+ 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.loader.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.devicemap.loader.Resource;
+
+public class URLResource implements Resource {
+
+ //TODO: put on CDN of some kind
+ private static final String DEFAULT_PATH = "http://svn.apache.org/repos/asf/incubator/devicemap/trunk/data/device-data/src/main/resources/devicedata";
+
+ private final String path;
+
+ public URLResource(String path) {
+ if (path == null) {
+ this.path = DEFAULT_PATH;
+ } else {
+ this.path = path;
+ }
+ }
+
+ @Override
+ public InputStream getResource(String file) throws IOException {
+ String rpath = path + "/" + file;
+ return new URL(rpath).openStream();
+ }
+
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientFileTestOptional.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientFileTestOptional.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientFileTestOptional.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientFileTestOptional.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,41 @@
+/*
+ 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;
+
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.devicemap.loader.LoaderOption;
+
+public class DeviceMapClientFileTestOptional {
+
+ @Test
+ public void DeviceMapClientFolderTest() throws Exception {
+ DeviceMapClient client = new DeviceMapClient();
+
+ client.initDeviceData(LoaderOption.FOLDER, "../../../data/device-data/src/main/resources/devicedata");
+
+ String test = "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";
+
+ Map<String, String> m = client.classify(test);
+
+ Assert.assertEquals("test ua not htc aria", "HTC Aria", m.get("id"));
+ }
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientJarTest.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientJarTest.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientJarTest.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientJarTest.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,41 @@
+/*
+ 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;
+
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.devicemap.loader.LoaderOption;
+
+public class DeviceMapClientJarTest {
+
+ @Test
+ public void DeviceMapClientJarTest() throws Exception {
+ DeviceMapClient client = new DeviceMapClient();
+
+ client.initDeviceData(LoaderOption.JAR);
+
+ String test = "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";
+
+ Map<String, String> m = client.classify(test);
+
+ Assert.assertEquals("test ua not htc aria", "HTC Aria", m.get("id"));
+ }
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientTest.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientTest.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientTest.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientTest.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,76 @@
+/*
+ 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;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.devicemap.loader.LoaderOption;
+
+@RunWith(value = Parameterized.class)
+public class DeviceMapClientTest {
+
+ private static DeviceMapClient client;
+
+ @BeforeClass
+ public static void setupDeviceMapClient() throws Exception {
+ client = new DeviceMapClient();
+ client.initDeviceData(LoaderOption.JAR);
+ }
+
+ @Parameters
+ public static Collection<Object[]> data() throws Exception {
+ Collection<Object[]> params = new ArrayList<Object[]>();
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(DeviceMapClientTest.class.getResourceAsStream("/uas.data")));
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ params.add(line.split("\\|\\|"));
+ }
+
+ reader.close();
+
+ return params;
+ }
+
+ private final String testString;
+ private final String resultId;
+
+ public DeviceMapClientTest(String testString, String resultId) {
+ this.testString = testString;
+ this.resultId = resultId;
+ }
+
+ @Test
+ public void DeviceMapClientTest() throws Exception {
+ Map<String, String> m = client.classify(testString);
+
+ Assert.assertEquals("classification failed for '" + testString + "'", resultId, m.get("id"));
+ }
+}
Added: incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientUrlTestOptional.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientUrlTestOptional.java?rev=1611239&view=auto
==============================================================================
--- incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientUrlTestOptional.java (added)
+++ incubator/devicemap/tags/releases/devicemap-java-client-1.0.0/src/test/java/org/apache/devicemap/DeviceMapClientUrlTestOptional.java Thu Jul 17 02:49:04 2014
@@ -0,0 +1,54 @@
+/*
+ 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;
+
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.devicemap.loader.LoaderOption;
+
+public class DeviceMapClientUrlTestOptional {
+
+ @Test
+ public void DeviceMapClientUrlTest() throws Exception {
+ DeviceMapClient client = new DeviceMapClient();
+
+ client.initDeviceData(LoaderOption.URL);
+
+ String test = "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";
+
+ Map<String, String> m = client.classify(test);
+
+ Assert.assertEquals("test ua not htc aria", "HTC Aria", m.get("id"));
+ }
+
+ @Test
+ public void DeviceMapClientCustomUrlTest() throws Exception {
+ DeviceMapClient client = new DeviceMapClient();
+
+ client.initDeviceData(LoaderOption.URL, "http://www.rezsoft.org/dmap-data/");
+
+ String test = "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";
+
+ Map<String, String> m = client.classify(test);
+
+ Assert.assertEquals("test ua not htc aria", "HTC Aria", m.get("id"));
+ }
+}