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 b398154361115194878ac84bf332d7cdd79f1cde..1732251400c48393de08e4d1220b243067075317 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 5caec258075dcd57e1720d34d40ba38e2dc0b379..c3247e60d536ca2c1f2d91678892ec3bb34be33a 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 a82fccd5fb87ca0df2e31e0b7e4f9963b247dd70..f62cbb2b9458c218670518c6babd5cb609035ff4 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 d1d9ad487f604c728ad6996639e3a881554b846d..7233362adb8a417ab34f02da424b5d8be04b32c3 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 68c45839c2c66996ec72bccbf241c6fdccd0b371..79abf4ede7773b3131f314b06832dbb5cbe3803e 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 c8bb1fc62193e352ccda0c13d26bbeb9d8c78c74..80e37ce9af6674a5b6790f164612bfa13bc14a2b 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 0000000000000000000000000000000000000000..c05e07f72d1f2a071c4bcbe97c1eec3f5b13a49c --- /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 d230142496756fb49dff772f487f060766761555..7f48ae3bdab9a481b9ffa0962d48187cd8e7003c 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 710b4fabfb8bcfa9a59f7e4a81e294167799c077..ba39f02ba09775388598c88ba988dba2bb667c6d 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 332e80587fad7029b3baaa24f691593fe3c80595..7e1eb12f8d071516f19da2e70fbb8ff951b7094c 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 0000000000000000000000000000000000000000..ac1a4c4381177800ce08652c19f2f1fb748679d7 --- /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)*")); + } +}