You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by al...@apache.org on 2017/12/04 05:42:48 UTC

svn commit: r1817062 - in /ctakes/trunk/ctakes-ytex: pom.xml src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties

Author: alexz
Date: Mon Dec  4 05:42:48 2017
New Revision: 1817062

URL: http://svn.apache.org/viewvc?rev=1817062&view=rev
Log:
CTAKES-308: fix ConceptDaoTest; missing hsqldb before running test

Added:
    ctakes/trunk/ctakes-ytex/src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties
Modified:
    ctakes/trunk/ctakes-ytex/pom.xml
    ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java
    ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java

Modified: ctakes/trunk/ctakes-ytex/pom.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/pom.xml?rev=1817062&r1=1817061&r2=1817062&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex/pom.xml (original)
+++ ctakes/trunk/ctakes-ytex/pom.xml Mon Dec  4 05:42:48 2017
@@ -299,12 +299,14 @@
 				</executions>
 			</plugin>
 
-			<!-- skip unit test run, tests to be executed during integration-test -->
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-surefire-plugin</artifactId>
 				<configuration>
-					<skip>true</skip>
+					<excludes>
+						<exclude>**/ConceptDaoTest*</exclude>
+						<exclude>**/UMLSDaoTest*</exclude>
+					</excludes>
 				</configuration>
 				<executions>
 					<execution>
@@ -314,18 +316,39 @@
 							<goal>test</goal>
 						</goals>
 						<configuration>
-							<skip>false</skip>
 							<forkMode>always</forkMode>
 							<systemPropertyVariables>
 								<log4j.configuration>file:${project.basedir}/src/test/resources/log4j.properties</log4j.configuration>
 							</systemPropertyVariables>
-							<additionalClasspathElements>
+							<!-- additionalClasspathElements>
 								<additionalClasspathElement>${project.basedir}/../ctakes-ytex-res/src/main/resources</additionalClasspathElement>
-							</additionalClasspathElements>
+							</additionalClasspathElements -->
 						</configuration>
 					</execution>
 				</executions>
 			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-failsafe-plugin</artifactId>
+				<version>2.20.1</version>
+				<configuration>
+					<includes>
+						<include>**/ConceptDaoTest</include>
+						<!-- IMPORTANT! in the apache-release profile, following test should be executed manually -->
+						<include>**/UMLSDaoTest</include>
+					</includes>
+				</configuration>
+				<executions>
+					<execution>
+						<goals>
+							<goal>integration-test</goal>
+							<goal>verify</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+
 		</plugins>
 		<pluginManagement>
 			<plugins>

