Issue-91: Introduce system properties configuration option
First commit
This commit is contained in:
parent
e2764a7be1
commit
fae996bde7
|
|
@ -31,7 +31,8 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public enum ConfigurationStrategyName {
|
||||
|
||||
DEFAULT(LegacyConfigurationStrategyImpl.class), JNDI(JndiConfigurationStrategyImpl.class), WEB_XML(WebXmlConfigurationStrategyImpl.class), PROPERTY_FILE(PropertiesConfigurationStrategyImpl.class);
|
||||
DEFAULT(LegacyConfigurationStrategyImpl.class), JNDI(JndiConfigurationStrategyImpl.class), WEB_XML(WebXmlConfigurationStrategyImpl.class),
|
||||
PROPERTY_FILE(PropertiesConfigurationStrategyImpl.class), SYSTEM_PROPERTIES(SystemPropertiesConfigurationStrategyImpl.class);
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationStrategyName.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work
|
||||
* for additional information regarding copyright ownership.
|
||||
* Jasig 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 the following location:
|
||||
*
|
||||
* 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 org.jasig.cas.client.configuration;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterConfig;
|
||||
|
||||
/**
|
||||
* Load all configuration from system properties.
|
||||
*
|
||||
* @author Jerome Leleu
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public class SystemPropertiesConfigurationStrategyImpl extends BaseConfigurationStrategy {
|
||||
|
||||
public void init(FilterConfig filterConfig, Class<? extends Filter> filterClazz) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String get(ConfigurationKey configurationKey) {
|
||||
return System.getProperty(configurationKey.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,8 @@ public final class ConfigurationStrategyNameTests {
|
|||
public void stringToClass() {
|
||||
assertEquals(JndiConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy(ConfigurationStrategyName.JNDI.name()));
|
||||
assertEquals(WebXmlConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy(ConfigurationStrategyName.WEB_XML.name()));
|
||||
assertEquals(PropertiesConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy(ConfigurationStrategyName.PROPERTY_FILE.name()));
|
||||
assertEquals(SystemPropertiesConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy(ConfigurationStrategyName.SYSTEM_PROPERTIES.name()));
|
||||
assertEquals(LegacyConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy(ConfigurationStrategyName.DEFAULT.name()));
|
||||
assertEquals(LegacyConfigurationStrategyImpl.class, ConfigurationStrategyName.resolveToConfigurationStrategy("bleh!"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work
|
||||
* for additional information regarding copyright ownership.
|
||||
* Jasig 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 the following location:
|
||||
*
|
||||
* 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 org.jasig.cas.client.configuration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockFilterConfig;
|
||||
|
||||
/**
|
||||
* Tests {@link SystemPropertiesConfigurationStrategyImpl}.
|
||||
*
|
||||
* @author Jerome Leleu
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public class SystemPropertiesConfigurationStrategyImplTests {
|
||||
|
||||
private final static String PARAMETER_NAME = "parameter";
|
||||
|
||||
private SystemPropertiesConfigurationStrategyImpl impl;
|
||||
|
||||
private MockFilterConfig filterConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.filterConfig = new MockFilterConfig();
|
||||
this.impl = new SystemPropertiesConfigurationStrategyImpl();
|
||||
this.impl.init(this.filterConfig, AbstractCasFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSystemPropertyDefined() {
|
||||
final ConfigurationKey<String> key = ConfigurationKeys.SERVER_NAME;
|
||||
// no system property defined
|
||||
assertEquals(key.getDefaultValue(), impl.getString(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSystemProperty() {
|
||||
final ConfigurationKey<String> key = ConfigurationKeys.ARTIFACT_PARAMETER_NAME;
|
||||
System.setProperty(key.getName(), PARAMETER_NAME);
|
||||
assertEquals(PARAMETER_NAME, impl.getString(key));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue