ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pabramowit...@apache.org
Subject svn commit: r1883540 - in /ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util: DummyAnnotator.java UmlsUserTest.java UmlsUserTester.java
Date Tue, 17 Nov 2020 15:13:50 GMT
Author: pabramowitsch
Date: Tue Nov 17 15:13:49 2020
New Revision: 1883540

URL: http://svn.apache.org/viewvc?rev=1883540&view=rev
Log:
Ctakes issue 545 UMLS Authentication

Added:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java
  (with props)
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTest.java
      - copied, changed from r1883539, ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTester.java
Removed:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTester.java

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java?rev=1883540&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java
Tue Nov 17 15:13:49 2020
@@ -0,0 +1,55 @@
+package org.apache.ctakes.dictionary.lookup2.util;
+/*
+ * 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.
+ */
+
+
+import org.apache.log4j.Logger;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+
+public class DummyAnnotator extends JCasAnnotator_ImplBase {
+
+	public static final String PARAM_SAVE_ANN = "PARAM_SAVE_ANN";
+	public static final String PARAM_PRINT_ANN = "PARAM_PRINT_ANN";
+
+	@Override
+	public void process(JCas jcas) throws AnalysisEngineProcessException {
+		// never run
+	}
+
+	@Override
+	public void initialize(UimaContext context)
+			throws ResourceInitializationException {
+		super.initialize(context);
+	}
+
+
+	public AnalysisEngineDescription createAnnotatorDescription()
+			throws ResourceInitializationException {
+		return AnalysisEngineFactory.createEngineDescription(
+				DummyAnnotator.class,
+				DummyAnnotator.PARAM_SAVE_ANN, true,
+				DummyAnnotator.PARAM_PRINT_ANN, true);
+	}
+}

Propchange: ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/DummyAnnotator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTest.java
(from r1883539, ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTester.java)
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTest.java?p2=ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTest.java&p1=ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTester.java&r1=1883539&r2=1883540&rev=1883540&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTester.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/test/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserTest.java
Tue Nov 17 15:13:49 2020
@@ -1,28 +1,127 @@
 package org.apache.ctakes.dictionary.lookup2.util;
+import java.io.File;
+import java.util.Properties;
 
+import org.junit.Assert;
+import org.junit.Ignore;
 import org.apache.ctakes.core.ae.UmlsEnvironmentConfiguration;
 import org.apache.ctakes.utils.env.EnvironmentVariable;
+import org.apache.ctakes.utils.test.TestUtil;
 import org.apache.log4j.Logger;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
 
 /**
- * @author SPF , chip-nlp
+ * @author SPF , chip-nlp, pabramowitsch
  * @version %I%
  * @since 8/24/2015
+ * 
+ * To run this test suite, please substitute CHANGE_ME for your API Key
+ * then add the following to your environment
+ *  umlsPass = <your api key>, 
+ *       or ctakes.umlspw = <your api key>
+ *  ummlsUser = "umls_api_user", 
+ *       or ctakes.umlsuser="umls_api_user"
+ *  Then Remove the @Ignore attribute below
+ *  Then run.
+ *  
  */
-final public class UmlsUserTester {
 
-   static private final Logger LOGGER = Logger.getLogger( "UmlsUserTester" );
+@Ignore  // needed for successful maven build/test when no API key is supplied
+final public class UmlsUserTest {
 
-   private UmlsUserTester() {
+   static private final Logger LOGGER = Logger.getLogger( "UmlsUserTester" );
+   static UimaContext _uimaContext = null;
+   
+   private final String apiKeyForTesting = "CHANGE_ME";
+ 
+   // reductio ad absurdem to get a UimaContext
+   static  {
+	   AnalysisEngine contextAE;
+	try {
+		DummyAnnotator da = new DummyAnnotator();
+		contextAE = UIMAFramework.produceAnalysisEngine(da.createAnnotatorDescription());
+		 _uimaContext = contextAE.getUimaContext();
+	} catch (ResourceInitializationException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	}
    }
-
-   static public boolean canTestUmlsUser() {
-      String user = EnvironmentVariable.getEnv(UmlsEnvironmentConfiguration.USER.toString());
-      if ( user == null || user.equals( EnvironmentVariable.NOT_PRESENT ) ) {
-         return false;
-      }
-      String pass = EnvironmentVariable.getEnv( UmlsEnvironmentConfiguration.PASSWORD.toString());
-      return pass != null && !pass.equals( EnvironmentVariable.NOT_PRESENT );
+   
+  @Test
+  public void testViaProps() {
+	   Properties props = new Properties();
+	   props.setProperty(UmlsUserApprover.USER_PARAM, "umls_api_key");
+	   props.setProperty(UmlsUserApprover.PASS_PARAM, apiKeyForTesting);
+	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+	   Assert.assertEquals(true, approver.isValidUMLSUser(_uimaContext, props));
+	   approver.resetUserCache();
    }
-
+  
+  @Test
+  public void testViaProps2() {
+	   Properties props = new Properties();
+	   props.setProperty(UmlsEnvironmentConfiguration.USER.toString(), "umls_api_key");
+	   props.setProperty(UmlsEnvironmentConfiguration.PASSWORD.toString(), apiKeyForTesting);
+	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+	   Assert.assertEquals(true, approver.isValidUMLSUser(_uimaContext, props));
+	   approver.resetUserCache();
+   }
+   
+   @Test
+   public void testViaEnvironment() {
+	   /**
+	    * to pass this test please either pair of environment variables
+	    * umlsUser, umlsPass
+	    * ctakes.umlsuser
+	    * ctakes.umlspass
+	    */
+ 	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+ 	   Assert.assertEquals(true, approver.isValidUMLSUser(_uimaContext, System.getProperties()));
+ 	   approver.resetUserCache();
+    }
+   
+   @Test
+   public void testViaApiKeyasUser() {
+	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+	   Assert.assertEquals(true,approver.isValidUMLSUser(
+			   "","","umls_api_key", apiKeyForTesting));
+	   approver.resetUserCache();
+   }
+   
+   @Test
+   public void testOldApiParams() {
+	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+	   Assert.assertNotEquals(true,approver.isValidUMLSUser(
+			   "","","mocuser","mockpwd"));
+	   approver.resetUserCache();
+   }
+   
+   @Test
+   public void testViaSingleProp() {
+ 	   Properties props = new Properties();
+ 	   props.setProperty(UmlsUserApprover.API_KEY_PROP, apiKeyForTesting);
+ 	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+ 	   Assert.assertEquals(true, approver.isValidUMLSUser(_uimaContext, props));
+ 	   approver.resetUserCache();
+    }
+   
+   /**
+    * for this test you will need to make sure any user/pass env vars have been removed and
instead
+    * export ctakes.umls_apikey="<Your Key>"   or  export ctakes_umls_apikey="<Your
Key>"
+    */
+   @Ignore
+   @Test
+   public void testViaSingleEnvar() {
+ 	   Properties props = new Properties();
+ 	   UmlsUserApprover approver = UmlsUserApprover.getInstance();
+ 	   Assert.assertEquals(true, approver.isValidUMLSUser(_uimaContext, props));
+ 	   approver.resetUserCache();
+    }
+   
 }



Mime
View raw message