Modified: ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java?rev=1817062&r1=1817061&r2=1817062&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java (original)
+++ ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java Mon Dec  4 05:42:48 2017
@@ -32,45 +32,75 @@ import org.apache.ctakes.ytex.kernel.met
 import org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityService.SimilarityMetricEnum;
 import org.apache.ctakes.ytex.kernel.model.ConceptGraph;
 import org.apache.log4j.Logger;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcOperations;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.Assert.*;
 
 public class ConceptDaoTest {
-	ConceptDao conceptDao;
-	ApplicationContext appCtx;
 
 	static private final Logger LOGGER = Logger.getLogger(ConceptDaoTest.class);
 
+	private ConceptDao conceptDao = null;
+
+	private ApplicationContext appCtx = null;
+
+	/**
+	 * Helper function to drop a 'table' from a DB, using SQL syntax
+	 *
+	 * @param jdbc
+	 * @param dbEngineType
+	 * @param sqlTableName
+	 */
+	private final void dropTableIfExist(JdbcOperations jdbc, final String dbEngineType, final String sqlTableName) {
+		// TODO: consider refactor using JOOQ
+		String sqlStatement = "";
+		switch (dbEngineType.toLowerCase()) {
+			case "hsql":
+			case "mysql":
+				sqlStatement = String.format("DROP TABLE IF EXISTS %s", sqlTableName);
+				break;
+			case "mssql":
+				sqlStatement = String.format("IF EXISTS(SELECT * FROM sys.objects WHERE object_id = object_id('%s')) DROP TABLE %s", sqlTableName);
+				break;
+			case "orcl":
+				sqlStatement = String.format("DROP TABLE %s", sqlTableName);
+				break;
+			default:
+				LOGGER.warn(String.format("unsupported DB engine type: %s", dbEngineType));
+				break;
+		}
+		if (!sqlStatement.isEmpty()) {
+			try {
+				jdbc.execute(sqlStatement);
+			} catch (DataAccessException e) {
+				LOGGER.warn("couldn't drop table test_concepts. Maybe it doesn't even exists", e);
+			}
+		}
+	}
+
 	@Before
 	public void setUp() throws Exception {
 		appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
 				.getInstance("classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
 				.useBeanFactory("kernelApplicationContext").getFactory();
 		conceptDao = appCtx.getBean(ConceptDao.class);
+
 		JdbcTemplate jdbcTemplate = new JdbcTemplate();
 		jdbcTemplate.setDataSource(appCtx.getBean(DataSource.class));
-		Properties ytexProperties = (Properties) appCtx
-				.getBean("ytexProperties");
+		Properties ytexProperties = (Properties) appCtx.getBean("ytexProperties");
 		String dbtype = ytexProperties.getProperty("db.type");
-		if ("hsql".equals(dbtype) || "mysql".equals(dbtype))
-			jdbcTemplate.execute("drop table if exists test_concepts");
-		if ("mssql".equals(dbtype))
-			jdbcTemplate.execute("if exists(select * from sys.objects where object_id = object_id('test_concepts')) drop table test_concepts");
-		if ("orcl".equals(dbtype)) {
-			// just try dropping the table, catch exception and hope all is well
-			try {
-				jdbcTemplate.execute("drop table test_concepts");
-			} catch (Exception ignore) {
 
-			}
-		}
+		dropTableIfExist(jdbcTemplate, dbtype, "test_concepts");
+
 		jdbcTemplate.execute("create table test_concepts(parent varchar(20), child varchar(20))");
 		jdbcTemplate.execute("insert into test_concepts values ('root', 'animal')");
 		jdbcTemplate.execute("insert into test_concepts values ('animal', 'vertebrate')");
@@ -78,13 +108,13 @@ public class ConceptDaoTest {
 		jdbcTemplate.execute("insert into test_concepts values ('vertebrate', 'dog')");
 		jdbcTemplate.execute("insert into test_concepts values ('root', 'bacteria')");
 		jdbcTemplate.execute("insert into test_concepts values ('bacteria', 'e coli')");
+
 		LOGGER.info("Create concept graph");
 		conceptDao.createConceptGraph(null, "test",
-				"select child, parent from test_concepts", true,
+				"SELECT child,parent FROM test_concepts", true,
 				Collections.EMPTY_SET);
 		ConceptGraph cg = conceptDao.getConceptGraph("test");
 		assertNotNull(cg);
-		((ConfigurableApplicationContext) appCtx).close();
 	}
 
 	@Test
@@ -112,4 +142,11 @@ public class ConceptDaoTest {
 		assertTrue(simDogCat.getSimilarities().get(1) > simDogEColi.getSimilarities().get(1));
 	}
 
+	@After
+	public void tearDown() throws  Exception {
+		if (appCtx != null) {
+			((ConfigurableApplicationContext) appCtx).close();
+			appCtx = null;
+		}
+	}
 }

Modified: ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java?rev=1817062&r1=1817061&r2=1817062&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java (original)
+++ ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/umls/dao/UMLSDaoTest.java Mon Dec  4 05:42:48 2017
@@ -20,13 +20,19 @@ package org.apache.ctakes.ytex.umls.dao;
 
 import java.util.List;
 
+import org.apache.ctakes.core.ae.UmlsEnvironmentConfiguration;
+import org.apache.ctakes.utils.env.EnvironmentVariable;
 import org.apache.log4j.Logger;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
 
+import static org.junit.Assume.assumeTrue;
+
 /**
  * this test only works if MRCONSO is in the database (not the case for default
  * test settings). In case MRCONSO is not there, catch exception and ignore.
@@ -36,28 +42,45 @@ import org.springframework.context.acces
  */
 public class UMLSDaoTest {
 	private static final Logger log = Logger.getLogger(UMLSDaoTest.class);
-	UMLSDao umlsDao = null;
+
+	private ApplicationContext appCtx = null;
+	private UMLSDao umlsDao = null;
+
+	// TODO: consider removing duplicates.
+	private static final Boolean hasUMLSCredentials() {
+		return EnvironmentVariable.getEnv(UmlsEnvironmentConfiguration.USER.toString()) != null;
+	}
 
 	@Before
 	public void setUp() throws Exception {
-		ApplicationContext appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
-				.getInstance(
-						"classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
+		assumeTrue( hasUMLSCredentials() );
+
+		appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
+				.getInstance("classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
 				.useBeanFactory("kernelApplicationContext").getFactory();
+
 		umlsDao = appCtx.getBean(UMLSDao.class);
 	}
 
+
 	@Test
 	public void testGetAllAuiStr() {
+		// TODO: by catching Exception, the test succedes even if the umlsDao.getAllAuiStr fails
 		try {
 			List<Object[]> auis = umlsDao.getAllAuiStr("");
+			// TODO: not a sufficient integration test
 			Assert.assertNotNull(auis);
 			log.debug("testGetAllAuiStr()" + auis.size());
 		} catch (Exception e) {
-			log.warn(
-					"sql exception - mrconso probably doesn't exist, check error",
-					e);
+			log.warn("sql exception - mrconso probably doesn't exist, check error", e);
 		}
 	}
 
+	@After
+	public void tearDown() throws  Exception {
+		if (appCtx != null) {
+			((ConfigurableApplicationContext) appCtx).close();
+			appCtx = null;
+		}
+	}
 }

Added: ctakes/trunk/ctakes-ytex/src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties?rev=1817062&view=auto
==============================================================================
--- ctakes/trunk/ctakes-ytex/src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties (added)
+++ ctakes/trunk/ctakes-ytex/src/test/resources/org/apache/ctakes/ytex/ytex.hsqldb.properties Mon Dec  4 05:42:48 2017
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+
+# database (catalog) name
+db.name=YTEX_TEST
+
+# schema. default is dbo
+db.schema=ytex
+
+# jdbc url for database.  Replace localhost and YTEX_TEST 
+# with the values of db.host and db.name respectively
+db.url=jdbc:hsqldb:hsql://localhost;databaseName=YTEX_TEST;integratedSecurity=false
+
+# assume windows integrated authentication, change if necessary
+db.username=ytex_test
+db.password=ytex
+
+# the schema and catalog (database) where umls is installed
+# if not specified, will default to schema/database from ytex
+#umls.schema=dbo
+#umls.catalog=umls_test
+
+# you should not have to modify anything below
+db.type=hsql
+db.driver=org.hsqldb.jdbcDriver
+db.initStatements=
+hibernate.dialect=org.hibernate.dialect.HSQLDialect
+
+# transaction isolation level
+db.isolationLevel=READ_UNCOMMITTED