Skip to content

Commit

Permalink
Merge pull request apereo#94 from leleuj/casc-91
Browse files Browse the repository at this point in the history
Issue-91: Introduce system properties configuration option
  • Loading branch information
battags committed Jan 7, 2015
2 parents e2764a7 + fae996b commit 33149e4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*/
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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 33149e4

Please sign in to comment.