From e8fc59049ec4b5067250146463f8dc7a437e7ff6 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 22 Oct 2012 06:31:02 +0000 Subject: [PATCH] SP-326,BIS-217: Introducing ModuleEnabledChecker (with unit tests) in order to check also for AS core plugins by using regex. Replacing 'technology' by 'module' in some names of variables, methods etc. SVN: 27251 --- .../systemtests/SystemTestCase.java | 2 +- .../web/server/AbstractClientService.java | 2 +- .../server/business/bo/CorePluginTable.java | 7 +- .../coreplugin/CorePluginRegistrator.java | 12 ++-- .../openbis/generic/shared/Constants.java | 2 +- .../coreplugin/CorePluginsInjector.java | 61 ++++------------ .../coreplugin/ModuleEnabledChecker.java | 70 +++++++++++++++++++ .../generic/shared/util/ServerUtils.java | 3 +- .../business/bo/CorePluginTableTest.java | 14 ++-- .../coreplugin/CorePluginsInjectorTest.java | 18 ++--- .../coreplugin/ModuleEnabledCheckerTest.java | 65 +++++++++++++++++ 11 files changed, 178 insertions(+), 78 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledChecker.java create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledCheckerTest.java diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java index b3981543611..1732251400c 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java @@ -165,7 +165,7 @@ public abstract class SystemTestCase extends AssertJUnit System.setProperty(OPENBIS_DSS_SYSTEM_PROPERTIES_PREFIX + "core-plugins-folder", SOURCE_TEST_CORE_PLUGINS); System.setProperty(OPENBIS_DSS_SYSTEM_PROPERTIES_PREFIX - + Constants.ENABLED_TECHNOLOGIES_KEY, getEnabledTechnologies()); + + Constants.ENABLED_MODULES_KEY, getEnabledTechnologies()); System.setProperty(OPENBIS_DSS_SYSTEM_PROPERTIES_PREFIX + ROOT_DIR_KEY, rootDir.getAbsolutePath()); System.setProperty(OPENBIS_DSS_SYSTEM_PROPERTIES_PREFIX diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java index 5caec258075..c3247e60d53 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java @@ -453,7 +453,7 @@ public abstract class AbstractClientService implements IClientService, .getWebClientConfiguration()); } applicationInfo.setEnabledTechnologies(ServerUtils.extractSet(getServiceProperties() - .getProperty(Constants.ENABLED_TECHNOLOGIES_KEY))); + .getProperty(Constants.ENABLED_MODULES_KEY))); applicationInfo.setCustomImports(extractCustomImportProperties()); applicationInfo.setWebapps(extractWebAppsProperties()); applicationInfo.setArchivingConfigured(isArchivingConfigured()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTable.java index a82fccd5fb8..f62cbb2b945 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTable.java @@ -99,15 +99,14 @@ public final class CorePluginTable extends AbstractBusinessObject implements ICo if (false == StringUtils.isEmpty(masterDataScript)) { runInitializeMasterDataScript(plugin, masterDataScript); + CorePluginPE pluginPE = CorePluginTranslator.translate(plugin, masterDataScript); + getCorePluginDAO().createCorePlugins(Collections.singletonList(pluginPE)); + operationLog.info(plugin + " installed succesfully."); } else { operationLog.info(String.format("No '%s' script found for '%s'. Skipping..", AsCorePluginPaths.INIT_MASTER_DATA_SCRIPT, plugin)); } - - CorePluginPE pluginPE = CorePluginTranslator.translate(plugin, masterDataScript); - getCorePluginDAO().createCorePlugins(Collections.singletonList(pluginPE)); - operationLog.info(plugin + " installed succesfully."); } private void runInitializeMasterDataScript(CorePlugin plugin, String masterDataScript) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java index d1d9ad487f6..7233362adb8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java @@ -16,8 +16,7 @@ package ch.systemsx.cisd.openbis.generic.server.coreplugin; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; import org.apache.log4j.Logger; import org.springframework.beans.factory.InitializingBean; @@ -28,6 +27,7 @@ import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin; import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner; import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner.ScannerType; +import ch.systemsx.cisd.openbis.generic.shared.coreplugin.ModuleEnabledChecker; import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; import ch.systemsx.cisd.openbis.generic.shared.util.ServerUtils; @@ -42,7 +42,7 @@ public class CorePluginRegistrator implements InitializingBean private String pluginsFolderName; - private Set<String> enabledTechnologies = new HashSet<String>(); + private ModuleEnabledChecker moduleEnabledChecker; /** * Loads and installs the deployed core plugins. Invoked from the Spring container after the @@ -59,7 +59,7 @@ public class CorePluginRegistrator implements InitializingBean String sessionToken = getSessionToken(); for (CorePlugin plugin : pluginScanner.scanForPlugins()) { - if (enabledTechnologies.contains(plugin.getName())) + if (moduleEnabledChecker.isModuleEnabled(plugin.getName())) { try { @@ -85,7 +85,9 @@ public class CorePluginRegistrator implements InitializingBean public void setEnabledTechnologies(String listOfEnabledTechnologies) { - enabledTechnologies = ServerUtils.extractSet(listOfEnabledTechnologies); + moduleEnabledChecker = + new ModuleEnabledChecker(new ArrayList<String>( + ServerUtils.extractSet(listOfEnabledTechnologies))); } public void setCommonServer(ICommonServerForInternalUse commonServer) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java index 68c45839c2c..79abf4ede77 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/Constants.java @@ -25,7 +25,7 @@ public class Constants { public static final String USER_PARAMETER = "user"; - public static final String ENABLED_TECHNOLOGIES_KEY = "enabled-modules"; + public static final String ENABLED_MODULES_KEY = "enabled-modules"; public static final int MAX_SPEED = 100; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java index c8bb1fc6219..80e37ce9af6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; @@ -30,10 +29,8 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.TreeSet; -import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; import ch.systemsx.cisd.common.exception.ConfigurationFailureException; import ch.systemsx.cisd.common.exception.EnvironmentFailureException; @@ -43,6 +40,7 @@ import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogLevel; import ch.systemsx.cisd.common.properties.PropertyParametersUtil; +import ch.systemsx.cisd.common.properties.PropertyUtils; import ch.systemsx.cisd.common.shared.basic.string.CommaSeparatedListBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin; import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner.ScannerType; @@ -98,27 +96,21 @@ public class CorePluginsInjector public void injectCorePlugins(Properties properties) { - String corePluginsFolderPath = CorePluginsUtils.getCorePluginsFolder(properties, scannerType); + String corePluginsFolderPath = + CorePluginsUtils.getCorePluginsFolder(properties, scannerType); injectCorePlugins(properties, corePluginsFolderPath); } public void injectCorePlugins(Properties properties, String corePluginsFolderPath) { - List<String> enabledTechnologiesRegexs = - getList(properties, - ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY); - List<Pattern> enabledTechnologiesPatterns = new ArrayList<Pattern>(); - for (String regex : enabledTechnologiesRegexs) - { - enabledTechnologiesPatterns.add(Pattern.compile(regex)); - } - List<String> disabledPlugins = getList(properties, DISABLED_CORE_PLUGINS_KEY); + ModuleEnabledChecker moduleEnabledChecker = new ModuleEnabledChecker(properties); + List<String> disabledPlugins = PropertyUtils.getList(properties, DISABLED_CORE_PLUGINS_KEY); PluginKeyBundles pluginKeyBundles = new PluginKeyBundles(properties, pluginTypes); Set<String> pluginNames = new HashSet<String>(); pluginKeyBundles.addAndCheckUniquePluginNames(pluginNames); Map<IPluginType, Map<String, NamedCorePluginFolder>> plugins = - scanForCorePlugins(corePluginsFolderPath, enabledTechnologiesPatterns, - disabledPlugins, pluginNames); + scanForCorePlugins(corePluginsFolderPath, moduleEnabledChecker, disabledPlugins, + pluginNames); for (Entry<IPluginType, Map<String, NamedCorePluginFolder>> entry : plugins.entrySet()) { IPluginType pluginType = entry.getKey(); @@ -177,35 +169,8 @@ public class CorePluginsInjector } } - private List<String> getList(Properties properties, String key) - { - List<String> set = new ArrayList<String>(); - String property = properties.getProperty(key); - if (StringUtils.isNotBlank(property)) - { - String[] splittedProperty = property.split(","); - for (String term : splittedProperty) - { - set.add(term.trim()); - } - } - return set; - } - - private boolean isTechnologyEnabled(List<Pattern> enabledTechnologiesPatterns, String technology) - { - for (Pattern pattern : enabledTechnologiesPatterns) - { - if (pattern.matcher(technology).matches()) - { - return true; - } - } - return false; - } - private Map<IPluginType, Map<String, NamedCorePluginFolder>> scanForCorePlugins( - String corePluginsFolderPath, List<Pattern> enabledTechnologies, + String corePluginsFolderPath, ModuleEnabledChecker moduleEnabledChecker, List<String> disabledPlugins, Set<String> pluginNames) { Map<IPluginType, Map<String, NamedCorePluginFolder>> typeToPluginsMap = @@ -215,10 +180,10 @@ public class CorePluginsInjector List<CorePlugin> plugins = scanner.scanForPlugins(); for (CorePlugin corePlugin : plugins) { - String technology = corePlugin.getName(); - if (isTechnologyEnabled(enabledTechnologies, technology) == false) + String module = corePlugin.getName(); + if (moduleEnabledChecker.isModuleEnabled(module) == false) { - logger.log(LogLevel.INFO, "Core plugins for technology '" + technology + logger.log(LogLevel.INFO, "Core plugins for module '" + module + "' are not enabled."); continue; } @@ -241,13 +206,13 @@ public class CorePluginsInjector { String pluginName = pluginFolder.getName(); NamedCorePluginFolder plugin = - new NamedCorePluginFolder(technology, pluginType, pluginFolder); + new NamedCorePluginFolder(module, pluginType, pluginFolder); String fullPluginName = plugin.getFullPluginName(); if (isDisabled(disabledPlugins, fullPluginName) == false) { String fullPluginKey = pluginType.getPrefix() - + pluginType.getPluginKey(technology, pluginName, + + pluginType.getPluginKey(module, pluginName, plugin.getPluginProperties()); assertAndAddPluginName(fullPluginKey, pluginNames, pluginType); Map<String, NamedCorePluginFolder> map = diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledChecker.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledChecker.java new file mode 100644 index 00000000000..c05e07f72d1 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledChecker.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed 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 ch.systemsx.cisd.openbis.generic.shared.coreplugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import ch.systemsx.cisd.common.exception.ConfigurationFailureException; +import ch.systemsx.cisd.common.properties.PropertyUtils; +import ch.systemsx.cisd.openbis.generic.shared.Constants; + +/** + * Helper class for checking enabled module. + * + * @author Franz-Josef Elmer + */ +public class ModuleEnabledChecker +{ + private final List<Pattern> enabledModulesPatterns; + + public ModuleEnabledChecker(Properties properties) + { + this(PropertyUtils.getList(properties, Constants.ENABLED_MODULES_KEY)); + } + + public ModuleEnabledChecker(List<String> moduleRegExs) + { + enabledModulesPatterns = new ArrayList<Pattern>(); + for (String regex : moduleRegExs) + { + try + { + enabledModulesPatterns.add(Pattern.compile(regex)); + } catch (PatternSyntaxException ex) + { + throw new ConfigurationFailureException("Invalid regular expression: " + + ex.getMessage()); + } + } + } + + public boolean isModuleEnabled(String module) + { + for (Pattern pattern : enabledModulesPatterns) + { + if (pattern.matcher(module).matches()) + { + return true; + } + } + return false; + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java index d2301424967..7f48ae3bdab 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.shared.util; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -68,7 +69,7 @@ public class ServerUtils */ public static Set<String> extractSet(String commaSeparatedList) { - Set<String> result = new HashSet<String>(); + Set<String> result = new LinkedHashSet<String>(); if (commaSeparatedList != null && commaSeparatedList.startsWith("$") == false) { String[] terms = commaSeparatedList.split(","); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTableTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTableTest.java index 710b4fabfb8..ba39f02ba09 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTableTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/CorePluginTableTest.java @@ -27,6 +27,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.common.exception.ConfigurationFailureException; +import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.common.test.RecordingMatcher; import ch.systemsx.cisd.openbis.generic.server.coreplugin.AsCorePluginPaths; import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl.IMasterDataScriptRegistrationRunner; @@ -50,9 +51,12 @@ public class CorePluginTableTest extends AbstractBOTest private CorePluginTable pluginTable; + private BufferedAppender logRecorder; + @BeforeMethod public void setUp() { + logRecorder = new BufferedAppender(); scriptRunner = context.mock(IMasterDataScriptRegistrationRunner.class); pluginResourceLoader = context.mock(ICorePluginResourceLoader.class); pluginTable = new CorePluginTable(daoFactory, EXAMPLE_SESSION, scriptRunner); @@ -80,19 +84,13 @@ public class CorePluginTableTest extends AbstractBOTest one(pluginResourceLoader).tryLoadToString(plugin, AsCorePluginPaths.INIT_MASTER_DATA_SCRIPT); will(returnValue(null)); - - one(corePluginDAO).createCorePlugins(with(createdPluginsMatcher)); } }); pluginTable.registerPlugin(plugin, pluginResourceLoader); - assertEquals(1, createdPluginsMatcher.getRecordedObjects().size()); - assertEquals(1, createdPluginsMatcher.recordedObject().size()); - CorePluginPE createdPluginPE = createdPluginsMatcher.recordedObject().get(0); - assertEquals(plugin.getName(), createdPluginPE.getName()); - assertEquals(plugin.getVersion(), createdPluginPE.getVersion()); - assertNull(createdPluginPE.getMasterDataRegistrationScript()); + assertEquals("No 'initialize-master-data.py' script found for " + + "'Core Plugin[name='A', version='2']'. Skipping..", logRecorder.getLogContent()); } @Test diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjectorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjectorTest.java index 332e80587fa..7e1eb12f8d0 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjectorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjectorTest.java @@ -107,7 +107,7 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase corePluginsFolderProperty = CorePluginsUtils.CORE_PLUGINS_FOLDER_KEY + " = " + corePluginsFolder + "\n"; enabledScreeningProperty = - ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_MODULES_KEY + " = screening\n"; } @@ -268,7 +268,7 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase injector.injectCorePlugins(properties); assertProperties(corePluginsFolderProperty - + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY + + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_MODULES_KEY + " = prot.*, screening\n" + "inputs = my-drop-box\n" + "my-drop-box.script1 = " + myDropBox + "/script1.py\n" + "my-drop-box.script2 = " + myDropBox + "/script2.py\n" + "my-processing.script = " + myProcessingPlugin + "/script.py\n" @@ -507,7 +507,7 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase injector.injectCorePlugins(properties); assertProperties(corePluginsFolderProperty - + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY + + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_MODULES_KEY + " = screening, proteomics\n" + "prefix.dss = dss1[proteomics], dss1[screening]\n" + "prefix.dss1[proteomics].driver = beta\n" + "prefix.dss1[proteomics].url = blub\n" @@ -536,7 +536,7 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase injector.injectCorePlugins(properties); assertProperties(corePluginsFolderProperty - + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY + + ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_MODULES_KEY + " = screening, dev\n" + "prefix.dss = dss1[screening], dss2[screening]\n" + "prefix.dss1[screening].driver = alpha\n" + "prefix.dss1[screening].url = blabla\n" @@ -583,13 +583,13 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase }); } - private void prepareNotEnabledTechnology(final String technology) + private void prepareNotEnabledTechnology(final String module) { context.checking(new Expectations() { { one(logger).log(LogLevel.INFO, - "Core plugins for technology '" + technology + "' are not enabled."); + "Core plugins for module '" + module + "' are not enabled."); } }); } @@ -621,9 +621,9 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase Properties properties = new ExtendedProperties(); properties.setProperty(CorePluginsUtils.CORE_PLUGINS_FOLDER_KEY, corePluginsFolder.getPath()); - properties.setProperty( - ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_TECHNOLOGIES_KEY, - technologies); + properties + .setProperty(ch.systemsx.cisd.openbis.generic.shared.Constants.ENABLED_MODULES_KEY, + technologies); return properties; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledCheckerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledCheckerTest.java new file mode 100644 index 00000000000..ac1a4c43811 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/ModuleEnabledCheckerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed 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 ch.systemsx.cisd.openbis.generic.shared.coreplugin; + +import java.util.Arrays; +import java.util.Properties; + +import junit.framework.TestCase; + +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.exception.ConfigurationFailureException; +import ch.systemsx.cisd.openbis.generic.shared.Constants; + +/** + * @author Franz-Josef Elmer + */ +public class ModuleEnabledCheckerTest extends TestCase +{ + @Test + public void testFromList() + { + ModuleEnabledChecker checker = new ModuleEnabledChecker(Arrays.asList("abc", "abc-.*")); + + assertEquals( + "[true, false, true, false]", + Arrays.asList(checker.isModuleEnabled("abc"), checker.isModuleEnabled("abcd"), + checker.isModuleEnabled("abc-d"), checker.isModuleEnabled("ABC")) + .toString()); + } + + @Test + public void testFromProperty() + { + Properties properties = new Properties(); + properties.setProperty(Constants.ENABLED_MODULES_KEY, "a.*, beta"); + ModuleEnabledChecker checker = new ModuleEnabledChecker(properties); + + assertEquals( + "[true, false, true, false]", + Arrays.asList(checker.isModuleEnabled("abc"), + checker.isModuleEnabled("betablocker"), checker.isModuleEnabled("beta"), + checker.isModuleEnabled("ABC")).toString()); + } + + @Test(expectedExceptions = ConfigurationFailureException.class) + public void testWithInvalidRegEx() + { + new ModuleEnabledChecker(Arrays.asList("[a-b)*")); + } +} -- GitLab