[ 
https://issues.apache.org/jira/browse/OPENNLP-1414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17652922#comment-17652922
 ] 

ASF GitHub Bot commented on OPENNLP-1414:
-----------------------------------------

rzo1 commented on code in PR #472:
URL: https://github.com/apache/opennlp/pull/472#discussion_r1059116766


##########
opennlp-tools/src/test/java/opennlp/tools/util/DownloadUtilTest.java:
##########
@@ -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 opennlp.tools.util;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.NullAndEmptySource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import opennlp.tools.sentdetect.SentenceModel;
+import opennlp.tools.tokenize.TokenizerModel;
+
+public class DownloadUtilTest {
+
+  @ParameterizedTest(name = "Verify \"{0}\" sentence model")
+  @ValueSource(strings = {"en", "fr", "de", "it", "nl"})
+  public void testDownloadModelByLanguage(String lang) throws IOException {
+    SentenceModel model = DownloadUtil.downloadModel(lang,
+            DownloadUtil.ModelType.SENTENCE_DETECTOR, SentenceModel.class);

Review Comment:
   If the files are available at `System.getProperty("user.home") + 
"/.opennlp/")` and you are offline, the tests will pass. Otherwise if the tests 
were never run and you are offline, they will fail.
   
   In order to mock it, we would need to adjust the `BASE_URL` part and inject 
a base url like `file://` pointing to a local location containing related 
(mock) models. Due to the `static` nature of `DownloadUtil`, this is pain ;-)
   
   Side note: Having hard-coded values is a bit error prone (as shown by this 
issue ;-)). Perhaps it would be worth to parse the content of 
https://dlcdn.apache.org/opennlp/models/ud-models-1.0/ and obtain the model 
urls dynamically from that location (of course via separate issue). We do 
something similar in TomEE to dynamically generate our download page for the 
website.
   





> Investigate why DownloadUtil can't retrieve NL models via CDN
> -------------------------------------------------------------
>
>                 Key: OPENNLP-1414
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1414
>             Project: OpenNLP
>          Issue Type: Improvement
>    Affects Versions: 2.1.0
>            Reporter: Martin Wiesner
>            Assignee: Martin Wiesner
>            Priority: Minor
>             Fix For: 2.1.1
>
>
> While working on OPENNLP-1413, I discovered that the class 
> _opennlp.tools.util.DownloadUtil_ has a runtime issue with downloading 
> resources (models) for the Dutch locale (nl). Other locales referenced via 
> the static initializer block are accessible and can be downloaded.
> Moreover, a JUnit test is missing and should be provided.
> {*}Aim{*}:
>  * Investigate what's wrong with NL resources.
>  * If possible, fix the problem with retrieving Dutch models.
>  * Provide a JUnit tests that demonstrates correct behavior for all locales.
> JavaDoc is improved via OPENNLP-1413. Don't work on it twice...
> {*}Note{*}:
> For Dutch community this affects other parts of the Tools component as Model 
> classes rely on _DownloadUtil_ in at least one constructor. Therefore, this 
> should be fixed before the next release.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to